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.

1269 lines
36 KiB

  1. //Copyright (c) 1998 - 1999 Microsoft Corporation
  2. /******************************************************************************
  3. *
  4. * QWINSTA.C
  5. *
  6. *
  7. *******************************************************************************/
  8. #include <nt.h>
  9. #include <ntrtl.h>
  10. #include <nturtl.h>
  11. #include <ntexapi.h>
  12. #include <stdio.h>
  13. #include <windows.h>
  14. #include <winstaw.h>
  15. #include <stdlib.h>
  16. #include <time.h>
  17. #include <utilsub.h>
  18. #include <process.h>
  19. #include <string.h>
  20. #include <malloc.h>
  21. #include <locale.h>
  22. #include <winsock.h>
  23. #include <wsipx.h>
  24. #include <wsnwlink.h>
  25. #include <wsnetbs.h>
  26. #include <nb30.h>
  27. #include <printfoa.h>
  28. #include <allproc.h>
  29. #include "qwinsta.h"
  30. LPCTSTR WINAPI
  31. StrConnectState( WINSTATIONSTATECLASS ConnectState,
  32. BOOL bShortString );
  33. LPCTSTR WINAPI
  34. StrAsyncConnectState( ASYNCCONNECTCLASS ConnectState );
  35. HANDLE hServerName = SERVERNAME_CURRENT;
  36. WCHAR ServerName[MAX_IDS_LEN+1];
  37. WCHAR term_string[MAX_IDS_LEN+1];
  38. USHORT a_flag = FALSE;
  39. USHORT c_flag = FALSE;
  40. USHORT f_flag = FALSE;
  41. USHORT m_flag = FALSE;
  42. USHORT help_flag = FALSE;
  43. USHORT fSm = FALSE;
  44. USHORT fDebug = FALSE;
  45. USHORT fVm = FALSE;
  46. USHORT counter_flag = FALSE;
  47. TOKMAP ptm[] = {
  48. {L" ", TMFLAG_OPTIONAL, TMFORM_S_STRING, MAX_IDS_LEN,
  49. term_string},
  50. {L"/address", TMFLAG_OPTIONAL, TMFORM_BOOLEAN, sizeof(USHORT), &a_flag},
  51. {L"/server", TMFLAG_OPTIONAL, TMFORM_STRING, MAX_IDS_LEN, ServerName},
  52. {L"/connect", TMFLAG_OPTIONAL, TMFORM_BOOLEAN, sizeof(USHORT), &c_flag},
  53. {L"/flow", TMFLAG_OPTIONAL, TMFORM_BOOLEAN, sizeof(USHORT), &f_flag},
  54. {L"/mode", TMFLAG_OPTIONAL, TMFORM_BOOLEAN, sizeof(USHORT), &m_flag},
  55. {L"/sm", TMFLAG_OPTIONAL, TMFORM_BOOLEAN, sizeof(USHORT), &fSm},
  56. {L"/debug", TMFLAG_OPTIONAL, TMFORM_BOOLEAN, sizeof(USHORT), &fDebug},
  57. {L"/vm", TMFLAG_OPTIONAL, TMFORM_BOOLEAN, sizeof(USHORT), &fVm},
  58. {L"/?", TMFLAG_OPTIONAL, TMFORM_BOOLEAN, sizeof(USHORT),
  59. &help_flag},
  60. {L"/counter", TMFLAG_OPTIONAL, TMFORM_BOOLEAN, sizeof(USHORT),
  61. &counter_flag},
  62. {0, 0, 0, 0, 0}
  63. };
  64. #define MAX_PRINTFOA_BUFFER_SIZE 1024
  65. char g_pWinStationName[MAX_PRINTFOA_BUFFER_SIZE];
  66. char g_pConnectState[MAX_PRINTFOA_BUFFER_SIZE];
  67. char g_pszState[MAX_PRINTFOA_BUFFER_SIZE];
  68. char g_pDeviceName[MAX_PRINTFOA_BUFFER_SIZE];
  69. char g_pWdDLL[MAX_PRINTFOA_BUFFER_SIZE];
  70. char g_pClientName[MAX_PRINTFOA_BUFFER_SIZE];
  71. char g_pClientAddress[MAX_PRINTFOA_BUFFER_SIZE];
  72. char g_pUserName[MAX_PRINTFOA_BUFFER_SIZE];
  73. WINSTATIONINFORMATION g_WinInfo;
  74. WDCONFIG g_WdInfo;
  75. WINSTATIONCONFIG g_WinConf;
  76. PDCONFIG g_PdConf;
  77. WINSTATIONCLIENT g_ClientConf;
  78. PDPARAMS g_PdParams;
  79. DEVICENAME g_DeviceName;
  80. /*
  81. * Local function prototypes
  82. */
  83. BOOLEAN PrintWinStationInfo( PLOGONID pWd, int WdCount );
  84. PWCHAR GetState( WINSTATIONSTATECLASS );
  85. void DisplayBaud( ULONG BaudRate );
  86. void DisplayParity( ULONG Parity );
  87. void DisplayDataBits( ULONG DataBits );
  88. void DisplayStopBits( ULONG StopBits );
  89. void DisplayConnect( ASYNCCONNECTCLASS ConnectFlag, USHORT header_flag );
  90. void DisplayFlow( PFLOWCONTROLCONFIG pFlow, USHORT header_flag );
  91. void DisplayLptPorts( BYTE LptMask, USHORT header_flag );
  92. void DisplayComPorts( BYTE ComMask, USHORT header_flag );
  93. void OutputHeader( void );
  94. void Usage( BOOLEAN bError );
  95. /*******************************************************************************
  96. *
  97. * main
  98. *
  99. ******************************************************************************/
  100. int __cdecl
  101. main(INT argc, CHAR **argv)
  102. {
  103. PLOGONID pWd;
  104. ULONG ByteCount, Index;
  105. UINT WdCount;
  106. ULONG Status;
  107. int rc, i;
  108. WCHAR **argvW;
  109. BOOLEAN MatchedOne = FALSE;
  110. BOOLEAN PrintWinStationInfo(PLOGONID pWd, int Count);
  111. TS_COUNTER TSCounters[3];
  112. setlocale(LC_ALL, ".OCP");
  113. /*
  114. * Massage the command line.
  115. */
  116. argvW = MassageCommandLine((DWORD)argc);
  117. if (argvW == NULL) {
  118. ErrorPrintf(IDS_ERROR_MALLOC);
  119. return(FAILURE);
  120. }
  121. /*
  122. * parse the cmd line without parsing the program name (argc-1, argv+1)
  123. */
  124. rc = ParseCommandLine(argc-1, argvW+1, ptm, 0);
  125. /*
  126. * Check for error from ParseCommandLine
  127. */
  128. if ( help_flag || (rc && !(rc & PARSE_FLAG_NO_PARMS)) ) {
  129. if ( !help_flag ) {
  130. Usage(TRUE);
  131. return(FAILURE);
  132. } else {
  133. Usage(FALSE);
  134. return(SUCCESS);
  135. }
  136. }
  137. // If no remote server was specified, then check if we are running under Terminal Server
  138. if ((!IsTokenPresent(ptm, L"/server") ) && (!AreWeRunningTerminalServices()))
  139. {
  140. ErrorPrintf(IDS_ERROR_NOT_TS);
  141. return(FAILURE);
  142. }
  143. /*
  144. * Open the specified server
  145. */
  146. if( ServerName[0] ) {
  147. hServerName = WinStationOpenServer( ServerName );
  148. if( hServerName == NULL ) {
  149. StringErrorPrintf(IDS_ERROR_SERVER,ServerName);
  150. PutStdErr( GetLastError(), 0 );
  151. return(FAILURE);
  152. }
  153. }
  154. #if 0
  155. //
  156. // Print local WINSTATION VM info
  157. //
  158. if( fVm ) {
  159. PrintWinStationVmInfo();
  160. return( SUCCESS );
  161. }
  162. #endif
  163. /*
  164. * if no winstation was specified, display all winstations
  165. */
  166. if ( !(*term_string) )
  167. wcscpy( term_string, L"*" );
  168. /*
  169. * Allocate buffer for WinStation ids
  170. */
  171. WdCount = 10;
  172. if ( (pWd = malloc( WdCount * sizeof(LOGONID) )) == NULL ) {
  173. ErrorPrintf(IDS_ERROR_MALLOC);
  174. goto tscounters;
  175. }
  176. ByteCount = WdCount * sizeof(LOGONID);
  177. Index = 0; // Start enumeration from the begining
  178. /*
  179. * get list of active WinStations
  180. */
  181. rc = WinStationEnumerate( hServerName, &pWd, &WdCount );
  182. if ( rc ) {
  183. if ( PrintWinStationInfo(pWd, WdCount) )
  184. MatchedOne = TRUE;
  185. WinStationFreeMemory(pWd);
  186. } else {
  187. Status = GetLastError();
  188. ErrorPrintf(IDS_ERROR_WINSTATION_ENUMERATE, Status);
  189. PutStdErr( Status, 0 );
  190. goto tscounters;
  191. }
  192. /*
  193. * Check for at least one match
  194. */
  195. if ( !MatchedOne ) {
  196. StringErrorPrintf(IDS_ERROR_WINSTATION_NOT_FOUND, term_string);
  197. goto tscounters;
  198. }
  199. tscounters:
  200. if (counter_flag) {
  201. TSCounters[0].counterHead.dwCounterID = TERMSRV_TOTAL_SESSIONS;
  202. TSCounters[1].counterHead.dwCounterID = TERMSRV_DISC_SESSIONS;
  203. TSCounters[2].counterHead.dwCounterID = TERMSRV_RECON_SESSIONS;
  204. rc = WinStationGetTermSrvCountersValue(hServerName, 3, TSCounters);
  205. if (rc) {
  206. if (TSCounters[0].counterHead.bResult == TRUE) {
  207. Message(IDS_TSCOUNTER_TOTAL_SESSIONS, TSCounters[0].dwValue);
  208. }
  209. if (TSCounters[1].counterHead.bResult == TRUE) {
  210. Message(IDS_TSCOUNTER_DISC_SESSIONS, TSCounters[1].dwValue);
  211. }
  212. if (TSCounters[2].counterHead.bResult == TRUE) {
  213. Message(IDS_TSCOUNTER_RECON_SESSIONS, TSCounters[2].dwValue);
  214. }
  215. }
  216. else {
  217. ErrorPrintf(IDS_ERROR_TERMSRV_COUNTERS);
  218. }
  219. }
  220. return(SUCCESS);
  221. } /* main() */
  222. /******************************************************************************
  223. *
  224. * PrintWinStationInfo
  225. *
  226. * Printout the WinStation Information for the WinStations described in
  227. * the PLOGONID array.
  228. *
  229. * ENTRY:
  230. * pWd (input)
  231. * pointer to array of LOGONID structures.
  232. * WdCount (input)
  233. * number of elements in the pWd array.
  234. *
  235. * EXIT:
  236. * TRUE if at least one WinStation was output; FALSE if none.
  237. *
  238. *****************************************************************************/
  239. BOOLEAN
  240. PrintWinStationInfo( PLOGONID pWd,
  241. int WdCount )
  242. {
  243. int i, rc;
  244. ULONG ErrorCode;
  245. ULONG ReturnLength;
  246. PWCHAR pState;
  247. UINT MatchedOne = FALSE;
  248. static UINT HeaderFlag = FALSE;
  249. /*
  250. * Output terminal ids
  251. */
  252. for ( i=0; i < WdCount; i++ ) {
  253. if ( fSm || fDebug ) {
  254. {
  255. WideCharToMultiByte(CP_OEMCP, 0,
  256. pWd[i].WinStationName, -1,
  257. g_pWinStationName, sizeof(g_pWinStationName),
  258. NULL, NULL);
  259. WideCharToMultiByte(CP_OEMCP, 0,
  260. GetState( pWd[i].State ), -1,
  261. g_pConnectState, sizeof(g_pConnectState),
  262. NULL, NULL);
  263. fprintf( stdout, "%4u %-20s %s\n", pWd[i].LogonId, g_pWinStationName,
  264. g_pConnectState );
  265. }
  266. if ( !fDebug )
  267. continue;
  268. }
  269. if ( !WinStationObjectMatch( hServerName , &pWd[i], term_string ) )
  270. continue;
  271. /*
  272. * Get all available information so we can pick out what we need as
  273. * well as verify the API's
  274. */
  275. memset( &g_WinInfo, 0, sizeof(WINSTATIONINFORMATION) );
  276. memset( &g_WdInfo, 0, sizeof(WDCONFIG) );
  277. memset( &g_WinConf, 0, sizeof(WINSTATIONCONFIG) );
  278. memset( &g_PdConf, 0, sizeof(PDCONFIG) );
  279. memset( &g_ClientConf, 0, sizeof(WINSTATIONCLIENT) );
  280. memset( &g_PdParams, 0, sizeof(PDPARAMS) );
  281. memset( &g_DeviceName, 0, sizeof(DEVICENAME) );
  282. /*
  283. * If this WinStation is 'down', don't open and query.
  284. */
  285. if ( pWd[i].State == State_Init || pWd[i].State == State_Down ) {
  286. g_WinInfo.ConnectState = pWd[i].State;
  287. } else {
  288. /*
  289. * Query WinStation's information.
  290. */
  291. rc = WinStationQueryInformation( hServerName,
  292. pWd[i].LogonId,
  293. WinStationInformation,
  294. (PVOID)&g_WinInfo,
  295. sizeof(WINSTATIONINFORMATION),
  296. &ReturnLength);
  297. if( !rc ) {
  298. continue;
  299. }
  300. if( ReturnLength != sizeof(WINSTATIONINFORMATION) ) {
  301. ErrorPrintf(IDS_ERROR_WINSTATION_INFO_VERSION_MISMATCH,
  302. L"WinStationInformation",
  303. ReturnLength, sizeof(WINSTATIONINFORMATION));
  304. continue;
  305. }
  306. rc = WinStationQueryInformation( hServerName,
  307. pWd[i].LogonId,
  308. WinStationWd,
  309. (PVOID)&g_WdInfo,
  310. sizeof(WDCONFIG),
  311. &ReturnLength);
  312. if( !rc ) {
  313. continue;
  314. }
  315. if( ReturnLength != sizeof(WDCONFIG) ) {
  316. ErrorPrintf(IDS_ERROR_WINSTATION_INFO_VERSION_MISMATCH,
  317. L"WinStationWd",
  318. ReturnLength, sizeof(WDCONFIG));
  319. continue;
  320. }
  321. rc = WinStationQueryInformation( hServerName,
  322. pWd[i].LogonId,
  323. WinStationConfiguration,
  324. (PVOID)&g_WinConf,
  325. sizeof(WINSTATIONCONFIG),
  326. &ReturnLength);
  327. if( !rc ) {
  328. continue;
  329. }
  330. if( ReturnLength != sizeof(WINSTATIONCONFIG) ) {
  331. ErrorPrintf(IDS_ERROR_WINSTATION_INFO_VERSION_MISMATCH,
  332. L"WinStationConfiguration",
  333. ReturnLength, sizeof(WINSTATIONCONFIG));
  334. continue;
  335. }
  336. rc = WinStationQueryInformation( hServerName,
  337. pWd[i].LogonId,
  338. WinStationPd,
  339. (PVOID)&g_PdConf,
  340. sizeof(PDCONFIG),
  341. &ReturnLength);
  342. if( !rc ) {
  343. continue;
  344. }
  345. if( ReturnLength != sizeof(PDCONFIG) ) {
  346. ErrorPrintf(IDS_ERROR_WINSTATION_INFO_VERSION_MISMATCH,
  347. L"WinStationPd",
  348. ReturnLength, sizeof(PDCONFIG));
  349. continue;
  350. }
  351. rc = WinStationQueryInformation( hServerName,
  352. pWd[i].LogonId,
  353. WinStationClient,
  354. (PVOID)&g_ClientConf,
  355. sizeof(WINSTATIONCLIENT),
  356. &ReturnLength);
  357. if( !rc ) {
  358. continue;
  359. }
  360. if( ReturnLength != sizeof(WINSTATIONCLIENT) ) {
  361. ErrorPrintf(IDS_ERROR_WINSTATION_INFO_VERSION_MISMATCH,
  362. L"WinStationClient",
  363. ReturnLength, sizeof(WINSTATIONCLIENT));
  364. continue;
  365. }
  366. rc = WinStationQueryInformation( hServerName,
  367. pWd[i].LogonId,
  368. WinStationPdParams,
  369. (PVOID)&g_PdParams,
  370. sizeof(PDPARAMS),
  371. &ReturnLength);
  372. if( !rc ) {
  373. continue;
  374. }
  375. if( ReturnLength != sizeof(PDPARAMS) ) {
  376. ErrorPrintf(IDS_ERROR_WINSTATION_INFO_VERSION_MISMATCH,
  377. L"WinStationPdParams",
  378. ReturnLength, sizeof(PDPARAMS));
  379. continue;
  380. }
  381. }
  382. /*
  383. * If this is a PdAsync Protocol, get the device name to display.
  384. */
  385. if ( g_PdParams.SdClass == SdAsync )
  386. wcscpy( g_DeviceName, g_PdParams.Async.DeviceName );
  387. /*
  388. * Flag sucessful match.
  389. */
  390. MatchedOne = TRUE;
  391. /*
  392. * trucate and convert to lower case
  393. */
  394. TruncateString( _wcslwr(g_WinInfo.WinStationName), 16 );
  395. TruncateString( _wcslwr(g_WdInfo.WdName), 8 );
  396. TruncateString( _wcslwr(g_DeviceName), 8 );
  397. TruncateString( _wcslwr(g_WdInfo.WdDLL), 13 );
  398. /*
  399. * Determine WinStation state
  400. */
  401. pState = GetState( g_WinInfo.ConnectState );
  402. /*
  403. * output header
  404. */
  405. if ( !HeaderFlag ) {
  406. HeaderFlag = TRUE;
  407. OutputHeader();
  408. }
  409. /*
  410. * identify current terminal
  411. */
  412. if ( (hServerName == SERVERNAME_CURRENT) && (pWd[i].LogonId == GetCurrentLogonId() ) )
  413. wprintf( L">" );
  414. else
  415. wprintf( L" " );
  416. if ( m_flag ) {
  417. {
  418. WideCharToMultiByte(CP_OEMCP, 0,
  419. g_WinInfo.WinStationName, -1,
  420. g_pWinStationName, sizeof(g_pWinStationName),
  421. NULL, NULL);
  422. WideCharToMultiByte(CP_OEMCP, 0,
  423. pState, -1,
  424. g_pszState, sizeof(g_pszState),
  425. NULL, NULL);
  426. WideCharToMultiByte(CP_OEMCP, 0,
  427. g_DeviceName, -1,
  428. g_pDeviceName, sizeof(g_pDeviceName),
  429. NULL, NULL);
  430. WideCharToMultiByte(CP_OEMCP, 0,
  431. g_WdInfo.WdDLL, -1,
  432. g_pWdDLL, sizeof(g_pWdDLL),
  433. NULL, NULL);
  434. fprintf(stdout , FORMAT_M, g_pWinStationName, g_pszState,
  435. g_pDeviceName, g_pWdDLL );
  436. }
  437. DisplayBaud( g_PdParams.Async.BaudRate );
  438. DisplayParity( g_PdParams.Async.Parity );
  439. DisplayDataBits( g_PdParams.Async.ByteSize );
  440. DisplayStopBits( g_PdParams.Async.StopBits );
  441. wprintf( L"\n" );
  442. if ( f_flag ) {
  443. DisplayFlow( &g_PdParams.Async.FlowControl, TRUE );
  444. wprintf( L"\n" );
  445. }
  446. if ( c_flag ) {
  447. DisplayConnect( g_PdParams.Async.Connect.Type, TRUE );
  448. wprintf( L"\n" );
  449. }
  450. fflush( stdout );
  451. } else if ( f_flag && c_flag ) {
  452. {
  453. WideCharToMultiByte(CP_OEMCP, 0,
  454. g_WinInfo.WinStationName, -1,
  455. g_pWinStationName, sizeof(g_pWinStationName),
  456. NULL, NULL);
  457. WideCharToMultiByte(CP_OEMCP, 0,
  458. g_DeviceName, -1,
  459. g_pDeviceName, sizeof(g_pDeviceName),
  460. NULL, NULL);
  461. fprintf(stdout,FORMAT_F_C, g_pWinStationName, g_pDeviceName );
  462. }
  463. DisplayFlow( &g_PdParams.Async.FlowControl, FALSE );
  464. DisplayConnect( g_PdParams.Async.Connect.Type, FALSE );
  465. wprintf( L"\n" );
  466. fflush( stdout );
  467. } else if ( c_flag ) {
  468. {
  469. WideCharToMultiByte(CP_OEMCP, 0,
  470. g_WinInfo.WinStationName, -1,
  471. g_pWinStationName, sizeof(g_pWinStationName),
  472. NULL, NULL);
  473. WideCharToMultiByte(CP_OEMCP, 0,
  474. pState, -1,
  475. g_pszState, sizeof(g_pszState),
  476. NULL, NULL);
  477. WideCharToMultiByte(CP_OEMCP, 0,
  478. g_DeviceName, -1,
  479. g_pDeviceName, sizeof(g_pDeviceName),
  480. NULL, NULL);
  481. WideCharToMultiByte(CP_OEMCP, 0,
  482. g_WdInfo.WdDLL, -1,
  483. g_pWdDLL, sizeof(g_pWdDLL),
  484. NULL, NULL);
  485. fprintf(stdout,FORMAT_C, g_pWinStationName, g_pszState,
  486. g_pDeviceName, g_pWdDLL );
  487. }
  488. DisplayConnect( g_PdParams.Async.Connect.Type, FALSE );
  489. wprintf( L"\n" );
  490. fflush(stdout);
  491. } else if ( f_flag ) {
  492. {
  493. WideCharToMultiByte(CP_OEMCP, 0,
  494. g_WinInfo.WinStationName, -1,
  495. g_pWinStationName, sizeof(g_pWinStationName),
  496. NULL, NULL);
  497. WideCharToMultiByte(CP_OEMCP, 0,
  498. pState, -1,
  499. g_pszState, sizeof(g_pszState),
  500. NULL, NULL);
  501. WideCharToMultiByte(CP_OEMCP, 0,
  502. g_DeviceName, -1,
  503. g_pDeviceName, sizeof(g_pDeviceName),
  504. NULL, NULL);
  505. WideCharToMultiByte(CP_OEMCP, 0,
  506. g_WdInfo.WdDLL, -1,
  507. g_pWdDLL, sizeof(g_pWdDLL),
  508. NULL, NULL);
  509. fprintf(stdout,FORMAT_F, g_pWinStationName, g_pszState,
  510. g_pDeviceName, g_pWdDLL );
  511. }
  512. DisplayFlow( &g_PdParams.Async.FlowControl, FALSE );
  513. wprintf( L"\n" );
  514. fflush(stdout);
  515. } else {
  516. {
  517. WideCharToMultiByte(CP_OEMCP, 0,
  518. g_WinInfo.WinStationName, -1,
  519. g_pWinStationName, sizeof(g_pWinStationName),
  520. NULL, NULL);
  521. WideCharToMultiByte(CP_OEMCP, 0,
  522. g_WinInfo.UserName, -1,
  523. g_pUserName, sizeof(g_pUserName),
  524. NULL, NULL);
  525. WideCharToMultiByte(CP_OEMCP, 0,
  526. pState, -1,
  527. g_pszState, sizeof(g_pszState),
  528. NULL, NULL);
  529. WideCharToMultiByte(CP_OEMCP, 0,
  530. g_DeviceName, -1,
  531. g_pDeviceName, sizeof(g_pDeviceName),
  532. NULL, NULL);
  533. WideCharToMultiByte(CP_OEMCP, 0,
  534. g_WdInfo.WdDLL, -1,
  535. g_pWdDLL, sizeof(g_pWdDLL),
  536. NULL, NULL);
  537. fprintf(stdout,FORMAT_DEFAULT, g_pWinStationName,
  538. g_pUserName, pWd[i].LogonId, g_pszState,
  539. g_pWdDLL, g_pDeviceName);
  540. }
  541. fflush(stdout);
  542. }
  543. } // end for(;;)
  544. return( MatchedOne || fSm );
  545. } /* PrintWinStationInfo() */
  546. /*******************************************************************************
  547. *
  548. * GetState
  549. *
  550. * This routine returns a pointer to a string describing the
  551. * current WinStation state.
  552. *
  553. * ENTRY:
  554. * State (input)
  555. * winstation state
  556. *
  557. * EXIT:
  558. * pointer to state string
  559. *
  560. ******************************************************************************/
  561. PWCHAR
  562. GetState( WINSTATIONSTATECLASS State )
  563. {
  564. PWCHAR pState;
  565. pState = (PWCHAR) StrConnectState(State,TRUE);
  566. /*
  567. switch ( State ) {
  568. case State_Active :
  569. pState = L"active";
  570. break;
  571. case State_Connected :
  572. pState = L"conn";
  573. break;
  574. case State_ConnectQuery :
  575. pState = L"connQ";
  576. break;
  577. case State_Shadow :
  578. pState = L"shadow";
  579. break;
  580. case State_Disconnected :
  581. pState = L"disc";
  582. break;
  583. case State_Idle :
  584. pState = L"idle";
  585. break;
  586. case State_Reset :
  587. pState = L"reset";
  588. break;
  589. case State_Down :
  590. pState = L"down";
  591. break;
  592. case State_Init :
  593. pState = L"init";
  594. break;
  595. case State_Listen :
  596. pState = L"listen";
  597. break;
  598. default :
  599. pState = L"unknown";
  600. break;
  601. }
  602. */
  603. return( pState );
  604. }
  605. /*******************************************************************************
  606. *
  607. * DisplayBaud
  608. *
  609. * This routine displays the baud rate
  610. *
  611. *
  612. * ENTRY:
  613. * BaudRate (input)
  614. * baud rate
  615. *
  616. * EXIT:
  617. * nothing
  618. *
  619. ******************************************************************************/
  620. void
  621. DisplayBaud( ULONG BaudRate )
  622. {
  623. if ( BaudRate > 0 )
  624. wprintf( L"%6lu ", BaudRate );
  625. else
  626. wprintf( L" " );
  627. fflush( stdout );
  628. } /* DisplayBaud() */
  629. /*******************************************************************************
  630. *
  631. * DisplayParity
  632. *
  633. * This routine displays parity
  634. *
  635. *
  636. * ENTRY:
  637. * Parity (input)
  638. * parity
  639. *
  640. * EXIT:
  641. * nothing
  642. *
  643. ******************************************************************************/
  644. void
  645. DisplayParity( ULONG Parity )
  646. {
  647. WCHAR szParity[64] = L"";
  648. switch ( Parity ) {
  649. case 0 :
  650. case 1 :
  651. case 2 :
  652. //
  653. // How does one handle a LoadString failure??? I choose to initialize
  654. // the storage to an empty string, and then ignore any failure.
  655. //
  656. LoadString(NULL, IDS_PARITY_NONE + Parity, szParity,
  657. sizeof(szParity) / sizeof(WCHAR));
  658. wprintf( szParity );
  659. break;
  660. default :
  661. LoadString(NULL, IDS_PARITY_BLANK, szParity,
  662. sizeof(szParity) / sizeof(WCHAR));
  663. wprintf( szParity );
  664. break;
  665. }
  666. fflush( stdout );
  667. } /* DisplayParity() */
  668. /*******************************************************************************
  669. *
  670. * DisplayDataBits
  671. *
  672. * This routine displays number of data bits
  673. *
  674. *
  675. * ENTRY:
  676. * DataBits (input)
  677. * data bits
  678. *
  679. * EXIT:
  680. * nothing
  681. *
  682. ******************************************************************************/
  683. void
  684. DisplayDataBits( ULONG DataBits )
  685. {
  686. WCHAR szDataBits[64] = L"";
  687. //
  688. // How does one handle a LoadString failure??? I choose to initialize
  689. // the storage to an empty string, and then ignore any failure. The
  690. // wprintf below, with an extra argument, won't cause any problems
  691. // if the LoadString fails.
  692. //
  693. if ( DataBits > 0 )
  694. {
  695. LoadString(NULL, IDS_DATABITS_FORMAT, szDataBits,
  696. sizeof(szDataBits) / sizeof(WCHAR));
  697. wprintf( szDataBits , DataBits );
  698. }
  699. else
  700. {
  701. LoadString(NULL, IDS_DATABITS_BLANK, szDataBits,
  702. sizeof(szDataBits) / sizeof(WCHAR));
  703. wprintf( szDataBits );
  704. }
  705. fflush( stdout );
  706. } /* DisplayDataBits() */
  707. /*******************************************************************************
  708. *
  709. * DisplayStopBits
  710. *
  711. * This routine displays the number of stop bits
  712. *
  713. *
  714. * ENTRY:
  715. * StopBits (input)
  716. * number of stop bits
  717. *
  718. * EXIT:
  719. * nothing
  720. *
  721. ******************************************************************************/
  722. void
  723. DisplayStopBits( ULONG StopBits )
  724. {
  725. WCHAR szStopBits[64] = L"";
  726. switch ( StopBits ) {
  727. case 0 :
  728. case 1 :
  729. case 2 :
  730. //
  731. // How does one handle a LoadString failure??? I choose to initialize
  732. // the storage to an empty string, and then ignore any failure.
  733. //
  734. LoadString(NULL, IDS_STOPBITS_ONE + StopBits, szStopBits,
  735. sizeof(szStopBits) / sizeof(WCHAR));
  736. wprintf( szStopBits );
  737. break;
  738. default :
  739. LoadString(NULL, IDS_STOPBITS_BLANK, szStopBits,
  740. sizeof(szStopBits) / sizeof(WCHAR));
  741. wprintf( szStopBits );
  742. break;
  743. }
  744. fflush( stdout );
  745. } /* DisplayStopBits() */
  746. /*******************************************************************************
  747. *
  748. * DisplayConnect
  749. *
  750. * This routine displays the connect settings
  751. *
  752. *
  753. * ENTRY:
  754. * ConnectFlag (input)
  755. * connect flags
  756. * header_flag (input)
  757. * TRUE to display sub-header; FALSE otherwise.
  758. *
  759. * EXIT:
  760. * nothing
  761. *
  762. ******************************************************************************/
  763. void
  764. DisplayConnect( ASYNCCONNECTCLASS ConnectFlag,
  765. USHORT header_flag )
  766. {
  767. WCHAR buffer[80] = L"";
  768. //
  769. // How does one handle a LoadString failure??? I choose to initialize
  770. // the storage to an empty string, and then ignore any failure. The
  771. // wprintf below, with an extra argument, won't cause any problems
  772. // if the LoadString fails.
  773. //
  774. if ( header_flag )
  775. {
  776. LoadString(NULL, IDS_CONNECT_HEADER, buffer, sizeof(buffer) / sizeof(WCHAR));
  777. wprintf(buffer);
  778. }
  779. buffer[0] = (WCHAR)NULL;
  780. LoadString(NULL, IDS_CONNECT_FORMAT, buffer, sizeof(buffer) / sizeof(WCHAR));
  781. wprintf( buffer, StrAsyncConnectState(ConnectFlag) );
  782. fflush( stdout );
  783. } /* DisplayConnect() */
  784. /*******************************************************************************
  785. *
  786. * DisplayFlow
  787. *
  788. * This routine displays the flow control settings
  789. *
  790. *
  791. * ENTRY:
  792. * pFlow (input)
  793. * Pointer to flow control configuration structure
  794. * header_flag (input)
  795. * TRUE to display sub-header; FALSE otherwise.
  796. *
  797. * EXIT:
  798. * nothing
  799. *
  800. ******************************************************************************/
  801. void
  802. DisplayFlow( PFLOWCONTROLCONFIG pFlow,
  803. USHORT header_flag )
  804. {
  805. WCHAR buffer[90], buf2[90], format[90];
  806. buffer[0] = 0;
  807. buf2[0] = 0;
  808. format[0] = 0;
  809. //
  810. // How does one handle a LoadString failure??? I choose to initialize
  811. // the storage to an empty string, and then ignore any failure. The
  812. // wprintf below, with an extra argument, won't cause any problems
  813. // if the LoadString fails.
  814. //
  815. if ( header_flag )
  816. {
  817. LoadString(NULL, IDS_FLOW_HEADER, buffer, sizeof(buffer) / sizeof(WCHAR));
  818. wprintf(buffer);
  819. }
  820. buffer[0] = (WCHAR)NULL;
  821. if( pFlow->fEnableDTR )
  822. {
  823. LoadString(NULL, IDS_FLOW_ENABLE_DTR, buf2, sizeof(buf2) / sizeof(WCHAR));
  824. wcscat(buffer, buf2);
  825. }
  826. buf2[0] = (WCHAR)NULL;
  827. if( pFlow->fEnableRTS )
  828. {
  829. LoadString(NULL, IDS_FLOW_ENABLE_DTR, buf2, sizeof(buf2) / sizeof(WCHAR));
  830. wcscat(buffer, buf2);
  831. }
  832. buf2[0] = (WCHAR)NULL;
  833. /*
  834. * Hardware and Software flow control are mutually exclusive
  835. */
  836. if( pFlow->Type == FlowControl_Hardware ) {
  837. if ( pFlow->HardwareReceive == ReceiveFlowControl_None )
  838. {
  839. LoadString(NULL, IDS_FLOW_RECEIVE_NONE, buf2,
  840. sizeof(buf2) / sizeof(WCHAR));
  841. }
  842. else if ( pFlow->HardwareReceive == ReceiveFlowControl_RTS )
  843. {
  844. LoadString(NULL, IDS_FLOW_RECEIVE_RTS, buf2,
  845. sizeof(buf2) / sizeof(WCHAR));
  846. }
  847. else if ( pFlow->HardwareReceive == ReceiveFlowControl_DTR )
  848. {
  849. LoadString(NULL, IDS_FLOW_RECEIVE_DTR, buf2,
  850. sizeof(buf2) / sizeof(WCHAR));
  851. }
  852. wcscat(buffer, buf2);
  853. buf2[0] = (WCHAR)NULL;
  854. if ( pFlow->HardwareTransmit == TransmitFlowControl_None )
  855. {
  856. LoadString(NULL, IDS_FLOW_TRANSMIT_NONE, buf2,
  857. sizeof(buf2) / sizeof(WCHAR));
  858. }
  859. else if ( pFlow->HardwareTransmit == TransmitFlowControl_CTS )
  860. {
  861. LoadString(NULL, IDS_FLOW_TRANSMIT_CTS, buf2,
  862. sizeof(buf2) / sizeof(WCHAR));
  863. }
  864. else if ( pFlow->HardwareTransmit == TransmitFlowControl_DSR )
  865. {
  866. LoadString(NULL, IDS_FLOW_TRANSMIT_DSR, buf2,
  867. sizeof(buf2) / sizeof(WCHAR));
  868. }
  869. wcscat(buffer, buf2);
  870. } else if ( pFlow->Type == FlowControl_Software ) {
  871. if ( pFlow->fEnableSoftwareTx )
  872. {
  873. LoadString(NULL, IDS_FLOW_SOFTWARE_TX, buf2,
  874. sizeof(buf2) / sizeof(WCHAR));
  875. }
  876. wcscat(buffer, buf2);
  877. buf2[0] = (WCHAR)NULL;
  878. if( pFlow->fEnableSoftwareRx )
  879. {
  880. LoadString(NULL, IDS_FLOW_SOFTWARE_TX, buf2,
  881. sizeof(buf2) / sizeof(WCHAR));
  882. }
  883. wcscat(buffer, buf2);
  884. buf2[0] = (WCHAR)NULL;
  885. if ( pFlow->XonChar == 0x65 && pFlow->XoffChar == 0x67 )
  886. {
  887. LoadString(NULL, IDS_FLOW_SOFTWARE_TX, buf2,
  888. sizeof(buf2) / sizeof(WCHAR));
  889. }
  890. else if( pFlow->fEnableSoftwareTx || pFlow->fEnableSoftwareRx )
  891. {
  892. LoadString(NULL, IDS_FLOW_SOFTWARE_TX, format,
  893. sizeof(format) / sizeof(WCHAR));
  894. wsprintf( buf2, format, pFlow->XonChar, pFlow->XoffChar );
  895. format[0] = (WCHAR)NULL;
  896. }
  897. wcscat( buffer, buf2 );
  898. }
  899. LoadString(NULL, IDS_FLOW_FORMAT, format, sizeof(format) / sizeof(WCHAR));
  900. wprintf( format, buffer );
  901. fflush( stdout );
  902. } /* DisplayFlow() */
  903. /*******************************************************************************
  904. *
  905. * DisplayLptPorts
  906. *
  907. * This routine displays the LPT ports that exist for a winstation
  908. *
  909. *
  910. * ENTRY:
  911. * LptMask (input)
  912. * LPT port mask
  913. * header_flag (input)
  914. * TRUE to display sub-header; FALSE otherwise.
  915. *
  916. * EXIT:
  917. * nothing
  918. *
  919. ******************************************************************************/
  920. void
  921. DisplayLptPorts( BYTE LptMask,
  922. USHORT header_flag )
  923. {
  924. WCHAR buffer[80], buf2[10], lptname[6];
  925. int i;
  926. buffer[0] = 0;
  927. buf2[0] = 0;
  928. lptname[0] = 0;
  929. //
  930. // How does one handle a LoadString failure??? I choose to initialize
  931. // the storage to an empty string, and then ignore any failure. The
  932. // wprintf below, with an extra argument, won't cause any problems
  933. // if the LoadString fails.
  934. //
  935. if ( header_flag )
  936. {
  937. LoadString(NULL, IDS_LPT_HEADER, buffer, sizeof(buffer) / sizeof(WCHAR));
  938. wprintf(buffer);
  939. }
  940. buffer[0] = (WCHAR)NULL;
  941. LoadString(NULL, IDS_LPT_FORMAT, buf2, sizeof(buf2) / sizeof(WCHAR));
  942. /*
  943. * Display from the 8 possible LPT ports.
  944. */
  945. for ( i=0; i < 8; i++ ) {
  946. if ( LptMask & (1<<i) ) {
  947. wsprintf( lptname, buf2, i+1 );
  948. wcscat( buffer, lptname );
  949. }
  950. }
  951. wprintf( buffer );
  952. fflush( stdout );
  953. } /* DisplayLptPorts() */
  954. /*******************************************************************************
  955. *
  956. * DisplayComPorts
  957. *
  958. * This routine displays the COM ports that exist for a winstation
  959. *
  960. *
  961. * ENTRY:
  962. * ComMask (input)
  963. * COM port mask
  964. * header_flag (input)
  965. * TRUE to display sub-header; FALSE otherwise.
  966. *
  967. * EXIT:
  968. * nothing
  969. *
  970. ******************************************************************************/
  971. void
  972. DisplayComPorts( BYTE ComMask,
  973. USHORT header_flag )
  974. {
  975. WCHAR buffer[80], buf2[10], comname[6];
  976. int i;
  977. buffer[0] = 0;
  978. buf2[0] = 0;
  979. comname[0] = 0;
  980. //
  981. // How does one handle a LoadString failure??? I choose to initialize
  982. // the storage to an empty string, and then ignore any failure. The
  983. // wprintf below, with an extra argument, won't cause any problems
  984. // if the LoadString fails.
  985. //
  986. if ( header_flag )
  987. {
  988. LoadString(NULL, IDS_COM_HEADER, buffer, sizeof(buffer) / sizeof(WCHAR));
  989. wprintf(buffer);
  990. }
  991. buffer[0] = (WCHAR)NULL;
  992. LoadString(NULL, IDS_COM_FORMAT, buf2, sizeof(buf2) / sizeof(WCHAR));
  993. /*
  994. * Display from the 8 possible LPT ports.
  995. */
  996. for ( i=0; i < 8; i++ ) {
  997. if ( ComMask & (1<<i) ) {
  998. wsprintf( comname, buf2, i+1 );
  999. wcscat( buffer, comname );
  1000. }
  1001. }
  1002. wprintf( buffer );
  1003. fflush( stdout );
  1004. } /* DisplayComPorts() */
  1005. /*******************************************************************************
  1006. *
  1007. * OutputHeader
  1008. *
  1009. * output header
  1010. *
  1011. *
  1012. * ENTRY:
  1013. * nothing
  1014. *
  1015. * EXIT:
  1016. * nothing
  1017. *
  1018. ******************************************************************************/
  1019. void
  1020. OutputHeader( void )
  1021. {
  1022. if ( a_flag ) {
  1023. Message(IDS_HEADER_A);
  1024. } else if ( m_flag ) {
  1025. Message(IDS_HEADER_M);
  1026. } else if ( f_flag && c_flag ) {
  1027. Message(IDS_HEADER_F_C);
  1028. } else if ( c_flag ) {
  1029. Message(IDS_HEADER_C);
  1030. } else if ( f_flag ) {
  1031. Message(IDS_HEADER_F);
  1032. } else {
  1033. Message(IDS_HEADER_DEFAULT);
  1034. }
  1035. fflush(stdout);
  1036. } /* OutputHeader() */
  1037. /*******************************************************************************
  1038. *
  1039. * Usage
  1040. *
  1041. * Output the usage message for this utility.
  1042. *
  1043. * ENTRY:
  1044. * bError (input)
  1045. * TRUE if the 'invalid parameter(s)' message should preceed the usage
  1046. * message and the output go to stderr; FALSE for no such error
  1047. * string and output goes to stdout.
  1048. *
  1049. * EXIT:
  1050. *
  1051. *
  1052. ******************************************************************************/
  1053. void
  1054. Usage( BOOLEAN bError )
  1055. {
  1056. if ( bError ) {
  1057. ErrorPrintf(IDS_ERROR_INVALID_PARAMETERS);
  1058. ErrorPrintf(IDS_HELP_USAGE1);
  1059. ErrorPrintf(IDS_HELP_USAGE2);
  1060. ErrorPrintf(IDS_HELP_USAGE3);
  1061. ErrorPrintf(IDS_HELP_USAGE4);
  1062. ErrorPrintf(IDS_HELP_USAGE5);
  1063. ErrorPrintf(IDS_HELP_USAGE6);
  1064. ErrorPrintf(IDS_HELP_USAGE7);
  1065. ErrorPrintf(IDS_HELP_USAGE8);
  1066. ErrorPrintf(IDS_HELP_USAGE9);
  1067. ErrorPrintf(IDS_HELP_USAGE10);
  1068. ErrorPrintf(IDS_HELP_USAGE11);
  1069. } else {
  1070. Message(IDS_HELP_USAGE1);
  1071. Message(IDS_HELP_USAGE2);
  1072. Message(IDS_HELP_USAGE3);
  1073. Message(IDS_HELP_USAGE4);
  1074. Message(IDS_HELP_USAGE5);
  1075. Message(IDS_HELP_USAGE6);
  1076. Message(IDS_HELP_USAGE7);
  1077. Message(IDS_HELP_USAGE8);
  1078. Message(IDS_HELP_USAGE9);
  1079. Message(IDS_HELP_USAGE10);
  1080. Message(IDS_HELP_USAGE11);
  1081. }
  1082. } /* Usage() */