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.

442 lines
11 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1996 - 1997.
  5. //
  6. // File: libmain.cxx
  7. //
  8. // Contents: DllMain for csadm.dll
  9. //
  10. // Functions: DllMain, DllGetClassObject
  11. //
  12. // History: 05-May-97 DebiM Created.
  13. // 16-Feb-98 UShaji CsGetClassStorePathForUser
  14. //----------------------------------------------------------------------------
  15. #include "cstore.hxx"
  16. #pragma hdrstop
  17. void Uninitialize();
  18. BOOL InitializeClassStore(BOOL fInit);
  19. // Globals
  20. HINSTANCE g_hInst = NULL;
  21. ULONG g_ulObjCount = 0; // Number of objects alive in csadm.dll
  22. CClassContainerCF *g_pCF = NULL;
  23. extern CClassAccessCF * pCSAccessCF;
  24. /*
  25. void Uninit()
  26. //
  27. // This routine is called at dll detach time
  28. //
  29. {
  30. //
  31. // release the Class Factory object
  32. //
  33. if (g_pCF)
  34. g_pCF->Release();
  35. }
  36. */
  37. //+---------------------------------------------------------------
  38. //
  39. // Function: DllGetClassObject
  40. //
  41. // Synopsis: Standard DLL entrypoint for locating class factories
  42. //
  43. //----------------------------------------------------------------
  44. STDAPI
  45. DllGetClassObject(REFCLSID clsid, REFIID iid, LPVOID FAR* ppv)
  46. {
  47. HRESULT hr;
  48. size_t i;
  49. if (IsEqualCLSID(clsid, CLSID_DirectoryClassBase))
  50. {
  51. return g_pCF->QueryInterface(iid, ppv);
  52. }
  53. if (IsEqualCLSID(clsid, CLSID_ClassAccess))
  54. {
  55. return pCSAccessCF->QueryInterface(iid, ppv);
  56. }
  57. *ppv = NULL;
  58. return E_NOINTERFACE;
  59. }
  60. //+---------------------------------------------------------------
  61. //
  62. // Function: DllCanUnloadNow
  63. //
  64. // Synopsis: Standard DLL entrypoint to determine if DLL can be unloaded
  65. //
  66. //---------------------------------------------------------------
  67. STDAPI
  68. DllCanUnloadNow(void)
  69. {
  70. HRESULT hr;
  71. hr = S_FALSE;
  72. //
  73. // BugBug
  74. //
  75. /*
  76. if (ulObjectCount > 0)
  77. hr = S_FALSE;
  78. else
  79. hr = S_OK;
  80. */
  81. return hr;
  82. }
  83. //+---------------------------------------------------------------
  84. //
  85. // Function: LibMain
  86. //
  87. // Synopsis: Standard DLL initialization entrypoint
  88. //
  89. //---------------------------------------------------------------
  90. EXTERN_C BOOL __cdecl
  91. LibMain(HINSTANCE hInst, ULONG ulReason, LPVOID pvReserved)
  92. {
  93. HRESULT hr;
  94. DWORD cbSize = _MAX_PATH;
  95. WCHAR wszUserName [_MAX_PATH];
  96. switch (ulReason)
  97. {
  98. case DLL_PROCESS_ATTACH:
  99. DisableThreadLibraryCalls(hInst);
  100. g_hInst = hInst;
  101. //g_pCF = new CClassContainerCF;
  102. InitializeClassStore(FALSE);
  103. break;
  104. case DLL_PROCESS_DETACH:
  105. //Uninit();
  106. Uninitialize();
  107. break;
  108. default:
  109. break;
  110. }
  111. return TRUE;
  112. }
  113. //+---------------------------------------------------------------------------
  114. //
  115. // Function: DllMain
  116. //
  117. // Synopsis: entry point for NT
  118. //
  119. //----------------------------------------------------------------------------
  120. BOOL
  121. DllMain(HANDLE hDll, DWORD dwReason, LPVOID lpReserved)
  122. {
  123. return LibMain((HINSTANCE)hDll, dwReason, lpReserved);
  124. }
  125. //+---------------------------------------------------------------
  126. //
  127. // Function: CsCreateClassStore
  128. //
  129. // Synopsis: Public entrypoint for creating an empty class store. factories
  130. //
  131. //----------------------------------------------------------------
  132. STDAPI
  133. CsCreateClassStore(LPOLESTR szParentPath, LPOLESTR szStoreName)
  134. {
  135. LPOLESTR szPath;
  136. if (wcsncmp (szParentPath, L"ADCS:", 5) == 0)
  137. szPath = szParentPath + 5;
  138. else
  139. szPath = szParentPath;
  140. return CreateRepository(szPath, szStoreName);
  141. }
  142. //+---------------------------------------------------------------
  143. //
  144. // Function: CsGetClassStore
  145. //
  146. // Synopsis: Public entrypoint for binding to a class store and
  147. // get back IClassAdmin
  148. //
  149. //----------------------------------------------------------------
  150. STDAPI
  151. CsGetClassStore(LPOLESTR szPath, void **ppIClassAdmin)
  152. {
  153. return g_pCF->CreateConnectedInstance(
  154. szPath,
  155. ppIClassAdmin);
  156. }
  157. //+---------------------------------------------------------------
  158. //
  159. // Function: CsDeleteClassStore
  160. //
  161. // Synopsis: Public entrypoint for deleting a class store container from DS.
  162. //
  163. //----------------------------------------------------------------
  164. STDAPI
  165. CsDeleteClassStore(LPOLESTR szPath)
  166. {
  167. return E_NOTIMPL;
  168. }
  169. //+-------------------------------------------------------------------
  170. //
  171. // CsGetAppCategories
  172. //
  173. // Returns the complete list of Category GUIDs and Category Descriptions
  174. // per the input Locale.
  175. //
  176. //
  177. // This is used by Add/Remove programs to get the definitive list of
  178. // Application Categories.
  179. //
  180. // The caller needs to free the memory allocated using CoTaskMemFree().
  181. //
  182. // Arguments:
  183. // [in]
  184. // LCID : Locale
  185. // [out]
  186. // APPCATEGORYINFOLIST *pAppCategoryList:
  187. // Returned list of GUIDs and Unicode descriptions
  188. //
  189. // Returns :
  190. // S_OK
  191. //
  192. //--------------------------------------------------------------------
  193. STDAPI
  194. CsGetAppCategories (APPCATEGORYINFOLIST *pAppCategoryList)
  195. {
  196. HRESULT hr;
  197. IClassAdmin * pIClassAdmin = NULL;
  198. hr = g_pCF->CreateInstance(
  199. NULL,
  200. IID_IClassAdmin,
  201. (void **)&pIClassAdmin);
  202. if (!SUCCEEDED(hr))
  203. return hr;
  204. hr = pIClassAdmin->GetAppCategories (
  205. GetUserDefaultLCID(),
  206. pAppCategoryList);
  207. pIClassAdmin->Release();
  208. return hr;
  209. }
  210. //+-------------------------------------------------------------------
  211. //
  212. // CsGetClassStorePath
  213. //
  214. // Returns the class store path for the user.
  215. //
  216. //
  217. // This is used by Winlogon to get the class store path for a given user.
  218. //
  219. // The caller needs to free the memory allocated using CoTaskMemFree().
  220. //
  221. // Arguments:
  222. // [in]
  223. // DSProfilePath: Path For the DS Object given to winlogon.
  224. // User Doesn't have to any checks.
  225. //
  226. // [out]
  227. // pCSPath: Unicode Path to the class store for the user.
  228. //
  229. // Returns :
  230. // S_OK, or whatever error underlying DS layer returns.
  231. // BUGBUG:: Error code have to be remapped.
  232. //
  233. //--------------------------------------------------------------------
  234. STDAPI
  235. CsGetClassStorePath(LPOLESTR DSProfilePath, LPOLESTR *pCSPath)
  236. {
  237. #if (0)
  238. HRESULT hr = S_OK;
  239. IADs *pADs = NULL;
  240. if ((!DSProfilePath) || (IsBadStringPtr(DSProfilePath, _MAX_PATH)))
  241. return E_INVALIDARG;
  242. hr = ADsGetObject(
  243. DSProfilePath,
  244. IID_IADs,
  245. (void **)&pADs
  246. );
  247. RETURN_ON_FAILURE(hr);
  248. hr = GetPropertyAlloc(pADs, DEFAULTCLASSSTOREPATH, pCSPath);
  249. pADs->Release();
  250. return hr;
  251. #else // temporary hack until property is written to ds
  252. if (!(*pCSPath = (WCHAR*) CoTaskMemAlloc(lstrlen(DSProfilePath) * sizeof (WCHAR) + sizeof L"CN=Class Store,")))
  253. {
  254. return E_OUTOFMEMORY;
  255. }
  256. lstrcpy(*pCSPath, L"LDAP://");
  257. lstrcat(*pCSPath, L"CN=Class Store,");
  258. lstrcat(*pCSPath, DSProfilePath + ((sizeof(L"LDAP://") / sizeof(WCHAR)) - 1));
  259. return S_OK;
  260. #endif
  261. }
  262. //+-------------------------------------------------------------------
  263. //
  264. // CsSetClassStorePath
  265. //
  266. // Writes the user class store path.
  267. //
  268. //
  269. // This is used by MMC snapin to write the class store path for a given user.
  270. //
  271. // Arguments:
  272. // [in]
  273. // DSProfilePath: Path For the DS Object.
  274. // User Doesn't have to any checks.
  275. //
  276. // pCSPath: Unicode Path to the class store for the user.
  277. //
  278. // Returns :
  279. // S_OK, or whatever error underlying DS layer returns.
  280. // BUGBUG:: Error code have to be remapped.
  281. //
  282. //--------------------------------------------------------------------
  283. STDAPI
  284. CsSetClassStorePath(LPOLESTR DSProfilePath, LPOLESTR szCSPath)
  285. {
  286. HRESULT hr = S_OK;
  287. IADs *pADs = NULL;
  288. if ((!DSProfilePath) || (IsBadStringPtr(DSProfilePath, _MAX_PATH)))
  289. return E_INVALIDARG;
  290. hr = ADsGetObject(
  291. DSProfilePath,
  292. IID_IADs,
  293. (void **)&pADs
  294. );
  295. RETURN_ON_FAILURE(hr);
  296. hr = SetProperty(pADs, DEFAULTCLASSSTOREPATH, szCSPath);
  297. if (SUCCEEDED(hr))
  298. hr = StoreIt(pADs);
  299. pADs->Release();
  300. return hr;
  301. }
  302. STDAPI
  303. ReleasePackageInfo(PACKAGEDISPINFO *pPackageInfo)
  304. {
  305. DWORD i;
  306. if (pPackageInfo)
  307. {
  308. CoTaskMemFree(pPackageInfo->pszScriptPath);
  309. CoTaskMemFree(pPackageInfo->pszPackageName);
  310. for (i = 0; i < (pPackageInfo->cUpgrades); i++)
  311. CoTaskMemFree(pPackageInfo->prgUpgradeScript[i]);
  312. CoTaskMemFree(pPackageInfo->prgUpgradeScript);
  313. CoTaskMemFree(pPackageInfo->prgUpgradeFlag);
  314. }
  315. return S_OK;
  316. }
  317. STDAPI
  318. ReleaseInstallInfo(INSTALLINFO *pInstallInfo)
  319. {
  320. DWORD i;
  321. if (pInstallInfo)
  322. {
  323. CoTaskMemFree(pInstallInfo->pszSetupCommand);
  324. CoTaskMemFree(pInstallInfo->pszScriptPath);
  325. CoTaskMemFree(pInstallInfo->pszUrl);
  326. CoTaskMemFree(pInstallInfo->pClsid);
  327. for (i = 0; i < (pInstallInfo->cUpgrades); i++)
  328. CoTaskMemFree(pInstallInfo->prgUpgradeScript[i]);
  329. CoTaskMemFree(pInstallInfo->prgUpgradeScript);
  330. CoTaskMemFree(pInstallInfo->prgUpgradeFlag);
  331. }
  332. return S_OK;
  333. }
  334. void
  335. ReleaseClassDetail(CLASSDETAIL ClassDetail)
  336. {
  337. DWORD i;
  338. for (i = 0; i < ClassDetail.cProgId; i++)
  339. CoTaskMemFree(ClassDetail.prgProgId[i]);
  340. CoTaskMemFree(ClassDetail.prgProgId);
  341. }
  342. STDAPI
  343. ReleasePackageDetail(PACKAGEDETAIL *pPackageDetail)
  344. {
  345. DWORD i;
  346. if (pPackageDetail)
  347. {
  348. if (pPackageDetail->pActInfo)
  349. {
  350. for (i = 0; i < pPackageDetail->pActInfo->cClasses; i++)
  351. ReleaseClassDetail((pPackageDetail->pActInfo->pClasses)[i]);
  352. CoTaskMemFree(pPackageDetail->pActInfo->pClasses);
  353. CoTaskMemFree(pPackageDetail->pActInfo->prgShellFileExt);
  354. CoTaskMemFree(pPackageDetail->pActInfo->prgPriority);
  355. CoTaskMemFree(pPackageDetail->pActInfo->prgInterfaceId);
  356. CoTaskMemFree(pPackageDetail->pActInfo->prgTlbId);
  357. CoTaskMemFree(pPackageDetail->pActInfo);
  358. }
  359. if (pPackageDetail->pPlatformInfo)
  360. {
  361. CoTaskMemFree(pPackageDetail->pPlatformInfo->prgPlatform);
  362. CoTaskMemFree(pPackageDetail->pPlatformInfo->prgLocale);
  363. CoTaskMemFree(pPackageDetail->pPlatformInfo);
  364. }
  365. if (pPackageDetail->pInstallInfo)
  366. {
  367. ReleaseInstallInfo(pPackageDetail->pInstallInfo);
  368. CoTaskMemFree(pPackageDetail->pInstallInfo);
  369. }
  370. for (i = 0; i < (pPackageDetail->cSources); i++)
  371. CoTaskMemFree(pPackageDetail->pszSourceList[i]);
  372. CoTaskMemFree(pPackageDetail->pszSourceList);
  373. CoTaskMemFree(pPackageDetail->rpCategory);
  374. }
  375. return S_OK;
  376. }