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.

517 lines
14 KiB

  1. /*****************************************************************/
  2. /** Microsoft Windows NT **/
  3. /** Copyright(c) Microsoft Corp., 1992 **/
  4. /*****************************************************************/
  5. /*
  6. * History:
  7. * JonN 13-Mar-1992 Split from lmoeusr.hxx
  8. * JonN 01-Apr-1992 NT enumerator CR changes, attended by
  9. * JimH, JohnL, KeithMo, JonN, ThomasPa
  10. * JonN 27-Jan-1994 Added group enumerator
  11. *
  12. */
  13. #ifndef _LMOENT_HXX_
  14. #define _LMOENT_HXX_
  15. #ifndef WIN32
  16. #error NT enumerator requires WIN32!
  17. #endif // WIN32
  18. #include "lmoersm.hxx"
  19. #include "uintsam.hxx"
  20. /*************************************************************************
  21. NAME: NT_ACCOUNT_ENUM
  22. SYNOPSIS: NT_ACCOUNT_ENUM is a special user enumerator available
  23. only from NT clients to NT servers. It is resumeable
  24. and has special features such as indexed access.
  25. It also guarantees that users will be returned
  26. in alphabetical order by username.
  27. INTERFACE: NT_ACCOUNT_ENUM - Class constructor.
  28. CallAPI - Invokes the enumeration API.
  29. PARENT: LM_RESUME_ENUM
  30. USES: None.
  31. CAVEATS:
  32. NOTES: The SAM_DOMAIN passed to the NT_ACCOUNT_ENUM constructor
  33. should not be deleted or modified until the
  34. NT_ACCOUNT_ENUM is deleted.
  35. HISTORY:
  36. JonN 29-Jan-1992 Templated from FILE_ENUM
  37. KeithMo 18-Mar-1992 FreeBuffer now takes BYTE **.
  38. **************************************************************************/
  39. DLL_CLASS NT_ACCOUNT_ENUM : public LM_RESUME_ENUM
  40. {
  41. private:
  42. //
  43. // The SamQueryDisplayInformation() resume key.
  44. //
  45. ULONG _ulIndex;
  46. //
  47. // The enumeration will take place on this domain. Do not delete
  48. // or change the SAM_DOMAIN until this object is deleted.
  49. //
  50. const SAM_DOMAIN * _psamdomain;
  51. //
  52. // Number of calls to CallAPI so far
  53. //
  54. INT _nCalls;
  55. //
  56. // Number of milliseconds required by the last API call
  57. //
  58. ULONG _msTimeLastCall;
  59. //
  60. // number of entries/bytes requested on the last call
  61. //
  62. ULONG _cEntriesRequested;
  63. ULONG _cbBytesRequested;
  64. //
  65. // This virtual callback invokes the SamQueryDisplayInformation() API.
  66. //
  67. virtual APIERR CallAPI( BOOL fRestartEnum,
  68. BYTE ** ppbBuffer,
  69. UINT * pcEntriesRead );
  70. protected:
  71. //
  72. // Usual constructor/destructor goodies.
  73. //
  74. NT_ACCOUNT_ENUM( const SAM_DOMAIN * psamdomain,
  75. enum _DOMAIN_DISPLAY_INFORMATION dinfo,
  76. BOOL fKeepBuffers = FALSE );
  77. ~NT_ACCOUNT_ENUM();
  78. //
  79. // Destroy the buffer with ::SamFreeMemory().
  80. //
  81. virtual VOID FreeBuffer( BYTE ** ppbBuffer );
  82. //
  83. // Determine how many entries and bytes to request in CallAPI
  84. //
  85. virtual APIERR QueryCountPreferences(
  86. ULONG * pcEntriesRequested, // how many entries to request on this call
  87. ULONG * pcbBytesRequested, // how many bytes to request on this call
  88. UINT nNthCall, // 0 just before 1st call, 1 before 2nd call, etc.
  89. ULONG cLastEntriesRequested, // how many entries requested on last call
  90. // ignore for nNthCall==0
  91. ULONG cbLastBytesRequested, // how many bytes requested on last call
  92. // ignore for nNthCall==0
  93. ULONG msTimeLastCall ); // how many milliseconds last call took
  94. //
  95. // Call through to this QueryCountPreferences to get default
  96. // behavior which tracks the time taken by each call and adjusts
  97. // the EntriesRequested and BytesRequested accordingly.
  98. //
  99. static APIERR QueryCountPreferences2(
  100. ULONG * pcEntriesRequested,
  101. ULONG * pcbBytesRequested,
  102. UINT nNthCall,
  103. ULONG cLastEntriesRequested,
  104. ULONG cbLastBytesRequested,
  105. ULONG msTimeLastCall );
  106. #ifndef UNICODE
  107. //
  108. // BUGBUG Temporary hack until UNICODE switch pulled
  109. // This method will map the enumeration buffer's UNICODE
  110. // strings to ASCII strings _in_place_.
  111. //
  112. virtual VOID FixupUnicodeStrings( BYTE * pbBuffer,
  113. UINT cEntries ) = 0;
  114. #endif // UNICODE
  115. }; // class NT_ACCOUNT_ENUM
  116. DLL_CLASS NT_USER_ITER; // Forward reference.
  117. /*************************************************************************
  118. NAME: NT_USER_ENUM
  119. SYNOPSIS: NT_USER_ENUM is an enumerator for enumerating the
  120. users on a domain. It can fetch a number of items
  121. of information beyond just the username and RID.
  122. INTERFACE: NT_USER_ENUM - Class constructor.
  123. PARENT: NT_ACCOUNT_ENUM
  124. HISTORY:
  125. JonN 29-Jan-1992 Templated from NT_ACCOUNT_ENUM
  126. **************************************************************************/
  127. DLL_CLASS NT_USER_ENUM : public NT_ACCOUNT_ENUM
  128. {
  129. protected:
  130. #ifndef UNICODE
  131. //
  132. // This method will map the enumeration buffer's UNICODE
  133. // strings to ASCII strings _in_place_.
  134. //
  135. virtual VOID FixupUnicodeStrings( BYTE * pbBuffer,
  136. UINT cEntries );
  137. #endif
  138. public:
  139. NT_USER_ENUM( const SAM_DOMAIN * psamdomain );
  140. ~NT_USER_ENUM();
  141. }; // class NT_USER_ENUM
  142. /*************************************************************************
  143. NAME: NT_USER_ENUM_OBJ
  144. SYNOPSIS: This is basically the return type from the NT_USER_ENUM_ITER
  145. iterator.
  146. INTERFACE: QueryUsername - Returns the username.
  147. QueryFullName - Returns the fullname.
  148. QueryComment - Returns the "admin" comment.
  149. QueryFlags - Returns the flags.
  150. QueryUserID - Returns the user ID (RID).
  151. PARENT: ENUM_OBJ_BASE
  152. HISTORY:
  153. JonN 29-Jan-1992 Templated from NT_ACCOUNT_ENUM
  154. KeithMo 25-Mar-1992 Added QueryUsernameLen(),
  155. QueryFullNameLen(), and QueryCommentLen().
  156. **************************************************************************/
  157. DLL_CLASS NT_USER_ENUM_OBJ : public ENUM_OBJ_BASE
  158. {
  159. public:
  160. //
  161. // Provide properly-casted buffer Query/Set methods.
  162. //
  163. const DOMAIN_DISPLAY_USER * QueryBufferPtr( VOID ) const
  164. { return (const DOMAIN_DISPLAY_USER *)ENUM_OBJ_BASE::QueryBufferPtr(); }
  165. VOID SetBufferPtr( const DOMAIN_DISPLAY_USER * pBuffer )
  166. { ENUM_OBJ_BASE::SetBufferPtr( (const BYTE *)pBuffer ); }
  167. //
  168. // Accessors.
  169. //
  170. const UNICODE_STRING * QueryUnicodeUsername() const
  171. { return &(QueryBufferPtr()->LogonName); }
  172. const UNICODE_STRING * QueryUnicodeFullName() const
  173. { return &(QueryBufferPtr()->FullName); }
  174. const UNICODE_STRING * QueryUnicodeComment() const
  175. { return &(QueryBufferPtr()->AdminComment); }
  176. APIERR QueryUsername( NLS_STR * pnls ) const
  177. {
  178. ASSERT(pnls!=NULL);
  179. return pnls->MapCopyFrom( QueryUnicodeUsername()->Buffer,
  180. QueryUnicodeUsername()->Length );
  181. }
  182. APIERR QueryFullName( NLS_STR * pnls ) const
  183. {
  184. ASSERT(pnls!=NULL);
  185. return pnls->MapCopyFrom( QueryUnicodeFullName()->Buffer,
  186. QueryUnicodeFullName()->Length );
  187. }
  188. APIERR QueryComment( NLS_STR * pnls ) const
  189. {
  190. ASSERT(pnls!=NULL);
  191. return pnls->MapCopyFrom( QueryUnicodeComment()->Buffer,
  192. QueryUnicodeComment()->Length );
  193. }
  194. DECLARE_ENUM_ACCESSOR( QueryFlags, ULONG, AccountControl );
  195. DECLARE_ENUM_ACCESSOR( QueryUserID, ULONG, Rid );
  196. }; // class NT_USER_ENUM_OBJ
  197. DECLARE_LM_RESUME_ENUM_ITER_OF( NT_USER, DOMAIN_DISPLAY_USER );
  198. DLL_CLASS NT_MACHINE_ITER; // Forward reference.
  199. /*************************************************************************
  200. NAME: NT_MACHINE_ENUM
  201. SYNOPSIS: NT_MACHINE_ENUM is an enumerator for enumerating the
  202. machines on a domain. It can fetch a number of items
  203. of information beyond just the machine name and RID.
  204. INTERFACE: NT_MACHINE_ENUM - Class constructor.
  205. PARENT: NT_ACCOUNT_ENUM
  206. HISTORY:
  207. KeithMo 16-Mar-1992 Created for the Server Manager.
  208. **************************************************************************/
  209. DLL_CLASS NT_MACHINE_ENUM : public NT_ACCOUNT_ENUM
  210. {
  211. protected:
  212. #ifndef UNICODE
  213. //
  214. // This method will map the enumeration buffer's UNICODE
  215. // strings to ASCII strings _in_place_.
  216. //
  217. virtual VOID FixupUnicodeStrings( BYTE * pbBuffer,
  218. UINT cEntries );
  219. #endif
  220. public:
  221. NT_MACHINE_ENUM( const SAM_DOMAIN * psamdomain );
  222. ~NT_MACHINE_ENUM();
  223. }; // class NT_MACHINE_ENUM
  224. /*************************************************************************
  225. NAME: NT_MACHINE_ENUM_OBJ
  226. SYNOPSIS: This is basically the return type from the
  227. NT_MACHINE_ENUM_ITER iterator.
  228. INTERFACE: QueryMachine - Returns the machine name.
  229. QueryComment - Returns the comment.
  230. QueryAccountCtrl - Returns the account control flags.
  231. QueryRID - Returns the RID for this machine.
  232. QueryIndex - Returns the enumeration index.
  233. PARENT: ENUM_OBJ_BASE
  234. HISTORY:
  235. KeithMo 16-Mar-1992 Created for the Server Manager.
  236. KeithMo 25-Mar-1992 Added QueryNameLen() & QueryCommentLen().
  237. **************************************************************************/
  238. DLL_CLASS NT_MACHINE_ENUM_OBJ : public ENUM_OBJ_BASE
  239. {
  240. public:
  241. //
  242. // Provide properly-casted buffer Query/Set methods.
  243. //
  244. const DOMAIN_DISPLAY_MACHINE * QueryBufferPtr( VOID ) const
  245. { return (const DOMAIN_DISPLAY_MACHINE *)ENUM_OBJ_BASE::QueryBufferPtr(); }
  246. VOID SetBufferPtr( const DOMAIN_DISPLAY_MACHINE * pBuffer )
  247. { ENUM_OBJ_BASE::SetBufferPtr( (const BYTE *)pBuffer ); }
  248. //
  249. // Accessors.
  250. //
  251. const UNICODE_STRING * QueryUnicodeMachine() const
  252. { return &(QueryBufferPtr()->Machine); }
  253. const UNICODE_STRING * QueryUnicodeComment() const
  254. { return &(QueryBufferPtr()->Comment); }
  255. APIERR QueryMachine( NLS_STR * pnls ) const
  256. {
  257. ASSERT(pnls!=NULL);
  258. return pnls->MapCopyFrom( QueryUnicodeMachine()->Buffer,
  259. QueryUnicodeMachine()->Length );
  260. }
  261. APIERR QueryComment( NLS_STR * pnls ) const
  262. {
  263. ASSERT(pnls!=NULL);
  264. return pnls->MapCopyFrom( QueryUnicodeComment()->Buffer,
  265. QueryUnicodeComment()->Length );
  266. }
  267. DECLARE_ENUM_ACCESSOR( QueryAccountCtrl, UINT, AccountControl );
  268. DECLARE_ENUM_ACCESSOR( QueryRID, UINT, Rid );
  269. DECLARE_ENUM_ACCESSOR( QueryIndex, UINT, Index );
  270. }; // class NT_MACHINE_ENUM_OBJ
  271. DECLARE_LM_RESUME_ENUM_ITER_OF( NT_MACHINE, DOMAIN_DISPLAY_MACHINE );
  272. /*************************************************************************
  273. NAME: NT_GROUP_ENUM
  274. SYNOPSIS: NT_GROUP_ENUM is an enumerator for enumerating the
  275. groups on a domain. It can fetch a number of items
  276. of information beyond just the group name and RID.
  277. INTERFACE: NT_GROUP_ENUM - Class constructor.
  278. PARENT: NT_ACCOUNT_ENUM
  279. HISTORY:
  280. JonN 27-Jan-1994 Templated from NT_MACHINE_ENUM
  281. **************************************************************************/
  282. DLL_CLASS NT_GROUP_ENUM : public NT_ACCOUNT_ENUM
  283. {
  284. protected:
  285. #ifndef UNICODE
  286. //
  287. // This method will map the enumeration buffer's UNICODE
  288. // strings to ASCII strings _in_place_.
  289. //
  290. virtual VOID FixupUnicodeStrings( BYTE * pbBuffer,
  291. UINT cEntries );
  292. #endif
  293. public:
  294. NT_GROUP_ENUM( const SAM_DOMAIN * psamdomain );
  295. ~NT_GROUP_ENUM();
  296. }; // class NT_GROUP_ENUM
  297. /*************************************************************************
  298. NAME: NT_GROUP_ENUM_OBJ
  299. SYNOPSIS: This is basically the return type from the
  300. NT_GROUP_ENUM_ITER iterator.
  301. INTERFACE: QueryGroup - Returns the group name.
  302. QueryComment - Returns the comment.
  303. QueryRID - Returns the RID for this group.
  304. QueryIndex - Returns the enumeration index.
  305. QueryAttributes - Returns the attributes.
  306. PARENT: ENUM_OBJ_BASE
  307. HISTORY:
  308. JonN 27-Jan-1994 Templated from NT_MACHINE_ENUM
  309. **************************************************************************/
  310. DLL_CLASS NT_GROUP_ENUM_OBJ : public ENUM_OBJ_BASE
  311. {
  312. public:
  313. //
  314. // Provide properly-casted buffer Query/Set methods.
  315. //
  316. const DOMAIN_DISPLAY_GROUP * QueryBufferPtr( VOID ) const
  317. { return (const DOMAIN_DISPLAY_GROUP *)ENUM_OBJ_BASE::QueryBufferPtr(); }
  318. VOID SetBufferPtr( const DOMAIN_DISPLAY_GROUP * pBuffer )
  319. { ENUM_OBJ_BASE::SetBufferPtr( (const BYTE *)pBuffer ); }
  320. //
  321. // Accessors.
  322. //
  323. const UNICODE_STRING * QueryUnicodeGroup() const
  324. { return &(QueryBufferPtr()->Group); }
  325. const UNICODE_STRING * QueryUnicodeComment() const
  326. { return &(QueryBufferPtr()->Comment); }
  327. APIERR QueryGroup( NLS_STR * pnls ) const
  328. {
  329. ASSERT(pnls!=NULL);
  330. return pnls->MapCopyFrom( QueryUnicodeGroup()->Buffer,
  331. QueryUnicodeGroup()->Length );
  332. }
  333. APIERR QueryComment( NLS_STR * pnls ) const
  334. {
  335. ASSERT(pnls!=NULL);
  336. return pnls->MapCopyFrom( QueryUnicodeComment()->Buffer,
  337. QueryUnicodeComment()->Length );
  338. }
  339. DECLARE_ENUM_ACCESSOR( QueryIndex, UINT, Index );
  340. DECLARE_ENUM_ACCESSOR( QueryRID, UINT, Rid );
  341. DECLARE_ENUM_ACCESSOR( QueryAttributes, UINT, Attributes );
  342. }; // class NT_GROUP_ENUM_OBJ
  343. DECLARE_LM_RESUME_ENUM_ITER_OF( NT_GROUP, DOMAIN_DISPLAY_GROUP );
  344. #endif // _LMOENT_HXX_