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.

254 lines
6.0 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. */
  87. //
  88. // if this key exists, some FAT->NTFS conversion happened and we need to set security
  89. // so spawn a thread to configure security after autostart service event is signalled.
  90. // LSA etc. are guaranteed to be started when this event is signalled
  91. //
  92. DWORD dwRegType = REG_NONE;
  93. rcConvert = ScepRegQueryValue(
  94. HKEY_LOCAL_MACHINE,
  95. SCE_ROOT_PATH,
  96. L"FatNtfsConvertedDrives",
  97. (PVOID *) &pszDrives,
  98. &dwRegType,
  99. NULL
  100. );
  101. //
  102. // at least one C: type drive should be there
  103. //
  104. if ( dwRegType != REG_MULTI_SZ || (pszDrives && wcslen(pszDrives) < 2) ) {
  105. if (pszDrives) {
  106. LocalFree(pszDrives);
  107. }
  108. rcConvert = ERROR_INVALID_PARAMETER;
  109. }
  110. //
  111. // if there is at least one drive scheduled to set security (dwWchars >= 4), pass this info
  112. // to the spawned thread along with an indication that we are in reboot (so it can loop
  113. // through all drives as queried)
  114. //
  115. if (rcConvert == ERROR_SUCCESS ) {
  116. if (pszDrives) {
  117. //
  118. // need to spawn some other event waiter thread that will call this function
  119. // thread will free pszDrives
  120. //
  121. StatusConvert = RtlQueueWorkItem(
  122. ScepWaitForServicesEventAndConvertSecurityThreadFunc,
  123. pszDrives,
  124. WT_EXECUTEONLYONCE | WT_EXECUTELONGFUNCTION
  125. ) ;
  126. }
  127. else if ( pszDrives ) {
  128. LocalFree( pszDrives );
  129. }
  130. }
  131. if ( rcConvert == ERROR_SUCCESS && pszDrives ) {
  132. //
  133. // since event log is not ready, log success or error
  134. // to logfile only if there is some drive to convert
  135. //
  136. WCHAR LogFileName[MAX_PATH + 50];
  137. LogFileName[0] = L'\0';
  138. GetSystemWindowsDirectory( LogFileName, MAX_PATH );
  139. LogFileName[MAX_PATH] = L'\0';
  140. //
  141. // same log file is used by this thread as well as the actual configuration
  142. // thread ScepWaitForServicesEventAndConvertSecurityThreadFunc - so use it
  143. // here and close it
  144. //
  145. wcscat(LogFileName, L"\\security\\logs\\convert.log");
  146. ScepEnableDisableLog(TRUE);
  147. ScepSetVerboseLog(3);
  148. if ( ScepLogInitialize( LogFileName ) == ERROR_INVALID_NAME ) {
  149. ScepLogOutput3(1,0, SCEDLL_LOGFILE_INVALID, LogFileName );
  150. }
  151. rcConvert = RtlNtStatusToDosError(StatusConvert);
  152. ScepLogOutput3(0,0, SCEDLL_CONVERT_STATUS_CREATING_THREAD, rcConvert, L"ScepWaitForServicesEventAndConvertSecurityThreadFunc");
  153. ScepLogClose();
  154. }
  155. //
  156. // use AUTHZ for LSA Policy Setting access check - don't care about error now
  157. //
  158. AuthzInitializeResourceManager(
  159. 0,
  160. NULL,
  161. NULL,
  162. NULL,
  163. L"SCE",
  164. &ghAuthzResourceManager );
  165. return(rc);
  166. }
  167. DWORD
  168. WINAPI
  169. ScesrvTerminateServer(
  170. IN PSVCS_STOP_RPC_SERVER pStopRpcServer
  171. )
  172. {
  173. NTSTATUS NtStatus;
  174. DWORD rc;
  175. NtStatus = ScepStopServerServices( TRUE ); //, pStopRpcServer );
  176. rc = RtlNtStatusToDosError(NtStatus);
  177. if (ghAuthzResourceManager)
  178. AuthzFreeResourceManager( ghAuthzResourceManager );
  179. return(rc);
  180. }