Просмотр исходного кода

Merge pull request #7833 from RussWhitehead/ldapBreak

HPCC-14293 Client Tools build break on LDAP component

Reviewed-by: Gavin Halliday <ghalliday@hpccsystems.com>
Gavin Halliday 9 лет назад
Родитель
Сommit
9025730bb4

+ 17 - 10
system/security/LdapSecurity/ldapconnection.cpp

@@ -60,7 +60,7 @@
 
 const char* UserFieldNames[] = { "@id", "@name", "@fullname", "@passwordexpiration" };
 
-extern __declspec(dllimport) const char* getUserFieldNames(UserField field)
+const char* getUserFieldNames(UserField field)
 {
     if (field < UFterm)
         return UserFieldNames[field];
@@ -69,7 +69,7 @@ extern __declspec(dllimport) const char* getUserFieldNames(UserField field)
 
 const char* GroupFieldNames[] = { "@name", "@managedby", "@desc" };
 
-extern __declspec(dllimport) const char* getGroupFieldNames(GroupField field)
+const char* getGroupFieldNames(GroupField field)
 {
     if (field < GFterm)
         return GroupFieldNames[field];
@@ -78,7 +78,7 @@ extern __declspec(dllimport) const char* getGroupFieldNames(GroupField field)
 
 const char* ResourceFieldNames[] = { "@name", "@desc" };
 
-extern __declspec(dllimport) const char* getResourceFieldNames(ResourceField field)
+const char* getResourceFieldNames(ResourceField field)
 {
     if (field < RFterm)
         return ResourceFieldNames[field];
@@ -1130,10 +1130,13 @@ private:
                 }
             }
 
-            int l_errcode;
+            unsigned long l_errcode;
             LDAPControl **  returnedCtrls = NULL;
+#ifdef _WIN32
             rc = ldap_parse_result(m_pLdapConn, m_pPageBlock, &l_errcode, NULL, NULL, NULL, &returnedCtrls, false);
-
+#else
+            rc = ldap_parse_result(m_pLdapConn, m_pPageBlock, (int*)&l_errcode, NULL, NULL, NULL, &returnedCtrls, false);
+#endif
             if (m_pCookie)
             {
                 ber_bvfree(m_pCookie);
@@ -1147,8 +1150,12 @@ private:
             }
 
             pageCtrlMem.setRetControls(returnedCtrls);
-            int totCount;
+            unsigned long totCount;
+#ifdef _WIN32
             rc = ldap_parse_page_control(m_pLdapConn, returnedCtrls, &totCount, &m_pCookie);//sets cookie for next call to ldap_create_page_control()
+#else
+            rc = ldap_parse_page_control(m_pLdapConn, returnedCtrls, (int*)&totCount, &m_pCookie);//sets cookie for next call to ldap_create_page_control()
+#endif
             if (rc != LDAP_SUCCESS)
             {
                 int err = GetLastError();
@@ -2485,7 +2492,7 @@ public:
         Owned<ILdapConnection> lconn = m_connections->getConnection();
         LDAP* ld = ((CLdapConnection*)lconn.get())->getLd();
 
-        int rc = LDAP_COMPARE_EXT_S(ld, (char*)groupdn, (char*)fldname, (char*)userdn,0,0,0);
+        int rc = LDAP_COMPARE_EXT_S(ld, (const char*)groupdn, (const char*)fldname, (const char*)userdn,0,0,0);
         if(rc == LDAP_COMPARE_TRUE)
             return true;
         else
@@ -2634,10 +2641,10 @@ public:
             attrs[ind++] = &loginshell_attr;
             Owned<ILdapConnection> lconn = m_connections->getConnection();
             LDAP* ld = ((CLdapConnection*)lconn.get())->getLd();
-            int compresult = LDAP_COMPARE_EXT_S(ld, (char*)userdn.str(), (char*)"objectclass", (char*)"posixAccount",0,0,0);
+            int compresult = LDAP_COMPARE_EXT_S(ld, (const char*)userdn.str(), (const char*)"objectclass", (const char*)"posixAccount",0,0,0);
             if(compresult != LDAP_COMPARE_TRUE)
                 attrs[ind++] = &oc_attr;
-            compresult = LDAP_COMPARE_EXT_S(ld, (char*)userdn.str(), (char*)"objectclass", (char*)"shadowAccount",0,0,0);
+            compresult = LDAP_COMPARE_EXT_S(ld, (const char*)userdn.str(), (const char*)"objectclass", (const char*)"shadowAccount",0,0,0);
             if(compresult != LDAP_COMPARE_TRUE)
                 attrs[ind++] = &oc1_attr;
             attrs[ind] = NULL;
@@ -2650,7 +2657,7 @@ public:
 
             Owned<ILdapConnection> lconn = m_connections->getConnection();
             LDAP* ld = ((CLdapConnection*)lconn.get())->getLd();
-            int compresult = LDAP_COMPARE_EXT_S(ld, (char*)userdn.str(), (char*)"objectclass", (char*)"posixAccount",0,0,0);
+            int compresult = LDAP_COMPARE_EXT_S(ld, (const char*)userdn.str(), (const char*)"objectclass", (const char*)"posixAccount",0,0,0);
             if(compresult != LDAP_COMPARE_TRUE)
             {
                 rc = LDAP_SUCCESS;

+ 39 - 7
system/security/LdapSecurity/ldapconnection.hpp

@@ -40,11 +40,43 @@
 #endif
 
 #ifdef _WIN32
-    #define LDAP_COMPARE_EXT_S(ld,dn,attr,bval,svrctrls,clientctrls,msgnum) ldap_compare_ext_s(ld,(char*)dn,(char*)attr,(struct berval *)bval,svrctrls,clientctrls,msgnum)
-    #define LDAP_UNBIND(ld) ldap_unbind(ld)
+    #ifndef LDAPSECURITY_EXPORTS
+        #define LDAPSECURITY_API __declspec(dllimport)
+    #else
+        #define LDAPSECURITY_API __declspec(dllexport)
+    #endif//LDAPSECURITY_EXPORTS
 #else
-    #define LDAP_COMPARE_EXT_S(ld,dn,attr,bval,svrctrls,clientctrls,msgnum) ldap_compare_ext_s(ld,(char*)dn,(char*)attr,(struct berval *)bval,svrctrls,clientctrls)
-    #define LDAP_UNBIND(ld) ldap_unbind_ext(ld,0,0)
+    #define LDAPSECURITY_API
+#endif //_WIN32
+
+#ifdef _WIN32
+/*from Winldap.h
+WINLDAPAPI ULONG LDAPAPI ldap_compare_ext_s(
+        LDAP *ld,
+        const PCHAR dn,
+        const PCHAR Attr,
+        const PCHAR Value,            // either value or Data is not null, not both
+        struct berval   *Data,
+        PLDAPControlA   *ServerControls,
+        PLDAPControlA   *ClientControls
+        );
+*/
+    #define LDAP_COMPARE_EXT_S(ld,dn,attr,bval,data,svrctrls,clientctrls) ldap_compare_ext_s(ld,(const PCHAR)dn,(const PCHAR)attr,(const PCHAR)bval,(struct berval *)data,svrctrls,clientctrls)
+    #define LDAP_UNBIND(ld)     ldap_unbind(ld)
+    #define LDAP_INIT(ld,uri)   ldap_init(ld, uri);
+#else
+/* from openLDAP ldap.h
+ldap_compare_ext_s LDAP_P((
+    LDAP            *ld,
+    LDAP_CONST char *dn,
+    LDAP_CONST char *attr,
+    struct berval   *bvalue,
+    LDAPControl    **serverctrls,
+    LDAPControl    **clientctrls ));
+*/
+    #define LDAP_COMPARE_EXT_S(ld,dn,attr,bval,svrctrls,clientctrls,msgnum) ldap_compare_ext_s(ld,(const char*)dn,(const char*)attr,(struct berval *)bval,svrctrls,clientctrls)
+    #define LDAP_UNBIND(ld)     ldap_unbind_ext(ld,0,0)
+    #define LDAP_INIT(ld,uri)   ldap_initialize(ld, uri);
 #endif
 
 #ifdef _WIN32
@@ -108,9 +140,9 @@ enum ResourceField
     RFnumeric = 1024
 };
 
-extern __declspec(dllimport) const char* getUserFieldNames(UserField feild);
-extern __declspec(dllimport) const char* getGroupFieldNames(GroupField feild);
-extern __declspec(dllimport) const char* getResourceFieldNames(ResourceField feild);
+extern LDAPSECURITY_API  const char* getUserFieldNames(UserField feild);
+extern LDAPSECURITY_API  const char* getGroupFieldNames(GroupField feild);
+extern LDAPSECURITY_API  const char* getResourceFieldNames(ResourceField feild);
 
 typedef IIteratorOf<IPropertyTree> ISecItemIterator;
 

+ 2 - 2
system/security/LdapSecurity/ldaputils.cpp

@@ -68,7 +68,7 @@ LDAP* LdapUtils::LdapInit(const char* protocol, const char* host, int port, int
         StringBuffer uri("ldaps://");
         uri.appendf("%s:%d", host, secure_port);
         DBGLOG("connecting to %s", uri.str());
-        int rc = ldap_initialize(&ld, uri.str());
+        int rc = LDAP_INIT(&ld, uri.str());
         if(rc != LDAP_SUCCESS)
         {
             DBGLOG("ldap_initialize error %s", ldap_err2string(rc));
@@ -84,7 +84,7 @@ LDAP* LdapUtils::LdapInit(const char* protocol, const char* host, int port, int
         StringBuffer uri;
         uri.appendf("ldap://%s:%d", host, port);
         DBGLOG("connecting to %s", uri.str());
-        int rc = ldap_initialize(&ld, uri.str());
+        int rc = LDAP_INIT(&ld, uri.str());
         if(rc != LDAP_SUCCESS)
         {
             throw MakeStringException(-1, "ldap_initialize(%s) error %s", uri.str(), ldap_err2string(rc));