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.

541 lines
18 KiB

  1. /**********************************************************************/
  2. /** Microsoft LAN Manager **/
  3. /** Copyright(c) Microsoft Corp., 1990 **/
  4. /**********************************************************************/
  5. /*
  6. * History
  7. * gregj 4/16/91 Cloned from COMPUTER class
  8. * gregj 4/22/91 Added USER, USER_11.
  9. * gregj 4/29/91 Results of 4/29/91 code review
  10. * with chuckc, jimh, terryk, ericch
  11. * gregj 5/21/91 Use new LOCATION class
  12. * gregj 5/22/91 Support LOCATION's LOCATION_TYPE constructor
  13. * SimoP 6/13/91 GetInfo and WriteInfo in class USER
  14. * moved to public
  15. * jonn 7/19/91 Writable USER_11 object
  16. * jonn 8/06/91 Updated to latest NEW_LM_OBJ spec
  17. * jonn 8/12/91 Code review changes
  18. * rustanl 8/26/91 Changed [W_]CloneFrom parameter from * to &
  19. * jonn 8/29/91 Added ChangeToNew()
  20. * jonn 9/04/91 Added UserComment accessors
  21. * jonn 9/05/91 Added IsOKState() and IsConstructedState()
  22. * terryk 9/11/91 Add LOGON_USER object
  23. * jonn 9/17/91 Added Parms accessors
  24. * terryk 9/19/91 Move LOGON_USER back to lmomisc.hxx
  25. * terryk 10/07/91 type changes for NT
  26. * terryk 10/21/91 type changes for NT
  27. * jonn 11/01/91 Added parms filter
  28. * jonn 12/11/91 Added LogonHours accessors
  29. * thomaspa 1/21/92 Added Rename() to USER
  30. * beng 05/07/92 Removed LOGON_HOURS_SETTING elsewhere
  31. */
  32. #ifndef _LMOUSER_HXX_
  33. #define _LMOUSER_HXX_
  34. #include "lmobj.hxx"
  35. #include "lhourset.hxx"
  36. #include "uiassert.hxx"
  37. #if defined(UNICODE)
  38. #define UI_NULL_USERSETINFO_PASSWD SZ(" ")
  39. #else
  40. #define UI_NULL_USERSETINFO_PASSWD NULL_USERSETINFO_PASSWD
  41. #endif
  42. /*************************************************************************
  43. NAME: USER
  44. SYNOPSIS: Superclass for manipulation of users
  45. Will eventually support deletion of existing users
  46. INTERFACE:
  47. QueryName
  48. Returns the user's account name.
  49. Rename
  50. Changes the name of the user account on NT
  51. SetName
  52. Sets the user's account name.
  53. PARENT: LOC_LM_OBJ
  54. USES:
  55. CAVEATS:
  56. NOTES:
  57. HISTORY:
  58. gregj 4/22/91 Created
  59. gregj 4/29/91 Added ValidateAccount(), use BUFFER
  60. gregj 5/21/91 Use new LOCATION class
  61. gregj 5/22/91 Support LOCATION_TYPE constructor
  62. SimoP 6/13/91 GetInfo and WriteInfo in class USER
  63. moved public
  64. thomaspa 1/21/92 Added Rename()
  65. **************************************************************************/
  66. DLL_CLASS USER : public LOC_LM_OBJ
  67. {
  68. private:
  69. VOID CtAux( const TCHAR *pszAccount ); // constructor helper
  70. protected:
  71. DECL_CLASS_NLS_STR( _nlsAccount, UNLEN ); // account name, may be ""
  72. APIERR HandleNullAccount();
  73. APIERR W_CloneFrom( const USER & user );
  74. virtual APIERR I_Delete( UINT uiForce );
  75. public:
  76. USER(const TCHAR *pszAccount, const TCHAR *pszLocation = NULL);
  77. USER(const TCHAR *pszAccount, enum LOCATION_TYPE loctype);
  78. USER(const TCHAR *pszAccount, const LOCATION & loc);
  79. ~USER();
  80. const TCHAR *QueryName() const;
  81. APIERR Rename( const TCHAR *pszAccount );
  82. APIERR SetName( const TCHAR *pszAccount );
  83. };
  84. /*************************************************************************
  85. NAME: USER_11
  86. SYNOPSIS: Wrapper for User APIs, level 11
  87. USER_11 does not support WriteInfo or WriteNew, since
  88. the API does not support NetUserSetInfo[11] or
  89. NetUserAdd[11].
  90. Unlike USER_2, a non-admin without accounts privilege
  91. may read USER_11 information on him/herself.
  92. INTERFACE: Construct with account name and server/domain name
  93. I_GetInfo
  94. Retrieves info about the user, returns a standard
  95. error code.
  96. QueryPriv
  97. Returns the user's privilege level.
  98. QueryAuthFlags
  99. Returns the user's authorization flags mask.
  100. IsPrintOperator
  101. TRUE if the user is a print operator
  102. IsCommOperator
  103. TRUE if the user is a comm queue operator
  104. IsServerOperator
  105. TRUE if the user is a server operator
  106. IsAccountsOperator
  107. TRUE if the user is an accounts operator
  108. QueryComment
  109. Returns the comment set by administrator
  110. QueryUserComment
  111. Returns the comment set by user
  112. QueryFullName
  113. Returns the user's fullname
  114. QueryHomeDir
  115. Returns the user's home directory
  116. QueryParms
  117. Returns the user's application parameters
  118. QueryWorkstations
  119. Returns the user's valid logon workstations,
  120. wkstas are separated by " "
  121. QueryLogonHours
  122. Returns the user's logon hours setting
  123. QueryPasswordAge
  124. QueryLastLogon
  125. QueryLastLogoff
  126. QueryBadPWCount
  127. QueryNumLogons
  128. QueryLogonServer
  129. QueryCountryCode
  130. QueryMaxStorage
  131. QueryCodePage
  132. All currently unimplemented.
  133. SetComment
  134. SetUserComment
  135. SetFullName
  136. SetPriv
  137. SetAuthFlags
  138. SetHomeDir
  139. SetParms
  140. SetLogonHours
  141. Set information about the USER_11 object.
  142. Returns ERROR_GEN_FAILURE if USER_11 obj not valid
  143. ERROR_INVALID_PARAM if input param invalid
  144. NERR_Success if ok.
  145. TrimParams
  146. Like LM21 NIF, User Manager trims certain Dialin
  147. information out of the parms field when a user is
  148. cloned. This does not happen automatically on
  149. CloneFrom, instead the caller must call TrimParams
  150. explicitly.
  151. PARENT: USER
  152. USES: NLS_STR, LOGON_HOURS_SETTING
  153. CAVEATS: (internal) The fields which appear both as member objects
  154. and in the API buffer should be accessed only as member
  155. objects. The API buffer is not updated until
  156. WriteInfo/WriteNew. This allows subclasses to use the
  157. same accessors.
  158. NOTES: The IsXxxxOperator methods are wrappers around
  159. specific flags in the QueryAuthFlags() return.
  160. They will always be FALSE if the user is an
  161. administrator, since only USER privilege accounts
  162. need operator rights.
  163. HISTORY:
  164. gregj 4/22/91 Created
  165. gregj 4/29/91 Added unimplemented method placeholders
  166. gregj 5/22/91 Support LOCATION_TYPE constructor
  167. jonn 7/22/91 Writable
  168. jonn 9/17/91 Added parms
  169. **************************************************************************/
  170. /*
  171. NT BUGBUG: The following definition of MAX_USER_INFO_SIZE_11
  172. is not safe for NT. It should be moved to a global header file.
  173. */
  174. #define MAX_USER_INFO_SIZE_11 (sizeof(struct user_info_11) + \
  175. ((MAXCOMMENTSZ+1) * 4) + ((PATHLEN+1) * 2) + MAX_PATH+1 + \
  176. (8 * (MAX_PATH) + 1) )
  177. DLL_CLASS USER_11 : public USER
  178. {
  179. private:
  180. VOID CtAux(); // constructor helper
  181. UINT _uPriv;
  182. ULONG _flAuth;
  183. NLS_STR _nlsComment;
  184. NLS_STR _nlsUserComment;
  185. NLS_STR _nlsFullName;
  186. NLS_STR _nlsHomeDir;
  187. NLS_STR _nlsParms;
  188. NLS_STR _nlsWorkstations;
  189. LOGON_HOURS_SETTING _logonhrs;
  190. protected:
  191. APIERR W_CloneFrom( const USER_11 & user11 );
  192. virtual APIERR W_CreateNew();
  193. virtual APIERR I_GetInfo();
  194. public:
  195. USER_11(const TCHAR *pszAccount, const TCHAR *pszLocation = NULL);
  196. USER_11(const TCHAR *pszAccount, enum LOCATION_TYPE loctype);
  197. USER_11(const TCHAR *pszAccount, const LOCATION & loc);
  198. ~USER_11();
  199. // redefined in LOCAL_USER
  200. virtual UINT QueryPriv() const;
  201. virtual ULONG QueryAuthFlags() const;
  202. BOOL IsPrintOperator() const;
  203. BOOL IsCommOperator() const;
  204. BOOL IsServerOperator() const;
  205. BOOL IsAccountsOperator() const;
  206. inline const TCHAR *QueryComment () const
  207. { CHECK_OK(NULL); return _nlsComment.QueryPch(); }
  208. inline const TCHAR *QueryUserComment () const
  209. { CHECK_OK(NULL); return _nlsUserComment.QueryPch(); }
  210. inline const TCHAR *QueryFullName () const
  211. { CHECK_OK(NULL); return _nlsFullName.QueryPch(); }
  212. inline const TCHAR *QueryHomeDir () const
  213. { CHECK_OK(NULL); return _nlsHomeDir.QueryPch(); }
  214. inline const TCHAR *QueryParms () const
  215. { CHECK_OK(NULL); return _nlsParms.QueryPch(); }
  216. inline const TCHAR *QueryWorkstations () const
  217. { CHECK_OK(NULL); return _nlsWorkstations.QueryPch(); }
  218. inline const LOGON_HOURS_SETTING & QueryLogonHours () const
  219. { return _logonhrs; }
  220. // unimplemented
  221. inline LONG QueryPasswordAge() const { return 0L; }
  222. inline LONG QueryLastLogon() const { return 0L; }
  223. inline LONG QueryLastLogoff() const { return 0L; }
  224. inline UINT QueryBadPWCount() const { return 0; }
  225. inline UINT QueryNumLogons() const { return 0; }
  226. inline const TCHAR *QueryLogonServer () const { return NULL; }
  227. inline UINT QueryCountryCode() const { return 0; }
  228. inline LONG QueryMaxStorage() const { return 0L; }
  229. inline UINT QueryCodePage() const { return 0; }
  230. APIERR SetComment( const TCHAR *pszComment );
  231. APIERR SetUserComment( const TCHAR *pszUserComment );
  232. APIERR SetFullName( const TCHAR *pszFullName );
  233. APIERR SetPriv( UINT uPriv );
  234. APIERR SetAuthFlags( ULONG flAuth );
  235. APIERR SetHomeDir( const TCHAR *pszHomeDir );
  236. APIERR SetParms( const TCHAR *pszParms );
  237. APIERR SetWorkstations( const TCHAR *pszWorkstations );
  238. APIERR SetLogonHours( const UCHAR * pLogonHours = NULL,
  239. UINT unitsperweek = LOGON_HOURS_SETTING::cHoursPerWeek );
  240. APIERR SetLogonHours( const LOGON_HOURS_SETTING & logonhrs )
  241. {
  242. return SetLogonHours( logonhrs.QueryHoursBlock(),
  243. logonhrs.QueryUnitsPerWeek() );
  244. }
  245. APIERR TrimParams();
  246. };
  247. /*************************************************************************
  248. NAME: USER_2
  249. SYNOPSIS: Wrapper for User APIs, level 2
  250. USER_2 must be used whenever the user wishes to use
  251. WriteInfo or WriteNew.
  252. INTERFACE: Construct with account name and server/domain name
  253. Interface is as USER_11, except that USER_2 supports
  254. I_GetInfo
  255. Reads in the current state of the object
  256. I_WriteInfo
  257. Writes the current state of the object to the
  258. API. This write is atomic, either all
  259. parameters are set or none are set.
  260. I_CreateNew
  261. Sets up the USER_2 object with default values in
  262. preparation for a call to WriteNew
  263. I_WriteNew
  264. Adds a new user account
  265. CloneFrom
  266. Makes this USER_2 instance an exact copy of the
  267. parameter USER_2 instance. All fields including
  268. name and state will be copied. If this operation
  269. fails, the object will be invalid. The parameter
  270. must be a USER_2 and not a subclass of USER_2.
  271. QueryUserFlags
  272. Returns the user's user flags
  273. QueryAccountExpires
  274. Returns the user's account expires information
  275. QueryScriptPath
  276. Returns the user's script path
  277. SetUserFlags
  278. SetAccountExpires
  279. SetScriptPath
  280. Set information about the USER_2 object
  281. Returns error code which is NERR_Success
  282. on success
  283. QueryPassword
  284. Queries the user password. Note that this
  285. information may be bogus, since the API does not
  286. provide this information. Instead, GetInfo() will
  287. set this to NULL_USERSETINFO_PASSWORD (see access.h).
  288. SetPassword
  289. Changes the user password.
  290. QueryUserFlag
  291. SetUserFlag
  292. Queries/changes any single flag in the user flags
  293. (usriX_flags).
  294. QueryAccountDisabled
  295. QueryUserCantChangePass
  296. QueryUserPassRequired
  297. QueryNoPasswordExpire
  298. SetAccountDisabled
  299. SetUserCantChangePass
  300. SetUserPassRequired
  301. SetNoPasswordExpire
  302. Queries/changes specific flags in the user flags:
  303. account disabled
  304. user-cannot-change-password
  305. password-required
  306. PARENT: USER_11
  307. USES: NLS_STR
  308. HISTORY:
  309. jonn 7/22/91 Created
  310. jonn 4/27/92 USER_2 and USER_3 virtual dtor
  311. **************************************************************************/
  312. /*
  313. NT BUGBUG: The following definition of MAX_USER_INFO_SIZE_2
  314. is not safe for NT. It should be moved to a global header file.
  315. */
  316. #define MAX_USER_INFO_SIZE_2 (sizeof(struct user_info_2) + \
  317. ((MAXCOMMENTSZ+1) * 4) + ((PATHLEN+1) * 3) + MAX_PATH+1 + \
  318. (8 * (MAX_PATH) + 1) )
  319. DLL_CLASS USER_2 : public USER_11
  320. {
  321. private:
  322. UINT _afUserFlags;
  323. LONG _lAcctExpires;
  324. NLS_STR _nlsPassword;
  325. NLS_STR _nlsScriptPath;
  326. VOID CtAux(); // constructor helper
  327. protected:
  328. APIERR W_Write(); // helper for I_WriteInfo and I_WriteNew
  329. APIERR W_CloneFrom( const USER_2 & user2 );
  330. virtual APIERR W_CreateNew();
  331. virtual APIERR I_GetInfo();
  332. virtual APIERR I_WriteInfo();
  333. virtual APIERR I_CreateNew();
  334. virtual APIERR I_WriteNew();
  335. virtual APIERR I_ChangeToNew();
  336. BOOL QueryUserFlag( UINT afMask ) const;
  337. APIERR SetUserFlag( BOOL fFlag, UINT afMask );
  338. public:
  339. USER_2(const TCHAR *pszAccount, const TCHAR *pszLocation = NULL);
  340. USER_2(const TCHAR *pszAccount, enum LOCATION_TYPE loctype);
  341. USER_2(const TCHAR *pszAccount, const LOCATION & loc);
  342. virtual ~USER_2();
  343. inline const TCHAR * QueryPassword() const
  344. { CHECK_OK(NULL); return _nlsPassword.QueryPch(); }
  345. // must be a valid password with null-termination
  346. APIERR SetPassword( const TCHAR *pszPassword );
  347. BOOL QueryAccountDisabled() const;
  348. APIERR SetAccountDisabled( BOOL fAccountDisabled );
  349. BOOL QueryUserCantChangePass() const;
  350. APIERR SetUserCantChangePass( BOOL fUserCantChangePass );
  351. BOOL QueryNoPasswordExpire() const;
  352. APIERR SetNoPasswordExpire( BOOL fNoPasswordExpire );
  353. BOOL QueryUserPassRequired() const;
  354. APIERR SetUserPassRequired( BOOL fUserPassRequired );
  355. BOOL QueryLockout() const;
  356. APIERR SetLockout( BOOL fLockout );
  357. APIERR CloneFrom( const USER_2 & user2 );
  358. inline const TCHAR * QueryScriptPath() const
  359. { CHECK_OK(NULL); return _nlsScriptPath.QueryPch(); }
  360. inline LONG QueryAccountExpires() const
  361. { CHECK_OK(0L); return _lAcctExpires; }
  362. inline UINT QueryUserFlags() const
  363. { CHECK_OK(0); return _afUserFlags; }
  364. APIERR SetScriptPath( const TCHAR * pszPath );
  365. APIERR SetAccountExpires( LONG lExpires );
  366. APIERR SetUserFlags( UINT afFlags );
  367. };
  368. /*************************************************************************
  369. NAME: LOCAL_USER
  370. SYNOPSIS: Local user info class
  371. INTERFACE:
  372. LOCAL_USER()
  373. Constructor. Construct the object with a
  374. domain name or server name; the two are
  375. distinguished by the leading \\. Any error
  376. (server/domain not found, etc.) will be
  377. reported at GetInfo time. A NULL (default)
  378. parameter means the logon domain. A password
  379. for share-level servers can also be specified.
  380. I_GetInfo()
  381. Gets information about the logged on user,
  382. pertaining to the specified domain or server.
  383. Returns a standard LANMAN error code.
  384. ERROR_INVALID_PASSWORD (86) usually indicates
  385. that it's a share-level server.
  386. QueryPriv()
  387. Returns the logged on user's privilege level.
  388. QueryAuthFlags()
  389. Returns the logged on user's authorization
  390. flags (operator rights).
  391. IsShareLevel()
  392. Returns TRUE if the named server is share level
  393. (and the given password was valid for ADMIN$).
  394. PARENT: USER_11
  395. HISTORY:
  396. gregj 4/16/91 Created
  397. gregj 4/22/91 Derived from USER_11
  398. gregj 4/29/91 Added IsShareLevel()
  399. gregj 5/22/91 Support LOCATION_TYPE constructor
  400. **************************************************************************/
  401. DLL_CLASS LOCAL_USER : public USER_11
  402. {
  403. protected:
  404. BOOL _fAdminConnect; // TRUE if ADMIN$ use made
  405. TCHAR _szPassword [PWLEN+3]; // ADMIN$ password
  406. virtual APIERR I_GetInfo();
  407. public:
  408. LOCAL_USER( const TCHAR *pszLocation = NULL, const TCHAR *pszPassword = NULL );
  409. LOCAL_USER( enum LOCATION_TYPE loctype );
  410. ~LOCAL_USER();
  411. UINT QueryPriv() const;
  412. ULONG QueryAuthFlags() const;
  413. BOOL IsShareLevel() const;
  414. };
  415. #endif // _LMOUSER_HXX_