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.

490 lines
13 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)); //This is not safe. hr should be checked in order to do pMemberPage = NULL.
  267. if( SUCCEEDED (hr) ) //Raid #550912, yanggao.
  268. {
  269. // the pointer is already added to the sheet
  270. pMemberPage = NULL;
  271. }
  272. }
  273. else
  274. {
  275. // Oops, fail to create the property sheet page
  276. hr = E_FAIL;
  277. }
  278. if ( SUCCEEDED(hr) )
  279. {
  280. pMemberOfPage->Initialize(pData);
  281. pMemberOfPage->SetMemberType(GROUP_MEMBER_OF);
  282. pMemberOfPage->SetSnapin(this);
  283. pMemberOfPage->SetSibling(pMemberPage);
  284. hPage = MyCreatePropertySheetPage (&pMemberOfPage->m_psp); //Raid #prefast
  285. if (hPage)
  286. {
  287. hr = pCallback->AddPage (hPage);
  288. ASSERT (SUCCEEDED (hr)); //This is not safe. hr should be checked in order to do pMemberOfPage = NULL.
  289. if( SUCCEEDED (hr) )//Raid #550912, yanggao.
  290. {
  291. // the pointer is already added to the sheet
  292. pMemberOfPage = NULL;
  293. }
  294. }
  295. else
  296. {
  297. hr = E_FAIL;
  298. }
  299. }
  300. }
  301. else
  302. {
  303. hr = E_OUTOFMEMORY;
  304. }
  305. if ( pMemberPage )
  306. {
  307. delete pMemberPage;
  308. }
  309. if ( pMemberOfPage )
  310. {
  311. delete pMemberOfPage;
  312. }
  313. }
  314. else
  315. {
  316. pAttr = CloneAttrDialog(pData,bGP);
  317. if (pAttr)
  318. {
  319. pAttr->SetSnapin(this);
  320. pAttr->Initialize(pData);
  321. pAttr->SetReadOnly(bReadOnly);
  322. pAttr->SetTitle(pData->GetAttrPretty());
  323. HPROPSHEETPAGE hPage = MyCreatePropertySheetPage (&pAttr->m_psp);
  324. if (hPage)
  325. {
  326. hr = pCallback->AddPage (hPage);
  327. ASSERT (SUCCEEDED (hr)); //This is not safe. hr should be checked in order to delete pAttr.
  328. if( !SUCCEEDED (hr) ) //Raid #550912, yanggao.
  329. {
  330. delete pAttr;
  331. }
  332. }
  333. else
  334. {
  335. //
  336. // fail to create the property sheet
  337. //
  338. delete pAttr;
  339. hr = E_FAIL;
  340. }
  341. }
  342. else
  343. {
  344. hr = E_OUTOFMEMORY;
  345. }
  346. }
  347. if ( SUCCEEDED(hr) )
  348. {
  349. //
  350. // In RSOP mode we need to add a precedence page too
  351. //
  352. if ((GetModeBits() & MB_RSOP) == MB_RSOP)
  353. {
  354. CPrecedencePage *ppp = new CPrecedencePage;
  355. if (ppp)
  356. {
  357. ppp->SetTitle(pData->GetAttrPretty());
  358. ppp->Initialize(pData,GetWMIRsop());
  359. HPROPSHEETPAGE hPage = MyCreatePropertySheetPage (&ppp->m_psp);
  360. if (hPage)
  361. {
  362. hr = pCallback->AddPage (hPage);
  363. ASSERT (SUCCEEDED (hr)); //This is not safe. hr should be checked in order to delete ppp.
  364. if( !SUCCEEDED (hr) )//Raid #550912, yanggao.
  365. {
  366. delete ppp;
  367. }
  368. }
  369. else
  370. {
  371. //
  372. // if the property sheet fails to be created, should free the buffer
  373. //
  374. delete ppp;
  375. hr = E_FAIL;
  376. }
  377. }
  378. else
  379. {
  380. hr = E_OUTOFMEMORY;
  381. }
  382. }
  383. }
  384. return hr;
  385. }
  386. HRESULT CComponentDataImpl::AddAttrPropPages(LPPROPERTYSHEETCALLBACK pCallback,
  387. CFolder *pData,
  388. LONG_PTR handle)
  389. {
  390. HRESULT hr=E_FAIL;
  391. CString strName;
  392. ASSERT(pCallback);
  393. ASSERT(pData);
  394. if (!pCallback || !pData)
  395. {
  396. return E_POINTER;
  397. }
  398. BOOL bReadOnly = ((GetModeBits() & MB_READ_ONLY) == MB_READ_ONLY);
  399. pData->GetDisplayName(strName,0);
  400. CAttrObject *pAttr = new CAttrObject;
  401. if (pAttr)
  402. {
  403. pAttr->Initialize(pData,this);
  404. pAttr->SetTitle(strName);
  405. pAttr->SetReadOnly(bReadOnly);
  406. HPROPSHEETPAGE hPage = MyCreatePropertySheetPage (&pAttr->m_psp);
  407. if ( hPage )
  408. {
  409. hr = pCallback->AddPage (hPage);
  410. ASSERT (SUCCEEDED (hr)); //This is not safe. hr should be checked in order to delete pAttr.
  411. if( !SUCCEEDED (hr) )//Raid #550912, yanggao.
  412. {
  413. delete pAttr;
  414. }
  415. }
  416. else
  417. {
  418. delete pAttr;
  419. hr = E_FAIL;
  420. }
  421. }
  422. else
  423. {
  424. hr = E_OUTOFMEMORY;
  425. }
  426. return hr;
  427. }