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.

228 lines
5.3 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1995.
  5. //
  6. // File: libmain.cxx
  7. //
  8. // Contents: LibMain for nds.dll
  9. //
  10. // Functions: LibMain, DllGetClassObject
  11. //
  12. // History: 25-Oct-94 KrishnaG Created.
  13. //
  14. //----------------------------------------------------------------------------
  15. #include "ldapc.hxx"
  16. #pragma hdrstop
  17. #if DBG==1
  18. #include "formtrck.hxx"
  19. extern "C" {
  20. #include "caiheap.h"
  21. }
  22. extern CRITICAL_SECTION g_csDP; // for debugprint
  23. extern CRITICAL_SECTION g_csOT; // for otracker
  24. extern CRITICAL_SECTION g_csMem; // for MemAlloc
  25. #endif
  26. extern CRITICAL_SECTION g_DomainDnsCache;
  27. //
  28. // External references to handles for libs we load dynamically.
  29. //
  30. extern HANDLE g_hDllNetApi32;
  31. extern HANDLE g_hDllSecur32;
  32. extern DWORD LsaDeregisterLogonProcessWrapper(
  33. IN HANDLE LsaHandle
  34. );
  35. //
  36. // Variables needed for localized strings.
  37. //
  38. WCHAR g_szNT_Authority[100];
  39. BOOL g_fStringsLoaded = FALSE;
  40. HINSTANCE g_hInst = NULL;
  41. //
  42. // LSA handle (needed by GetUserDomainFlatName)
  43. //
  44. extern HANDLE g_hLsa;
  45. //---------------------------------------------------------------------------
  46. // ADs debug print, mem leak and object tracking-related stuff
  47. //---------------------------------------------------------------------------
  48. DECLARE_INFOLEVEL(ADs)
  49. //+---------------------------------------------------------------------------
  50. //
  51. // Function: ShutDown
  52. //
  53. // Synopsis: Function to handle printing out heap debugging display
  54. //
  55. //----------------------------------------------------------------------------
  56. inline VOID ShutDown()
  57. {
  58. #if DBG==1
  59. #ifndef MSVC
  60. DUMP_TRACKING_INFO_DELETE();
  61. AllocArenaDump( NULL );
  62. DeleteCriticalSection(&g_csOT);
  63. #endif // ifndef MSVC
  64. DeleteCriticalSection(&g_csDP);
  65. #endif
  66. }
  67. //+---------------------------------------------------------------
  68. //
  69. // Function: LibMain
  70. //
  71. // Synopsis: Standard DLL initialization entrypoint
  72. //
  73. //---------------------------------------------------------------
  74. EXTERN_C BOOL __cdecl
  75. LibMain(HINSTANCE hInst, ULONG ulReason, LPVOID pvReserved)
  76. {
  77. HRESULT hr;
  78. switch (ulReason)
  79. {
  80. case DLL_PROCESS_ATTACH:
  81. //
  82. // Need to handle case of crit sect init failing.
  83. //
  84. __try {
  85. InitADsMem() ;
  86. //
  87. // Initialize the error records
  88. //
  89. memset(&ADsErrorRecList, 0, sizeof(ERROR_RECORD));
  90. InitializeCriticalSection(&ADsErrorRecCritSec);
  91. BindCacheInit() ;
  92. SchemaInit() ;
  93. InitializeCriticalSection(&g_DomainDnsCache);
  94. g_hInst = hInst;
  95. #if DBG==1
  96. #ifndef MSVC
  97. InitializeCriticalSection(&g_csOT); // Used by Object Tracker
  98. InitializeCriticalSection(&g_csMem); // Used by Object Tracker
  99. #endif
  100. InitializeCriticalSection(&g_csDP); // Used by ADsDebug
  101. #endif
  102. }
  103. __except (EXCEPTION_EXECUTE_HANDLER) {
  104. //
  105. // Critical faliure
  106. //
  107. return FALSE;
  108. }
  109. //
  110. // Time to load localized strings if applicable.
  111. //
  112. if (!g_fStringsLoaded) {
  113. //
  114. // Load NT AUthority
  115. //
  116. if (!LoadStringW(
  117. g_hInst,
  118. LDAPC_NT_AUTHORITY,
  119. g_szNT_Authority,
  120. sizeof( g_szNT_Authority ) / sizeof( WCHAR )
  121. )
  122. ) {
  123. wcscpy(g_szNT_Authority, L"NT AUTHORITY");
  124. }
  125. g_fStringsLoaded = TRUE;
  126. }
  127. break;
  128. case DLL_PROCESS_DETACH:
  129. ADsFreeAllErrorRecords();
  130. SchemaCleanup();
  131. BindCacheCleanup();
  132. #if (!defined WIN95)
  133. if (g_hLsa != INVALID_HANDLE_VALUE) {
  134. LsaDeregisterLogonProcessWrapper(g_hLsa);
  135. }
  136. #endif
  137. if (g_hDllNetApi32) {
  138. FreeLibrary((HMODULE)g_hDllNetApi32);
  139. g_hDllNetApi32 = NULL;
  140. }
  141. if (g_hDllSecur32) {
  142. FreeLibrary((HMODULE)g_hDllSecur32);
  143. g_hDllSecur32 = NULL;
  144. }
  145. DeleteCriticalSection(&ADsErrorRecCritSec);
  146. DeleteCriticalSection(&g_DomainDnsCache);
  147. #if DBG==1
  148. #ifndef MSVC
  149. DeleteCriticalSection(&g_csOT); // Used by Object Tracker
  150. DeleteCriticalSection(&g_csMem); // Used by Object Tracker
  151. #endif
  152. DeleteCriticalSection(&g_csDP); // Used by ADsDebug
  153. #endif
  154. if (gpszServerName) {
  155. FreeADsStr(gpszServerName);
  156. gpszServerName = NULL;
  157. }
  158. if (gpszDomainName) {
  159. FreeADsStr(gpszDomainName);
  160. gpszDomainName = NULL;
  161. }
  162. #if DBG==1
  163. DumpMemoryTracker();
  164. #endif
  165. #if DBG==1
  166. DeleteCriticalSection(&ADsMemCritSect);
  167. #endif
  168. break;
  169. case DLL_THREAD_DETACH:
  170. ADsFreeThreadErrorRecords();
  171. break;
  172. default:
  173. break;
  174. }
  175. return TRUE;
  176. }
  177. //+---------------------------------------------------------------------------
  178. //
  179. // Function: DllMain
  180. //
  181. // Synopsis: entry point for NT - post .546
  182. //
  183. //----------------------------------------------------------------------------
  184. BOOL
  185. DllMain(HANDLE hDll, DWORD dwReason, LPVOID lpReserved)
  186. {
  187. return LibMain((HINSTANCE)hDll, dwReason, lpReserved);
  188. }