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.

370 lines
11 KiB

  1. /******************************************************************************
  2. *
  3. * TSPROF.C
  4. *
  5. * Description:
  6. *
  7. * Copyright Citrix Systems Inc. 1997
  8. *
  9. * Copyright (c) 1998 - 1999 Microsoft Corporation
  10. *
  11. * Author: Kurt Perry (kurtp)
  12. *
  13. * Date: 11-Apr-1997
  14. *
  15. * $Log: N:\nt\private\utils\citrix\wfprof\VCS\tsprof.c $
  16. *
  17. * Rev 1.5 May 04 1998 17:46:34 tyl
  18. * bug 2019 - oem to ansi
  19. *
  20. * Rev 1.4 Jan 30 1998 20:46:22 yufengz
  21. * change the file name
  22. *
  23. * Rev 1.3 Jun 26 1997 18:26:30 billm
  24. * move to WF40 tree
  25. *
  26. * Rev 1.2 23 Jun 1997 16:20:02 butchd
  27. * update
  28. *
  29. * Rev 1.1 29 Apr 1997 21:35:20 kurtp
  30. * I fixed a bug in this file, update, duh!
  31. *
  32. *******************************************************************************/
  33. #include <nt.h>
  34. #include <ntrtl.h> // NT runtime library definitions
  35. #include <nturtl.h>
  36. #include <windows.h>
  37. #include <stdio.h>
  38. #include <stdlib.h>
  39. #include <string.h>
  40. #include <locale.h>
  41. #include <lmerr.h>
  42. #include <lmcons.h>
  43. #include <lmaccess.h>
  44. #include <lmserver.h>
  45. #include <lmremutl.h>
  46. #include <winstaw.h>
  47. #include <utilsub.h>
  48. #include <printfoa.h>
  49. #include "wfprof.h"
  50. /*=============================================================================
  51. == Macros
  52. =============================================================================*/
  53. /*=============================================================================
  54. == Variables
  55. =============================================================================*/
  56. WCHAR * pServerName = NULL;
  57. WCHAR DomainName[MAX_IDS_LEN + 1];
  58. WCHAR SourceUser[MAX_IDS_LEN + 1];
  59. WCHAR DestinationUser[MAX_IDS_LEN + 1];
  60. WCHAR WFProfilePath[MAX_IDS_LEN + 1];
  61. /*=============================================================================
  62. == Data types and definitions
  63. =============================================================================*/
  64. USHORT copy_flag = FALSE;
  65. USHORT update_flag = FALSE;
  66. USHORT query_flag = FALSE;
  67. USHORT help_flag = FALSE;
  68. USHORT local_flag = FALSE;
  69. TOKMAP ptm[] = {
  70. {L" ", TMFLAG_REQUIRED, TMFORM_STRING, MAX_IDS_LEN, SourceUser},
  71. {L" ", TMFLAG_OPTIONAL, TMFORM_STRING, MAX_IDS_LEN, DestinationUser},
  72. {L"/Domain", TMFLAG_OPTIONAL, TMFORM_STRING, MAX_IDS_LEN, DomainName},
  73. {L"/Profile", TMFLAG_OPTIONAL, TMFORM_STRING, MAX_IDS_LEN, WFProfilePath},
  74. {L"/Local", TMFLAG_OPTIONAL, TMFORM_BOOLEAN, sizeof(USHORT), &local_flag},
  75. {L"/Copy", TMFLAG_OPTIONAL, TMFORM_BOOLEAN, sizeof(USHORT), &copy_flag},
  76. {L"/Q", TMFLAG_OPTIONAL, TMFORM_BOOLEAN, sizeof(USHORT), &query_flag},
  77. {L"/Update", TMFLAG_OPTIONAL, TMFORM_BOOLEAN, sizeof(USHORT), &update_flag},
  78. {L"/?", TMFLAG_OPTIONAL, TMFORM_BOOLEAN, sizeof(USHORT), &help_flag},
  79. {0, 0, 0, 0, 0}
  80. };
  81. #define SOURCE_USER (ptm[0].tmFlag & TMFLAG_PRESENT)
  82. #define DEST_USER (ptm[1].tmFlag & TMFLAG_PRESENT)
  83. #define DOMAIN (ptm[2].tmFlag & TMFLAG_PRESENT)
  84. #define PROFILE_PATH (ptm[3].tmFlag & TMFLAG_PRESENT)
  85. #define LOCAL (ptm[4].tmFlag & TMFLAG_PRESENT)
  86. /*=============================================================================
  87. == Functions
  88. =============================================================================*/
  89. void Usage( BOOLEAN bError );
  90. /*******************************************************************************
  91. *
  92. * main
  93. *
  94. ******************************************************************************/
  95. int __cdecl
  96. main( int argc, char **argv )
  97. {
  98. int i;
  99. int Error;
  100. ULONG ReturnLength;
  101. WCHAR **argvW;
  102. USERCONFIG UserConfig;
  103. setlocale(LC_ALL, ".OCP");
  104. /*
  105. * Massage the command line.
  106. */
  107. argvW = MassageCommandLine((DWORD)argc);
  108. if (argvW == NULL) {
  109. ErrorPrintf(IDS_ERROR_MALLOC);
  110. return(FAILURE);
  111. }
  112. /*
  113. * parse the cmd line without parsing the program name (argc-1, argv+1)
  114. */
  115. Error = ParseCommandLine(argc-1, argvW+1, ptm, PCL_FLAG_NO_CLEAR_MEMORY);
  116. /*
  117. * Check for error from ParseCommandLine
  118. */
  119. if ( help_flag ) {
  120. Usage(FALSE);
  121. return(SUCCESS);
  122. }
  123. else if ( Error ||
  124. (!copy_flag && !update_flag && !query_flag) ||
  125. (copy_flag && update_flag) ||
  126. (copy_flag && query_flag) ||
  127. (update_flag && query_flag) ||
  128. (copy_flag && !DEST_USER) ||
  129. (update_flag && !PROFILE_PATH) ||
  130. (!DOMAIN && !LOCAL) ||
  131. (DOMAIN && LOCAL) ) {
  132. Usage(TRUE);
  133. return(FAILURE);
  134. }
  135. /*
  136. * Get server name for domain name
  137. */
  138. if ( LOCAL ) {
  139. pServerName = NULL;
  140. Error = ERROR_SUCCESS;
  141. }
  142. else {
  143. Error = NetGetDCName( (WCHAR)NULL, DomainName, (LPBYTE *)&pServerName );
  144. }
  145. if ( Error == ERROR_SUCCESS ) {
  146. /*
  147. * Update or Query
  148. */
  149. if ( update_flag || query_flag ) {
  150. query_it:
  151. Error = RegUserConfigQuery( pServerName,
  152. SourceUser,
  153. &UserConfig,
  154. sizeof(UserConfig),
  155. &ReturnLength );
  156. if(Error != ERROR_SUCCESS)
  157. {
  158. Error = RegDefaultUserConfigQuery(pServerName,
  159. &UserConfig, // address for userconfig buffer
  160. sizeof(UserConfig), // size of buffer
  161. &ReturnLength);
  162. }
  163. if ( Error == ERROR_SUCCESS )
  164. {
  165. if ( query_flag )
  166. {
  167. TCHAR tchOutput[ 512 ];
  168. TCHAR tchFormat[ 256 ];
  169. DWORD_PTR dw[ 3 ];
  170. dw[ 0 ] = (DWORD_PTR)(ULONG_PTR)&DomainName[0];
  171. dw[ 1 ] = (DWORD_PTR)(ULONG_PTR)&SourceUser[0];
  172. dw[ 2 ] = (DWORD_PTR)(ULONG_PTR)&UserConfig.WFProfilePath[0];
  173. LoadString( NULL , IDS_QUERY3 , tchFormat , sizeof( tchFormat ) / sizeof( TCHAR ) );
  174. FormatMessage( FORMAT_MESSAGE_FROM_STRING | FORMAT_MESSAGE_ARGUMENT_ARRAY,
  175. tchFormat ,
  176. 0 ,
  177. 0 ,
  178. tchOutput ,
  179. sizeof( tchOutput ) / sizeof( TCHAR ) ,
  180. ( va_list * )&dw );
  181. My_wprintf( tchOutput );
  182. /*
  183. StringMessage( IDS_QUERY1,
  184. DomainName);
  185. StringMessage( IDS_QUERY2,
  186. SourceUser);
  187. StringMessage( IDS_QUERY3,
  188. UserConfig.WFProfilePath );
  189. */
  190. }
  191. else
  192. {
  193. wcscpy( UserConfig.WFProfilePath, WFProfilePath );
  194. Error = RegUserConfigSet( pServerName,
  195. SourceUser,
  196. &UserConfig,
  197. sizeof(UserConfig) );
  198. if ( Error == ERROR_SUCCESS )
  199. {
  200. query_flag = TRUE;
  201. goto query_it;
  202. }
  203. else
  204. {
  205. ErrorPrintf(IDS_ERROR_SET_USER_CONFIG, Error, Error);
  206. }
  207. }
  208. }
  209. else {
  210. ErrorPrintf(IDS_ERROR_GET_USER_CONFIG, Error, Error);
  211. }
  212. }
  213. else if ( copy_flag ) {
  214. Error = RegUserConfigQuery( pServerName,
  215. SourceUser,
  216. &UserConfig,
  217. sizeof(UserConfig),
  218. &ReturnLength );
  219. if ( Error == ERROR_SUCCESS )
  220. {
  221. if ( query_flag )
  222. {
  223. TCHAR tchOutput[ 512 ];
  224. TCHAR tchFormat[ 256 ];
  225. ULONG_PTR dw[ 3 ];
  226. dw[ 0 ] = (ULONG_PTR)&DomainName[0];
  227. dw[ 1 ] = (ULONG_PTR)&SourceUser[0];
  228. dw[ 2 ] = (ULONG_PTR)&UserConfig.WFProfilePath[0];
  229. LoadString( NULL , IDS_QUERY3 , tchFormat , sizeof( tchFormat ) / sizeof( TCHAR ) );
  230. FormatMessage( FORMAT_MESSAGE_FROM_STRING | FORMAT_MESSAGE_ARGUMENT_ARRAY,
  231. tchFormat ,
  232. 0 ,
  233. 0 ,
  234. tchOutput ,
  235. sizeof( tchOutput ) / sizeof( TCHAR ) ,
  236. ( va_list * )&dw );
  237. My_wprintf( tchOutput );
  238. /*
  239. StringMessage( IDS_QUERY1,
  240. DomainName);
  241. StringMessage( IDS_QUERY2,
  242. SourceUser);
  243. StringMessage( IDS_QUERY3,
  244. UserConfig.WFProfilePath );
  245. */
  246. }
  247. else {
  248. if ( PROFILE_PATH ) {
  249. wcscpy( UserConfig.WFProfilePath, WFProfilePath );
  250. }
  251. Error = RegUserConfigSet( pServerName,
  252. DestinationUser,
  253. &UserConfig,
  254. sizeof(UserConfig) );
  255. if ( Error != ERROR_SUCCESS ) {
  256. ErrorPrintf(IDS_ERROR_SET_USER_CONFIG, Error, Error);
  257. }
  258. }
  259. }
  260. else {
  261. ErrorPrintf(IDS_ERROR_GET_USER_CONFIG, Error, Error);
  262. }
  263. }
  264. }
  265. else {
  266. ErrorPrintf(IDS_ERROR_GET_DC, Error, Error);
  267. }
  268. return( (Error == ERROR_SUCCESS ? SUCCESS : FAILURE) );
  269. }
  270. /*******************************************************************************
  271. *
  272. * Usage
  273. *
  274. * Output the usage message for this utility.
  275. *
  276. * ENTRY:
  277. * bError (input)
  278. * TRUE if the 'invalid parameter(s)' message should preceed the usage
  279. * message and the output go to stderr; FALSE for no such error
  280. * string and output goes to stdout.
  281. *
  282. * EXIT:
  283. *
  284. *
  285. ******************************************************************************/
  286. void
  287. Usage( BOOLEAN bError )
  288. {
  289. if ( bError ) {
  290. ErrorPrintf(IDS_ERROR_INVALID_PARAMETERS);
  291. }
  292. Message(IDS_USAGE1);
  293. Message(IDS_USAGE2);
  294. Message(IDS_USAGE3);
  295. } /* Usage() */