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.

524 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); //Is it a safe usage?
  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. //
  218. // if no security is selected, use Everyone Full control
  219. //
  220. if ( SE_FILE_OBJECT == seType ) {
  221. GetDefaultFileSecurity(&pSelSD,&SelSeInfo);
  222. } else {
  223. GetDefaultRegKeySecurity(&pSelSD,&SelSeInfo);
  224. }
  225. }
  226. //
  227. // Bring up the object editor.
  228. //
  229. CWnd *pWnd = NULL;
  230. BOOL bAllocWnd = FALSE;
  231. if (hwndParent) {
  232. pWnd = CWnd::FromHandlePermanent( hwndParent );
  233. if (pWnd == NULL) {
  234. pWnd = new CWnd;
  235. if (!pWnd) {
  236. if (pSelSD) {
  237. LocalFree(pSelSD);
  238. pSelSD = NULL;
  239. }
  240. return E_FAIL;
  241. }
  242. bAllocWnd = TRUE;
  243. pWnd->Attach(hwndParent);
  244. }
  245. }
  246. CAddObject theObjAcl(
  247. seType,
  248. (LPTSTR)(LPCTSTR)strFile,
  249. TRUE,
  250. pWnd
  251. );
  252. //
  253. // CAddObject frees these pointers
  254. //
  255. theObjAcl.SetSD(pSelSD);
  256. pSelSD = NULL;
  257. theObjAcl.SetSeInfo(SelSeInfo);
  258. SelSeInfo = NULL;
  259. CThemeContextActivator activator;
  260. nRet = theObjAcl.DoModal();
  261. if (bAllocWnd) {
  262. pWnd->Detach();
  263. delete pWnd;
  264. }
  265. if (nRet == IDOK ) {
  266. pSelSD = theObjAcl.GetSD();
  267. SelSeInfo = theObjAcl.GetSeInfo();
  268. ConfigStatus = theObjAcl.GetStatus();
  269. return S_OK;
  270. }
  271. if ( pSelSD ) {
  272. LocalFree(pSelSD);
  273. pSelSD = NULL;
  274. }
  275. return E_FAIL;
  276. }
  277. HRESULT CComponentDataImpl::AddAnalysisFilesToList(LPDATAOBJECT lpDataObject,MMC_COOKIE cookie, FOLDER_TYPES folderType)
  278. {
  279. PEDITTEMPLATE pet;
  280. PSCE_PROFILE_INFO pProfileInfo;
  281. PVOID pHandle = SadHandle;
  282. if ( !pHandle ) {
  283. return E_INVALIDARG;
  284. }
  285. HRESULT hr=E_FAIL;
  286. //
  287. // to select a file.
  288. //
  289. CFileDialog fd(true,
  290. NULL,
  291. NULL,
  292. OFN_DONTADDTORECENT|
  293. OFN_ALLOWMULTISELECT);
  294. CThemeContextActivator activator;
  295. if (IDOK == fd.DoModal()) {
  296. POSITION pos = fd.GetStartPosition();
  297. if ( pos ) {
  298. //
  299. // if anyone is selected, invoke acl editor
  300. //
  301. CString strPath = fd.GetNextPathName(pos);
  302. if ( strPath.GetLength() ) {
  303. PSECURITY_DESCRIPTOR pSelSD=NULL;
  304. SECURITY_INFORMATION SelSeInfo = 0;
  305. BYTE ConfigStatus = 0;
  306. if( GetAddObjectSecurity( m_hwndParent,
  307. strPath,
  308. TRUE,
  309. SE_FILE_OBJECT,
  310. pSelSD,
  311. SelSeInfo,
  312. ConfigStatus
  313. ) == E_FAIL ){
  314. return S_OK;
  315. }
  316. if ( pSelSD && SelSeInfo ) {
  317. //
  318. // only add the object(s) if a security descriptor is selected
  319. //
  320. SCESTATUS sceStatus=SCESTATUS_SUCCESS;
  321. //
  322. // start the transaction if it's not started
  323. //
  324. if ( EngineTransactionStarted() ) {
  325. do {
  326. //
  327. // add to the engine directly
  328. //
  329. BYTE AnalStatus;
  330. sceStatus = SceUpdateObjectInfo(
  331. pHandle,
  332. AREA_FILE_SECURITY,
  333. (LPTSTR)(LPCTSTR)strPath,
  334. strPath.GetLength(), // number of characters
  335. ConfigStatus,
  336. FALSE,
  337. pSelSD,
  338. SelSeInfo,
  339. &AnalStatus
  340. );
  341. if ( SCESTATUS_SUCCESS == sceStatus &&
  342. (pet = GetTemplate(GT_COMPUTER_TEMPLATE,AREA_FILE_SECURITY))) {
  343. pProfileInfo = pet->pTemplate;
  344. //
  345. // just free the object list and unmark the area
  346. // so when the node is clicked, the profile info
  347. // will be reloaded
  348. //
  349. SceFreeMemory((PVOID)(pProfileInfo->pFiles.pOneLevel), SCE_STRUCT_OBJECT_LIST);
  350. pProfileInfo->pFiles.pOneLevel = NULL;
  351. pet->ClearArea(AREA_FILE_SECURITY);
  352. pet->SetDirty(AREA_FILE_SECURITY);
  353. }
  354. if ( SCESTATUS_SUCCESS != sceStatus ) {
  355. CString str;
  356. str.LoadString(IDS_SAVE_FAILED);
  357. AfxMessageBox(str);
  358. break;
  359. }
  360. } while (pos && (strPath = fd.GetNextPathName(pos)) );
  361. if ( SCESTATUS_SUCCESS == sceStatus ) {
  362. hr = S_OK;
  363. }
  364. } else {
  365. //
  366. // no transaction is started to update the object
  367. //
  368. hr = E_FAIL;
  369. }
  370. } // if no SD is selected, the object won't be added
  371. if ( pSelSD ) {
  372. LocalFree(pSelSD);
  373. pSelSD = NULL;
  374. }
  375. if ( FAILED(hr) ) {
  376. CString str;
  377. str.LoadString(IDS_CANT_ADD_FILE);
  378. AfxMessageBox(str);
  379. }
  380. }
  381. }
  382. }
  383. return hr;
  384. }
  385. HRESULT CComponentDataImpl::UpdateScopeResultObject(LPDATAOBJECT pDataObj,
  386. MMC_COOKIE cookie,
  387. AREA_INFORMATION area)
  388. {
  389. PEDITTEMPLATE pet;
  390. PSCE_PROFILE_INFO pProfileInfo;
  391. if ( !cookie || area != AREA_REGISTRY_SECURITY ) {
  392. return E_INVALIDARG;
  393. }
  394. pet = GetTemplate(GT_COMPUTER_TEMPLATE,area);
  395. if ( pet ) {
  396. pProfileInfo = pet->pTemplate;
  397. //
  398. // just free the object list and unmark the area
  399. // so when the node is clicked, the profile info
  400. // will be reloaded
  401. //
  402. switch ( area ) {
  403. case AREA_REGISTRY_SECURITY:
  404. SceFreeMemory((PVOID)(pProfileInfo->pRegistryKeys.pOneLevel), SCE_STRUCT_OBJECT_LIST);
  405. pProfileInfo->pRegistryKeys.pOneLevel = NULL;
  406. break;
  407. case AREA_FILE_SECURITY:
  408. SceFreeMemory((PVOID)(pProfileInfo->pFiles.pOneLevel), SCE_STRUCT_OBJECT_LIST);
  409. pProfileInfo->pFiles.pOneLevel = NULL;
  410. break;
  411. default:
  412. return E_INVALIDARG;
  413. }
  414. pet->ClearArea(area);
  415. CFolder *pFolder = (CFolder *)cookie;
  416. DeleteChildrenUnderNode(pFolder);
  417. if ( pFolder->IsEnumerated() ) {
  418. pFolder->Set(FALSE);
  419. EnumerateScopePane(cookie,pFolder->GetScopeItem()->ID);
  420. }
  421. pFolder->RemoveAllResultItems();
  422. m_pConsole->UpdateAllViews(NULL,(LONG_PTR)pFolder,UAV_RESULTITEM_UPDATEALL);
  423. }
  424. return S_OK;
  425. }