1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
9 #if defined(HAVE_OPENLDAP)
10 #define LDAP_DEPRECATED 1
23 #if defined(HAVE_OPENLDAP)
31 std::string searchfilter;
34 bool msad = false; /* TODO: possible future specialization */
38 using lock_guard = std::lock_guard<std::mutex>;
40 LDAPHelper(std::string _uri, std::string _binddn, std::string _bindpw,
41 std::string _searchdn, std::string _searchfilter, std::string _dnattr)
42 : uri(std::move(_uri)), binddn(std::move(_binddn)),
43 bindpw(std::move(_bindpw)), searchdn(_searchdn), searchfilter(_searchfilter), dnattr(_dnattr),
50 ret = ldap_initialize(&ldap, uri.c_str());
51 if (ret == LDAP_SUCCESS) {
52 unsigned long ldap_ver = LDAP_VERSION3;
53 ret = ldap_set_option(ldap, LDAP_OPT_PROTOCOL_VERSION,
56 if (ret == LDAP_SUCCESS) {
57 ret = ldap_set_option(ldap, LDAP_OPT_REFERRALS, LDAP_OPT_OFF);
59 return (ret == LDAP_SUCCESS) ? ret : -EINVAL;
64 ret = ldap_simple_bind_s(ldap, binddn.c_str(), bindpw.c_str());
65 return (ret == LDAP_SUCCESS) ? ret : -EINVAL;
70 (void) ldap_unbind(ldap);
77 int simple_bind(const char *dn, const std::string& pwd) {
79 int ret = ldap_initialize(&tldap, uri.c_str());
80 if (ret == LDAP_SUCCESS) {
81 unsigned long ldap_ver = LDAP_VERSION3;
82 ret = ldap_set_option(tldap, LDAP_OPT_PROTOCOL_VERSION,
84 if (ret == LDAP_SUCCESS) {
85 ret = ldap_simple_bind_s(tldap, dn, pwd.c_str());
86 if (ret == LDAP_SUCCESS) {
87 (void) ldap_unbind(tldap);
91 return ret; // OpenLDAP client error space
94 int auth(const std::string uid, const std::string pwd);
98 (void) ldap_unbind(ldap);
108 LDAPHelper(std::string _uri, std::string _binddn, std::string _bindpw,
109 std::string _searchdn, std::string _searchfilter, std::string _dnattr)
120 int auth(const std::string uid, const std::string pwd) {
129 #endif /* HAVE_OPENLDAP */
131 } /* namespace rgw */
133 #include "common/ceph_context.h"
134 #include "common/common_init.h"
135 #include "common/dout.h"
136 #include "common/safe_io.h"
137 #include <boost/algorithm/string.hpp>
139 #include "include/assert.h"
141 std::string parse_rgw_ldap_bindpw(CephContext* ctx);
143 #endif /* RGW_LDAP_H */