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.

995 lines
40 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1999
  5. //
  6. // File: dsUtil.h
  7. //
  8. // Contents: Utility functions for working with Active Directory
  9. //
  10. // History: 05-Sep-2000 JeffJon Created
  11. //
  12. //
  13. //--------------------------------------------------------------------------
  14. #ifndef _DSUTIL_H_
  15. #define _DSUTIL_H_
  16. // Define a symbol for the bit in the options flag on a NTDSDSA object
  17. // that determines if the server is a global catalog
  18. #define SERVER_IS_GC_BIT 0x1
  19. #include <Ntdsapi.h>
  20. #include <Sddl.h>
  21. //+--------------------------------------------------------------------------
  22. //
  23. // Class: CDSCmdCredentialObject
  24. //
  25. // Purpose: Object for maintaining username and an encrypted password
  26. //
  27. // History: 6-Sep-2000 JeffJon Created
  28. //
  29. //---------------------------------------------------------------------------
  30. class CDSCmdCredentialObject
  31. {
  32. public :
  33. //
  34. // Constructor
  35. //
  36. CDSCmdCredentialObject();
  37. //
  38. // Destructor
  39. //
  40. ~CDSCmdCredentialObject();
  41. //
  42. // Public accessor methods
  43. //
  44. PCWSTR GetUsername() const { return m_sbstrUsername; }
  45. HRESULT SetUsername(PCWSTR pszUsername);
  46. HRESULT GetPassword(PWSTR *ppszPassword) const;
  47. HRESULT SetPassword(PCWSTR pszPassword);
  48. HRESULT SetEncryptedPassword(DATA_BLOB* pEncryptedPasswordDataBlob);
  49. bool UsingCredentials() const { return m_bUsingCredentials; }
  50. void SetUsingCredentials(const bool bUseCred) { m_bUsingCredentials = bUseCred; }
  51. private :
  52. //
  53. // Private data members
  54. //
  55. CComBSTR m_sbstrUsername;
  56. DATA_BLOB m_EncryptedPasswordDataBlob;
  57. bool m_bUsingCredentials;
  58. };
  59. typedef enum
  60. {
  61. DSCMD_LDAP_PROVIDER = 0,
  62. DSCMD_GC_PROVIDER
  63. } DSCMD_PROVIDER_TYPE;
  64. //+--------------------------------------------------------------------------
  65. //
  66. // Class: CDSCmdBasePathsInfo
  67. //
  68. // Purpose: Object for storing and retrieving the paths for the well
  69. // known naming contexts
  70. //
  71. // History: 6-Sep-2000 JeffJon Created
  72. //
  73. //---------------------------------------------------------------------------
  74. class CDSCmdBasePathsInfo
  75. {
  76. public:
  77. //
  78. // Constructor
  79. //
  80. CDSCmdBasePathsInfo();
  81. //
  82. // Destructor
  83. //
  84. ~CDSCmdBasePathsInfo();
  85. //
  86. // Public accessor methods
  87. //
  88. HRESULT InitializeFromName(const CDSCmdCredentialObject& refCredentialObject,
  89. PCWSTR pszServerOrDomain,
  90. bool bServerName = false);
  91. bool IsInitialized() const { return m_bInitialized; }
  92. CComBSTR GetProviderAndServerName() const { return m_sbstrProviderAndServerName; }
  93. CComBSTR GetGCProvider() const { return m_sbstrGCProvider; }
  94. CComBSTR GetServerName() const { return m_sbstrServerName; }
  95. CComBSTR GetAbstractSchemaPath() const { return m_sbstrAbstractSchemaPath; }
  96. IADs* GetRootDSE() const { return m_spRootDSE; }
  97. CComBSTR GetConfigurationNamingContext() const;
  98. CComBSTR GetSchemaNamingContext() const;
  99. CComBSTR GetDefaultNamingContext() const;
  100. //
  101. // Other helpful methods
  102. //
  103. void ComposePathFromDN(PCWSTR pszDN,
  104. CComBSTR& refsbstrPath,
  105. DSCMD_PROVIDER_TYPE nProviderType = DSCMD_LDAP_PROVIDER) const;
  106. HRESULT GetDomainMode(const CDSCmdCredentialObject& refCredObject,
  107. bool& bMixedMode) const;
  108. private:
  109. //
  110. // Private data members
  111. //
  112. bool m_bInitialized;
  113. CComBSTR m_sbstrProviderAndServerName;
  114. CComBSTR m_sbstrGCProvider;
  115. CComBSTR m_sbstrServerName;
  116. CComBSTR m_sbstrAbstractSchemaPath;
  117. mutable bool m_bModeInitialized;
  118. mutable bool m_bDomainMode;
  119. mutable CComBSTR m_sbstrConfigNamingContext;
  120. mutable CComBSTR m_sbstrSchemaNamingContext;
  121. mutable CComBSTR m_sbstrDefaultNamingContext;
  122. CComPtr<IADs> m_spRootDSE;
  123. };
  124. //////////////////////////////////////////////////////////////////////////////////////
  125. //+--------------------------------------------------------------------------
  126. //
  127. // Function: DSCmdOpenObject
  128. //
  129. // Synopsis: A wrapper around ADsOpenObject
  130. //
  131. // Arguments: [refCredentialObject - IN] : a reference to a credential management object
  132. // [pszPath - IN] : a pointer to a NULL terminated wide character
  133. // string that contains the ADSI path of the
  134. // object to connect to
  135. // [refIID - IN] : the interface ID of the interface to return
  136. // [ppObject - OUT] : a pointer which is to receive the interface pointer
  137. // [bBindToServer - IN] : true if the path contains a server name,
  138. // false otherwise
  139. //
  140. // Returns: HRESULT : S_OK if everything succeeded
  141. // Anything else is a failure code from an ADSI call
  142. //
  143. // History: 06-Sep-2000 JeffJon Created
  144. //
  145. //---------------------------------------------------------------------------
  146. HRESULT DSCmdOpenObject(const CDSCmdCredentialObject& refCredentialObject,
  147. PCWSTR pszPath,
  148. REFIID refIID,
  149. void** ppObject,
  150. bool bBindToServer);
  151. //+--------------------------------------------------------------------------
  152. //
  153. // Function: GetErrorMessage
  154. //
  155. // Synopsis: Retrieves the error message associated with the HRESULT by
  156. // using FormatMessage
  157. //
  158. // Arguments: [hr - IN] : HRESULT for which the error
  159. // message is to be retrieved
  160. // [sbstrErrorMessage - OUT] : Receives the error message
  161. //
  162. // Returns: bool : true if the message was formatted properly
  163. // false otherwise
  164. //
  165. // History: 11-Sep-2000 JeffJon Created
  166. //
  167. //---------------------------------------------------------------------------
  168. bool GetErrorMessage(HRESULT hr, CComBSTR& sbstrErrorMessage);
  169. //+--------------------------------------------------------------------------
  170. //
  171. // Function: DisplayErrorMessage
  172. //
  173. // Synopsis: Displays the error message retrieved from GetErrorMessage
  174. // to stderr. If GetErrorMessage fails, it displays the error
  175. // code of the HRESULT
  176. //
  177. // Arguments: [pszCommand - IN]: the name of the command line executable
  178. // [pszName - IN] : the name passed in as the target of the operation
  179. // [hr - IN] : HRESULT for which the error
  180. // message is to be retrieved
  181. // [pszMessage - IN]: string of an additional message to be displayed
  182. // at the end
  183. //
  184. // Returns: bool : true if the message was formatted and displayed properly
  185. // false otherwise
  186. //
  187. // History: 11-Sep-2000 JeffJon Created
  188. //
  189. //---------------------------------------------------------------------------
  190. bool DisplayErrorMessage(PCWSTR pszCommand,
  191. PCWSTR pszName,
  192. HRESULT hr,
  193. PCWSTR pszMessage = NULL);
  194. //+--------------------------------------------------------------------------
  195. //
  196. // Function: DisplayErrorMessage
  197. //
  198. // Synopsis: Displays the error message retrieved from GetErrorMessage
  199. // to stderr. If GetErrorMessage fails, it displays the error
  200. // code of the HRESULT
  201. //
  202. // Arguments: [pszCommand - IN]: the name of the command line executable
  203. // [pszName - IN] : the name passed in as the target of the operation
  204. // [hr - IN] : HRESULT for which the error
  205. // message is to be retrieved
  206. // [nStringID - IN] : Resource ID an additional message to be displayed
  207. // at the end
  208. //
  209. // Returns: bool : true if the message was formatted and displayed properly
  210. // false otherwise
  211. //
  212. // History: 11-Sep-2000 JeffJon Created
  213. //
  214. //---------------------------------------------------------------------------
  215. bool DisplayErrorMessage(PCWSTR pszCommand,
  216. PCWSTR pszName,
  217. HRESULT hr,
  218. UINT nStringID);
  219. //+--------------------------------------------------------------------------
  220. //
  221. // Function: DisplaySuccessMessage
  222. //
  223. // Synopsis: Displays a success message for the command
  224. //
  225. // Arguments: [pszCommand - IN]: the name of the command line executable
  226. // [pszName - IN] : the name passed in as the target of the operation
  227. //
  228. // Returns: bool : true if the message was formatted and displayed properly
  229. // false otherwise
  230. //
  231. // History: 11-Sep-2000 JeffJon Created
  232. //
  233. //---------------------------------------------------------------------------
  234. bool DisplaySuccessMessage(PCWSTR pszCommand,
  235. PCWSTR pszName);
  236. //+--------------------------------------------------------------------------
  237. //
  238. // Function: WriteStringIDToStandardOut
  239. //
  240. // Synopsis: Loads the String Resource and displays on Standardout
  241. //
  242. // Arguments: nStringID : Resource ID
  243. // Returns: bool : true if the message was formatted and displayed properly
  244. // false otherwise
  245. //
  246. // History: 11-Sep-2000 hiteshr Created
  247. //
  248. //---------------------------------------------------------------------------
  249. bool WriteStringIDToStandardOut(UINT nStringID);
  250. //+--------------------------------------------------------------------------
  251. //
  252. // Function: WriteStringIDToStandardErr
  253. //
  254. // Synopsis: Loads the String Resource and displays on StandardErr
  255. //
  256. // Arguments: nStringID : Resource ID
  257. // Returns: bool : true if the message was formatted and displayed properly
  258. // false otherwise
  259. //
  260. // History: 14-June-2001 hiteshr Created
  261. //
  262. //---------------------------------------------------------------------------
  263. bool WriteStringIDToStandardErr(UINT nStringID);
  264. /////////////////////////////////////////////////////////////////////////////////////////
  265. //
  266. // Forward declarations
  267. //
  268. struct _DSAttributeTableEntry;
  269. //+--------------------------------------------------------------------------
  270. //
  271. // Struct: _DSObjectTableEntry
  272. //
  273. // Purpose: Definition of a table entry that describes what attributes
  274. // are exposed on an specific object class
  275. //
  276. // History: 6-Sep-2000 JeffJon Created
  277. //
  278. //---------------------------------------------------------------------------
  279. typedef struct _DSObjectTableEntry
  280. {
  281. //
  282. // The objectClass of the object to be created or modified
  283. //
  284. PCWSTR pszObjectClass;
  285. //
  286. // The command line string used to determine the object class
  287. // This is not always identical to pszObjectClass
  288. //
  289. PCWSTR pszCommandLineObjectType;
  290. //
  291. // The table to merge with the common switches for the parser
  292. //
  293. ARG_RECORD* pParserTable;
  294. //
  295. // The ID of the Usage help text for this
  296. //
  297. UINT* nUsageID;
  298. //
  299. // A count of the number of attributes in the table above
  300. //
  301. DWORD dwAttributeCount;
  302. //
  303. // A pointer to a table of attributes that can be modified or set on this class
  304. //
  305. _DSAttributeTableEntry** pAttributeTable;
  306. // Some sort of creation function
  307. } DSOBJECTTABLEENTRY, *PDSOBJECTTABLEENTRY;
  308. //+-------------------------------------------------------------------------
  309. //
  310. // Type: PATTRIBUTEEVALFUNC
  311. //
  312. // Synopsis: The definition of a function that prepares the command line
  313. // string value to be set in the DS.
  314. //
  315. // Note: *ppAttr should be set to NULL if this function does not need
  316. // to create a new unique ADS_ATTR_INFO structure in the array
  317. // to be set on the object. For instance, there are many bits
  318. // in the user account control that are represented by different
  319. // command line flags but we really only need one entry for the
  320. // userAccountControl attribute.
  321. //
  322. // Returns: S_OK if the pAttr members were successfully set.
  323. // S_FALSE if the function failed but displayed its own error message.
  324. // If the return value is S_FALSE then the function should call
  325. // SetLastError() with the error code.
  326. // Otherwise the pAttr info will not be used when making
  327. // the modifications to the object and an error will be reported
  328. //
  329. // History: 08-Sep-2000 JeffJon Created
  330. //
  331. //---------------------------------------------------------------------------
  332. typedef HRESULT (*PATTRIBUTEEVALFUNC)(PCWSTR pszPath,
  333. const CDSCmdBasePathsInfo& refBasePathsInfo,
  334. const CDSCmdCredentialObject& refCredentialObject,
  335. const PDSOBJECTTABLEENTRY pObjectEntry,
  336. const ARG_RECORD& argRecord,
  337. DWORD dwAttributeIdx,
  338. PADS_ATTR_INFO* ppAttr);
  339. //+--------------------------------------------------------------------------
  340. //
  341. // Flags for the _DSAttributeDescription and _DSAttributeTableEntry
  342. // struct dwFlags field
  343. //
  344. //---------------------------------------------------------------------------
  345. #define DS_ATTRIBUTE_DIRTY 0x00000001
  346. #define DS_ATTRIBUTE_READ 0x00000002
  347. #define DS_ATTRIBUTE_ONCREATE 0x00000004
  348. #define DS_ATTRIBUTE_POSTCREATE 0x00000008
  349. #define DS_ATTRIBUTE_REQUIRED 0x00000010
  350. #define DS_ATTRIBUTE_NOT_REUSABLE 0x00000020
  351. //+--------------------------------------------------------------------------
  352. //
  353. // Struct: _DSAttributeDescription
  354. //
  355. // Purpose: Definition of a table entry that describes an attribute
  356. // This was split out from _DSAttributeTableEntry so that
  357. // more than one entry could point to the same attribute.
  358. // For instance, the userAccountControl bits are separate
  359. // command line flags but all use the same attribute. This
  360. // way we only need to read the attribute once and set it once.
  361. //
  362. // History: 13-Sep-2000 JeffJon Created
  363. //
  364. //---------------------------------------------------------------------------
  365. typedef struct _DSAttributeDescription
  366. {
  367. //
  368. // The ADS_ATTR_INFO struct that defines how this attribute will be set
  369. //
  370. ADS_ATTR_INFO adsAttrInfo;
  371. //
  372. // Flags that are used to determine how and when the attribute can be set,
  373. // if the adsAttrInfo has been retrieved and/or set.
  374. // For instance, group membership can only be set after the user object is
  375. // created
  376. //
  377. DWORD dwFlags;
  378. } DSATTRIBUTEDESCRIPTION, *PDSATTRIBUTEDESCRIPTION;
  379. //+--------------------------------------------------------------------------
  380. //
  381. // Struct: _DSAttributeTableEntry
  382. //
  383. // Purpose: Definition of a table entry that describes an attribute
  384. //
  385. // History: 6-Sep-2000 JeffJon Created
  386. //
  387. //---------------------------------------------------------------------------
  388. typedef struct _DSAttributeTableEntry
  389. {
  390. //
  391. // The name of the attribute
  392. //
  393. PWSTR pszName;
  394. //
  395. // The unique identifier for this attribute that cooresponds to
  396. // the command line switch
  397. //
  398. UINT nAttributeID;
  399. //
  400. // Flags that represent when this attribute can be set in relation to
  401. // the objects creation
  402. //
  403. DWORD dwFlags;
  404. //
  405. // Pointer to the description of the attribute
  406. //
  407. PDSATTRIBUTEDESCRIPTION pAttrDesc;
  408. //
  409. // A function that can evaluate the value string passed in and make
  410. // it ready for setting on the object
  411. //
  412. PATTRIBUTEEVALFUNC pEvalFunc;
  413. //
  414. // Undefined data that is static and specific for the entry
  415. //
  416. void* pVoid;
  417. } DSATTRIBUTETABLEENTRY, *PDSATTRIBUTETABLEENTRY;
  418. //+--------------------------------------------------------------------------
  419. //
  420. // Function: ReadGroupType
  421. //
  422. // Synopsis: Reads the group type from the group specified by the given DN
  423. //
  424. // Arguments: [pszDN - IN] : pointer to a string containing the DN
  425. // to the object being modified
  426. // [refBasePathsInfo - IN] : reference to an instance of the
  427. // CDSCmdBasePathsInfo class
  428. // [refCredentialObject - IN] : reference to an instance of the
  429. // CDSCmdCredentialObject class
  430. // [plType - OUT] : returns the currect group type
  431. //
  432. // Returns: HRESULT : S_OK if everything succeeded
  433. // Otherwise an ADSI failure code
  434. //
  435. // History: 18-Sep-2000 JeffJon Created
  436. //
  437. //---------------------------------------------------------------------------
  438. HRESULT ReadGroupType(PCWSTR pszDN,
  439. const CDSCmdBasePathsInfo& refBasePathsInfo,
  440. const CDSCmdCredentialObject& refCredentialObject,
  441. long* plType);
  442. //+--------------------------------------------------------------------------
  443. // Function to be used in the attribute table for evaluating the command line
  444. // strings
  445. //---------------------------------------------------------------------------
  446. HRESULT FillAttrInfoFromObjectEntry(PCWSTR pszDN,
  447. const CDSCmdBasePathsInfo& refBasePathsInfo,
  448. const CDSCmdCredentialObject& refCredentialObject,
  449. const PDSOBJECTTABLEENTRY pObjectEntry,
  450. const ARG_RECORD& argRecord,
  451. DWORD dwAttributeIdx,
  452. PADS_ATTR_INFO* ppAttr);
  453. HRESULT ResetUserPassword(PCWSTR pszDN,
  454. const CDSCmdBasePathsInfo& refBasePathsInfo,
  455. const CDSCmdCredentialObject& refCredentialObject,
  456. const PDSOBJECTTABLEENTRY pObjectEntry,
  457. const ARG_RECORD& argRecord,
  458. DWORD dwAttributeIdx,
  459. PADS_ATTR_INFO* ppAttr);
  460. HRESULT ResetComputerAccount(PCWSTR pszDN,
  461. const CDSCmdBasePathsInfo& refBasePathsInfo,
  462. const CDSCmdCredentialObject& refCredentialObject,
  463. const PDSOBJECTTABLEENTRY pObjectEntry,
  464. const ARG_RECORD& argRecord,
  465. DWORD dwAttributeIdx,
  466. PADS_ATTR_INFO* ppAttr);
  467. HRESULT PasswordNotRequired(PCWSTR pszDN,
  468. const CDSCmdBasePathsInfo& refBasePathsInfo,
  469. const CDSCmdCredentialObject& refCredentialObject,
  470. const PDSOBJECTTABLEENTRY pObjectEntry,
  471. const ARG_RECORD& argRecord,
  472. DWORD dwAttributeIdx,
  473. PADS_ATTR_INFO* ppAttr);
  474. HRESULT DisableAccount(PCWSTR pszDN,
  475. const CDSCmdBasePathsInfo& refBasePathsInfo,
  476. const CDSCmdCredentialObject& refCredentialObject,
  477. const PDSOBJECTTABLEENTRY pObjectEntry,
  478. const ARG_RECORD& argRecord,
  479. DWORD dwAttributeIdx,
  480. PADS_ATTR_INFO* ppAttr);
  481. HRESULT SetMustChangePwd(PCWSTR pszDN,
  482. const CDSCmdBasePathsInfo& refBasePathsInfo,
  483. const CDSCmdCredentialObject& refCredentialObject,
  484. const PDSOBJECTTABLEENTRY pObjectEntry,
  485. const ARG_RECORD& argRecord,
  486. DWORD dwAttributeIdx,
  487. PADS_ATTR_INFO* ppAttr);
  488. HRESULT ChangeMustChangePwd(PCWSTR pszDN,
  489. const CDSCmdBasePathsInfo& refBasePathsInfo,
  490. const CDSCmdCredentialObject& refCredentialObject,
  491. const PDSOBJECTTABLEENTRY pObjectEntry,
  492. const ARG_RECORD& argRecord,
  493. DWORD dwAttributeIdx,
  494. PADS_ATTR_INFO* ppAttr);
  495. HRESULT PwdNeverExpires(PCWSTR pszDN,
  496. const CDSCmdBasePathsInfo& refBasePathsInfo,
  497. const CDSCmdCredentialObject& refCredentialObject,
  498. const PDSOBJECTTABLEENTRY pObjectEntry,
  499. const ARG_RECORD& argRecord,
  500. DWORD dwAttributeIdx,
  501. PADS_ATTR_INFO* ppAttr);
  502. HRESULT ReversiblePwd(PCWSTR pszDN,
  503. const CDSCmdBasePathsInfo& refBasePathsInfo,
  504. const CDSCmdCredentialObject& refCredentialObject,
  505. const PDSOBJECTTABLEENTRY pObjectEntry,
  506. const ARG_RECORD& argRecord,
  507. DWORD dwAttributeIdx,
  508. PADS_ATTR_INFO* ppAttr);
  509. HRESULT AccountExpires(PCWSTR pszDN,
  510. const CDSCmdBasePathsInfo& refBasePathsInfo,
  511. const CDSCmdCredentialObject& refCredentialObject,
  512. const PDSOBJECTTABLEENTRY pObjectEntry,
  513. const ARG_RECORD& argRecord,
  514. DWORD dwAttributeIdx,
  515. PADS_ATTR_INFO* ppAttr);
  516. HRESULT SetCanChangePassword(PCWSTR pszDN,
  517. const CDSCmdBasePathsInfo& refBasePathsInfo,
  518. const CDSCmdCredentialObject& refCredentialObject,
  519. const PDSOBJECTTABLEENTRY pObjectEntry,
  520. const ARG_RECORD& argRecord,
  521. DWORD dwAttributeIdx,
  522. PADS_ATTR_INFO* ppAttr);
  523. HRESULT ChangeCanChangePassword(PCWSTR pszDN,
  524. const CDSCmdBasePathsInfo& refBasePathsInfo,
  525. const CDSCmdCredentialObject& refCredentialObject,
  526. const PDSOBJECTTABLEENTRY pObjectEntry,
  527. const ARG_RECORD& argRecord,
  528. DWORD dwAttributeIdx,
  529. PADS_ATTR_INFO* ppAttr);
  530. HRESULT SetGroupScope(PCWSTR pszDN,
  531. const CDSCmdBasePathsInfo& refBasePathsInfo,
  532. const CDSCmdCredentialObject& refCredentialObject,
  533. const PDSOBJECTTABLEENTRY pObjectEntry,
  534. const ARG_RECORD& argRecord,
  535. DWORD dwAttributeIdx,
  536. PADS_ATTR_INFO* ppAttr);
  537. HRESULT ChangeGroupScope(PCWSTR pszDN,
  538. const CDSCmdBasePathsInfo& refBasePathsInfo,
  539. const CDSCmdCredentialObject& refCredentialObject,
  540. const PDSOBJECTTABLEENTRY pObjectEntry,
  541. const ARG_RECORD& argRecord,
  542. DWORD dwAttributeIdx,
  543. PADS_ATTR_INFO* ppAttr);
  544. HRESULT SetGroupSecurity(PCWSTR pszDN,
  545. const CDSCmdBasePathsInfo& refBasePathsInfo,
  546. const CDSCmdCredentialObject& refCredentialObject,
  547. const PDSOBJECTTABLEENTRY pObjectEntry,
  548. const ARG_RECORD& argRecord,
  549. DWORD dwAttributeIdx,
  550. PADS_ATTR_INFO* ppAttr);
  551. HRESULT ChangeGroupSecurity(PCWSTR pszDN,
  552. const CDSCmdBasePathsInfo& refBasePathsInfo,
  553. const CDSCmdCredentialObject& refCredentialObject,
  554. const PDSOBJECTTABLEENTRY pObjectEntry,
  555. const ARG_RECORD& argRecord,
  556. DWORD dwAttributeIdx,
  557. PADS_ATTR_INFO* ppAttr);
  558. HRESULT ModifyGroupMembers(PCWSTR pszDN,
  559. const CDSCmdBasePathsInfo& refBasePathsInfo,
  560. const CDSCmdCredentialObject& refCredentialObject,
  561. const PDSOBJECTTABLEENTRY pObjectEntry,
  562. const ARG_RECORD& argRecord,
  563. DWORD dwAttributeIdx,
  564. PADS_ATTR_INFO* ppAttr);
  565. HRESULT RemoveGroupMembers(PCWSTR pszDN,
  566. const CDSCmdBasePathsInfo& refBasePathsInfo,
  567. const CDSCmdCredentialObject& refCredentialObject,
  568. const PDSOBJECTTABLEENTRY pObjectEntry,
  569. const ARG_RECORD& argRecord,
  570. DWORD dwAttributeIdx,
  571. PADS_ATTR_INFO* ppAttr);
  572. HRESULT MakeMemberOf(PCWSTR pszDN,
  573. const CDSCmdBasePathsInfo& refBasePathsInfo,
  574. const CDSCmdCredentialObject& refCredentialObject,
  575. const PDSOBJECTTABLEENTRY pObjectEntry,
  576. const ARG_RECORD& argRecord,
  577. DWORD dwAttributeIdx,
  578. PADS_ATTR_INFO* ppAttr);
  579. HRESULT BuildComputerSAMName(PCWSTR pszDN,
  580. const CDSCmdBasePathsInfo& refBasePathsInfo,
  581. const CDSCmdCredentialObject& refCredentialObject,
  582. const PDSOBJECTTABLEENTRY pObjectEntry,
  583. const ARG_RECORD& argRecord,
  584. DWORD dwAttributeIdx,
  585. PADS_ATTR_INFO* ppAttr);
  586. HRESULT BuildGroupSAMName(PCWSTR pszDN,
  587. const CDSCmdBasePathsInfo& refBasePathsInfo,
  588. const CDSCmdCredentialObject& refCredentialObject,
  589. const PDSOBJECTTABLEENTRY pObjectEntry,
  590. const ARG_RECORD& argRecord,
  591. DWORD dwAttributeIdx,
  592. PADS_ATTR_INFO* ppAttr);
  593. HRESULT BuildUserSAMName(PCWSTR pszDN,
  594. const CDSCmdBasePathsInfo& refBasePathsInfo,
  595. const CDSCmdCredentialObject& refCredentialObject,
  596. const PDSOBJECTTABLEENTRY pObjectEntry,
  597. const ARG_RECORD& argRecord,
  598. DWORD dwAttributeIdx,
  599. PADS_ATTR_INFO* ppAttr);
  600. HRESULT FillAttrInfoFromObjectEntryExpandUsername(PCWSTR pszDN,
  601. const CDSCmdBasePathsInfo& refBasePathsInfo,
  602. const CDSCmdCredentialObject& refCredentialObject,
  603. const PDSOBJECTTABLEENTRY pObjectEntry,
  604. const ARG_RECORD& argRecord,
  605. DWORD dwAttributeIdx,
  606. PADS_ATTR_INFO* ppAttr);
  607. HRESULT SetComputerAccountType(PCWSTR pszDN,
  608. const CDSCmdBasePathsInfo& refBasePathsInfo,
  609. const CDSCmdCredentialObject& refCredentialObject,
  610. const PDSOBJECTTABLEENTRY pObjectEntry,
  611. const ARG_RECORD& argRecord,
  612. DWORD dwAttributeIdx,
  613. PADS_ATTR_INFO* ppAttr);
  614. HRESULT SetIsGC(PCWSTR pszDN,
  615. const CDSCmdBasePathsInfo& refBasePathsInfo,
  616. const CDSCmdCredentialObject& refCredentialObject,
  617. const PDSOBJECTTABLEENTRY pObjectEntry,
  618. const ARG_RECORD& argRecord,
  619. DWORD dwAttributeIdx,
  620. PADS_ATTR_INFO* ppAttr);
  621. HRESULT SetAccountEntry(PCWSTR pszDN,
  622. const CDSCmdBasePathsInfo& refBasePathsInfo,
  623. const CDSCmdCredentialObject& refCredentialObject,
  624. const PDSOBJECTTABLEENTRY pObjectEntry,
  625. const ARG_RECORD& argRecord,
  626. DWORD dwAttributeIdx,
  627. PADS_ATTR_INFO* ppAttr);
  628. //+--------------------------------------------------------------------------
  629. //
  630. // Function: EvaluateMustChangePassword
  631. //
  632. // Synopsis:
  633. //
  634. // Arguments: [pszDN - IN] : DN of the object to check
  635. // [refBasePathsInfo - IN] : reference to the base paths info
  636. // [refCredentialObject - IN] : reference to the credential manangement object
  637. // [bMustChangePassword - OUT] : true if the user must change their
  638. // password at next logon, false otherwise
  639. //
  640. // Returns: HRESULT : S_OK if everything succeeded
  641. // Otherwise an ADSI failure code
  642. //
  643. // History: 27-Oct-2000 JeffJon Created
  644. //
  645. //---------------------------------------------------------------------------
  646. HRESULT EvaluateMustChangePassword(PCWSTR pszDN,
  647. const CDSCmdBasePathsInfo& refBasePathsInfo,
  648. const CDSCmdCredentialObject& refCredentialObject,
  649. bool& bMustChangePassword);
  650. //+--------------------------------------------------------------------------
  651. //
  652. // Function: EvaluateCanChangePasswordAces
  653. //
  654. // Synopsis: Looks for explicit entries in the ACL to see if the user can
  655. // change their password
  656. //
  657. // Arguments: [pszDN - IN] : DN of the object to check
  658. // [refBasePathsInfo - IN] : reference to the base paths info
  659. // [refCredentialObject - IN] : reference to the credential manangement object
  660. // [bCanChangePassword - OUT] : false if there are explicit entries
  661. // that keep the user from changing their
  662. // password. true otherwise.
  663. //
  664. // Returns: HRESULT : S_OK if everything succeeded
  665. // Otherwise an ADSI failure code
  666. //
  667. // History: 27-Oct-2000 JeffJon Created
  668. //
  669. //---------------------------------------------------------------------------
  670. HRESULT EvaluateCanChangePasswordAces(PCWSTR pszDN,
  671. const CDSCmdBasePathsInfo& refBasePathsInfo,
  672. const CDSCmdCredentialObject& refCredentialObject,
  673. bool& bCanChangePassword);
  674. //+--------------------------------------------------------------------------
  675. //
  676. // Enumeration: FSMO_TYPE
  677. //
  678. // Synopsis: The types of FSMO owners
  679. //
  680. //---------------------------------------------------------------------------
  681. enum FSMO_TYPE
  682. {
  683. SCHEMA_FSMO,
  684. RID_POOL_FSMO,
  685. PDC_FSMO,
  686. INFRASTUCTURE_FSMO,
  687. DOMAIN_NAMING_FSMO,
  688. };
  689. //+--------------------------------------------------------------------------
  690. //
  691. // Function: BindToFSMOHolder
  692. //
  693. // Synopsis: Binds to the appropriate object which can be used to find a
  694. // particular FSMO owner
  695. //
  696. // Arguments: [refBasePathsInfo - IN] : reference to the base paths info object
  697. // [refCredObject - IN] : reference to the credential management object
  698. // [fsmoType - IN] : type of the FSMO we are searching for
  699. // [refspIADs - OUT] : interface to the object that will be
  700. // used to start a search for the FSMO owner
  701. //
  702. // Returns: HRESULT : S_OK if everything succeeded
  703. // Otherwise an ADSI failure code
  704. //
  705. // History: 13-Dec-2000 JeffJon Created
  706. //
  707. //---------------------------------------------------------------------------
  708. HRESULT BindToFSMOHolder(IN const CDSCmdBasePathsInfo& refBasePathsInfo,
  709. IN const CDSCmdCredentialObject& refCredObject,
  710. IN FSMO_TYPE fsmoType,
  711. OUT CComPtr<IADs>& refspIADs);
  712. //+--------------------------------------------------------------------------
  713. //
  714. // Function: FindFSMOOwner
  715. //
  716. // Synopsis:
  717. //
  718. // Arguments: [refBasePathsInfo - IN] : reference to the base paths info object
  719. // [refCredObject - IN] : reference to the credential management object
  720. // [fsmoType - IN] : type of the FSMO we are searching for
  721. // [refspIADs - OUT] : interface to the object that will be
  722. // used to start a search for the FSMO owner
  723. //
  724. // Returns: HRESULT : S_OK if everything succeeded
  725. // Otherwise an ADSI failure code
  726. //
  727. // History: 13-Dec-2000 JeffJon Created
  728. //
  729. //---------------------------------------------------------------------------
  730. HRESULT FindFSMOOwner(IN const CDSCmdBasePathsInfo& refBasePathsInfo,
  731. IN const CDSCmdCredentialObject& refCredObject,
  732. IN FSMO_TYPE fsmoType,
  733. OUT CComBSTR& refsbstrServer);
  734. //+--------------------------------------------------------------------------
  735. //
  736. // Function: ValidateAndModifySAMName
  737. //
  738. // Synopsis: Looks for any illegal characters in the SamAccountName and
  739. // converts them to the replacementChar
  740. //
  741. // Arguments: [pszSAMName - IN/OUT] : pointer to a string that contains the SamAccountName
  742. // illegal characters will be replaced
  743. // [pszInvalidChars - IN] : string containing the illegal characters
  744. //
  745. // Returns: HRESULT : S_OK if the name was valid and no characters had to be replaced
  746. // S_FALSE if the name contained invalid characters that were replaced
  747. // E_INVALIDARG
  748. //
  749. // History: 21-Feb-2001 JeffJon Created
  750. //
  751. //---------------------------------------------------------------------------
  752. #define INVALID_NETBIOS_AND_ACCOUNT_NAME_CHARS_WITH_AT ILLEGAL_FAT_CHARS L".@"
  753. HRESULT ValidateAndModifySAMName(PWSTR pszSAMName,
  754. PCWSTR pszInvalidChars);
  755. //+--------------------------------------------------------------------------
  756. //
  757. // Class: GetOutputDN
  758. //
  759. // Purpose: Converts an ADSI-escaped DN to one with DSCMD input escaping.
  760. // This way, the output DN can be piped as input to another
  761. // DSCMD command.
  762. //
  763. // History: 08-May-2001 JonN Created
  764. //
  765. //---------------------------------------------------------------------------
  766. HRESULT GetOutputDN( OUT BSTR* pbstrOut, IN PCWSTR pszIn );
  767. //+--------------------------------------------------------------------------
  768. //
  769. // Class: ValidateDNSyntax
  770. //
  771. // Purpose: Validates each string in the null separated list as having
  772. // DN syntax
  773. //
  774. // Returns: The count of valid DNs in the list
  775. //
  776. // History: 12-Oct-2001 JeffJon Created
  777. //
  778. //---------------------------------------------------------------------------
  779. UINT ValidateDNSyntax(IN PWSTR* ppszArray, UINT nStrings);
  780. //+--------------------------------------------------------------------------
  781. //
  782. // Function: IsServerGC
  783. //
  784. // Purpose: Checks if server is Global Catalog
  785. //
  786. // Returns: TRUE if GC else flase
  787. //
  788. // History: 05-Jan-2002 hiteshr Created
  789. //
  790. //---------------------------------------------------------------------------
  791. BOOL
  792. IsServerGC(LPCWSTR pszServerName,
  793. CDSCmdCredentialObject& refCredentialObject);
  794. //+--------------------------------------------------------------------------
  795. //
  796. // Function: GetQuotedDN
  797. //
  798. // Purpose: Takes the give DN and surrounds it with quotes
  799. //
  800. // Returns: the quoted DN
  801. //
  802. // History: 10-Oct-2002 jeffjon Created
  803. //
  804. //---------------------------------------------------------------------------
  805. CComBSTR GetQuotedDN(PWSTR pszDN);
  806. //+--------------------------------------------------------------------------
  807. //
  808. // Function: ConvertTrusteeToDN
  809. //
  810. // Synopsis: Get the DN for an -acct param
  811. //
  812. // Arguments: [lpszDomain - IN]: Domain to query or NULL for local
  813. // [lpszTrustee - IN]: Acct to resolve
  814. // [lpszDN - OUT]: Returns the DN. Use LocalFree when done
  815. //
  816. // Returns: HRESULT : S_OK if everything succeeded
  817. // E_INVALIDARG for invalid input
  818. // Anything else is a failure code from an ADSI call
  819. //
  820. // History: 20-Aug-2002 RonMart Created
  821. //
  822. //---------------------------------------------------------------------------
  823. HRESULT ConvertTrusteeToDN(LPCWSTR lpszDomain, LPCWSTR lpszTrustee,
  824. LPWSTR* lpszDN);
  825. //+--------------------------------------------------------------------------
  826. //
  827. // Function: GetDNSid
  828. //
  829. // Synopsis: Given a DN the objecSid value will be retrieved and returned
  830. // as a SID
  831. //
  832. // Arguments: [lpszDN - IN]: DN to query
  833. // [refBasePathsInfo - IN]: LDAP settings
  834. // [refCredentialObject - IN]: Credentials to use for the query
  835. // [pSid - OUT]: A SID if successful. Call LocalFree
  836. // when done.
  837. //
  838. // Returns: HRESULT : S_OK if everything succeeded
  839. // E_INVALIDARG for invalid input
  840. // Anything else is a failure code from an ADSI call
  841. //
  842. // History: 20-Aug-2002 RonMart Created
  843. //
  844. //---------------------------------------------------------------------------
  845. HRESULT GetDNSid(LPCTSTR lpszDN,
  846. const CDSCmdBasePathsInfo& refBasePathsInfo,
  847. const CDSCmdCredentialObject& refCredentialObject,
  848. PSID* pSid);
  849. //+--------------------------------------------------------------------------
  850. //
  851. // Function: GetQuotaContainerDN
  852. //
  853. // Synopsis: Takes the partition dn and merges it with the NTDS Quotas
  854. // string (from wellKnownObjects GUID)
  855. //
  856. // Arguments: [basePathsInfo - IN]:
  857. // [credentialObject - IN]: Creditials object used for
  858. // binding to other objects
  859. // [lpszPartitionDN - IN]: The partition to bind to
  860. // [pszNewDN - OUT]: The munged quotas DN to return
  861. //
  862. // Returns: HRESULT : S_OK if everything succeeded
  863. // E_UNEXPECTED in most failure cases
  864. // E_OUTOFMEMORY if a LocalAlloc fails
  865. // Anything else is a failure code from an ADSI call
  866. //
  867. // History: 05-Aug-2002 RonMart Created
  868. //
  869. //---------------------------------------------------------------------------
  870. HRESULT GetQuotaContainerDN(IN CDSCmdBasePathsInfo& basePathsInfo,
  871. IN const CDSCmdCredentialObject& credentialObject,
  872. IN LPCWSTR lpszPartitionDN,
  873. OUT PWSTR* pszNewDN);
  874. //+--------------------------------------------------------------------------
  875. //
  876. // Function: ConvertTrusteeToNT4Name
  877. //
  878. // Synopsis: Get the DN for an -acct param
  879. //
  880. // Arguments: [lpszDomain - IN]: Domain to query or NULL for local
  881. // [lpszTrustee - IN]: Acct to resolve
  882. // [lpszNT4 - OUT]: Returns the NT4 name.
  883. // Use LocalFree when done
  884. //
  885. // Returns: HRESULT : S_OK if everything succeeded
  886. // E_INVALIDARG for invalid input
  887. // Anything else is a failure code from an ADSI call
  888. //
  889. // History: 20-Aug-2002 RonMart Created
  890. //
  891. //---------------------------------------------------------------------------
  892. HRESULT ConvertTrusteeToNT4Name(LPCWSTR lpszDomain, LPCWSTR lpszTrustee,
  893. LPWSTR* lpszNT4);
  894. #endif //_DSUTIL_H_