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.

472 lines
12 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation 1996-2001.
  5. //
  6. // File: attrprop.cpp
  7. //
  8. // Contents: implementation of code for adding property pages
  9. //
  10. //----------------------------------------------------------------------------
  11. #include "stdafx.h"
  12. #include "wsecmgr.h"
  13. #include "resource.h"
  14. #include <accctrl.h>
  15. #include "servperm.h"
  16. #include "stdafx.h"
  17. #include "wsecmgr.h"
  18. #include "snapmgr.h"
  19. #include "util.h"
  20. #include "UIThread.h"
  21. #include "attr.h"
  22. #include "aaudit.h"
  23. #include "aenable.h"
  24. #include "AMember.h"
  25. #include "anumber.h"
  26. #include "AObject.h"
  27. #include "ARet.h"
  28. #include "ARight.h"
  29. #include "aservice.h"
  30. #include "astring.h"
  31. #include "CAudit.h"
  32. #include "CEnable.h"
  33. #include "CGroup.h"
  34. #include "CName.h"
  35. #include "CNumber.h"
  36. #include "cobject.h"
  37. #include "CPrivs.h"
  38. #include "CRet.h"
  39. #include "cservice.h"
  40. #include "regvldlg.h"
  41. #include "perfanal.h"
  42. #include "applcnfg.h"
  43. #include "wrapper.h"
  44. #include "locdesc.h"
  45. #include "profdesc.h"
  46. #include "newprof.h"
  47. #include "laudit.h"
  48. #include "lenable.h"
  49. #include "lret.h"
  50. #include "lnumber.h"
  51. #include "lstring.h"
  52. #include "lright.h"
  53. #include "achoice.h"
  54. #include "cchoice.h"
  55. #include "lchoice.h"
  56. #include "dattrs.h"
  57. #include "lflags.h"
  58. #include "aflags.h"
  59. #include "multisz.h"
  60. #include "precpage.h"
  61. //+--------------------------------------------------------------------------
  62. //
  63. // Function: CloneAttrDialog
  64. //
  65. // Synopsis: Create a new CAttribute object of the appropriate class for
  66. // the type and pData passed in
  67. //
  68. // Arguments: [type] - The type of data the CAttribute will represent
  69. // [pData] - More information about the CAttribute
  70. // [bGP] - True to use CDomain* instead of CConfig* dialogs
  71. //
  72. //
  73. //---------------------------------------------------------------------------
  74. CAttribute *CloneAttrDialog(CResult *pData, BOOL bGP)
  75. {
  76. switch(pData->GetType())
  77. {
  78. case ITEM_ANAL_SERV:
  79. return new CAnalysisService;
  80. case ITEM_B2ON:
  81. return new CAttrAudit;
  82. case ITEM_BON:
  83. case ITEM_BOOL:
  84. return new CAttrEnable (0);
  85. case ITEM_FILESD:
  86. case ITEM_REGSD:
  87. return new CAttrObject;
  88. case ITEM_DW:
  89. return new CAttrNumber (0);
  90. case ITEM_GROUP:
  91. // PropertySheet based
  92. break;
  93. case ITEM_PRIVS:
  94. return new CAttrRight;
  95. case ITEM_PROF_B2ON:
  96. return bGP ? new CDomainAudit : new CConfigAudit (0);
  97. case ITEM_PROF_BOOL:
  98. return bGP ? new CDomainEnable : new CConfigEnable (0);
  99. case ITEM_PROF_FILESD:
  100. case ITEM_PROF_REGSD:
  101. return bGP ? new CDomainObject : new CConfigObject (0);
  102. case ITEM_PROF_DW:
  103. return bGP ? new CDomainNumber : new CConfigNumber (0);
  104. case ITEM_PROF_GROUP:
  105. return bGP ? new CDomainGroup : new CConfigGroup (0);
  106. case ITEM_PROF_PRIVS:
  107. return bGP ? new CDomainPrivs : new CConfigPrivs (0);
  108. case ITEM_PROF_REGVALUE:
  109. switch(pData->GetID())
  110. {
  111. case SCE_REG_DISPLAY_NUMBER:
  112. return bGP ? new CDomainRegNumber : new CConfigRegNumber (0);
  113. case SCE_REG_DISPLAY_STRING:
  114. return bGP ? new CDomainRegString(0) : new CConfigRegString (0); //Raid #381309, 4/31/2001
  115. case SCE_REG_DISPLAY_FLAGS:
  116. return bGP ? new CDomainRegFlags : new CConfigRegFlags (0);
  117. case SCE_REG_DISPLAY_CHOICE:
  118. return bGP ? new CDomainChoice : new CConfigChoice (0);
  119. case SCE_REG_DISPLAY_MULTISZ:
  120. if ( bGP )
  121. return new CDomainRegMultiSZ;
  122. else
  123. return new CConfigRegMultiSZ;
  124. default:
  125. return bGP ? new CDomainRegEnable : new CConfigRegEnable (0);
  126. }
  127. case ITEM_PROF_RET:
  128. return bGP ? new CDomainRet : new CConfigRet (0);
  129. case ITEM_PROF_SERV:
  130. return bGP ? new CDomainService : new CConfigService (0);
  131. case ITEM_PROF_SZ:
  132. return bGP ? new CDomainName : new CConfigName (0);
  133. case ITEM_REGVALUE:
  134. switch (pData->GetID())
  135. {
  136. case SCE_REG_DISPLAY_NUMBER:
  137. return new CAttrRegNumber;
  138. case SCE_REG_DISPLAY_STRING:
  139. return new CAttrRegString (0);
  140. case SCE_REG_DISPLAY_CHOICE:
  141. return new CAttrChoice;
  142. case SCE_REG_DISPLAY_FLAGS:
  143. return new CAttrRegFlags;
  144. case SCE_REG_DISPLAY_MULTISZ:
  145. return new CAttrRegMultiSZ;
  146. default:
  147. return new CAttrRegEnable;
  148. }
  149. case ITEM_RET:
  150. return new CAttrRet (0);
  151. case ITEM_SZ:
  152. return new CAttrString (0);
  153. case ITEM_LOCALPOL_RET:
  154. return new CLocalPolRet;
  155. case ITEM_LOCALPOL_SZ:
  156. return new CLocalPolString;
  157. case ITEM_LOCALPOL_B2ON:
  158. return new CLocalPolAudit;
  159. case ITEM_LOCALPOL_BON:
  160. case ITEM_LOCALPOL_BOOL:
  161. return new CLocalPolEnable;
  162. case ITEM_LOCALPOL_DW:
  163. return new CLocalPolNumber;
  164. case ITEM_LOCALPOL_PRIVS:
  165. return new CLocalPolRight;
  166. case ITEM_LOCALPOL_REGVALUE:
  167. switch (pData->GetID())
  168. {
  169. case SCE_REG_DISPLAY_NUMBER:
  170. return new CLocalPolRegNumber;
  171. case SCE_REG_DISPLAY_STRING:
  172. return new CLocalPolRegString (0);
  173. case SCE_REG_DISPLAY_MULTISZ:
  174. return new CLocalPolRegMultiSZ;
  175. case SCE_REG_DISPLAY_CHOICE:
  176. return new CLocalPolChoice;
  177. case SCE_REG_DISPLAY_FLAGS:
  178. return new CLocalPolRegFlags;
  179. default:
  180. return new CLocalPolRegEnable;
  181. }
  182. }
  183. return 0;
  184. }
  185. BOOL IsPointerType(CResult *pData)
  186. {
  187. switch (pData->GetType())
  188. {
  189. case ITEM_LOCALPOL_PRIVS:
  190. case ITEM_LOCALPOL_SZ:
  191. return TRUE;
  192. case ITEM_REGVALUE:
  193. switch (pData->GetID())
  194. {
  195. case SCE_REG_DISPLAY_STRING:
  196. case SCE_REG_DISPLAY_MULTISZ:
  197. return TRUE;
  198. default:
  199. return FALSE;
  200. }
  201. break;
  202. default:
  203. break;
  204. }
  205. return FALSE;
  206. }
  207. HRESULT CSnapin::AddAttrPropPages(LPPROPERTYSHEETCALLBACK pCallback,
  208. CResult *pData,
  209. LONG_PTR handle)
  210. {
  211. ASSERT(pCallback);
  212. ASSERT(pData);
  213. if (!pCallback || !pData)
  214. {
  215. return E_POINTER;
  216. }
  217. BOOL bGP = ( (GetModeBits() & MB_SINGLE_TEMPLATE_ONLY) == MB_SINGLE_TEMPLATE_ONLY );
  218. BOOL bReadOnly = ( (GetModeBits() & MB_READ_ONLY) == MB_READ_ONLY );
  219. RESULT_TYPES type = pData->GetType();
  220. CAttribute* pAttr = NULL;
  221. HRESULT hr = S_OK;
  222. //
  223. // If the item has an entry from global policy then treat it as read only
  224. //
  225. if ((GetModeBits() & MB_LOCALSEC) == MB_LOCALSEC)
  226. {
  227. bGP = FALSE;
  228. if (type == ITEM_LOCALPOL_REGVALUE)
  229. {
  230. SCE_REGISTRY_VALUE_INFO *pRegValue = NULL;
  231. pRegValue = (PSCE_REGISTRY_VALUE_INFO)pData->GetSetting();
  232. if ( pRegValue && pRegValue->Status != SCE_STATUS_NOT_CONFIGURED )
  233. {
  234. bReadOnly = TRUE;
  235. }
  236. }
  237. else if (IsPointerType(pData))
  238. {
  239. //
  240. // If there is a setting it's a pointer; if not, it is NULL
  241. //
  242. if (pData->GetSetting())
  243. {
  244. bReadOnly = TRUE;
  245. }
  246. }
  247. else if ((LONG_PTR)ULongToPtr(SCE_NO_VALUE) != pData->GetSetting())
  248. {
  249. bReadOnly = TRUE;
  250. }
  251. }
  252. if (type == ITEM_GROUP)
  253. {
  254. CAttrMember *pMemberPage = new CAttrMember;
  255. CAttrMember *pMemberOfPage = new CAttrMember;
  256. if ( pMemberPage && pMemberOfPage)
  257. {
  258. pMemberPage->Initialize(pData);
  259. pMemberPage->SetMemberType(GROUP_MEMBERS);
  260. pMemberPage->SetSnapin(this);
  261. pMemberPage->SetSibling(pMemberOfPage);
  262. HPROPSHEETPAGE hPage = MyCreatePropertySheetPage (&pMemberPage->m_psp);
  263. if (hPage)
  264. {
  265. hr = pCallback->AddPage (hPage);
  266. ASSERT (SUCCEEDED (hr));
  267. // the pointer is already added to the sheet
  268. pMemberPage = NULL;
  269. }
  270. else
  271. {
  272. // Oops, fail to create the property sheet page
  273. hr = E_FAIL;
  274. }
  275. if ( SUCCEEDED(hr) )
  276. {
  277. pMemberOfPage->Initialize(pData);
  278. pMemberOfPage->SetMemberType(GROUP_MEMBER_OF);
  279. pMemberOfPage->SetSnapin(this);
  280. pMemberOfPage->SetSibling(pMemberPage);
  281. HPROPSHEETPAGE hPage = MyCreatePropertySheetPage (&pMemberOfPage->m_psp);
  282. if (hPage)
  283. {
  284. hr = pCallback->AddPage (hPage);
  285. ASSERT (SUCCEEDED (hr));
  286. // the pointer is already added to the sheet
  287. pMemberOfPage = NULL;
  288. }
  289. else
  290. {
  291. hr = E_FAIL;
  292. }
  293. }
  294. }
  295. else
  296. {
  297. hr = E_OUTOFMEMORY;
  298. }
  299. if ( pMemberPage )
  300. {
  301. delete pMemberPage;
  302. }
  303. if ( pMemberOfPage )
  304. {
  305. delete pMemberOfPage;
  306. }
  307. }
  308. else
  309. {
  310. pAttr = CloneAttrDialog(pData,bGP);
  311. if (pAttr)
  312. {
  313. pAttr->SetSnapin(this);
  314. pAttr->Initialize(pData);
  315. pAttr->SetReadOnly(bReadOnly);
  316. pAttr->SetTitle(pData->GetAttrPretty());
  317. HPROPSHEETPAGE hPage = MyCreatePropertySheetPage (&pAttr->m_psp);
  318. if (hPage)
  319. {
  320. hr = pCallback->AddPage (hPage);
  321. ASSERT (SUCCEEDED (hr));
  322. }
  323. else
  324. {
  325. //
  326. // fail to create the property sheet
  327. //
  328. delete pAttr;
  329. hr = E_FAIL;
  330. }
  331. }
  332. else
  333. {
  334. hr = E_OUTOFMEMORY;
  335. }
  336. }
  337. if ( SUCCEEDED(hr) )
  338. {
  339. //
  340. // In RSOP mode we need to add a precedence page too
  341. //
  342. if ((GetModeBits() & MB_RSOP) == MB_RSOP)
  343. {
  344. CPrecedencePage *ppp = new CPrecedencePage;
  345. if (ppp)
  346. {
  347. ppp->SetTitle(pData->GetAttrPretty());
  348. ppp->Initialize(pData,GetWMIRsop());
  349. HPROPSHEETPAGE hPage = MyCreatePropertySheetPage (&ppp->m_psp);
  350. if (hPage)
  351. {
  352. hr = pCallback->AddPage (hPage);
  353. ASSERT (SUCCEEDED (hr));
  354. }
  355. else
  356. {
  357. //
  358. // if the property sheet fails to be created, should free the buffer
  359. //
  360. delete ppp;
  361. hr = E_FAIL;
  362. }
  363. }
  364. else
  365. {
  366. hr = E_OUTOFMEMORY;
  367. }
  368. }
  369. }
  370. return hr;
  371. }
  372. HRESULT CComponentDataImpl::AddAttrPropPages(LPPROPERTYSHEETCALLBACK pCallback,
  373. CFolder *pData,
  374. LONG_PTR handle)
  375. {
  376. HRESULT hr=E_FAIL;
  377. CString strName;
  378. ASSERT(pCallback);
  379. ASSERT(pData);
  380. if (!pCallback || !pData)
  381. {
  382. return E_POINTER;
  383. }
  384. BOOL bReadOnly = ((GetModeBits() & MB_READ_ONLY) == MB_READ_ONLY);
  385. pData->GetDisplayName(strName,0);
  386. CAttrObject *pAttr = new CAttrObject;
  387. if (pAttr)
  388. {
  389. pAttr->Initialize(pData,this);
  390. pAttr->SetTitle(strName);
  391. pAttr->SetReadOnly(bReadOnly);
  392. HPROPSHEETPAGE hPage = MyCreatePropertySheetPage (&pAttr->m_psp);
  393. if ( hPage )
  394. {
  395. hr = pCallback->AddPage (hPage);
  396. ASSERT (SUCCEEDED (hr));
  397. }
  398. else
  399. {
  400. delete pAttr;
  401. hr = E_FAIL;
  402. }
  403. }
  404. else
  405. {
  406. hr = E_OUTOFMEMORY;
  407. }
  408. return hr;
  409. }