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.

234 lines
5.8 KiB

  1. /*++
  2. Copyright(c) 1995 Microsoft Corporation
  3. MODULE NAME
  4. service.c
  5. ABSTRACT
  6. Service controller procedures for the automatic connection service.
  7. AUTHOR
  8. Anthony Discolo (adiscolo) 08-May-1995
  9. REVISION HISTORY
  10. --*/
  11. #define UNICODE
  12. #define _UNICODE
  13. #include <nt.h>
  14. #include <ntrtl.h>
  15. #include <nturtl.h>
  16. #include <stdlib.h>
  17. #include <windows.h>
  18. #include <stdio.h>
  19. #include <wchar.h>
  20. #include <npapi.h>
  21. #include <ipexport.h>
  22. #include <acd.h>
  23. #include "init.h"
  24. #include "reg.h"
  25. #include "misc.h"
  26. #include "table.h"
  27. #include "addrmap.h"
  28. #include "imperson.h"
  29. #include "rtutils.h"
  30. extern HANDLE hNewFusG;
  31. //
  32. // Global variables
  33. //
  34. DWORD Checkpoint = 1;
  35. SERVICE_STATUS_HANDLE hService;
  36. //
  37. // Imported routines
  38. //
  39. VOID AcsDoService();
  40. DWORD
  41. WINAPI
  42. ServiceHandlerEx(
  43. DWORD fdwControl,
  44. DWORD fdwEventType,
  45. LPVOID lpEventData,
  46. LPVOID lpContext)
  47. {
  48. SERVICE_STATUS status;
  49. DWORD dwRetCode = ERROR_SUCCESS;
  50. WTSSESSION_NOTIFICATION * pNotify;
  51. RASAUTO_TRACE2(
  52. "ServiceHandlerEx enter. ctrl=%d type=%d",
  53. fdwControl,
  54. fdwEventType);
  55. ZeroMemory (&status, sizeof(status));
  56. status.dwServiceType = SERVICE_WIN32_SHARE_PROCESS;
  57. switch (fdwControl)
  58. {
  59. case SERVICE_CONTROL_PAUSE:
  60. case SERVICE_CONTROL_CONTINUE:
  61. case SERVICE_CONTROL_INTERROGATE:
  62. RASAUTO_TRACE("ServiceHandlerEx: pause/cont/interrogate");
  63. status.dwCurrentState = SERVICE_RUNNING;
  64. status.dwControlsAccepted = SERVICE_ACCEPT_STOP |
  65. SERVICE_ACCEPT_SHUTDOWN |
  66. SERVICE_ACCEPT_POWEREVENT |
  67. SERVICE_ACCEPT_SESSIONCHANGE;
  68. status.dwCheckPoint = Checkpoint++;
  69. SetServiceStatus(hService, &status);
  70. break;
  71. case SERVICE_CONTROL_STOP:
  72. case SERVICE_CONTROL_SHUTDOWN:
  73. RASAUTO_TRACE("ServiceHandlerEx: stop/shutdown");
  74. status.dwCurrentState = SERVICE_STOP_PENDING;
  75. SetServiceStatus(hService, &status);
  76. //
  77. // Stop the service.
  78. //
  79. AcsTerminate();
  80. break;
  81. case SERVICE_CONTROL_SESSIONCHANGE:
  82. RASAUTO_TRACE1("ServiceHandlerEx: Session Change %d", fdwEventType);
  83. if (fdwEventType == WTS_CONSOLE_CONNECT)
  84. {
  85. pNotify = (WTSSESSION_NOTIFICATION*)lpEventData;
  86. if (pNotify)
  87. {
  88. SetCurrentLoginSession(pNotify->dwSessionId);
  89. SetEvent(hNewFusG);
  90. }
  91. }
  92. break;
  93. case SERVICE_CONTROL_POWEREVENT:
  94. {
  95. RASAUTO_TRACE("ServiceHandlerEx: power event");
  96. switch(fdwEventType)
  97. {
  98. case PBT_APMRESUMESTANDBY:
  99. case PBT_APMRESUMESUSPEND:
  100. case PBT_APMRESUMECRITICAL:
  101. case PBT_APMRESUMEAUTOMATIC:
  102. {
  103. //
  104. // When the machine is resuming from hibernation
  105. // clear the disabled addresses
  106. //
  107. ResetDisabledAddresses();
  108. break;
  109. }
  110. default:
  111. {
  112. break;
  113. }
  114. }
  115. }
  116. break;
  117. }
  118. return ERROR_SUCCESS;
  119. } // ServiceHandler
  120. VOID
  121. ServiceMain(
  122. DWORD dwArgc,
  123. LPWSTR *lpszArgv
  124. )
  125. /*++
  126. DESCRIPTION
  127. Perform initialization and start the main loop for ics.dll.
  128. ARGUMENTS
  129. hService: the service handle created for us by rasman.exe
  130. pStatus: a pointer to the service status descriptor initialize
  131. for us by rasman.exe
  132. dwArgc: ignored
  133. lpszArgv: ignored
  134. RETURN VALUE
  135. None.
  136. --*/
  137. {
  138. SERVICE_STATUS status;
  139. DWORD dwError;
  140. UNREFERENCED_PARAMETER(dwArgc);
  141. UNREFERENCED_PARAMETER(lpszArgv);
  142. ZeroMemory (&status, sizeof(status));
  143. status.dwServiceType = SERVICE_WIN32_SHARE_PROCESS;
  144. // Register the control request handler.
  145. //
  146. hService = RegisterServiceCtrlHandlerEx(TEXT("rasauto"),
  147. ServiceHandlerEx,
  148. NULL);
  149. if (hService)
  150. {
  151. status.dwCurrentState = SERVICE_START_PENDING;
  152. SetServiceStatus(hService, &status);
  153. //
  154. // Perform initialization.
  155. //
  156. dwError = AcsInitialize();
  157. if (dwError == ERROR_SUCCESS) {
  158. //
  159. // Initialization succeeded. Update status.
  160. //
  161. status.dwControlsAccepted = SERVICE_ACCEPT_STOP
  162. | SERVICE_ACCEPT_POWEREVENT
  163. | SERVICE_ACCEPT_SESSIONCHANGE;
  164. status.dwCurrentState = SERVICE_RUNNING;
  165. SetServiceStatus(hService, &status);
  166. //
  167. // This is where the real work gets done.
  168. // It will return only after the service
  169. // is stopped.
  170. //
  171. AcsDoService();
  172. //
  173. // Update return code status.
  174. //
  175. status.dwWin32ExitCode = NO_ERROR;
  176. status.dwServiceSpecificExitCode = 0;
  177. }
  178. else {
  179. //
  180. // Initialization failed. Update status.
  181. //
  182. status.dwWin32ExitCode = dwError;
  183. }
  184. status.dwControlsAccepted = 0;
  185. status.dwCurrentState = SERVICE_STOPPED;
  186. SetServiceStatus(hService, &status);
  187. }
  188. } // ServiceMain