ldaputils.hpp 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /*##############################################################################
  2. HPCC SYSTEMS software Copyright (C) 2015 HPCC Systems.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. ############################################################################## */
  13. #ifndef __LDAPUTILS_HPP
  14. #define __LDAPUTILS_HPP
  15. #include "ldapconnection.hpp"
  16. #ifdef _WIN32
  17. #include <windows.h>
  18. #include <winldap.h>
  19. #include <winber.h>
  20. #include <rpc.h>
  21. #include <rpcdce.h>
  22. #include "dsgetdc.h"
  23. #include <lm.h>
  24. #else
  25. #define LDAP_DEPRECATED 1
  26. #include <ldap_cdefs.h>
  27. #include <ldap.h>
  28. #endif
  29. class LdapUtils
  30. {
  31. public:
  32. static LDAP* LdapInit(const char* protocol, const char* host, int port, int secure_port, bool throwOnError = true);
  33. static int LdapSimpleBind(LDAP* ld, int ldapTimeout, char* userdn, char* password);
  34. // userdn is required for ldap_simple_bind_s, not really necessary for ldap_bind_s.
  35. static int LdapBind(LDAP* ld, int ldapTimeout, const char* domain, const char* username, const char* password, const char* userdn, LdapServerType server_type, const char* method="kerberos");
  36. static void bin2str(MemoryBuffer& from, StringBuffer& to);
  37. static LDAP* ldapInitAndSimpleBind(const char* ldapserver, const char* userDN, const char* pwd, const char* ldapprotocol, int ldapport, int timeout, int * err);
  38. static int getServerInfo(const char* ldapserver, const char * user, const char *pwd, const char* ldapprotocol, int ldapport, StringBuffer& domainDN, LdapServerType& stype, const char* domainname, int timeout);
  39. static void normalizeDn(const char* dn, const char* basedn, StringBuffer& dnbuf);
  40. static bool containsBasedn(const char* str);
  41. static void cleanupDn(const char* dn, StringBuffer& dnbuf);
  42. static bool getDcName(const char* domain, StringBuffer& dc);
  43. static void getName(const char* dn, StringBuffer& name);
  44. };
  45. #endif