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.

199 lines
6.6 KiB

  1. // --------------------------------------------------------------------------
  2. // Module Name: BAMService.cpp
  3. //
  4. // Copyright (c) 2001, Microsoft Corporation
  5. //
  6. // This file contains functions that are called from the shell services DLL
  7. // to interact with the BAM service.
  8. //
  9. // History: 2001-01-02 vtan created
  10. // --------------------------------------------------------------------------
  11. #include "StandardHeader.h"
  12. #include "BAMService.h"
  13. #include <shlwapi.h>
  14. #include <shlwapip.h>
  15. #include "BadApplicationAPIRequest.h"
  16. #include "BadApplicationAPIServer.h"
  17. #include "BadApplicationService.h"
  18. #include "Resource.h"
  19. extern HINSTANCE g_hInstance;
  20. // --------------------------------------------------------------------------
  21. // CThemeService::Main
  22. //
  23. // Arguments: See the platform SDK under DllMain.
  24. //
  25. // Returns: See the platform SDK under DllMain.
  26. //
  27. // Purpose: Performs initialization and clean up on process attach and
  28. // detach. Not interested in anything else.
  29. //
  30. // History: 2000-10-12 vtan created
  31. // 2001-01-02 vtan scoped to a C++ class
  32. // --------------------------------------------------------------------------
  33. BOOL CBAMService::Main (DWORD dwReason)
  34. {
  35. UNREFERENCED_PARAMETER(dwReason);
  36. return TRUE;
  37. }
  38. // --------------------------------------------------------------------------
  39. // ::DllRegisterServer
  40. //
  41. // Arguments: <none>
  42. //
  43. // Returns: NTSTATUS
  44. //
  45. // Purpose: Register entry point to allow the BAM server to install
  46. // itself into the registry.
  47. //
  48. // History: 2000-12-04 vtan created
  49. // 2001-01-02 vtan scoped to a C++ class
  50. // --------------------------------------------------------------------------
  51. NTSTATUS CBAMService::RegisterServer (void)
  52. {
  53. NTSTATUS status;
  54. status = STATUS_SUCCESS;
  55. #ifdef _WIN64
  56. // In upgrade cases for 64-bit, remove the service
  57. (NTSTATUS)CService::Remove(CBadApplicationService::GetName());
  58. #else
  59. // This is 32-bit only. Check if this is REALLY 32-bit and not 32-bit on 64-bit.
  60. // This will also not be installed on any server, as it is irrelevent.
  61. if (!IsOS(OS_WOW6432) && !IsOS(OS_ANYSERVER))
  62. {
  63. static const TCHAR s_szDependencies[] = TEXT("TermService\0");
  64. // Now install the new service by name.
  65. status = CService::Install(CBadApplicationService::GetName(),
  66. TEXT("%SystemRoot%\\System32\\svchost.exe -k netsvcs"),
  67. NULL,
  68. NULL,
  69. TEXT("shsvcs.dll"),
  70. s_szDependencies,
  71. TEXT("netsvcs"),
  72. TEXT("BadApplicationServiceMain"),
  73. SERVICE_DEMAND_START,
  74. g_hInstance,
  75. IDS_BAMSERVER_DISPLAYNAME,
  76. IDS_BAMSERVER_DESCRIPTION);
  77. }
  78. #endif
  79. return(status);
  80. }
  81. // --------------------------------------------------------------------------
  82. // ::DllUnregisterServer
  83. //
  84. // Arguments: <none>
  85. //
  86. // Returns: HRESULT
  87. //
  88. // Purpose: Unregister entry point to allow the BAM server to uninstall
  89. // itself from the registry.
  90. //
  91. // History: 2000-12-04 vtan created
  92. // 2001-01-02 vtan scoped to a C++ class
  93. // --------------------------------------------------------------------------
  94. NTSTATUS CBAMService::UnregisterServer (void)
  95. {
  96. (NTSTATUS)CService::Remove(CBadApplicationService::GetName());
  97. return(STATUS_SUCCESS);
  98. }
  99. // --------------------------------------------------------------------------
  100. // ::BadApplicationServiceMain
  101. //
  102. // Arguments: dwArgc = Number of arguments.
  103. // lpszArgv = Argument array.
  104. //
  105. // Returns: <none>
  106. //
  107. // Purpose: ServiceMain entry point for BAM server.
  108. //
  109. // History: 2000-11-28 vtan created
  110. // 2001-01-02 vtan scoped to the BAM service
  111. // --------------------------------------------------------------------------
  112. #ifdef _X86_
  113. void WINAPI BadApplicationServiceMain (DWORD dwArgc, LPWSTR *lpszArgv)
  114. {
  115. UNREFERENCED_PARAMETER(dwArgc);
  116. UNREFERENCED_PARAMETER(lpszArgv);
  117. NTSTATUS status;
  118. // Because svchost doesn't unload the DLL ever we need to call static
  119. // initializers here so that if the service is stopped and restarted
  120. // the static member variables can be initialized. Statically destruct
  121. // what was initialized. The initialize code accounts for already
  122. // initialized member variables.
  123. status = CBadApplicationAPIRequest::StaticInitialize(g_hInstance);
  124. if (NT_SUCCESS(status))
  125. {
  126. CBadApplicationAPIServer *pBadApplicationAPIServer;
  127. pBadApplicationAPIServer = new CBadApplicationAPIServer;
  128. if (pBadApplicationAPIServer != NULL)
  129. {
  130. CAPIConnection *pAPIConnection;
  131. pAPIConnection = new CAPIConnection(pBadApplicationAPIServer);
  132. if (pAPIConnection != NULL)
  133. {
  134. CBadApplicationService *pBadApplicationService;
  135. pBadApplicationService = new CBadApplicationService(pAPIConnection, pBadApplicationAPIServer);
  136. if (pBadApplicationService != NULL)
  137. {
  138. static SID_IDENTIFIER_AUTHORITY s_SecurityWorldAuthority = SECURITY_WORLD_SID_AUTHORITY;
  139. PSID pSIDWorld;
  140. // Explicitly add access for S-1-1-0 <everybody> as PORT_CONNECT.
  141. if (AllocateAndInitializeSid(&s_SecurityWorldAuthority,
  142. 1,
  143. SECURITY_WORLD_RID,
  144. 0, 0, 0, 0, 0, 0, 0,
  145. &pSIDWorld) != FALSE)
  146. {
  147. TSTATUS(pAPIConnection->AddAccess(pSIDWorld, PORT_CONNECT));
  148. (void*)FreeSid(pSIDWorld);
  149. }
  150. pBadApplicationService->Start();
  151. pBadApplicationService->Release();
  152. }
  153. pAPIConnection->Release();
  154. }
  155. pBadApplicationAPIServer->Release();
  156. }
  157. TSTATUS(CBadApplicationAPIRequest::StaticTerminate());
  158. }
  159. }
  160. #endif /* _X86_ */