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.

280 lines
9.4 KiB

  1. // %%Includes: ---------------------------------------------------------------
  2. #include "precomp.hxx"
  3. #include <initguid.h>
  4. #include <imd.h>
  5. #include <mb.hxx>
  6. #include <iadm.h>
  7. #include "coiadm.hxx"
  8. #include "admacl.hxx"
  9. extern ULONG g_dwRefCount;
  10. extern COpenHandle g_ohMasterRootHandle;
  11. #ifdef _M_IX86
  12. static BYTE SP3Sig[] = {0xbd, 0x9f, 0x13, 0xc5, 0x92, 0x12, 0x2b, 0x72,
  13. 0x4a, 0xba, 0xb6, 0x2a, 0xf9, 0xfc, 0x54, 0x46,
  14. 0x6f, 0xa1, 0xb4, 0xbb, 0x43, 0xa8, 0xfe, 0xf8,
  15. 0xa8, 0x23, 0x7d, 0xd1, 0x85, 0x84, 0x22, 0x6e,
  16. 0xb4, 0x58, 0x00, 0x3e, 0x0b, 0x19, 0x83, 0x88,
  17. 0x6a, 0x8d, 0x64, 0x02, 0xdf, 0x5f, 0x65, 0x7e,
  18. 0x3b, 0x4d, 0xd4, 0x10, 0x44, 0xb9, 0x46, 0x34,
  19. 0xf3, 0x40, 0xf4, 0xbc, 0x9f, 0x4b, 0x82, 0x1e,
  20. 0xcc, 0xa7, 0xd0, 0x2d, 0x22, 0xd7, 0xb1, 0xf0,
  21. 0x2e, 0xcd, 0x0e, 0x21, 0x52, 0xbc, 0x3e, 0x81,
  22. 0xb1, 0x1a, 0x86, 0x52, 0x4d, 0x3f, 0xfb, 0xa2,
  23. 0x9d, 0xae, 0xc6, 0x3d, 0xaa, 0x13, 0x4d, 0x18,
  24. 0x7c, 0xd2, 0x28, 0xce, 0x72, 0xb1, 0x26, 0x3f,
  25. 0xba, 0xf8, 0xa6, 0x4b, 0x01, 0xb9, 0xa4, 0x5c,
  26. 0x43, 0x68, 0xd3, 0x46, 0x81, 0x00, 0x7f, 0x6a,
  27. 0xd7, 0xd1, 0x69, 0x51, 0x47, 0x25, 0x14, 0x40,
  28. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
  29. #else // other than _M_IX86
  30. static BYTE SP3Sig[] = {0x8a, 0x06, 0x01, 0x6d, 0xc2, 0xb5, 0xa2, 0x66,
  31. 0x12, 0x1b, 0x9c, 0xe4, 0x58, 0xb1, 0xf8, 0x7d,
  32. 0xad, 0x17, 0xc1, 0xf9, 0x3f, 0x87, 0xe3, 0x9c,
  33. 0xdd, 0xeb, 0xcc, 0xa8, 0x6b, 0x62, 0xd0, 0x72,
  34. 0xe7, 0xf2, 0xec, 0xd6, 0xd6, 0x36, 0xab, 0x2d,
  35. 0x28, 0xea, 0x74, 0x07, 0x0e, 0x6c, 0x6d, 0xe1,
  36. 0xf8, 0x17, 0x97, 0x13, 0x8d, 0xb1, 0x8b, 0x0b,
  37. 0x33, 0x97, 0xc5, 0x46, 0x66, 0x96, 0xb4, 0xf7,
  38. 0x03, 0xc5, 0x03, 0x98, 0xf7, 0x91, 0xae, 0x9d,
  39. 0x00, 0x1a, 0xc6, 0x86, 0x30, 0x5c, 0xc8, 0xc7,
  40. 0x05, 0x47, 0xed, 0x2d, 0xc2, 0x0b, 0x61, 0x4b,
  41. 0xce, 0xe5, 0xb7, 0xd7, 0x27, 0x0c, 0x9e, 0x2f,
  42. 0xc5, 0x25, 0xe3, 0x81, 0x13, 0x9d, 0xa2, 0x67,
  43. 0xb2, 0x26, 0xfc, 0x99, 0x9d, 0xce, 0x0e, 0xaf,
  44. 0x30, 0xf3, 0x30, 0xec, 0xa3, 0x0a, 0xfe, 0x16,
  45. 0xb6, 0xda, 0x16, 0x90, 0x9a, 0x9a, 0x74, 0x7a,
  46. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
  47. #endif // _M_IX86
  48. DWORD g_dwComRegisterW;
  49. DWORD g_bInitialized = FALSE;
  50. IMDCOM3 *g_pcCom = NULL;
  51. STDAPI
  52. InitComAdmindata()
  53. {
  54. HRESULT hr = S_OK;
  55. DWORD dwError;
  56. CADMCOMSrvFactoryW *pADMClassFactoryW = NULL;
  57. CREATE_DEBUG_PRINT_OBJECT( "coadmin" );
  58. LOAD_DEBUG_FLAGS_FROM_REG_STR( "System\\CurrentControlSet\\Services\\iisadmin\\Parameters", 0 );
  59. INITIALIZE_PLATFORM_TYPE();
  60. CADMCOMW::InitObjectList();
  61. hr = g_ohMasterRootHandle.Init( METADATA_MASTER_ROOT_HANDLE,
  62. L"",
  63. L"");
  64. DBG_ASSERT( SUCCEEDED( hr ) );
  65. if ( FAILED( hr ) )
  66. {
  67. DBGPRINTF(( DBG_CONTEXT,
  68. "[InitComAdmindata] g_ohMasterRootHandle.Init failed, hr 0x%8x\n",
  69. hr ));
  70. goto exit;
  71. }
  72. // Cache the pids of this process and the process hosting RpcSs
  73. hr = CADMCOMW::GetPids();
  74. if( FAILED( hr ) )
  75. {
  76. DBGPRINTF(( DBG_CONTEXT,
  77. "[InitComAdmindata] CADMCOMW::GetPids failed, hr 0x%08x\n",
  78. hr ));
  79. goto exit;
  80. }
  81. hr = CoCreateInstance( GETMDCLSID( TRUE ),
  82. NULL,
  83. CLSCTX_INPROC_SERVER,
  84. IID_IMDCOM3,
  85. (void**) &g_pcCom );
  86. if ( FAILED( hr ) )
  87. {
  88. goto exit;
  89. }
  90. hr = g_pcCom->ComMDInitialize();
  91. if( FAILED( hr ) )
  92. {
  93. DBGPRINTF(( DBG_CONTEXT,
  94. "[InitComAdmindata] Error initialize MDCOM object. hr = %x\n",
  95. hr ));
  96. goto exit;
  97. }
  98. pADMClassFactoryW = new CADMCOMSrvFactoryW;
  99. if ( pADMClassFactoryW == NULL )
  100. {
  101. dwError = GetLastError();
  102. DBGPRINTF(( DBG_CONTEXT,
  103. "[InitComAdmindata] CADMCOMSrvFactoryW failed, error %lx\n",
  104. GetLastError() ));
  105. hr = HRESULT_FROM_WIN32( dwError );
  106. goto exit;
  107. }
  108. pADMClassFactoryW->AddRef();
  109. // register the class-object with OLE
  110. hr = CoRegisterClassObject( GETAdminBaseCLSIDW( TRUE ),
  111. pADMClassFactoryW,
  112. CLSCTX_SERVER,
  113. REGCLS_MULTIPLEUSE,
  114. &g_dwComRegisterW );
  115. if ( FAILED( hr ) )
  116. {
  117. DBGPRINTF(( DBG_CONTEXT,
  118. "[InitComAdmindata] CoRegisterClassObject failed, error %lx\n",
  119. GetLastError() ));
  120. goto exit;
  121. }
  122. exit:
  123. if ( pADMClassFactoryW )
  124. {
  125. pADMClassFactoryW->Release();
  126. }
  127. if ( FAILED( hr ) )
  128. {
  129. AdminAclDisableAclCache();
  130. AdminAclFlushCache();
  131. if ( g_dwComRegisterW != 0 )
  132. {
  133. CoRevokeClassObject( g_dwComRegisterW );
  134. g_dwComRegisterW = 0;
  135. }
  136. if ( g_pcCom != NULL )
  137. {
  138. g_pcCom->ComMDSendShutdownNotifications();
  139. g_pcCom->ComMDStopEWR();
  140. }
  141. CADMCOMW::ShutDownObjects();
  142. CADMCOMW::TerminateObjectList();
  143. if ( g_pcCom != NULL )
  144. {
  145. g_pcCom->ComMDShutdown();
  146. g_pcCom->ComMDTerminate(FALSE);
  147. g_pcCom->Release();
  148. g_pcCom = NULL;
  149. }
  150. }
  151. g_bInitialized = SUCCEEDED( hr );
  152. return hr;
  153. } // main
  154. STDAPI
  155. TerminateComAdmindata()
  156. {
  157. HRESULT hr = S_OK;
  158. int i;
  159. DBGPRINTF(( DBG_CONTEXT,
  160. "[TerminateComAdmindata] Terminating ABO.\n" ));
  161. if ( !g_bInitialized )
  162. {
  163. DBGPRINTF(( DBG_CONTEXT,
  164. "[TerminateComAdmindata] Not initialized!\n" ));
  165. goto exit;
  166. }
  167. g_bInitialized = FALSE;
  168. // Go ahead and flush the acl cache, since it holds
  169. // references to the CMDCOM object. If users come in
  170. // after this and recreate the acls, they will be created
  171. // again and we will just wait the 7 seconds below.
  172. AdminAclDisableAclCache();
  173. AdminAclFlushCache();
  174. DBGPRINTF(( DBG_CONTEXT,
  175. "[TerminateComAdmindata] Disabled the ACL cache.\n" ));
  176. if ( g_dwComRegisterW != 0 )
  177. {
  178. hr = CoRevokeClassObject( g_dwComRegisterW );
  179. DBGPRINTF(( DBG_CONTEXT,
  180. "[TerminateComAdmindata] Revoked the ABO class factory %d with hr = 0x%08x.\n",
  181. g_dwComRegisterW,
  182. hr ));
  183. g_dwComRegisterW = 0;
  184. }
  185. if ( g_pcCom != NULL )
  186. {
  187. hr = g_pcCom->ComMDSendShutdownNotifications();
  188. DBGPRINTF(( DBG_CONTEXT,
  189. "[TerminateComAdmindata] Sent shutdown notifications with hr = 0x%08x.\n",
  190. hr ));
  191. hr = g_pcCom->ComMDStopEWR();
  192. DBGPRINTF(( DBG_CONTEXT,
  193. "[TerminateComAdmindata] Stopped EWR with hr = 0x%08x.\n",
  194. hr ));
  195. }
  196. DBGPRINTF(( DBG_CONTEXT,
  197. "[TerminateComAdmindata] Terminating all ABO objects.\n" ));
  198. CADMCOMW::ShutDownObjects();
  199. // Wait for remaining accesses to the factory to complete
  200. // Do this after ShutDownObject to avoid extra waiting
  201. for ( i = 0; (g_dwRefCount > 0) && (i < 5); i++ )
  202. {
  203. DBGPRINTF(( DBG_CONTEXT,
  204. "[TerminateComAdmindata] Waiting on factory shutdown, i = %d\n",
  205. i ));
  206. Sleep( 1000 );
  207. }
  208. // Just in case another object was allocated came through
  209. // while we were waiting
  210. CADMCOMW::ShutDownObjects();
  211. DBGPRINTF(( DBG_CONTEXT,
  212. "[TerminateComAdmindata] Terminated all ABO objects.\n" ));
  213. AdminAclDisableAclCache();
  214. AdminAclFlushCache();
  215. CADMCOMW::TerminateObjectList();
  216. DBGPRINTF(( DBG_CONTEXT,
  217. "[TerminateComAdmindata] Terminated ABO ROT.\n" ));
  218. if ( g_pcCom != NULL )
  219. {
  220. hr = g_pcCom->ComMDShutdown();
  221. DBGPRINTF(( DBG_CONTEXT,
  222. "[TerminateComAdmindata] Shutdown metadata with hr = 0x%08x.\n",
  223. hr ));
  224. hr = g_pcCom->ComMDTerminate(FALSE);
  225. DBGPRINTF(( DBG_CONTEXT,
  226. "[TerminateComAdmindata] Terminated metadata with hr = 0x%08x.\n",
  227. hr ));
  228. g_pcCom->Release();
  229. g_pcCom = NULL;
  230. }
  231. DBGPRINTF(( DBG_CONTEXT,
  232. "[TerminateComAdmindata] Done with hr = 0x%08x.\n",
  233. hr ));
  234. #ifndef _NO_TRACING_
  235. DELETE_DEBUG_PRINT_OBJECT();
  236. #endif
  237. exit:
  238. return hr;
  239. }