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.

1005 lines
29 KiB

  1. /*++
  2. Copyright (c) 1994 Microsoft Corporation
  3. Module Name :
  4. main.c
  5. Abstract:
  6. main program to test the working of RPC APIs
  7. Author:
  8. Murali R. Krishnan ( MuraliK ) 22-Nov-1994
  9. Project:
  10. Gopher Server Admin Test Program
  11. Functions Exported:
  12. Revision History:
  13. 21-Apr-1995 Updated configuration to remove Admin Name and Email.
  14. --*/
  15. /************************************************************
  16. * Include Headers
  17. ************************************************************/
  18. # include <windows.h>
  19. # include <lm.h>
  20. # include <stdio.h>
  21. # include <stdlib.h>
  22. # include "inetinfo.h"
  23. # include "apiutil.h"
  24. //
  25. // size of half dword in bits
  26. //
  27. # define HALF_DWORD_SIZE ( sizeof(DWORD) * 8 / 2)
  28. //
  29. // To Avoid overflows I multiply using two parts
  30. //
  31. # define LargeIntegerToDouble( li) \
  32. ( ( 1 << HALF_DWORD_SIZE) * \
  33. (( double) (li).HighPart) * ( 1 << HALF_DWORD_SIZE) + \
  34. ((li).LowPart) \
  35. )
  36. static LPWSTR g_lpszServerAddress = NULL;
  37. //
  38. // Prototypes of Functions
  39. //
  40. BOOL GenUsageMessage( int argc, char * argv[]);
  41. BOOL TestGetStatistics( int argc, char * argv[]);
  42. BOOL TestClearStatistics( int argc, char * argv[]);
  43. BOOL TestGetAdminInfo( int argc, char * argv[]);
  44. BOOL TestSetAdminInfo( int argc, char * argv[]);
  45. BOOL TestInetGetAdminInfo( int argc, char * argv[]);
  46. BOOL TestInetSetAdminInfo( int argc, char * argv[]);
  47. //
  48. // The following DefineAllCommands() defines a template for all commands.
  49. // Format: CmdCodeName CommandName Function Pointer Comments
  50. //
  51. // To add addditional test commands, add just another line to the
  52. // given list
  53. // Dont touch any macros below, they are all automatically generated.
  54. // Always the first entry should be usage function.
  55. //
  56. #define DefineAllCommands() \
  57. Cmd( CmdUsage, "usage", GenUsageMessage, \
  58. " Commands Available" ) \
  59. Cmd( CmdGetStatistics, "getstatistics", TestGetStatistics, \
  60. " Get Statistics From Gopher Server" ) \
  61. Cmd( CmdClearStatistics, "clearstatistics", TestClearStatistics,\
  62. " Clear Gopher Server Statistics" ) \
  63. Cmd( CmdGetAdminInfo, "getadmininfo", TestGetAdminInfo, \
  64. " Get Administrative Information" ) \
  65. Cmd( CmdSetAdminInfo, "setadmininfo", TestSetAdminInfo, \
  66. " Set Administrative Information for Gopher Server" ) \
  67. Cmd( CmdInetGetAdminInfo, "igetadmininfo", TestInetGetAdminInfo, \
  68. " Get Gopher's common Internet Administrative Information" ) \
  69. Cmd( CmdInetSetAdminInfo, "isetadmininfo", TestInetSetAdminInfo, \
  70. " Set Gopher's common Internet Administrative Information" ) \
  71. Cmd( CmdDebugFlags, "debug", NULL, \
  72. " isetadmininfo: Set Debugging flags for the server" ) \
  73. Cmd( CmdPortNumber, "port", NULL, \
  74. " isetadmininfo: Set the port number for server") \
  75. Cmd( CmdMaxConnections, "maxconn", NULL, \
  76. " isetadmininfo: Set the max connections allowed in server") \
  77. Cmd( CmdConnectionTimeout, "timeout", NULL, \
  78. " isetadmininfo: Set the Connection Timeout interval( in seconds)") \
  79. Cmd( CmdLogAnonymous, "loganon", NULL, \
  80. " isetadmininfo: Set the LogAnonymous Flag") \
  81. Cmd( CmdLogNonAnonymous, "lognonanon", NULL, \
  82. " isetadmininfo: Set the LogNonAnonymous Flag") \
  83. Cmd( CmdAnonUserName, "anonuser", NULL, \
  84. " isetadmininfo: Set the Anonymous User Name ") \
  85. /* following are string data */ \
  86. \
  87. Cmd( CmdSite, "site", NULL, \
  88. " setadmininfo: Set the Site of the server ") \
  89. Cmd( CmdOrganization, "organization", NULL, \
  90. " setadmininfo: Set the Organization ") \
  91. Cmd( CmdLocation, "location", NULL, \
  92. " setadmininfo: Set the Location of the server ") \
  93. Cmd( CmdGeography, "geography", NULL, \
  94. " setadmininfo: Set the Geography Data for server location ") \
  95. Cmd( CmdLanguage, "language", NULL, \
  96. " setadmininfo: Set the Language for server location ") \
  97. Cmd( CmdCheckForWaisDb, "checkforwaisdb", NULL, \
  98. " setadmininfo: Sets the checkfor WaisDb flag to given value ") \
  99. // Define command codes
  100. # define Cmd( CmdCode, CmdName, CmdFunc, CmdComments) CmdCode,
  101. typedef enum _CmdCodes {
  102. DefineAllCommands()
  103. maxCmdCode
  104. } CmdCodes;
  105. #undef Cmd
  106. // Define the functions and array of mappings
  107. // General command function type
  108. typedef BOOL ( * CMDFUNC)( int argc, char * argv[]);
  109. typedef struct _CmdStruct {
  110. CmdCodes cmdCode;
  111. char * pszCmdName;
  112. CMDFUNC cmdFunc;
  113. char * pszCmdComments;
  114. } CmdStruct;
  115. // Define Prototypes of command functions
  116. # define Cmd( CmdCode, CmdName, CmdFunc, CmdComments) \
  117. BOOL CmdFunc(int argc, char * argv[]);
  118. // Cause an expansion to generate prototypes
  119. // DefineAllCommands()
  120. // Automatic generation causes a problem when we have NULL in Function ptrs :(
  121. // Let the user explicitly define the prototypes
  122. #undef Cmd
  123. //
  124. // Define the global array of commands
  125. //
  126. # define Cmd( CmdCode, CmdName, CmdFunc, CmdComments) \
  127. { CmdCode, CmdName, CmdFunc, CmdComments},
  128. static CmdStruct g_cmds[] = {
  129. DefineAllCommands()
  130. { maxCmdCode, NULL, NULL} // sentinel command
  131. };
  132. #undef Cmd
  133. /************************************************************
  134. * Functions
  135. ************************************************************/
  136. BOOL
  137. GenUsageMessage( int argc, char * argv[])
  138. {
  139. CmdStruct * pCmd;
  140. printf( " Usage:\n %s <server-name/address> <cmd name> <cmd arguments>\n",
  141. argv[0]);
  142. for( pCmd = g_cmds; pCmd != NULL && pCmd->cmdCode != maxCmdCode; pCmd++) {
  143. printf( "\t%s\t%s\n", pCmd->pszCmdName, pCmd->pszCmdComments);
  144. }
  145. return ( TRUE);
  146. } // GenUsageMessage()
  147. static
  148. CmdStruct * DecodeCommand( char * pszCmd)
  149. {
  150. CmdStruct * pCmd;
  151. if ( pszCmd != NULL) {
  152. for( pCmd = g_cmds;
  153. pCmd != NULL && pCmd->cmdCode != maxCmdCode; pCmd++) {
  154. if ( _stricmp( pszCmd, pCmd->pszCmdName) == 0) {
  155. return ( pCmd);
  156. }
  157. } // for
  158. }
  159. return ( &g_cmds[0]); // No match found, return usage message
  160. } // DecodeCommand()
  161. static
  162. LPWSTR
  163. ConvertToUnicode( char * psz)
  164. /*++
  165. Converts a given string into unicode string (after allocating buffer space)
  166. Returns NULL on failure. Use GetLastError() for details.
  167. --*/
  168. {
  169. LPWSTR pszUnicode;
  170. int cch;
  171. cch = strlen( psz) + 1;
  172. pszUnicode = ( LPWSTR ) malloc( cch * sizeof( WCHAR));
  173. if ( pszUnicode != NULL) {
  174. // Success. Copy the string now
  175. int iRet;
  176. iRet = MultiByteToWideChar( CP_ACP, MB_PRECOMPOSED,
  177. psz, cch,
  178. pszUnicode, cch);
  179. if ( iRet == 0 || iRet != cch) {
  180. free( pszUnicode); // failure so free the block
  181. pszUnicode = NULL;
  182. }
  183. } else {
  184. SetLastError( ERROR_NOT_ENOUGH_MEMORY);
  185. }
  186. return ( pszUnicode);
  187. } // ConvertToUnicode()
  188. static
  189. VOID
  190. PrintStatisticsInfo( IN LPGOPHERD_STATISTICS_INFO pStat)
  191. {
  192. if ( pStat == NULL) {
  193. return ;
  194. }
  195. printf( " Printing Statistics Information: \n");
  196. printf( "%20s = %4.3g\n", "Bytes Sent",
  197. LargeIntegerToDouble( pStat->TotalBytesSent));
  198. printf( "%20s = %4.3g\n", "Bytes Received",
  199. LargeIntegerToDouble(pStat->TotalBytesRecvd));
  200. printf( "%20s = %ld\n", "Files Sent ", pStat->TotalFilesSent);
  201. printf( "%20s = %ld\n", "Directory Listings",
  202. pStat->TotalDirectoryListings);
  203. printf( "%20s = %ld\n", "Searches Done ", pStat->TotalSearches);
  204. printf( "%20s = %ld\n", "Current Anon Users",
  205. pStat->CurrentAnonymousUsers);
  206. printf( "%20s = %ld\n", "Current NonAnon Users",
  207. pStat->CurrentNonAnonymousUsers);
  208. printf( "%20s = %ld\n", "Total Anon Users", pStat->TotalAnonymousUsers);
  209. printf( "%20s = %ld\n", "Total NonAnon Users",
  210. pStat->TotalNonAnonymousUsers);
  211. printf( "%20s = %ld\n", "Max Anon Users", pStat->MaxAnonymousUsers);
  212. printf( "%20s = %ld\n", "Max NonAnon Users", pStat->MaxNonAnonymousUsers);
  213. printf( "%20s = %ld\n", "Current Connections", pStat->CurrentConnections);
  214. printf( "%20s = %ld\n", "Total Connections", pStat->TotalConnections);
  215. printf( "%20s = %ld\n", "Max Connections", pStat->MaxConnections);
  216. printf( "%20s = %ld\n", "Connection Attempts", pStat->ConnectionAttempts);
  217. printf( "%20s = %ld\n", "Logon Attempts", pStat->LogonAttempts);
  218. printf( "%20s = %ld\n", "Aborted Attempts", pStat->AbortedAttempts);
  219. printf( "%20s = %ld\n", "Errored Connections", pStat->ErroredConnections);
  220. printf( "%20s = %ld\n", "Gopher+ Requests", pStat->GopherPlusRequests);
  221. return;
  222. } // PrintStatisticsInfo()
  223. static
  224. VOID
  225. PrintStatsForTime( IN LPGOPHERD_STATISTICS_INFO pStatStart,
  226. IN LPGOPHERD_STATISTICS_INFO pStatEnd,
  227. IN DWORD sInterval)
  228. /*++
  229. Print the statistics information over a time interval sInterval seconds.
  230. Arguments:
  231. pStatStart pointer to statistics information for starting sample
  232. pStatEnd pointer to statistics information for ending sample
  233. sInterval Time interval in seconds for the sample
  234. Returns:
  235. None
  236. --*/
  237. {
  238. LARGE_INTEGER liDiff;
  239. if ( pStatStart == NULL || pStatEnd == NULL ) {
  240. return ;
  241. }
  242. printf( "Gopher Stats. Time: %u seconds\n", sInterval);
  243. printf( "%20s\t %10s\t%10s\t%10s\n\n",
  244. "Item", "Start Sample", "End Sample", "Difference");
  245. liDiff.QuadPart = ( pStatEnd->TotalBytesSent.QuadPart -
  246. pStatStart->TotalBytesSent.QuadPart);
  247. printf( "%20s\t %10.3g\t %10.3g\t %10.3g\n",
  248. "Bytes Sent",
  249. LargeIntegerToDouble( pStatStart->TotalBytesSent),
  250. LargeIntegerToDouble( pStatStart->TotalBytesSent),
  251. LargeIntegerToDouble( liDiff)
  252. );
  253. liDiff.QuadPart = ( pStatEnd->TotalBytesRecvd.QuadPart -
  254. pStatStart->TotalBytesRecvd.QuadPart);
  255. printf( "%20s\t %10.3g\t %10.3g\t %10.3g\n",
  256. "Bytes Received",
  257. LargeIntegerToDouble(pStatStart->TotalBytesRecvd),
  258. LargeIntegerToDouble(pStatEnd->TotalBytesRecvd),
  259. LargeIntegerToDouble(liDiff)
  260. );
  261. printf( "%20s\t %10ld\t %10ld\t %10ld\n",
  262. "Files Sent ",
  263. pStatStart->TotalFilesSent,
  264. pStatEnd->TotalFilesSent,
  265. pStatEnd->TotalFilesSent - pStatStart->TotalFilesSent
  266. );
  267. printf( "%20s\t %10ld\t %10ld\t %10ld\n",
  268. "Directory Listings",
  269. pStatStart->TotalDirectoryListings,
  270. pStatEnd->TotalDirectoryListings,
  271. pStatEnd->TotalDirectoryListings -
  272. pStatStart->TotalDirectoryListings
  273. );
  274. printf( "%20s\t %10ld\t %10ld\t %10ld\n",
  275. "Searches Done ",
  276. pStatStart->TotalSearches,
  277. pStatEnd->TotalSearches,
  278. pStatEnd->TotalSearches - pStatStart->TotalSearches
  279. );
  280. printf( "%20s\t %10ld\t %10ld\t %10ld\n",
  281. "Current Anon Users",
  282. pStatStart->CurrentAnonymousUsers,
  283. pStatEnd->CurrentAnonymousUsers,
  284. pStatEnd->CurrentAnonymousUsers - pStatStart->CurrentAnonymousUsers
  285. );
  286. printf( "%20s\t %10ld\t %10ld\t %10ld\n",
  287. "Current NonAnon Users",
  288. pStatStart->CurrentNonAnonymousUsers,
  289. pStatEnd->CurrentNonAnonymousUsers,
  290. pStatStart->CurrentNonAnonymousUsers -
  291. pStatEnd->CurrentNonAnonymousUsers
  292. );
  293. printf( "%20s\t %10ld\t %10ld\t %10ld\n",
  294. "Total Anon Users",
  295. pStatStart->TotalAnonymousUsers,
  296. pStatEnd->TotalAnonymousUsers,
  297. pStatEnd->TotalAnonymousUsers - pStatStart->TotalAnonymousUsers
  298. );
  299. printf( "%20s\t %10ld\t %10ld\t %10ld\n",
  300. "Total NonAnon Users",
  301. pStatStart->TotalNonAnonymousUsers,
  302. pStatEnd->TotalNonAnonymousUsers,
  303. pStatEnd->TotalNonAnonymousUsers -pStatStart->TotalNonAnonymousUsers
  304. );
  305. printf( "%20s\t %10ld\t %10ld\t %10ld\n",
  306. "Max Anon Users",
  307. pStatStart->MaxAnonymousUsers,
  308. pStatEnd->MaxAnonymousUsers,
  309. pStatEnd->MaxAnonymousUsers - pStatStart->MaxAnonymousUsers
  310. );
  311. printf( "%20s\t %10ld\t %10ld\t %10ld\n",
  312. "Max NonAnon Users",
  313. pStatStart->MaxNonAnonymousUsers,
  314. pStatEnd->MaxNonAnonymousUsers,
  315. pStatEnd->MaxNonAnonymousUsers - pStatStart->MaxNonAnonymousUsers
  316. );
  317. printf( "%20s\t %10ld\t %10ld\t %10ld\n",
  318. "Current Connections",
  319. pStatStart->CurrentConnections,
  320. pStatEnd->CurrentConnections,
  321. pStatEnd->CurrentConnections - pStatStart->CurrentConnections
  322. );
  323. printf( "%20s\t %10ld\t %10ld\t %10ld\n",
  324. "Total Connections",
  325. pStatStart->TotalConnections,
  326. pStatEnd->TotalConnections,
  327. pStatEnd->TotalConnections - pStatStart->TotalConnections
  328. );
  329. printf( "%20s\t %10ld\t %10ld\t %10ld\n",
  330. "Max Connections",
  331. pStatStart->MaxConnections,
  332. pStatEnd->MaxConnections,
  333. pStatEnd->MaxConnections - pStatStart->MaxConnections
  334. );
  335. printf( "%20s\t %10ld\t %10ld\t %10ld\n",
  336. "Connection Attempts",
  337. pStatStart->ConnectionAttempts,
  338. pStatEnd->ConnectionAttempts,
  339. pStatEnd->ConnectionAttempts - pStatStart->ConnectionAttempts
  340. );
  341. printf( "%20s\t %10ld\t %10ld\t %10ld\n",
  342. "Logon Attempts",
  343. pStatStart->LogonAttempts,
  344. pStatEnd->LogonAttempts,
  345. pStatEnd->LogonAttempts - pStatStart->LogonAttempts
  346. );
  347. printf( "%20s\t %10ld\t %10ld\t %10ld\n",
  348. "Aborted Attempts",
  349. pStatStart->AbortedAttempts,
  350. pStatEnd->AbortedAttempts,
  351. pStatEnd->AbortedAttempts - pStatStart->AbortedAttempts
  352. );
  353. printf( "%20s\t %10ld\t %10ld\t %10ld\n",
  354. "Errored Connections",
  355. pStatStart->ErroredConnections,
  356. pStatEnd->ErroredConnections,
  357. pStatEnd->ErroredConnections - pStatStart->ErroredConnections
  358. );
  359. printf( "%20s\t %10ld\t %10ld\t %10ld\n",
  360. "Gopher+ Requests",
  361. pStatStart->GopherPlusRequests,
  362. pStatEnd->GopherPlusRequests,
  363. pStatEnd->GopherPlusRequests - pStatStart->GopherPlusRequests
  364. );
  365. return;
  366. } // PrintStatisticsInfo()
  367. BOOL
  368. TestGetStatistics( int argc, char * argv[] )
  369. /*++
  370. Gets Gopher Statistics from server and prints it.
  371. If the optional time information is given, then this function
  372. obtains the statistics, sleeps for specified time interval and then
  373. again obtains new statistics and prints the difference, neatly formatted.
  374. Arguments:
  375. argc = count of arguments
  376. argv array of strings for command
  377. argv[0] = stats
  378. argv[1] = time interval if specified in seconds
  379. --*/
  380. {
  381. DWORD err;
  382. DWORD timeToSleep = 0;
  383. GOPHERD_STATISTICS_INFO stat1;
  384. GOPHERD_STATISTICS_INFO * pStat1 = &stat1;
  385. if ( argc > 1 && argv[1] != NULL) {
  386. timeToSleep = atoi( argv[1]);
  387. }
  388. err = GdGetStatistics( g_lpszServerAddress,
  389. (LPBYTE ) pStat1);
  390. if ( err == NO_ERROR) {
  391. if ( timeToSleep <= 0) {
  392. PrintStatisticsInfo( pStat1);
  393. } else {
  394. GOPHERD_STATISTICS_INFO stat2;
  395. GOPHERD_STATISTICS_INFO * pStat2 = &stat2;
  396. printf( "\nGopher Statistics For Time Interval %u seconds\n\n",
  397. timeToSleep);
  398. Sleep( timeToSleep * 1000); // sleep for the interval
  399. err = GdGetStatistics( g_lpszServerAddress,
  400. (LPBYTE ) pStat2);
  401. if ( err == NO_ERROR) {
  402. PrintStatsForTime( pStat1, pStat2, timeToSleep);
  403. }
  404. }
  405. }
  406. SetLastError( err);
  407. return ( err == NO_ERROR);
  408. } // TestGetStatistics()
  409. BOOL
  410. TestClearStatistics( int argc, char * argv[])
  411. {
  412. DWORD err;
  413. printf( " GdClearStatistics called at: Time = %d\n",
  414. GetTickCount());
  415. err = GdClearStatistics( g_lpszServerAddress);
  416. printf( " Time = %d\n",
  417. GetTickCount());
  418. printf( "Cleared the statistics Err = %d\n", err);
  419. SetLastError( err);
  420. return ( err == NO_ERROR);
  421. } // TestClearStatistics()
  422. static VOID
  423. PrintAdminInformation( IN LPGOPHERD_CONFIG_INFO pConfigInfo)
  424. {
  425. if ( pConfigInfo == NULL)
  426. return;
  427. printf( "\n Printing Config Information in %08x\n", pConfigInfo);
  428. printf( "%20s= %S\n", "Site Name", pConfigInfo->lpszSite);
  429. printf( "%20s= %S\n", "Organization", pConfigInfo->lpszOrganization);
  430. printf( "%20s= %S\n", "Location", pConfigInfo->lpszLocation);
  431. printf( "%20s= %S\n", "Geography", pConfigInfo->lpszGeography);
  432. printf( "%20s= %S\n", "Language", pConfigInfo->lpszLanguage);
  433. printf( "%20s= %d\n", "CheckForWaisDb", pConfigInfo->fCheckForWaisDb);
  434. printf( "%20s= %x\n", "Debugging Flags", pConfigInfo->dwDebugFlags);
  435. return;
  436. } // PrintAdminInformation()
  437. static BOOL
  438. TestGetAdminInfo( int argc, char * argv[] )
  439. {
  440. DWORD err;
  441. LPGOPHERD_CONFIG_INFO pConfig = NULL;
  442. printf( " GdGetAdminInformation() called at: Time = %d\n",
  443. GetTickCount());
  444. err = GdGetAdminInformation( g_lpszServerAddress, &pConfig);
  445. printf( " Time = %d\n", GetTickCount());
  446. printf( "GdGetAdminInformation returned Error Code = %d\n", err);
  447. if ( err == NO_ERROR) {
  448. PrintAdminInformation( pConfig);
  449. MIDL_user_free( ( LPVOID) pConfig);
  450. }
  451. SetLastError( err);
  452. return ( err == NO_ERROR);
  453. } // TestGetAdminInfo()
  454. DWORD
  455. SetAdminField(
  456. IN LPGOPHERD_CONFIG_INFO pConfigIn,
  457. IN char * pszSubCmd,
  458. IN char * pszValue)
  459. {
  460. DWORD err = NO_ERROR;
  461. CmdStruct * pCmd = DecodeCommand( pszSubCmd); // get command struct
  462. if ( pCmd == NULL) {
  463. // ignore invalid commands
  464. printf( " Invalid SubCommand for set admin info %s. Ignoring...\n",
  465. pszSubCmd);
  466. return ( ERROR_INVALID_PARAMETER);
  467. }
  468. switch ( pCmd->cmdCode) {
  469. # if DBG
  470. case CmdDebugFlags:
  471. SetField( pConfigIn->FieldControl, GDA_DEBUG_FLAGS);
  472. pConfigIn->dwDebugFlags = atoi( pszValue);
  473. break;
  474. # endif // DBG
  475. case CmdSite:
  476. SetField( pConfigIn->FieldControl, GDA_SITE);
  477. pConfigIn->lpszSite = ConvertToUnicode( pszValue);
  478. if ( pConfigIn->lpszSite == NULL) {
  479. err = GetLastError();
  480. }
  481. break;
  482. case CmdOrganization:
  483. SetField( pConfigIn->FieldControl, GDA_ORGANIZATION);
  484. pConfigIn->lpszOrganization = ConvertToUnicode( pszValue);
  485. if ( pConfigIn->lpszOrganization == NULL) {
  486. err = GetLastError();
  487. }
  488. break;
  489. case CmdLocation:
  490. SetField( pConfigIn->FieldControl, GDA_LOCATION);
  491. pConfigIn->lpszLocation = ConvertToUnicode( pszValue);
  492. if ( pConfigIn->lpszLocation == NULL) {
  493. err = GetLastError();
  494. }
  495. break;
  496. case CmdGeography:
  497. SetField( pConfigIn->FieldControl, GDA_GEOGRAPHY);
  498. pConfigIn->lpszGeography = ConvertToUnicode( pszValue);
  499. if ( pConfigIn->lpszGeography == NULL) {
  500. err = GetLastError();
  501. }
  502. break;
  503. case CmdLanguage:
  504. SetField( pConfigIn->FieldControl, GDA_LANGUAGE);
  505. pConfigIn->lpszLanguage = ConvertToUnicode( pszValue);
  506. if ( pConfigIn->lpszLanguage == NULL) {
  507. err = GetLastError();
  508. }
  509. break;
  510. case CmdCheckForWaisDb:
  511. SetField( pConfigIn->FieldControl, GDA_CHECK_FOR_WAISDB);
  512. pConfigIn->fCheckForWaisDb = (atoi(pszValue) != 0) ? TRUE: FALSE;
  513. break;
  514. default:
  515. printf( " Invalid Sub command %s for SetConfigInfo(). Ignoring.\n",
  516. pszSubCmd);
  517. err = ERROR_INVALID_PARAMETER;
  518. break;
  519. } // switch
  520. return ( err);
  521. } // SetAdminField()
  522. static VOID
  523. FreeBuffer( IN PVOID * ppBuffer)
  524. {
  525. if ( *ppBuffer != NULL) {
  526. free( * ppBuffer);
  527. *ppBuffer = NULL; // reset the old value
  528. }
  529. return;
  530. } // FreeBuffer()
  531. VOID
  532. FreeStringsInAdminInfo( IN OUT LPGOPHERD_CONFIG_INFO pConfigInfo)
  533. {
  534. FreeBuffer( (PVOID *) & pConfigInfo->lpszSite);
  535. FreeBuffer( (PVOID *) & pConfigInfo->lpszOrganization);
  536. FreeBuffer( (PVOID *) & pConfigInfo->lpszLocation);
  537. FreeBuffer( (PVOID *) & pConfigInfo->lpszGeography);
  538. FreeBuffer( (PVOID *) & pConfigInfo->lpszLanguage);
  539. } // FreeStringsInAdminInfo()
  540. BOOL
  541. TestSetAdminInfo( int argc, char * argv[])
  542. /*++
  543. Arguments:
  544. argc = count of arguments
  545. argv array of strings for command
  546. argv[0] = setadmininfo
  547. argv[1] = sub function within set info for testing
  548. argv[2] = value for sub function
  549. for all information to be set, give <sub command name> <value>
  550. --*/
  551. {
  552. DWORD err = ERROR_CALL_NOT_IMPLEMENTED;
  553. LPGOPHERD_CONFIG_INFO * ppConfigOut = NULL;
  554. // config value obtained from server
  555. GOPHERD_CONFIG_INFO configIn; // config values that are set
  556. if ( argc < 1 || ( (argc & 0x1) != 0x1 ) ) { // argc should be > 1 and odd
  557. printf( "Invalid Number of arguments for %s\n", argv[0]);
  558. SetLastError( ERROR_INVALID_PARAMETER);
  559. return ( FALSE);
  560. }
  561. //
  562. // form the admin info block to set the information
  563. //
  564. memset( ( LPVOID) &configIn, 0, sizeof( configIn)); // init to Zeros
  565. // extract each field and value to set in configIn
  566. for( ; --argc > 1; argc -= 2) {
  567. if ( SetAdminField( &configIn, argv[argc - 1], argv[argc])
  568. != NO_ERROR) {
  569. break;
  570. }
  571. } // for() to extract and set all fields
  572. if ( err != NO_ERROR) {
  573. // Now make RPC call to set the fields
  574. err = GdSetAdminInformation( g_lpszServerAddress,
  575. &configIn);
  576. }
  577. // Need to free all the buffers allocated for the strings
  578. FreeStringsInAdminInfo( &configIn);
  579. SetLastError( err );
  580. return ( err == NO_ERROR );
  581. } // TestSetAdminInfo()
  582. static VOID
  583. PrintInetAdminInformation( IN LPINET_INFO_CONFIG_INFO pConfigInfo)
  584. {
  585. if ( pConfigInfo == NULL)
  586. return;
  587. printf( "\n Printing InetA Config Information in %08x\n", pConfigInfo);
  588. printf( "%20s= %d\n", "LogAnonymous", pConfigInfo->fLogAnonymous);
  589. printf( "%20s= %d\n", "LogNonAnonymous",pConfigInfo->fLogNonAnonymous);
  590. printf( "%20s= %08x\n", "Authentication Flags",
  591. pConfigInfo->dwAuthentication);
  592. printf( "%20s= %d\n", "Port", pConfigInfo->sPort);
  593. printf( "%20s= %d\n", "Connection Timeout",
  594. pConfigInfo->dwConnectionTimeout);
  595. printf( "%20s= %d\n", "Max Connections",
  596. pConfigInfo->dwMaxConnections);
  597. printf( "%20s= %S\n", "AnonUserName", pConfigInfo->lpszAnonUserName);
  598. printf( "%20s= %S\n", "AnonPassword", pConfigInfo->szAnonPassword);
  599. //
  600. // IP lists and Grant lists not included now. Later.
  601. //
  602. return;
  603. } // PrintInetAdminInformation()
  604. static BOOL
  605. TestInetGetAdminInfo( int argc, char * argv[] )
  606. /*++
  607. Gets the configuration information using InetInfoGetAdminInformation()
  608. --*/
  609. {
  610. DWORD err;
  611. LPINET_INFO_CONFIG_INFO pConfig = NULL;
  612. printf( " InetInfoGetAdminInformation() called at: Time = %d\n",
  613. GetTickCount());
  614. err = InetInfoGetAdminInformation( g_lpszServerAddress,
  615. INET_GOPHER,
  616. &pConfig);
  617. printf( "Finished at Time = %d\n", GetTickCount());
  618. printf( "InetInfoGetAdminInformation returned Error Code = %d\n", err);
  619. if ( err == NO_ERROR) {
  620. PrintInetAdminInformation( pConfig);
  621. MIDL_user_free( ( LPVOID) pConfig);
  622. }
  623. SetLastError( err);
  624. return ( err == NO_ERROR);
  625. } // TestInetGetAdminInfo()
  626. DWORD
  627. SetInetAdminField(
  628. IN LPINET_INFO_CONFIG_INFO pConfigIn,
  629. IN char * pszSubCmd,
  630. IN char * pszValue)
  631. {
  632. DWORD err = NO_ERROR;
  633. CmdStruct * pCmd = DecodeCommand( pszSubCmd); // get command struct
  634. if ( pCmd == NULL) {
  635. // ignore invalid commands
  636. printf( " Invalid SubCommand for set admin info %s. Ignoring...\n",
  637. pszSubCmd);
  638. return ( ERROR_INVALID_PARAMETER);
  639. }
  640. switch ( pCmd->cmdCode) {
  641. case CmdPortNumber:
  642. SetField( pConfigIn->FieldControl, FC_INET_INFO_PORT_NUMBER);
  643. pConfigIn->sPort = atoi( pszValue);
  644. break;
  645. case CmdConnectionTimeout:
  646. SetField( pConfigIn->FieldControl, FC_INET_INFO_CONNECTION_TIMEOUT);
  647. pConfigIn->dwConnectionTimeout = atoi( pszValue);
  648. break;
  649. case CmdMaxConnections:
  650. SetField( pConfigIn->FieldControl, FC_INET_INFO_MAX_CONNECTIONS);
  651. pConfigIn->dwMaxConnections = atoi( pszValue);
  652. break;
  653. case CmdLogAnonymous:
  654. SetField( pConfigIn->FieldControl, FC_INET_INFO_LOG_ANONYMOUS);
  655. pConfigIn->fLogAnonymous = atoi( pszValue);
  656. break;
  657. case CmdLogNonAnonymous:
  658. SetField( pConfigIn->FieldControl, FC_INET_INFO_LOG_NONANONYMOUS);
  659. pConfigIn->fLogNonAnonymous = atoi( pszValue);
  660. break;
  661. case CmdAnonUserName:
  662. SetField( pConfigIn->FieldControl, FC_INET_INFO_ANON_USER_NAME);
  663. pConfigIn->lpszAnonUserName = ConvertToUnicode( pszValue);
  664. if ( pConfigIn->lpszAnonUserName == NULL) {
  665. err = GetLastError();
  666. }
  667. break;
  668. default:
  669. printf( " Invalid Sub command %s for SetConfigInfo(). Ignoring.\n",
  670. pszSubCmd);
  671. err = ERROR_INVALID_PARAMETER;
  672. break;
  673. } // switch
  674. return ( err);
  675. } // SetAdminField()
  676. VOID
  677. FreeStringsInInetConfigInfo( IN OUT LPINET_INFO_CONFIG_INFO pConfigInfo)
  678. {
  679. FreeBuffer( (PVOID *) & pConfigInfo->lpszAnonUserName);
  680. } // FreeStringsInInetConfigInfo()
  681. BOOL
  682. TestInetSetAdminInfo( int argc, char * argv[])
  683. /*++
  684. Arguments:
  685. argc = count of arguments
  686. argv array of strings for command
  687. argv[0] = setadmininfo
  688. argv[1] = sub function within set info for testing
  689. argv[2] = value for sub function
  690. for all information to be set, give <sub command name> <value>
  691. --*/
  692. {
  693. DWORD err = ERROR_CALL_NOT_IMPLEMENTED;
  694. LPINET_INFO_CONFIG_INFO * ppConfigOut = NULL;
  695. INET_INFO_CONFIG_INFO configIn; // config values that are set
  696. if ( argc < 1 || ( (argc & 0x1) != 0x1 ) ) { // argc should be > 1 and odd
  697. printf( "Invalid Number of arguments for %s\n", argv[0]);
  698. SetLastError( ERROR_INVALID_PARAMETER);
  699. return ( FALSE);
  700. }
  701. //
  702. // form the admin info block to set the information
  703. //
  704. memset( ( LPVOID) &configIn, 0, sizeof( configIn)); // init to Zeros
  705. // extract each field and value to set in configIn
  706. for( ; --argc > 1; argc -= 2) {
  707. if ( SetInetAdminField( &configIn, argv[argc - 1], argv[argc])
  708. != NO_ERROR) {
  709. break;
  710. }
  711. } // for() to extract and set all fields
  712. if ( err != NO_ERROR) {
  713. // Now make RPC call to set the fields
  714. err = InetInfoSetAdminInformation( g_lpszServerAddress,
  715. INET_GOPHER,
  716. &configIn);
  717. }
  718. // Need to free all the buffers allocated for the strings
  719. FreeStringsInInetConfigInfo( &configIn);
  720. SetLastError( err );
  721. return ( err == NO_ERROR );
  722. } // TestSetInetAdminInfo()
  723. int __cdecl
  724. main( int argc, char * argv[])
  725. {
  726. DWORD err = NO_ERROR;
  727. char ** ppszArgv; // arguments for command functions
  728. int cArgs; // arg count for command functions
  729. char * pszCmdName;
  730. CmdStruct * pCmd;
  731. CMDFUNC pCmdFunc = NULL;
  732. if ( argc < 3 || argv[1] == NULL ) {
  733. // Insufficient arguments
  734. GenUsageMessage( argc, argv);
  735. return ( 1);
  736. }
  737. pszCmdName = argv[2];
  738. if (( pCmd = DecodeCommand( pszCmdName)) == NULL || pCmd->cmdFunc == NULL) {
  739. printf( "Internal Error: Invalid Command %s\n", pszCmdName);
  740. GenUsageMessage( argc, argv);
  741. return ( 1);
  742. }
  743. g_lpszServerAddress = ConvertToUnicode( argv[1]); // get server address
  744. cArgs = argc - 2;
  745. ppszArgv = argv + 2; // position at the start of the command name
  746. if ( !(*pCmd->cmdFunc)( cArgs, ppszArgv)) { // call the test function
  747. // Test function failed.
  748. printf( "Command %s failed. Error = %d\n", pszCmdName, GetLastError());
  749. return ( 1);
  750. }
  751. printf( " Command %s succeeded\n", pszCmdName);
  752. return ( 0); // success
  753. } // main()
  754. /************************ End of File ***********************/