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.

189 lines
5.8 KiB

  1. //*************************************************************
  2. //
  3. // Main entry point
  4. //
  5. // Microsoft Confidential
  6. // Copyright (c) Microsoft Corporation 1995
  7. // All rights reserved
  8. //
  9. //*************************************************************
  10. #include "uenv.h"
  11. extern DWORD g_dwLoadFlags;
  12. //*************************************************************
  13. //
  14. // DllMain()
  15. //
  16. // Purpose: Main entry point
  17. //
  18. // Parameters: hInstance - Module instance
  19. // dwReason - Way this function is being called
  20. // lpReseved - Reserved
  21. //
  22. //
  23. // Return: (BOOL) TRUE if successfully initialized
  24. // FALSE if an error occurs
  25. //
  26. //
  27. // Comments:
  28. //
  29. //
  30. // History: Date Author Comment
  31. // 5/24/95 ericflo Created
  32. //
  33. //*************************************************************
  34. BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
  35. {
  36. DWORD dwStatus;
  37. switch (dwReason)
  38. {
  39. case DLL_PROCESS_ATTACH:
  40. {
  41. DisableThreadLibraryCalls (hInstance);
  42. InitializeGlobals (hInstance);
  43. InitializeAPIs();
  44. dwStatus = InitializeNotifySupport();
  45. if ( dwStatus != ERROR_SUCCESS )
  46. {
  47. DebugMsg((DM_WARNING, TEXT("LibMain:: InitializeNotifySupport failed with WIN32 error %d."), dwStatus) );
  48. return FALSE;
  49. }
  50. __try
  51. {
  52. InitializeGPOCriticalSection();
  53. }
  54. __except( EXCEPTION_EXECUTE_HANDLER )
  55. {
  56. CloseGPOCriticalSection();
  57. ShutdownNotifySupport();
  58. return FALSE;
  59. }
  60. InitializeSnapProv();
  61. {
  62. TCHAR szProcessName[MAX_PATH] = {0};
  63. DWORD dwLoadFlags = FALSE;
  64. DWORD WINLOGON_LEN = 12; // Length of string "winlogon.exe"
  65. DWORD SETUP_LEN = 9; // Length of string "setup.exe"
  66. DWORD dwRet = GetModuleFileName (NULL, szProcessName, ARRAYSIZE(szProcessName));
  67. szProcessName[MAX_PATH-1] = 0;
  68. if ( dwRet > WINLOGON_LEN ) {
  69. if ( CompareString ( LOCALE_INVARIANT, NORM_IGNORECASE,
  70. &szProcessName[dwRet-WINLOGON_LEN], -1, L"winlogon.exe", -1 ) == CSTR_EQUAL ) {
  71. g_dwLoadFlags = dwLoadFlags = WINLOGON_LOAD;
  72. }
  73. }
  74. #if 0
  75. if ( dwRet > SETUP_LEN ) {
  76. if ( CompareString ( LOCALE_USER_DEFAULT, NORM_IGNORECASE,
  77. &szProcessName[dwRet-SETUP_LEN], -1, L"setup.exe", -1 ) == CSTR_EQUAL ) {
  78. g_dwLoadFlags = dwLoadFlags = SETUP_LOAD;
  79. }
  80. }
  81. #endif
  82. InitDebugSupport( dwLoadFlags );
  83. if (dwLoadFlags == WINLOGON_LOAD) {
  84. InitializePolicyProcessing(TRUE);
  85. InitializePolicyProcessing(FALSE);
  86. }
  87. DebugMsg((DM_VERBOSE, TEXT("LibMain: Process Name: %s"), szProcessName));
  88. }
  89. }
  90. break;
  91. case DLL_PROCESS_DETACH:
  92. if (g_hProfileSetup) {
  93. CloseHandle (g_hProfileSetup);
  94. g_hProfileSetup = NULL;
  95. }
  96. if (g_hPolicyCritMutexMach) {
  97. CloseHandle (g_hPolicyCritMutexMach);
  98. g_hPolicyCritMutexMach = NULL;
  99. }
  100. if (g_hPolicyCritMutexUser) {
  101. CloseHandle (g_hPolicyCritMutexUser);
  102. g_hPolicyCritMutexUser = NULL;
  103. }
  104. if (g_hRegistryPolicyCritMutexMach) {
  105. CloseHandle (g_hRegistryPolicyCritMutexMach);
  106. g_hRegistryPolicyCritMutexMach = NULL;
  107. }
  108. if (g_hRegistryPolicyCritMutexUser) {
  109. CloseHandle (g_hRegistryPolicyCritMutexUser);
  110. g_hRegistryPolicyCritMutexUser = NULL;
  111. }
  112. if (g_hPolicyNotifyEventMach) {
  113. CloseHandle (g_hPolicyNotifyEventMach);
  114. g_hPolicyNotifyEventMach = NULL;
  115. }
  116. if (g_hPolicyNotifyEventUser) {
  117. CloseHandle (g_hPolicyNotifyEventUser);
  118. g_hPolicyNotifyEventUser = NULL;
  119. }
  120. if (g_hPolicyNeedFGEventMach) {
  121. CloseHandle (g_hPolicyNeedFGEventMach);
  122. g_hPolicyNeedFGEventMach = NULL;
  123. }
  124. if (g_hPolicyNeedFGEventUser) {
  125. CloseHandle (g_hPolicyNeedFGEventUser);
  126. g_hPolicyNeedFGEventUser = NULL;
  127. }
  128. if (g_hPolicyDoneEventMach) {
  129. CloseHandle (g_hPolicyDoneEventMach);
  130. g_hPolicyDoneEventMach = NULL;
  131. }
  132. if (g_hPolicyDoneEventUser) {
  133. CloseHandle (g_hPolicyDoneEventUser);
  134. g_hPolicyDoneEventUser = NULL;
  135. }
  136. if ( g_hPolicyForegroundDoneEventUser )
  137. {
  138. CloseHandle( g_hPolicyForegroundDoneEventUser );
  139. g_hPolicyForegroundDoneEventUser = 0;
  140. }
  141. if ( g_hPolicyForegroundDoneEventMach )
  142. {
  143. CloseHandle( g_hPolicyForegroundDoneEventMach );
  144. g_hPolicyForegroundDoneEventMach = 0;
  145. }
  146. CloseApiDLLsCritSec();
  147. ShutdownEvents ();
  148. ShutdownNotifySupport();
  149. CloseGPOCriticalSection();
  150. ClosePingCritSec();
  151. break;
  152. }
  153. return TRUE;
  154. }