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.

711 lines
14 KiB

  1. /*++
  2. Copyright (c) 1994-1998 Microsoft Corporation
  3. Module Name :
  4. usrbrows.h
  5. Abstract:
  6. User Browser Dialog definitions
  7. Author:
  8. Ronald Meijer (ronaldm)
  9. Project:
  10. Internet Services Manager
  11. Revision History:
  12. --*/
  13. #ifndef _USRBROWS_H
  14. #define _USRBROWS_H
  15. #ifndef _GETUSER_H_
  16. extern "C"
  17. {
  18. #define _NTSEAPI_ // We already have the security API hdrs
  19. #include <getuser.h>
  20. }
  21. #endif // _GETUSER_H_
  22. #ifndef _SHLOBJ_H_
  23. #include <shlobj.h>
  24. #endif // _SHLOBJ_H_
  25. BOOL COMDLL
  26. GetIUsrAccount(
  27. IN LPCTSTR lpstrServer,
  28. IN CWnd * pParent,
  29. OUT CString & str
  30. );
  31. DWORD COMDLL
  32. VerifyUserPassword(
  33. IN LPCTSTR lpstrUserName,
  34. IN LPCTSTR lpstrPassword
  35. );
  36. class COMDLL CAccessEntry : public CObjectPlus
  37. /*++
  38. Class Description:
  39. An access description entry, containing a SID and ACCESS mask
  40. of rights specifically granted.
  41. Public Interface:
  42. LookupAccountSid : Resolve account name to SID
  43. CAccessEntry : Constructors
  44. ~CAccessEntry : Destructor
  45. ResolveSID : Resolve account name to SID
  46. operator == : Comparison operator
  47. AddPermissions : Add to access mask
  48. RemovePermissions : Remove from access mask
  49. MarkEntryAsNew : Flag object as new
  50. MarkEntryAsClean : Remove dirty flag
  51. QueryUserName : Get the account name
  52. QueryPictureID : Get 0-based bitmap offset for account
  53. GetSid : Get the SID
  54. QueryAccessMask : Get the raw Access granted bits
  55. IsDirty : Determine if item has changed
  56. IsDeleted : Determine if item is flagged for deletion
  57. IsVisible : Determine if item should be shown in listbox
  58. FlagForDeletion : Flag object for deletion or reset that flag
  59. IsSIDResolved : Return TRUE if the SID has already been resolved
  60. HasAppropriateAccess : Compare access bits to see if the objects has
  61. specific permissions
  62. HasSomeAccess : Check to see if object has at least one
  63. permission bit set.
  64. IsDeletable : Determine if object can be deleted
  65. --*/
  66. {
  67. public:
  68. //
  69. // Helper function to look up account sid
  70. //
  71. static BOOL LookupAccountSid(
  72. IN CString & str,
  73. OUT int & nPictureID,
  74. OUT PSID pSid,
  75. IN LPCTSTR lpstrSystemName = NULL
  76. );
  77. //
  78. // Construction/Destruction
  79. //
  80. public:
  81. CAccessEntry(
  82. IN LPVOID pAce,
  83. IN BOOL fResolveSID = FALSE
  84. );
  85. CAccessEntry(
  86. IN ACCESS_MASK accPermissions,
  87. IN PSID pSid,
  88. IN LPCTSTR lpstrSystemName = NULL,
  89. IN BOOL fResolveSID = FALSE
  90. );
  91. CAccessEntry(
  92. IN PSID pSid,
  93. IN LPCTSTR pszUserName,
  94. IN LPCTSTR pszClassName
  95. );
  96. CAccessEntry(
  97. IN CAccessEntry& ae
  98. );
  99. ~CAccessEntry();
  100. //
  101. // Operations
  102. //
  103. public:
  104. //void SetAccessMask(LPACCESS_ENTRY lpAccessEntry);
  105. BOOL ResolveSID();
  106. BOOL operator ==(const CAccessEntry & acc) const;
  107. BOOL operator ==(const PSID pSid) const;
  108. void AddPermissions(ACCESS_MASK accnewPermissions);
  109. void RemovePermissions(ACCESS_MASK accPermissions);
  110. void MarkEntryAsNew();
  111. void MarkEntryAsClean();
  112. void MarkEntryAsChanged();
  113. //
  114. // Access Functions
  115. //
  116. public:
  117. LPCTSTR QueryUserName() const;
  118. //
  119. // The "picture" id is the 0-based index of the
  120. // bitmap that goes with this entry, and which
  121. // is used for display in the listbox.
  122. //
  123. int QueryPictureID() const;
  124. PSID GetSid();
  125. ACCESS_MASK QueryAccessMask() const;
  126. //
  127. // Check to see if this entry has undergone
  128. // any changes since we called it up
  129. //
  130. BOOL IsDirty() const;
  131. BOOL IsDeleted() const;
  132. BOOL IsVisible() const;
  133. void FlagForDeletion(
  134. IN BOOL fDelete = TRUE
  135. );
  136. //
  137. // Check to see if we've already looked up the
  138. // name of this SID
  139. //
  140. BOOL IsSIDResolved() const;
  141. //
  142. // Check to see if the add flag has been set for this
  143. // entry.
  144. //
  145. /*
  146. BOOL IsNew() const;
  147. //
  148. // Check to see if the update flag has been set for this
  149. // entry.
  150. //
  151. BOOL IsDifferent() const;
  152. */
  153. //
  154. // See if the entry has the access mask required.
  155. //
  156. BOOL HasAppropriateAccess(ACCESS_MASK accTargetMask) const;
  157. //
  158. // Check to see if the entry has at least some
  159. // privileges (if it doesn't, it should be deleted)
  160. //
  161. BOOL HasSomeAccess() const;
  162. //
  163. // See if this is a deletable entry
  164. //
  165. BOOL IsDeletable() const;
  166. private:
  167. ACCESS_MASK m_accMask;
  168. CString m_strUserName;
  169. LPTSTR m_lpstrSystemName;
  170. PSID m_pSid;
  171. BOOL m_fDirty;
  172. BOOL m_fSIDResolved;
  173. BOOL m_fDeletable;
  174. BOOL m_fInvisible;
  175. BOOL m_fDeleted;
  176. int m_nPictureID;
  177. int m_fUpdates;
  178. };
  179. //
  180. // Helper functions
  181. //
  182. // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  183. //
  184. // Convert an oblist of CAccessEntry objects to a blob
  185. //
  186. BOOL COMDLL BuildAclBlob(
  187. IN CObListPlus & oblSID,
  188. OUT CBlob & blob
  189. );
  190. //
  191. // Reverse the above. Build an oblist of CAccessEntry lists from
  192. // a blob.
  193. //
  194. DWORD COMDLL BuildAclOblistFromBlob(
  195. IN CBlob & blob,
  196. OUT CObListPlus & oblSID
  197. );
  198. //
  199. // Build a blob representing an ACL with the local domain group
  200. //
  201. DWORD COMDLL BuildAdminAclBlob(
  202. OUT CBlob & blob
  203. );
  204. class COMDLL CAccessEntryListBox : public CRMCListBox
  205. /*++
  206. Class Description:
  207. Listbox of access entry objects. Listbox may be
  208. single or multiselect.
  209. Public Interface:
  210. CAccessEntryListBox : Constructor
  211. AddToAccessList : Add to list
  212. FillAccessListBox : Fill listbox
  213. ResolveAccessList : Resolve all SIDS in the container
  214. AddUserPermissions : Add user permissions
  215. GetSelectedItem : Get item if it's the only one selected,
  216. or NULL.
  217. --*/
  218. {
  219. DECLARE_DYNAMIC(CAccessEntryListBox);
  220. public:
  221. static const nBitmaps; // Number of bitmaps
  222. //
  223. // Constructor
  224. //
  225. public:
  226. CAccessEntryListBox(
  227. IN int nTab = 0
  228. );
  229. //
  230. // Interface
  231. //
  232. public:
  233. //
  234. // Return the singly selected item, or NULL
  235. // if 0, or more than one item is selected
  236. //
  237. CAccessEntry * GetSelectedItem(
  238. OUT int * pnSel = NULL
  239. );
  240. //
  241. // Return next selected listbox item (doesn't matter
  242. // if the listbox is single select or multi-select)
  243. //
  244. CAccessEntry * GetNextSelectedItem(
  245. IN OUT int * pnStartingIndex
  246. );
  247. //
  248. // Get item at selection or NULL
  249. //
  250. CAccessEntry * GetItem(UINT nIndex);
  251. //
  252. // Interface to container
  253. //
  254. public:
  255. BOOL AddToAccessList(
  256. IN CWnd * pWnd,
  257. IN LPCTSTR lpstrServer,
  258. IN CObListPlus & obl
  259. );
  260. void FillAccessListBox(
  261. IN CObListPlus & obl
  262. );
  263. protected:
  264. void ResolveAccessList(
  265. IN CObListPlus &obl
  266. );
  267. BOOL AddUserPermissions(
  268. IN LPCTSTR lpstrServer,
  269. IN CObListPlus &oblSID,
  270. IN CAccessEntry * newUser,
  271. IN ACCESS_MASK accPermissions
  272. );
  273. //
  274. // Interface to listbox
  275. //
  276. protected:
  277. int AddItem(CAccessEntry * pItem);
  278. void SetTabs(int nTab);
  279. protected:
  280. virtual void DrawItemEx(CRMCListBoxDrawStruct & s);
  281. private:
  282. int m_nTab;
  283. };
  284. class COMDLL CBrowseDomainDlg
  285. /*++
  286. Class Description:
  287. Domain browser dialog
  288. Public Interface:
  289. CBrowseDomainDlg : Construct the dialog
  290. ~CBrowseDomainDlg : Destruct the dialog
  291. GetSelectedDomain : Get the full path selected
  292. --*/
  293. {
  294. //
  295. // Construction
  296. //
  297. public:
  298. //
  299. // standard constructor
  300. //
  301. CBrowseDomainDlg(
  302. IN CWnd * pParent = NULL,
  303. IN LPCTSTR lpszInitialDomain = NULL
  304. );
  305. ~CBrowseDomainDlg();
  306. public:
  307. LPCTSTR GetSelectedDomain(
  308. OUT CString & str
  309. ) const;
  310. virtual int DoModal();
  311. protected:
  312. TCHAR m_szBuffer[MAX_PATH+1];
  313. CString m_strTitle;
  314. CString m_strInitialDomain;
  315. BROWSEINFO m_bi;
  316. };
  317. class COMDLL CBrowseUserDlg
  318. /*++
  319. Class Description:
  320. User browser dialog class. This is simply a thin wrapper around
  321. the getuser interface
  322. Public Interface:
  323. CBrowseUserDlg : Construct the dialog
  324. DoModal : Show the dialog
  325. GetSelectionCount : Query how many user names/groups were selected
  326. GetSelectedAccounts : Get the string list of account names
  327. --*/
  328. {
  329. public:
  330. //
  331. // Constructor
  332. //
  333. CBrowseUserDlg(
  334. IN CWnd * pParentWnd = NULL,
  335. IN LPCTSTR lpszTitle = NULL,
  336. IN LPCTSTR lpszInitialDomain = NULL,
  337. IN BOOL fExpandNames = FALSE,
  338. IN BOOL fSkipInitialDomainInName = TRUE,
  339. IN DWORD dwFlags = USRBROWS_INCL_EVERYONE
  340. | USRBROWS_SHOW_ALL,
  341. IN LPCTSTR lpszHelpFileName = NULL,
  342. IN ULONG ulHelpContext = 0L
  343. );
  344. //
  345. // Show the dialog
  346. //
  347. virtual int DoModal();
  348. //
  349. // Get the number of selected accounts
  350. //
  351. int GetSelectionCount() const;
  352. //
  353. // Get the selected accounts list
  354. //
  355. CStringList & GetSelectedAccounts();
  356. private:
  357. USERBROWSER m_ub;
  358. BOOL m_fSkipInitialDomainInName;
  359. CStringList m_strSelectedAccounts;
  360. CString m_strTitle;
  361. CString m_strInitialDomain;
  362. CString m_strHelpFileName;
  363. };
  364. class COMDLL CUserAccountDlg : public CDialog
  365. /*++
  366. Class Description:
  367. User account dialog. Present a user account/password and allow
  368. changing, browsing and checking the password
  369. Public Interface:
  370. CUserAccountDlg : Constructor
  371. --*/
  372. {
  373. //
  374. // Construction
  375. //
  376. public:
  377. CUserAccountDlg(
  378. IN LPCTSTR lpstrServer,
  379. IN LPCTSTR lpstrUserName,
  380. IN LPCTSTR lpstrPassword,
  381. IN CWnd * pParent = NULL
  382. );
  383. //
  384. // Dialog Data
  385. //
  386. public:
  387. //{{AFX_DATA(CUserAccountDlg)
  388. enum { IDD = IDD_USER_ACCOUNT };
  389. CEdit m_edit_UserName;
  390. CEdit m_edit_Password;
  391. CString m_strUserName;
  392. //}}AFX_DATA
  393. CString m_strPassword;
  394. //
  395. // Overrides
  396. //
  397. protected:
  398. // ClassWizard generated virtual function overrides
  399. //{{AFX_VIRTUAL(CUserAccountDlg)
  400. protected:
  401. virtual void DoDataExchange(CDataExchange * pDX);
  402. //}}AFX_VIRTUAL
  403. //
  404. // Implementation
  405. //
  406. protected:
  407. // Generated message map functions
  408. //{{AFX_MSG(CUserAccountDlg)
  409. afx_msg void OnButtonBrowseUsers();
  410. afx_msg void OnButtonCheckPassword();
  411. afx_msg void OnChangeEditUsername();
  412. //}}AFX_MSG
  413. DECLARE_MESSAGE_MAP()
  414. private:
  415. CString m_strServer;
  416. };
  417. //
  418. // Inline Expansion
  419. //
  420. // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  421. inline int CAccessEntry::QueryPictureID() const
  422. {
  423. ASSERT(m_fSIDResolved);
  424. return m_nPictureID;
  425. }
  426. inline LPCTSTR CAccessEntry::QueryUserName() const
  427. {
  428. return m_strUserName;
  429. }
  430. inline PSID CAccessEntry::GetSid()
  431. {
  432. return m_pSid;
  433. }
  434. inline ACCESS_MASK CAccessEntry::QueryAccessMask() const
  435. {
  436. return m_accMask;
  437. }
  438. inline BOOL CAccessEntry::IsDirty() const
  439. {
  440. return m_fDirty;
  441. }
  442. inline BOOL CAccessEntry::IsDeleted() const
  443. {
  444. return m_fDeleted;
  445. }
  446. inline BOOL CAccessEntry::IsVisible() const
  447. {
  448. return !m_fInvisible;
  449. }
  450. inline void CAccessEntry::FlagForDeletion(
  451. IN BOOL fDelete
  452. )
  453. {
  454. m_fDirty = TRUE;
  455. m_fDeleted = fDelete;
  456. }
  457. inline BOOL CAccessEntry::IsSIDResolved() const
  458. {
  459. return m_fSIDResolved;
  460. }
  461. /*
  462. inline BOOL CAccessEntry::IsNew() const
  463. {
  464. return (m_fUpdates & UPD_ADDED) != 0;
  465. }
  466. inline BOOL CAccessEntry::IsDifferent() const
  467. {
  468. return (m_fUpdates & UPD_CHANGED) != 0;
  469. }
  470. inline void CAccessEntry::SetAccessMask(
  471. IN LPACCESS_ENTRY lpAccessEntry
  472. )
  473. {
  474. m_accMask = lpAccessEntry->AccessRights;
  475. }
  476. */
  477. inline BOOL CAccessEntry::HasAppropriateAccess(
  478. IN ACCESS_MASK accTargetMask
  479. ) const
  480. {
  481. return (m_accMask & accTargetMask) == accTargetMask;
  482. }
  483. inline BOOL CAccessEntry::HasSomeAccess() const
  484. {
  485. return m_accMask;
  486. }
  487. inline BOOL CAccessEntry::IsDeletable() const
  488. {
  489. return m_fDeletable;
  490. }
  491. inline BOOL CAccessEntry::operator ==(
  492. IN const CAccessEntry & acc
  493. ) const
  494. {
  495. return ::EqualSid(acc.m_pSid, m_pSid);
  496. }
  497. inline BOOL CAccessEntry::operator ==(
  498. IN const PSID pSid
  499. ) const
  500. {
  501. return ::EqualSid(pSid, m_pSid);
  502. }
  503. inline void CAccessEntry::MarkEntryAsNew()
  504. {
  505. m_fDirty = TRUE;
  506. //m_fUpdates |= UPD_ADDED;
  507. }
  508. inline void CAccessEntry::MarkEntryAsClean()
  509. {
  510. m_fDirty = FALSE;
  511. //m_fUpdates = UPD_NONE;
  512. }
  513. inline void CAccessEntry::MarkEntryAsChanged()
  514. {
  515. m_fDirty = TRUE;
  516. //m_fUpdates = UPD_CHANGED;
  517. }
  518. inline CAccessEntryListBox::CAccessEntryListBox (
  519. IN int nTab
  520. )
  521. {
  522. SetTabs(nTab);
  523. }
  524. inline void CAccessEntryListBox::SetTabs(
  525. IN int nTab
  526. )
  527. {
  528. m_nTab = nTab;
  529. }
  530. inline CAccessEntry * CAccessEntryListBox::GetItem(
  531. IN UINT nIndex
  532. )
  533. {
  534. return (CAccessEntry *)GetItemDataPtr(nIndex);
  535. }
  536. inline int CAccessEntryListBox::AddItem(
  537. IN CAccessEntry * pItem
  538. )
  539. {
  540. return AddString ((LPCTSTR)pItem);
  541. }
  542. inline CAccessEntry * CAccessEntryListBox::GetSelectedItem(
  543. OUT int * pnSel
  544. )
  545. {
  546. return (CAccessEntry *)CRMCListBox::GetSelectedListItem(pnSel);
  547. }
  548. inline CAccessEntry * CAccessEntryListBox::GetNextSelectedItem(
  549. IN OUT int * pnStartingIndex
  550. )
  551. {
  552. return (CAccessEntry *)CRMCListBox::GetNextSelectedItem(pnStartingIndex);
  553. }
  554. inline int CBrowseUserDlg::GetSelectionCount() const
  555. {
  556. return (int) m_strSelectedAccounts.GetCount();
  557. }
  558. inline CStringList & CBrowseUserDlg::GetSelectedAccounts()
  559. {
  560. return m_strSelectedAccounts;
  561. }
  562. #endif // _USRBROWS_H