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.

305 lines
7.8 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 "ldap.hxx"
  16. #pragma hdrstop
  17. HINSTANCE g_hInst = NULL;
  18. BOOL fInitializeCritSect = FALSE;
  19. //---------------------------------------------------------------------------
  20. // ADs debug print, mem leak and object tracking-related stuff
  21. //---------------------------------------------------------------------------
  22. DECLARE_INFOLEVEL(ADs)
  23. //+---------------------------------------------------------------------------
  24. //
  25. // Function: ShutDown
  26. //
  27. // Synopsis: Function to handle printing out heap debugging display
  28. //
  29. //----------------------------------------------------------------------------
  30. inline VOID ShutDown()
  31. {
  32. #if DBG==1
  33. #ifndef MSVC
  34. DUMP_TRACKING_INFO_DELETE();
  35. DeleteCriticalSection(&g_csOT);
  36. #endif // ifndef MSVC
  37. DeleteCriticalSection(&g_csDP);
  38. #endif
  39. }
  40. extern "C" DWORD heapInfoLevel;
  41. extern "C" DWORD OtInfoLevel;
  42. extern "C" DWORD ADsInfoLevel;
  43. CLDAPUserCF g_cfUser;
  44. CLDAPOrganizationCF g_cfOrganization;
  45. CLDAPOrganizationUnitCF g_cfOrganizationUnit;
  46. CLDAPLocalityCF g_cfLocality;
  47. CLDAPPrintQueueCF g_cfPrintQueue;
  48. CLDAPGroupCF g_cfGroup;
  49. extern CRITICAL_SECTION g_ExtTypeInfoCritSect;
  50. extern CRITICAL_SECTION g_DispTypeInfoCritSect;
  51. extern CRITICAL_SECTION g_ServerListCritSect;
  52. //+---------------------------------------------------------------------------
  53. //
  54. // Function: GetINIHeapInfoLevel
  55. //
  56. // Synopsis: Gets various infolevel values from win.ini
  57. //
  58. //----------------------------------------------------------------------------
  59. inline VOID GetINIHeapInfoLevel()
  60. {
  61. #if DBG==1
  62. const INT MAXINFOLEN=11;
  63. TCHAR awcs[MAXINFOLEN];
  64. #ifndef MSVC
  65. if (GetProfileString(TEXT("LDAP"),TEXT("heapInfoLevel"), TEXT("00000003"), awcs,MAXINFOLEN))
  66. heapInfoLevel = _tcstoul(awcs, NULL, 16);
  67. if (GetProfileString(TEXT("LDAP"),TEXT("Ot"), TEXT("00000003"), awcs, MAXINFOLEN))
  68. OtInfoLevel = _tcstoul(awcs, NULL, 16);
  69. #endif // MSVC
  70. if (GetProfileString(TEXT("LDAP"),TEXT("ADsInfoLevel"), TEXT("00000003"), awcs,MAXINFOLEN))
  71. ADsInfoLevel = _tcstoul(awcs, NULL, 16);
  72. #endif
  73. }
  74. // Globals
  75. ULONG g_ulObjCount = 0; // Number of objects alive in oleds.dll
  76. //+------------------------------------------------------------------------
  77. //
  78. // oleds class factories
  79. //
  80. //-------------------------------------------------------------------------
  81. struct CLSCACHE
  82. {
  83. const CLSID * pclsid;
  84. IClassFactory * pCF;
  85. };
  86. CLSCACHE g_aclscache[] =
  87. {
  88. &CLSID_MSExtUser, &g_cfUser,
  89. &CLSID_MSExtOrganization, &g_cfOrganization,
  90. &CLSID_MSExtOrganizationUnit, &g_cfOrganizationUnit,
  91. &CLSID_MSExtLocality, &g_cfLocality,
  92. &CLSID_MSExtPrintQueue, &g_cfPrintQueue,
  93. &CLSID_MSExtGroup, &g_cfGroup
  94. };
  95. //+---------------------------------------------------------------
  96. //
  97. // Function: DllGetClassObject
  98. //
  99. // Synopsis: Standard DLL entrypoint for locating class factories
  100. //
  101. //----------------------------------------------------------------
  102. STDAPI
  103. DllGetClassObject(REFCLSID clsid, REFIID iid, LPVOID FAR* ppv)
  104. {
  105. HRESULT hr;
  106. size_t i;
  107. for (i = 0; i < ARRAY_SIZE(g_aclscache); i++)
  108. {
  109. if (IsEqualCLSID(clsid, *g_aclscache[i].pclsid))
  110. {
  111. hr = g_aclscache[i].pCF->QueryInterface(iid, ppv);
  112. RRETURN(hr);
  113. }
  114. }
  115. *ppv = NULL;
  116. //
  117. // Add Debugging Code to indicate that the oleds.DllGetClassObject has been called with an unknown CLSID.
  118. //
  119. return E_NOINTERFACE;
  120. }
  121. //+---------------------------------------------------------------
  122. //
  123. // Function: DllCanUnloadNow
  124. //
  125. // Synopsis: Standard DLL entrypoint to determine if DLL can be unloaded
  126. //
  127. //---------------------------------------------------------------
  128. STDAPI
  129. DllCanUnloadNow(void)
  130. {
  131. HRESULT hr;
  132. hr = S_FALSE;
  133. if (AggregateeDllCanUnload() && DllReadyToUnload()) {
  134. hr = S_OK;
  135. }
  136. return hr;
  137. }
  138. //+---------------------------------------------------------------
  139. //
  140. // Function: LibMain
  141. //
  142. // Synopsis: Standard DLL initialization entrypoint
  143. //
  144. //---------------------------------------------------------------
  145. EXTERN_C BOOL __cdecl
  146. LibMain(HINSTANCE hInst, ULONG ulReason, LPVOID pvReserved)
  147. {
  148. HRESULT hr;
  149. DWORD dwCritSectIniStage = 0;
  150. switch (ulReason)
  151. {
  152. case DLL_PROCESS_ATTACH:
  153. //
  154. // Catch init crit sect failing.
  155. //
  156. __try {
  157. DisableThreadLibraryCalls(hInst);
  158. g_hInst = hInst;
  159. InitializeCriticalSection(&g_ExtTypeInfoCritSect);
  160. dwCritSectIniStage = 1;
  161. InitializeCriticalSection(&g_DispTypeInfoCritSect);
  162. dwCritSectIniStage = 2;
  163. InitializeCriticalSection(&g_ServerListCritSect);
  164. dwCritSectIniStage = 3;
  165. #if DBG==1
  166. InitializeCriticalSection(&g_csDP);
  167. dwCritSectIniStage = 4;
  168. #ifndef MSVC
  169. InitializeCriticalSection(&g_csOT);
  170. dwCritSectIniStage = 5;
  171. InitializeCriticalSection(&g_csMem);
  172. dwCritSectIniStage = 6;
  173. #endif
  174. #endif
  175. fInitializeCritSect = TRUE;
  176. }
  177. __except (EXCEPTION_EXECUTE_HANDLER) {
  178. //
  179. // Critical Failure
  180. //
  181. switch(dwCritSectIniStage)
  182. {
  183. #if DBG==1
  184. #ifndef MSVC
  185. case 6:
  186. DeleteCriticalSection(&g_csMem);
  187. case 5:
  188. DeleteCriticalSection(&g_csOT);
  189. #endif
  190. case 4:
  191. DeleteCriticalSection(&g_csDP);
  192. #endif
  193. case 3:
  194. DeleteCriticalSection(&g_ServerListCritSect);
  195. case 2:
  196. DeleteCriticalSection(&g_DispTypeInfoCritSect);
  197. case 1:
  198. DeleteCriticalSection(&g_ExtTypeInfoCritSect);
  199. }
  200. return FALSE;
  201. }
  202. break;
  203. case DLL_PROCESS_DETACH:
  204. AggregateeFreeTypeInfoTable();
  205. FreeServerSSLSupportList();
  206. //
  207. // Delete the critsects.
  208. if(fInitializeCritSect)
  209. {
  210. #if DBG==1
  211. #ifndef MSVC
  212. DeleteCriticalSection(&g_csOT);
  213. DeleteCriticalSection(&g_csMem);
  214. #endif
  215. DeleteCriticalSection(&g_csDP);
  216. #endif
  217. DeleteCriticalSection(&g_ExtTypeInfoCritSect);
  218. DeleteCriticalSection(&g_DispTypeInfoCritSect);
  219. DeleteCriticalSection(&g_ServerListCritSect);
  220. }
  221. if (g_hDllSecur32) {
  222. FreeLibrary((HMODULE)g_hDllSecur32);
  223. g_hDllSecur32 = NULL;
  224. }
  225. break;
  226. default:
  227. break;
  228. }
  229. return TRUE;
  230. }
  231. //+---------------------------------------------------------------------------
  232. //
  233. // Function: DllMain
  234. //
  235. // Synopsis: entry point for NT - post .546
  236. //
  237. //----------------------------------------------------------------------------
  238. BOOL
  239. DllMain(HANDLE hDll, DWORD dwReason, LPVOID lpReserved)
  240. {
  241. return LibMain((HINSTANCE)hDll, dwReason, lpReserved);
  242. }