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.

525 lines
15 KiB

  1. // This is a part of the Microsoft Management Console.
  2. // Copyright (C) 1995-2001 Microsoft Corporation
  3. // All rights reserved.
  4. //
  5. // This source code is only intended as a supplement to the
  6. // Microsoft Management Console and related
  7. // electronic documentation provided with the interfaces.
  8. #include "stdafx.h"
  9. #include "afxdlgs.h"
  10. #include "cookie.h"
  11. #include "snapmgr.h"
  12. #include "util.h"
  13. #include "servperm.h"
  14. #include "addobj.h"
  15. #include "wrapper.h"
  16. //#include <objsel.h>
  17. //#include <ntdsapi.h>
  18. //#include <dsgetdc.h>
  19. #include <initguid.h>
  20. #include <cmnquery.h>
  21. #include <dsquery.h>
  22. #include <dsclient.h>
  23. static CLIPFORMAT g_cfDsObjectNames = 0;
  24. #if USE_DS
  25. HRESULT MyDsFindDsObjects(
  26. IN LPTSTR pMyScope,
  27. OUT PDWORD pCount,
  28. OUT LPTSTR **ppSelObjs
  29. );
  30. HRESULT MyDsFreeObjectBuffer(
  31. IN DWORD nCount,
  32. IN LPTSTR *pSelObjs
  33. );
  34. #endif
  35. //
  36. // in snapmgr.cpp
  37. //
  38. int BrowseCallbackProc(HWND hwnd,UINT uMsg, LPARAM lParam, LPARAM pData);
  39. HRESULT CComponentDataImpl::AddAnalysisFolderToList(LPDATAOBJECT lpDataObject,
  40. MMC_COOKIE cookie,
  41. FOLDER_TYPES folderType)
  42. {
  43. PEDITTEMPLATE pet = NULL;
  44. PSCE_PROFILE_INFO pProfileInfo = NULL;
  45. PVOID pHandle = SadHandle;
  46. if ( !pHandle ) {
  47. return E_INVALIDARG;
  48. }
  49. //
  50. // to select a folder.
  51. //
  52. BROWSEINFO bi;
  53. CString strTitle;
  54. LPITEMIDLIST pidlRoot = NULL;
  55. if (FAILED(SHGetSpecialFolderLocation(m_hwndParent,CSIDL_DRIVES,&pidlRoot))) {
  56. return E_FAIL;
  57. }
  58. ZeroMemory(&bi,sizeof(bi));
  59. bi.ulFlags = BIF_RETURNONLYFSDIRS | BIF_BROWSEINCLUDEFILES | BIF_EDITBOX | BIF_NEWDIALOGSTYLE;
  60. bi.lpfn = BrowseCallbackProc;
  61. strTitle.LoadString(IDS_ADDFILESANDFOLDERS_TITLE);
  62. bi.lpszTitle = strTitle;
  63. bi.hwndOwner = m_hwndParent;
  64. bi.pidlRoot = pidlRoot;
  65. LPITEMIDLIST pidlLocation = NULL;
  66. pidlLocation = SHBrowseForFolder(&bi);
  67. if (!pidlLocation) {
  68. return E_FAIL;
  69. }
  70. CString strPath;
  71. LPMALLOC pMalloc = NULL;
  72. SHGetPathFromIDList(pidlLocation,strPath.GetBuffer(MAX_PATH));
  73. strPath.ReleaseBuffer();
  74. if (SUCCEEDED(SHGetMalloc(&pMalloc))) {
  75. pMalloc->Free(pidlLocation);
  76. pMalloc->Free(pidlRoot);
  77. pMalloc->Release();
  78. }
  79. HRESULT hr=E_FAIL;
  80. if ( strPath.GetLength() ) {
  81. PSECURITY_DESCRIPTOR pSelSD=NULL;
  82. SECURITY_INFORMATION SelSeInfo = 0;
  83. BYTE ConfigStatus = 0;
  84. if (GetAddObjectSecurity( m_hwndParent,
  85. strPath,
  86. TRUE,
  87. SE_FILE_OBJECT,
  88. pSelSD,
  89. SelSeInfo,
  90. ConfigStatus
  91. ) == E_FAIL) {
  92. return hr;
  93. }
  94. //
  95. // only add the object(s) if a security descriptor is selected
  96. //
  97. if ( pSelSD && SelSeInfo ) {
  98. //
  99. // add to the engine directly
  100. //
  101. SCESTATUS sceStatus=SCESTATUS_SUCCESS;
  102. BYTE AnalStatus;
  103. //
  104. // start the transaction if it's not started
  105. //
  106. if ( EngineTransactionStarted() ) {
  107. sceStatus = SceUpdateObjectInfo( pHandle,
  108. AREA_FILE_SECURITY,
  109. (LPTSTR)(LPCTSTR)strPath,
  110. strPath.GetLength(), // number of characters
  111. ConfigStatus,
  112. TRUE,
  113. pSelSD,
  114. SelSeInfo,
  115. &AnalStatus
  116. );
  117. if ( SCESTATUS_SUCCESS == sceStatus &&
  118. (pet = GetTemplate(GT_COMPUTER_TEMPLATE,AREA_FILE_SECURITY))) {
  119. pProfileInfo = pet->pTemplate;
  120. //
  121. // just free the object list and unmark the area
  122. // so when the node is clicked, the profile info
  123. // will be reloaded
  124. //
  125. SceFreeMemory((PVOID)(pProfileInfo->pFiles.pOneLevel), SCE_STRUCT_OBJECT_LIST);
  126. pProfileInfo->pFiles.pOneLevel = NULL;
  127. pet->ClearArea(AREA_FILE_SECURITY);
  128. pet->SetDirty(AREA_FILE_SECURITY);
  129. }
  130. if ( SCESTATUS_SUCCESS == sceStatus ) {
  131. hr = S_OK;
  132. }
  133. } else {
  134. //
  135. // transaction can't be started to update the object
  136. //
  137. hr = E_FAIL;
  138. }
  139. } // if no SD is selected, the object won't be added
  140. if ( pSelSD ) {
  141. LocalFree(pSelSD);
  142. pSelSD = NULL;
  143. }
  144. if ( FAILED(hr) ) {
  145. CString str;
  146. str.LoadString(IDS_CANT_ADD_FOLDER);
  147. AfxMessageBox(str);
  148. }
  149. } // cancel is clicked
  150. return hr;
  151. }
  152. /*-------------------------------------------------------------------------------------
  153. Method: CComponentDataImpl::GetAddObjectSecurity
  154. Synopsis: Gets security information for files and folders that are begin added.
  155. Arguments: [hwndParent] - [in] Parent of the dialogs displayed.
  156. [strFile] - [in] File to display in the dialogs.
  157. [bContainer] - [in] Container security or not.
  158. [pSelSD] - [out] Security descriptor.
  159. [SelSeInfo] - [out] Se info.
  160. [ConfigStatus] - [out] Status of the configration
  161. Returns:
  162. S_OK - Operation was successful
  163. S_FAIL - Operation was canceled.
  164. -------------------------------------------------------------------------------------*/
  165. HRESULT
  166. CComponentDataImpl::GetAddObjectSecurity(
  167. HWND hwndParent,
  168. LPCTSTR strFile,
  169. BOOL bContainer,
  170. SE_OBJECT_TYPE seType,
  171. PSECURITY_DESCRIPTOR &pSelSD,
  172. SECURITY_INFORMATION &SelSeInfo,
  173. BYTE &ConfigStatus
  174. )
  175. {
  176. if (!strFile || !lstrlen(strFile)) {
  177. return E_FAIL;
  178. }
  179. //
  180. // Default values.
  181. //
  182. DWORD SDSize;
  183. pSelSD = NULL;
  184. SelSeInfo = NULL;
  185. ConfigStatus = 0;
  186. INT_PTR nRet;
  187. //
  188. // Bring up the ACL editor.
  189. //
  190. nRet = MyCreateSecurityPage2( bContainer,
  191. &pSelSD,
  192. &SelSeInfo,
  193. (LPCTSTR)strFile,
  194. seType,
  195. CONFIG_SECURITY_PAGE,
  196. hwndParent,
  197. FALSE // not modeless
  198. );
  199. if (nRet == -1) {
  200. if (pSelSD) {
  201. LocalFree(pSelSD);
  202. pSelSD = NULL;
  203. }
  204. CString str;
  205. str.LoadString(IDS_CANT_ASSIGN_SECURITY);
  206. AfxMessageBox(str);
  207. return E_FAIL;
  208. }
  209. if (nRet <= 0) {
  210. if (pSelSD) {
  211. LocalFree(pSelSD);
  212. pSelSD = NULL;
  213. }
  214. return E_FAIL;
  215. }
  216. if ( !pSelSD ) {
  217. DWORD SDSize;
  218. //
  219. // if no security is selected, use Everyone Full control
  220. //
  221. if ( SE_FILE_OBJECT == seType ) {
  222. GetDefaultFileSecurity(&pSelSD,&SelSeInfo);
  223. } else {
  224. GetDefaultRegKeySecurity(&pSelSD,&SelSeInfo);
  225. }
  226. }
  227. //
  228. // Bring up the object editor.
  229. //
  230. CWnd *pWnd = NULL;
  231. BOOL bAllocWnd = FALSE;
  232. if (hwndParent) {
  233. pWnd = CWnd::FromHandlePermanent( hwndParent );
  234. if (pWnd == NULL) {
  235. pWnd = new CWnd;
  236. if (!pWnd) {
  237. if (pSelSD) {
  238. LocalFree(pSelSD);
  239. pSelSD = NULL;
  240. }
  241. return E_FAIL;
  242. }
  243. bAllocWnd = TRUE;
  244. pWnd->Attach(hwndParent);
  245. }
  246. }
  247. CAddObject theObjAcl(
  248. seType,
  249. (LPTSTR)(LPCTSTR)strFile,
  250. TRUE,
  251. pWnd
  252. );
  253. //
  254. // CAddObject frees these pointers
  255. //
  256. theObjAcl.SetSD(pSelSD);
  257. pSelSD = NULL;
  258. theObjAcl.SetSeInfo(SelSeInfo);
  259. SelSeInfo = NULL;
  260. CThemeContextActivator activator;
  261. nRet = theObjAcl.DoModal();
  262. if (bAllocWnd) {
  263. pWnd->Detach();
  264. delete pWnd;
  265. }
  266. if (nRet == IDOK ) {
  267. pSelSD = theObjAcl.GetSD();
  268. SelSeInfo = theObjAcl.GetSeInfo();
  269. ConfigStatus = theObjAcl.GetStatus();
  270. return S_OK;
  271. }
  272. if ( pSelSD ) {
  273. LocalFree(pSelSD);
  274. pSelSD = NULL;
  275. }
  276. return E_FAIL;
  277. }
  278. HRESULT CComponentDataImpl::AddAnalysisFilesToList(LPDATAOBJECT lpDataObject,MMC_COOKIE cookie, FOLDER_TYPES folderType)
  279. {
  280. PEDITTEMPLATE pet;
  281. PSCE_PROFILE_INFO pProfileInfo;
  282. PVOID pHandle = SadHandle;
  283. if ( !pHandle ) {
  284. return E_INVALIDARG;
  285. }
  286. HRESULT hr=E_FAIL;
  287. //
  288. // to select a file.
  289. //
  290. CFileDialog fd(true,
  291. NULL,
  292. NULL,
  293. OFN_DONTADDTORECENT|
  294. OFN_ALLOWMULTISELECT);
  295. CThemeContextActivator activator;
  296. if (IDOK == fd.DoModal()) {
  297. POSITION pos = fd.GetStartPosition();
  298. if ( pos ) {
  299. //
  300. // if anyone is selected, invoke acl editor
  301. //
  302. CString strPath = fd.GetNextPathName(pos);
  303. if ( strPath.GetLength() ) {
  304. PSECURITY_DESCRIPTOR pSelSD=NULL;
  305. SECURITY_INFORMATION SelSeInfo = 0;
  306. BYTE ConfigStatus = 0;
  307. if( GetAddObjectSecurity( m_hwndParent,
  308. strPath,
  309. TRUE,
  310. SE_FILE_OBJECT,
  311. pSelSD,
  312. SelSeInfo,
  313. ConfigStatus
  314. ) == E_FAIL ){
  315. return S_OK;
  316. }
  317. if ( pSelSD && SelSeInfo ) {
  318. //
  319. // only add the object(s) if a security descriptor is selected
  320. //
  321. SCESTATUS sceStatus=SCESTATUS_SUCCESS;
  322. //
  323. // start the transaction if it's not started
  324. //
  325. if ( EngineTransactionStarted() ) {
  326. do {
  327. //
  328. // add to the engine directly
  329. //
  330. BYTE AnalStatus;
  331. sceStatus = SceUpdateObjectInfo(
  332. pHandle,
  333. AREA_FILE_SECURITY,
  334. (LPTSTR)(LPCTSTR)strPath,
  335. strPath.GetLength(), // number of characters
  336. ConfigStatus,
  337. FALSE,
  338. pSelSD,
  339. SelSeInfo,
  340. &AnalStatus
  341. );
  342. if ( SCESTATUS_SUCCESS == sceStatus &&
  343. (pet = GetTemplate(GT_COMPUTER_TEMPLATE,AREA_FILE_SECURITY))) {
  344. pProfileInfo = pet->pTemplate;
  345. //
  346. // just free the object list and unmark the area
  347. // so when the node is clicked, the profile info
  348. // will be reloaded
  349. //
  350. SceFreeMemory((PVOID)(pProfileInfo->pFiles.pOneLevel), SCE_STRUCT_OBJECT_LIST);
  351. pProfileInfo->pFiles.pOneLevel = NULL;
  352. pet->ClearArea(AREA_FILE_SECURITY);
  353. pet->SetDirty(AREA_FILE_SECURITY);
  354. }
  355. if ( SCESTATUS_SUCCESS != sceStatus ) {
  356. CString str;
  357. str.LoadString(IDS_SAVE_FAILED);
  358. AfxMessageBox(str);
  359. break;
  360. }
  361. } while (pos && (strPath = fd.GetNextPathName(pos)) );
  362. if ( SCESTATUS_SUCCESS == sceStatus ) {
  363. hr = S_OK;
  364. }
  365. } else {
  366. //
  367. // no transaction is started to update the object
  368. //
  369. hr = E_FAIL;
  370. }
  371. } // if no SD is selected, the object won't be added
  372. if ( pSelSD ) {
  373. LocalFree(pSelSD);
  374. pSelSD = NULL;
  375. }
  376. if ( FAILED(hr) ) {
  377. CString str;
  378. str.LoadString(IDS_CANT_ADD_FILE);
  379. AfxMessageBox(str);
  380. }
  381. }
  382. }
  383. }
  384. return hr;
  385. }
  386. HRESULT CComponentDataImpl::UpdateScopeResultObject(LPDATAOBJECT pDataObj,
  387. MMC_COOKIE cookie,
  388. AREA_INFORMATION area)
  389. {
  390. PEDITTEMPLATE pet;
  391. PSCE_PROFILE_INFO pProfileInfo;
  392. if ( !cookie || area != AREA_REGISTRY_SECURITY ) {
  393. return E_INVALIDARG;
  394. }
  395. pet = GetTemplate(GT_COMPUTER_TEMPLATE,area);
  396. if ( pet ) {
  397. pProfileInfo = pet->pTemplate;
  398. //
  399. // just free the object list and unmark the area
  400. // so when the node is clicked, the profile info
  401. // will be reloaded
  402. //
  403. switch ( area ) {
  404. case AREA_REGISTRY_SECURITY:
  405. SceFreeMemory((PVOID)(pProfileInfo->pRegistryKeys.pOneLevel), SCE_STRUCT_OBJECT_LIST);
  406. pProfileInfo->pRegistryKeys.pOneLevel = NULL;
  407. break;
  408. case AREA_FILE_SECURITY:
  409. SceFreeMemory((PVOID)(pProfileInfo->pFiles.pOneLevel), SCE_STRUCT_OBJECT_LIST);
  410. pProfileInfo->pFiles.pOneLevel = NULL;
  411. break;
  412. default:
  413. return E_INVALIDARG;
  414. }
  415. pet->ClearArea(area);
  416. CFolder *pFolder = (CFolder *)cookie;
  417. DeleteChildrenUnderNode(pFolder);
  418. if ( pFolder->IsEnumerated() ) {
  419. pFolder->Set(FALSE);
  420. EnumerateScopePane(cookie,pFolder->GetScopeItem()->ID);
  421. }
  422. pFolder->RemoveAllResultItems();
  423. m_pConsole->UpdateAllViews(NULL,(LONG_PTR)pFolder,UAV_RESULTITEM_UPDATEALL);
  424. }
  425. return S_OK;
  426. }