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.

143 lines
2.8 KiB

  1. //---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1996
  5. //
  6. // File: cprov.cxx
  7. //
  8. // Contents: LDAP Provider Object Class Factory Code
  9. //
  10. // CLDAPProvider
  11. //
  12. // History: 06-15-96 yihsins Created.
  13. //
  14. //----------------------------------------------------------------------------
  15. #include "ldap.hxx"
  16. #pragma hdrstop
  17. extern ULONG g_ulLocks;
  18. extern CRITICAL_SECTION g_LockCritSect;
  19. // Class CLDAPProvider
  20. CLDAPProvider::CLDAPProvider()
  21. {
  22. EnterCriticalSection(&g_LockCritSect);
  23. g_ulLocks++;
  24. LeaveCriticalSection(&g_LockCritSect);
  25. ENLIST_TRACKING(CLDAPProvider);
  26. }
  27. HRESULT
  28. CLDAPProvider::Create(CLDAPProvider FAR * FAR * ppProvider)
  29. {
  30. CLDAPProvider FAR * pProvider = NULL;
  31. HRESULT hr = S_OK;
  32. //Create the Provider Object
  33. pProvider = new CLDAPProvider();
  34. if (pProvider == NULL) {
  35. RRETURN_EXP_IF_ERR(E_OUTOFMEMORY);
  36. }
  37. if (FAILED(hr)) {
  38. delete pProvider;
  39. RRETURN(hr);
  40. }
  41. *ppProvider = pProvider;
  42. RRETURN_EXP_IF_ERR(hr);
  43. }
  44. CLDAPProvider::~CLDAPProvider( )
  45. {
  46. EnterCriticalSection(&g_LockCritSect);
  47. g_ulLocks--;
  48. LeaveCriticalSection(&g_LockCritSect);
  49. }
  50. STDMETHODIMP
  51. CLDAPProvider::QueryInterface(REFIID iid, LPVOID FAR* ppv)
  52. {
  53. if (ppv == NULL) {
  54. RRETURN(E_POINTER);
  55. }
  56. if (IsEqualIID(iid, IID_IUnknown))
  57. {
  58. *ppv = this;
  59. }
  60. else if (IsEqualIID(iid, IID_IParseDisplayName))
  61. {
  62. *ppv = (IADs FAR *) this;
  63. }
  64. else
  65. {
  66. *ppv = NULL;
  67. return E_NOINTERFACE;
  68. }
  69. AddRef();
  70. return NOERROR;
  71. }
  72. STDMETHODIMP
  73. CLDAPProvider::ParseDisplayName(IBindCtx* pbc, TCHAR* szDisplayName, ULONG* pchEaten, IMoniker** ppmk)
  74. {
  75. HRESULT hr;
  76. *ppmk = NULL;
  77. if (pchEaten != NULL){
  78. *pchEaten = 0;
  79. }
  80. hr = ResolvePathName(
  81. pbc,
  82. szDisplayName,
  83. pchEaten,
  84. ppmk
  85. );
  86. RRETURN_EXP_IF_ERR(hr);
  87. }
  88. HRESULT
  89. CLDAPProvider::ResolvePathName(IBindCtx* pbc,
  90. TCHAR* szDisplayName,
  91. ULONG* pchEaten,
  92. IMoniker** ppmk
  93. )
  94. {
  95. HRESULT hr;
  96. LPUNKNOWN pUnknown = NULL;
  97. CCredentials Credentials;
  98. if (!pchEaten) {
  99. BAIL_IF_ERROR(hr = E_INVALIDARG);
  100. }
  101. *pchEaten = 0;
  102. hr = GetObject(
  103. szDisplayName,
  104. Credentials,
  105. (LPVOID *)&pUnknown
  106. );
  107. BAIL_IF_ERROR(hr);
  108. hr = CreatePointerMoniker(pUnknown, ppmk);
  109. BAIL_IF_ERROR(hr);
  110. *pchEaten += _tcslen(szDisplayName);
  111. cleanup:
  112. if (pUnknown) {
  113. pUnknown->Release();
  114. }
  115. RRETURN_EXP_IF_ERR(hr);
  116. }