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.

198 lines
6.4 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. NTSTATUS CBAMService::Main (DWORD dwReason)
  34. {
  35. UNREFERENCED_PARAMETER(dwReason);
  36. return(STATUS_SUCCESS);
  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. if (!IsOS(OS_WOW6432))
  61. {
  62. static const TCHAR s_szDependencies[] = TEXT("TermService\0");
  63. // Now install the new service by name.
  64. status = CService::Install(CBadApplicationService::GetName(),
  65. TEXT("%SystemRoot%\\System32\\svchost.exe -k netsvcs"),
  66. NULL,
  67. NULL,
  68. TEXT("shsvcs.dll"),
  69. s_szDependencies,
  70. TEXT("netsvcs"),
  71. TEXT("BadApplicationServiceMain"),
  72. SERVICE_DEMAND_START,
  73. g_hInstance,
  74. IDS_BAMSERVER_DISPLAYNAME,
  75. IDS_BAMSERVER_DESCRIPTION);
  76. }
  77. #endif
  78. return(status);
  79. }
  80. // --------------------------------------------------------------------------
  81. // ::DllUnregisterServer
  82. //
  83. // Arguments: <none>
  84. //
  85. // Returns: HRESULT
  86. //
  87. // Purpose: Unregister entry point to allow the BAM server to uninstall
  88. // itself from the registry.
  89. //
  90. // History: 2000-12-04 vtan created
  91. // 2001-01-02 vtan scoped to a C++ class
  92. // --------------------------------------------------------------------------
  93. NTSTATUS CBAMService::UnregisterServer (void)
  94. {
  95. (NTSTATUS)CService::Remove(CBadApplicationService::GetName());
  96. return(STATUS_SUCCESS);
  97. }
  98. // --------------------------------------------------------------------------
  99. // ::BadApplicationServiceMain
  100. //
  101. // Arguments: dwArgc = Number of arguments.
  102. // lpszArgv = Argument array.
  103. //
  104. // Returns: <none>
  105. //
  106. // Purpose: ServiceMain entry point for BAM server.
  107. //
  108. // History: 2000-11-28 vtan created
  109. // 2001-01-02 vtan scoped to the BAM service
  110. // --------------------------------------------------------------------------
  111. #ifdef _X86_
  112. void WINAPI BadApplicationServiceMain (DWORD dwArgc, LPWSTR *lpszArgv)
  113. {
  114. UNREFERENCED_PARAMETER(dwArgc);
  115. UNREFERENCED_PARAMETER(lpszArgv);
  116. NTSTATUS status;
  117. // Because svchost doesn't unload the DLL ever we need to call static
  118. // initializers here so that if the service is stopped and restarted
  119. // the static member variables can be initialized. Statically destruct
  120. // what was initialized. The initialize code accounts for already
  121. // initialized member variables.
  122. status = CBadApplicationAPIRequest::StaticInitialize(g_hInstance);
  123. if (NT_SUCCESS(status))
  124. {
  125. CBadApplicationAPIServer *pBadApplicationAPIServer;
  126. pBadApplicationAPIServer = new CBadApplicationAPIServer;
  127. if (pBadApplicationAPIServer != NULL)
  128. {
  129. CAPIConnection *pAPIConnection;
  130. pAPIConnection = new CAPIConnection(pBadApplicationAPIServer);
  131. if (pAPIConnection != NULL)
  132. {
  133. CBadApplicationService *pBadApplicationService;
  134. pBadApplicationService = new CBadApplicationService(pAPIConnection, pBadApplicationAPIServer);
  135. if (pBadApplicationService != NULL)
  136. {
  137. static SID_IDENTIFIER_AUTHORITY s_SecurityWorldAuthority = SECURITY_WORLD_SID_AUTHORITY;
  138. PSID pSIDWorld;
  139. // Explicitly add access for S-1-1-0 <everybody> as PORT_CONNECT.
  140. if (AllocateAndInitializeSid(&s_SecurityWorldAuthority,
  141. 1,
  142. SECURITY_WORLD_RID,
  143. 0, 0, 0, 0, 0, 0, 0,
  144. &pSIDWorld) != FALSE)
  145. {
  146. TSTATUS(pAPIConnection->AddAccess(pSIDWorld, PORT_CONNECT));
  147. (void*)FreeSid(pSIDWorld);
  148. }
  149. pBadApplicationService->Start();
  150. pBadApplicationService->Release();
  151. }
  152. pAPIConnection->Release();
  153. }
  154. pBadApplicationAPIServer->Release();
  155. }
  156. TSTATUS(CBadApplicationAPIRequest::StaticTerminate());
  157. }
  158. }
  159. #endif /* _X86_ */