ldapconnection.cpp (msktutil-1.1.tar.bz2) | : | ldapconnection.cpp (msktutil-1.2.1) | ||
---|---|---|---|---|
skipping to change at line 58 | skipping to change at line 58 | |||
while (interact->id != SASL_CB_LIST_END) { | while (interact->id != SASL_CB_LIST_END) { | |||
dflt = (char *) interact->defresult; | dflt = (char *) interact->defresult; | |||
interact->result = (dflt && *dflt) ? dflt : (void *) ""; | interact->result = (dflt && *dflt) ? dflt : (void *) ""; | |||
interact->len = (dflt && *dflt) ? strlen(dflt) : 0; | interact->len = (dflt && *dflt) ? strlen(dflt) : 0; | |||
interact++; | interact++; | |||
} | } | |||
return LDAP_SUCCESS; | return LDAP_SUCCESS; | |||
} | } | |||
LDAPConnection::LDAPConnection(const std::string &server, | LDAPConnection::LDAPConnection(const std::string &server, | |||
const std::string &sasl_mechanisms, | ||||
bool no_reverse_lookups) : | bool no_reverse_lookups) : | |||
m_ldap() | m_ldap() | |||
{ | { | |||
int ret = 0; | int ret = 0; | |||
#ifdef HAVE_LDAP_INITIALIZE | #ifdef HAVE_LDAP_INITIALIZE | |||
std::string ldap_url = "ldap://" + server; | std::string ldap_url = "ldap://" + server; | |||
VERBOSEldap("calling ldap_initialize"); | VERBOSEldap("Calling ldap_initialize"); | |||
ret = ldap_initialize(&m_ldap, ldap_url.c_str()); | ret = ldap_initialize(&m_ldap, ldap_url.c_str()); | |||
#else | #else | |||
VERBOSEldap("calling ldap_init"); | VERBOSEldap("Calling ldap_init"); | |||
m_ldap = ldap_init(server.c_str(), LDAP_PORT); | m_ldap = ldap_init(server.c_str(), LDAP_PORT); | |||
if (m_ldap) { | if (m_ldap) { | |||
ret = LDAP_SUCCESS; | ret = LDAP_SUCCESS; | |||
} else { | } else { | |||
ret = LDAP_OTHER; | ret = LDAP_OTHER; | |||
} | } | |||
#endif | #endif | |||
if (ret) { | if (ret) { | |||
throw LDAPException("ldap_initialize", ret); | throw LDAPException("ldap_initialize", ret); | |||
} | } | |||
skipping to change at line 108 | skipping to change at line 109 | |||
set_option(LDAP_OPT_X_SASL_NOCANON, LDAP_OPT_ON); | set_option(LDAP_OPT_X_SASL_NOCANON, LDAP_OPT_ON); | |||
} catch (LDAPException &e) { | } catch (LDAPException &e) { | |||
VERBOSE("Could not disable reverse lookups in LDAP"); | VERBOSE("Could not disable reverse lookups in LDAP"); | |||
} | } | |||
} | } | |||
#else | #else | |||
VERBOSE("Your LDAP version does not support the option to disable " | VERBOSE("Your LDAP version does not support the option to disable " | |||
"reverse lookups"); | "reverse lookups"); | |||
#endif | #endif | |||
VERBOSEldap("calling ldap_sasl_interactive_bind_s"); | VERBOSEldap("Calling ldap_sasl_interactive_bind_s with mechs: %s", sasl_mech anisms.c_str()); | |||
ret = ldap_sasl_interactive_bind_s(m_ldap, NULL, "GSSAPI", NULL, NULL, | ret = ldap_sasl_interactive_bind_s(m_ldap, NULL, sasl_mechanisms.c_str(), NU LL, NULL, | |||
#ifdef LDAP_SASL_QUIET | #ifdef LDAP_SASL_QUIET | |||
g_verbose ? 0 : LDAP_SASL_QUIET, | g_verbose ? 0 : LDAP_SASL_QUIET, | |||
#else | #else | |||
0, | 0, | |||
#endif | #endif | |||
sasl_interact, NULL); | sasl_interact, NULL); | |||
if (ret) { | if (ret) { | |||
print_diagnostics("ldap_sasl_interactive_bind_s failed", ret); | print_diagnostics("ldap_sasl_interactive_bind_s failed", ret); | |||
m_ldap = NULL; | m_ldap = NULL; | |||
skipping to change at line 215 | skipping to change at line 216 | |||
char **vattr = &v_chptr[0]; | char **vattr = &v_chptr[0]; | |||
return search(base_dn, scope, filter, const_cast<const char**>(vattr)); | return search(base_dn, scope, filter, const_cast<const char**>(vattr)); | |||
} | } | |||
LDAPMessage * | LDAPMessage * | |||
LDAPConnection::search(const std::string &base_dn, int scope, | LDAPConnection::search(const std::string &base_dn, int scope, | |||
const std::string &filter, const char *attrs[]) | const std::string &filter, const char *attrs[]) | |||
{ | { | |||
LDAPMessage * mesg; | LDAPMessage * mesg; | |||
VERBOSEldap("calling ldap_search_ext_s"); | VERBOSEldap("Calling ldap_search_ext_s"); | |||
VERBOSEldap("ldap_search_ext_s base context: %s", base_dn.c_str()); | VERBOSEldap("ldap_search_ext_s base context: %s", base_dn.c_str()); | |||
VERBOSEldap("ldap_search_ext_s filter: %s", filter.c_str()); | VERBOSEldap("ldap_search_ext_s filter: %s", filter.c_str()); | |||
int ret = ldap_search_ext_s(m_ldap, base_dn.c_str(), scope, filter.c_str(), | int ret = ldap_search_ext_s(m_ldap, base_dn.c_str(), scope, filter.c_str(), | |||
const_cast<char **>(attrs), 0, NULL, NULL, NULL, -1, &mesg); | const_cast<char **>(attrs), 0, NULL, NULL, NULL, -1, &mesg); | |||
if (ret) { | if (ret) { | |||
print_diagnostics("ldap_search_ext_s failed", ret); | print_diagnostics("ldap_search_ext_s failed", ret); | |||
throw LDAPException("ldap_search_ext_s", ret); | throw LDAPException("ldap_search_ext_s", ret); | |||
} | } | |||
return mesg; | return mesg; | |||
skipping to change at line 280 | skipping to change at line 281 | |||
LDAPMod attr; | LDAPMod attr; | |||
int ret; | int ret; | |||
mod_attrs[0] = &attr; | mod_attrs[0] = &attr; | |||
attr.mod_op = op; | attr.mod_op = op; | |||
attr.mod_type = const_cast<char *>(type.c_str()); | attr.mod_type = const_cast<char *>(type.c_str()); | |||
attr.mod_values = vals; | attr.mod_values = vals; | |||
mod_attrs[1] = NULL; | mod_attrs[1] = NULL; | |||
VERBOSEldap("calling ldap_modify_ext_s"); | VERBOSEldap("Calling ldap_modify_ext_s"); | |||
ret = ldap_modify_ext_s(m_ldap, dn.c_str(), mod_attrs, NULL, NULL); | ret = ldap_modify_ext_s(m_ldap, dn.c_str(), mod_attrs, NULL, NULL); | |||
if (check && ret != LDAP_SUCCESS) { | if (check && ret != LDAP_SUCCESS) { | |||
VERBOSE("ldap_modify_ext_s failed (%s)", ldap_err2string(ret)); | VERBOSE("ldap_modify_ext_s failed: %s", ldap_err2string(ret)); | |||
} | } | |||
return ret; | return ret; | |||
} | } | |||
int LDAPConnection::remove_attr(const std::string &dn, const std::string& type, | int LDAPConnection::remove_attr(const std::string &dn, const std::string& type, | |||
const std::string& val) | const std::string& val) | |||
{ | { | |||
char *vals_name[] = { NULL, NULL }; | char *vals_name[] = { NULL, NULL }; | |||
vals_name[0] = const_cast<char *>(val.c_str()); | vals_name[0] = const_cast<char *>(val.c_str()); | |||
return modify_ext(dn, type, vals_name, LDAP_MOD_DELETE, true); | return modify_ext(dn, type, vals_name, LDAP_MOD_DELETE, true); | |||
skipping to change at line 335 | skipping to change at line 336 | |||
const_cast<LDAPMod **>(&tmp[0]), | const_cast<LDAPMod **>(&tmp[0]), | |||
NULL, | NULL, | |||
NULL); | NULL); | |||
if (ret) { | if (ret) { | |||
print_diagnostics("ldap_add_ext_s failed", ret); | print_diagnostics("ldap_add_ext_s failed", ret); | |||
throw LDAPException("ldap_add_ext_s", ret); | throw LDAPException("ldap_add_ext_s", ret); | |||
} | } | |||
return ret; | return ret; | |||
} | } | |||
int LDAPConnection::del(const std::string &dn) | ||||
{ | ||||
int ret = ldap_delete_ext_s(m_ldap, dn.c_str(), NULL, NULL); | ||||
if (ret) { | ||||
print_diagnostics("ldap_delete_ext_s failed", ret); | ||||
throw LDAPException("ldap_delete_ext_s", ret); | ||||
} | ||||
return ret; | ||||
} | ||||
void LDAP_mod::add(const std::string& type, const std::string& val, | void LDAP_mod::add(const std::string& type, const std::string& val, | |||
bool ucs) | bool ucs) | |||
{ | { | |||
LDAPMod *lm = new LDAPMod; | LDAPMod *lm = new LDAPMod; | |||
lm->mod_type = strdup(type.c_str()); | lm->mod_type = strdup(type.c_str()); | |||
if (ucs == false) { | if (ucs == false) { | |||
char **mv = new char *[2]; | char **mv = new char *[2]; | |||
mv[0] = strdup(val.c_str()); | mv[0] = strdup(val.c_str()); | |||
mv[1] = NULL; | mv[1] = NULL; | |||
lm->mod_values = mv; | lm->mod_values = mv; | |||
End of changes. 9 change blocks. | ||||
7 lines changed or deleted | 18 lines changed or added |