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.

1219 lines
29 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1998 - 1999
  6. //
  7. // File: util.h
  8. //
  9. //--------------------------------------------------------------------------
  10. #ifndef _UTIL_H__
  11. #define _UTIL_H__
  12. #include <dsclient.h>
  13. #include "stlutil.h"
  14. ///////////////////////////////////////////////////////////////////////
  15. // MACROS
  16. // flags to interpret the DSSEC.DAT file values (from JeffreyS)
  17. #define IDC_CLASS_NO_CREATE 0x00000001
  18. #define IDC_CLASS_NO_DELETE 0x00000002
  19. #define IDC_CLASS_NO_INHERIT 0x00000004
  20. #define IDC_PROP_NO_READ 0x00000001
  21. #define IDC_PROP_NO_WRITE 0x00000002
  22. // derived flags
  23. #define IDC_CLASS_NO (IDC_CLASS_NO_CREATE | IDC_CLASS_NO_DELETE | IDC_CLASS_NO_INHERIT)
  24. #define IDC_PROP_NO (IDC_PROP_NO_READ | IDC_PROP_NO_WRITE)
  25. ///////////////////////////////////////////////////////////////////////
  26. // strings
  27. // special classes
  28. extern PWSTR g_wzRootDSE;
  29. extern PWSTR g_wzSchemaNamingContext;
  30. extern PWSTR g_wzLDAPAbstractSchemaFormat;
  31. // fwd decl
  32. class CAdsiObject;
  33. class CErrorMessageHandlerBase;
  34. ///////////////////////////////////////////////////////////////////////
  35. // CWString
  36. class CWString : public wstring
  37. {
  38. public:
  39. operator LPCWSTR() { return c_str(); }
  40. CWString& operator=(LPCWSTR lpsz)
  41. {
  42. if (lpsz == NULL)
  43. lpsz = L"";
  44. *((wstring*)this) = lpsz;
  45. return *this;
  46. }
  47. BOOL LoadFromResource(UINT uID);
  48. };
  49. ///////////////////////////////////////////////////////////////////////
  50. // GLOBAL FUNCTIONS
  51. BOOL LoadStringHelper(UINT uID, LPTSTR lpszBuffer, int nBufferMax);
  52. BOOL GetStringFromHRESULTError(HRESULT hr, CWString& szErrorString, BOOL bTryADsIErrors = TRUE);
  53. BOOL GetStringFromWin32Error(DWORD dwErr, CWString& CWString);
  54. inline HRESULT ADsOpenObjectHelper(LPCWSTR lpszPathName, REFIID riid, void** ppObject)
  55. {
  56. return ADsOpenObject((LPWSTR)lpszPathName,
  57. NULL, //LPWSTR lpszUserName,
  58. NULL, //LPWSTR lpszPassword,
  59. ADS_SECURE_AUTHENTICATION, //DWORD dwReserved,
  60. riid,
  61. ppObject
  62. );
  63. }
  64. HRESULT InitCheckAccess( HWND hwndParent, LPCWSTR pszObjectLADPPath );
  65. // functions to access DSSEC.DAT
  66. ULONG GetClassFlags(LPCWSTR lpszClassName);
  67. ULONG GetAttributeFlags(LPCWSTR lpszClassName, LPCWSTR lpszAttr);
  68. void BuildLdapPathHelper(LPCWSTR lpszServerName, LPCWSTR lpszNamingContext, CWString& szLdapPath);
  69. void BuildWin32PathHelper(LPCWSTR lpszServerName, LPCWSTR lpszNamingContext, CWString& szWin32Path);
  70. HRESULT GetCanonicalNameFromNamingContext(LPCWSTR lpszNamingContext, CWString& szCanonicalName);
  71. HRESULT GetGlobalNamingContexts(LPCWSTR lpszServerName,
  72. CWString& szPhysicalSchemaNamingContext,
  73. CWString& szConfigurationNamingContext);
  74. HRESULT GetSchemaClassName(LPCWSTR lpszServerName, LPCWSTR lpszPhysicalSchemaNamingContext,
  75. LPCWSTR lpszClassLdapDisplayName, // e.g. "organizationalUnit"
  76. CWString& szClassName // e.g. "Organizational-Unit"
  77. );
  78. extern LPCWSTR g_lpszSummaryIdent;
  79. extern LPCWSTR g_lpszSummaryNewLine;
  80. void WriteSummaryTitleLine(CWString& szSummary, UINT nTitleID, LPCWSTR lpszNewLine);
  81. void WriteSummaryLine(CWString& szSummary, LPCWSTR lpsz, LPCWSTR lpszIdent, LPCWSTR lpszNewLine);
  82. DWORD AddObjectRightInAcl(IN PSID pSid,
  83. IN ULONG uAccess,
  84. IN const GUID* pRightGUID,
  85. IN const GUID* pInheritGUID,
  86. IN OUT PACL* ppAcl);
  87. ///////////////////////////////////////////////////////////////////////
  88. //////////////////////////// HELPER CLASSES ///////////////////////////
  89. ///////////////////////////////////////////////////////////////////////
  90. // CWaitCursor
  91. class CWaitCursor
  92. {
  93. public:
  94. CWaitCursor()
  95. {
  96. m_hCurrentCursor = ::SetCursor(::LoadCursor(NULL, IDC_WAIT));
  97. }
  98. ~CWaitCursor()
  99. {
  100. ::SetCursor(m_hCurrentCursor);
  101. }
  102. private:
  103. HCURSOR m_hCurrentCursor;
  104. };
  105. BOOL FormatStringGUID(LPWSTR lpszBuf, UINT nBufSize, const GUID* pGuid);
  106. BOOL GuidFromString(GUID* pGuid, LPCWSTR lpszGuidString);
  107. ///////////////////////////////////////////////////////////////////////
  108. // CFilterBase
  109. class CFilterBase
  110. {
  111. public:
  112. virtual BOOL CanAdd(LPCWSTR lpsz, ULONG* pFilterFlags) = 0;
  113. };
  114. ///////////////////////////////////////////////////////////////////////
  115. // CSidHolder
  116. class CSidHolder
  117. {
  118. public:
  119. CSidHolder()
  120. {
  121. _Init();
  122. }
  123. ~CSidHolder()
  124. {
  125. _Free();
  126. }
  127. PSID Get()
  128. {
  129. return m_pSID;
  130. }
  131. BOOL Copy(PSID p)
  132. {
  133. _Free();
  134. return _Copy(p);
  135. }
  136. void Attach(PSID p, BOOL bLocalAlloc)
  137. {
  138. _Free();
  139. m_pSID = p;
  140. m_bLocalAlloc = bLocalAlloc;
  141. }
  142. private:
  143. void _Init()
  144. {
  145. m_pSID = NULL;
  146. m_bLocalAlloc = TRUE;
  147. }
  148. void _Free()
  149. {
  150. if (m_pSID != NULL)
  151. {
  152. if (m_bLocalAlloc)
  153. ::LocalFree(m_pSID);
  154. else
  155. ::FreeSid(m_pSID);
  156. _Init();
  157. }
  158. }
  159. BOOL _Copy(PSID p)
  160. {
  161. if ( (p == NULL) || !::IsValidSid(p) )
  162. return FALSE;
  163. DWORD dwLen = ::GetLengthSid(p);
  164. PSID pNew = ::LocalAlloc(LPTR, dwLen);
  165. if(!pNew)
  166. return FALSE;
  167. if (!::CopySid(dwLen, pNew, p))
  168. {
  169. ::LocalFree(pNew);
  170. return FALSE;
  171. }
  172. m_bLocalAlloc = TRUE;
  173. m_pSID = pNew;
  174. ASSERT(dwLen == ::GetLengthSid(m_pSID));
  175. ASSERT(memcmp(p, m_pSID, dwLen) == 0);
  176. return TRUE;
  177. }
  178. PSID m_pSID;
  179. BOOL m_bLocalAlloc;
  180. };
  181. ///////////////////////////////////////////////////////////////////////
  182. // CPrincipal
  183. class CPrincipal
  184. {
  185. public:
  186. CPrincipal()
  187. {
  188. m_hClassIcon = NULL;
  189. }
  190. HRESULT Initialize(PDS_SELECTION pDsSelection, HICON hClassIcon);
  191. HRESULT Initialize (PSID psid);
  192. BOOL IsEqual(CPrincipal* p);
  193. PSID GetSid()
  194. {
  195. return m_sidHolder.Get();
  196. }
  197. LPCWSTR GetClass()
  198. {
  199. return m_szClass;
  200. }
  201. HICON GetClassIcon()
  202. {
  203. return m_hClassIcon;
  204. }
  205. LPCWSTR GetDisplayName()
  206. {
  207. return m_szDisplayName;
  208. }
  209. private:
  210. void _ComposeDisplayName();
  211. // names
  212. CWString m_szName; // e.g. "JoeB"
  213. CWString m_szADsPath; //e.g. "WINNT://FOODOM/JoeB"
  214. CWString m_szUPN; // e.g. "[email protected]."
  215. CWString m_szClass; // e.g. "user"
  216. CWString m_szDisplayName; // generated, to be shown into the UI
  217. // other data
  218. HICON m_hClassIcon; // icon handle
  219. CSidHolder m_sidHolder; // PSID holder
  220. };
  221. ///////////////////////////////////////////////////////////////////////
  222. // CPrincipalList
  223. class CPrincipalList : public CPtrList<CPrincipal*>
  224. {
  225. public:
  226. CPrincipalList(BOOL bOwnMem = TRUE) : CPtrList<CPrincipal*>(bOwnMem)
  227. {
  228. }
  229. BOOL AddIfNotPresent(CPrincipal* p);
  230. void WriteSummaryInfo(CWString& szSummary, LPCWSTR lpszIdent, LPCWSTR lpszNewLine);
  231. };
  232. ///////////////////////////////////////////////////////////////////////
  233. // CBasicRightInfo
  234. class CBasicRightInfo
  235. {
  236. public:
  237. CBasicRightInfo()
  238. {
  239. m_fAccess = 0x0;
  240. m_bSelected = FALSE;
  241. }
  242. LPCWSTR GetDisplayName() { return m_szDisplayName; }
  243. ULONG GetAccess() { return m_fAccess; }
  244. BOOL IsSelected() { return m_bSelected; }
  245. void Select(BOOL b) { m_bSelected = b; }
  246. protected:
  247. CWString m_szDisplayName;
  248. ULONG m_fAccess;
  249. private:
  250. BOOL m_bSelected;
  251. };
  252. ///////////////////////////////////////////////////////////////////////
  253. // CAccessRightInfo
  254. class CTemplateAccessPermissionsHolder; // fwd decl
  255. class CCustomAccessPermissionsHolder; // fwd decl
  256. class CAccessRightInfo : public CBasicRightInfo
  257. {
  258. friend class CTemplateAccessPermissionsHolder;
  259. friend class CCustomAccessPermissionsHolder;
  260. };
  261. ///////////////////////////////////////////////////////////////////////
  262. // CAccessRightInfoArray
  263. class CAccessRightInfoArray : public CGrowableArr<CAccessRightInfo>
  264. {
  265. };
  266. ///////////////////////////////////////////////////////////////////////
  267. // CControlRightInfo
  268. class CControlRightInfoArray; //fwd decl
  269. class CControlRightInfo : public CBasicRightInfo
  270. {
  271. public:
  272. CControlRightInfo()
  273. {
  274. ZeroMemory(&m_rightsGUID, sizeof (GUID));
  275. }
  276. const GUID* GetRightsGUID() { return &m_rightsGUID;}
  277. LPCWSTR GetLdapDisplayName() { return m_szLdapDisplayName; }
  278. LPCWSTR GetLocalizedName() { return m_szLocalizedName; }
  279. BOOL IsPropertySet()
  280. {
  281. return ((m_fAccess & (ACTRL_DS_READ_PROP | ACTRL_DS_WRITE_PROP)) != 0);
  282. }
  283. void SetLocalizedName(UINT nLocalizationDisplayId, HMODULE hModule);
  284. private:
  285. GUID m_rightsGUID;
  286. CWString m_szLdapDisplayName; // this is from the schema, not localized
  287. CWString m_szLocalizedName; // this is obtained from NTMARTA
  288. friend class CControlRightInfoArray;
  289. };
  290. ///////////////////////////////////////////////////////////////////////
  291. // CControlRightInfoArray
  292. class CControlRightInfoArray : public CGrowableArr<CControlRightInfo>
  293. {
  294. public:
  295. HRESULT InitFromDS(CAdsiObject* pADSIObj,
  296. const GUID* pSchemaIDGUID);
  297. };
  298. ///////////////////////////////////////////////////////////////////////
  299. // CSchemaObjectInfo
  300. class CSchemaObjectInfo
  301. {
  302. public:
  303. CSchemaObjectInfo(LPCWSTR lpszName)
  304. {
  305. m_bFilter = FALSE;
  306. if (lpszName != NULL)
  307. m_szName = lpszName;
  308. ZeroMemory(&m_schemaIDGUID, sizeof(GUID));
  309. }
  310. virtual ~CSchemaObjectInfo()
  311. {
  312. }
  313. void SetDisplayName(LPCWSTR lpszDisplayName)
  314. {
  315. //TRACE(_T("SetDisplayName(%s)\n"),lpszDisplayName);
  316. m_szDisplayName = (lpszDisplayName != NULL) ? lpszDisplayName : m_szName;
  317. //TRACE(_T("m_szDisplayName = (%s)\n"),m_szDisplayName.c_str());
  318. }
  319. LPCWSTR GetName()
  320. {
  321. return (m_szName.data()[0] == NULL) ? NULL : m_szName.c_str();
  322. }
  323. LPCWSTR GetDisplayName()
  324. {
  325. //TRACE(_T("GetDisplayName() m_szName = (%s) m_szDisplayName = (%s)\n"),
  326. // m_szName.c_str(), m_szDisplayName.c_str());
  327. return (m_szDisplayName.data()[0] == NULL) ? NULL : m_szDisplayName.c_str();
  328. }
  329. const GUID* GetSchemaGUID()
  330. {
  331. return &m_schemaIDGUID;
  332. }
  333. bool operator<(CSchemaObjectInfo& x)
  334. {
  335. if ((GetDisplayName() == NULL) || (x.GetDisplayName() == NULL))
  336. return false;
  337. return (_wcsicmp(GetDisplayName(), x.GetDisplayName()) < 0);
  338. }
  339. void SetFiltered() { m_bFilter = TRUE;}
  340. BOOL IsFiltered() { return m_bFilter;}
  341. protected:
  342. BOOL m_bFilter;
  343. CWString m_szName;
  344. CWString m_szDisplayName;
  345. GUID m_schemaIDGUID;
  346. };
  347. //////////////////////////////////////////////////////////////////////
  348. // CPropertyRightInfo
  349. class CPropertyRightInfoArray; // fwd decl
  350. class CPropertyRightInfo : public CSchemaObjectInfo
  351. {
  352. public:
  353. CPropertyRightInfo(ULONG filterFlags, LPCWSTR lpszName)
  354. : CSchemaObjectInfo(lpszName)
  355. {
  356. //TRACE(_T("CPropertyRightInfo(0x%x, %s)\n"),filterFlags, lpszName);
  357. m_FilterFlags = filterFlags;
  358. m_nRightCount = m_nRightCountMax;
  359. if (m_FilterFlags & IDC_PROP_NO_READ)
  360. m_nRightCount--;
  361. if (m_FilterFlags & IDC_PROP_NO_WRITE)
  362. m_nRightCount--;
  363. ASSERT(m_nRightCount > 0);
  364. m_Access = 0x0;
  365. }
  366. ~CPropertyRightInfo() {}
  367. static const ULONG m_nRightCountMax;
  368. static const ULONG m_nReadIndex;
  369. static const ULONG m_nWriteIndex;
  370. LPCWSTR GetRightDisplayString(ULONG iRight);
  371. void SetRight(ULONG iRight, BOOL b);
  372. ULONG GetRight(ULONG iRight);
  373. BOOL IsRightSelected(ULONG iRight);
  374. ULONG GetAccess() { return m_Access;}
  375. void AddAccessRight(ULONG uRight) { m_Access |= uRight;}
  376. ULONG GetRightCount() { return m_nRightCount;}
  377. private:
  378. ULONG m_nRightCount;
  379. ULONG m_FilterFlags;
  380. ULONG m_Access;
  381. friend class CPropertyRightInfoArray;
  382. };
  383. //////////////////////////////////////////////////////////////////////
  384. // CPropertyRightInfoArray
  385. class CPropertyRightInfoFilter : public CFilterBase
  386. {
  387. public:
  388. virtual BOOL CanAdd(LPCWSTR lpsz, ULONG* pFilterFlags)
  389. {
  390. *pFilterFlags = ::GetAttributeFlags(m_szClassName, lpsz);
  391. if (*pFilterFlags == 0)
  392. return TRUE; // have no info, so add anyway
  393. if ((*pFilterFlags & IDC_PROP_NO) == IDC_PROP_NO)
  394. return FALSE; // have all the hide flags set
  395. return TRUE; // some of the hide flags not set
  396. }
  397. void SetClassName(LPCWSTR lpszClassName)
  398. {
  399. if (lpszClassName == NULL)
  400. m_szClassName = L"";
  401. else
  402. m_szClassName = lpszClassName;
  403. }
  404. private:
  405. CWString m_szClassName;
  406. };
  407. class CPropertyRightInfoArray : public CGrowableArr<CPropertyRightInfo>
  408. {
  409. public:
  410. HRESULT InitFromSchema(CAdsiObject* pADSIObj, IADsClass* pDsSchemaClass,
  411. LPCWSTR lpszClassName, BOOL bUseFilter);
  412. };
  413. //////////////////////////////////////////////////////////////////////
  414. // CClassRightInfo
  415. class CClassRightInfoArray; // fwd decl.
  416. class CClassRightInfo : public CSchemaObjectInfo
  417. {
  418. public:
  419. CClassRightInfo(ULONG filterFlags, LPCWSTR lpszName)
  420. : CSchemaObjectInfo(lpszName)
  421. {
  422. //TRACE(_T("CClassRightInfo(0x%x, %s)\n"),filterFlags, lpszName);
  423. m_FilterFlags = filterFlags;
  424. m_nRightCount = m_nRightCountMax;
  425. if (m_FilterFlags & IDC_CLASS_NO_CREATE)
  426. m_nRightCount--;
  427. if (m_FilterFlags & IDC_CLASS_NO_DELETE)
  428. m_nRightCount--;
  429. // REVIEW_MARCOC: do we need this?
  430. //if (m_FilterFlags & IDC_CLASS_NO_INHERIT)
  431. // m_nRightCount--;
  432. ASSERT(m_nRightCount > 0);
  433. m_Access = 0x0;
  434. }
  435. ~CClassRightInfo() {}
  436. static const ULONG m_nRightCountMax;
  437. static const ULONG m_nCreateIndex;
  438. static const ULONG m_nDeleteIndex;
  439. LPCWSTR GetRightDisplayString(ULONG iRight);
  440. void SetRight(ULONG iRight, BOOL b);
  441. ULONG GetRight(ULONG iRight);
  442. BOOL IsRightSelected(ULONG iRight);
  443. ULONG GetAccess() { return m_Access;}
  444. void AddAccessRight(ULONG uRight) { m_Access |= uRight;}
  445. ULONG GetRightCount() { return m_nRightCount;}
  446. private:
  447. ULONG m_nRightCount;
  448. ULONG m_FilterFlags;
  449. ULONG m_Access;
  450. friend class CClassRightInfoArray;
  451. };
  452. //////////////////////////////////////////////////////////////////////
  453. // CClassRightInfoArray
  454. class CClassRightInfoFilter : public CFilterBase
  455. {
  456. public:
  457. virtual BOOL CanAdd(LPCWSTR lpsz, ULONG* pFilterFlags)
  458. {
  459. *pFilterFlags = ::GetClassFlags(lpsz);
  460. if (*pFilterFlags == 0)
  461. return TRUE; // have no info, so add anyway
  462. if ((*pFilterFlags & IDC_CLASS_NO) == IDC_CLASS_NO)
  463. return FALSE; // have all the hide flags set
  464. return TRUE; // some of the hide flags not set
  465. }
  466. };
  467. class CClassRightInfoArray : public CGrowableArr<CClassRightInfo>
  468. {
  469. public:
  470. HRESULT InitFromSchema(CAdsiObject* pADSIObj, IADsClass* pDsSchemaClass, BOOL bUseFilter);
  471. };
  472. ///////////////////////////////////////////////////////////////////////
  473. // CSchemaClassInfo
  474. #define CHILD_CLASS_NOT_EXIST 1
  475. #define CHILD_CLASS_EXIST 2
  476. #define CHILD_CLASS_NOT_CALCULATED 3
  477. class CSchemaClassInfo : public CSchemaObjectInfo
  478. {
  479. public:
  480. CSchemaClassInfo(LPCWSTR lpszName, LPCWSTR lpszSchemaClassName,
  481. const GUID* pSchemaIDGUID)
  482. : CSchemaObjectInfo(lpszName)
  483. {
  484. m_szSchemaClassName = lpszSchemaClassName;
  485. m_schemaIDGUID = *pSchemaIDGUID;
  486. m_dwChildClass = CHILD_CLASS_NOT_CALCULATED;
  487. m_bSelected = FALSE;
  488. m_bAux = FALSE;
  489. }
  490. ~CSchemaClassInfo()
  491. {
  492. }
  493. VOID SetAux(){m_bAux=TRUE;}
  494. BOOL IsAux(){return m_bAux;}
  495. BOOL m_bSelected;
  496. DWORD m_dwChildClass;
  497. LPCWSTR GetSchemaClassName() { return m_szSchemaClassName; }
  498. private:
  499. CWString m_szSchemaClassName;
  500. BOOL m_bAux;
  501. };
  502. ////////////////////////////////////////////////////////////////////////
  503. // CRigthsListViewItem
  504. class CRigthsListViewItem
  505. {
  506. public:
  507. enum rightType { access, ctrl, prop, subobj };
  508. CRigthsListViewItem(ULONG iIndex, ULONG iRight, rightType type)
  509. {
  510. m_type = type;
  511. m_iIndex = iIndex;
  512. m_iRight = iRight;
  513. }
  514. public:
  515. rightType m_type;
  516. ULONG m_iIndex;
  517. ULONG m_iRight;
  518. };
  519. typedef CGrowableArr<CRigthsListViewItem> CRigthsListViewItemArray;
  520. ///////////////////////////////////////////////////////////////////////
  521. // CAccessPermissionsHolderBase
  522. class CAccessPermissionsHolderBase
  523. {
  524. public:
  525. CAccessPermissionsHolderBase(BOOL bUseFilter);
  526. virtual ~CAccessPermissionsHolderBase();
  527. void Clear();
  528. // entry manipulation functions
  529. size_t GetTotalCount()
  530. {
  531. return m_accessRightInfoArr.GetCount() + m_controlRightInfoArr.GetCount()
  532. + m_propertyRightInfoArray.GetCount() + m_classRightInfoArray.GetCount();
  533. }
  534. BOOL HasPermissionSelected();
  535. // backend DS operations
  536. HRESULT ReadDataFromDS(CAdsiObject* pADSIObj,
  537. LPCWSTR lpszObjectNamingContext,
  538. LPCWSTR lpszClassName,
  539. const GUID* pSchemaIDGUID,
  540. BOOL bChildClass,
  541. BOOL bHideListObject = FALSE);
  542. DWORD UpdateAccessList( CPrincipal* pPrincipal,
  543. CSchemaClassInfo* pClassInfo,
  544. LPCWSTR lpszServerName,
  545. LPCWSTR lpszPhysicalSchemaNamingContext,
  546. PACL* ppAcl);
  547. protected:
  548. // standard access rigths
  549. CAccessRightInfoArray m_accessRightInfoArr;
  550. virtual HRESULT _LoadAccessRightInfoArrayFromTable( BOOL bCreateDeleteChild,BOOL bHideListObject) = 0;
  551. // extended access rigths
  552. CControlRightInfoArray m_controlRightInfoArr;
  553. // array of property rights
  554. CPropertyRightInfoArray m_propertyRightInfoArray;
  555. // array of class rights
  556. CClassRightInfoArray m_classRightInfoArray;
  557. // array of selections in the UI
  558. BOOL* m_pbSelectedArr; // selected?
  559. private:
  560. BOOL m_bUseFilter;
  561. HRESULT _ReadClassInfoFromDS(CAdsiObject* pADSIObj, LPCWSTR lpszClassName);
  562. DWORD _UpdateAccessListHelper(PSID pSid,
  563. const GUID* pClassGUID,
  564. PACL *ppAcl,
  565. BOOL bChildClass);
  566. };
  567. ///////////////////////////////////////////////////////////////////////
  568. // CCustomAccessPermissionsHolder
  569. // bitfields to keep track of the filtering state
  570. #define FILTER_EXP_GEN 0x1
  571. #define FILTER_EXP_PROP 0x2
  572. #define FILTER_EXP_SUBOBJ 0x4
  573. #define FILTER_EXP_GEN_DISABLED 0x8
  574. class CCheckListViewHelper; // fwd decl
  575. class CCustomAccessPermissionsHolder : public CAccessPermissionsHolderBase
  576. {
  577. public:
  578. CCustomAccessPermissionsHolder();
  579. virtual ~CCustomAccessPermissionsHolder();
  580. void Clear();
  581. // entry manipulation functions
  582. void Select(IN CRigthsListViewItem* pItem,
  583. IN BOOL bSelect,
  584. OUT ULONG* pnNewFilterState);
  585. void FillAccessRightsListView(
  586. CCheckListViewHelper* pListViewHelper,
  587. ULONG nFilterState);
  588. void UpdateAccessRightsListViewSelection(
  589. CCheckListViewHelper* pListViewHelper,
  590. ULONG nFilterState);
  591. // display finish page summary info
  592. void WriteSummary(CWString& szSummary, LPCWSTR lpszIdent, LPCWSTR lpszNewLine);
  593. protected:
  594. virtual HRESULT _LoadAccessRightInfoArrayFromTable(BOOL bCreateDeleteChild,BOOL bHideListObject);
  595. private:
  596. // helper functions to do selection and deselection
  597. void _SelectAllRigths();
  598. void _SelectAllPropertyRigths(ULONG fAccessPermission);
  599. void _SelectAllSubObjectRigths(ULONG fAccessPermission);
  600. void _DeselectAssociatedRights(ULONG fAccessPermission);
  601. // array of listview items, for indexing
  602. CRigthsListViewItemArray m_listViewItemArr;
  603. };
  604. ///////////////////////////////////////////////////////////////////////
  605. // CCheckListViewHelper
  606. class CCheckListViewHelper
  607. {
  608. public:
  609. static BOOL CheckChanged(NM_LISTVIEW* pNMListView);
  610. static BOOL IsChecked(NM_LISTVIEW* pNMListView);
  611. CCheckListViewHelper()
  612. {
  613. m_hWnd = NULL;
  614. }
  615. BOOL Initialize(UINT nID, HWND hParent);
  616. int InsertItem(int iItem, LPCTSTR lpszText, LPARAM lParam, BOOL bCheck);
  617. BOOL SetItemCheck(int iItem, BOOL bCheck);
  618. void SetCheckAll(BOOL bCheck);
  619. LPARAM GetItemData(int iItem);
  620. BOOL IsItemChecked(int iItem);
  621. int GetCheckCount();
  622. void GetCheckedItems(int nCheckCount, int* nCheckArray);
  623. BOOL GetCheckState(int iItem)
  624. {
  625. return ListView_GetCheckState(m_hWnd,iItem);
  626. }
  627. int GetItemCount()
  628. {
  629. return ListView_GetItemCount(m_hWnd);
  630. }
  631. BOOL DeleteAllItems()
  632. {
  633. return ListView_DeleteAllItems(m_hWnd);
  634. }
  635. void EnableWindow(BOOL bEnable)
  636. {
  637. ::EnableWindow(m_hWnd, bEnable);
  638. }
  639. private:
  640. HWND m_hWnd;
  641. };
  642. ////////////////////////////////////////////////////////////////////////////
  643. // CNamedSecurityInfo
  644. /*
  645. class CNamedSecurityInfo
  646. {
  647. public:
  648. CNamedSecurityInfo()
  649. {
  650. m_pAuditList = NULL;
  651. m_pOwner = NULL;
  652. m_pGroup = NULL;
  653. m_pAccessList = NULL;
  654. }
  655. ~CNamedSecurityInfo()
  656. {
  657. Reset();
  658. }
  659. DWORD Get();
  660. DWORD Set();
  661. void Reset();
  662. private:
  663. CWString m_szObjectName; // name of the object
  664. // the following varables are just read and written back
  665. // i.e. no modification
  666. PACTRL_AUDIT m_pAuditList;
  667. LPWSTR m_pOwner;
  668. LPWSTR m_pGroup;
  669. // list to be edited and written back
  670. PACTRL_ACCESS m_pAccessList;
  671. };
  672. */
  673. ////////////////////////////////////////////////////////////////////////////
  674. // CAdsPathNameObj
  675. class CAdsPathNameObj
  676. {
  677. public:
  678. CAdsPathNameObj(){}
  679. ~CAdsPathNameObj(){ m_spADsPath = NULL;}
  680. HRESULT SkipPrefix(LPCWSTR pwzObj, BSTR* pBstr)
  681. {
  682. HRESULT hr = _Create();
  683. if (FAILED(hr))
  684. return hr;
  685. hr = m_spADsPath->Set((PWSTR)pwzObj, ADS_SETTYPE_FULL);
  686. if (FAILED(hr))
  687. return hr;
  688. hr = m_spADsPath->Retrieve(ADS_FORMAT_X500_DN, pBstr);
  689. return hr;
  690. }
  691. HRESULT SkipPrefix(LPCWSTR pwzObj, CWString& str)
  692. {
  693. CComBSTR b;
  694. HRESULT hr = SkipPrefix(pwzObj, &b);
  695. if (FAILED(hr))
  696. {
  697. str = L"";
  698. }
  699. else
  700. {
  701. str = b;
  702. }
  703. return hr;
  704. }
  705. HRESULT GetProvider(LPCWSTR pwzObj, BSTR* pBstr)
  706. {
  707. HRESULT hr = _Create();
  708. if (FAILED(hr))
  709. return hr;
  710. hr = m_spADsPath->Set((PWSTR)pwzObj, ADS_SETTYPE_FULL);
  711. if (FAILED(hr))
  712. return hr;
  713. hr = m_spADsPath->Retrieve(ADS_FORMAT_PROVIDER, pBstr);
  714. return hr;
  715. }
  716. private:
  717. CComPtr<IADsPathname> m_spADsPath;
  718. HRESULT _Create()
  719. {
  720. HRESULT hr = S_OK;
  721. if (m_spADsPath == NULL)
  722. {
  723. hr = ::CoCreateInstance(CLSID_Pathname, NULL, CLSCTX_INPROC_SERVER,
  724. IID_IADsPathname, (PVOID *)&m_spADsPath);
  725. }
  726. return hr;
  727. }
  728. };
  729. ////////////////////////////////////////////////////////////////////////////
  730. // CAdsiObject
  731. class CAdsiObject
  732. {
  733. public:
  734. CAdsiObject():m_iListObjectEnforced(-1)
  735. { _Clear(); }
  736. virtual ~CAdsiObject(){}
  737. virtual HRESULT Bind(LPCWSTR lpszLdapPath);
  738. BOOL IsBound() { return m_spIADs != NULL; }
  739. HRESULT QuerySchemaClasses(CGrowableArr<CSchemaClassInfo>* pSchemaClassesInfoArray,
  740. BOOL bGetAttributes = FALSE);
  741. // accessor functions
  742. LPCWSTR GetLdapPath() { return m_szLdapPath; }
  743. LPCWSTR GetServerName() { return m_szServerName; }
  744. LPCWSTR GetNamingContext() { return m_szNamingContext; }
  745. LPCWSTR GetCanonicalName() { return m_szCanonicalName; }
  746. LPCWSTR GetClass() { return m_szClass; }
  747. LPCWSTR GetPhysicalSchemaNamingContext() { return m_szPhysicalSchemaNamingContext;}
  748. LPCWSTR GetConfigurationNamingContext() { return m_szConfigurationNamingContext;}
  749. // methods to access display specifiers
  750. HICON GetClassIcon(LPCWSTR lpszObjectClass);
  751. HRESULT GetFriendlyClassName(LPCWSTR lpszObjectClass,
  752. LPWSTR lpszBuffer, int cchBuffer);
  753. HRESULT GetFriendlyAttributeName(LPCWSTR lpszObjectClass,
  754. LPCWSTR lpszAttributeName,
  755. LPWSTR lpszBuffer, int cchBuffer);
  756. HRESULT GetClassGuid(LPCWSTR lpszClassLdapDisplayName, BOOL bGetAttribute, GUID& guid);
  757. CAdsPathNameObj* GetPathNameObject()
  758. {
  759. return &m_pathNameObject;
  760. }
  761. bool GetListObjectEnforced();
  762. protected:
  763. CComPtr<IADs> m_spIADs; // pointer to ADSI object
  764. private:
  765. int m_iListObjectEnforced;
  766. CComPtr<IDsDisplaySpecifier> m_spIDsDisplaySpecifier; // pointer to Display Specifier Cache
  767. CAdsPathNameObj m_pathNameObject; // path cracker object wrapper
  768. // cached naming strings
  769. CWString m_szServerName; // DNS name the object is bound to ("foo.bar.com.")
  770. CWString m_szNamingContext; // naming context (X500) ("cn=xyz,...");
  771. CWString m_szLdapPath; // full LDAP path ("LDAP://foo.bar.com.\cn=xyz,...")
  772. CWString m_szCanonicalName; // name in canonical form
  773. CWString m_szClass; // class name in abstract schema, corresponding to
  774. // LDAPDisplayName attribute in physical schema,
  775. // (e.g. "organizationalUnit")
  776. // commonly used naming contexts
  777. CWString m_szPhysicalSchemaNamingContext;
  778. CWString m_szConfigurationNamingContext;
  779. void _Clear()
  780. {
  781. m_spIADs = NULL;
  782. m_spIDsDisplaySpecifier = NULL;
  783. m_szServerName = L"";
  784. m_szLdapPath = L"";
  785. m_szCanonicalName = L"";
  786. m_szClass = L"";
  787. m_szPhysicalSchemaNamingContext = L"";
  788. m_szConfigurationNamingContext = L"";
  789. }
  790. HRESULT _QueryDNSServerName();
  791. HRESULT _InitGlobalNamingContexts();
  792. HRESULT _GetFriendlyClassNames(CGrowableArr<CSchemaClassInfo>* pSchemaClassesInfoArray);
  793. };
  794. ////////////////////////////////////////////////////////////////////////////////////////
  795. // CAdsiSearch
  796. class CAdsiSearch
  797. {
  798. public:
  799. CAdsiSearch()
  800. {
  801. m_SearchHandle = NULL;
  802. }
  803. ~CAdsiSearch()
  804. {
  805. Reset();
  806. }
  807. HRESULT Init(LPCWSTR lpszObjectPath)
  808. {
  809. Reset();
  810. return ::ADsOpenObjectHelper(lpszObjectPath, IID_IDirectorySearch,
  811. (void**)&m_spSearchObj);
  812. }
  813. void Reset()
  814. {
  815. if (m_spSearchObj != NULL)
  816. {
  817. if (m_SearchHandle != NULL)
  818. {
  819. m_spSearchObj->CloseSearchHandle(m_SearchHandle);
  820. m_SearchHandle = NULL;
  821. }
  822. }
  823. m_spSearchObj = NULL;
  824. }
  825. HRESULT SetSearchScope(ADS_SCOPEENUM scope)
  826. {
  827. if (m_spSearchObj == NULL)
  828. return E_ADS_BAD_PATHNAME;
  829. ADS_SEARCHPREF_INFO aSearchPref;
  830. aSearchPref.dwSearchPref = ADS_SEARCHPREF_SEARCH_SCOPE;
  831. aSearchPref.vValue.dwType = ADSTYPE_INTEGER;
  832. aSearchPref.vValue.Integer = scope;
  833. return m_spSearchObj->SetSearchPreference(&aSearchPref, 1);
  834. }
  835. HRESULT DoQuery(LPCWSTR lpszFilter, LPCWSTR* pszAttribsArr, const int cAttrs);
  836. HRESULT GetNextRow()
  837. {
  838. if (m_spSearchObj == NULL)
  839. return E_ADS_BAD_PATHNAME;
  840. return m_spSearchObj->GetNextRow(m_SearchHandle);
  841. }
  842. HRESULT GetColumn(LPCWSTR lpszAttribute,
  843. PADS_SEARCH_COLUMN pColumnData)
  844. {
  845. if (m_spSearchObj == NULL)
  846. return E_ADS_BAD_PATHNAME;
  847. return m_spSearchObj->GetColumn(m_SearchHandle,
  848. (LPWSTR)lpszAttribute,
  849. pColumnData);
  850. }
  851. HRESULT FreeColumn(PADS_SEARCH_COLUMN pColumnData)
  852. {
  853. if (m_spSearchObj == NULL)
  854. return E_ADS_BAD_PATHNAME;
  855. return m_spSearchObj->FreeColumn(pColumnData);
  856. }
  857. HRESULT GetColumnString(LPCWSTR lpszAttribute,
  858. CWString& szData)
  859. {
  860. ADS_SEARCH_COLUMN ColumnData;
  861. ::ZeroMemory (&ColumnData, sizeof (ADS_SEARCH_COLUMN));
  862. HRESULT hr = GetColumn(lpszAttribute, &ColumnData);
  863. if (SUCCEEDED(hr))
  864. {
  865. if (ColumnData.dwADsType == ADSTYPE_CASE_IGNORE_STRING)
  866. szData = ColumnData.pADsValues->CaseIgnoreString;
  867. else
  868. {
  869. szData = L"";
  870. hr = E_INVALIDARG;
  871. }
  872. FreeColumn(&ColumnData);
  873. }
  874. return hr;
  875. }
  876. HRESULT GetColumnOctectStringGUID(LPCWSTR lpszAttribute,
  877. GUID& guid)
  878. {
  879. ADS_SEARCH_COLUMN ColumnData;
  880. ::ZeroMemory (&ColumnData, sizeof (ADS_SEARCH_COLUMN));
  881. HRESULT hr = GetColumn(lpszAttribute, &ColumnData);
  882. if (SUCCEEDED(hr))
  883. {
  884. if ( (ColumnData.dwADsType == ADSTYPE_OCTET_STRING) &&
  885. (ColumnData.pADsValues->OctetString.dwLength == 16) )
  886. {
  887. // we have a blob containing a GUID in binary form
  888. memcpy(&guid, ColumnData.pADsValues->OctetString.lpValue, sizeof(GUID));
  889. }
  890. else
  891. {
  892. guid = GUID_NULL;
  893. hr = E_INVALIDARG;
  894. }
  895. FreeColumn(&ColumnData);
  896. }
  897. return hr;
  898. }
  899. HRESULT GetColumnOctectStringGUID(LPCWSTR lpszAttribute,
  900. CWString& szData)
  901. {
  902. GUID guid;
  903. szData = L"";
  904. HRESULT hr = GetColumnOctectStringGUID(lpszAttribute, guid);
  905. if (SUCCEEDED(hr))
  906. {
  907. WCHAR szBuf[128];
  908. if (FormatStringGUID(szBuf, 128, &guid))
  909. {
  910. szData = szBuf;
  911. }
  912. else
  913. {
  914. szData = L"";
  915. hr = E_INVALIDARG;
  916. }
  917. }
  918. return hr;
  919. }
  920. HRESULT GetColumnInteger(LPCWSTR lpszAttribute,
  921. ULONG& uVal)
  922. {
  923. ADS_SEARCH_COLUMN ColumnData;
  924. ::ZeroMemory (&ColumnData, sizeof (ADS_SEARCH_COLUMN));
  925. HRESULT hr = GetColumn(lpszAttribute, &ColumnData);
  926. if (SUCCEEDED(hr))
  927. {
  928. if (ColumnData.dwADsType == ADSTYPE_INTEGER)
  929. uVal = ColumnData.pADsValues->Integer;
  930. else
  931. hr = E_INVALIDARG;
  932. FreeColumn(&ColumnData);
  933. }
  934. return hr;
  935. }
  936. private:
  937. CComPtr<IDirectorySearch> m_spSearchObj;
  938. ADS_SEARCH_HANDLE m_SearchHandle;
  939. };
  940. ///////////////////////////////////////////////////////////////////////
  941. // CErrorMessageHandlerBase
  942. class CErrorMessageHandlerBase
  943. {
  944. public:
  945. CErrorMessageHandlerBase() {}
  946. virtual ~CErrorMessageHandlerBase() {}
  947. virtual void ReportHRESULTError(LPCWSTR lpszMsg, HRESULT hr)
  948. {
  949. UNREFERENCED_PARAMETER (lpszMsg);
  950. UNREFERENCED_PARAMETER (hr);
  951. }
  952. virtual void ReportHRESULTError(UINT nStringID, HRESULT hr)
  953. {
  954. UNREFERENCED_PARAMETER (nStringID);
  955. UNREFERENCED_PARAMETER (hr);
  956. }
  957. };
  958. DWORD
  959. FormatStringID(LPTSTR *ppszResult, UINT idStr , ...);
  960. #endif // _UTIL_H__