Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

128 lines
3.2 KiB

  1. //+------------------------------------------------------------
  2. //
  3. // Copyright (C) 2001, Microsoft Corporation
  4. //
  5. // File: pldapwrap.cpp
  6. //
  7. // Contents: CPLDAPWrap methods
  8. //
  9. // Classes: CPLDAPWrap
  10. //
  11. // Functions:
  12. // CPLDAPWrap::CPLDAPWrap
  13. //
  14. // History:
  15. // jstamerj 2001/11/28 15:10:11: Created.
  16. //
  17. //-------------------------------------------------------------
  18. #include "precomp.h"
  19. //+------------------------------------------------------------
  20. //
  21. // Function: CPLDAPWrap::CPLDAPWrap
  22. //
  23. // Synopsis: Opens a wldap32 connection to a server
  24. //
  25. // Arguments:
  26. // pszHost: FQDN matching the DNS A Record of an LDAP server
  27. // dwPort: Server LDAP TCP port #
  28. //
  29. // Returns: Nothing. m_pldap will be NULL if there is an error.
  30. //
  31. // History:
  32. // jstamerj 2001/11/28 15:10:51: Created.
  33. //
  34. //-------------------------------------------------------------
  35. CPLDAPWrap::CPLDAPWrap(
  36. ISMTPServerEx *pISMTPServerEx,
  37. LPSTR pszHost,
  38. DWORD dwPort)
  39. {
  40. PLDAP pldap = NULL;
  41. ULONG ulLdapOn = (ULONG)((ULONG_PTR)LDAP_OPT_ON);
  42. ULONG ulLdapRet = LDAP_SUCCESS;
  43. CatFunctEnterEx((LPARAM)this, "CPLDAPWrap::CPLDAPWrap");
  44. m_dwSig = SIGNATURE_CPLDAPWRAP;
  45. m_pldap = NULL;
  46. //
  47. // Use ldap_init so that we can set ldap options before connecting
  48. //
  49. pldap = ldap_init(
  50. pszHost,
  51. dwPort);
  52. if(pldap == NULL)
  53. {
  54. ulLdapRet = LdapGetLastError();
  55. ErrorTrace((LPARAM)this,
  56. "ldap_init returned NULL, gle=0x%08lx, lgle=0x%08lx",
  57. GetLastError(),
  58. LdapGetLastError());
  59. LogLdapError(
  60. pISMTPServerEx,
  61. ulLdapRet,
  62. pszHost,
  63. "ldap_init");
  64. goto CLEANUP;
  65. }
  66. //
  67. // Tell wldap32 to lookup A records only. By default, wldap32
  68. // supports domain names, so it looksup DNS SRV records. Since we
  69. // always have a FQDN of a server, this is wasteful. Set the
  70. // AREC_EXCLUSIVE option so that we only do A record lookups.
  71. //
  72. ulLdapRet = ldap_set_option(
  73. pldap,
  74. LDAP_OPT_AREC_EXCLUSIVE,
  75. (PVOID) &ulLdapOn);
  76. if(ulLdapRet != LDAP_SUCCESS)
  77. {
  78. //
  79. // Trace the error, but continue anyway
  80. //
  81. ErrorTrace((LPARAM)this,
  82. "ldap_set_option(AREC_EXCLUSIVE, ON) failed 0x%08lx",
  83. ulLdapRet);
  84. LogLdapError(
  85. pISMTPServerEx,
  86. ulLdapRet,
  87. pszHost,
  88. "ldap_set_option(LDAP_OPT_AREC_EXCLUSIVE)");
  89. }
  90. //
  91. // Now that the options are setup, connect.
  92. //
  93. ulLdapRet = ldap_connect(pldap, NULL);
  94. if(ulLdapRet != LDAP_SUCCESS)
  95. {
  96. ErrorTrace((LPARAM)this,
  97. "ldap_connect to server %s failed, error 0x%08lx",
  98. pszHost,
  99. ulLdapRet);
  100. LogLdapError(
  101. pISMTPServerEx,
  102. ulLdapRet,
  103. pszHost,
  104. "ldap_connect");
  105. goto CLEANUP;
  106. }
  107. //
  108. // Success! Set m_pldap
  109. //
  110. m_pldap = pldap;
  111. pldap = NULL;
  112. CLEANUP:
  113. if(pldap)
  114. ldap_unbind(pldap);
  115. }