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.

427 lines
16 KiB

  1. /********************************************************************/
  2. /** Microsoft LAN Manager **/
  3. /** Copyright(c) Microsoft Corp., 1987-1990 **/
  4. /********************************************************************/
  5. /*
  6. * FILE STATUS:
  7. * 10/11/90 jonn created
  8. * 01/10/91 jonn removed PSHORT, PUSHORT
  9. * 01/27/91 jonn changed from CFGFILE, added UserProfileInit/Free
  10. * 02/02/91 jonn added UserProfileWrite/Clear, removed Confirm,
  11. * redefined Set.
  12. * 02/04/91 jonn added cpszUsername param to Query, Enum, Set
  13. * 03/08/91 chuckc added UserPreferenceXXX() calls.
  14. * 04/16/91 jonn added USERPREF_CONFIRMATION and USERPREF_ADMINMENUS
  15. * 05/08/91 jonn Added canonicalization of netnames, canonicalize
  16. * on read
  17. * 06-Apr-92 beng Nuked PSZ and CPSZ types (Unicode pass)
  18. */
  19. /****************************************************************************
  20. MODULE: UIProf.h
  21. PURPOSE: Handles low-level manipulation of user profile files
  22. Handles user preferences (saved info)
  23. FUNCTIONS:
  24. UserProfileInit() - Initializes the user profile module. The
  25. cached profile is initially empty.
  26. UserProfileFree() - Frees memory used by the user profile module.
  27. UserProfileRead() - Caches the profile for the specified user from
  28. permanent storage into a global data structure,
  29. for future UserProfileQuery/Enum calls.
  30. Call with NULL to clear the cached profile.
  31. UserProfileWrite() - Writes the cached profile into permanent storage.
  32. UserProfileQuery() - Returns one entry from the cached profile.
  33. UserProfileEnum() - Lists all entries in the cached profile.
  34. UserProfileSet() - Changes the cached profile. It is generally
  35. advisable to immediately precede this call with
  36. UserProfileRead, and immediately follow it with
  37. UserProfileWrite.
  38. UserPreferenceQuery() - queries a single user preference string.
  39. UserPreferenceSet() - saves a single user preference string.
  40. UserPreferenceQueryBool() - queries a user preference bool value.
  41. UserPreferenceSetBool() - saves a user preference bool value.
  42. COMMENTS:
  43. UserProfile routines:
  44. Under LM30, the profile in $(LANROOT) will only be used if the
  45. profile stored in the DS is unavailable.
  46. Be sure to cache a user's profile before calling
  47. UserProfileQuery, UserProfileEnum or UserProfileSet. These
  48. routines will fail if no profile is currently cached.
  49. The cpszUsername argument is handled differently from different
  50. APIs. UserProfileRead and UserProfileWrite use it to specify the
  51. user profile to read or write. UserProfileRead will also remember
  52. the last username in a static variable whether the call succeeds
  53. or not. Null or empty user names clear the stored profile in
  54. UserProfileRead, and return NERR_BadUsername in
  55. UserProfileWrite.
  56. UserProfileQuery, Enum and Set compare cpszUsername with the
  57. last username remembered by UserProfileRead. If UserProfileRead
  58. has never been called, or if it was last called with a different
  59. username (NULL and empty string are equivalent), these calls
  60. fail with ERROR_GEN_FAILURE. In this way, you can use the
  61. cpszUsername parameter to check whether the correct profile is
  62. loaded, or you can use it to check whether your module has just
  63. started and should perform the initial UserProfileRead. Note that
  64. UserProfileRead(NULL) will prevent the ERROR_GEN_FAILURE return
  65. code when cpszUsername==NULL.
  66. Remember that a user may be logged on from several different
  67. machines, and that the cached profile is not automatically
  68. updated. When the profile is to be changed in permanent
  69. storage, it is generally advisable to reread the profile from
  70. permanent storage with UserProfileRead, make the change in the
  71. cache with userProfileSet, and immediately rewrite the profile
  72. with UserProfileWrite; this reduces the chance that another
  73. user's changes will be lost.
  74. When successful, the UserProfile APIs return NO_ERROR (0). The
  75. following are the error codes returned by the UserProfile APIs:
  76. NERR_BadUsername: bad username argument
  77. NERR_InvalidDevice: bad devicename argument
  78. ERROR_BAD_NETPATH: bad lanroot argument
  79. ERROR_BAD_NET_NAME: bad remotename argument
  80. NERR_UseNotFound: the specified device is not listed in the profile
  81. ERROR_NOT_ENOUGH_MEMORY: lack of global memory or overfull profile
  82. ERROR_GET_FAILURE: username mismatch
  83. ERROR_FILE_NOT_FOUND: any file read error
  84. ERROR_WRITE_FAULT: any file write error
  85. BUGBUG We must determine correct behavior when no user is logged on.
  86. BUGBUG Do we return ERROR_GEN_FAILURE? NO_ERROR? what?
  87. User preferences routines:
  88. These routines read and write sticky values in some section
  89. of the local LANMAN.INI. These sticky values are therefore
  90. all local to the workstation; this mechanism is not intended
  91. for values associated with a user. Unlike the UserProfile
  92. routines, these routines do not cache any data.
  93. ****************************************************************************/
  94. /* returncodes: */
  95. /* global macros */
  96. #define PROFILE_DEFAULTFILE "LMUSER.INI"
  97. #define USERPREF_MAX 256 // arbitrary limit to ease mem alloc
  98. #define USERPREF_YES "yes" // this is not internationalized.
  99. #define USERPREF_NO "no" // ditto
  100. #define USERPREF_NONE 0 // no such value
  101. #define USERPREF_AUTOLOGON 0x1 // auto logon
  102. #define USERPREF_AUTORESTORE 0x2 // auto restore profile
  103. #define USERPREF_SAVECONNECTIONS 0x3 // auto save connections
  104. #define USERPREF_USERNAME 0x4 // user name
  105. #define USERPREF_CONFIRMATION 0x5 // confirm actions?
  106. #define USERPREF_ADMINMENUS 0x6 // Admin menus (PrintMgr)
  107. #ifdef __cplusplus
  108. extern "C" {
  109. #endif
  110. /* functions: */
  111. /*
  112. * UserProfileInit prepares the profile library. This API must be
  113. * called exactly once, and before any other UserProfile APIs.
  114. *
  115. * error returns:
  116. * ERROR_NOT_ENOUGH_MEMORY
  117. */
  118. USHORT UserProfileInit( void
  119. );
  120. /*
  121. * UserProfileFree releases memory claimed by the profile library.
  122. * Do not call UserProfileFree unless the profile library is initialized.
  123. * After UserProfileFree, the only permissible UserProfile call is
  124. * userProfileInit.
  125. *
  126. * error returns:
  127. * <none>
  128. */
  129. USHORT UserProfileFree( void
  130. );
  131. /*
  132. * UserProfileRead attempt to cache the user's profile as stored in
  133. * permanent storage (<cpszLanroot>\LMUSER.INI, or the DS for LM30).
  134. *
  135. * Call with cpszUsername==NULL or cpszUsername=="" to clear cached profile.
  136. * In this case, cpszLanroot is ignored.
  137. *
  138. * UserProfileRead updates the username associated with the current
  139. * profile, for use by UserProfileQuery/Enum/Set.
  140. *
  141. * error returns:
  142. * NERR_BadUsername
  143. * ERROR_BAD_NETPATH
  144. * ERROR_NOT_ENOUGH_MEMORY: includes "profile full" state
  145. * ERROR_FILE_NOT_FOUND
  146. */
  147. USHORT UserProfileRead(
  148. const TCHAR * pszUsername,
  149. const TCHAR * pszLanroot
  150. );
  151. /*
  152. * UserProfileWrite attempts to write the user's profile back to
  153. * permanent storage (<cpszLanroot>\LMUSER.INI, or the DS for LM30).
  154. *
  155. * error returns:
  156. * NERR_BadUsername
  157. * ERROR_BAD_NETPATH
  158. * ERROR_NOT_ENOUGH_MEMORY
  159. * ERROR_WRITE_FAULT
  160. */
  161. USHORT UserProfileWrite(
  162. const TCHAR * pszUsername,
  163. const TCHAR * pszLanroot
  164. );
  165. /*
  166. * psAsgType returns the device type as in use_info_1 or (LM30) use_info_2
  167. * fields ui1_asg_type or (LM30) ui2_asg_type. pusResType returns
  168. * the device name type (e.g. UNC, alias, DFS, DS) as in the
  169. * use_info_2 ui1_res_type field. Either of these parameters may be
  170. * passed as NULL by programs which do not care about the return value.
  171. *
  172. * cpszUsername is used to confirm that the cached profile is for the
  173. * named user. Pass NULL to accept any cached profile (but still
  174. * reject if UserProfileRead has not been called).
  175. *
  176. * error returns:
  177. * ERROR_GEN_FAILURE: cached profile is not for the named user
  178. * NERR_BadUsername
  179. * NERR_InvalidDevice
  180. * NERR_UseNotFound
  181. * ERROR_NOT_ENOUGH_MEMORY
  182. * ERROR_INSUFFICIENT_BUFFER
  183. */
  184. USHORT UserProfileQuery(
  185. const TCHAR * pszUsername,
  186. const TCHAR * pszDeviceName,
  187. TCHAR * pszBuffer, // returns UNC, alias or domain name
  188. USHORT usBufferSize, // length of above buffer
  189. short far * psAsgType, // as ui1_asg_type / ui2_asg_type
  190. // ignored if NULL
  191. unsigned short far * pusResType // ignore / as ui2_res_type
  192. // ignored if NULL
  193. );
  194. /*
  195. * Returns a list of all devices for which the cached profile lists a
  196. * connection, separated by nulls, with a null-null at the end.
  197. * For example, "LPT1:\0D:\0F:\0" (don't forget the extra '\0'
  198. * implicit in "" strings)
  199. *
  200. * cpszUsername is used to confirm that the cached profile is for the
  201. * named user. Pass NULL to accept any cached profile (but still
  202. * reject if UserProfileRead has not been called).
  203. *
  204. * error returns:
  205. * NERR_BadUsername
  206. * ERROR_NOT_ENOUGH_MEMORY
  207. * ERROR_INSUFFICIENT_BUFFER
  208. */
  209. USHORT UserProfileEnum(
  210. const TCHAR * pszUsername,
  211. TCHAR * pszBuffer, // returns NULL-NULL list of device names
  212. USHORT usBufferSize // length of above buffer
  213. );
  214. /*
  215. * Changes the cached profile. Follow this call with a call to
  216. * UserProfileWrite to write the profile to permanent storage.
  217. *
  218. * The user is expected to ensure that usResType corresponds to
  219. * the type of the remote resource, and that device pszDeviceName
  220. * can be connected to a resource of that type.
  221. *
  222. * Does not canonicalize cpszCanonRemoteName, caller must do this
  223. *
  224. * cpszUsername is used to confirm that the cached profile is for the
  225. * named user. Pass NULL to accept any cached profile (but still
  226. * reject if no user profile is cached).
  227. *
  228. * error returns:
  229. * ERROR_GEN_FAILURE: cached profile is not for the named user
  230. * NERR_InvalidDevice: bad cpszDeviceName
  231. * ERROR_BAD_NET_NAME: bad cpszRemoteName
  232. * ERROR_NOT_ENOUGH_MEMORY: includes "profile full" state
  233. */
  234. USHORT UserProfileSet(
  235. const TCHAR * pszUsername,
  236. const TCHAR * pszDeviceName,
  237. const TCHAR * pszRemoteName,
  238. short sAsgType, // as ui2_asg_type
  239. unsigned short usResType // as ui2_res_type
  240. );
  241. /*************************************************************************
  242. NAME: UserPreferenceQuery
  243. SYNOPSIS: Queries a user preference (ie remembered string).
  244. INTERFACE: UserPreferenceQuery( usKey, pchValue, cbLen )
  245. usKey - will indicate which value we want, as defined
  246. in uiprof.h.
  247. pchValue - pointer to buffer that will receive value
  248. cbLen - size of buffer
  249. return value is NERR_Success, ERROR_INAVALID_PARAMETER,
  250. or NetConfigGet2 error.
  251. USES: Use to recall values saved by UserPrefenceSet(), normally
  252. things like default logon name, etc.
  253. CAVEATS:
  254. NOTES: Currently, the values are stored in LANMAN.INI, and hence
  255. each value is per machine.
  256. HISTORY:
  257. chuckc 7-Mar-1991 Created
  258. **************************************************************************/
  259. USHORT UserPreferenceQuery( USHORT usKey,
  260. TCHAR FAR * pchValue,
  261. USHORT cbLen);
  262. /*************************************************************************
  263. NAME: UserPreferenceSet
  264. SYNOPSIS: Sets a user preference (remembers a string).
  265. INTERFACE: UserPreferenceSet( usKey, pchValue )
  266. usKey - will indicate which value we want, as defined
  267. in uiprof.h.
  268. pchValue - pointer to null terminates string to be remembered
  269. return value is NERR_Success, ERROR_INAVALID_PARAMETER,
  270. or NetConfigSet error.
  271. USES: Use to save values to be retrieved by UserPrefenceQuery(),
  272. normally things like default logon name, etc.
  273. CAVEATS:
  274. NOTES: Currently, the values are stored in LANMAN.INI, and hence
  275. each value is per machine.
  276. HISTORY:
  277. chuckc 7-Mar-1991 Created
  278. **************************************************************************/
  279. USHORT UserPreferenceSet( USHORT usKey,
  280. TCHAR FAR * pchValue);
  281. /*************************************************************************
  282. NAME: UserPreferenceQueryBool
  283. SYNOPSIS: Queries a BOOL a user preference (remembered flag).
  284. INTERFACE: UserPreferenceQueryBool( usKey, pfValue )
  285. usKey - will indicate which value we want, as defined
  286. in uiprof.h.
  287. pfValue - pointer to BOOL that will contain value
  288. return value is NERR_Success, ERROR_INAVALID_PARAMETER,
  289. or UserPreferenceQuery error.
  290. USES: Use to retrieve flags set by by UserPrefenceSetBool(),
  291. normally things like auto logon, etc.
  292. CAVEATS:
  293. NOTES: Currently, the values are stored in LANMAN.INI, and hence
  294. each value is per machine. This func calls
  295. UserPreferenceQuery(), taking "yes" or "YES" to be
  296. true, "no" or "NO" to be false.
  297. HISTORY:
  298. chuckc 7-Mar-1991 Created
  299. **************************************************************************/
  300. USHORT UserPreferenceQueryBool( USHORT usKey,
  301. BOOL FAR * pfValue) ;
  302. /*************************************************************************
  303. NAME: UserPreferenceSetBool
  304. SYNOPSIS: Sets a user preference flag
  305. INTERFACE: UserPreferenceSetBool( usKey, fValue )
  306. usKey - will indicate which value we want, as defined
  307. in uiprof.h.
  308. fValue - BOOL value, true or false
  309. return value is NERR_Success, ERROR_INAVALID_PARAMETER,
  310. or UserPreferenceSet error.
  311. USES: Use to save values to be retrieved by UserPrefenceQueryBool(),
  312. normally flags like autologon, etc.
  313. CAVEATS:
  314. NOTES: Currently, the values are stored in LANMAN.INI, and hence
  315. each value is per machine. This func calls
  316. UserPreferenceSet(), taking "yes" or "YES" to be
  317. true, "no" or "NO" to be false.
  318. We also restrict values to length of < USERPREF_MAX.
  319. HISTORY:
  320. chuckc 7-Mar-1991 Created
  321. **************************************************************************/
  322. USHORT UserPreferenceSetBool( USHORT usKey,
  323. BOOL fValue);
  324. #ifdef __cplusplus
  325. }
  326. #endif