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.

129 lines
3.0 KiB

  1. /*++
  2. Copyright (c) 1989-2001 Microsoft Corporation
  3. Module Name:
  4. smbsvc.c
  5. Abstract:
  6. This the user-mode proxy for the kernel mode DNS resolver.
  7. features:
  8. 1. Multi-threaded
  9. NBT4 use a single-threaded design. The DNS name resolution is a performance blocker.
  10. When a connection request is being served by LmhSvc, all the other requests requiring
  11. DNS resolution will be blocked.
  12. 2. IPv6 and IPv4 compatiable
  13. 3. can be run either as a service or standalone executable (for debug purpose)
  14. When started as service, debug spew is sent to debugger.
  15. When started as a standalong executable, the debug spew is sent to either
  16. the console or debugger. smbhelper.c contain the _main for the standardalone
  17. executable.
  18. Author:
  19. Jiandong Ruan
  20. Revision History:
  21. --*/
  22. #include "precomp.h"
  23. #include <lm.h>
  24. #include <netevent.h>
  25. #include <ws2tcpip.h>
  26. #include <mstcpip.h>
  27. #include <ipexport.h>
  28. #include <winsock2.h>
  29. #include <icmpapi.h>
  30. #include "ping6.h"
  31. static HANDLE hService;
  32. static SERVICE_STATUS SvcStatus;
  33. DWORD
  34. SmbsvcUpdateStatus(
  35. VOID
  36. )
  37. {
  38. DWORD Error = ERROR_SUCCESS;
  39. if (NULL == hService) {
  40. return ERROR_SUCCESS;
  41. }
  42. SvcStatus.dwCheckPoint++;
  43. if (!SetServiceStatus(hService, &SvcStatus)) {
  44. Error = GetLastError();
  45. }
  46. return Error;
  47. }
  48. VOID
  49. SvcCtrlHandler(
  50. IN DWORD controlcode
  51. )
  52. {
  53. ULONG i;
  54. switch (controlcode) {
  55. case SERVICE_CONTROL_STOP:
  56. SvcStatus.dwCurrentState = SERVICE_STOP_PENDING;
  57. SmbsvcUpdateStatus();
  58. SmbStopService(SmbsvcUpdateStatus);
  59. SvcStatus.dwCurrentState = SERVICE_STOPPED;
  60. SvcStatus.dwCheckPoint = 0;
  61. SvcStatus.dwWaitHint = 0;
  62. /* fall through */
  63. case SERVICE_CONTROL_INTERROGATE:
  64. SmbsvcUpdateStatus();
  65. break;
  66. case SERVICE_CONTROL_CONTINUE:
  67. case SERVICE_CONTROL_PAUSE:
  68. case SERVICE_CONTROL_SHUTDOWN:
  69. default:
  70. ASSERT(0);
  71. break;
  72. }
  73. }
  74. VOID
  75. ServiceMain (
  76. IN DWORD argc,
  77. IN LPTSTR *argv
  78. )
  79. {
  80. DWORD Error;
  81. #if DBG
  82. SmbSetTraceRoutine(DbgPrint);
  83. #endif
  84. hService = RegisterServiceCtrlHandler(L"SmbSvc", SvcCtrlHandler);
  85. if (hService == NULL) {
  86. return;
  87. }
  88. SvcStatus.dwServiceType = SERVICE_WIN32;
  89. SvcStatus.dwCurrentState = SERVICE_START_PENDING;
  90. SvcStatus.dwControlsAccepted = SERVICE_ACCEPT_STOP;
  91. SvcStatus.dwWin32ExitCode = 0;
  92. SvcStatus.dwServiceSpecificExitCode = 0;
  93. SvcStatus.dwCheckPoint = 0;
  94. SvcStatus.dwWaitHint = 20000; // 20 seconds
  95. SmbsvcUpdateStatus();
  96. Error = SmbStartService(0, SmbsvcUpdateStatus);
  97. if (ERROR_SUCCESS != Error) {
  98. SvcStatus.dwCurrentState = SERVICE_STOPPED;
  99. } else {
  100. SvcStatus.dwCurrentState = SERVICE_RUNNING;
  101. }
  102. SmbsvcUpdateStatus();
  103. }