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.

364 lines
11 KiB

  1. /**********************************************************************/
  2. /** Microsoft LAN Manager **/
  3. /** Copyright(c) Microsoft Corp., 1990 **/
  4. /**********************************************************************/
  5. /*
  6. winprof.hxx
  7. High-level profile APIs (PROFILE object)
  8. The PROFILE class contains a higher-level interface to the
  9. UserProfile APIs. It is meant solely for use by WINNET. All WINNET
  10. modules should use the PROFILE APIs rather than going directly to
  11. the UserProfile APIs. Applications other than WINNET will have to
  12. use the UserProfile APIs.
  13. The PROFILE class adds the following to the basic UserProfile APIs:
  14. - Establishes connections as specified in profile, including
  15. prompting for password
  16. - Displays error popups as appropriate during profile load
  17. Note that the UserProfile APIs which the PROFILE class accesses
  18. use access global variables. For this reason, it never makes sense
  19. to have more than one PROFILE object, and it is generally not
  20. desirable to have a PROFILE object of other than global scope.
  21. Those PROFILE APIs which take an HWND parameter may give control to
  22. Windows or call Windows APIs, but those which do not take an HWND
  23. parameter will never do either. Thus, of the exported APIs, only
  24. PROFILE::Load is liable to compact memory.
  25. Several PROFILE methods take a UINT *puWnErr parameter in order to
  26. return an auxiliary WN_ error code. In these cases, the following
  27. combinations of error codes are possible:
  28. Return code: Auxiliary: Meaning
  29. NERR_Success WN_SUCCESS Operation was successful
  30. NERR_Success WN_CANCEL Operation cancelled, error
  31. already displayed
  32. NERR_Success WN_CONTINUE Error occurred, error
  33. already displayed
  34. <other> <other> Error has not been displayed
  35. PROFILE::Init
  36. Initializes the PROFILE object. Call this before calling any other
  37. PROFILE method. Call this method while in the (DS register) context
  38. of the shell rather than the context of any application.
  39. Return Values:
  40. NERR_Success Success
  41. ERROR_NOT_ENOUGH_MEMORY Out of memory
  42. PROFILE::Free
  43. Releases the PROFILE object. Call this after calling all other
  44. PROFILE methods.
  45. Return Values:
  46. NERR_Success Success
  47. PROFILE::Load
  48. Loads one device connection from the user profile, or loads all
  49. device connections from the user profile. Also returns an advisory
  50. parameter indicating whether the connection was cancelled, or
  51. whether some error has already been reported; note that the return
  52. code is NERR_Success if the dialog is cancelled.
  53. Return Values:
  54. NERR_Success Success
  55. ERROR_NOT_ENOUGH_MEMORY Out of memory
  56. other Misc. net error
  57. PROFILE::Query
  58. Asks about a specific connection in the user profile.
  59. If PROFILE::Query returns NERR_Success, the other fields are valid.
  60. sResourceType is one of the values of field use_info_1.ui1_arg_type.
  61. sResourceName_Type is one of the values of field use_info_2.ui1_res_type.
  62. Return Values:
  63. NERR_Success Success
  64. NERR_UseNotFound Connection not in profile
  65. ERROR_NOT_ENOUGH_MEMORY Out of memory
  66. other Misc. net error
  67. PROFILE::Enum
  68. Lists all connections in the user profile. This list appears as a
  69. list of null-terminated strings with NULL-NULL at the end, e.g.
  70. D:\0G:\0LPT1\0E:\0\0
  71. The list is in no defined order. Pass only a valid pointer to a
  72. BUFFER object.
  73. If PROFILE::Enum returns WN_SUCCESS, the bufDeviceList field is valid.
  74. Return Values:
  75. NERR_Success Success
  76. ERROR_INSUFFICIENT_BUFFER The pbufDeviceList buffer is too small.
  77. ERROR_NOT_ENOUGH_MEMORY Out of memory
  78. other Misc. net error
  79. PROFILE::Change
  80. Saves a connection into the user profile, or removes a connection
  81. from the user profile. PROFILE::Change will prompt the user
  82. before creating a new profile entry.
  83. If cnlsResourceName.strlen() == 0, PROFILE::Change will remove an
  84. existing profile entry.
  85. sResourceType is one of the values of field use_info_1.ui1_arg_type.
  86. usResourceName_Type is one of the values of field use_info_2.ui1_res_type.
  87. Return Values:
  88. NERR_Success Success
  89. ERROR_NOT_ENOUGH_MEMORY Out of memory
  90. other Misc. net error
  91. PROFILE::Remove
  92. Removes a <device,remote> association from the profile. If the
  93. given device is associated with a different remote name than the
  94. one passed as a parameter, this method does nothing but return
  95. success.
  96. This method is intended to be used in disconnect operations.
  97. Then, if the the profile contained a previously unavailable device,
  98. which was left in the profile when a new connection was established
  99. on top of the unavailable device, the profile will be unchanged.
  100. Thus, the previously "covered" or "hidden" unavailable device, now
  101. becomes what the local device is "connected" to again.
  102. cnlsDeviceName is the local device name in the <device,remote> pair.
  103. cnlsResourceName is the remote name in the <device,remote> pair. This
  104. name is typically that DEVICE::QueryRemoteName returns before
  105. DEVICE::Disconnect is called.
  106. Return Values:
  107. NERR_Success Success
  108. other Misc. net error
  109. PROFILE::MapNetError
  110. Miscallaneous utility routine to help convert an NERR_ error code
  111. to a WN_ error code.
  112. PROFILE::DisplayChangeError
  113. Displays an error popup for a failure to change the profile. This
  114. routine should only be used for SYS and NET error codes, not for IERR
  115. error codes.
  116. PROFILE::DisplayLoadError
  117. Displays an error popup for a failure to load some connecion in the
  118. profile. This routine should only be used for SYS and NET error codes,
  119. not for IERR error codes. If you pass fAllowCancel then the user will
  120. also be able to press a cancel button. If they did press cancel, then
  121. *pfDidCancel will be TRUE, otherwise *pfDidCancel will be FALSE. Note
  122. it is only valid to check pfDidCancel if fAllowCancel is TRUE.
  123. FILE HISTORY:
  124. jonn 06-Dec-1990 Created
  125. jonn 27-Dec-1990 Updated to CDD version 0.4
  126. jonn 02-Jan-1991 Integrated into SHELL
  127. jonn 07-Jan-1991 All methods become static
  128. jonn 10-Jan-1991 Removed PSHORT, PUSHORT
  129. jonn 25-Feb-1991 Changed to return NERR error codes
  130. jonn 06-Mar-1991 Added Display[Read|Change]Error
  131. jonn 11-Mar-1991 Modified Display[Load|Change]Error
  132. jonn 14-Mar-1991 Provide LogonUser to UPQuery
  133. rustanl 10-Apr-1991 Added PROFILE::Remove
  134. jonn 22-May-1991 Removed PROFILE_CANCELLED return code
  135. JohnL 18-Jun-1991 Allow user to cancel loading profiles (added
  136. flags to DisplayLoadError & LoadOne).
  137. Yi-HsinS 31-Dec-1991 Unicode work - change char to TCHAR
  138. beng 06-Apr-1992 More Unicode work
  139. */
  140. #ifndef _WINPROF_HXX
  141. #define _WINPROF_HXX
  142. #include <miscapis.hxx> // for USE_RES_DEFAULT
  143. class BUFFER; // declared in uibuffer.hxx
  144. class PROFILE {
  145. public:
  146. /* no constructor or destructor */
  147. static APIERR Init(
  148. );
  149. static APIERR Free(
  150. );
  151. static BOOL ConfirmUsername(
  152. const TCHAR * cpszUsername
  153. );
  154. static APIERR Load(
  155. UINT * puWnErr,
  156. HWND hParent,
  157. NLS_STR *pnlsDeviceName
  158. );
  159. static APIERR Query(
  160. const NLS_STR& cnlsDeviceName,
  161. NLS_STR& nlsResourceName,
  162. short * psResourceType,
  163. unsigned short *pusResourceName_Type = NULL
  164. // LM21 programs should use default
  165. );
  166. static APIERR Enum(
  167. BUFFER * pbufDeviceList
  168. );
  169. static APIERR Change(
  170. const NLS_STR& cnlsDeviceName,
  171. const NLS_STR& cnlsResourceName,
  172. short sResourceType,
  173. unsigned short usResourceName_Type = USE_RES_DEFAULT
  174. // LM21 programs should use default
  175. // defined in miscapis.hxx
  176. );
  177. static APIERR Remove(
  178. const NLS_STR & cnlsDeviceName,
  179. const NLS_STR & cnlsResourceName
  180. );
  181. static UINT MapNetError(
  182. APIERR errNetErr
  183. );
  184. static void DisplayChangeError(
  185. HWND hwndParent,
  186. APIERR errProfErr
  187. );
  188. static void DisplayLoadError(
  189. HWND hwndParent,
  190. APIERR errProfErr,
  191. const TCHAR * pchDevice,
  192. const TCHAR * pchResource,
  193. BOOL fAllowCancel = FALSE,
  194. BOOL *pfDidCancel = NULL
  195. );
  196. protected:
  197. /*
  198. * PROFILE::Read
  199. *
  200. * Reads user profile into cache for the use of the other internal
  201. * profile functions.
  202. *
  203. * Return Values:
  204. * NERR_Success Success
  205. * ERROR_NOT_ENOUGH_MEMORY Out of memory
  206. * other Misc. error
  207. */
  208. static APIERR Read();
  209. /*
  210. * PROFILE::LoadOne
  211. *
  212. * Loads one device connection from the user profile. Used only by
  213. * PROFILE::Load().
  214. *
  215. * Return Values:
  216. * NERR_Success Success
  217. * ERROR_NOT_ENOUGH_MEMORY Out of memory
  218. * other Misc. error
  219. */
  220. static APIERR LoadOne(
  221. UINT * puWnErr,
  222. HWND hParent,
  223. const TCHAR * cpszLogonUser,
  224. NLS_STR nlsDeviceName,
  225. BOOL fAllowCancel = FALSE,
  226. BOOL *pfDidCancel = NULL
  227. );
  228. /*
  229. * PROFILE::LoadAll
  230. *
  231. * Loads all device connections from the user profile. Used only by
  232. * PROFILE::Load().
  233. *
  234. * Return Values:
  235. * NERR_Success Success
  236. * ERROR_NOT_ENOUGH_MEMORY Out of memory
  237. * other Misc. error
  238. */
  239. static APIERR LoadAll(
  240. UINT * puWnErr,
  241. HWND hParent,
  242. const TCHAR * cpszLogonUser
  243. );
  244. /*
  245. * PROFILE::DisplayError
  246. *
  247. * Internal routine for the user of DisplayChangeError and DisplayReadError
  248. */
  249. static void DisplayError(
  250. HWND hwndParent,
  251. MSGID msgidMsgNum,
  252. APIERR errProfErr,
  253. ULONG ulHelpTopic,
  254. const TCHAR * pchDevice,
  255. const TCHAR * pchResource,
  256. BOOL fAllowCancel = FALSE,
  257. BOOL *pfDidCancel = NULL
  258. );
  259. }; // end of class PROFILE
  260. #endif // _WINPROF_HXX