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.

382 lines
9.3 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation 1996-2001.
  5. //
  6. // File: cobject.cpp
  7. //
  8. // Contents: implementation of CConfigObject
  9. //
  10. //----------------------------------------------------------------------------
  11. #include "stdafx.h"
  12. #include "wsecmgr.h"
  13. #include "attr.h"
  14. #include "resource.h"
  15. #include "snapmgr.h"
  16. #include "util.h"
  17. #include "servperm.h"
  18. #include "CObject.h"
  19. #ifdef _DEBUG
  20. #define new DEBUG_NEW
  21. #undef THIS_FILE
  22. static char THIS_FILE[] = __FILE__;
  23. #endif
  24. /////////////////////////////////////////////////////////////////////////////
  25. // CConfigObject dialog
  26. CConfigObject::CConfigObject(UINT nTemplateID)
  27. : CAttribute(nTemplateID ? nTemplateID : IDD),
  28. m_pfnCreateDsPage(NULL),
  29. m_pSI(NULL),
  30. m_pNewSD(NULL),
  31. m_NewSeInfo(0),
  32. m_hwndSecurity(NULL)
  33. {
  34. //{{AFX_DATA_INIT(CConfigObject)
  35. m_radConfigPrevent = 0;
  36. m_radInheritOverwrite = 0;
  37. //}}AFX_DATA_INIT
  38. m_pHelpIDs = (DWORD_PTR)a197HelpIDs;
  39. m_uTemplateResID = IDD;
  40. }
  41. void CConfigObject::DoDataExchange(CDataExchange* pDX)
  42. {
  43. CAttribute::DoDataExchange(pDX);
  44. //{{AFX_DATA_MAP(CConfigObject)
  45. DDX_Radio(pDX, IDC_CONFIG, m_radConfigPrevent);
  46. DDX_Radio(pDX, IDC_INHERIT, m_radInheritOverwrite);
  47. //}}AFX_DATA_MAP
  48. }
  49. BEGIN_MESSAGE_MAP(CConfigObject, CAttribute)
  50. //{{AFX_MSG_MAP(CConfigObject)
  51. ON_BN_CLICKED(IDC_SECURITY, OnTemplateSecurity)
  52. ON_BN_CLICKED(IDC_CONFIG, OnConfig)
  53. ON_BN_CLICKED(IDC_PREVENT, OnPrevent)
  54. //}}AFX_MSG_MAP
  55. END_MESSAGE_MAP()
  56. /////////////////////////////////////////////////////////////////////////////
  57. // CConfigObject message handlers
  58. BOOL CConfigObject::OnApply()
  59. {
  60. if ( !m_bReadOnly )
  61. {
  62. DWORD dw = 0;
  63. int status = 0;
  64. UpdateData(TRUE);
  65. PEDITTEMPLATE pTemp = m_pData->GetBaseProfile();
  66. switch (m_radConfigPrevent)
  67. {
  68. case 0:
  69. // config
  70. switch(m_radInheritOverwrite)
  71. {
  72. case 0:
  73. // inherit
  74. dw = SCE_STATUS_CHECK;
  75. break;
  76. case 1:
  77. // overwrite
  78. dw = SCE_STATUS_OVERWRITE;
  79. break;
  80. default:
  81. break;
  82. }
  83. break;
  84. case 1:
  85. // prevent
  86. dw = SCE_STATUS_IGNORE;
  87. break;
  88. default:
  89. break;
  90. }
  91. PSCE_OBJECT_SECURITY pObjSec=(PSCE_OBJECT_SECURITY)(m_pData->GetID());
  92. if ( NULL == pObjSec )
  93. {
  94. //
  95. // this branch is impossible
  96. //
  97. if ( m_pNewSD != NULL )
  98. {
  99. LocalFree(m_pNewSD);
  100. m_pNewSD = NULL;
  101. }
  102. }
  103. else
  104. {
  105. //
  106. // an existing object
  107. //
  108. pObjSec->Status = (BYTE)dw;
  109. if ( m_pNewSD != NULL )
  110. {
  111. if ( pObjSec->pSecurityDescriptor != m_pNewSD &&
  112. pObjSec->pSecurityDescriptor != NULL )
  113. {
  114. LocalFree(pObjSec->pSecurityDescriptor);
  115. }
  116. pObjSec->pSecurityDescriptor = m_pNewSD;
  117. m_pNewSD = NULL;
  118. pObjSec->SeInfo = m_NewSeInfo;
  119. }
  120. m_pData->SetStatus(dw);
  121. }
  122. m_pData->Update(m_pSnapin);
  123. m_NewSeInfo = 0;
  124. m_hwndParent = NULL;
  125. if ( m_pSI )
  126. {
  127. m_pSI->Release();
  128. m_pSI = NULL;
  129. }
  130. m_pfnCreateDsPage=NULL;
  131. }
  132. return CAttribute::OnApply();
  133. }
  134. void CConfigObject::OnCancel()
  135. {
  136. if ( m_pNewSD ) {
  137. LocalFree(m_pNewSD);
  138. m_pNewSD = NULL;
  139. }
  140. m_NewSeInfo = 0;
  141. m_hwndParent = NULL;
  142. if ( m_pSI ) {
  143. m_pSI->Release();
  144. m_pSI = NULL;
  145. }
  146. m_pfnCreateDsPage=NULL;
  147. CAttribute::OnCancel();
  148. }
  149. void CConfigObject::OnTemplateSecurity()
  150. {
  151. SE_OBJECT_TYPE SeType;
  152. if (IsWindow(m_hwndSecurity)) {
  153. ::BringWindowToTop(m_hwndSecurity);
  154. return;
  155. }
  156. switch(m_pData->GetType()) {
  157. case ITEM_PROF_REGSD:
  158. SeType = SE_REGISTRY_KEY;
  159. break;
  160. case ITEM_PROF_FILESD:
  161. SeType = SE_FILE_OBJECT;
  162. break;
  163. default:
  164. ASSERT(FALSE);
  165. return;
  166. }
  167. INT_PTR nRet;
  168. if ( SE_DS_OBJECT == SeType ) {
  169. if ( !m_pfnCreateDsPage ) {
  170. if (!g_hDsSecDll)
  171. g_hDsSecDll = LoadLibrary(TEXT("dssec.dll"));
  172. if ( g_hDsSecDll) {
  173. m_pfnCreateDsPage = (PFNDSCREATEISECINFO)GetProcAddress(g_hDsSecDll,
  174. "DSCreateISecurityInfoObject");
  175. }
  176. }
  177. if ( m_pfnCreateDsPage ) {
  178. nRet= MyCreateDsSecurityPage(&m_pSI, m_pfnCreateDsPage,
  179. &m_pNewSD, &m_NewSeInfo,
  180. (LPCTSTR)(m_pData->GetAttr()),
  181. QueryReadOnly() ? SECURITY_PAGE_READ_ONLY : SECURITY_PAGE,
  182. m_hwndParent);
  183. } else
  184. nRet = -1;
  185. } else {
  186. BOOL bContainer;
  187. if ( SE_FILE_OBJECT == SeType ) {
  188. if ( m_pData->GetID() ) {
  189. bContainer = ((PSCE_OBJECT_SECURITY)(m_pData->GetID()))->IsContainer;
  190. } else {
  191. bContainer = FALSE;
  192. }
  193. } else {
  194. bContainer = TRUE;
  195. }
  196. m_hwndSecurity = (HWND) MyCreateSecurityPage2(bContainer,
  197. &m_pNewSD,
  198. &m_NewSeInfo,
  199. (LPCTSTR)(m_pData->GetAttr()),
  200. SeType,
  201. QueryReadOnly() ? SECURITY_PAGE_READ_ONLY : SECURITY_PAGE,
  202. GetSafeHwnd(),
  203. FALSE); // not modeless
  204. }
  205. if (NULL == m_hwndSecurity ) {
  206. /*
  207. BUG 147098 applies here - don't display message if this was canceled
  208. CString str;
  209. str.LoadString(IDS_CANT_ASSIGN_SECURITY);
  210. AfxMessageBox(str);
  211. */
  212. }
  213. }
  214. void CConfigObject::Initialize(CResult * pData)
  215. {
  216. CAttribute::Initialize(pData);
  217. if ( m_pSI ) {
  218. m_pSI->Release();
  219. m_pSI = NULL;
  220. }
  221. m_pfnCreateDsPage=NULL;
  222. m_pNewSD = NULL;
  223. m_NewSeInfo = 0;
  224. // if (SCE_NO_VALUE == pData->GetBase()) {
  225. if ( pData->GetID() ) {
  226. PSCE_OBJECT_SECURITY pObject = (PSCE_OBJECT_SECURITY)(pData->GetID());
  227. switch (pObject-> Status) {
  228. case SCE_STATUS_IGNORE:
  229. m_radConfigPrevent = 1;
  230. m_radInheritOverwrite = 0;
  231. break;
  232. case SCE_STATUS_OVERWRITE:
  233. m_radConfigPrevent = 0;
  234. m_radInheritOverwrite = 1;
  235. break;
  236. case SCE_STATUS_CHECK:
  237. m_radConfigPrevent = 0;
  238. m_radInheritOverwrite = 0;
  239. break;
  240. case SCE_STATUS_NO_AUTO_INHERIT:
  241. default:
  242. m_radConfigPrevent = 1;
  243. m_radInheritOverwrite = 0;
  244. break;
  245. }
  246. if ( pObject->pSecurityDescriptor ) {
  247. MyMakeSelfRelativeSD(pObject->pSecurityDescriptor,
  248. &m_pNewSD);
  249. }
  250. m_NewSeInfo = pObject->SeInfo;
  251. }
  252. }
  253. BOOL CConfigObject::OnInitDialog()
  254. {
  255. CAttribute::OnInitDialog();
  256. UpdateData(FALSE);
  257. AddUserControl(IDC_OVERWRITE);
  258. AddUserControl(IDC_PREVENT);
  259. AddUserControl(IDC_INHERIT);
  260. AddUserControl(IDC_SECURITY);
  261. AddUserControl(IDC_CONFIG);
  262. OnConfigure();
  263. if (ITEM_PROF_REGSD == m_pData->GetType()) {
  264. CString str;
  265. str.LoadString(IDS_REGISTRY_CONFIGURE);
  266. SetDlgItemText(IDC_CONFIG,str);
  267. str.LoadString(IDS_REGISTRY_APPLY);
  268. SetDlgItemText(IDC_OVERWRITE,str);
  269. str.LoadString(IDS_REGISTRY_INHERIT);
  270. SetDlgItemText(IDC_INHERIT,str);
  271. str.LoadString(IDS_REGISTRY_PREVENT);
  272. SetDlgItemText(IDC_PREVENT,str);
  273. }
  274. if (QueryReadOnly()) {
  275. CString str;
  276. str.LoadString(IDS_VIEW_SECURITY);
  277. SetDlgItemText(IDC_SECURITY,str);
  278. }
  279. if (m_bConfigure) {
  280. if (0 == m_radConfigPrevent) {
  281. OnConfig();
  282. } else {
  283. OnPrevent();
  284. }
  285. }
  286. return TRUE; // return TRUE unless you set the focus to a control
  287. // EXCEPTION: OCX Property Pages should return FALSE
  288. }
  289. void CConfigObject::OnConfig()
  290. {
  291. CWnd *pRadio = 0;
  292. if (m_bConfigure && !QueryReadOnly())
  293. {
  294. pRadio = GetDlgItem(IDC_INHERIT);
  295. pRadio->EnableWindow(TRUE);
  296. pRadio = GetDlgItem(IDC_OVERWRITE);
  297. pRadio->EnableWindow(TRUE);
  298. }
  299. }
  300. void CConfigObject::OnPrevent()
  301. {
  302. CWnd *pRadio = GetDlgItem(IDC_INHERIT);
  303. pRadio->EnableWindow(FALSE);
  304. pRadio = GetDlgItem(IDC_OVERWRITE);
  305. pRadio->EnableWindow(FALSE);
  306. }
  307. void
  308. CConfigObject::EnableUserControls( BOOL bEnable ) {
  309. CAttribute::EnableUserControls(bEnable);
  310. //
  311. // IDC_SECURITY needs to be available even in read only
  312. // mode so that the security page can be viewed.
  313. //
  314. // The page itself will be read only if necessary
  315. //
  316. if (QueryReadOnly() && bEnable) {
  317. CWnd *wnd = GetDlgItem(IDC_SECURITY);
  318. if (wnd) {
  319. wnd->EnableWindow(TRUE);
  320. }
  321. }
  322. }