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.

219 lines
5.7 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1993.
  5. //
  6. // File: libmain.cxx
  7. //
  8. // Contents: LibMain for ADs.dll
  9. //
  10. // Functions: LibMain, DllGetClassObject
  11. //
  12. // History: 25-Oct-94 KrishnaG Created.
  13. //
  14. //----------------------------------------------------------------------------
  15. #include "oleds.hxx"
  16. #pragma hdrstop
  17. LPCWSTR lpszTopLevel = L"SOFTWARE\\Microsoft\\ADs";
  18. LPCWSTR lpszProviders = L"Providers";
  19. PROUTER_ENTRY
  20. InitializeRouter()
  21. {
  22. HKEY hTopLevelKey = NULL;
  23. HKEY hMapKey = NULL;
  24. HKEY hProviderKey = NULL;
  25. DWORD dwIndex = 0;
  26. WCHAR lpszProvider[MAX_PATH];
  27. DWORD dwchProvider = 0;
  28. WCHAR lpszNamespace[MAX_PATH];
  29. WCHAR lpszAliases[MAX_PATH];
  30. DWORD dwchNamespace = 0;
  31. DWORD dwchAliases = 0;
  32. PROUTER_ENTRY pRouterHead = NULL, pRouterEntry = NULL;
  33. LPCLSID pclsid = NULL;
  34. HRESULT hr;
  35. if (RegOpenKeyEx(HKEY_LOCAL_MACHINE,
  36. lpszTopLevel,
  37. 0,
  38. KEY_READ,
  39. &hTopLevelKey
  40. ) != ERROR_SUCCESS)
  41. {
  42. // must succeed
  43. goto CleanupAndExit;
  44. }
  45. if (RegOpenKeyEx(hTopLevelKey,
  46. lpszProviders,
  47. 0,
  48. KEY_READ,
  49. &hMapKey
  50. ) != ERROR_SUCCESS)
  51. {
  52. // must succeed; at least one provider from ADSI
  53. goto CleanupAndExit;
  54. }
  55. memset(lpszProvider, 0, sizeof(lpszProvider));
  56. //
  57. // Size has to be in number of TCHARS not in bytes.
  58. //
  59. dwchProvider = sizeof(lpszProvider)/sizeof(WCHAR);
  60. while(RegEnumKeyEx(hMapKey,
  61. dwIndex++, // + index even if last 1 bail out in mid loop
  62. lpszProvider,
  63. &dwchProvider,
  64. NULL,
  65. NULL,
  66. NULL,
  67. NULL
  68. ) == ERROR_SUCCESS)
  69. {
  70. //
  71. // Read namespace
  72. //
  73. if (RegOpenKeyEx(hMapKey,
  74. lpszProvider,
  75. 0,
  76. KEY_READ,
  77. &hProviderKey
  78. ) != ERROR_SUCCESS)
  79. {
  80. //
  81. // if cannot read registry of 1 provider, continue with others;
  82. // especially since providers can be written outside ADSI
  83. //
  84. memset(lpszProvider, 0, sizeof(lpszProvider));
  85. dwchProvider = sizeof(lpszProvider)/sizeof(WCHAR);
  86. continue;
  87. }
  88. memset(lpszNamespace, 0, sizeof(lpszNamespace));
  89. dwchNamespace = sizeof(lpszNamespace);
  90. if (RegQueryValueEx(hProviderKey,
  91. NULL,
  92. NULL,
  93. NULL,
  94. (LPBYTE) lpszNamespace,
  95. &dwchNamespace
  96. ) != ERROR_SUCCESS)
  97. {
  98. //
  99. // if cannot read registry of 1 provider, continue with others;
  100. // especially since providers can be written outside ADSI
  101. //
  102. RegCloseKey(hProviderKey);
  103. hProviderKey = NULL;
  104. memset(lpszProvider, 0, sizeof(lpszProvider));
  105. dwchProvider = sizeof(lpszProvider)/sizeof(WCHAR);
  106. continue;
  107. }
  108. //
  109. // If Aliases value name is defined, get the values
  110. //
  111. memset(lpszAliases, 0, sizeof(lpszAliases));
  112. dwchAliases = sizeof(lpszAliases);
  113. RegQueryValueEx(hProviderKey,
  114. L"Aliases",
  115. NULL,
  116. NULL,
  117. (LPBYTE) lpszAliases,
  118. &dwchAliases
  119. );
  120. RegCloseKey(hProviderKey);
  121. hProviderKey = NULL;
  122. //
  123. // Generate CLSID from the ProgID
  124. //
  125. pclsid = (LPCLSID)LocalAlloc(LPTR,
  126. sizeof(CLSID));
  127. if (!pclsid) {
  128. //
  129. // if cannot read registry of 1 provider, continue with others;
  130. // especially since providers can be written outside ADSI
  131. //
  132. memset(lpszProvider, 0, sizeof(lpszProvider));
  133. dwchProvider = sizeof(lpszProvider)/sizeof(WCHAR);
  134. continue;
  135. }
  136. hr = CLSIDFromProgID(lpszNamespace, pclsid);
  137. if (FAILED(hr)) {
  138. LocalFree(pclsid);
  139. } else {
  140. if (pRouterEntry = (PROUTER_ENTRY)LocalAlloc(LPTR,
  141. sizeof(ROUTER_ENTRY))){
  142. wcscpy(pRouterEntry->szProviderProgId, lpszProvider);
  143. wcscpy(pRouterEntry->szNamespaceProgId, lpszNamespace);
  144. wcscpy(pRouterEntry->szAliases, lpszAliases);
  145. pRouterEntry->pNamespaceClsid = pclsid;
  146. pRouterEntry->pNext = pRouterHead;
  147. pRouterHead = pRouterEntry;
  148. }
  149. }
  150. memset(lpszProvider, 0, sizeof(lpszProvider));
  151. dwchProvider = sizeof(lpszProvider)/sizeof(WCHAR);
  152. }
  153. CleanupAndExit:
  154. if (hProviderKey) {
  155. RegCloseKey(hProviderKey);
  156. }
  157. if (hMapKey) {
  158. RegCloseKey(hMapKey);
  159. }
  160. if (hTopLevelKey) {
  161. RegCloseKey(hTopLevelKey);
  162. }
  163. return(pRouterHead);
  164. }
  165. void
  166. CleanupRouter(
  167. PROUTER_ENTRY pRouterHead
  168. )
  169. {
  170. PROUTER_ENTRY pRouter = pRouterHead, pRouterNext = NULL;
  171. while (pRouter) {
  172. pRouterNext = pRouter->pNext;
  173. if (pRouter->pNamespaceClsid) {
  174. LocalFree(pRouter->pNamespaceClsid);
  175. }
  176. LocalFree(pRouter);
  177. pRouter = pRouterNext;
  178. }
  179. return;
  180. }