Source code of Windows XP (NT5)
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.

110 lines
2.6 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. protected:
  69. LDAPConnection(PLDAP ld) throw ()
  70. : connection(ld),
  71. refCount(1),
  72. disabled(FALSE),
  73. base(NULL)
  74. { }
  75. ~LDAPConnection() throw ()
  76. {
  77. delete[] base;
  78. ldap_unbind(connection);
  79. }
  80. // Verifies that we have sufficient access to the remote server.
  81. DWORD checkAccess() throw ();
  82. // Initializes 'base' by reading the defaultNamingContext from the RootDSE.
  83. DWORD readRootDSE() throw ();
  84. PLDAP connection;
  85. LONG refCount;
  86. BOOL disabled;
  87. PWSTR base; // Base DN of this connection. Useful for doing
  88. // subtree searches of the entire server.
  89. };
  90. #endif // _LDAPCXN_H_