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.

242 lines
5.5 KiB

  1. //---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1996
  5. //
  6. // File: getobj.cxx
  7. //
  8. // Contents: ADs Wrapper Function to mimic Visual Basic's GetObject
  9. //
  10. //
  11. // History: 11-15-95 krishnag Created.
  12. // 07-12-96 t-danal Added path validation.
  13. //
  14. //----------------------------------------------------------------------------
  15. #include "oleds.hxx"
  16. #pragma hdrstop
  17. extern PROUTER_ENTRY g_pRouterHead;
  18. extern CRITICAL_SECTION g_csRouterHeadCritSect;
  19. BOOL
  20. IsPathOfProgId(
  21. LPWSTR ProgId,
  22. LPWSTR Path
  23. );
  24. BOOL
  25. IsADsProgId(
  26. LPWSTR Path
  27. );
  28. //+---------------------------------------------------------------------------
  29. // Function: ADsGetObject
  30. //
  31. // Synopsis:
  32. //
  33. // Arguments: [LPWSTR lpszPathName]
  34. // [REFIID riid]
  35. // [void FAR * FAR * ppObject]
  36. //
  37. // Returns: HRESULT
  38. //
  39. // Modifies: -
  40. //
  41. // History: 07-12-95 t-danal Created.
  42. //
  43. //----------------------------------------------------------------------------
  44. HRESULT
  45. ADsGetObject(
  46. LPCWSTR lpszPathName,
  47. REFIID riid,
  48. void FAR * FAR * ppObject
  49. )
  50. {
  51. HRESULT hr;
  52. hr = GetObject((LPWSTR)lpszPathName,
  53. riid,
  54. ppObject,
  55. FALSE);
  56. RRETURN(hr);
  57. }
  58. //+---------------------------------------------------------------------------
  59. // Function: GetObject
  60. //
  61. // Synopsis:
  62. //
  63. // Arguments: [LPWSTR lpszPathName]
  64. // [REFIID riid]
  65. // [void FAR * FAR * ppObject]
  66. // [BOOL Generic]
  67. //
  68. // Returns: HRESULT
  69. //
  70. // Modifies: -
  71. //
  72. // History: 11-03-95 krishnag Created.
  73. // 07-12-95 t-danal Added router verification and
  74. // renamed from ADsGetObject
  75. //
  76. //----------------------------------------------------------------------------
  77. HRESULT
  78. GetObject(
  79. LPWSTR lpszPathName,
  80. REFIID riid,
  81. void FAR * FAR * ppObject,
  82. BOOL bRelative
  83. )
  84. {
  85. HRESULT hr;
  86. ULONG chEaten = 0L;
  87. IMoniker * pMoniker = NULL;
  88. IBindCtx *pbc = NULL;
  89. WCHAR* lpszProgId = NULL;
  90. if (!lpszPathName)
  91. return E_FAIL;
  92. lpszProgId = new WCHAR[wcslen(lpszPathName) + 1];
  93. if(!lpszProgId)
  94. {
  95. hr = E_OUTOFMEMORY;
  96. BAIL_IF_ERROR(hr);
  97. }
  98. hr = CopyADsProgId(
  99. (LPWSTR)lpszPathName,
  100. lpszProgId
  101. );
  102. BAIL_IF_ERROR( hr );
  103. //
  104. // Make sure the router has been initialized
  105. //
  106. EnterCriticalSection(&g_csRouterHeadCritSect);
  107. if (!g_pRouterHead) {
  108. g_pRouterHead = InitializeRouter();
  109. }
  110. LeaveCriticalSection(&g_csRouterHeadCritSect);
  111. PROUTER_ENTRY lpRouter = g_pRouterHead;
  112. //
  113. // Check if the Path matches with ProviderProgId or the Aliases
  114. //
  115. // ADs is a special case, and we also did not differentiate between uppercase and lowercase before, so keep this unchanged
  116. if(_wcsicmp(lpszProgId, L"ADs"))
  117. {
  118. while (lpRouter &&
  119. (!IsPathOfProgId(lpRouter->szProviderProgId, lpszProgId) &&
  120. !IsPathOfProgId(lpRouter->szAliases, lpszProgId)))
  121. lpRouter = lpRouter->pNext;
  122. if (!lpRouter)
  123. BAIL_IF_ERROR(hr=E_FAIL);
  124. }
  125. hr = CreateBindCtx(0, &pbc);
  126. BAIL_IF_ERROR(hr);
  127. hr = MkParseDisplayName(pbc,
  128. lpszPathName,
  129. &chEaten,
  130. &pMoniker);
  131. BAIL_IF_ERROR(hr);
  132. hr = pMoniker->BindToObject(pbc, NULL, riid, ppObject);
  133. BAIL_IF_ERROR(hr);
  134. cleanup:
  135. if (pbc) {
  136. pbc->Release();
  137. }
  138. if (pMoniker) {
  139. pMoniker->Release();
  140. }
  141. if(lpszProgId)
  142. {
  143. delete [] lpszProgId;
  144. lpszProgId = NULL;
  145. }
  146. RRETURN(hr);
  147. }
  148. //+---------------------------------------------------------------------------
  149. // Function: IsPathOfProgId
  150. //
  151. // Synopsis: Checks if an OLE Path corresponds to given ProgId.
  152. // Path must be @Foo! or Foo: style.
  153. //
  154. // Arguments: [LPWSTR ProgId]
  155. // [LPWSTR Path]
  156. //
  157. // Returns: BOOL
  158. //
  159. // Modifies: -
  160. //
  161. // History: 07-12-95 t-danal Created
  162. //
  163. //----------------------------------------------------------------------------
  164. BOOL
  165. IsPathOfProgId(
  166. LPWSTR ProgId,
  167. LPWSTR Path
  168. )
  169. {
  170. if (!ProgId || !Path) // Just in case...
  171. return FALSE;
  172. if(wcscmp(ProgId, Path))
  173. return FALSE;
  174. return TRUE;
  175. }
  176. //+---------------------------------------------------------------------------
  177. // Function: IsADsProgId
  178. //
  179. // Synopsis: Checks if the ProgIds of paths is ADs progid.
  180. // Paths must be @Foo! or Foo: style.
  181. //
  182. // Arguments: [LPWSTR Path]
  183. //
  184. // Returns: BOOL
  185. //
  186. // Modifies: -
  187. //
  188. // History: 07-12-95 t-danal Created
  189. //
  190. //----------------------------------------------------------------------------
  191. BOOL
  192. IsADsProgId(
  193. LPWSTR Path
  194. )
  195. {
  196. int cch = 0;
  197. LPWSTR pEnd;
  198. if (!Path)
  199. return FALSE;
  200. if (*Path == L'@')
  201. Path++;
  202. pEnd = Path;
  203. while (*pEnd &&
  204. *pEnd != L'!' &&
  205. *pEnd != L':') {
  206. pEnd++;
  207. }
  208. if (_wcsnicmp(L"ADS", Path, (int)(pEnd-Path)))
  209. return FALSE;
  210. return TRUE;
  211. }