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.

349 lines
8.1 KiB

  1. //Copyright (c) 1998 - 1999 Microsoft Corporation
  2. /******************************************************************************
  3. *
  4. * QAPPSRV.C
  5. *
  6. * query appserver information
  7. *
  8. *
  9. *******************************************************************************/
  10. /*
  11. * Includes
  12. */
  13. #include <windows.h>
  14. #include <stdio.h>
  15. #include <stdlib.h>
  16. #include <string.h>
  17. #include <locale.h>
  18. #include <lm.h>
  19. #include <winstaw.h>
  20. #include <utilsub.h>
  21. #include <printfoa.h>
  22. #include "qappsrv.h"
  23. /*=============================================================================
  24. == Global data
  25. =============================================================================*/
  26. WCHAR CurrentAppServer[MAXNAME];
  27. WCHAR AppServer[MAXNAME];
  28. WCHAR Domain[MAX_IDS_LEN+1];
  29. USHORT help_flag = FALSE;
  30. BOOLEAN MatchedOne = FALSE;
  31. USHORT fAddress = FALSE;
  32. USHORT fNoPage = FALSE;
  33. ULONG Rows = 23;
  34. HANDLE hConIn;
  35. HANDLE hConOut;
  36. TOKMAP ptm[] = {
  37. {L" ", TMFLAG_OPTIONAL, TMFORM_STRING, MAXNAME, AppServer},
  38. {L"/DOMAIN", TMFLAG_OPTIONAL, TMFORM_STRING, MAX_IDS_LEN, Domain},
  39. {L"/ADDRESS", TMFLAG_OPTIONAL, TMFORM_BOOLEAN,sizeof(USHORT), &fAddress},
  40. {L"/Continue",TMFLAG_OPTIONAL, TMFORM_BOOLEAN,sizeof(USHORT), &fNoPage },
  41. {L"/?", TMFLAG_OPTIONAL, TMFORM_BOOLEAN,sizeof(USHORT), &help_flag},
  42. {0, 0, 0, 0, 0}
  43. };
  44. /*=============================================================================
  45. == Internal Functions Defined
  46. =============================================================================*/
  47. void DisplayServer( LPTSTR, LPTSTR );
  48. void Usage( BOOLEAN bError );
  49. int _getch( void );
  50. /*=============================================================================
  51. == Functions used
  52. =============================================================================*/
  53. int AppServerEnum( void );
  54. void TreeTraverse( PTREETRAVERSE );
  55. /*******************************************************************************
  56. *
  57. * main
  58. *
  59. * main routine
  60. *
  61. * ENTRY:
  62. * argc (input)
  63. * number of command line arguments
  64. * argv (input)
  65. * pointer to arrary of command line arguments
  66. *
  67. * EXIT:
  68. * ERROR_SUCCESS - no error
  69. *
  70. ******************************************************************************/
  71. int __cdecl
  72. main(INT argc, CHAR **argv)
  73. {
  74. CONSOLE_SCREEN_BUFFER_INFO ScreenInfo;
  75. PSERVER_INFO_101 pCurrentServer;
  76. ULONG Status;
  77. ULONG rc;
  78. WCHAR **argvW;
  79. int i;
  80. Domain[0] = UNICODE_NULL;
  81. setlocale(LC_ALL, ".OCP");
  82. /*
  83. * Massage the command line.
  84. */
  85. argvW = MassageCommandLine((DWORD)argc);
  86. if (argvW == NULL) {
  87. ErrorPrintf(IDS_ERROR_MALLOC);
  88. return(FAILURE);
  89. }
  90. /*
  91. * parse the cmd line without parsing the program name (argc-1, argv+1)
  92. */
  93. rc = ParseCommandLine(argc-1, argvW+1, ptm, 0);
  94. /*
  95. * Check for error from ParseCommandLine
  96. */
  97. if ( help_flag || (rc && !(rc & PARSE_FLAG_NO_PARMS)) ) {
  98. if ( !help_flag ) {
  99. Usage(TRUE);
  100. return(FAILURE);
  101. } else {
  102. Usage(FALSE);
  103. return(SUCCESS);
  104. }
  105. }
  106. /*
  107. * Get handle to console
  108. */
  109. hConIn = CreateFile( L"CONIN$", GENERIC_READ | GENERIC_WRITE,
  110. FILE_SHARE_READ | FILE_SHARE_WRITE,
  111. NULL, OPEN_EXISTING, 0, NULL );
  112. hConOut = CreateFile( L"CONOUT$", GENERIC_READ | GENERIC_WRITE,
  113. FILE_SHARE_READ | FILE_SHARE_WRITE,
  114. NULL, OPEN_EXISTING, 0, NULL );
  115. /*
  116. * Get the number of rows on the screen
  117. */
  118. if ( GetConsoleScreenBufferInfo( hConOut, &ScreenInfo ) )
  119. Rows = ScreenInfo.dwSize.Y - 2;
  120. /*
  121. * Get current server
  122. */
  123. Status = NetServerGetInfo( NULL, 101, (LPBYTE *) &pCurrentServer );
  124. if ( Status ) {
  125. ErrorPrintf(IDS_ERROR_SERVER_INFO, Status);
  126. PutStdErr( Status, 0 );
  127. return(FAILURE);
  128. }
  129. lstrcpyn( CurrentAppServer, pCurrentServer->sv101_name, MAXNAME );
  130. /*
  131. * Get the names and the count
  132. */
  133. //if ( rc = AppServerEnum() ) {
  134. // ErrorPrintf(IDS_ERROR_SERVER_ENUMERATE, rc );
  135. // PutStdErr( rc, 0 );
  136. // return(FAILURE);
  137. //}
  138. AppServerEnum();
  139. /*
  140. * Display names
  141. */
  142. TreeTraverse( DisplayServer );
  143. if (!MatchedOne)
  144. {
  145. if ( AppServer[0])
  146. {
  147. Message(IDS_ERROR_TERMSERVER_NOT_FOUND);
  148. }
  149. else
  150. {
  151. Message(IDS_ERROR_NO_TERMSERVER_IN_DOMAIN);
  152. }
  153. }
  154. if( pCurrentServer != NULL )
  155. {
  156. NetApiBufferFree( pCurrentServer );
  157. }
  158. return(SUCCESS);
  159. }
  160. /*******************************************************************************
  161. *
  162. * DisplayServer
  163. *
  164. * This routine displays information for one server
  165. *
  166. *
  167. * ENTRY:
  168. * pName (input)
  169. * pointer to server name
  170. * pAddress (input)
  171. * pointer to server address
  172. *
  173. * EXIT:
  174. * nothing
  175. *
  176. ******************************************************************************/
  177. void
  178. DisplayServer( LPTSTR pName, LPTSTR pAddress )
  179. {
  180. static ULONG RowCount = 0;
  181. /*
  182. * If appserver name was specified only show it
  183. */
  184. if ( AppServer[0] && _wcsicmp( pName, AppServer ) )
  185. return;
  186. /*
  187. * Page pause
  188. */
  189. if ( !(++RowCount % Rows) && !fNoPage ) {
  190. Message(IDS_PAUSE_MSG);
  191. _getch();
  192. wprintf(L"\n");
  193. }
  194. /*
  195. * If first time - output title
  196. */
  197. if ( !MatchedOne ) {
  198. Message( fAddress ? IDS_TITLE_ADDR : IDS_TITLE );
  199. Message( fAddress ? IDS_TITLE_ADDR1 : IDS_TITLE1 );
  200. MatchedOne = TRUE;
  201. }
  202. if ( fAddress ) {
  203. My_wprintf( L"%-37s%-21s\n", _wcsupr(pName), pAddress );
  204. } else {
  205. My_wprintf( L"%s\n", _wcsupr(pName) );
  206. }
  207. }
  208. /*******************************************************************************
  209. *
  210. * Usage
  211. *
  212. * Output the usage message for this utility.
  213. *
  214. * ENTRY:
  215. * bError (input)
  216. * TRUE if the 'invalid parameter(s)' message should preceed the usage
  217. * message and the output go to stderr; FALSE for no such error
  218. * string and output goes to stdout.
  219. *
  220. * EXIT:
  221. *
  222. *
  223. ******************************************************************************/
  224. void
  225. Usage( BOOLEAN bError )
  226. {
  227. if ( bError ) {
  228. ErrorPrintf(IDS_ERROR_INVALID_PARAMETERS);
  229. ErrorPrintf(IDS_HELP_USAGE1);
  230. ErrorPrintf(IDS_HELP_USAGE2);
  231. ErrorPrintf(IDS_HELP_USAGE3);
  232. ErrorPrintf(IDS_HELP_USAGE4);
  233. ErrorPrintf(IDS_HELP_USAGE5);
  234. ErrorPrintf(IDS_HELP_USAGE6);
  235. ErrorPrintf(IDS_HELP_USAGE7);
  236. } else {
  237. Message(IDS_HELP_USAGE1);
  238. Message(IDS_HELP_USAGE2);
  239. Message(IDS_HELP_USAGE3);
  240. Message(IDS_HELP_USAGE4);
  241. Message(IDS_HELP_USAGE5);
  242. Message(IDS_HELP_USAGE6);
  243. Message(IDS_HELP_USAGE7);
  244. }
  245. }
  246. int _getch( void )
  247. {
  248. INPUT_RECORD ConInpRec;
  249. DWORD NumRead;
  250. int ch = 0; /* single character buffer */
  251. DWORD oldstate = 0;
  252. /*
  253. * Switch to raw mode (no line input, no echo input)
  254. */
  255. GetConsoleMode( hConIn, &oldstate );
  256. SetConsoleMode( hConIn, 0L );
  257. for ( ; ; ) {
  258. /*
  259. * Get a console input event.
  260. */
  261. if ( !ReadConsoleInput( hConIn,
  262. &ConInpRec,
  263. 1L,
  264. &NumRead )
  265. || (NumRead == 0L) )
  266. {
  267. ch = EOF;
  268. break;
  269. }
  270. /*
  271. * Look for, and decipher, key events.
  272. */
  273. if ( (ConInpRec.EventType == KEY_EVENT) &&
  274. ConInpRec.Event.KeyEvent.bKeyDown ) {
  275. /*
  276. * Easy case: if uChar.AsciiChar is non-zero, just stuff it
  277. * into ch and quit.
  278. */
  279. if ( ch = (unsigned char)ConInpRec.Event.KeyEvent.uChar.AsciiChar )
  280. break;
  281. }
  282. }
  283. /*
  284. * Restore previous console mode.
  285. */
  286. SetConsoleMode( hConIn, oldstate );
  287. return ch;
  288. }