]> git.sur5r.net Git - openldap/commitdiff
don't use deprecated libldap functions
authorRalf Haferkamp <ralf@openldap.org>
Wed, 5 Oct 2005 17:26:27 +0000 (17:26 +0000)
committerRalf Haferkamp <ralf@openldap.org>
Wed, 5 Oct 2005 17:26:27 +0000 (17:26 +0000)
contrib/ldapc++/src/LDAPAsynConnection.cpp
contrib/ldapc++/src/LDAPException.cpp
contrib/ldapc++/src/LDAPResult.cpp
contrib/ldapc++/src/LDAPSearchReference.cpp
contrib/ldapc++/src/LDAPSearchRequest.cpp

index 58b60565762aa6e3d9c8626f80ede783b71cef0d..5e192c36071db8e29a530aa8939e9c3fa264091a 100644 (file)
@@ -21,6 +21,7 @@
 #include "LDAPRebind.h"
 #include "LDAPRebindAuth.h"
 #include "LDAPSearchRequest.h"
+#include <sstream>
 
 using namespace std;
 
@@ -48,7 +49,10 @@ void LDAPAsynConnection::init(const string& hostname, int port){
     DEBUG(LDAP_DEBUG_TRACE | LDAP_DEBUG_PARAMETER,
             "   hostname:" << hostname << endl
             << "   port:" << port << endl);
-    cur_session=ldap_init(hostname.c_str(),port);
+    std::ostringstream urlstream;
+    urlstream << "ldap://" + hostname << ":" << port;
+    std::string url = urlstream.str();
+    ldap_initialize(&cur_session, url.c_str());
     m_host=hostname;
     m_port=port;
     int opt=3;
@@ -270,18 +274,20 @@ LDAPAsynConnection* LDAPAsynConnection::referralConnect(
             string dn = auth->getDN();
             string passwd = auth->getPassword();
             const char* c_dn=0;
-            const char* c_passwd=0;
+            struct berval c_passwd = { 0, 0 };
             if(dn != ""){
                 c_dn = dn.c_str();
             }
             if(passwd != ""){
-                c_passwd = passwd.c_str();
+                c_passwd.bv_val = const_cast<char*>(passwd.c_str());
+                c_passwd.bv_len = passwd.size();
             }
-            err = ldap_simple_bind_s(tmpConn->getSessionHandle(), c_dn,
-                    c_passwd);
+            err = ldap_sasl_bind_s(tmpConn->getSessionHandle(), c_dn,
+                    LDAP_SASL_SIMPLE, &c_passwd, NULL, NULL, NULL);
         } else {   
             // Do anonymous bind
-            err = ldap_simple_bind_s(tmpConn->getSessionHandle(), 0,0);
+            err = ldap_sasl_bind_s(tmpConn->getSessionHandle(),NULL,
+                    LDAP_SASL_SIMPLE, NULL, NULL, NULL, NULL);
         }
         if( err == LDAP_SUCCESS ){
             usedUrl=conUrl;
index 5038df613b794eba9b005dc54c49949e0b0496dd..c7b0c5689ed17afb2b28794850cce450882e4171 100644 (file)
@@ -21,14 +21,21 @@ LDAPException::LDAPException(int res_code, const string& err_string){
 }
 
 LDAPException::LDAPException(const LDAPAsynConnection *lc){
-       m_err_string=string();
-       m_res_string=string();
-       LDAP *l = lc->getSessionHandle();
-       ldap_get_option(l,LDAP_OPT_ERROR_NUMBER,&m_res_code);
-       m_res_string=string(ldap_err2string(m_res_code));
-    char* err_string;
-       ldap_get_option(l,LDAP_OPT_ERROR_STRING,&err_string);
-    m_err_string=string(err_string);
+    LDAP *l = lc->getSessionHandle();
+    ldap_get_option(l,LDAP_OPT_ERROR_NUMBER,&m_res_code);
+    const char *res_cstring = ldap_err2string(m_res_code);
+    if ( res_cstring ) {
+        m_res_string = string(res_cstring);
+    } else {
+        m_res_string = "";
+    }
+    const char* err_string;
+    ldap_get_option(l,LDAP_OPT_ERROR_STRING,&err_string);
+    if ( err_string ) {
+        m_res_string = string(err_string);
+    } else {
+        m_res_string = "";
+    }
 }
 
 LDAPException::~LDAPException(){
index 598adc330a3ea5e38a859e4d6ecce413d14134af..5a3b2e48e370c6d86263ebf124d24ed0fbb9fa12 100644 (file)
@@ -24,13 +24,13 @@ LDAPResult::LDAPResult(const LDAPRequest *req, LDAPMessage *msg) :
         int err=ldap_parse_result(con->getSessionHandle(),msg,&m_resCode,
                 &matchedDN, &errMsg,&refs,&srvctrls,0);
         if(err != LDAP_SUCCESS){
-            ldap_value_free(refs);
+            ber_memvfree((void**) refs);
             ldap_controls_free(srvctrls);
             throw LDAPException(err);
         }else{
             if (refs){
                 m_referrals=LDAPUrlList(refs);
-                ldap_value_free(refs);
+                ber_memvfree((void**) refs);
             }
             if (srvctrls){
                 m_srvControls = LDAPControlSet(srvctrls);
index 7d22cea52e3fd110011a444cc919c6e645095ee3..a4e1b577ca6bdae15a7fdf1806bc162f957a2374 100644 (file)
@@ -24,12 +24,12 @@ LDAPSearchReference::LDAPSearchReference(const LDAPRequest *req,
     int err = ldap_parse_reference(con->getSessionHandle(), msg, &ref, 
             &srvctrls,0);
     if (err != LDAP_SUCCESS){
-        ldap_value_free(ref);
+        ber_memvfree((void**) ref);
         ldap_controls_free(srvctrls);
         throw LDAPException(err);
     }else{
         m_urlList=LDAPUrlList(ref);
-        ldap_value_free(ref);
+        ber_memvfree((void**) ref);
         if (srvctrls){
             m_srvControls = LDAPControlSet(srvctrls);
             m_hasControls = true;
index aa13cd77c9959a45a88a583c973a594ed7535d7f..532e86f38ed5b32da1cdb5580f7793b526bc7330 100644 (file)
@@ -70,7 +70,7 @@ LDAPMessageQueue* LDAPSearchRequest::sendRequest(){
             m_scope, m_filter.c_str(), tmpattrs, m_attrsOnly, tmpSrvCtrl,
             tmpClCtrl, tmptime, m_cons->getSizeLimit(), &msgID );
     delete tmptime;
-    ldap_value_free(tmpattrs);
+    ber_memvfree((void**)tmpattrs);
     LDAPControlSet::freeLDAPControlArray(tmpSrvCtrl);
     LDAPControlSet::freeLDAPControlArray(tmpClCtrl);