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.

289 lines
5.9 KiB

  1. /*++
  2. Copyright (C) 1992-98 Microsft Corporation. All rights reserved.
  3. Module Name:
  4. dllinit.c
  5. Abstract:
  6. This file contains init code called from DLL's init routine
  7. Author:
  8. Gurdeep Singh Pall (gurdeep) 06-Jun-1997
  9. Revision History:
  10. Miscellaneous Modifications - raos 31-Dec-1997
  11. --*/
  12. #include <nt.h>
  13. #include <ntrtl.h>
  14. #include <nturtl.h>
  15. #include <rasman.h>
  16. #include <wanpub.h>
  17. #include <ntlsa.h>
  18. #include <ntmsv1_0.h>
  19. #include <raserror.h>
  20. #include <rasppp.h>
  21. #include <media.h>
  22. #include <devioctl.h>
  23. #include <stdio.h>
  24. #include <stdarg.h>
  25. #include <stdlib.h>
  26. #include <string.h>
  27. #include "defs.h"
  28. #include "structs.h"
  29. #include "protos.h"
  30. #include "globals.h"
  31. /*++
  32. Routine Description
  33. Function: Used to close any open ports when rasman exits
  34. Arguments
  35. Return Value
  36. FALSE to allow other handlers to run.
  37. --*/
  38. BOOL
  39. HandlerRoutine (DWORD ctrltype)
  40. {
  41. WORD i ;
  42. BYTE buffer [10] ;
  43. if (ctrltype == CTRL_SHUTDOWN_EVENT)
  44. {
  45. }
  46. return FALSE ;
  47. }
  48. /*++
  49. Routine Description
  50. Used to check if the service is already running: if not,
  51. to start it.
  52. Arguments
  53. Return Value
  54. SUCCESS
  55. 1 (failure to start)
  56. Error codes from service control APIs. "
  57. --*/
  58. /*
  59. DWORD
  60. RasmanServiceCheck()
  61. {
  62. SC_HANDLE schandle ;
  63. SC_HANDLE svchandle ;
  64. SERVICE_STATUS status ;
  65. STARTUPINFO startupinfo ;
  66. //
  67. // If this is the Service DLL attaching, let it: no
  68. // initializations required. NOTE: We do not increment
  69. // AttachedCount for RASMAN service: its used *only*
  70. // for rasman client processes like UI, Gateway, etc.
  71. //
  72. GetStartupInfo(&startupinfo) ;
  73. if (strstr (startupinfo.lpTitle, SCREG_EXE_NAME) != NULL)
  74. {
  75. return SUCCESS ;
  76. }
  77. if (strstr (startupinfo.lpTitle, RASMAN_EXE_NAME) != NULL)
  78. {
  79. SetConsoleCtrlHandler (HandlerRoutine, TRUE) ;
  80. return SUCCESS ;
  81. }
  82. //
  83. // This is put in as a work-around for the SC bug which
  84. // does not allow OpenService call to be made when
  85. // Remoteaccess is starting
  86. //
  87. if (strstr (startupinfo.lpTitle, "rassrv.exe") != NULL)
  88. {
  89. return SUCCESS ;
  90. }
  91. //
  92. // Get handles to check status of service and (if it
  93. // is not started -) to start it.
  94. //
  95. if ( !(schandle = OpenSCManager(
  96. NULL,
  97. NULL,
  98. SC_MANAGER_CONNECT))
  99. || !(svchandle = OpenService(
  100. schandle,
  101. RASMAN_SERVICE_NAME,
  102. SERVICE_START
  103. |SERVICE_QUERY_STATUS)))
  104. {
  105. DWORD retcode;
  106. retcode = GetLastError();
  107. #if DBG
  108. RasmanOutputDebug("RASMAN: Failed to openservice %s. error=%d\n",
  109. RASMAN_SERVICE_NAME,
  110. retcode );
  111. #endif
  112. if (ERROR_SERVICE_DOES_NOT_EXIST == retcode)
  113. {
  114. #if DBG
  115. RasmanOutputDebug ("RASMAN: RAS is not installed. %d\n",
  116. retcode);
  117. #endif
  118. //
  119. // let rasman.dll load eventhough RAS is not
  120. // installed. Any Ras call when made through
  121. // this dll will fail with rasman service not
  122. // installed error.
  123. //
  124. return SUCCESS;
  125. }
  126. return retcode;
  127. }
  128. //
  129. // Check if service is already starting:
  130. //
  131. if (QueryServiceStatus(svchandle,&status) == FALSE)
  132. {
  133. DWORD retcode;
  134. retcode = GetLastError();
  135. #if DBG
  136. RasmanOutputDebug ("RASMAN: Failed to query rasman. %d\n",
  137. retcode );
  138. #endif
  139. return retcode;
  140. }
  141. switch (status.dwCurrentState)
  142. {
  143. case SERVICE_STOPPED:
  144. break ;
  145. case SERVICE_START_PENDING:
  146. case SERVICE_RUNNING:
  147. break ;
  148. default:
  149. return 1 ;
  150. }
  151. CloseServiceHandle (schandle) ;
  152. CloseServiceHandle (svchandle) ;
  153. return SUCCESS ;
  154. } */
  155. /*++
  156. Routine Description
  157. Waits until the rasman service is stopped before returning.
  158. Arguments
  159. Return Value
  160. Nothing.
  161. --*/
  162. VOID
  163. WaitForRasmanServiceStop ()
  164. {
  165. SC_HANDLE schandle = NULL;
  166. SC_HANDLE svchandle = NULL;
  167. SERVICE_STATUS status ;
  168. DWORD i;
  169. //
  170. // Get handles to check status of service
  171. //
  172. if ( !(schandle = OpenSCManager(
  173. NULL,
  174. NULL,
  175. SC_MANAGER_CONNECT))
  176. || !(svchandle = OpenService(
  177. schandle,
  178. RASMAN_SERVICE_NAME,
  179. SERVICE_START
  180. | SERVICE_QUERY_STATUS)))
  181. {
  182. GetLastError() ;
  183. goto done ;
  184. }
  185. //
  186. // Loop here for the service to stop.
  187. //
  188. for (i = 0; i < 60; i++)
  189. {
  190. //
  191. // Check if service is already starting:
  192. //
  193. if (QueryServiceStatus(svchandle,&status) == FALSE)
  194. {
  195. GetLastError () ;
  196. goto done ;
  197. }
  198. switch (status.dwCurrentState)
  199. {
  200. case SERVICE_STOPPED:
  201. goto done ;
  202. case SERVICE_STOP_PENDING:
  203. case SERVICE_RUNNING:
  204. Sleep (250L) ;
  205. break ;
  206. default:
  207. goto done ;
  208. }
  209. }
  210. done:
  211. if(NULL != schandle)
  212. {
  213. CloseServiceHandle(schandle);
  214. }
  215. if(NULL != svchandle)
  216. {
  217. CloseServiceHandle(svchandle);
  218. }
  219. return;
  220. }
  221.