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.

1188 lines
35 KiB

  1. /*++
  2. Copyright (c) 1994 Microsoft Corporation
  3. Module Name :
  4. w3admin.cxx
  5. Abstract:
  6. main program to test the working of RPC APIs of W3 server
  7. Author:
  8. Murali R. Krishnan ( MuraliK ) 3-July1-995
  9. Project:
  10. W3 server Admin Test Program
  11. Functions Exported:
  12. Revision History:
  13. --*/
  14. /************************************************************
  15. * Include Headers
  16. ************************************************************/
  17. # include <windows.h>
  18. # include <lm.h>
  19. # include <stdio.h>
  20. # include <stdlib.h>
  21. # include <time.h>
  22. # include <winsock2.h>
  23. # include "inetinfo.h"
  24. # include "apiutil.h"
  25. //
  26. // size of half dword in bits
  27. //
  28. # define HALF_DWORD_SIZE ( sizeof(DWORD) * 8 / 2)
  29. //
  30. // To Avoid overflows I multiply using two parts
  31. //
  32. # define LargeIntegerToDouble( li) \
  33. ( ( 1 << HALF_DWORD_SIZE) * \
  34. (( double) (li).HighPart) * ( 1 << HALF_DWORD_SIZE) + \
  35. ((li).LowPart) \
  36. )
  37. static LPWSTR g_lpszServerAddress = NULL;
  38. //
  39. // Prototypes of Functions
  40. //
  41. BOOL GenUsageMessage( int argc, char * argv[]);
  42. BOOL TestGetStatistics( int argc, char * argv[]);
  43. BOOL TestClearStatistics( int argc, char * argv[]);
  44. BOOL TestGetAdminInfo( int argc, char * argv[]);
  45. BOOL TestSetAdminInfo( int argc, char * argv[]);
  46. BOOL TestInetGetAdminInfo( int argc, char * argv[]);
  47. BOOL TestInetSetAdminInfo( int argc, char * argv[]);
  48. BOOL TestEnumUserInfo( int argc, char * argv[]);
  49. //
  50. // The following DefineAllCommands() defines a template for all commands.
  51. // Format: CmdCodeName CommandName Function Pointer Comments
  52. //
  53. // To add addditional test commands, add just another line to the list
  54. // Dont touch any macros below, they are all automatically generated.
  55. // Always the first entry should be usage function.
  56. //
  57. #define DefineAllCommands() \
  58. Cmd( CmdUsage, "usage", GenUsageMessage, \
  59. " Commands Available" ) \
  60. Cmd( CmdGetStatistics, "getstatistics", TestGetStatistics, \
  61. " Get Server Statistics " ) \
  62. Cmd( CmdGetStats, "stats", TestGetStatistics, \
  63. " Get Server Statistics " ) \
  64. Cmd( CmdClearStatistics, "clearstatistics", TestClearStatistics,\
  65. " Clear Server Statistics" ) \
  66. Cmd( CmdGetAdminInfo, "getadmininfo", TestGetAdminInfo, \
  67. " Get Administrative Information" ) \
  68. Cmd( CmdSetAdminInfo, "setadmininfo", TestSetAdminInfo, \
  69. " Set Administrative Information" ) \
  70. Cmd( CmdEnumUserInfo, "enumusers", TestEnumUserInfo, \
  71. " Enumerate connected users" ) \
  72. Cmd( CmdInetGetAdminInfo, "igetadmininfo", TestInetGetAdminInfo, \
  73. " Get common Internet Administrative Information" ) \
  74. Cmd( CmdInetSetAdminInfo, "isetadmininfo", TestInetSetAdminInfo, \
  75. " Set common Internet Administrative Information" ) \
  76. Cmd( CmdDebugFlags, "debug", NULL, \
  77. " isetadmininfo: Set Debugging flags for the server" ) \
  78. Cmd( CmdPortNumber, "port", NULL, \
  79. " isetadmininfo: Set the port number for server") \
  80. Cmd( CmdMaxConnections, "maxconn", NULL, \
  81. " isetadmininfo: Set the max connections allowed in server") \
  82. Cmd( CmdConnectionTimeout, "timeout", NULL, \
  83. " isetadmininfo: Set the Connection Timeout interval( in seconds)") \
  84. Cmd( CmdLogAnonymous, "loganon", NULL, \
  85. " isetadmininfo: Set the LogAnonymous Flag") \
  86. Cmd( CmdLogNonAnonymous, "lognonanon", NULL, \
  87. " isetadmininfo: Set the LogNonAnonymous Flag") \
  88. Cmd( CmdAnonUserName, "anonuser", NULL, \
  89. " isetadmininfo: Set the Anonymous User Name ") \
  90. Cmd( CmdAdminName, "adminname", NULL, \
  91. " isetadmininfo: Set the Administrator name ") \
  92. Cmd( CmdAdminEmail, "adminemail", NULL, \
  93. " isetadmininfo: Set the Administrator Email ") \
  94. Cmd( CmdServerComment, "servercomment", NULL, \
  95. " isetadmininfo: Set the Server Comments for server ") \
  96. /* following are string data */ \
  97. \
  98. Cmd( CmdCatapultPwd, "catapultpwd", NULL, \
  99. " setadmininfo: Sets the catapult user password ") \
  100. /*++
  101. Unimplemented Options:
  102. (from old w3t.exe)
  103. Query: Query Volume Security masks.
  104. Set: Catapult user password.
  105. nuke: Disconnect a connected user.
  106. --*/
  107. // Define command codes
  108. # define Cmd( CmdCode, CmdName, CmdFunc, CmdComments) CmdCode,
  109. typedef enum _CmdCodes {
  110. DefineAllCommands()
  111. maxCmdCode
  112. } CmdCodes;
  113. #undef Cmd
  114. // Define the functions and array of mappings
  115. // General command function type
  116. typedef BOOL ( * CMDFUNC)( int argc, char * argv[]);
  117. typedef struct _CmdStruct {
  118. CmdCodes cmdCode;
  119. char * pszCmdName;
  120. CMDFUNC cmdFunc;
  121. char * pszCmdComments;
  122. } CmdStruct;
  123. // Define Prototypes of command functions
  124. # define Cmd( CmdCode, CmdName, CmdFunc, CmdComments) \
  125. BOOL CmdFunc(int argc, char * argv[]);
  126. // Cause an expansion to generate prototypes
  127. // DefineAllCommands()
  128. // Automatic generation causes a problem when we have NULL in Function ptrs :(
  129. // Let the user explicitly define the prototypes
  130. #undef Cmd
  131. //
  132. // Define the global array of commands
  133. //
  134. # define Cmd( CmdCode, CmdName, CmdFunc, CmdComments) \
  135. { CmdCode, CmdName, CmdFunc, CmdComments},
  136. static CmdStruct g_cmds[] = {
  137. DefineAllCommands()
  138. { maxCmdCode, NULL, NULL} // sentinel command
  139. };
  140. #undef Cmd
  141. /************************************************************
  142. * Functions
  143. ************************************************************/
  144. BOOL
  145. GenUsageMessage( int argc, char * argv[])
  146. {
  147. CmdStruct * pCmd;
  148. printf( " Usage:\n %s <server-name/address> <cmd name> <cmd arguments>\n",
  149. argv[0]);
  150. for( pCmd = g_cmds; pCmd != NULL && pCmd->cmdCode != maxCmdCode; pCmd++) {
  151. printf( "\t%s\t%s\n", pCmd->pszCmdName, pCmd->pszCmdComments);
  152. }
  153. return ( TRUE);
  154. } // GenUsageMessage()
  155. static
  156. CmdStruct * DecodeCommand( char * pszCmd)
  157. {
  158. CmdStruct * pCmd;
  159. if ( pszCmd != NULL) {
  160. for( pCmd = g_cmds;
  161. pCmd != NULL && pCmd->cmdCode != maxCmdCode; pCmd++) {
  162. if ( _stricmp( pszCmd, pCmd->pszCmdName) == 0) {
  163. return ( pCmd);
  164. }
  165. } // for
  166. }
  167. return ( &g_cmds[0]); // No match found, return usage message
  168. } // DecodeCommand()
  169. static
  170. LPWSTR
  171. ConvertToUnicode( char * psz)
  172. /*++
  173. Converts a given string into unicode string (after allocating buffer space)
  174. Returns NULL on failure. Use GetLastError() for details.
  175. --*/
  176. {
  177. LPWSTR pszUnicode;
  178. int cch;
  179. cch = strlen( psz) + 1;
  180. pszUnicode = ( LPWSTR ) malloc( cch * sizeof( WCHAR));
  181. if ( pszUnicode != NULL) {
  182. // Success. Copy the string now
  183. int iRet;
  184. iRet = MultiByteToWideChar( CP_ACP, MB_PRECOMPOSED,
  185. psz, cch,
  186. pszUnicode, cch);
  187. if ( iRet == 0 || iRet != cch) {
  188. free( pszUnicode); // failure so free the block
  189. pszUnicode = NULL;
  190. }
  191. } else {
  192. SetLastError( ERROR_NOT_ENOUGH_MEMORY);
  193. }
  194. return ( pszUnicode);
  195. } // ConvertToUnicode()
  196. static
  197. VOID
  198. PrintStatisticsInfo( IN W3_STATISTICS_0 * pStat)
  199. {
  200. DWORD i;
  201. if ( pStat == NULL) {
  202. return ;
  203. }
  204. printf( " Printing Statistics Information: \n");
  205. printf( "%20s = %10.3g\n", "BytesSent",
  206. LargeIntegerToDouble( pStat->TotalBytesSent));
  207. printf( "%20s = %4.3g\n", "BytesReceived",
  208. LargeIntegerToDouble(pStat->TotalBytesReceived));
  209. printf( "%20s = %ld\n", "Files Sent ", pStat->TotalFilesSent);
  210. printf( "%20s = %ld\n", "Current Anon Users",pStat->CurrentAnonymousUsers);
  211. printf( "%20s = %ld\n", "Current NonAnon Users",
  212. pStat->CurrentNonAnonymousUsers);
  213. printf( "%20s = %ld\n", "Total Anon Users", pStat->TotalAnonymousUsers);
  214. printf( "%20s = %ld\n", "Total NonAnon Users",
  215. pStat->TotalNonAnonymousUsers);
  216. printf( "%20s = %ld\n", "Max Anon Users", pStat->MaxAnonymousUsers);
  217. printf( "%20s = %ld\n", "Max NonAnon Users", pStat->MaxNonAnonymousUsers);
  218. printf( "%20s = %ld\n", "Current Connections", pStat->CurrentConnections);
  219. printf( "%20s = %ld\n", "Max Connections", pStat->MaxConnections);
  220. printf( "%20s = %ld\n", "Connection Attempts", pStat->ConnectionAttempts);
  221. printf( "%20s = %ld\n", "Logon Attempts", pStat->LogonAttempts);
  222. printf( "%20s = %ld\n", "Total Gets", pStat->TotalGets);
  223. printf( "%20s = %ld\n", "Total Heads", pStat->TotalHeads);
  224. printf( "%20s = %ld\n", "Total Posts", pStat->TotalPosts);
  225. printf( "%20s = %ld\n", "Total CGI Reqs", pStat->TotalCGIRequests);
  226. printf( "%20s = %ld\n", "Total BGI Reqs", pStat->TotalBGIRequests);
  227. printf( "%20s = %ld\n", "Current CGI Reqs", pStat->CurrentCGIRequests);
  228. printf( "%20s = %ld\n", "Current BGI Reqs", pStat->CurrentBGIRequests);
  229. printf( "%20s = %ld\n", "Max CGI Reqs", pStat->MaxCGIRequests);
  230. printf( "%20s = %ld\n", "Max BGI Reqs", pStat->MaxBGIRequests);
  231. printf( "%20s = %ld\n", "Total Not Found Errors",
  232. pStat->TotalNotFoundErrors);
  233. printf( "%20s = %s\n", "Time of Last Clear",
  234. asctime( localtime( (time_t *)&pStat->TimeOfLastClear ) ) );
  235. #ifndef NO_AUX_PERF
  236. printf( " Auxiliary Counters # = %u\n",
  237. pStat->nAuxCounters);
  238. for ( i = 0; i < pStat->nAuxCounters; i++) {
  239. printf( "Aux Counter[%u] = %u\n", i, pStat->rgCounters[i]);
  240. } //for
  241. #endif // NO_AUX_PERF
  242. return;
  243. } // PrintStatisticsInfo()
  244. static
  245. VOID
  246. PrintStatsForTime( IN W3_STATISTICS_0 * pStatStart,
  247. IN W3_STATISTICS_0 * pStatEnd,
  248. IN DWORD sInterval)
  249. /*++
  250. Print the statistics information over a time interval sInterval seconds.
  251. Arguments:
  252. pStatStart pointer to statistics information for starting sample
  253. pStatEnd pointer to statistics information for ending sample
  254. sInterval Time interval in seconds for the sample
  255. Returns:
  256. None
  257. --*/
  258. {
  259. LARGE_INTEGER liDiff;
  260. double dDiff;
  261. if ( pStatStart == NULL || pStatEnd == NULL || sInterval == 0 ) {
  262. return ;
  263. }
  264. printf( "Statistics for Interval = %u seconds\n", sInterval);
  265. printf( "%20s\t %10s\t%10s\t%10s\t%6s\n\n",
  266. "Item ", "Start Sample", "End Sample", "Difference", "Rate/s");
  267. liDiff.QuadPart = ( pStatEnd->TotalBytesSent.QuadPart -
  268. pStatStart->TotalBytesSent.QuadPart);
  269. dDiff = LargeIntegerToDouble( liDiff);
  270. printf( "%20s\t %10.3g\t %10.3g\t %10.3g\t%6.3g\n",
  271. "Bytes Sent",
  272. LargeIntegerToDouble( pStatStart->TotalBytesSent),
  273. LargeIntegerToDouble( pStatEnd->TotalBytesSent),
  274. dDiff,
  275. dDiff/sInterval
  276. );
  277. liDiff.QuadPart = ( pStatEnd->TotalBytesReceived.QuadPart -
  278. pStatStart->TotalBytesReceived.QuadPart);
  279. dDiff = LargeIntegerToDouble( liDiff);
  280. printf( "%20s\t %10.3g\t %10.3g\t %10.3g\t%6.3g\n",
  281. "Bytes Received",
  282. LargeIntegerToDouble(pStatStart->TotalBytesReceived),
  283. LargeIntegerToDouble(pStatEnd->TotalBytesReceived),
  284. dDiff,
  285. dDiff/sInterval
  286. );
  287. printf( "%20s\t %10ld\t %10ld\t %10ld\t%6ld\n",
  288. "Files Sent ",
  289. pStatStart->TotalFilesSent,
  290. pStatEnd->TotalFilesSent,
  291. pStatEnd->TotalFilesSent - pStatStart->TotalFilesSent,
  292. (pStatEnd->TotalFilesSent - pStatStart->TotalFilesSent)/sInterval
  293. );
  294. printf( "%20s\t %10ld\t %10ld\t %10ld\t%6ld\n",
  295. "Current Anon Users",
  296. pStatStart->CurrentAnonymousUsers,
  297. pStatEnd->CurrentAnonymousUsers,
  298. pStatEnd->CurrentAnonymousUsers - pStatStart->CurrentAnonymousUsers,
  299. (int ) (pStatEnd->CurrentAnonymousUsers -
  300. pStatStart->CurrentAnonymousUsers)/sInterval
  301. );
  302. printf( "%20s\t %10ld\t %10ld\t %10ld\t%6ld\n",
  303. "Current NonAnon Users",
  304. pStatStart->CurrentNonAnonymousUsers,
  305. pStatEnd->CurrentNonAnonymousUsers,
  306. (pStatStart->CurrentNonAnonymousUsers -
  307. pStatEnd->CurrentNonAnonymousUsers),
  308. (int ) (pStatStart->CurrentNonAnonymousUsers -
  309. pStatEnd->CurrentNonAnonymousUsers)/sInterval
  310. );
  311. printf( "%20s\t %10ld\t %10ld\t %10ld\t%6ld\n",
  312. "Total Anon Users",
  313. pStatStart->TotalAnonymousUsers,
  314. pStatEnd->TotalAnonymousUsers,
  315. pStatEnd->TotalAnonymousUsers - pStatStart->TotalAnonymousUsers,
  316. (pStatEnd->TotalAnonymousUsers - pStatStart->TotalAnonymousUsers)/
  317. sInterval
  318. );
  319. printf( "%20s\t %10ld\t %10ld\t %10ld\t%6ld\n",
  320. "Total NonAnon Users",
  321. pStatStart->TotalNonAnonymousUsers,
  322. pStatEnd->TotalNonAnonymousUsers,
  323. (pStatEnd->TotalNonAnonymousUsers -
  324. pStatStart->TotalNonAnonymousUsers),
  325. (pStatEnd->TotalNonAnonymousUsers -
  326. pStatStart->TotalNonAnonymousUsers)/sInterval
  327. );
  328. printf( "%20s\t %10ld\t %10ld\t %10ld\t%6ld\n",
  329. "Max Anon Users",
  330. pStatStart->MaxAnonymousUsers,
  331. pStatEnd->MaxAnonymousUsers,
  332. pStatEnd->MaxAnonymousUsers - pStatStart->MaxAnonymousUsers,
  333. (pStatEnd->MaxAnonymousUsers - pStatStart->MaxAnonymousUsers)
  334. /sInterval
  335. );
  336. printf( "%20s\t %10ld\t %10ld\t %10ld\t%6ld\n",
  337. "Max NonAnon Users",
  338. pStatStart->MaxNonAnonymousUsers,
  339. pStatEnd->MaxNonAnonymousUsers,
  340. pStatEnd->MaxNonAnonymousUsers - pStatStart->MaxNonAnonymousUsers,
  341. (pStatEnd->MaxNonAnonymousUsers - pStatStart->MaxNonAnonymousUsers)/
  342. sInterval
  343. );
  344. printf( "%20s\t %10ld\t %10ld\t %10ld\t%6ld\n",
  345. "Current Connections",
  346. pStatStart->CurrentConnections,
  347. pStatEnd->CurrentConnections,
  348. pStatEnd->CurrentConnections - pStatStart->CurrentConnections,
  349. (int )
  350. (pStatEnd->CurrentConnections - pStatStart->CurrentConnections)/
  351. sInterval
  352. );
  353. printf( "%20s\t %10ld\t %10ld\t %10ld\t%6ld\n",
  354. "Max Connections",
  355. pStatStart->MaxConnections,
  356. pStatEnd->MaxConnections,
  357. pStatEnd->MaxConnections - pStatStart->MaxConnections,
  358. (pStatEnd->MaxConnections - pStatStart->MaxConnections)/sInterval
  359. );
  360. printf( "%20s\t %10ld\t %10ld\t %10ld\t%6ld\n",
  361. "Connection Attempts",
  362. pStatStart->ConnectionAttempts,
  363. pStatEnd->ConnectionAttempts,
  364. pStatEnd->ConnectionAttempts - pStatStart->ConnectionAttempts,
  365. (pStatEnd->ConnectionAttempts - pStatStart->ConnectionAttempts)/
  366. sInterval
  367. );
  368. printf( "%20s\t %10ld\t %10ld\t %10ld\t%6ld\n",
  369. "Logon Attempts",
  370. pStatStart->LogonAttempts,
  371. pStatEnd->LogonAttempts,
  372. pStatEnd->LogonAttempts - pStatStart->LogonAttempts,
  373. (pStatEnd->LogonAttempts - pStatStart->LogonAttempts)/sInterval
  374. );
  375. printf( "%20s\t %10ld\t %10ld\t %10ld\t%6ld\n",
  376. "Total Gets",
  377. pStatStart->TotalGets,
  378. pStatEnd->TotalGets,
  379. pStatEnd->TotalGets - pStatStart->TotalGets,
  380. (pStatEnd->TotalGets - pStatStart->TotalGets)/sInterval
  381. );
  382. printf( "%20s\t %10ld\t %10ld\t %10ld\t%6ld\n",
  383. "Total Heads",
  384. pStatStart->TotalHeads,
  385. pStatEnd->TotalHeads,
  386. pStatEnd->TotalHeads - pStatStart->TotalHeads,
  387. (pStatEnd->TotalHeads - pStatStart->TotalHeads)/sInterval
  388. );
  389. printf( "%20s\t %10ld\t %10ld\t %10ld\t%6ld\n",
  390. "Total Posts",
  391. pStatStart->TotalPosts,
  392. pStatEnd->TotalPosts,
  393. pStatEnd->TotalPosts - pStatStart->TotalPosts,
  394. (pStatEnd->TotalPosts - pStatStart->TotalPosts)/sInterval
  395. );
  396. printf( "%20s\t %10ld\t %10ld\t %10ld\t%6ld\n",
  397. "Total Others",
  398. pStatStart->TotalOthers,
  399. pStatEnd->TotalOthers,
  400. pStatEnd->TotalOthers - pStatStart->TotalOthers,
  401. (pStatEnd->TotalOthers - pStatStart->TotalOthers)/sInterval
  402. );
  403. printf( "%20s\t %10ld\t %10ld\t %10ld\t%6ld\n",
  404. "Current CGI Requests",
  405. pStatStart->CurrentCGIRequests,
  406. pStatEnd->CurrentCGIRequests,
  407. pStatEnd->CurrentCGIRequests - pStatStart->CurrentCGIRequests,
  408. (pStatEnd->CurrentCGIRequests - pStatStart->CurrentCGIRequests)/
  409. sInterval
  410. );
  411. printf( "%20s\t %10ld\t %10ld\t %10ld\t%6ld\n",
  412. "Total CGI Requests",
  413. pStatStart->TotalCGIRequests,
  414. pStatEnd->TotalCGIRequests,
  415. pStatEnd->TotalCGIRequests - pStatStart->TotalCGIRequests,
  416. (pStatEnd->TotalCGIRequests - pStatStart->TotalCGIRequests)/
  417. sInterval
  418. );
  419. printf( "%20s\t %10ld\t %10ld\t %10ld\t%6ld\n",
  420. "Max CGIRequests",
  421. pStatStart->MaxCGIRequests,
  422. pStatEnd->MaxCGIRequests,
  423. pStatEnd->MaxCGIRequests - pStatStart->MaxCGIRequests,
  424. (pStatEnd->MaxCGIRequests - pStatStart->MaxCGIRequests)/sInterval
  425. );
  426. printf( "%20s\t %10ld\t %10ld\t %10ld\t%6ld\n",
  427. "Current BGI Requests",
  428. pStatStart->CurrentBGIRequests,
  429. pStatEnd->CurrentBGIRequests,
  430. pStatEnd->CurrentBGIRequests - pStatStart->CurrentBGIRequests,
  431. (pStatEnd->CurrentBGIRequests - pStatStart->CurrentBGIRequests)/
  432. sInterval
  433. );
  434. printf( "%20s\t %10ld\t %10ld\t %10ld\t%6ld\n",
  435. "Total BGI Requests",
  436. pStatStart->TotalBGIRequests,
  437. pStatEnd->TotalBGIRequests,
  438. pStatEnd->TotalBGIRequests - pStatStart->TotalBGIRequests,
  439. (pStatEnd->TotalBGIRequests - pStatStart->TotalBGIRequests)/
  440. sInterval
  441. );
  442. printf( "%20s\t %10ld\t %10ld\t %10ld\t%6ld\n",
  443. "Max BGIRequests",
  444. pStatStart->MaxBGIRequests,
  445. pStatEnd->MaxBGIRequests,
  446. pStatEnd->MaxBGIRequests - pStatStart->MaxBGIRequests,
  447. (pStatEnd->MaxBGIRequests - pStatStart->MaxBGIRequests)/sInterval
  448. );
  449. printf( "%20s\t %10ld\t %10ld\t %10ld\t%6ld\n",
  450. "Total Not Found Errors",
  451. pStatStart->TotalNotFoundErrors,
  452. pStatEnd->TotalNotFoundErrors,
  453. pStatEnd->TotalNotFoundErrors - pStatStart->TotalNotFoundErrors,
  454. (pStatEnd->TotalNotFoundErrors - pStatStart->TotalNotFoundErrors)/
  455. sInterval
  456. );
  457. return;
  458. } // PrintStatisticsInfo()
  459. BOOL
  460. TestGetStatistics( int argc, char * argv[] )
  461. /*++
  462. Gets Statistics from server and prints it.
  463. If the optional time information is given, then this function
  464. obtains the statistics, sleeps for specified time interval and then
  465. again obtains new statistics and prints the difference, neatly formatted.
  466. Arguments:
  467. argc = count of arguments
  468. argv array of strings for command
  469. argv[0] = stats or getstatistics
  470. argv[1] = time interval if specified in seconds
  471. if argv[1] = -t10 => loop getting stats every 10 seconds.
  472. --*/
  473. {
  474. DWORD err;
  475. DWORD timeToSleep = 0;
  476. W3_STATISTICS_0 * pStat1 = NULL; // this should be freed ? NYI
  477. BOOL fLoop = FALSE;
  478. if ( argc > 1 && argv[1] != NULL) {
  479. if ( argv[1][0] == '-' && argv[1][1] == 't') {
  480. fLoop = TRUE;
  481. timeToSleep = atoi(argv[1] + 2);
  482. } else {
  483. timeToSleep = atoi( argv[1]);
  484. }
  485. }
  486. err = W3QueryStatistics(g_lpszServerAddress,
  487. 0,
  488. (LPBYTE *) &pStat1);
  489. if ( err == NO_ERROR) {
  490. if ( timeToSleep <= 0) {
  491. PrintStatisticsInfo( pStat1);
  492. } else {
  493. W3_STATISTICS_0 * pStat2 = NULL;
  494. do {
  495. printf( "\n\nStatistics For Time Interval %u seconds\n\n",
  496. timeToSleep);
  497. Sleep( timeToSleep * 1000); // sleep for the interval
  498. err = W3QueryStatistics(g_lpszServerAddress,
  499. 0,
  500. (LPBYTE *) &pStat2);
  501. if ( err == NO_ERROR) {
  502. PrintStatsForTime( pStat1, pStat2, timeToSleep);
  503. } else {
  504. break;
  505. }
  506. if ( pStat1 != NULL) {
  507. MIDL_user_free( pStat1);
  508. pStat1 = NULL;
  509. }
  510. pStat1 = pStat2;
  511. } while ( fLoop);
  512. }
  513. }
  514. if ( pStat1 != NULL) {
  515. MIDL_user_free( pStat1);
  516. }
  517. SetLastError( err);
  518. return ( err == NO_ERROR);
  519. } // TestGetStatistics()
  520. BOOL
  521. TestClearStatistics( int argc, char * argv[])
  522. {
  523. DWORD err;
  524. err = W3ClearStatistics( g_lpszServerAddress);
  525. printf( "Cleared the statistics Err = %d\n", err);
  526. SetLastError( err);
  527. return ( err == NO_ERROR);
  528. } // TestClearStatistics()
  529. static VOID
  530. PrintAdminInformation( IN W3_CONFIG_INFO * pConfigInfo)
  531. {
  532. if ( pConfigInfo == NULL)
  533. return;
  534. printf( "\n Printing Config Information in %08x\n", pConfigInfo);
  535. printf( "%20s= %S\n", "DirBrowseControl", pConfigInfo->dwDirBrowseControl);
  536. printf( "%20s= %S\n", "fCheckForWAISDB", pConfigInfo->fCheckForWAISDB);
  537. printf( "%20s= %S\n", "DefaultLoadFiles",pConfigInfo->lpszDefaultLoadFile);
  538. printf( "%20s= %S\n", "DirectoryImage", pConfigInfo->lpszDirectoryImage);
  539. printf( "%20s= %S\n", "Catapult User", pConfigInfo->lpszCatapultUser);
  540. printf( "%20s= %x\n", "CatapultUserPwd", pConfigInfo->szCatapultUserPwd);
  541. return;
  542. } // PrintAdminInformation()
  543. static BOOL
  544. TestGetAdminInfo( int argc, char * argv[] )
  545. {
  546. DWORD err;
  547. W3_CONFIG_INFO * pConfig = NULL;
  548. err = W3GetAdminInformation( g_lpszServerAddress, &pConfig);
  549. printf( "W3GetAdminInformation returned Error Code = %d\n", err);
  550. if ( err == NO_ERROR) {
  551. PrintAdminInformation( pConfig);
  552. MIDL_user_free( ( LPVOID) pConfig);
  553. }
  554. SetLastError( err);
  555. return ( err == NO_ERROR);
  556. } // TestGetAdminInfo()
  557. DWORD
  558. SetAdminField(
  559. IN W3_CONFIG_INFO * pConfigIn,
  560. IN char * pszSubCmd,
  561. IN char * pszValue)
  562. {
  563. DWORD err = NO_ERROR;
  564. CmdStruct * pCmd = DecodeCommand( pszSubCmd); // get command struct
  565. if ( pCmd == NULL) {
  566. // ignore invalid commands
  567. printf( " Invalid SubCommand for set admin info %s. Ignoring...\n",
  568. pszSubCmd);
  569. return ( ERROR_INVALID_PARAMETER);
  570. }
  571. switch ( pCmd->cmdCode) {
  572. case CmdCatapultPwd:
  573. {
  574. if ( pszValue) {
  575. WCHAR achPassword[ PWLEN + 1];
  576. wsprintfW( achPassword, L"%S", pszValue);
  577. wcscpy( pConfigIn->szCatapultUserPwd, achPassword);
  578. }
  579. break;
  580. }
  581. default:
  582. printf( " Invalid Sub command %s for SetConfigInfo(). Ignoring.\n",
  583. pszSubCmd);
  584. err = ERROR_INVALID_PARAMETER;
  585. break;
  586. } // switch
  587. return ( err);
  588. } // SetAdminField()
  589. BOOL
  590. TestSetAdminInfo( int argc, char * argv[])
  591. /*++
  592. Arguments:
  593. argc = count of arguments
  594. argv array of strings for command
  595. argv[0] = setadmininfo
  596. argv[1] = sub function within set info for testing
  597. argv[2] = value for sub function
  598. for all information to be set, give <sub command name> <value>
  599. --*/
  600. {
  601. DWORD err = ERROR_CALL_NOT_IMPLEMENTED;
  602. W3_CONFIG_INFO * pConfigOut = NULL; // config value obtained from server
  603. if ( argc < 1 || ( (argc & 0x1) != 0x1 ) ) { // argc should be > 1 and odd
  604. printf( "Invalid Number of arguments for %s\n", argv[0]);
  605. SetLastError( ERROR_INVALID_PARAMETER);
  606. return ( FALSE);
  607. }
  608. // Get the config from server to start with
  609. err = W3GetAdminInformation( g_lpszServerAddress, &pConfigOut);
  610. if ( err != NO_ERROR) {
  611. printf( " W3GetAdminInformation() failed with error = %u\n",
  612. err);
  613. SetLastError( err);
  614. return (FALSE);
  615. }
  616. // extract each field and value to set in configIn
  617. for( ; --argc > 1; argc -= 2) {
  618. if ( SetAdminField( pConfigOut, argv[argc - 1], argv[argc])
  619. != NO_ERROR) {
  620. break;
  621. }
  622. } // for() to extract and set all fields
  623. if ( err != NO_ERROR) {
  624. // Now make RPC call to set the fields
  625. err = W3SetAdminInformation( g_lpszServerAddress,
  626. pConfigOut);
  627. }
  628. MIDL_user_free( pConfigOut);
  629. SetLastError( err );
  630. return ( err == NO_ERROR );
  631. } // TestSetAdminInfo()
  632. static VOID
  633. PrintInetInfodminInformation( IN LPINET_INFO_CONFIG_INFO pConfigInfo)
  634. {
  635. if ( pConfigInfo == NULL)
  636. return;
  637. printf( "\n Printing InetInfo Config Information in %08x\n", pConfigInfo);
  638. printf( "%20s= %d\n", "LogAnonymous", pConfigInfo->fLogAnonymous);
  639. printf( "%20s= %d\n", "LogNonAnonymous",pConfigInfo->fLogNonAnonymous);
  640. printf( "%20s= %08x\n", "Authentication Flags",
  641. pConfigInfo->dwAuthentication);
  642. printf( "%20s= %d\n", "Port", pConfigInfo->sPort);
  643. printf( "%20s= %d\n", "Connection Timeout",
  644. pConfigInfo->dwConnectionTimeout);
  645. printf( "%20s= %d\n", "Max Connections",
  646. pConfigInfo->dwMaxConnections);
  647. printf( "%20s= %S\n", "AnonUserName", pConfigInfo->lpszAnonUserName);
  648. printf( "%20s= %S\n", "AnonPassword", pConfigInfo->szAnonPassword);
  649. printf( "%20s= %S\n", "Admin Name",
  650. pConfigInfo->lpszAdminName);
  651. printf( "%20s= %S\n", "Admin Email",
  652. pConfigInfo->lpszAdminEmail);
  653. printf( "%20s= %S\n", "Server Comments",
  654. pConfigInfo->lpszServerComment);
  655. //
  656. // IP lists and Grant lists, Virtual Roots are not included now. Later.
  657. //
  658. return;
  659. } // PrintInetInfodminInformation()
  660. static DWORD
  661. GetServiceIdFromString( IN LPCSTR pszService)
  662. {
  663. if ( pszService != NULL) {
  664. if ( !_stricmp(pszService, "HTTP")) {
  665. return ( INET_HTTP);
  666. } else if (!_stricmp( pszService, "GOPHER")) {
  667. return (INET_GOPHER);
  668. } else if ( !_stricmp( pszService, "FTP")) {
  669. return (INET_FTP);
  670. } else if ( !_stricmp( pszService, "DNS")) {
  671. return (INET_DNS);
  672. }
  673. }
  674. return ( INET_HTTP);
  675. } // GetServiceIdFromString()
  676. static BOOL
  677. TestInetGetAdminInfo( int argc, char * argv[] )
  678. /*++
  679. Gets the configuration information using InetInfoGetAdminInformation()
  680. argv[0] = igetadmininfo
  681. argv[1] = service name ( gopher, http, ftp, catapult)
  682. --*/
  683. {
  684. DWORD err;
  685. LPINET_INFO_CONFIG_INFO pConfig = NULL;
  686. DWORD dwServiceId;
  687. printf( " InetInfoGetAdminInformation() called at: Time = %d\n",
  688. GetTickCount());
  689. dwServiceId = (argc > 1) ? GetServiceIdFromString( argv[1]) : INET_HTTP;
  690. err = InetInfoGetAdminInformation( g_lpszServerAddress,
  691. dwServiceId,
  692. &pConfig);
  693. printf( "Finished at Time = %d\n", GetTickCount());
  694. printf( "InetInfoGetAdminInformation returned Error Code = %d\n", err);
  695. if ( err == NO_ERROR) {
  696. PrintInetInfodminInformation( pConfig);
  697. MIDL_user_free( ( LPVOID) pConfig);
  698. }
  699. SetLastError( err);
  700. return ( err == NO_ERROR);
  701. } // TestInetGetAdminInfo()
  702. DWORD
  703. SetInetInfoAdminField(
  704. IN LPINET_INFO_CONFIG_INFO pConfigIn,
  705. IN char * pszSubCmd,
  706. IN char * pszValue)
  707. {
  708. DWORD err = NO_ERROR;
  709. CmdStruct * pCmd = DecodeCommand( pszSubCmd); // get command struct
  710. if ( pCmd == NULL) {
  711. // ignore invalid commands
  712. printf( " Invalid SubCommand for set admin info %s. Ignoring...\n",
  713. pszSubCmd);
  714. return ( ERROR_INVALID_PARAMETER);
  715. }
  716. switch ( pCmd->cmdCode) {
  717. case CmdPortNumber:
  718. SetField( pConfigIn->FieldControl, FC_INET_INFO_PORT_NUMBER);
  719. pConfigIn->sPort = atoi( pszValue);
  720. break;
  721. case CmdConnectionTimeout:
  722. SetField( pConfigIn->FieldControl, FC_INET_INFO_CONNECTION_TIMEOUT);
  723. pConfigIn->dwConnectionTimeout = atoi( pszValue);
  724. break;
  725. case CmdMaxConnections:
  726. SetField( pConfigIn->FieldControl, FC_INET_INFO_MAX_CONNECTIONS);
  727. pConfigIn->dwMaxConnections = atoi( pszValue);
  728. break;
  729. case CmdLogAnonymous:
  730. SetField( pConfigIn->FieldControl, FC_INET_INFO_LOG_ANONYMOUS);
  731. pConfigIn->fLogAnonymous = atoi( pszValue);
  732. break;
  733. case CmdLogNonAnonymous:
  734. SetField( pConfigIn->FieldControl, FC_INET_INFO_LOG_NONANONYMOUS);
  735. pConfigIn->fLogNonAnonymous = atoi( pszValue);
  736. break;
  737. case CmdAnonUserName:
  738. SetField( pConfigIn->FieldControl, FC_INET_INFO_ANON_USER_NAME);
  739. pConfigIn->lpszAnonUserName = ConvertToUnicode( pszValue);
  740. if ( pConfigIn->lpszAnonUserName == NULL) {
  741. err = GetLastError();
  742. }
  743. break;
  744. case CmdAdminName:
  745. SetField( pConfigIn->FieldControl, FC_INET_INFO_ADMIN_NAME);
  746. pConfigIn->lpszAdminName =
  747. ConvertToUnicode( pszValue);
  748. if ( pConfigIn->lpszAdminName == NULL) {
  749. err = GetLastError();
  750. }
  751. break;
  752. case CmdAdminEmail:
  753. SetField( pConfigIn->FieldControl, FC_INET_INFO_ADMIN_EMAIL);
  754. pConfigIn->lpszAdminEmail =
  755. ConvertToUnicode( pszValue);
  756. if ( pConfigIn->lpszAdminEmail == NULL) {
  757. err = GetLastError();
  758. }
  759. break;
  760. case CmdServerComment:
  761. SetField( pConfigIn->FieldControl, FC_INET_INFO_SERVER_COMMENT);
  762. pConfigIn->lpszServerComment =
  763. ConvertToUnicode( pszValue);
  764. if ( pConfigIn->lpszServerComment == NULL) {
  765. err = GetLastError();
  766. }
  767. break;
  768. default:
  769. printf( " Invalid Sub command %s for SetConfigInfo(). Ignoring.\n",
  770. pszSubCmd);
  771. err = ERROR_INVALID_PARAMETER;
  772. break;
  773. } // switch
  774. return ( err);
  775. } // SetAdminField()
  776. static VOID
  777. FreeBuffer( IN PVOID * ppBuffer)
  778. {
  779. if ( *ppBuffer != NULL) {
  780. free( * ppBuffer);
  781. *ppBuffer = NULL; // reset the old value
  782. }
  783. return;
  784. } // FreeBuffer()
  785. VOID
  786. FreeStringsInInetConfigInfo( IN OUT LPINET_INFO_CONFIG_INFO pConfigInfo)
  787. {
  788. FreeBuffer( (PVOID *) & pConfigInfo->lpszAnonUserName);
  789. } // FreeStringsInInetConfigInfo()
  790. BOOL
  791. TestInetSetAdminInfo( int argc, char * argv[])
  792. /*++
  793. Arguments:
  794. argc = count of arguments
  795. argv array of strings for command
  796. argv[0] = isetadmininfo
  797. argv[1] = sub function within set info for testing
  798. argv[2] = value for sub function
  799. for all information to be set, give <sub command name> <value>
  800. --*/
  801. {
  802. DWORD err = ERROR_CALL_NOT_IMPLEMENTED;
  803. LPINET_INFO_CONFIG_INFO * ppConfigOut = NULL;
  804. INET_INFO_CONFIG_INFO configIn; // config values that are set
  805. if ( argc < 1 || ( (argc & 0x1) != 0x1 ) ) { // argc should be > 1 and odd
  806. printf( "Invalid Number of arguments for %s\n", argv[0]);
  807. SetLastError( ERROR_INVALID_PARAMETER);
  808. return ( FALSE);
  809. }
  810. //
  811. // form the admin info block to set the information
  812. //
  813. memset( ( LPVOID) &configIn, 0, sizeof( configIn)); // init to Zeros
  814. // extract each field and value to set in configIn
  815. for( ; --argc > 1; argc -= 2) {
  816. if ( SetInetInfoAdminField( &configIn, argv[argc - 1], argv[argc])
  817. != NO_ERROR) {
  818. break;
  819. }
  820. } // for() to extract and set all fields
  821. if ( err != NO_ERROR) {
  822. // Now make RPC call to set the fields
  823. err = InetInfoSetAdminInformation( g_lpszServerAddress,
  824. INET_HTTP,
  825. &configIn);
  826. }
  827. // Need to free all the buffers allocated for the strings
  828. FreeStringsInInetConfigInfo( &configIn);
  829. SetLastError( err );
  830. return ( err == NO_ERROR );
  831. } // TestSetInetAdminInfo()
  832. BOOL TestEnumUserInfo( int argc, char * argv[])
  833. {
  834. DWORD err;
  835. W3_USER_INFO * pUserInfo;
  836. DWORD cEntries;
  837. printf( "Invoking W3EnumerateUsers..." );
  838. err = W3EnumerateUsers( g_lpszServerAddress,
  839. &cEntries,
  840. &pUserInfo );
  841. if( err == NO_ERROR )
  842. {
  843. printf( " %lu connected users\n", cEntries );
  844. while( cEntries-- )
  845. {
  846. IN_ADDR addr;
  847. addr.s_addr = (u_long)pUserInfo->inetHost;
  848. printf( "idUser = %lu\n"
  849. "pszUser = %S\n"
  850. "fAnonymous = %lu\n"
  851. "inetHost = %s\n"
  852. "tConnect = %lu\n\n",
  853. pUserInfo->idUser,
  854. pUserInfo->pszUser,
  855. pUserInfo->fAnonymous,
  856. inet_ntoa( addr ),
  857. pUserInfo->tConnect );
  858. pUserInfo++;
  859. }
  860. }
  861. SetLastError( err);
  862. return ( err == NO_ERROR);
  863. } // TestEnumUserInfo()
  864. int __cdecl
  865. main( int argc, char * argv[])
  866. {
  867. DWORD err = NO_ERROR;
  868. char ** ppszArgv; // arguments for command functions
  869. int cArgs; // arg count for command functions
  870. char * pszCmdName;
  871. CmdStruct * pCmd;
  872. CMDFUNC pCmdFunc = NULL;
  873. if ( argc < 3 || argv[1] == NULL ) {
  874. // Insufficient arguments
  875. GenUsageMessage( argc, argv);
  876. return ( 1);
  877. }
  878. pszCmdName = argv[2];
  879. if (( pCmd = DecodeCommand( pszCmdName)) == NULL || pCmd->cmdFunc == NULL) {
  880. printf( "Internal Error: Invalid Command %s\n", pszCmdName);
  881. GenUsageMessage( argc, argv);
  882. return ( 1);
  883. }
  884. g_lpszServerAddress = ConvertToUnicode( argv[1]); // get server address
  885. cArgs = argc - 2;
  886. ppszArgv = argv + 2; // position at the start of the command name
  887. if ( !(*pCmd->cmdFunc)( cArgs, ppszArgv)) { // call the test function
  888. // Test function failed.
  889. printf( "Command %s failed. Error = %d\n", pszCmdName, GetLastError());
  890. return ( 1);
  891. }
  892. printf( " Command %s succeeded\n", pszCmdName);
  893. return ( 0); // success
  894. } // main()
  895. /************************ End of File ***********************/