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.

264 lines
5.9 KiB

  1. /*++
  2. Copyright (c) 1998 Microsoft Corporation
  3. Module Name:
  4. scesrv.cpp
  5. Abstract:
  6. SCE Engine initialization
  7. Author:
  8. Jin Huang (jinhuang) 23-Jan-1998 created
  9. --*/
  10. #include "serverp.h"
  11. #include <locale.h>
  12. #include "authz.h"
  13. #include <alloca.h>
  14. extern HINSTANCE MyModuleHandle;
  15. AUTHZ_RESOURCE_MANAGER_HANDLE ghAuthzResourceManager = NULL;
  16. #include "scesrv.h"
  17. /*=============================================================================
  18. ** Procedure Name: DllMain
  19. **
  20. ** Arguments:
  21. **
  22. **
  23. **
  24. ** Returns: 0 = SUCCESS
  25. ** !0 = ERROR
  26. **
  27. ** Abstract:
  28. **
  29. ** Notes:
  30. **
  31. **===========================================================================*/
  32. BOOL WINAPI DllMain(
  33. IN HANDLE DllHandle,
  34. IN ULONG ulReason,
  35. IN LPVOID Reserved )
  36. {
  37. switch(ulReason) {
  38. case DLL_PROCESS_ATTACH:
  39. MyModuleHandle = (HINSTANCE)DllHandle;
  40. //
  41. // initizlize server and thread data
  42. //
  43. setlocale(LC_ALL, ".OCP");
  44. (VOID) ScepInitServerData();
  45. #if DBG == 1
  46. DebugInitialize();
  47. #endif
  48. //
  49. // initialize dynamic stack allocation
  50. //
  51. SafeAllocaInitialize(SAFEALLOCA_USE_DEFAULT,
  52. SAFEALLOCA_USE_DEFAULT,
  53. NULL,
  54. NULL
  55. );
  56. break;
  57. case DLL_THREAD_ATTACH:
  58. break;
  59. case DLL_PROCESS_DETACH:
  60. (VOID) ScepUninitServerData();
  61. #if DBG == 1
  62. DebugUninit();
  63. #endif
  64. break;
  65. case DLL_THREAD_DETACH:
  66. break;
  67. }
  68. return TRUE;
  69. }
  70. DWORD
  71. WINAPI
  72. ScesrvInitializeServer(
  73. IN PSVCS_START_RPC_SERVER pStartRpcServer
  74. )
  75. {
  76. NTSTATUS NtStatus;
  77. NTSTATUS StatusConvert = STATUS_SUCCESS;
  78. DWORD rc;
  79. DWORD rcConvert;
  80. PWSTR pszDrives = NULL;
  81. DWORD dwWchars = 0;
  82. NtStatus = ScepStartServerServices(); // pStartRpcServer );
  83. rc = RtlNtStatusToDosError(NtStatus);
  84. /* remove code to check "DemoteInProgress" value and trigger policy propagation
  85. because demoting a DC will always have policy re-propagated at reboot
  86. DWORD dwDemoteInProgress=0;
  87. ScepRegQueryIntValue(
  88. HKEY_LOCAL_MACHINE,
  89. SCE_ROOT_PATH,
  90. TEXT("DemoteInProgress"),
  91. &dwDemoteInProgress
  92. );
  93. */
  94. //
  95. // if this key exists, some FAT->NTFS conversion happened and we need to set security
  96. // so spawn a thread to configure security after autostart service event is signalled.
  97. // LSA etc. are guaranteed to be started when this event is signalled
  98. //
  99. DWORD dwRegType = REG_NONE;
  100. rcConvert = ScepRegQueryValue(
  101. HKEY_LOCAL_MACHINE,
  102. SCE_ROOT_PATH,
  103. L"FatNtfsConvertedDrives",
  104. (PVOID *) &pszDrives,
  105. &dwRegType
  106. );
  107. //
  108. // at least one C: type drive should be there
  109. //
  110. if ( dwRegType != REG_MULTI_SZ || (pszDrives && wcslen(pszDrives) < 2) ) {
  111. if (pszDrives) {
  112. LocalFree(pszDrives);
  113. }
  114. rcConvert = ERROR_INVALID_PARAMETER;
  115. }
  116. //
  117. // if there is at least one drive scheduled to set security (dwWchars >= 4), pass this info
  118. // to the spawned thread along with an indication that we are in reboot (so it can loop
  119. // through all drives as queried)
  120. //
  121. if (rcConvert == ERROR_SUCCESS ) {
  122. if (pszDrives) {
  123. //
  124. // need to spawn some other event waiter thread that will call this function
  125. // thread will free pszDrives
  126. //
  127. StatusConvert = RtlQueueWorkItem(
  128. ScepWaitForServicesEventAndConvertSecurityThreadFunc,
  129. pszDrives,
  130. WT_EXECUTEONLYONCE | WT_EXECUTELONGFUNCTION
  131. ) ;
  132. }
  133. else if ( pszDrives ) {
  134. LocalFree( pszDrives );
  135. }
  136. }
  137. if ( rcConvert == ERROR_SUCCESS && pszDrives ) {
  138. //
  139. // since event log is not ready, log success or error
  140. // to logfile only if there is some drive to convert
  141. //
  142. WCHAR szWinDir[MAX_PATH*2 + 1];
  143. WCHAR LogFileName[MAX_PATH + 1];
  144. szWinDir[0] = L'\0';
  145. GetSystemWindowsDirectory( szWinDir, MAX_PATH );
  146. //
  147. // same log file is used by this thread as well as the actual configuration
  148. // thread ScepWaitForServicesEventAndConvertSecurityThreadFunc - so use it
  149. // here and close it
  150. //
  151. LogFileName[0] = L'\0';
  152. wcscpy(LogFileName, szWinDir);
  153. wcscat(LogFileName, L"\\security\\logs\\convert.log");
  154. ScepEnableDisableLog(TRUE);
  155. ScepSetVerboseLog(3);
  156. if ( ScepLogInitialize( LogFileName ) == ERROR_INVALID_NAME ) {
  157. ScepLogOutput3(1,0, SCEDLL_LOGFILE_INVALID, LogFileName );
  158. }
  159. rcConvert = RtlNtStatusToDosError(StatusConvert);
  160. ScepLogOutput3(0,0, SCEDLL_CONVERT_STATUS_CREATING_THREAD, rcConvert, L"ScepWaitForServicesEventAndConvertSecurityThreadFunc");
  161. ScepLogClose();
  162. }
  163. //
  164. // use AUTHZ for LSA Policy Setting access check - don't care about error now
  165. //
  166. AuthzInitializeResourceManager(
  167. 0,
  168. NULL,
  169. NULL,
  170. NULL,
  171. L"SCE",
  172. &ghAuthzResourceManager );
  173. return(rc);
  174. }
  175. DWORD
  176. WINAPI
  177. ScesrvTerminateServer(
  178. IN PSVCS_STOP_RPC_SERVER pStopRpcServer
  179. )
  180. {
  181. NTSTATUS NtStatus;
  182. DWORD rc;
  183. NtStatus = ScepStopServerServices( TRUE ); //, pStopRpcServer );
  184. rc = RtlNtStatusToDosError(NtStatus);
  185. if (ghAuthzResourceManager)
  186. AuthzFreeResourceManager( ghAuthzResourceManager );
  187. return(rc);
  188. }