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.

476 lines
7.9 KiB

  1. /*++
  2. Copyright (c) 1997 Microsoft Corporation
  3. Module Name:
  4. cmds.cxx
  5. Abstract:
  6. IISNET command handlers.
  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. #define WAIT_FOR_STATE_CHANGE_TIMEOUT 1000 // ms
  17. //
  18. // Private types.
  19. //
  20. typedef struct _ENUM_CONTEXT {
  21. BOOL ShowAll;
  22. LPWSTR Instance;
  23. WCHAR Service[MAX_PATH];
  24. } ENUM_CONTEXT, *PENUM_CONTEXT;
  25. //
  26. // Private globals.
  27. //
  28. //
  29. // Private prototypes.
  30. //
  31. VOID
  32. PerformStateChange(
  33. IN IMSAdminBase * AdmCom,
  34. IN ADMIN_SINK * Sink,
  35. IN LPWSTR InstanceName,
  36. IN DWORD Command,
  37. IN DWORD TransientState
  38. );
  39. VOID
  40. EnumInstances(
  41. IN IMSAdminBase * AdmCom,
  42. IN BOOL ShowAll
  43. );
  44. BOOL
  45. WINAPI
  46. ServerLevelCallback(
  47. IN IMSAdminBase * AdmCom,
  48. IN LPWSTR ObjectName,
  49. IN VOID * Context
  50. );
  51. BOOL
  52. WINAPI
  53. InstanceLevelCallback(
  54. IN IMSAdminBase * AdmCom,
  55. IN LPWSTR ObjectName,
  56. IN VOID * Context
  57. );
  58. //
  59. // Public functions.
  60. //
  61. VOID
  62. WINAPI
  63. StartCommand(
  64. IN IMSAdminBase * AdmCom,
  65. IN ADMIN_SINK * Sink,
  66. IN INT argc,
  67. IN LPWSTR argv[]
  68. )
  69. {
  70. if( argc == 0 ) {
  71. EnumInstances(
  72. AdmCom,
  73. FALSE // ShowAll
  74. );
  75. } else
  76. if( argc == 1 ) {
  77. PerformStateChange(
  78. AdmCom,
  79. Sink,
  80. *argv,
  81. MD_SERVER_COMMAND_START,
  82. MD_SERVER_STATE_STARTING
  83. );
  84. } else {
  85. wprintf(
  86. L"use: iisnet start [service/instance]\n"
  87. );
  88. }
  89. } // StartCommand
  90. VOID
  91. WINAPI
  92. StopCommand(
  93. IN IMSAdminBase * AdmCom,
  94. IN ADMIN_SINK * Sink,
  95. IN INT argc,
  96. IN LPWSTR argv[]
  97. )
  98. {
  99. if( argc != 1 ) {
  100. wprintf(
  101. L"use: iisnet stop service/instance\n"
  102. );
  103. } else {
  104. PerformStateChange(
  105. AdmCom,
  106. Sink,
  107. *argv,
  108. MD_SERVER_COMMAND_STOP,
  109. MD_SERVER_STATE_STOPPING
  110. );
  111. }
  112. } // StopCommand
  113. VOID
  114. WINAPI
  115. PauseCommand(
  116. IN IMSAdminBase * AdmCom,
  117. IN ADMIN_SINK * Sink,
  118. IN INT argc,
  119. IN LPWSTR argv[]
  120. )
  121. {
  122. if( argc != 1 ) {
  123. wprintf(
  124. L"use: iisnet pause service/instance\n"
  125. );
  126. } else {
  127. PerformStateChange(
  128. AdmCom,
  129. Sink,
  130. *argv,
  131. MD_SERVER_COMMAND_PAUSE,
  132. MD_SERVER_STATE_PAUSING
  133. );
  134. }
  135. } // PauseCommand
  136. VOID
  137. WINAPI
  138. ContinueCommand(
  139. IN IMSAdminBase * AdmCom,
  140. IN ADMIN_SINK * Sink,
  141. IN INT argc,
  142. IN LPWSTR argv[]
  143. )
  144. {
  145. if( argc != 1 ) {
  146. wprintf(
  147. L"use: iisnet continue service/instance\n"
  148. );
  149. } else {
  150. PerformStateChange(
  151. AdmCom,
  152. Sink,
  153. *argv,
  154. MD_SERVER_COMMAND_CONTINUE,
  155. MD_SERVER_STATE_CONTINUING
  156. );
  157. }
  158. } // ContinueCommand
  159. VOID
  160. WINAPI
  161. QueryCommand(
  162. IN IMSAdminBase * AdmCom,
  163. IN ADMIN_SINK * Sink,
  164. IN INT argc,
  165. IN LPWSTR argv[]
  166. )
  167. {
  168. if( argc == 0 ) {
  169. EnumInstances(
  170. AdmCom,
  171. TRUE // ShowAll
  172. );
  173. } else
  174. if( argc == 1 ) {
  175. HRESULT result;
  176. result = MdDisplayInstanceState(
  177. AdmCom,
  178. *argv
  179. );
  180. if( FAILED(result) ) {
  181. wprintf(
  182. L"iisnet: cannot get instance state, error %lx\n",
  183. result
  184. );
  185. }
  186. } else {
  187. wprintf(
  188. L"use: iisnet query [server/instance]\n"
  189. );
  190. }
  191. } // QueryCommand
  192. //
  193. // Private functions.
  194. //
  195. VOID
  196. PerformStateChange(
  197. IN IMSAdminBase * AdmCom,
  198. IN ADMIN_SINK * Sink,
  199. IN LPWSTR InstanceName,
  200. IN DWORD Command,
  201. IN DWORD TransientState
  202. )
  203. {
  204. HRESULT result;
  205. DWORD status;
  206. DWORD currentState;
  207. DWORD currentWin32Status;
  208. result = MdDisplayInstanceState(
  209. AdmCom,
  210. InstanceName
  211. );
  212. if( FAILED(result) ) {
  213. wprintf(
  214. L"Cannot query server state, error %lx\n",
  215. result
  216. );
  217. return;
  218. }
  219. result = MdControlInstance(
  220. AdmCom,
  221. InstanceName,
  222. Command
  223. );
  224. if( FAILED(result) ) {
  225. wprintf(
  226. L"Cannot set server state, error %lu\n",
  227. result
  228. );
  229. return;
  230. }
  231. wprintf(
  232. L"Waiting for state change..."
  233. );
  234. currentState = TransientState;
  235. do {
  236. status = Sink->WaitForStateChange( WAIT_FOR_STATE_CHANGE_TIMEOUT );
  237. if( status == WAIT_TIMEOUT ) {
  238. wprintf( L"." );
  239. continue;
  240. }
  241. result = MdGetInstanceState(
  242. AdmCom,
  243. InstanceName,
  244. &currentState,
  245. &currentWin32Status
  246. );
  247. if( FAILED(result) ) {
  248. wprintf(
  249. L"Cannot query server state, error %lx\n",
  250. result
  251. );
  252. break;
  253. }
  254. } while( currentState == TransientState );
  255. wprintf( L"\n" );
  256. MdDisplayInstanceState(
  257. AdmCom,
  258. InstanceName
  259. );
  260. } // PerformStateChange
  261. VOID
  262. EnumInstances(
  263. IN IMSAdminBase * AdmCom,
  264. IN BOOL ShowAll
  265. )
  266. {
  267. HRESULT result;
  268. ENUM_CONTEXT context;
  269. context.ShowAll = ShowAll;
  270. result = MdEnumMetaObjects(
  271. AdmCom,
  272. L"LM",
  273. &ServerLevelCallback,
  274. (VOID *)&context
  275. );
  276. if( FAILED(result) ) {
  277. wprintf(
  278. L"iisnet: cannot enumerate servers, error %lx\n",
  279. result
  280. );
  281. }
  282. } // EnumRunningInstances
  283. BOOL
  284. WINAPI
  285. ServerLevelCallback(
  286. IN IMSAdminBase * AdmCom,
  287. IN LPWSTR ObjectName,
  288. IN VOID * Context
  289. )
  290. {
  291. HRESULT result;
  292. PENUM_CONTEXT context = (PENUM_CONTEXT)Context;
  293. WCHAR path[MAX_PATH];
  294. swprintf(
  295. path,
  296. L"%S/%s",
  297. IIS_MD_LOCAL_MACHINE_PATH,
  298. ObjectName
  299. );
  300. wcscpy(
  301. context->Service,
  302. ObjectName
  303. );
  304. context->Instance = context->Service + wcslen( ObjectName );
  305. result = MdEnumMetaObjects(
  306. AdmCom,
  307. path,
  308. &InstanceLevelCallback,
  309. Context
  310. );
  311. return TRUE;
  312. } // ServerLevelCallback
  313. BOOL
  314. WINAPI
  315. InstanceLevelCallback(
  316. IN IMSAdminBase * AdmCom,
  317. IN LPWSTR ObjectName,
  318. IN VOID * Context
  319. )
  320. {
  321. HRESULT result;
  322. PENUM_CONTEXT context = (PENUM_CONTEXT)Context;
  323. DWORD currentState;
  324. DWORD currentWin32Status;
  325. swprintf(
  326. context->Instance,
  327. L"/%s",
  328. ObjectName
  329. );
  330. result = MdGetInstanceState(
  331. AdmCom,
  332. context->Service,
  333. &currentState,
  334. &currentWin32Status
  335. );
  336. if( SUCCEEDED(result) ) {
  337. if( context->ShowAll || currentState == MD_SERVER_STATE_STARTED ) {
  338. wprintf(
  339. L"%s: state = %lu (%s), status = %lu\n",
  340. context->Service,
  341. currentState,
  342. MdInstanceStateToString( currentState ),
  343. currentWin32Status
  344. );
  345. }
  346. }
  347. return TRUE;
  348. } // InstanceLevelCallback