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.

121 lines
2.9 KiB

  1. ///////////////////////////////////////////////////////////////////////////////
  2. //
  3. // FILE
  4. //
  5. // ldapcxn.h
  6. //
  7. // SYNOPSIS
  8. //
  9. // Declares the class LDAPConnection.
  10. //
  11. // MODIFICATION HISTORY
  12. //
  13. // 05/07/1998 Original version.
  14. // 06/10/1998 Added getHost() method.
  15. // 08/25/1998 Added 'base' property.
  16. // 09/16/1998 Perform access check after bind.
  17. // 04/14/1999 Specify domain and server when opening a connection.
  18. // 09/14/1999 Add SEARCH_TIMEOUT.
  19. //
  20. ///////////////////////////////////////////////////////////////////////////////
  21. #ifndef _LDAPCXN_H_
  22. #define _LDAPCXN_H_
  23. #if _MSC_VER >= 1000
  24. #pragma once
  25. #endif
  26. #include <nocopy.h>
  27. #include <winldap.h>
  28. class LDAPServer;
  29. ///////////////////////////////////////////////////////////////////////////////
  30. //
  31. // CLASS
  32. //
  33. // LDAPConnection
  34. //
  35. // DESCRIPTION
  36. //
  37. // This class allows multiple clients to share a single LDAP connection.
  38. // The connection is reference counted and will be automatically unbound
  39. // when the last reference is released. It also contains a disabled flag
  40. // that any client can use to indicate that the connection has gone bad.
  41. //
  42. ///////////////////////////////////////////////////////////////////////////////
  43. class LDAPConnection
  44. : NonCopyable
  45. {
  46. public:
  47. void AddRef() throw ()
  48. { InterlockedIncrement(&refCount); }
  49. void Release() throw ();
  50. void disable() throw ()
  51. { disabled = TRUE; }
  52. BOOL isDisabled() const throw ()
  53. { return disabled; }
  54. PLDAP get() const throw ()
  55. { return connection; }
  56. PCWSTR getBase() const throw ()
  57. { return base; }
  58. PCSTR getHost() const throw ()
  59. { return connection->ld_host; }
  60. operator PLDAP() const throw ()
  61. { return connection; }
  62. static DWORD createInstance(
  63. PCWSTR domain,
  64. PCWSTR server,
  65. LDAPConnection** cxn
  66. ) throw ();
  67. static LDAP_TIMEVAL SEARCH_TIMEOUT;
  68. void TraceFailure(
  69. PCSTR functionName,
  70. ULONG errorCode
  71. );
  72. protected:
  73. LDAPConnection(PLDAP ld) throw ()
  74. : connection(ld),
  75. refCount(1),
  76. disabled(FALSE),
  77. base(NULL)
  78. { }
  79. ~LDAPConnection() throw ()
  80. {
  81. delete[] base;
  82. ldap_unbind(connection);
  83. }
  84. // Verifies that we have sufficient access to the remote server.
  85. DWORD checkAccess() throw ();
  86. // Initializes 'base' by reading the defaultNamingContext from the RootDSE.
  87. DWORD readRootDSE() throw ();
  88. PLDAP connection;
  89. LONG refCount;
  90. BOOL disabled;
  91. PWSTR base; // Base DN of this connection. Useful for doing
  92. // subtree searches of the entire server.
  93. };
  94. void IASTraceLdapFailure(
  95. PCSTR functionName,
  96. ULONG errorCode,
  97. LDAP* connection = NULL
  98. );
  99. #endif // _LDAPCXN_H_