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.

253 lines
6.7 KiB

  1. /*++
  2. Copyright (c) 1997 Microsoft Corporation
  3. Module Name:
  4. extcom.cxx
  5. Abstract:
  6. IIS Services IISADMIN Extension
  7. Main COM interface.
  8. Class CadmExt
  9. CLSID = CLSID_W3EXTEND
  10. IID = IID_IADMEXT
  11. Author:
  12. Michael W. Thomas 16-Sep-97
  13. --*/
  14. #include <cominc.hxx>
  15. #ifndef _NO_TRACING_
  16. DECLARE_DEBUG_PRINTS_OBJECT();
  17. #include <initguid.h>
  18. DEFINE_GUID(IisExtComGuid,
  19. 0x784d8925, 0xaa8c, 0x11d2, 0x92, 0x5e, 0x00, 0xc0, 0x4f, 0x72, 0xd9, 0x0e);
  20. #endif
  21. CAdmExt::CAdmExt():
  22. m_dwRefCount(0),
  23. m_pcCom(NULL),
  24. m_dwSinkCookie(0),
  25. m_pConnPoint(NULL)
  26. {
  27. }
  28. CAdmExt::~CAdmExt()
  29. {
  30. #ifndef _NO_TRACING_
  31. DELETE_DEBUG_PRINT_OBJECT();
  32. #endif
  33. }
  34. HRESULT
  35. CAdmExt::QueryInterface(REFIID riid, void **ppObject) {
  36. if (riid==IID_IUnknown || riid==IID_IADMEXT) {
  37. *ppObject = (IADMEXT *) this;
  38. }
  39. else {
  40. return E_NOINTERFACE;
  41. }
  42. AddRef();
  43. return NO_ERROR;
  44. }
  45. ULONG
  46. CAdmExt::AddRef()
  47. {
  48. DWORD dwRefCount;
  49. InterlockedIncrement((long *)&g_dwRefCount);
  50. dwRefCount = InterlockedIncrement((long *)&m_dwRefCount);
  51. return dwRefCount;
  52. }
  53. ULONG
  54. CAdmExt::Release()
  55. {
  56. DWORD dwRefCount;
  57. InterlockedDecrement((long *)&g_dwRefCount);
  58. dwRefCount = InterlockedDecrement((long *)&m_dwRefCount);
  59. //
  60. // This is now a member of class factory.
  61. // It is not dynamically allocated, so don't delete it.
  62. //
  63. /*
  64. if (dwRefCount == 0) {
  65. delete this;
  66. return 0;
  67. }
  68. */
  69. return dwRefCount;
  70. }
  71. HRESULT STDMETHODCALLTYPE
  72. CAdmExt::Initialize(void)
  73. {
  74. HRESULT hresReturn;
  75. #ifdef _NO_TRACING_
  76. CREATE_DEBUG_PRINT_OBJECT( "SVCEXT" );
  77. #else
  78. CREATE_DEBUG_PRINT_OBJECT("SVCEXT", IisExtComGuid);
  79. #endif
  80. hresReturn = CoCreateInstance(CLSID_MDCOM,
  81. NULL,
  82. CLSCTX_SERVER,
  83. IID_IMDCOM,
  84. (void**) &m_pcCom);
  85. if (SUCCEEDED(hresReturn)) {
  86. //
  87. // First, set the state of all servers to Stopped.
  88. //
  89. SetServerState(L"/LM/W3SVC");
  90. SetServerState(L"/LM/MSFTPSVC");
  91. //
  92. // Set up a sink for special processing.
  93. //
  94. IConnectionPointContainer* pConnPointContainer = NULL;
  95. BOOL bSinkConnected = FALSE;
  96. CSvcExtImpIMDCOMSINK *pEventSink = new CSvcExtImpIMDCOMSINK(m_pcCom);
  97. if (pEventSink != NULL) {
  98. // First query the object for its Connection Point Container. This
  99. // essentially asks the object in the server if it is connectable.
  100. hresReturn = m_pcCom->QueryInterface(
  101. IID_IConnectionPointContainer,
  102. (PVOID *)&pConnPointContainer);
  103. if SUCCEEDED(hresReturn)
  104. {
  105. // Find the requested Connection Point. This AddRef's the
  106. // returned pointer.
  107. hresReturn = pConnPointContainer->FindConnectionPoint(IID_IMDCOMSINK_W, &m_pConnPoint);
  108. if (SUCCEEDED(hresReturn)) {
  109. hresReturn = m_pConnPoint->Advise((IUnknown *)pEventSink, &m_dwSinkCookie);
  110. }
  111. pConnPointContainer->Release();
  112. }
  113. pEventSink->Release();
  114. }
  115. else {
  116. hresReturn = E_OUTOFMEMORY;
  117. }
  118. }
  119. UpdateUsers();
  120. return hresReturn;
  121. }
  122. HRESULT STDMETHODCALLTYPE
  123. CAdmExt::EnumDcomCLSIDs(
  124. /* [size_is][out] */ CLSID *pclsidDcom,
  125. /* [in] */ DWORD dwEnumIndex)
  126. {
  127. return HRESULT_FROM_WIN32(ERROR_NO_MORE_ITEMS);
  128. }
  129. HRESULT STDMETHODCALLTYPE
  130. CAdmExt::Terminate(void)
  131. {
  132. if (m_pcCom != NULL) {
  133. if (m_pConnPoint != NULL) {
  134. if (m_dwSinkCookie != 0) {
  135. m_pConnPoint->Unadvise(m_dwSinkCookie);
  136. }
  137. m_pConnPoint->Release();
  138. }
  139. m_pcCom->Release();
  140. }
  141. return S_OK;
  142. }
  143. VOID
  144. CAdmExt::SetServerState(
  145. LPWSTR pszPath)
  146. {
  147. HRESULT hresReturn, hresTempReturn;
  148. TCHAR pszNameBuf[METADATA_MAX_NAME_LEN];
  149. int i;
  150. METADATA_RECORD mdrData;
  151. DWORD dwData;
  152. DWORD dwRequiredDataLen;
  153. METADATA_HANDLE mdhCurrent;
  154. hresReturn = m_pcCom->ComMDOpenMetaObject(METADATA_MASTER_ROOT_HANDLE,
  155. pszPath,
  156. METADATA_PERMISSION_WRITE | METADATA_PERMISSION_READ,
  157. OPEN_TIMEOUT_VALUE,
  158. &mdhCurrent);
  159. if (SUCCEEDED(hresReturn)) {
  160. for (i=0;hresReturn == ERROR_SUCCESS;i++) {
  161. //
  162. // enumerate children
  163. //
  164. hresReturn = m_pcCom->ComMDEnumMetaObjects(mdhCurrent,
  165. TEXT(""),
  166. pszNameBuf,
  167. i);
  168. if (SUCCEEDED(hresReturn)) {
  169. MD_SET_DATA_RECORD_EXT(&mdrData,
  170. MD_SERVER_STATE,
  171. METADATA_NO_ATTRIBUTES,
  172. 0,
  173. DWORD_METADATA,
  174. sizeof(DWORD),
  175. (PBYTE)&dwData)
  176. //
  177. // See if Server State exists at this node,
  178. // and pick up the current attributes, etc.
  179. //
  180. hresTempReturn = m_pcCom->ComMDGetMetaData(mdhCurrent,
  181. pszNameBuf,
  182. &mdrData,
  183. &dwRequiredDataLen);
  184. //
  185. // PREFIX
  186. // ComMDGetMetaData should not return success without setting the data
  187. // value pointed to by dwData. I'm not sure if PREFIX is incapable of
  188. // recognizing the extra level of indirection or if there is some path
  189. // that I missed in reviewing ComMDGetMetaData. I'm going to shut down
  190. // this warning, but I'll open an issue with the PREFIX guys.
  191. //
  192. /* INTRINSA suppress = uninitialized */
  193. if ((SUCCEEDED(hresTempReturn)) && (dwData != MD_SERVER_STATE_STOPPED)) {
  194. //
  195. // Set the new data
  196. //
  197. dwData = MD_SERVER_STATE_STOPPED;
  198. hresTempReturn = m_pcCom->ComMDSetMetaData(mdhCurrent,
  199. pszNameBuf,
  200. &mdrData);
  201. }
  202. }
  203. }
  204. hresReturn = m_pcCom->ComMDCloseMetaObject(mdhCurrent);
  205. }
  206. }