[Libreoffice-commits] .: extensions/source

Fridrich Strba fridrich at kemper.freedesktop.org
Wed Jul 18 06:17:36 PDT 2012


 extensions/source/config/ldap/ldapaccess.cxx      |   72 ++++++++++++++++++----
 extensions/source/config/ldap/wrapldapinclude.hxx |    6 -
 2 files changed, 64 insertions(+), 14 deletions(-)

New commits:
commit d391fe20a19393224900157414d9f1c6f731698a
Author: Fridrich Å trba <fridrich.strba at bluewin.ch>
Date:   Wed Jul 18 15:17:08 2012 +0200

    Using WCHAR ldap api on Windows
    
    Change-Id: Ie81c33a5c51ae588ae8242d8790c3c748b442d31

diff --git a/extensions/source/config/ldap/ldapaccess.cxx b/extensions/source/config/ldap/ldapaccess.cxx
index fefef06..45f656b 100644
--- a/extensions/source/config/ldap/ldapaccess.cxx
+++ b/extensions/source/config/ldap/ldapaccess.cxx
@@ -131,15 +131,27 @@ void  LdapConnection::connectSimple()
 #ifdef LDAP_X_OPT_CONNECT_TIMEOUT // OpenLDAP doesn't support this and the func
         /* timeout is specified in milliseconds -> 4 seconds*/
         int timeout = 4000;
+#ifdef WNT
+        ldap_set_optionW( mConnection,
+                        LDAP_X_OPT_CONNECT_TIMEOUT,
+                        &timeout );
+#else
         ldap_set_option( mConnection,
                         LDAP_X_OPT_CONNECT_TIMEOUT,
                         &timeout );
 #endif
+#endif
 
         // Do the bind
+#ifdef WNT
+        LdapErrCode retCode = ldap_simple_bind_sW(mConnection,
+                                               (PWCHAR) mLdapDefinition.mAnonUser.getStr(),
+                                               (PWCHAR) mLdapDefinition.mAnonCredentials.getStr() );
+#else
         LdapErrCode retCode = ldap_simple_bind_s(mConnection,
-                                               CONST_PCHAR_CAST rtl::OUStringToOString( mLdapDefinition.mAnonUser, RTL_TEXTENCODING_UTF8 ).getStr(),
-                                               CONST_PCHAR_CAST rtl::OUStringToOString( mLdapDefinition.mAnonCredentials, RTL_TEXTENCODING_UTF8 ).getStr()) ;
+                                               rtl::OUStringToOString( mLdapDefinition.mAnonUser, RTL_TEXTENCODING_UTF8 ).getStr(),
+                                               rtl::OUStringToOString( mLdapDefinition.mAnonCredentials, RTL_TEXTENCODING_UTF8 ).getStr()) ;
+#endif
 
         checkLdapReturnCode("SimpleBind", retCode, mConnection) ;
     }
@@ -158,8 +170,13 @@ void LdapConnection::initConnection()
 
     if (mLdapDefinition.mPort == 0) mLdapDefinition.mPort = LDAP_PORT;
 
-    mConnection = ldap_init(CONST_PCHAR_CAST  rtl::OUStringToOString( mLdapDefinition.mServer, RTL_TEXTENCODING_UTF8 ).getStr(),
+#ifdef WNT
+    mConnection = ldap_initW((PWCHAR) mLdapDefinition.mServer.getStr(),
+                            mLdapDefinition.mPort) ;
+#else
+    mConnection = ldap_init(rtl::OUStringToOString( mLdapDefinition.mServer, RTL_TEXTENCODING_UTF8 ).getStr(),
                             mLdapDefinition.mPort) ;
+#endif
     if (mConnection == NULL)
     {
         rtl::OUStringBuffer message ;
@@ -184,17 +201,37 @@ void LdapConnection::initConnection()
     rtl::OUString aUserDn =findUserDn( aUser );
 
     LdapMessageHolder result;
+#ifdef WNT
+    LdapErrCode retCode = ldap_search_sW(mConnection,
+                                      (PWCHAR) aUserDn.getStr(),
+                                      LDAP_SCOPE_BASE,
+                                      L"(objectclass=*)",
+                                      0,
+                                      0, // Attributes + values
+                                      &result.msg) ;
+#else
     LdapErrCode retCode = ldap_search_s(mConnection,
-                                      CONST_PCHAR_CAST rtl::OUStringToOString( aUserDn, RTL_TEXTENCODING_UTF8 ).getStr(),
+                                      rtl::OUStringToOString( aUserDn, RTL_TEXTENCODING_UTF8 ).getStr(),
                                       LDAP_SCOPE_BASE,
                                       "(objectclass=*)",
                                       0,
                                       0, // Attributes + values
                                       &result.msg) ;
-
+#endif
     checkLdapReturnCode("getUserProfile", retCode,mConnection) ;
 
     BerElement * ptr;
+#ifdef WNT
+    PWCHAR attr = ldap_first_attributeW(mConnection, result.msg, &ptr);
+    while (attr != 0) {
+        PWCHAR * values = ldap_get_valuesW(mConnection, result.msg, attr);
+        if (values != 0) {
+            data->insert(
+                LdapData::value_type( attr, *values ));
+            ldap_value_freeW(values);
+        }
+        attr = ldap_next_attributeW(mConnection, result.msg, ptr);
+#else
     char * attr = ldap_first_attribute(mConnection, result.msg, &ptr);
     while (attr != 0) {
         char ** values = ldap_get_values(mConnection, result.msg, attr);
@@ -206,6 +243,7 @@ void LdapConnection::initConnection()
             ldap_value_free(values);
         }
         attr = ldap_next_attribute(mConnection, result.msg, ptr);
+#endif
     }
 }
 //------------------------------------------------------------------------------
@@ -231,24 +269,36 @@ void LdapConnection::initConnection()
     filter.append( mLdapDefinition.mUserUniqueAttr ).append("=").append(aUser).append("))") ;
 
     LdapMessageHolder result;
-    sal_Char * attributes [2];
-    attributes[0]= const_cast<sal_Char *>(LDAP_NO_ATTRS);
-    attributes[1]= NULL;
+#ifdef WNT
+    PWCHAR attributes [2] = { LDAP_NO_ATTRS, NULL };
+    LdapErrCode retCode = ldap_search_sW(mConnection,
+                                      (PWCHAR) mLdapDefinition.mBaseDN.getStr(),
+                                      LDAP_SCOPE_SUBTREE,
+                                      (PWCHAR) filter.makeStringAndClear().getStr(), attributes, 0, &result.msg) ;
+#else
+    sal_Char * attributes [2] = { const_cast<sal_Char *>(LDAP_NO_ATTRS), NULL };
     LdapErrCode retCode = ldap_search_s(mConnection,
-                                      CONST_PCHAR_CAST rtl::OUStringToOString( mLdapDefinition.mBaseDN, RTL_TEXTENCODING_UTF8 ).getStr(),
+                                      rtl::OUStringToOString( mLdapDefinition.mBaseDN, RTL_TEXTENCODING_UTF8 ).getStr(),
                                       LDAP_SCOPE_SUBTREE,
-                                      CONST_PCHAR_CAST rtl::OUStringToOString( filter.makeStringAndClear(), RTL_TEXTENCODING_UTF8 ).getStr(), attributes, 0, &result.msg) ;
-
+                                      rtl::OUStringToOString( filter.makeStringAndClear(), RTL_TEXTENCODING_UTF8 ).getStr(), attributes, 0, &result.msg) ;
+#endif
     checkLdapReturnCode("FindUserDn", retCode,mConnection) ;
     rtl::OUString userDn ;
     LDAPMessage *entry = ldap_first_entry(mConnection, result.msg) ;
 
     if (entry != NULL)
     {
+#ifdef WNT
+        PWCHAR charsDn = ldap_get_dnW(mConnection, entry) ;
+
+        userDn = charsDn;
+        ldap_memfreeW(charsDn) ;
+#else
         sal_Char *charsDn = ldap_get_dn(mConnection, entry) ;
 
         userDn = rtl::OStringToOUString( charsDn, RTL_TEXTENCODING_UTF8 );
         ldap_memfree(charsDn) ;
+#endif
     }
     else
     {
diff --git a/extensions/source/config/ldap/wrapldapinclude.hxx b/extensions/source/config/ldap/wrapldapinclude.hxx
index fe2c7ea..7d8cf5c 100644
--- a/extensions/source/config/ldap/wrapldapinclude.hxx
+++ b/extensions/source/config/ldap/wrapldapinclude.hxx
@@ -25,6 +25,9 @@
 #ifdef WNT
 #include <windows.h>
 #include <winldap.h>
+#ifndef LDAP_NO_ATTRS
+#    define LDAP_NO_ATTRS L"1.1"
+#endif
 #define CONST_PCHAR_CAST (const PCHAR)
 #else // !defined WNT
 #include <ldap.h>
@@ -37,9 +40,6 @@
 #ifndef LDAP_CALL
 #    define LDAP_CALL
 #endif
-#ifndef LDAP_NO_ATTRS
-#    define LDAP_NO_ATTRS "1.1"
-#endif
 
 #ifdef WNT
 #pragma warning (pop)


More information about the Libreoffice-commits mailing list