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.

281 lines
9.4 KiB

  1. /**********************************************************************/
  2. /** Microsoft Windows NT **/
  3. /** Copyright(c) Microsoft Corp., 1997 **/
  4. /**********************************************************************/
  5. /*
  6. admsub.cxx
  7. This module contains IISADMIN subroutines.
  8. FILE HISTORY:
  9. 7/7/97 michth created
  10. */
  11. #define INITGUID
  12. extern "C" {
  13. #include <nt.h>
  14. #include <ntrtl.h>
  15. #include <nturtl.h>
  16. }
  17. #include <dbgutil.h>
  18. #include <apiutil.h>
  19. #include <loadmd.hxx>
  20. #include <loadadm.hxx>
  21. #include <ole2.h>
  22. #include <inetsvcs.h>
  23. #include <ntsec.h>
  24. #include <string.hxx>
  25. #include <registry.hxx>
  26. #include <iadmext.h>
  27. #include <admsub.hxx>
  28. #include <stringau.hxx>
  29. #include <imd.h>
  30. #include <iiscnfg.h>
  31. PIADMEXT_CONTAINER g_piaecHead = NULL;
  32. HRESULT AddServiceExtension(IADMEXT *piaeExtension)
  33. {
  34. HRESULT hresReturn = ERROR_SUCCESS;
  35. PIADMEXT_CONTAINER piaecExtension = new IADMEXT_CONTAINER;
  36. if (piaecExtension == NULL) {
  37. hresReturn = HRESULT_FROM_WIN32(ERROR_NOT_ENOUGH_MEMORY);
  38. }
  39. else {
  40. piaecExtension->piaeInstance = piaeExtension;
  41. piaecExtension->NextPtr = g_piaecHead;
  42. g_piaecHead = piaecExtension;
  43. }
  44. return hresReturn;
  45. }
  46. VOID
  47. StartServiceExtension(LPTSTR pszExtension)
  48. {
  49. HRESULT hresError;
  50. CLSID clsidExtension;
  51. IADMEXT *piaeExtension;
  52. STRAU strauCLSID(pszExtension);
  53. if (strauCLSID.IsValid() && (strauCLSID.QueryStrW() != NULL)) {
  54. hresError = CLSIDFromString(strauCLSID.QueryStrW(),
  55. &clsidExtension);
  56. if (SUCCEEDED(hresError)) {
  57. hresError = CoCreateInstance(clsidExtension,
  58. NULL,
  59. CLSCTX_SERVER,
  60. IID_IADMEXT,
  61. (void**) &piaeExtension);
  62. if (SUCCEEDED(hresError)) {
  63. hresError = piaeExtension->Initialize();
  64. if (SUCCEEDED(hresError)) {
  65. hresError = AddServiceExtension(piaeExtension);
  66. if (FAILED(hresError)) {
  67. piaeExtension->Terminate();
  68. }
  69. }
  70. if (FAILED(hresError)) {
  71. piaeExtension->Release();
  72. }
  73. }
  74. }
  75. }
  76. }
  77. VOID
  78. StartServiceExtensions()
  79. {
  80. DBG_ASSERT(g_piaecHead == NULL);
  81. MDRegKey mdrkMain(HKEY_LOCAL_MACHINE,
  82. IISADMIN_EXTENSIONS_REG_KEY);
  83. if (GetLastError() == ERROR_SUCCESS) {
  84. MDRegKeyIter *pmdrkiCLSID = new MDRegKeyIter(mdrkMain);
  85. if ((pmdrkiCLSID != NULL) && (GetLastError() == ERROR_SUCCESS)) {
  86. LPTSTR pszExtension;
  87. for (DWORD dwIndex = 0;
  88. pmdrkiCLSID->Next(&pszExtension, NULL, dwIndex) == ERROR_SUCCESS;
  89. dwIndex++) {
  90. StartServiceExtension(pszExtension);
  91. }
  92. }
  93. delete (pmdrkiCLSID);
  94. }
  95. }
  96. BOOL
  97. RemoveServiceExtension(IADMEXT **ppiaeExtension)
  98. {
  99. BOOL bReturn = FALSE;
  100. if (g_piaecHead != NULL) {
  101. PIADMEXT_CONTAINER piaecExtension = g_piaecHead;
  102. *ppiaeExtension = g_piaecHead->piaeInstance;
  103. g_piaecHead = g_piaecHead->NextPtr;
  104. delete piaecExtension;
  105. bReturn = TRUE;
  106. }
  107. return bReturn;
  108. }
  109. VOID
  110. StopServiceExtension(IADMEXT *piaeExtension)
  111. {
  112. piaeExtension->Terminate();
  113. piaeExtension->Release();
  114. }
  115. VOID StopServiceExtensions()
  116. {
  117. IADMEXT *piaeExtension;
  118. while (RemoveServiceExtension(&piaeExtension)) {
  119. StopServiceExtension(piaeExtension);
  120. }
  121. DBG_ASSERT(g_piaecHead == NULL);
  122. }
  123. HRESULT
  124. AddClsidToBuffer(CLSID clsidDcomExtension,
  125. BUFFER *pbufCLSIDs,
  126. DWORD *pdwMLSZLen,
  127. LPMALLOC pmallocOle)
  128. {
  129. HRESULT hresReturn = S_OK;
  130. LPWSTR pszCLSID;
  131. if (!pbufCLSIDs->Resize((*pdwMLSZLen + CLSID_LEN) * sizeof(WCHAR))) {
  132. hresReturn = HRESULT_FROM_WIN32(ERROR_NOT_ENOUGH_MEMORY);
  133. }
  134. else {
  135. if (SUCCEEDED(StringFromCLSID(clsidDcomExtension, &pszCLSID))) {
  136. DBG_ASSERT(wcslen(pszCLSID) + 1 == CLSID_LEN);
  137. memcpy(((LPWSTR)pbufCLSIDs->QueryPtr()) + *pdwMLSZLen, pszCLSID, CLSID_LEN * sizeof(WCHAR));
  138. (*pdwMLSZLen) += CLSID_LEN;
  139. if (pmallocOle != NULL) {
  140. pmallocOle->Free(pszCLSID);
  141. }
  142. }
  143. }
  144. return hresReturn;
  145. }
  146. VOID
  147. RegisterServiceExtensionCLSIDs()
  148. {
  149. HRESULT hresMDError;
  150. HRESULT hresExtensionError;
  151. HRESULT hresBufferError;
  152. HRESULT hresCom;
  153. CLSID clsidDcomExtension;
  154. DWORD i;
  155. IMDCOM * pcCom = NULL;
  156. METADATA_HANDLE mdhRoot;
  157. METADATA_HANDLE mdhExtension;
  158. METADATA_RECORD mdrData;
  159. PIADMEXT_CONTAINER piaecExtension;
  160. BUFFER bufCLSIDs;
  161. DWORD dwMLSZLen = 0;
  162. BOOL bAreCLSIDs = FALSE;
  163. LPMALLOC pmallocOle = NULL;
  164. hresCom = CoGetMalloc(1, &pmallocOle);
  165. if( SUCCEEDED(hresCom) ) {
  166. hresMDError = CoCreateInstance(CLSID_MDCOM,
  167. NULL,
  168. CLSCTX_SERVER,
  169. IID_IMDCOM,
  170. (void**) &pcCom);
  171. if (SUCCEEDED(hresMDError)) {
  172. hresMDError = pcCom->ComMDInitialize();
  173. if (SUCCEEDED(hresMDError)) {
  174. hresMDError = pcCom->ComMDOpenMetaObject(
  175. METADATA_MASTER_ROOT_HANDLE,
  176. (PBYTE)IISADMIN_EXTENSIONS_CLSID_MD_KEY,
  177. METADATA_PERMISSION_WRITE | METADATA_PERMISSION_READ,
  178. MD_OPEN_DEFAULT_TIMEOUT_VALUE,
  179. &mdhExtension);
  180. if (hresMDError == RETURNCODETOHRESULT(ERROR_PATH_NOT_FOUND)) {
  181. hresMDError = pcCom->ComMDOpenMetaObject(
  182. METADATA_MASTER_ROOT_HANDLE,
  183. NULL,
  184. METADATA_PERMISSION_WRITE | METADATA_PERMISSION_READ,
  185. MD_OPEN_DEFAULT_TIMEOUT_VALUE,
  186. &mdhRoot);
  187. if (SUCCEEDED(hresMDError)) {
  188. hresMDError = pcCom->ComMDAddMetaObject(
  189. mdhRoot,
  190. (PBYTE)IISADMIN_EXTENSIONS_CLSID_MD_KEY);
  191. pcCom->ComMDCloseMetaObject(mdhRoot);
  192. if (SUCCEEDED(hresMDError)) {
  193. hresMDError = pcCom->ComMDOpenMetaObject(
  194. METADATA_MASTER_ROOT_HANDLE,
  195. (PBYTE)IISADMIN_EXTENSIONS_CLSID_MD_KEY,
  196. METADATA_PERMISSION_WRITE | METADATA_PERMISSION_READ,
  197. MD_OPEN_DEFAULT_TIMEOUT_VALUE,
  198. &mdhExtension);
  199. }
  200. }
  201. }
  202. if (SUCCEEDED(hresMDError)) {
  203. pcCom->ComMDDeleteMetaData(
  204. mdhExtension,
  205. NULL,
  206. MD_IISADMIN_EXTENSIONS,
  207. MULTISZ_METADATA);
  208. for (piaecExtension = g_piaecHead, hresBufferError = S_OK;
  209. (piaecExtension != NULL) && (SUCCEEDED(hresBufferError));
  210. piaecExtension = piaecExtension->NextPtr) {
  211. hresMDError = ERROR_SUCCESS;
  212. for (i = 0;
  213. SUCCEEDED(hresExtensionError =
  214. piaecExtension->piaeInstance->EnumDcomCLSIDs(&clsidDcomExtension,
  215. i));
  216. i++) {
  217. bAreCLSIDs = TRUE;
  218. hresBufferError = AddClsidToBuffer(clsidDcomExtension,
  219. &bufCLSIDs,
  220. &dwMLSZLen,
  221. pmallocOle);
  222. if (FAILED(hresBufferError)) {
  223. break;
  224. }
  225. }
  226. }
  227. if (bAreCLSIDs && SUCCEEDED(hresBufferError)) {
  228. if (bufCLSIDs.Resize((dwMLSZLen + 1) * sizeof(WCHAR))) {
  229. *(((LPWSTR)bufCLSIDs.QueryPtr()) + dwMLSZLen) = (WCHAR)'\0';
  230. mdrData.dwMDAttributes = METADATA_NO_ATTRIBUTES;
  231. mdrData.dwMDUserType = IIS_MD_UT_SERVER;
  232. mdrData.dwMDDataType = MULTISZ_METADATA;
  233. mdrData.dwMDDataLen = (dwMLSZLen + 1) * sizeof(WCHAR);
  234. mdrData.pbMDData = (PBYTE)bufCLSIDs.QueryPtr();
  235. mdrData.dwMDIdentifier = IISADMIN_EXTENSIONS_CLSID_MD_ID;
  236. hresMDError = pcCom->ComMDSetMetaDataW(
  237. mdhExtension,
  238. NULL,
  239. &mdrData);
  240. }
  241. }
  242. pcCom->ComMDCloseMetaObject(mdhExtension);
  243. }
  244. pcCom->ComMDTerminate(TRUE);
  245. }
  246. pcCom->Release();
  247. }
  248. if (pmallocOle != NULL) {
  249. pmallocOle->Release();
  250. }
  251. }
  252. }