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.

371 lines
11 KiB

  1. ///////////////////////////////////////////////////////////////////////////////
  2. /* File: dskquota.cpp
  3. Description: Contains standard functions for an OLE component server DLL.
  4. DllMain
  5. DllGetClassObject
  6. DllCanUnloadNow
  7. Revision History:
  8. Date Description Programmer
  9. -------- --------------------------------------------------- ----------
  10. 05/22/96 Initial creation. BrianAu
  11. 12/10/96 Moved to free-threading OLE apartment model. BrianAu
  12. */
  13. ///////////////////////////////////////////////////////////////////////////////
  14. #include "pch.h" // PCH
  15. #pragma hdrstop
  16. #define INITGUIDS // Define GUIDs.
  17. #include "dskquota.h"
  18. #include "guidsp.h" // Private GUIDs.
  19. #include <gpedit.h> // For GUIDs.
  20. #include "factory.h" // Class factory declarations.
  21. #include "sidcache.h" // SID/Name cache.
  22. #include "registry.h"
  23. //
  24. // Verify that build is UNICODE.
  25. //
  26. #if !defined(UNICODE)
  27. # error This module must be compiled UNICODE.
  28. #endif
  29. HINSTANCE g_hInstDll = NULL; // DLL instance handle.
  30. LONG g_cRefThisDll = 0; // DLL reference count.
  31. LONG g_cLockThisDll = 0; // DLL lock count.
  32. ///////////////////////////////////////////////////////////////////////////////
  33. /* Function: DllGetClassObject
  34. Description: Creates instance of DiskQuotaControlClassFactory.
  35. Arguments:
  36. rclsid - Reference to class ID that identifies the type of object that the
  37. class factory will be asked to create.
  38. riid - Reference to interface ID on the class factory object.
  39. ppvOut - Destination location for class factory object pointer after
  40. instantiation.
  41. Returns:
  42. NOERROR - Success.
  43. E_OUTOFMEMORY - Can't create class factory object.
  44. E_NOINTERFACE - Interface not supported.
  45. E_INVALIDARG - ppvOut arg is NULL.
  46. CLASS_E_CLASSNOTAVAILABLE - Class factory not available.
  47. Revision History:
  48. Date Description Programmer
  49. -------- --------------------------------------------------- ----------
  50. 05/22/96 Initial creation. BrianAu
  51. */
  52. ///////////////////////////////////////////////////////////////////////////////
  53. STDAPI
  54. DllGetClassObject(
  55. REFCLSID rclsid,
  56. REFIID riid,
  57. LPVOID *ppvOut
  58. )
  59. {
  60. DBGTRACE((DM_COM, DL_HIGH, TEXT("DllGetClassObject")));
  61. DBGPRINTIID(DM_COM, DL_HIGH, (REFIID)rclsid);
  62. DBGPRINTIID(DM_COM, DL_HIGH, riid);
  63. HRESULT hr = CLASS_E_CLASSNOTAVAILABLE;
  64. if (NULL == ppvOut)
  65. return E_INVALIDARG;
  66. *ppvOut = NULL;
  67. try
  68. {
  69. if (IsEqualIID(rclsid, CLSID_DiskQuotaControl))
  70. {
  71. DiskQuotaControlClassFactory *pClassFactory = NULL;
  72. pClassFactory = new DiskQuotaControlClassFactory;
  73. hr = pClassFactory->QueryInterface(riid, ppvOut);
  74. if (FAILED(hr))
  75. {
  76. delete pClassFactory;
  77. }
  78. }
  79. }
  80. catch(CAllocException& e)
  81. {
  82. DBGERROR((TEXT("Insufficient memory exception")));
  83. hr = E_OUTOFMEMORY;
  84. }
  85. return hr;
  86. }
  87. ///////////////////////////////////////////////////////////////////////////////
  88. /* Function: DllCanUnloadNow
  89. Description: Called by OLE to determine if DLL can be unloaded.
  90. Arguments: None.
  91. Returns:
  92. S_FALSE - Can't unload. Ref count or lock count are > 0.
  93. S_OK - OK to unload. Ref count and lock count are 0.
  94. Revision History:
  95. Date Description Programmer
  96. -------- --------------------------------------------------- ----------
  97. 05/22/96 Initial creation. BrianAu
  98. */
  99. ///////////////////////////////////////////////////////////////////////////////
  100. STDAPI
  101. DllCanUnloadNow(
  102. VOID
  103. )
  104. {
  105. DBGTRACE((DM_COM, DL_HIGH, TEXT("DllCanUnloadNow")));
  106. DBGPRINT((DM_COM, DL_HIGH, TEXT("\tRefCnt = %d LockCnt = %d"),
  107. g_cRefThisDll, g_cLockThisDll));
  108. return (0 == g_cRefThisDll && 0 == g_cLockThisDll) ? S_OK : S_FALSE;
  109. }
  110. ///////////////////////////////////////////////////////////////////////////////
  111. /* Function: DllRegisterServer
  112. Description: Create the necessary registry entries for dskquota.dll
  113. to operate properly. This is called by REGSVR32.EXE.
  114. Arguments: None.
  115. Returns:
  116. S_OK - Succeeded.
  117. SELFREG_E_CLASS - Failed to create one of the registry entries.
  118. Revision History:
  119. Date Description Programmer
  120. -------- --------------------------------------------------- ----------
  121. 08/18/97 Initial creation. BrianAu
  122. */
  123. ///////////////////////////////////////////////////////////////////////////////
  124. HRESULT
  125. DllRegisterServer(
  126. VOID
  127. )
  128. {
  129. DBGTRACE((DM_COM, DL_HIGH, TEXT("DllRegisterServer")));
  130. HRESULT hr = CallRegInstall(g_hInstDll, "RegDll");
  131. if (FAILED(hr))
  132. {
  133. hr = SELFREG_E_CLASS;
  134. }
  135. return hr;
  136. }
  137. ///////////////////////////////////////////////////////////////////////////////
  138. /* Function: DllUnregisterServer
  139. Description: Remove the necessary registry entries for dskquota.dll.
  140. This is called by REGSVR32.EXE.
  141. Arguments: None.
  142. Returns:
  143. S_OK - Succeeded.
  144. SELFREG_E_CLASS - Failed to remove the CLSID entry.
  145. Revision History:
  146. Date Description Programmer
  147. -------- --------------------------------------------------- ----------
  148. 08/18/97 Initial creation. BrianAu
  149. */
  150. ///////////////////////////////////////////////////////////////////////////////
  151. HRESULT
  152. DllUnregisterServer(
  153. VOID
  154. )
  155. {
  156. DBGTRACE((DM_COM, DL_HIGH, TEXT("DllUnregisterServer")));
  157. HRESULT hr = CallRegInstall(g_hInstDll, "UnregDll");
  158. if (FAILED(hr))
  159. {
  160. hr = SELFREG_E_CLASS;
  161. }
  162. return hr;
  163. }
  164. ///////////////////////////////////////////////////////////////////////////////
  165. /* Function: OnProcessAttach
  166. Description: Handles all tasks associated with a process attaching to
  167. the DLL.
  168. Try to keep processing time to a minimum.
  169. Arguments:
  170. hInstDll - The DLL instance handle passed to DllMain.
  171. Returns:
  172. NOERROR - Success.
  173. E_FAIL - Something failed.
  174. Revision History:
  175. Date Description Programmer
  176. -------- --------------------------------------------------- ----------
  177. 08/09/96 Initial creation. BrianAu
  178. */
  179. ///////////////////////////////////////////////////////////////////////////////
  180. HRESULT
  181. OnProcessAttach(
  182. HINSTANCE hInstDll
  183. )
  184. {
  185. DBGTRACE((DM_COM, DL_HIGH, TEXT("OnProcessAttach")));
  186. HRESULT hr = NOERROR;
  187. //
  188. // Start IceCAP profiling.
  189. //
  190. ICAP_START_ALL;
  191. #if DBG
  192. DBGMODULE(TEXT("DSKQUOTA")); // Name of module displayed with messages.
  193. RegKey key(HKEY_LOCAL_MACHINE, REGSTR_KEY_DISKQUOTA);
  194. if (SUCCEEDED(key.Open(KEY_READ)))
  195. {
  196. DebugRegParams dp;
  197. if (SUCCEEDED(key.GetValue(REGSTR_VAL_DEBUGPARAMS, (LPBYTE)&dp, sizeof(dp))))
  198. {
  199. DBGPRINTMASK(dp.PrintMask);
  200. DBGPRINTLEVEL(dp.PrintLevel);
  201. DBGPRINTVERBOSE(dp.PrintVerbose);
  202. DBGTRACEMASK(dp.TraceMask);
  203. DBGTRACELEVEL(dp.TraceLevel);
  204. DBGTRACEVERBOSE(dp.TraceVerbose);
  205. DBGTRACEONEXIT(dp.TraceOnExit);
  206. }
  207. }
  208. #endif // DBG
  209. g_hInstDll = hInstDll;
  210. DisableThreadLibraryCalls(hInstDll);
  211. return hr;
  212. }
  213. ///////////////////////////////////////////////////////////////////////////////
  214. /* Function: OnProcessDetach
  215. Description: Handles all tasks associated with a process detaching from
  216. the DLL.
  217. Arguments: None.
  218. Returns:
  219. NOERROR - Success.
  220. Revision History:
  221. Date Description Programmer
  222. -------- --------------------------------------------------- ----------
  223. 08/09/96 Initial creation. BrianAu
  224. */
  225. ///////////////////////////////////////////////////////////////////////////////
  226. HRESULT
  227. OnProcessDetach(
  228. VOID
  229. )
  230. {
  231. DBGTRACE((DM_COM, DL_HIGH, TEXT("OnProcessAttach")));
  232. HRESULT hr = NOERROR;
  233. SidNameCache_Destroy();
  234. //
  235. // Stop IceCAP profiling.
  236. //
  237. ICAP_STOP_ALL;
  238. return hr;
  239. }
  240. ///////////////////////////////////////////////////////////////////////////////
  241. /* Function: DllMain
  242. Description: Main entry point for OLE component server.
  243. Arguments:
  244. hInstDll - Instance handle of DLL
  245. fdwReason - Reason DllMain is being called. Can be at Process attach/
  246. detach or Thread attach/detach.
  247. lpdwReserved - Reserved.
  248. Returns:
  249. TRUE - Successful initialization.
  250. FALSE - Failed initialization.
  251. Revision History:
  252. Date Description Programmer
  253. -------- --------------------------------------------------- ----------
  254. 05/22/96 Initial creation. BrianAu
  255. 08/09/96 Moved code associated with process attach and BrianAu
  256. detach out to separate functions.
  257. */
  258. ///////////////////////////////////////////////////////////////////////////////
  259. BOOL WINAPI
  260. DllMain(
  261. HINSTANCE hInstDll,
  262. DWORD fdwReason,
  263. LPVOID lpvReserved
  264. )
  265. {
  266. DBGTRACE((DM_COM, DL_HIGH, TEXT("DllMain")));
  267. BOOL bResult = FALSE;
  268. switch(fdwReason)
  269. {
  270. case DLL_PROCESS_ATTACH:
  271. DBGPRINT((DM_COM, DL_HIGH, TEXT("DLL_PROCESS_ATTACH")));
  272. bResult = SUCCEEDED(OnProcessAttach(hInstDll));
  273. break;
  274. case DLL_THREAD_ATTACH:
  275. case DLL_THREAD_DETACH:
  276. bResult = TRUE;
  277. break;
  278. case DLL_PROCESS_DETACH:
  279. DBGPRINT((DM_COM, DL_HIGH, TEXT("DLL_PROCESS_DETACH")));
  280. bResult = SUCCEEDED(OnProcessDetach());
  281. break;
  282. }
  283. return bResult;
  284. }