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.

207 lines
4.3 KiB

  1. //---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1996
  5. //
  6. // File: openobj.cxx
  7. //
  8. // Contents: ADs Wrapper Function to open an Active Directory object
  9. //
  10. //
  11. // History: 11-15-95 krishnag Created.
  12. //
  13. //----------------------------------------------------------------------------
  14. #include "oleds.hxx"
  15. #pragma hdrstop
  16. extern PROUTER_ENTRY g_pRouterHead;
  17. extern CRITICAL_SECTION g_csRouterHeadCritSect;
  18. //+---------------------------------------------------------------------------
  19. // Function: ADsOpenObject
  20. //
  21. // Synopsis:
  22. //
  23. // Arguments: [LPWSTR lpszPathName]
  24. // [LPWSTR lpszUserName]
  25. // [LPWSTR lpszPassword]
  26. // [REFIID riid]
  27. // [void FAR * FAR * ppObject]
  28. //
  29. // Returns: HRESULT
  30. //
  31. // Modifies: -
  32. //
  33. // History: 07-12-96 krishnag Created.
  34. //
  35. //----------------------------------------------------------------------------
  36. HRESULT
  37. ADsOpenObject(
  38. LPCWSTR lpszPathName,
  39. LPCWSTR lpszUserName,
  40. LPCWSTR lpszPassword,
  41. DWORD dwReserved,
  42. REFIID riid,
  43. void FAR * FAR * ppObject
  44. )
  45. {
  46. IADsOpenDSObject FAR * pNamespace = NULL;
  47. IDispatch FAR * pDispatch = NULL;
  48. HRESULT hr = S_OK;
  49. GUID NamespaceClsid;
  50. WCHAR lpszProgId[MAX_PATH];
  51. hr = CopyADsProgId(
  52. (LPWSTR)lpszPathName,
  53. lpszProgId
  54. );
  55. BAIL_ON_FAILURE( hr );
  56. hr = ADsGetCLSIDFromProgID(
  57. lpszProgId,
  58. &NamespaceClsid
  59. );
  60. BAIL_ON_FAILURE( hr );
  61. hr = CoCreateInstance(
  62. NamespaceClsid,
  63. NULL,
  64. CLSCTX_INPROC_SERVER,
  65. IID_IADsOpenDSObject,
  66. (void **)&pNamespace
  67. );
  68. BAIL_ON_FAILURE( hr );
  69. hr = pNamespace->OpenDSObject(
  70. (LPWSTR)lpszPathName,
  71. (LPWSTR)lpszUserName,
  72. (LPWSTR)lpszPassword,
  73. (long)dwReserved,
  74. &pDispatch
  75. );
  76. BAIL_ON_FAILURE( hr );
  77. hr = pDispatch->QueryInterface(
  78. riid,
  79. ppObject
  80. );
  81. error:
  82. if( pDispatch ) {
  83. pDispatch->Release();
  84. }
  85. if( pNamespace ) {
  86. pNamespace->Release();
  87. }
  88. RRETURN( hr );
  89. }
  90. //+---------------------------------------------------------------------------
  91. // Function: CopyADsProgId
  92. //
  93. // Synopsis:
  94. //
  95. //
  96. // Arguments: [LPWSTR Path]
  97. // [LPWSTR szProgId]
  98. //
  99. // Returns: HRESULT
  100. //
  101. // Modifies: -
  102. //
  103. // History: 09-16-96 krishnag Created
  104. //
  105. //----------------------------------------------------------------------------
  106. HRESULT
  107. CopyADsProgId(
  108. LPWSTR Path,
  109. LPWSTR szProgId
  110. )
  111. {
  112. LPWSTR pChar = NULL;
  113. if( !Path )
  114. return E_FAIL;
  115. pChar = szProgId;
  116. if( *Path == L'@' ) {
  117. while (*Path != L'!' && *Path != L'\0') {
  118. *pChar = *Path;
  119. pChar++;
  120. Path++;
  121. }
  122. if( *Path == L'\0' ) {
  123. //
  124. // couldn't find the terminating ! for the ProgID
  125. //
  126. return( E_FAIL );
  127. }
  128. }else {
  129. while (*Path != L':' && *Path != L'\0') {
  130. *pChar = *Path;
  131. pChar++;
  132. Path++;
  133. }
  134. if( *Path == L'\0' ) {
  135. //
  136. // couldn't find the terminating : for the ProgID
  137. //
  138. return( E_FAIL );
  139. }
  140. }
  141. *pChar = L'\0';
  142. return S_OK;
  143. }
  144. HRESULT
  145. ADsGetCLSIDFromProgID(
  146. LPWSTR pszProgId,
  147. GUID * pClsid
  148. )
  149. {
  150. //
  151. // Make sure the router has been initialized
  152. //
  153. EnterCriticalSection(&g_csRouterHeadCritSect);
  154. if (!g_pRouterHead) {
  155. g_pRouterHead = InitializeRouter();
  156. }
  157. LeaveCriticalSection(&g_csRouterHeadCritSect);
  158. PROUTER_ENTRY lpRouter = g_pRouterHead;
  159. while (lpRouter){
  160. if (!wcscmp(lpRouter->szProviderProgId, pszProgId)) {
  161. memcpy(pClsid, lpRouter->pNamespaceClsid, sizeof(CLSID));
  162. RRETURN(S_OK);
  163. }
  164. else if (!wcscmp(lpRouter->szAliases, pszProgId)) {
  165. //
  166. // Check Aliases
  167. //
  168. memcpy(pClsid, lpRouter->pNamespaceClsid, sizeof(CLSID));
  169. RRETURN(S_OK);
  170. }
  171. lpRouter = lpRouter->pNext;
  172. }
  173. RRETURN( E_ADS_BAD_PATHNAME );
  174. }