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.

404 lines
12 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation 1996-2001.
  5. //
  6. // File: aright.cpp
  7. //
  8. // Contents: implementation of CAttrRight
  9. //
  10. //----------------------------------------------------------------------------
  11. #include "stdafx.h"
  12. #include "wsecmgr.h"
  13. #include "snapmgr.h"
  14. #include "attr.h"
  15. #include "util.h"
  16. #include "chklist.h"
  17. #include "ARight.h"
  18. #include "getuser.h"
  19. #ifdef _DEBUG
  20. #define new DEBUG_NEW
  21. #undef THIS_FILE
  22. static char THIS_FILE[] = __FILE__;
  23. #endif
  24. /////////////////////////////////////////////////////////////////////////////
  25. // CAttrRight dialog
  26. CAttrRight::CAttrRight()
  27. : CAttribute(IDD),
  28. m_pMergeList(NULL),
  29. m_bDirty(false)
  30. {
  31. //{{AFX_DATA_INIT(CAttrRight)
  32. //}}AFX_DATA_INIT
  33. m_pHelpIDs = (DWORD_PTR)a191HelpIDs;
  34. m_uTemplateResID = IDD;
  35. }
  36. CAttrRight::~CAttrRight()
  37. {
  38. if ( m_pMergeList ) {
  39. SceFreeMemory(m_pMergeList, SCE_STRUCT_NAME_STATUS_LIST);
  40. m_pMergeList = NULL;
  41. }
  42. }
  43. void CAttrRight::DoDataExchange(CDataExchange* pDX)
  44. {
  45. CAttribute::DoDataExchange(pDX);
  46. //{{AFX_DATA_MAP(CAttrRight)
  47. //}}AFX_DATA_MAP
  48. }
  49. BEGIN_MESSAGE_MAP(CAttrRight, CAttribute)
  50. //{{AFX_MSG_MAP(CAttrRight)
  51. ON_BN_CLICKED(IDC_ADD, OnAdd)
  52. //}}AFX_MSG_MAP
  53. ON_NOTIFY(CLN_CLICK, IDC_RIGHTS, OnClickCheckBox)
  54. END_MESSAGE_MAP()
  55. /////////////////////////////////////////////////////////////////////////////
  56. // CAttrRight message handlers
  57. void CAttrRight::Initialize(CResult * pData)
  58. {
  59. CAttribute::Initialize(pData);
  60. //
  61. // The default for Not configured is false.
  62. //
  63. PSCE_PRIVILEGE_ASSIGNMENT pInspect, pTemplate;
  64. PSCE_NAME_LIST pnlTemplate=NULL,pnlInspect=NULL;
  65. pTemplate = (PSCE_PRIVILEGE_ASSIGNMENT) m_pData->GetBase();
  66. pInspect = (PSCE_PRIVILEGE_ASSIGNMENT) m_pData->GetSetting();
  67. if ((LONG_PTR)ULongToPtr(SCE_NO_VALUE) == (LONG_PTR)pTemplate || !pTemplate) {
  68. m_bConfigure = FALSE;
  69. pTemplate = NULL;
  70. }
  71. if ((LONG_PTR)ULongToPtr(SCE_NO_VALUE) == (LONG_PTR)pInspect) {
  72. pInspect = NULL;
  73. }
  74. if ( pTemplate ) {
  75. pnlTemplate = pTemplate->AssignedTo;
  76. }
  77. if ( pInspect ) {
  78. pnlInspect = pInspect->AssignedTo;
  79. }
  80. m_pMergeList = MergeNameStatusList(pnlTemplate, pnlInspect);
  81. m_bDirty=false;
  82. }
  83. BOOL CAttrRight::OnInitDialog()
  84. {
  85. CAttribute::OnInitDialog();
  86. PSCE_NAME_STATUS_LIST pItem;
  87. HWND hCheckList;
  88. LRESULT nItem;
  89. pItem = m_pMergeList;
  90. hCheckList = ::GetDlgItem(m_hWnd,IDC_RIGHTS);
  91. ::SendMessage(hCheckList,CLM_RESETCONTENT, 0, 0);
  92. RECT rAnal;
  93. LONG lWidth;
  94. GetDlgItem(IDC_ANALYZED_SETTING_STATIC)->GetWindowRect(&rAnal);
  95. // lWidth = rAnal.right - rAnal.left / 2;
  96. lWidth = 64;
  97. ::SendMessage(hCheckList,CLM_SETCOLUMNWIDTH,0,lWidth);
  98. while (pItem) {
  99. // Store the name of the item in the item data so we can retrieve it later
  100. nItem = ::SendMessage(hCheckList,CLM_ADDITEM,(WPARAM) pItem->Name,(LPARAM) pItem->Name);
  101. ::SendMessage(hCheckList,CLM_SETSTATE,MAKELONG(nItem,1),
  102. ((pItem->Status & MERGED_TEMPLATE) ? CLST_CHECKED : CLST_UNCHECKED));
  103. ::SendMessage(hCheckList,CLM_SETSTATE,MAKELONG(nItem,2),
  104. ((pItem->Status & MERGED_INSPECT) ? CLST_CHECKDISABLED : CLST_DISABLED));
  105. pItem = pItem->Next;
  106. }
  107. AddUserControl( IDC_RIGHTS );
  108. AddUserControl( IDC_ADD );
  109. OnConfigure();
  110. return TRUE; // return TRUE unless you set the focus to a control
  111. // EXCEPTION: OCX Property Pages should return FALSE
  112. }
  113. BOOL CAttrRight::OnApply()
  114. {
  115. if ( !m_bReadOnly ) //Raid #388710, #471660, #471653, Yang Gao
  116. {
  117. PEDITTEMPLATE pet = NULL;
  118. CWnd *pCheckList = GetDlgItem(IDC_RIGHTS);
  119. if ( !pCheckList ) {
  120. return FALSE;
  121. }
  122. UpdateData(TRUE);
  123. int iItem;
  124. PSCE_NAME_STATUS_LIST pIndex;
  125. PSCE_NAME_LIST pTemplate=NULL;
  126. PSCE_NAME_LIST pInspect=NULL;
  127. PSCE_NAME_LIST pTemp = NULL;
  128. DWORD status;
  129. DWORD misMatch = SCE_STATUS_GOOD;
  130. pIndex = m_pMergeList;
  131. iItem = 0;
  132. HRESULT hr=S_OK;
  133. PSCE_PROFILE_INFO pspi = (PSCE_PROFILE_INFO)m_pData->GetBaseProfile();
  134. //
  135. // should not change the list for last inspection
  136. // only change the base
  137. //
  138. if( m_bConfigure ){
  139. while (pIndex) {
  140. if (pCheckList->SendMessage(CLM_GETSTATE,MAKELONG(iItem,1)) & CLST_CHECKED) {
  141. if ( !(pIndex->Status & MERGED_TEMPLATE) )
  142. m_bDirty = true;
  143. if ( SCESTATUS_SUCCESS != SceAddToNameList(&pTemplate, pIndex->Name, lstrlen(pIndex->Name))) {
  144. hr = E_FAIL;
  145. break;
  146. }
  147. } else if ( pIndex->Status & MERGED_TEMPLATE ) {
  148. m_bDirty = true;
  149. }
  150. pIndex = pIndex->Next;
  151. iItem++;
  152. }
  153. }
  154. status = ERROR_SUCCESS;
  155. if ( SUCCEEDED(hr) ) {
  156. PSCE_PRIVILEGE_ASSIGNMENT pSetting,pBasePriv;
  157. LPTSTR szPrivName=NULL;
  158. //
  159. // Get privilege rights from the CResult item.
  160. //
  161. pBasePriv = (PSCE_PRIVILEGE_ASSIGNMENT) (m_pData->GetBase());
  162. if(pBasePriv == (PSCE_PRIVILEGE_ASSIGNMENT)ULongToPtr(SCE_NO_VALUE) ){
  163. pBasePriv = NULL;
  164. }
  165. pSetting = (PSCE_PRIVILEGE_ASSIGNMENT) (m_pData->GetSetting());
  166. if(pSetting == (PSCE_PRIVILEGE_ASSIGNMENT)ULongToPtr(SCE_NO_VALUE) ){
  167. pSetting = NULL;
  168. }
  169. if(!m_bConfigure){
  170. //
  171. // If not configured then
  172. misMatch = SCE_STATUS_NOT_CONFIGURED;
  173. if(pBasePriv) {
  174. status = m_pSnapin->UpdateAnalysisInfo(
  175. m_pData,
  176. TRUE,
  177. &pBasePriv
  178. );
  179. if(pSetting){
  180. pSetting->Status = SCE_STATUS_NOT_CONFIGURED;
  181. }
  182. m_bDirty = TRUE;
  183. }
  184. } else {
  185. if ( pSetting ) {
  186. szPrivName = pSetting->Name;
  187. }
  188. if ( !pBasePriv ) {
  189. status = m_pSnapin->UpdateAnalysisInfo(
  190. m_pData,
  191. FALSE,
  192. &pBasePriv,
  193. szPrivName
  194. );
  195. }
  196. if ( pSetting ) {
  197. //
  198. // Check mismatch
  199. //
  200. if ( !SceCompareNameList(pTemplate, pSetting->AssignedTo) ) {
  201. pSetting->Status = SCE_STATUS_MISMATCH;
  202. } else {
  203. pSetting->Status = SCE_STATUS_GOOD;
  204. }
  205. misMatch = pSetting->Status;
  206. } else {
  207. // else should NEVER occur
  208. misMatch = SCE_STATUS_MISMATCH;
  209. }
  210. }
  211. //
  212. // Set mismatch status of the result item.
  213. //
  214. if(misMatch != (DWORD)m_pData->GetStatus()){
  215. m_pData->SetStatus(misMatch);
  216. m_bDirty = TRUE;
  217. }
  218. if(status != ERROR_SUCCESS){
  219. hr = E_FAIL;
  220. } else if ( pBasePriv ) {
  221. pTemp = pBasePriv->AssignedTo;
  222. pBasePriv->AssignedTo = pTemplate;
  223. pTemplate = NULL;
  224. m_bDirty = TRUE;
  225. SceFreeMemory(pTemp,SCE_STRUCT_NAME_LIST);
  226. //
  227. // update dirty flag
  228. //
  229. if(m_pData->GetBaseProfile()){
  230. m_pData->GetBaseProfile()->SetDirty( AREA_PRIVILEGES );
  231. }
  232. }
  233. } // failed
  234. SceFreeMemory(pTemplate,SCE_STRUCT_NAME_LIST);
  235. if ( FAILED(hr) ) {
  236. CString str;
  237. str.LoadString(IDS_SAVE_FAILED);
  238. m_bDirty = FALSE;
  239. AfxMessageBox(str);
  240. }
  241. if (m_bDirty) {
  242. m_pData->Update(m_pSnapin);
  243. }
  244. }
  245. return CAttribute::OnApply();
  246. }
  247. void CAttrRight::OnCancel()
  248. {
  249. if ( m_pMergeList )
  250. SceFreeMemory(m_pMergeList,SCE_STRUCT_NAME_STATUS_LIST);
  251. m_pMergeList = NULL;
  252. //
  253. // Should not call base class
  254. //
  255. //CAttribute::OnCancel();
  256. DestroyWindow();
  257. }
  258. void CAttrRight::OnAdd()
  259. {
  260. CGetUser gu;
  261. HRESULT hr=S_OK;
  262. if (gu.Create(GetSafeHwnd(),SCE_SHOW_SCOPE_ALL|SCE_SHOW_DIFF_MODE_OFF_DC|
  263. SCE_SHOW_USERS | SCE_SHOW_LOCALGROUPS | SCE_SHOW_GLOBAL |
  264. SCE_SHOW_WELLKNOWN | SCE_SHOW_BUILTIN)) {
  265. CWnd *pCheckList;
  266. PSCE_NAME_STATUS_LIST pList,pLast=NULL;
  267. LRESULT iItem;
  268. bool bFound;
  269. pCheckList = GetDlgItem(IDC_RIGHTS);
  270. PSCE_NAME_LIST pName = gu.GetUsers();
  271. while (pName) {
  272. if ( pName->Name ) {
  273. pList = m_pMergeList;
  274. pLast = NULL;
  275. iItem = 0;
  276. bFound = false;
  277. while (pList) {
  278. // If so, then make sure its "Template" box is checked
  279. if (lstrcmp(pList->Name,pName->Name) == 0) {
  280. if (!(pCheckList->SendMessage(CLM_GETSTATE,MAKELONG(iItem,1)) & CLST_CHECKED)) {
  281. m_bDirty = true;
  282. pCheckList->SendMessage(CLM_SETSTATE,MAKELONG(iItem,1),CLST_CHECKED);
  283. }
  284. bFound = true;
  285. break;
  286. }
  287. pLast = pList;
  288. pList = pList->Next;
  289. iItem++;
  290. }
  291. // Otherwise add it both to m_pMerged and to the CheckList
  292. if (!bFound) {
  293. PSCE_NAME_STATUS_LIST pNewNode;
  294. pNewNode = (PSCE_NAME_STATUS_LIST)LocalAlloc(0,sizeof(SCE_NAME_STATUS_LIST));
  295. if ( pNewNode ) {
  296. pNewNode->Name = (LPTSTR)LocalAlloc(0, (lstrlen(pName->Name)+1)*sizeof(TCHAR));
  297. if ( pNewNode->Name ) {
  298. // This may not be a safe usage. pNewNode->Name is PWSTR, using WCHAR instead of TCHAR. Consider fix.
  299. lstrcpy(pNewNode->Name, pName->Name);
  300. pNewNode->Next = NULL;
  301. pNewNode->Status = MERGED_TEMPLATE;
  302. } else {
  303. LocalFree(pNewNode);
  304. pNewNode = NULL;
  305. }
  306. }
  307. if ( pNewNode ) {
  308. if ( pLast ) {
  309. pLast->Next = pNewNode;
  310. } else {
  311. m_pMergeList = pNewNode;
  312. }
  313. pLast = pNewNode;
  314. iItem = pCheckList->SendMessage(CLM_ADDITEM,(WPARAM)pLast->Name,(LPARAM)pLast->Name);
  315. pCheckList->SendMessage(CLM_SETSTATE,MAKELONG(iItem,1),CLST_CHECKED);
  316. pCheckList->SendMessage(CLM_SETSTATE,MAKELONG(iItem,2),CLST_DISABLED);
  317. m_bDirty = true;
  318. } else {
  319. hr = E_OUTOFMEMORY;
  320. ASSERT(FALSE);
  321. break;
  322. }
  323. }
  324. }
  325. pName = pName->Next;
  326. }
  327. }
  328. if (m_bDirty) {
  329. SetModified(TRUE);
  330. }
  331. if ( FAILED(hr) ) {
  332. CString str;
  333. str.LoadString(IDS_CANT_ADD_USER);
  334. AfxMessageBox(str);
  335. }
  336. }
  337. void CAttrRight::OnClickCheckBox(NMHDR *pNM, LRESULT *pResult) //Raid #396108, 5/17/2001
  338. {
  339. SetModified(TRUE);
  340. }