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.

267 lines
6.0 KiB

  1. /*++
  2. Copyright (c) 1999 Microsoft Corporation
  3. Module Name:
  4. Shutdown.c
  5. Abstract:
  6. This module contains the server side implementation for the Win32 remote
  7. shutdown APIs, that is:
  8. - BaseInitiateSystemShutdown
  9. - BaseAbortSystemShutdown
  10. - BaseInitiateSystemShutdownEx
  11. Author:
  12. Dragos C. Sambotin 18-May-1999
  13. Notes:
  14. These server side APIs are just stubs RPCalling in the winlogon's shutdown
  15. interface. They are provided only for backward compatibility. When support
  16. for older versions is dropped, these stubs can be removed.
  17. Revision History:
  18. --*/
  19. #define UNICODE
  20. #include <rpc.h>
  21. #include "regrpc.h"
  22. #include "shutinit.h"
  23. #include "..\regconn\regconn.h"
  24. ULONG
  25. BaseInitiateSystemShutdown(
  26. IN PREGISTRY_SERVER_NAME ServerName,
  27. IN PUNICODE_STRING lpMessage OPTIONAL,
  28. IN DWORD dwTimeout,
  29. IN BOOLEAN bForceAppsClosed,
  30. IN BOOLEAN bRebootAfterShutdown
  31. )
  32. /*++
  33. Routine Description:
  34. This routine is provided for backward compatibility. It does nothing
  35. Arguments:
  36. ServerName - Name of machine this server code is running on. (Ignored)
  37. lpMessage - message to display during shutdown timeout period.
  38. dwTimeout - number of seconds to delay before shutting down
  39. bForceAppsClosed - Normally applications may prevent system shutdown.
  40. - If this true, all applications are terminated unconditionally.
  41. bRebootAfterShutdown - TRUE if the system should reboot. FALSE if it should
  42. - be left in a shutdown state.
  43. Return Value:
  44. Returns ERROR_SUCCESS (0) for success; error-code for failure.
  45. --*/
  46. {
  47. DWORD Result;
  48. SHUTDOWN_CONTEXT ShutdownContext;
  49. RPC_STATUS RpcStatus ;
  50. //
  51. // If we are here, we have been called by an NT4 or Win9x machine
  52. // which doesn't know about the new interface
  53. //
  54. //
  55. // Explicitly bind to the given server.
  56. //
  57. if (!ARGUMENT_PRESENT(ServerName)) {
  58. return ERROR_SUCCESS;
  59. }
  60. RpcStatus = RpcImpersonateClient( NULL );
  61. if ( RpcStatus != 0 )
  62. {
  63. return RpcStatus ;
  64. }
  65. //
  66. // do it locally
  67. //
  68. ServerName = L"";
  69. ShutdownContext.dwTimeout = dwTimeout;
  70. ShutdownContext.bForceAppsClosed = (bForceAppsClosed != 0);
  71. ShutdownContext.bRebootAfterShutdown = (bRebootAfterShutdown != 0);
  72. //
  73. // delegate the call to the new interface
  74. //
  75. Result = BaseBindToMachineShutdownInterface(ServerName,
  76. NewShutdownCallback,
  77. lpMessage,
  78. &ShutdownContext);
  79. RevertToSelf();
  80. return Result;
  81. }
  82. ULONG
  83. BaseInitiateSystemShutdownEx(
  84. IN PREGISTRY_SERVER_NAME ServerName,
  85. IN PUNICODE_STRING lpMessage OPTIONAL,
  86. IN DWORD dwTimeout,
  87. IN BOOLEAN bForceAppsClosed,
  88. IN BOOLEAN bRebootAfterShutdown,
  89. IN DWORD dwReason
  90. )
  91. /*++
  92. Routine Description:
  93. This routine is provided for backward compatibility. It does nothing
  94. Arguments:
  95. ServerName - Name of machine this server code is running on. (Ignored)
  96. lpMessage - message to display during shutdown timeout period.
  97. dwTimeout - number of seconds to delay before shutting down
  98. bForceAppsClosed - Normally applications may prevent system shutdown.
  99. - If this true, all applications are terminated unconditionally.
  100. bRebootAfterShutdown - TRUE if the system should reboot. FALSE if it should
  101. - be left in a shutdown state.
  102. dwReason - Reason for initiating the shutdown. This reason is logged
  103. in the eventlog #6006 event.
  104. Return Value:
  105. Returns ERROR_SUCCESS (0) for success; error-code for failure.
  106. --*/
  107. {
  108. DWORD Result;
  109. SHUTDOWN_CONTEXTEX ShutdownContext;
  110. RPC_STATUS RpcStatus ;
  111. //
  112. // If we are here, we have been called by an NT4 or Win9x machine
  113. // which doesn't know about the new interface
  114. //
  115. //
  116. // Explicitly bind to the given server.
  117. //
  118. if (!ARGUMENT_PRESENT(ServerName)) {
  119. return ERROR_SUCCESS;
  120. }
  121. RpcStatus = RpcImpersonateClient( NULL );
  122. if ( RpcStatus != 0 )
  123. {
  124. return RpcStatus ;
  125. }
  126. // do it locally
  127. ServerName = L"";
  128. ShutdownContext.dwTimeout = dwTimeout;
  129. ShutdownContext.bForceAppsClosed = (bForceAppsClosed != 0);
  130. ShutdownContext.bRebootAfterShutdown = (bRebootAfterShutdown != 0);
  131. ShutdownContext.dwReason = dwReason;
  132. //
  133. // delegate the call to the new interface
  134. //
  135. Result = BaseBindToMachineShutdownInterface(ServerName,
  136. NewShutdownCallbackEx,
  137. lpMessage,
  138. &ShutdownContext);
  139. RevertToSelf();
  140. return Result;
  141. }
  142. ULONG
  143. BaseAbortSystemShutdown(
  144. IN PREGISTRY_SERVER_NAME ServerName
  145. )
  146. /*++
  147. Routine Description:
  148. This routine is provided for backward compatibility. It does nothing
  149. Arguments:
  150. ServerName - Name of machine this server code is running on. (Ignored)
  151. Return Value:
  152. Returns ERROR_SUCCESS (0) for success; error-code for failure.
  153. --*/
  154. {
  155. DWORD Result;
  156. RPC_BINDING_HANDLE binding;
  157. RPC_STATUS RpcStatus ;
  158. //
  159. // If we are here, we have been called by an NT4 or Win9x machine
  160. // which doesn't know about the new interface
  161. //
  162. //
  163. // Explicitly bind to the given server.
  164. //
  165. if (!ARGUMENT_PRESENT(ServerName)) {
  166. return ERROR_SUCCESS;
  167. }
  168. //
  169. // Call the server
  170. //
  171. RpcStatus = RpcImpersonateClient( NULL );
  172. if ( RpcStatus != 0 )
  173. {
  174. return RpcStatus ;
  175. }
  176. // do it locally
  177. ServerName = L"";
  178. //
  179. // delegate the call to the new interface
  180. //
  181. Result = BaseBindToMachineShutdownInterface(ServerName,
  182. NewAbortShutdownCallback,
  183. NULL,
  184. NULL);
  185. RevertToSelf();
  186. return Result;
  187. }