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.

331 lines
5.6 KiB

  1. /*++
  2. Copyright (c) 1997 Microsoft Corporation
  3. Module Name:
  4. instance.cxx
  5. Abstract:
  6. General server instance control utility functions.
  7. Author:
  8. Keith Moore (keithmo) 05-Feb-1997
  9. Revision History:
  10. --*/
  11. #include "precomp.hxx"
  12. #pragma hdrstop
  13. //
  14. // Private constants.
  15. //
  16. //
  17. // Private types.
  18. //
  19. //
  20. // Private globals.
  21. //
  22. //
  23. // Private prototypes.
  24. //
  25. //
  26. // Public functions.
  27. //
  28. HRESULT
  29. MdGetInstanceState(
  30. IN IMSAdminBase * AdmCom,
  31. IN LPWSTR InstanceName,
  32. OUT DWORD * CurrentState,
  33. OUT DWORD * CurrentWin32Status
  34. )
  35. {
  36. DWORD length;
  37. METADATA_HANDLE handle;
  38. HRESULT result;
  39. METADATA_RECORD record;
  40. WCHAR path[MAX_PATH];
  41. //
  42. // Setup locals so we know how to cleanup on exit.
  43. //
  44. handle = 0;
  45. //
  46. // Build the instance path.
  47. //
  48. swprintf(
  49. path,
  50. L"/%S/%s",
  51. IIS_MD_LOCAL_MACHINE_PATH,
  52. InstanceName
  53. );
  54. //
  55. // Open the metabase.
  56. //
  57. result = AdmCom->OpenKey(
  58. METADATA_MASTER_ROOT_HANDLE,
  59. path,
  60. METADATA_PERMISSION_READ,
  61. METABASE_OPEN_TIMEOUT,
  62. &handle
  63. );
  64. if( FAILED(result) ) {
  65. goto Cleanup;
  66. }
  67. //
  68. // Read the server state.
  69. //
  70. length = sizeof(*CurrentState);
  71. INITIALIZE_METADATA_RECORD(
  72. &record,
  73. MD_SERVER_STATE,
  74. METADATA_INHERIT,
  75. IIS_MD_UT_SERVER,
  76. DWORD_METADATA,
  77. length,
  78. CurrentState
  79. );
  80. result = AdmCom->GetData(
  81. handle,
  82. L"",
  83. &record,
  84. &length
  85. );
  86. if( FAILED(result) ) {
  87. goto Cleanup;
  88. }
  89. //
  90. // Read the win32 status.
  91. //
  92. length = sizeof(*CurrentWin32Status);
  93. INITIALIZE_METADATA_RECORD(
  94. &record,
  95. MD_WIN32_ERROR,
  96. METADATA_INHERIT,
  97. IIS_MD_UT_SERVER,
  98. DWORD_METADATA,
  99. length,
  100. CurrentWin32Status
  101. );
  102. result = AdmCom->GetData(
  103. handle,
  104. L"",
  105. &record,
  106. &length
  107. );
  108. if( FAILED(result) ) {
  109. if( result == MD_ERROR_DATA_NOT_FOUND ) {
  110. *CurrentWin32Status = NO_ERROR;
  111. result = NO_ERROR;
  112. } else {
  113. goto Cleanup;
  114. }
  115. }
  116. Cleanup:
  117. if( handle != 0 ) {
  118. (VOID)AdmCom->CloseKey( handle );
  119. }
  120. return result;
  121. } // MdGetInstanceState
  122. HRESULT
  123. MdControlInstance(
  124. IN IMSAdminBase * AdmCom,
  125. IN LPWSTR InstanceName,
  126. IN DWORD Command
  127. )
  128. {
  129. METADATA_HANDLE handle;
  130. HRESULT result;
  131. METADATA_RECORD record;
  132. WCHAR path[MAX_PATH];
  133. //
  134. // Setup locals so we know how to cleanup on exit.
  135. //
  136. handle = 0;
  137. result = NO_ERROR;
  138. //
  139. // Build the instance path.
  140. //
  141. swprintf(
  142. path,
  143. L"/%S/%s",
  144. IIS_MD_LOCAL_MACHINE_PATH,
  145. InstanceName
  146. );
  147. //
  148. // Open the metabase.
  149. //
  150. result = AdmCom->OpenKey(
  151. METADATA_MASTER_ROOT_HANDLE,
  152. path,
  153. METADATA_PERMISSION_READ | METADATA_PERMISSION_WRITE,
  154. METABASE_OPEN_TIMEOUT,
  155. &handle
  156. );
  157. if( SUCCEEDED(result) ) {
  158. //
  159. // Send the command.
  160. //
  161. INITIALIZE_METADATA_RECORD(
  162. &record,
  163. MD_SERVER_COMMAND,
  164. METADATA_INHERIT,
  165. IIS_MD_UT_SERVER,
  166. DWORD_METADATA,
  167. sizeof(Command),
  168. &Command
  169. );
  170. result = AdmCom->SetData(
  171. handle,
  172. L"",
  173. &record
  174. );
  175. //
  176. // Close the meta object handle.
  177. //
  178. (VOID)AdmCom->CloseKey( handle );
  179. }
  180. return result;
  181. } // MdControlInstance
  182. HRESULT
  183. MdDisplayInstanceState(
  184. IN IMSAdminBase * AdmCom,
  185. IN LPWSTR InstanceName
  186. )
  187. {
  188. DWORD currentState;
  189. DWORD currentWin32Status;
  190. HRESULT result;
  191. //
  192. // Get the current state.
  193. //
  194. result = MdGetInstanceState(
  195. AdmCom,
  196. InstanceName,
  197. &currentState,
  198. &currentWin32Status
  199. );
  200. if( SUCCEEDED(result) ) {
  201. wprintf(
  202. L"%s: state = %lu (%s), status = %lu\n",
  203. InstanceName,
  204. currentState,
  205. MdInstanceStateToString( currentState ),
  206. currentWin32Status
  207. );
  208. }
  209. return result;
  210. } // MdDisplayInstanceState
  211. LPWSTR
  212. MdInstanceStateToString(
  213. IN DWORD State
  214. )
  215. {
  216. static WCHAR invalidState[sizeof("INVALID STATE 4294967296")];
  217. switch( State ) {
  218. case MD_SERVER_STATE_STARTING :
  219. return L"Starting";
  220. case MD_SERVER_STATE_STARTED :
  221. return L"Started";
  222. case MD_SERVER_STATE_STOPPING :
  223. return L"Stopping";
  224. case MD_SERVER_STATE_STOPPED :
  225. return L"Stopped";
  226. case MD_SERVER_STATE_PAUSING :
  227. return L"Pausing";
  228. case MD_SERVER_STATE_PAUSED :
  229. return L"Paused";
  230. case MD_SERVER_STATE_CONTINUING :
  231. return L"Continuing";
  232. }
  233. swprintf(
  234. invalidState,
  235. L"INVALID STATE %lu",
  236. State
  237. );
  238. return invalidState;
  239. } // MdInstanceStateToString
  240. //
  241. // Private functions.
  242. //