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.

590 lines
19 KiB

  1. /********************************************************************/
  2. /** Microsoft LAN Manager **/
  3. /** Copyright(c) Microsoft Corp., 1990,1991 **/
  4. /********************************************************************/
  5. /*
  6. newprof.h
  7. C-language wrappers for ini-file-handling classes
  8. FILE HISTORY:
  9. 10/11/90 jonn created
  10. 01/10/91 jonn removed PSHORT, PUSHORT
  11. 01/27/91 jonn changed from CFGFILE, added UserProfileInit/Free
  12. 02/02/91 jonn added UserProfileWrite/Clear, removed Confirm,
  13. redefined Set.
  14. 02/04/91 jonn added cpszUsername param to Query, Enum, Set
  15. 03/08/91 chuckc added UserPreferenceXXX() calls.
  16. 04/16/91 jonn added USERPREF_CONFIRMATION and USERPREF_ADMINMENUS
  17. 05/08/91 jonn Added canonicalization of netnames, canonicalize
  18. on read
  19. 05/28/91 jonn Restructured to allow preferences in LMUSER.INI
  20. */
  21. #ifndef _NEWPROF_H_
  22. #define _NEWPROF_H_
  23. /****************************************************************************
  24. MODULE: NewProf.h
  25. PURPOSE: Handles low-level manipulation of user preference files
  26. FUNCTIONS:
  27. UserPreferenceRead() - Reads the preferences from permanent storage
  28. into a file image, for future UserPreference or
  29. UserPref calls.
  30. UserPreferenceWrite() - Writes the preferences from a file image
  31. into permanent storage.
  32. UserPreferenceFree() - Frees memory claimed by a file image.
  33. UserPrefStringQuery() - queries a single user preference string.
  34. UserPrefStringSet() - saves a single user preference string.
  35. It is generally advisable to immediately precede
  36. this call with UserPreferenceRead, and to
  37. immediately follow it with UserPreferenceSet.
  38. UserPrefBoolQuery() - queries a single user preference bool value.
  39. UserPrefBoolSet() - saves a single user preference bool value.
  40. Same usage recommendations as UserPrefStringSet.
  41. UserPrefProfileQuery() - Returns one device connection from a file
  42. image.
  43. UserPrefProfileEnum() - Lists all device connections in a file image.
  44. UserPrefProfileSet() - Changes a device connection in a file image.
  45. Same usage recommendations as UserPrefStringSet.
  46. UserPrefProfileTrim() - Trims all components in a file image
  47. which are not relevant to device connections.
  48. COMMENTS:
  49. These APIs are wrappers to the C++ INI-file handling classes defined
  50. in newprof.hxx. Most clients will prefer to use the wrapper APIs,
  51. including all C clients. These wrapper APIs provide almost all
  52. the functionality of the C++ APIs. The C++ APIs are more subject to
  53. change with changing implementation (NT configuration manager, DS)
  54. than are these C-language wrappers.
  55. UserPreference routines:
  56. Under LM21, these routines read and write the local LMUSER.INI.
  57. These sticky values are therefore all local to the workstation;
  58. this mechanism is not intended for values associated with a user.
  59. Under LM30, the preferences in LMUSER.INI will only be used if the
  60. preferences stored in the DS (NT Configuration Manager?) are
  61. unavailable. Some preferences, such as default username, will be
  62. stored in LMUSER.INI regardless.
  63. UserPreferenceRead returns a PFILEIMAGE which the UserPreference APIs
  64. can interpret as an image of the LMUSER.INI file. This PFILEIMAGE
  65. must be passed through to UserPreferenceWrite and to the
  66. UserPrefProfile, UserPrefBool etc. APIs. When this image is no
  67. longer needed, it should be freed with UserPreferenceFree.
  68. Remember that a user may be logged on from several different
  69. machines, and that the cached profile is not automatically
  70. updated. When the profile is to be changed in permanent
  71. storage, it is generally advisable to reread the profile from
  72. permanent storage with UserPreferenceRead, make the change in the
  73. cache with UserPrefBoolSet (et al), and immediately rewrite the
  74. profile with UserPreferenceWrite; this reduces the chance that
  75. another user's changes will be lost.
  76. When successful, these APIs return NERR_Success (0). The following
  77. are the error codes returned by the UserPref APIs:
  78. NERR_CfgCompNotFound: the specified component is not in the file
  79. NERR_CfgParamNotFound: the specified parameter is not in the file,
  80. or it is in the file but is not valid for a parameter of
  81. this type.
  82. NERR_InvalidDevice: bad devicename argument
  83. ERROR_BAD_NET_NAME: bad remotename argument
  84. ERROR_NOT_ENOUGH_MEMORY: lack of global memory
  85. other file read and file write errors
  86. UserPref routines:
  87. These routines read and write one particular type of sticky
  88. values. For example, the UserPrefProfile APIs read and write
  89. device profile entries, while UserPrefBool APis read and write
  90. boolean-valued entries. Client programs must still read the file
  91. image first with UserPreferenceRead, save the changes with
  92. UserPreferenceWrite, and free the file image with UserPreferenceFree.
  93. Use UserPrefProfileTrim when you intend to keep the file image
  94. around for a long time (e.g. in a cache), and are not iterested
  95. in entries other than device connections. Do not write such a
  96. trimmed file image, you will lose the other entries!
  97. Use UserPrefStringSet(pfileimage,usKey,NULL) to remove both
  98. string-valued parameters and boolean-valued parameters.
  99. CAVEATS:
  100. These routines take PSZ and CPSZ buffers because these are
  101. explicitly far for C programs (in particular lui\profile.c), but
  102. do not generate errors under C++.
  103. ****************************************************************************/
  104. /* returncodes: */
  105. /* global macros */
  106. #include <newprofc.h>
  107. /* typedefs: */
  108. typedef PVOID PFILEIMAGE;
  109. typedef PFILEIMAGE FAR * PPFILEIMAGE;
  110. /* functions: */
  111. /*************************************************************************
  112. NAME: UserPreferenceRead
  113. SYNOPSIS: UserPreferenceRead attempts to read the user's profile from
  114. permanent storage (<cpszLanroot>\LMUSER.INI for LM21).
  115. It returns a PFILEIMAGE which serves as a "file image" for use
  116. of the other APIs.
  117. INTERFACE: UserPreferenceRead( ppFileImage )
  118. ppFileImage - returns pointer to a file image.
  119. Return values are:
  120. NERR_Success
  121. ERROR_NOT_ENOUGH_MEMORY
  122. errors in NetWkstaGetInfo[1]
  123. file read errors
  124. USES: Use to obtain a file image for use in the UserPref APIs.
  125. NOTES: Currently, the values are stored in LANMAN.INI, and hence
  126. each value is per machine.
  127. Use UserPreferenceFree to release the file image when
  128. it is no longer needed.
  129. Some users may choose to ignore ERROR_FILE_NOT_FOUND.
  130. The file image must be freed regardless of the return
  131. code.
  132. HISTORY:
  133. jonn 10/11/90 Created
  134. jonn 05/28/91 Restructured to allow preferences in LMUSER.INI
  135. jonn 06/26/91 No longer takes LANROOT parameter
  136. **************************************************************************/
  137. APIERR UserPreferenceRead(
  138. PPFILEIMAGE ppFileImage
  139. ) ;
  140. /*************************************************************************
  141. NAME: UserPreferenceWrite
  142. SYNOPSIS: UserPreferenceWrite attempts to write the user's profile
  143. back to permanent storage.
  144. INTERFACE: UserPreferenceWrite( pFileImage )
  145. pFileImage - a file image originally obtained from
  146. UserPreferenceRead.
  147. Return values are:
  148. NERR_Success
  149. ERROR_NOT_ENOUGH_MEMORY
  150. file write errors
  151. USES: Use to write out changes to the preferences in a file image.
  152. HISTORY:
  153. jonn 10/11/90 Created
  154. jonn 05/28/91 Restructured to allow preferences in LMUSER.INI
  155. jonn 06/26/91 No longer takes LANROOT parameter
  156. **************************************************************************/
  157. APIERR UserPreferenceWrite(
  158. PFILEIMAGE pFileImage
  159. ) ;
  160. /*************************************************************************
  161. NAME: UserPreferenceFree
  162. SYNOPSIS: UserPreferenceFree releases a file image.
  163. INTERFACE: UserPreferenceFree( pFileImage )
  164. pFileImage - a file image originally obtained from
  165. UserPreferenceRead.
  166. RETURNS: NERR_Success
  167. USES: Use when a file image is no longer needed. File images
  168. use a considerable amount of memory, so be sure to free
  169. them.
  170. NOTES: It is permitted to free a null file image pointer.
  171. CAVEATS: Do not use the file image after it has been freed.
  172. HISTORY:
  173. jonn 10/11/90 Created
  174. jonn 05/28/91 Restructured to allow preferences in LMUSER.INI
  175. **************************************************************************/
  176. APIERR UserPreferenceFree(
  177. PFILEIMAGE pFileImage
  178. ) ;
  179. /*************************************************************************
  180. NAME: UserPrefStringQuery
  181. SYNOPSIS: Queries a user preference (i.e. remembered string).
  182. INTERFACE: UserPrefStringQuery( pFileImage, usKey, pszBuffer, cbBuffer )
  183. pFileImage - as obtained from UserPreferenceRead
  184. usKey - will indicate which value we want, as defined
  185. in newprofc.h.
  186. pszBuffer - pointer to buffer that will receive value
  187. cbBuffer - size of buffer in bytes
  188. return values are:
  189. NERR_Success
  190. NERR_CfgCompNotFound
  191. NERR_CfgParamNotFound
  192. ERROR_INVALID_PARAMETER: bad usKey
  193. NERR_BufTooSmall
  194. ERROR_NOT_ENOUGH_MEMORY
  195. USES: Use to recall string-valued parameters, normally things
  196. like default logon name. Do not use for boolean-valued
  197. parameters -- for those, use UserPrefBool instead.
  198. NOTES: Currently, the values are stored in LANMAN.INI, and hence
  199. each value is per machine.
  200. A buffer of size MAXPATHLEN+1 is guaranteed to be large enough.
  201. HISTORY:
  202. chuckc 03/07/91 Created
  203. jonn 05/28/91 Restructured to allow preferences in LMUSER.INI
  204. **************************************************************************/
  205. APIERR UserPrefStringQuery( PFILEIMAGE pFileImage,
  206. USHORT usKey,
  207. PSZ pszBuffer,
  208. USHORT cbBuffer) ;
  209. /*************************************************************************
  210. NAME: UserPrefStringSet
  211. SYNOPSIS: Sets a user preference (i.e. remembered string).
  212. INTERFACE: UserPrefStringSet( pFileImage, usKey, pszValue )
  213. pFileImage - as obtained from UserPreferenceRead
  214. usKey - will indicate which value we want, as defined
  215. in newprofc.h.
  216. pszValue - pointer to null-terminated string to be remembered
  217. return values are:
  218. NERR_Success
  219. ERROR_INVALID_PARAMETER: bad usKey
  220. ERROR_NOT_ENOUGH_MEMORY
  221. USES: Use to create or change string-valued parameters,
  222. normally things like default logon name, etc. Do not use
  223. for boolean-valued parameters -- for those, use UserPrefBool
  224. instead.
  225. CAVEATS: Note that this API only modifies the file image; you must
  226. call UserPreferenceWrite to save the change in permanent
  227. storage.
  228. NOTES: Currently, the values are stored in LANMAN.INI, and hence
  229. each value is per machine.
  230. Also used to delete boolean-valued parameters.
  231. HISTORY:
  232. chuckc 03/07/91 Created
  233. jonn 05/28/91 Restructured to allow preferences in LMUSER.INI
  234. **************************************************************************/
  235. APIERR UserPrefStringSet( PFILEIMAGE pFileImage,
  236. USHORT usKey,
  237. CPSZ cpszValue) ;
  238. /*************************************************************************
  239. NAME: UserPrefBoolQuery
  240. SYNOPSIS: Queries a boolean user preference
  241. INTERFACE: UserPrefBoolQuery( pFileImage, usKey, pfValue )
  242. pFileImage - as obtained from UserPreferenceRead
  243. usKey - will indicate which value we want, as defined
  244. in newprofc.h.
  245. pfValue - pointer to BOOL that will contain value
  246. return values as UserPrefStringQuery
  247. USES: as UserPrefStringQuery for boolean-valued parameters
  248. CAVEATS: as UserPrefStringQuery for boolean-valued parameters
  249. NOTES: as UserPrefStringQuery for boolean-valued parameters
  250. We take USERPREF_YES to be true, USERPREF_NO to be false
  251. (case-insensitive); other values are invalid.
  252. os2def.h defines PBOOL as BOOL FAR *.
  253. HISTORY:
  254. chuckc 03/07/91 Created
  255. jonn 05/28/91 Restructured to allow preferences in LMUSER.INI
  256. **************************************************************************/
  257. APIERR UserPrefBoolQuery( PFILEIMAGE pFileImage,
  258. USHORT usKey,
  259. PBOOL pfValue) ;
  260. /*************************************************************************
  261. NAME: UserPrefBoolSet
  262. SYNOPSIS: Sets a boolean user preference
  263. INTERFACE: UserPrefBoolSet( pFileImage, usKey, fValue )
  264. pFileImage - as obtained from UserPreferenceRead
  265. usKey - will indicate which value we want, as defined
  266. in newprofc.h.
  267. fValue - BOOL value, true or false
  268. return values as UserPrefStringSet
  269. USES: as UserPrefStringSet for boolean-valued parameters
  270. CAVEATS: as UserPrefStringSet for boolean-valued parameters
  271. NOTES: as UserPrefStringSet for boolean-valued parameters
  272. We write USERPREF_YES for TRUE, USERPREF_NO for FALSE.
  273. Use UserPrefStringSet to delete boolean-valued parameters.
  274. HISTORY:
  275. chuckc 03/07/91 Created
  276. jonn 05/28/91 Restructured to allow preferences in LMUSER.INI
  277. **************************************************************************/
  278. APIERR UserPrefBoolSet( PFILEIMAGE pFileImage,
  279. USHORT usKey,
  280. BOOL fValue) ;
  281. /*************************************************************************
  282. NAME: UserPrefProfileQuery
  283. SYNOPSIS: Queries a device-connection user preference
  284. INTERFACE: UserPrefProfileQuery( pFileImage, cpszDeviceName,
  285. pszBuffer, cbBuffer, psAsgType, pusResType )
  286. pFileImage - as obtained from UserPreferenceRead
  287. cpszDeviceName - indicates which device we want
  288. pszBuffer - buffer into which to store remote name
  289. cbBuffer - length of buffer in bytes
  290. psAsgType - returns asgType of remote device
  291. pusResType - returns resType of remote device
  292. return values as UserPrefStringQuery
  293. ERROR_INVALID_PARAMETER: bad cpszDeviceName
  294. USES: as UserPrefStringQuery for device-connection parameters
  295. psAsgType returns the device type as in use_info_1 or
  296. (LM30) use_info_2 fields ui1_asg_type or (LM30) ui2_asg_type.
  297. pusResType returns the device name type (e.g. UNC, alias, DFS,
  298. DS) as in the use_info_2 ui1_res_type field. Either of these
  299. parameters may be passed as NULL by programs which do not
  300. care about those return values.
  301. CAVEATS: as UserPrefStringQuery for device-connection parameters
  302. Note that it is the caller's reponsibility to deal with
  303. the case where the user is not logged on and should therefore
  304. see no unavailable connections.
  305. NOTES: as UserPrefStringQuery for device-connection parameters
  306. os2def.h defines PSHORT and PUSHORT as explicitly FAR.
  307. HISTORY:
  308. chuckc 03/07/91 Created
  309. jonn 05/28/91 Restructured to allow preferences in LMUSER.INI
  310. **************************************************************************/
  311. APIERR UserPrefProfileQuery(
  312. PFILEIMAGE pFileImage,
  313. CPSZ cpszDeviceName,
  314. PSZ pszBuffer, // returns UNC, alias or domain name
  315. USHORT cbBuffer, // length of above buffer in bytes
  316. PSHORT psAsgType, // as ui1_asg_type / ui2_asg_type
  317. // ignored if NULL
  318. PUSHORT pusResType // ignore / as ui2_res_type
  319. // ignored if NULL
  320. ) ;
  321. /*************************************************************************
  322. NAME: UserPrefProfileEnum
  323. SYNOPSIS: Lists all device-connection user preferences
  324. INTERFACE: UserPrefProfileEnum( pFileImage, pszBuffer, cbBuffer );
  325. pFileImage - as obtained from UserPreferenceRead
  326. pszBuffer - buffer into which to store list of device names
  327. cbBuffer - length of buffer in bytes
  328. return values are:
  329. ERROR_NOT_ENOUGH_MEMORY
  330. NERR_BufTooSmall
  331. USES: Returns a list of all devices for which the file image
  332. lists a connection, separated by nulls, with a null-null at
  333. the end. For example, "LPT1:\0D:\0F:\0" (don't forget the
  334. extra '\0' implicit in "" strings)
  335. CAVEATS: Note that it is the caller's reponsibility to deal with
  336. the case where the user is not logged on and should therefore
  337. see no unavailable connections.
  338. HISTORY:
  339. chuckc 03/07/91 Created
  340. jonn 05/28/91 Restructured to allow preferences in LMUSER.INI
  341. **************************************************************************/
  342. APIERR UserPrefProfileEnum(
  343. PFILEIMAGE pFileImage,
  344. PSZ pszBuffer, // returns NULL-NULL list of device names
  345. USHORT cbBuffer // length of above buffer in bytes
  346. ) ;
  347. /*************************************************************************
  348. NAME: UserPrefProfileSet
  349. SYNOPSIS: Sets a device-connection user preference
  350. INTERFACE: UserPrefProfileSet( pFileImage, cpszDeviceName,
  351. cpszRemoteName, sAsgType, usResType )
  352. pFileImage - as obtained from UserPreferenceRead
  353. cpszDeviceName - Device to associate with remote resource
  354. cpszRemoteName - name of remote resource (UNCname for LM21)
  355. Use NULL to delete entries
  356. sAsgType - asgType of remote device
  357. usResType - resType of remote device (ignored for LM21)
  358. return values as UserPrefStringSet
  359. ERROR_INVALID_PARAMETER: bad cpszDeviceName
  360. USES: as UserPrefStringSet for device-connection parameters
  361. CAVEATS: as UserPrefStringSet for device-connection parameters
  362. The user is expected to ensure that usResType corresponds
  363. to the type of the remote resource, and that device
  364. pszDeviceName can be connected to a resource of that type.
  365. Note that it is the caller's reponsibility to deal with
  366. the case where the user is not logged on and should therefore
  367. see no unavailable connections.
  368. NOTES: as UserPrefStringSet for device-connection parameters
  369. LM21 programs should pass 0 for usResType
  370. Pass cpszRemoteName==NULL to delete device-connection
  371. parameters.
  372. HISTORY:
  373. chuckc 03/07/91 Created
  374. jonn 05/28/91 Restructured to allow preferences in LMUSER.INI
  375. **************************************************************************/
  376. APIERR UserPrefProfileSet(
  377. PFILEIMAGE pFileImage,
  378. CPSZ cpszDeviceName,
  379. CPSZ cpszRemoteName,
  380. short sAsgType, // as ui1_asg_type / ui2_asg_type
  381. unsigned short usResType // as ui2_res_type
  382. ) ;
  383. /*************************************************************************
  384. NAME: UserPrefProfileTrim
  385. SYNOPSIS: Trims an file image to contain only device-connection
  386. components.
  387. INTERFACE: UserPrefProfileTrim( pFileImage )
  388. pFileImage - as obtained from UserPreferenceRead
  389. USES: This is meant for use where a "cache" of device
  390. connection parameters will be held for a long time.
  391. RETURNS: NERR_NOT_ENOUGH_MEMORY
  392. Does not fail if component not found
  393. CAVEATS: Do not write a trimmed file image -- this will destroy all
  394. parameters which are not device connections!
  395. NOTES: Free the file image if this API fails.
  396. HISTORY:
  397. jonn 06/26/91 Created
  398. **************************************************************************/
  399. APIERR UserPrefProfileTrim(
  400. PFILEIMAGE pFileImage
  401. ) ;
  402. #endif // _NEWPROF_H_