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.

298 lines
8.4 KiB

  1. /******************************************************************************
  2. *
  3. * WFPROF.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: M:\nt\private\utils\citrix\wfprof\VCS\wfprof.c $
  16. *
  17. * Rev 1.3 Jun 26 1997 18:26:30 billm
  18. * move to WF40 tree
  19. *
  20. * Rev 1.2 23 Jun 1997 16:20:02 butchd
  21. * update
  22. *
  23. * Rev 1.1 29 Apr 1997 21:35:20 kurtp
  24. * I fixed a bug in this file, update, duh!
  25. *
  26. *******************************************************************************/
  27. #include <nt.h>
  28. #include <ntrtl.h> // NT runtime library definitions
  29. #include <nturtl.h>
  30. #include <windows.h>
  31. #include <stdio.h>
  32. #include <stdlib.h>
  33. #include <string.h>
  34. #include <lmerr.h>
  35. #include <lmcons.h>
  36. #include <lmaccess.h>
  37. #include <lmserver.h>
  38. #include <lmremutl.h>
  39. #include <citrix\winstaw.h>
  40. #include <utilsub.h>
  41. #include "wfprof.h"
  42. /*=============================================================================
  43. == Macros
  44. =============================================================================*/
  45. /*=============================================================================
  46. == Variables
  47. =============================================================================*/
  48. WCHAR * pServerName = NULL;
  49. WCHAR DomainName[MAX_IDS_LEN + 1];
  50. WCHAR SourceUser[MAX_IDS_LEN + 1];
  51. WCHAR DestinationUser[MAX_IDS_LEN + 1];
  52. WCHAR WFProfilePath[MAX_IDS_LEN + 1];
  53. /*=============================================================================
  54. == Data types and definitions
  55. =============================================================================*/
  56. USHORT copy_flag = FALSE;
  57. USHORT update_flag = FALSE;
  58. USHORT query_flag = FALSE;
  59. USHORT help_flag = FALSE;
  60. USHORT local_flag = FALSE;
  61. TOKMAP ptm[] = {
  62. {L" ", TMFLAG_REQUIRED, TMFORM_STRING, MAX_IDS_LEN, SourceUser},
  63. {L" ", TMFLAG_OPTIONAL, TMFORM_STRING, MAX_IDS_LEN, DestinationUser},
  64. {L"/Domain", TMFLAG_OPTIONAL, TMFORM_STRING, MAX_IDS_LEN, DomainName},
  65. {L"/Profile", TMFLAG_OPTIONAL, TMFORM_STRING, MAX_IDS_LEN, WFProfilePath},
  66. {L"/Local", TMFLAG_OPTIONAL, TMFORM_BOOLEAN, sizeof(USHORT), &local_flag},
  67. {L"/Copy", TMFLAG_OPTIONAL, TMFORM_BOOLEAN, sizeof(USHORT), &copy_flag},
  68. {L"/Q", TMFLAG_OPTIONAL, TMFORM_BOOLEAN, sizeof(USHORT), &query_flag},
  69. {L"/Update", TMFLAG_OPTIONAL, TMFORM_BOOLEAN, sizeof(USHORT), &update_flag},
  70. {L"/?", TMFLAG_OPTIONAL, TMFORM_BOOLEAN, sizeof(USHORT), &help_flag},
  71. {0, 0, 0, 0, 0}
  72. };
  73. #define SOURCE_USER (ptm[0].tmFlag & TMFLAG_PRESENT)
  74. #define DEST_USER (ptm[1].tmFlag & TMFLAG_PRESENT)
  75. #define DOMAIN (ptm[2].tmFlag & TMFLAG_PRESENT)
  76. #define PROFILE_PATH (ptm[3].tmFlag & TMFLAG_PRESENT)
  77. #define LOCAL (ptm[4].tmFlag & TMFLAG_PRESENT)
  78. /*=============================================================================
  79. == Functions
  80. =============================================================================*/
  81. void Usage( BOOLEAN bError );
  82. /*******************************************************************************
  83. *
  84. * main
  85. *
  86. ******************************************************************************/
  87. int __cdecl
  88. main( int argc, char **argv )
  89. {
  90. int i;
  91. int Error;
  92. ULONG ReturnLength;
  93. WCHAR **argvW;
  94. USERCONFIG UserConfig;
  95. /*
  96. * Massage the new command line to look like an argv[] type
  97. * because ParseCommandLine() depends on this format
  98. */
  99. argvW = (WCHAR **)malloc( sizeof(WCHAR *) * (argc+1) );
  100. if(argvW == NULL) {
  101. printf( "Error: malloc failed\n" );
  102. return(FAILURE);
  103. }
  104. for( i=0; i < argc; i++ ) {
  105. argvW[i] = (WCHAR *)malloc( (strlen(argv[i]) + 1) * sizeof(WCHAR) );
  106. wsprintf( argvW[i], L"%S", argv[i] );
  107. }
  108. argvW[argc] = NULL;
  109. /*
  110. * parse the cmd line without parsing the program name (argc-1, argv+1)
  111. */
  112. Error = ParseCommandLine(argc-1, argvW+1, ptm, PCL_FLAG_NO_CLEAR_MEMORY);
  113. /*
  114. * Check for error from ParseCommandLine
  115. */
  116. if ( help_flag ) {
  117. Usage(FALSE);
  118. return(SUCCESS);
  119. }
  120. else if ( Error ||
  121. (!copy_flag && !update_flag && !query_flag) ||
  122. (copy_flag && update_flag) ||
  123. (copy_flag && query_flag) ||
  124. (update_flag && query_flag) ||
  125. (copy_flag && !DEST_USER) ||
  126. (update_flag && !PROFILE_PATH) ||
  127. (!DOMAIN && !LOCAL) ||
  128. (DOMAIN && LOCAL) ) {
  129. Usage(TRUE);
  130. return(FAILURE);
  131. }
  132. /*
  133. * Get server name for domain name
  134. */
  135. if ( LOCAL ) {
  136. pServerName = NULL;
  137. Error = ERROR_SUCCESS;
  138. }
  139. else {
  140. Error = NetGetDCName( (WCHAR)NULL, DomainName, (LPBYTE *)&pServerName );
  141. }
  142. if ( Error == ERROR_SUCCESS ) {
  143. /*
  144. * Update or Query
  145. */
  146. if ( update_flag || query_flag ) {
  147. query_it:
  148. Error = RegUserConfigQuery( pServerName,
  149. SourceUser,
  150. &UserConfig,
  151. sizeof(UserConfig),
  152. &ReturnLength );
  153. if ( Error == ERROR_SUCCESS ) {
  154. if ( query_flag ) {
  155. Message( IDS_QUERY,
  156. DomainName,
  157. SourceUser,
  158. UserConfig.WFProfilePath );
  159. }
  160. else {
  161. wcscpy( UserConfig.WFProfilePath, WFProfilePath );
  162. Error = RegUserConfigSet( pServerName,
  163. SourceUser,
  164. &UserConfig,
  165. sizeof(UserConfig) );
  166. if ( Error == ERROR_SUCCESS ) {
  167. query_flag = TRUE;
  168. goto query_it;
  169. }
  170. else {
  171. ErrorPrintf(IDS_ERROR_SET_USER_CONFIG, Error, Error);
  172. }
  173. }
  174. }
  175. else {
  176. ErrorPrintf(IDS_ERROR_GET_USER_CONFIG, Error, Error);
  177. }
  178. }
  179. else if ( copy_flag ) {
  180. Error = RegUserConfigQuery( pServerName,
  181. SourceUser,
  182. &UserConfig,
  183. sizeof(UserConfig),
  184. &ReturnLength );
  185. if ( Error == ERROR_SUCCESS ) {
  186. if ( query_flag ) {
  187. Message( IDS_QUERY,
  188. DomainName,
  189. SourceUser,
  190. UserConfig.WFProfilePath );
  191. }
  192. else {
  193. if ( PROFILE_PATH ) {
  194. wcscpy( UserConfig.WFProfilePath, WFProfilePath );
  195. }
  196. Error = RegUserConfigSet( pServerName,
  197. DestinationUser,
  198. &UserConfig,
  199. sizeof(UserConfig) );
  200. if ( Error != ERROR_SUCCESS ) {
  201. ErrorPrintf(IDS_ERROR_SET_USER_CONFIG, Error, Error);
  202. }
  203. }
  204. }
  205. else {
  206. ErrorPrintf(IDS_ERROR_GET_USER_CONFIG, Error, Error);
  207. }
  208. }
  209. }
  210. else {
  211. ErrorPrintf(IDS_ERROR_GET_DC, Error, Error);
  212. }
  213. return( (Error == ERROR_SUCCESS ? SUCCESS : FAILURE) );
  214. }
  215. /*******************************************************************************
  216. *
  217. * Usage
  218. *
  219. * Output the usage message for this utility.
  220. *
  221. * ENTRY:
  222. * bError (input)
  223. * TRUE if the 'invalid parameter(s)' message should preceed the usage
  224. * message and the output go to stderr; FALSE for no such error
  225. * string and output goes to stdout.
  226. *
  227. * EXIT:
  228. *
  229. *
  230. ******************************************************************************/
  231. void
  232. Usage( BOOLEAN bError )
  233. {
  234. if ( bError ) {
  235. ErrorPrintf(IDS_ERROR_INVALID_PARAMETERS);
  236. }
  237. Message(IDS_USAGE1);
  238. Message(IDS_USAGE2);
  239. Message(IDS_USAGE3);
  240. } /* Usage() */