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.

415 lines
11 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. ON_BN_CLICKED(IDC_OVERWRITE, OnOverwriteInherit)
  55. ON_BN_CLICKED(IDC_INHERIT, OnOverwriteInherit)
  56. //}}AFX_MSG_MAP
  57. END_MESSAGE_MAP()
  58. /////////////////////////////////////////////////////////////////////////////
  59. // CConfigObject message handlers
  60. BOOL CConfigObject::OnApply()
  61. {
  62. if ( !m_bReadOnly )
  63. {
  64. DWORD dw = 0;
  65. int status = 0;
  66. UpdateData(TRUE);
  67. PEDITTEMPLATE pTemp = m_pData->GetBaseProfile();
  68. switch (m_radConfigPrevent)
  69. {
  70. case 0:
  71. // config
  72. switch(m_radInheritOverwrite)
  73. {
  74. case 0:
  75. // inherit
  76. dw = SCE_STATUS_CHECK;
  77. break;
  78. case 1:
  79. // overwrite
  80. dw = SCE_STATUS_OVERWRITE;
  81. break;
  82. default:
  83. break;
  84. }
  85. break;
  86. case 1:
  87. // prevent
  88. dw = SCE_STATUS_IGNORE;
  89. break;
  90. default:
  91. break;
  92. }
  93. PSCE_OBJECT_SECURITY pObjSec=(PSCE_OBJECT_SECURITY)(m_pData->GetID());
  94. if ( NULL == pObjSec )
  95. {
  96. //
  97. // this branch is impossible
  98. //
  99. if ( m_pNewSD != NULL )
  100. {
  101. LocalFree(m_pNewSD);
  102. m_pNewSD = NULL;
  103. }
  104. }
  105. else
  106. {
  107. //
  108. // an existing object
  109. //
  110. pObjSec->Status = (BYTE)dw;
  111. if ( m_pNewSD != NULL )
  112. {
  113. if ( pObjSec->pSecurityDescriptor != m_pNewSD &&
  114. pObjSec->pSecurityDescriptor != NULL )
  115. {
  116. LocalFree(pObjSec->pSecurityDescriptor);
  117. }
  118. pObjSec->pSecurityDescriptor = m_pNewSD;
  119. m_pNewSD = NULL;
  120. pObjSec->SeInfo = m_NewSeInfo;
  121. }
  122. m_pData->SetStatus(dw);
  123. }
  124. m_pData->Update(m_pSnapin);
  125. m_NewSeInfo = 0;
  126. m_hwndParent = NULL;
  127. if ( m_pSI )
  128. {
  129. m_pSI->Release();
  130. m_pSI = NULL;
  131. }
  132. m_pfnCreateDsPage=NULL;
  133. }
  134. return CAttribute::OnApply();
  135. }
  136. void CConfigObject::OnCancel()
  137. {
  138. if ( m_pNewSD ) {
  139. LocalFree(m_pNewSD);
  140. m_pNewSD = NULL;
  141. }
  142. m_NewSeInfo = 0;
  143. m_hwndParent = NULL;
  144. if ( m_pSI ) {
  145. m_pSI->Release();
  146. m_pSI = NULL;
  147. }
  148. m_pfnCreateDsPage=NULL;
  149. CAttribute::OnCancel();
  150. }
  151. void CConfigObject::OnTemplateSecurity()
  152. {
  153. SE_OBJECT_TYPE SeType;
  154. if (IsWindow(m_hwndSecurity)) {
  155. ::BringWindowToTop(m_hwndSecurity);
  156. return;
  157. }
  158. switch(m_pData->GetType()) {
  159. case ITEM_PROF_REGSD:
  160. SeType = SE_REGISTRY_KEY;
  161. break;
  162. case ITEM_PROF_FILESD:
  163. SeType = SE_FILE_OBJECT;
  164. break;
  165. default:
  166. ASSERT(FALSE);
  167. return;
  168. }
  169. INT_PTR nRet;
  170. if ( SE_DS_OBJECT == SeType ) {
  171. if ( !m_pfnCreateDsPage ) {
  172. if (!g_hDsSecDll)
  173. g_hDsSecDll = LoadLibrary(TEXT("dssec.dll"));
  174. if ( g_hDsSecDll) {
  175. m_pfnCreateDsPage = (PFNDSCREATEISECINFO)GetProcAddress(g_hDsSecDll,
  176. "DSCreateISecurityInfoObject");
  177. }
  178. }
  179. if ( m_pfnCreateDsPage ) {
  180. nRet= MyCreateDsSecurityPage(&m_pSI, m_pfnCreateDsPage,
  181. &m_pNewSD, &m_NewSeInfo,
  182. (LPCTSTR)(m_pData->GetAttr()),
  183. QueryReadOnly() ? SECURITY_PAGE_READ_ONLY : SECURITY_PAGE,
  184. m_hwndParent);
  185. } else
  186. nRet = -1;
  187. } else {
  188. BOOL bContainer;
  189. if ( SE_FILE_OBJECT == SeType ) {
  190. if ( m_pData->GetID() ) {
  191. bContainer = ((PSCE_OBJECT_SECURITY)(m_pData->GetID()))->IsContainer;
  192. } else {
  193. bContainer = FALSE;
  194. }
  195. } else {
  196. bContainer = TRUE;
  197. }
  198. m_hwndSecurity = (HWND) MyCreateSecurityPage2(bContainer,
  199. &m_pNewSD,
  200. &m_NewSeInfo,
  201. (LPCTSTR)(m_pData->GetAttr()),
  202. SeType,
  203. QueryReadOnly() ? SECURITY_PAGE_READ_ONLY : SECURITY_PAGE,
  204. GetSafeHwnd(),
  205. FALSE); // not modeless
  206. }
  207. if (NULL == m_hwndSecurity ) {
  208. /*
  209. BUG 147098 applies here - don't display message if this was canceled
  210. CString str;
  211. str.LoadString(IDS_CANT_ASSIGN_SECURITY);
  212. AfxMessageBox(str);
  213. */
  214. }
  215. }
  216. void CConfigObject::Initialize(CResult * pData)
  217. {
  218. CAttribute::Initialize(pData);
  219. if ( m_pSI ) {
  220. m_pSI->Release();
  221. m_pSI = NULL;
  222. }
  223. m_pfnCreateDsPage=NULL;
  224. m_pNewSD = NULL;
  225. m_NewSeInfo = 0;
  226. // if (SCE_NO_VALUE == pData->GetBase()) {
  227. if ( pData->GetID() ) {
  228. PSCE_OBJECT_SECURITY pObject = (PSCE_OBJECT_SECURITY)(pData->GetID());
  229. switch (pObject-> Status) {
  230. case SCE_STATUS_IGNORE:
  231. m_radConfigPrevent = 1;
  232. m_radInheritOverwrite = 0;
  233. break;
  234. case SCE_STATUS_OVERWRITE:
  235. m_radConfigPrevent = 0;
  236. m_radInheritOverwrite = 1;
  237. break;
  238. case SCE_STATUS_CHECK:
  239. m_radConfigPrevent = 0;
  240. m_radInheritOverwrite = 0;
  241. break;
  242. case SCE_STATUS_NO_AUTO_INHERIT:
  243. default:
  244. m_radConfigPrevent = 1;
  245. m_radInheritOverwrite = 0;
  246. break;
  247. }
  248. if ( pObject->pSecurityDescriptor ) {
  249. MyMakeSelfRelativeSD(pObject->pSecurityDescriptor,
  250. &m_pNewSD);
  251. }
  252. m_NewSeInfo = pObject->SeInfo;
  253. }
  254. }
  255. BOOL CConfigObject::OnInitDialog()
  256. {
  257. CAttribute::OnInitDialog();
  258. UpdateData(FALSE);
  259. AddUserControl(IDC_OVERWRITE);
  260. AddUserControl(IDC_PREVENT);
  261. AddUserControl(IDC_INHERIT);
  262. AddUserControl(IDC_SECURITY);
  263. AddUserControl(IDC_CONFIG);
  264. OnConfigure();
  265. if (ITEM_PROF_REGSD == m_pData->GetType()) {
  266. CString str;
  267. str.LoadString(IDS_REGISTRY_CONFIGURE);
  268. SetDlgItemText(IDC_CONFIG,str);
  269. str.LoadString(IDS_REGISTRY_APPLY);
  270. SetDlgItemText(IDC_OVERWRITE,str);
  271. str.LoadString(IDS_REGISTRY_INHERIT);
  272. SetDlgItemText(IDC_INHERIT,str);
  273. str.LoadString(IDS_REGISTRY_PREVENT);
  274. SetDlgItemText(IDC_PREVENT,str);
  275. }
  276. if (QueryReadOnly()) {
  277. CString str;
  278. str.LoadString(IDS_VIEW_SECURITY);
  279. SetDlgItemText(IDC_SECURITY,str);
  280. }
  281. if (m_bConfigure) {
  282. if (0 == m_radConfigPrevent) {
  283. OnConfig();
  284. } else {
  285. OnPrevent();
  286. }
  287. }
  288. return TRUE; // return TRUE unless you set the focus to a control
  289. // EXCEPTION: OCX Property Pages should return FALSE
  290. }
  291. void CConfigObject::OnConfig()
  292. {
  293. CWnd *pRadio = 0;
  294. int privValue = m_radConfigPrevent; //Raid #478746, Yanggao, 10/10/2001
  295. UpdateData();
  296. if (m_bConfigure && !QueryReadOnly())
  297. {
  298. pRadio = GetDlgItem(IDC_INHERIT);
  299. pRadio->EnableWindow(TRUE);
  300. pRadio = GetDlgItem(IDC_OVERWRITE);
  301. pRadio->EnableWindow(TRUE);
  302. pRadio = GetDlgItem(IDC_SECURITY); //Raid #467312, Yang Gao
  303. if( pRadio )
  304. pRadio->EnableWindow(TRUE);
  305. if(m_radConfigPrevent != privValue) //Raid #478746, Yanggao, 10/10/2001
  306. {
  307. SetModified(TRUE);
  308. }
  309. }
  310. }
  311. void CConfigObject::OnPrevent()
  312. {
  313. CWnd *pRadio = GetDlgItem(IDC_INHERIT);
  314. pRadio->EnableWindow(FALSE);
  315. pRadio = GetDlgItem(IDC_OVERWRITE);
  316. pRadio->EnableWindow(FALSE);
  317. pRadio = GetDlgItem(IDC_SECURITY); //Raid #467312, Yang Gao
  318. if( pRadio )
  319. pRadio->EnableWindow(FALSE);
  320. int privValue = m_radConfigPrevent; //Raid #478746, Yanggao, 10/10/2001
  321. UpdateData();
  322. if(m_radConfigPrevent != privValue)
  323. {
  324. SetModified(TRUE);
  325. }
  326. }
  327. void CConfigObject::OnOverwriteInherit() //Raid #478746, Yanggao, 10/10/2001
  328. {
  329. int privValue = m_radInheritOverwrite;
  330. UpdateData();
  331. if(m_radInheritOverwrite != privValue)
  332. {
  333. SetModified(TRUE);
  334. }
  335. }
  336. void
  337. CConfigObject::EnableUserControls( BOOL bEnable ) {
  338. CAttribute::EnableUserControls(bEnable);
  339. //
  340. // IDC_SECURITY needs to be available even in read only
  341. // mode so that the security page can be viewed.
  342. //
  343. // The page itself will be read only if necessary
  344. //
  345. if (QueryReadOnly() && bEnable) {
  346. CWnd *wnd = GetDlgItem(IDC_SECURITY);
  347. if (wnd) {
  348. wnd->EnableWindow(TRUE);
  349. }
  350. }
  351. }