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.

352 lines
8.0 KiB

  1. /********************************************************************/
  2. /** Microsoft LAN Manager **/
  3. /** Copyright(c) Microsoft Corp., 1990-1991 **/
  4. /********************************************************************/
  5. /*++
  6. Filename:
  7. USRPARMS.C
  8. Description:
  9. Contains code to get set and initialize the user_parms field.
  10. The 49-byte user params structure is laid out as follows:
  11. NOTE that the buffer is 48 byte + NULL byte.
  12. +-+-------------------+-+------------------------+-+
  13. |m|Macintosh Pri Group|d|Dial-in CallBack Number |0|
  14. +-+-------------------+-+------------------------+-+
  15. | | |
  16. +---------------------+------ Signature +- NULL terminator
  17. The routines were originally written for RAS 1.0 and deal only with
  18. multi-byte strings. For NT unicodification, wcstombs() and mbstowcs()
  19. have been used to convert string formats. Eventually these routines
  20. can be converted to be native Unicode.
  21. History:
  22. 20/3/91 Narendra Gidwani Created original version
  23. July 14 92 Janakiram Cherala Modified for NT
  24. May 13 93 Andy Herron Coexist with other apps using user parms
  25. --*/
  26. #include <windows.h>
  27. #include <string.h>
  28. #include <lm.h>
  29. #include <stdlib.h>
  30. #include <rasman.h>
  31. #include <rasppp.h>
  32. #include "usrparms.h"
  33. /*++
  34. Routine Description:
  35. Initializes the user params buffer.
  36. Arguments:
  37. UserParms - Pointer to a USER_PARMS structure which is initialized.
  38. After initializing, the UserParms structure would look
  39. like:
  40. 0 49
  41. +-+-------------------+-+------------------------+-+
  42. |m|: |d|1 |0|
  43. +-+-------------------+-+------------------------+-+
  44. Return Value:
  45. None.
  46. --*/
  47. void InitUsrParams(
  48. USER_PARMS *pUserParms
  49. )
  50. {
  51. //
  52. // Null the whole structure and check for GP fault.
  53. //
  54. memset(pUserParms, '\0', sizeof(USER_PARMS));
  55. //
  56. // Initialize Macintosh fields
  57. //
  58. pUserParms->up_MACid = UP_CLIENT_MAC;
  59. memset(pUserParms->up_PriGrp, ' ', UP_LEN_MAC);
  60. pUserParms->up_PriGrp[0] = ':';
  61. pUserParms->up_MAC_Terminater = ' ';
  62. //
  63. // Initialize RAS fields
  64. //
  65. pUserParms->up_DIALid = UP_CLIENT_DIAL;
  66. pUserParms->up_CBNum[0] = 1;
  67. }
  68. USHORT SetUsrParams(
  69. USHORT InfoType,
  70. LPWSTR InBuf,
  71. LPWSTR OutBuf
  72. )
  73. /*++
  74. Routine Description:
  75. Sets either dialin information or mac information into
  76. the user_parms field in the proper format.
  77. Arguments:
  78. InfoType - An unsigned short representing the type of information
  79. to be set: UP_CLIENT_DIAL or UP_CLIENT_MAC.
  80. InBuf - Pointer to string ie either call back number and permissions
  81. for dialin or primary group name for Macintosh.
  82. OutBuf - Pointer to a USER_PARMS that has been initialized or is in
  83. the correct format. This is loaded with the information
  84. passed in InBuf.
  85. Return Value:
  86. 0 indicating success
  87. ERROR_BAD_FORMAT - failure.
  88. ERROR_INVALID_PARAMETER - failure
  89. --*/
  90. {
  91. USHORT len;
  92. char Buffer[sizeof(USER_PARMS)];
  93. char uBuffer[sizeof(USER_PARMS)];
  94. USER_PARMS FAR * OutBufPtr;
  95. char FAR * InBufPtr = Buffer;
  96. //
  97. // convert the unicode string to multi byte for processing
  98. //
  99. wcstombs(Buffer, InBuf, sizeof(USER_PARMS));
  100. wcstombs(uBuffer, OutBuf, sizeof(USER_PARMS));
  101. OutBufPtr = (USER_PARMS FAR *)uBuffer;
  102. //
  103. // Validate InfoType
  104. //
  105. if (InfoType != UP_CLIENT_MAC && InfoType != UP_CLIENT_DIAL )
  106. {
  107. return( ERROR_INVALID_PARAMETER );
  108. }
  109. //
  110. // Make sure the field to be set is in the correct format
  111. //
  112. if (( OutBufPtr->up_MACid != UP_CLIENT_MAC ) ||
  113. ( OutBufPtr->up_DIALid != UP_CLIENT_DIAL ) )
  114. {
  115. return( ERROR_BAD_FORMAT );
  116. }
  117. len = (USHORT)strlen( InBufPtr );
  118. switch ( InfoType )
  119. {
  120. case UP_CLIENT_MAC:
  121. if ( len > UP_LEN_MAC )
  122. {
  123. return( ERROR_BAD_FORMAT );
  124. }
  125. //
  126. // Set the MAC information
  127. //
  128. if ( len > 0 )
  129. {
  130. strcpy( OutBufPtr->up_PriGrp, InBufPtr );
  131. }
  132. OutBufPtr->up_PriGrp[len] = ':';
  133. break;
  134. case UP_CLIENT_DIAL:
  135. if ( len > UP_LEN_DIAL )
  136. {
  137. return( ERROR_BAD_FORMAT );
  138. }
  139. //
  140. // Set the dialin information
  141. //
  142. if ( len > 0 )
  143. {
  144. strcpy( OutBufPtr->up_CBNum, InBufPtr );
  145. }
  146. break;
  147. default:
  148. return( ERROR_INVALID_PARAMETER );
  149. }
  150. //
  151. // convert multicode string to unicode
  152. //
  153. mbstowcs(OutBuf, uBuffer, sizeof(USER_PARMS));
  154. return( 0 );
  155. }
  156. USHORT FAR APIENTRY
  157. MprGetUsrParams(
  158. USHORT InfoType,
  159. LPWSTR InBuf,
  160. LPWSTR OutBuf
  161. )
  162. /*++
  163. Routine Description:
  164. Extracts dialin or mac information from the user_parms
  165. Arguments:
  166. InfoType - An unsigned short representing the
  167. type of information to be extracted.
  168. UP_CLIENT_DIAL or UP_CLIENT_MAC.
  169. InBuf - Pointer to a USER_PARMS that has been
  170. initialized or is in the correct format.
  171. and contains the information to be
  172. extracted. This should be NULL
  173. terminated.
  174. OutBuf - Contains the extracted information.
  175. This buffer should be large enough to
  176. hold the information requested as well
  177. as a NULL terminater.
  178. Returns:
  179. 0 on success
  180. ERROR_BAD_FORMAT - failure
  181. ERROR_INVALID_PARAMETER - failure
  182. --*/
  183. {
  184. USER_PARMS FAR * InBufPtr;
  185. USHORT len;
  186. char FAR * TerminaterPtr;
  187. char FAR * OutBufPtr;
  188. char Buffer[sizeof(USER_PARMS)];
  189. char uBuffer[sizeof(USER_PARMS)];
  190. // convert string to mulitbyte before processing
  191. wcstombs(Buffer, InBuf, sizeof(USER_PARMS));
  192. InBufPtr = (USER_PARMS FAR *)Buffer;
  193. // Validate InfoType
  194. //
  195. if ( InfoType != UP_CLIENT_MAC && InfoType != UP_CLIENT_DIAL )
  196. return( ERROR_INVALID_PARAMETER );
  197. // First make sure the user parms field is at least the minimum length.
  198. //
  199. len = (USHORT)strlen( Buffer );
  200. // 3 = 1 for MAC_Terminater + 1 for up_MACid + 1 for up_DIALid
  201. //
  202. if ( len < ( UP_LEN_MAC + 3 ) )
  203. return( ERROR_BAD_FORMAT );
  204. // Check for correct signatures.
  205. //
  206. if ( ( InBufPtr->up_MACid != UP_CLIENT_MAC) ||
  207. ( InBufPtr->up_DIALid != UP_CLIENT_DIAL ))
  208. return( ERROR_BAD_FORMAT );
  209. switch( InfoType ) {
  210. case UP_CLIENT_MAC:
  211. OutBufPtr = InBufPtr->up_PriGrp;
  212. // Validate the information
  213. //
  214. if ( ( TerminaterPtr = strchr( OutBufPtr, ':')) == NULL)
  215. return( ERROR_BAD_FORMAT );
  216. if ( ( len = (USHORT)( TerminaterPtr - OutBufPtr ) ) > UP_LEN_MAC)
  217. return( ERROR_BAD_FORMAT );
  218. // Copy the data
  219. //
  220. strcpy( uBuffer, OutBufPtr);
  221. break;
  222. case UP_CLIENT_DIAL:
  223. OutBufPtr = InBufPtr->up_CBNum;
  224. len = (USHORT)strlen( OutBufPtr );
  225. //
  226. // AndyHe... Peal off all trailing blanks
  227. //
  228. while (len > 1 && *(OutBufPtr+len-1) == ' ')
  229. {
  230. *(OutBufPtr+len-1) = '\0';
  231. len--;
  232. }
  233. if ( len > UP_LEN_DIAL)
  234. return( ERROR_BAD_FORMAT );
  235. if ( len > 0 )
  236. strcpy( uBuffer, OutBufPtr);
  237. break;
  238. default:
  239. return( ERROR_INVALID_PARAMETER );
  240. }
  241. // convert string to unicode before returning
  242. mbstowcs(OutBuf, uBuffer, sizeof(USER_PARMS));
  243. return( 0 );
  244. }