Leaked source code of windows server 2003
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.

856 lines
25 KiB

  1. /*++
  2. Copyright (c) 1994 Microsoft Corporation
  3. Module Name :
  4. infotest.cxx
  5. Abstract:
  6. main program to test the working of RPC APIs for Internet Services
  7. Author:
  8. Murali R. Krishnan ( MuraliK ) 23-Jan-1996
  9. Project:
  10. Internet Services Common RPC Client.
  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 "inetinfo.h"
  22. # include "apiutil.h"
  23. //
  24. // size of half dword in bits
  25. //
  26. # define HALF_DWORD_SIZE ( sizeof(DWORD) * 8 / 2)
  27. //
  28. // To Avoid overflows I multiply using two parts
  29. //
  30. # define LargeIntegerToDouble( li) \
  31. ( ( 1 << HALF_DWORD_SIZE) * \
  32. (( double) (li).HighPart) * ( 1 << HALF_DWORD_SIZE) + \
  33. ((li).LowPart) \
  34. )
  35. static LPWSTR g_lpszServerAddress = NULL;
  36. //
  37. // Prototypes of Functions
  38. //
  39. BOOL GenUsageMessage( int argc, char * argv[]);
  40. BOOL TestGetStatistics( int argc, char * argv[]);
  41. BOOL TestInetGetAdminInfo( int argc, char * argv[]);
  42. BOOL TestInetSetAdminInfo( int argc, char * argv[]);
  43. //
  44. // The following DefineAllCommands() defines a template for all commands.
  45. // Format: CmdCodeName CommandName Function Pointer Comments
  46. //
  47. // To add addditional test commands, add just another line to the
  48. // given list
  49. // Dont touch any macros below, they are all automatically generated.
  50. // Always the first entry should be usage function.
  51. //
  52. #define DefineAllCommands() \
  53. Cmd( CmdUsage, "usage", GenUsageMessage, \
  54. " Commands Available" ) \
  55. Cmd( CmdGetStatistics, "getstatistics", TestGetStatistics, \
  56. " Get Common Statistics" ) \
  57. Cmd( CmdInetGetAdminInfo, "igetadmininfo", TestInetGetAdminInfo, \
  58. " Get common Internet Administrative Information" ) \
  59. Cmd( CmdInetSetAdminInfo, "isetadmininfo", TestInetSetAdminInfo, \
  60. " Set common Internet Administrative Information" ) \
  61. Cmd( CmdGet1Statistics, "stats", TestGetStatistics, \
  62. " Get Common Statistics" ) \
  63. Cmd( CmdDebugFlags, "debug", NULL, \
  64. " isetadmininfo: Set Debugging flags for the server" ) \
  65. Cmd( CmdPortNumber, "port", NULL, \
  66. " isetadmininfo: Set the port number for server") \
  67. Cmd( CmdMaxConnections, "maxconn", NULL, \
  68. " isetadmininfo: Set the max connections allowed in server") \
  69. Cmd( CmdConnectionTimeout, "timeout", NULL, \
  70. " isetadmininfo: Set the Connection Timeout interval( in seconds)") \
  71. Cmd( CmdLogAnonymous, "loganon", NULL, \
  72. " isetadmininfo: Set the LogAnonymous Flag") \
  73. Cmd( CmdLogNonAnonymous, "lognonanon", NULL, \
  74. " isetadmininfo: Set the LogNonAnonymous Flag") \
  75. Cmd( CmdAnonUserName, "anonuser", NULL, \
  76. " isetadmininfo: Set the Anonymous User Name ") \
  77. Cmd( CmdAdminName, "adminname", NULL, \
  78. " isetadmininfo: Set the Administrator name ") \
  79. Cmd( CmdAdminEmail, "adminemail", NULL, \
  80. " isetadmininfo: Set the Administrator Email ") \
  81. Cmd( CmdServerComment, "servercomment", NULL, \
  82. " isetadmininfo: Set the Server Comments for server ") \
  83. // Define command codes
  84. # define Cmd( CmdCode, CmdName, CmdFunc, CmdComments) CmdCode,
  85. typedef enum _CmdCodes {
  86. DefineAllCommands()
  87. maxCmdCode
  88. } CmdCodes;
  89. #undef Cmd
  90. // Define the functions and array of mappings
  91. // General command function type
  92. typedef BOOL ( * CMDFUNC)( int argc, char * argv[]);
  93. typedef struct _CmdStruct {
  94. CmdCodes cmdCode;
  95. char * pszCmdName;
  96. CMDFUNC cmdFunc;
  97. char * pszCmdComments;
  98. } CmdStruct;
  99. // Define Prototypes of command functions
  100. # define Cmd( CmdCode, CmdName, CmdFunc, CmdComments) \
  101. BOOL CmdFunc(int argc, char * argv[]);
  102. // Cause an expansion to generate prototypes
  103. // DefineAllCommands()
  104. // Automatic generation causes a problem when we have NULL in Function ptrs :(
  105. // Let the user explicitly define the prototypes
  106. #undef Cmd
  107. //
  108. // Define the global array of commands
  109. //
  110. # define Cmd( CmdCode, CmdName, CmdFunc, CmdComments) \
  111. { CmdCode, CmdName, CmdFunc, CmdComments},
  112. static CmdStruct g_cmds[] = {
  113. DefineAllCommands()
  114. { maxCmdCode, NULL, NULL} // sentinel command
  115. };
  116. #undef Cmd
  117. /************************************************************
  118. * Functions
  119. ************************************************************/
  120. BOOL
  121. GenUsageMessage( int argc, char * argv[])
  122. {
  123. CmdStruct * pCmd;
  124. printf( " Usage:\n %s <server-name/address> <cmd name> <cmd arguments>\n",
  125. argv[0]);
  126. for( pCmd = g_cmds; pCmd != NULL && pCmd->cmdCode != maxCmdCode; pCmd++) {
  127. printf( "\t%s\t%s\n", pCmd->pszCmdName, pCmd->pszCmdComments);
  128. }
  129. return ( TRUE);
  130. } // GenUsageMessage()
  131. static
  132. CmdStruct * DecodeCommand( char * pszCmd)
  133. {
  134. CmdStruct * pCmd;
  135. if ( pszCmd != NULL) {
  136. for( pCmd = g_cmds;
  137. pCmd != NULL && pCmd->cmdCode != maxCmdCode; pCmd++) {
  138. if ( lstrcmpiA( pszCmd, pCmd->pszCmdName) == 0) {
  139. return ( pCmd);
  140. }
  141. } // for
  142. }
  143. return ( &g_cmds[0]); // No match found, return usage message
  144. } // DecodeCommand()
  145. static
  146. LPWSTR
  147. ConvertToUnicode( char * psz)
  148. /*++
  149. Converts a given string into unicode string (after allocating buffer space)
  150. Returns NULL on failure. Use GetLastError() for details.
  151. --*/
  152. {
  153. LPWSTR pszUnicode;
  154. int cch;
  155. cch = strlen( psz) + 1;
  156. pszUnicode = ( LPWSTR ) malloc( cch * sizeof( WCHAR));
  157. if ( pszUnicode != NULL) {
  158. // Success. Copy the string now
  159. int iRet;
  160. iRet = MultiByteToWideChar( CP_ACP, MB_PRECOMPOSED,
  161. psz, cch,
  162. pszUnicode, cch);
  163. if ( iRet == 0 || iRet != cch) {
  164. free( pszUnicode); // failure so free the block
  165. pszUnicode = NULL;
  166. }
  167. } else {
  168. SetLastError( ERROR_NOT_ENOUGH_MEMORY);
  169. }
  170. return ( pszUnicode);
  171. } // ConvertToUnicode()
  172. static
  173. VOID
  174. PrintStatisticsInfo( IN LPINET_INFO_STATISTICS_0 pStat)
  175. {
  176. double gCacheHit = 0;
  177. if ( pStat == NULL) {
  178. return ;
  179. }
  180. printf( " Printing Statistics Information: \n");
  181. printf( "%20s = %ld\n", "Cache Bytes Total",
  182. pStat->CacheCtrs.CacheBytesTotal);
  183. printf( "%20s = %ld\n", "Cache Bytes In Use",
  184. pStat->CacheCtrs.CacheBytesInUse);
  185. printf( "%20s = %ld\n", "Open File Handles ",
  186. pStat->CacheCtrs.CurrentOpenFileHandles);
  187. printf( "%20s = %ld\n", "Current Dir Lists",
  188. pStat->CacheCtrs.CurrentDirLists);
  189. printf( "%20s = %ld\n", "Current Objects ",
  190. pStat->CacheCtrs.CurrentObjects);
  191. printf( "%20s = %ld\n", "Cache Flushes",
  192. pStat->CacheCtrs.FlushesFromDirChanges);
  193. printf( "%20s = %ld\n", "Cache Hits",
  194. pStat->CacheCtrs.CacheHits);
  195. printf( "%20s = %ld\n", "Cache Misses",
  196. pStat->CacheCtrs.CacheMisses);
  197. gCacheHit = (((float) pStat->CacheCtrs.CacheHits * 100) /
  198. (pStat->CacheCtrs.CacheHits + pStat->CacheCtrs.CacheMisses));
  199. printf( "%20s = %6.4g\n", " Cache Hit Ratio",
  200. gCacheHit);
  201. printf( "%20s = %ld\n", "Atq Allowed Requests",
  202. pStat->AtqCtrs.TotalAllowedRequests);
  203. printf( "%20s = %ld\n", "Atq Blocked Requests",
  204. pStat->AtqCtrs.TotalBlockedRequests);
  205. printf( "%20s = %ld\n", "Atq Current Blocked Requests",
  206. pStat->AtqCtrs.CurrentBlockedRequests);
  207. printf( "%20s = %ld Bytes/sec\n", "Atq Measured Bandwidth",
  208. pStat->AtqCtrs.MeasuredBandwidth);
  209. #ifndef NO_AUX_PERF
  210. printf( " Auxiliary Counters # = %u\n",
  211. pStat->nAuxCounters);
  212. for ( DWORD i = 0; i < pStat->nAuxCounters; i++) {
  213. printf( "Aux Counter[%u] = %u\n", i, pStat->rgCounters[i]);
  214. } //for
  215. #endif // NO_AUX_PERF
  216. return;
  217. } // PrintStatisticsInfo()
  218. static
  219. VOID
  220. PrintStatsForTime( IN INET_INFO_STATISTICS_0 * pStatStart,
  221. IN INET_INFO_STATISTICS_0 * pStatEnd,
  222. IN DWORD sInterval)
  223. /*++
  224. Print the statistics information over a time interval sInterval seconds.
  225. Arguments:
  226. pStatStart pointer to statistics information for starting sample
  227. pStatEnd pointer to statistics information for ending sample
  228. sInterval Time interval in seconds for the sample
  229. Returns:
  230. None
  231. --*/
  232. {
  233. DWORD dwDiff;
  234. if ( pStatStart == NULL || pStatEnd == NULL || sInterval == 0 ) {
  235. return ;
  236. }
  237. printf( "Statistics for Interval = %u seconds\n", sInterval);
  238. printf( "%20s\t %10s\t%10s\t%10s\t%6s\n\n",
  239. "Item ", "Start Sample", "End Sample", "Difference", "Rate/s");
  240. dwDiff = (pStatEnd->CacheCtrs.CacheBytesTotal -
  241. pStatStart->CacheCtrs.CacheBytesTotal);
  242. printf( "%20s\t %10.3g\t %10ld\t %10ld\t%6ld\n",
  243. "Cache Bytes Total",
  244. (pStatStart->CacheCtrs.CacheBytesTotal),
  245. (pStatEnd->CacheCtrs.CacheBytesTotal),
  246. dwDiff,
  247. dwDiff/sInterval
  248. );
  249. dwDiff = (pStatEnd->CacheCtrs.CacheBytesInUse -
  250. pStatStart->CacheCtrs.CacheBytesInUse);
  251. printf( "%20s\t %10.3g\t %10ld\t %10ld\t%6ld\n",
  252. "Cache Bytes In Use",
  253. (pStatStart->CacheCtrs.CacheBytesInUse),
  254. (pStatEnd->CacheCtrs.CacheBytesInUse),
  255. dwDiff,
  256. dwDiff/sInterval
  257. );
  258. dwDiff = (pStatEnd->CacheCtrs.CurrentOpenFileHandles -
  259. pStatStart->CacheCtrs.CurrentOpenFileHandles);
  260. printf( "%20s\t %10ld\t %10ld\t %10ld\t%6ld\n",
  261. "File Handle Cached ",
  262. (pStatStart->CacheCtrs.CurrentOpenFileHandles),
  263. (pStatEnd->CacheCtrs.CurrentOpenFileHandles),
  264. dwDiff,
  265. dwDiff/sInterval
  266. );
  267. dwDiff = (pStatEnd->CacheCtrs.CurrentDirLists -
  268. pStatStart->CacheCtrs.CurrentDirLists);
  269. printf( "%20s\t %10ld\t %10ld\t %10ld\t%6ld\n",
  270. "Current Dir Lists ",
  271. (pStatStart->CacheCtrs.CurrentDirLists),
  272. (pStatEnd->CacheCtrs.CurrentDirLists),
  273. dwDiff,
  274. dwDiff/sInterval
  275. );
  276. dwDiff = (pStatEnd->CacheCtrs.CurrentObjects -
  277. pStatStart->CacheCtrs.CurrentObjects);
  278. printf( "%20s\t %10ld\t %10ld\t %10ld\t%6ld\n",
  279. "Current Objects Cached",
  280. (pStatStart->CacheCtrs.CurrentObjects),
  281. (pStatEnd->CacheCtrs.CurrentObjects),
  282. dwDiff,
  283. dwDiff/sInterval
  284. );
  285. dwDiff = (pStatEnd->CacheCtrs.FlushesFromDirChanges -
  286. pStatStart->CacheCtrs.FlushesFromDirChanges);
  287. printf( "%20s\t %10ld\t %10ld\t %10ld\t%6ld\n",
  288. "Cache Flushes",
  289. (pStatStart->CacheCtrs.FlushesFromDirChanges),
  290. (pStatEnd->CacheCtrs.FlushesFromDirChanges),
  291. dwDiff,
  292. dwDiff/sInterval
  293. );
  294. dwDiff = (pStatEnd->CacheCtrs.CacheHits -
  295. pStatStart->CacheCtrs.CacheHits);
  296. printf( "%20s\t %10ld\t %10ld\t %10ld\t%6ld\n",
  297. "Cache Hits",
  298. (pStatStart->CacheCtrs.CacheHits),
  299. (pStatEnd->CacheCtrs.CacheHits),
  300. dwDiff,
  301. dwDiff/sInterval
  302. );
  303. dwDiff = (pStatEnd->CacheCtrs.CacheMisses -
  304. pStatStart->CacheCtrs.CacheMisses);
  305. printf( "%20s\t %10ld\t %10ld\t %10ld\t%6ld\n",
  306. "Cache Misses",
  307. (pStatStart->CacheCtrs.CacheMisses),
  308. (pStatEnd->CacheCtrs.CacheMisses),
  309. dwDiff,
  310. dwDiff/sInterval
  311. );
  312. dwDiff = (pStatEnd->AtqCtrs.TotalAllowedRequests -
  313. pStatStart->AtqCtrs.TotalAllowedRequests);
  314. printf( "%20s\t %10ld\t %10ld\t %10ld\t%6ld\n",
  315. "Total Atq Allowed Requests",
  316. (pStatStart->AtqCtrs.TotalAllowedRequests),
  317. (pStatEnd->AtqCtrs.TotalAllowedRequests),
  318. dwDiff,
  319. dwDiff/sInterval
  320. );
  321. dwDiff = (pStatEnd->AtqCtrs.TotalBlockedRequests -
  322. pStatStart->AtqCtrs.TotalBlockedRequests);
  323. printf( "%20s\t %10ld\t %10ld\t %10ld\t%6ld\n",
  324. "Total Atq Blocked Requests",
  325. (pStatStart->AtqCtrs.TotalBlockedRequests),
  326. (pStatEnd->AtqCtrs.TotalBlockedRequests),
  327. dwDiff,
  328. dwDiff/sInterval
  329. );
  330. dwDiff = (pStatEnd->AtqCtrs.TotalRejectedRequests -
  331. pStatStart->AtqCtrs.TotalRejectedRequests);
  332. printf( "%20s\t %10ld\t %10ld\t %10ld\t%6ld\n",
  333. "Total Atq Rejected Requests",
  334. (pStatStart->AtqCtrs.TotalRejectedRequests),
  335. (pStatEnd->AtqCtrs.TotalRejectedRequests),
  336. dwDiff,
  337. dwDiff/sInterval
  338. );
  339. dwDiff = (pStatEnd->AtqCtrs.CurrentBlockedRequests -
  340. pStatStart->AtqCtrs.CurrentBlockedRequests);
  341. printf( "%20s\t %10ld\t %10ld\t %10ld\t%6ld\n",
  342. "Current Atq Blocked Requests",
  343. (pStatStart->AtqCtrs.CurrentBlockedRequests),
  344. (pStatEnd->AtqCtrs.CurrentBlockedRequests),
  345. dwDiff,
  346. dwDiff/sInterval
  347. );
  348. dwDiff = (pStatEnd->AtqCtrs.MeasuredBandwidth -
  349. pStatStart->AtqCtrs.MeasuredBandwidth);
  350. printf( "%20s\t %10ld\t %10ld\t %10ld\t%6ld\n",
  351. "Measured Bandwidth",
  352. (pStatStart->AtqCtrs.MeasuredBandwidth),
  353. (pStatEnd->AtqCtrs.MeasuredBandwidth),
  354. dwDiff,
  355. dwDiff/sInterval
  356. );
  357. return;
  358. } // PrintStatisticsInfo()
  359. BOOL
  360. TestGetStatistics( int argc, char * argv[] )
  361. /*++
  362. Gets common Statistics from server and prints it.
  363. If the optional time information is given, then this function
  364. obtains the statistics, sleeps for specified time interval and then
  365. again obtains new statistics and prints the difference, neatly formatted.
  366. Arguments:
  367. argc = count of arguments
  368. argv array of strings for command
  369. argv[0] = stats or getstatistics
  370. argv[1] = time interval if specified in seconds
  371. --*/
  372. {
  373. DWORD err;
  374. DWORD timeToSleep = 0;
  375. INET_INFO_STATISTICS_0 * pStat1 = NULL;
  376. if ( argc > 1 && argv[1] != NULL) {
  377. timeToSleep = atoi( argv[1]);
  378. }
  379. err = InetInfoQueryStatistics(g_lpszServerAddress,
  380. 0,
  381. 0,
  382. (LPBYTE *) &pStat1);
  383. if ( err == NO_ERROR) {
  384. if ( timeToSleep <= 0) {
  385. PrintStatisticsInfo( pStat1);
  386. } else {
  387. INET_INFO_STATISTICS_0 * pStat2 = NULL;
  388. printf( "Statistics For Time Interval %u seconds\n\n",
  389. timeToSleep);
  390. Sleep( timeToSleep * 1000); // sleep for the interval
  391. err = InetInfoQueryStatistics(g_lpszServerAddress,
  392. 0,
  393. 0,
  394. (LPBYTE *) &pStat2);
  395. if ( err == NO_ERROR) {
  396. PrintStatsForTime( pStat1, pStat2, timeToSleep);
  397. }
  398. if ( pStat2 != NULL) {
  399. MIDL_user_free( pStat2);
  400. }
  401. }
  402. }
  403. if ( pStat1 != NULL) {
  404. MIDL_user_free( pStat1);
  405. }
  406. SetLastError( err);
  407. return ( err == NO_ERROR);
  408. } // TestGetStatistics()
  409. static VOID
  410. PrintInetAdminInformation( IN LPINETA_CONFIG_INFO pConfigInfo)
  411. {
  412. if ( pConfigInfo == NULL)
  413. return;
  414. printf( "\n Printing InetA Config Information in %08x\n", pConfigInfo);
  415. printf( "%20s= %d\n", "LogAnonymous", pConfigInfo->fLogAnonymous);
  416. printf( "%20s= %d\n", "LogNonAnonymous",pConfigInfo->fLogNonAnonymous);
  417. printf( "%20s= %08x\n", "Authentication Flags",
  418. pConfigInfo->dwAuthentication);
  419. printf( "%20s= %d\n", "Port", pConfigInfo->sPort);
  420. printf( "%20s= %d\n", "Connection Timeout",
  421. pConfigInfo->CommonConfigInfo.dwConnectionTimeout);
  422. printf( "%20s= %d\n", "Max Connections",
  423. pConfigInfo->CommonConfigInfo.dwMaxConnections);
  424. printf( "%20s= %S\n", "AnonUserName",
  425. pConfigInfo->lpszAnonUserName);
  426. printf( "%20s= %S\n", "AnonPassword",
  427. pConfigInfo->szAnonPassword);
  428. printf( "%20s= %S\n", "Admin Name",
  429. pConfigInfo->CommonConfigInfo.lpszAdminName);
  430. printf( "%20s= %S\n", "Admin Email",
  431. pConfigInfo->CommonConfigInfo.lpszAdminEmail);
  432. printf( "%20s= %S\n", "Server Comments",
  433. pConfigInfo->CommonConfigInfo.lpszServerComment);
  434. //
  435. // IP lists and Grant lists, Virtual Roots are not included now. Later.
  436. //
  437. return;
  438. } // PrintInetAdminInformation()
  439. static DWORD
  440. GetServiceIdFromString( IN LPCSTR pszService)
  441. {
  442. if ( pszService != NULL) {
  443. if ( !_stricmp(pszService, "HTTP")) {
  444. return ( INET_HTTP);
  445. } else if (!_stricmp( pszService, "GOPHER")) {
  446. return (INET_GOPHER);
  447. } else if ( !_stricmp( pszService, "FTP")) {
  448. return (INET_FTP);
  449. } else if ( !_stricmp( pszService, "DNS")) {
  450. return (INET_DNS);
  451. }
  452. }
  453. return ( INET_HTTP);
  454. } // GetServiceIdFromString()
  455. static BOOL
  456. TestInetGetAdminInfo( int argc, char * argv[] )
  457. /*++
  458. Gets the configuration information using InetInfoGetAdminInformation()
  459. argv[0] = igetadmininfo
  460. argv[1] = service name ( gopher, http, ftp, catapult)
  461. --*/
  462. {
  463. DWORD err;
  464. LPINETA_CONFIG_INFO pConfig = NULL;
  465. DWORD dwServiceId;
  466. printf( " InetInfoGetAdminInformation() called at: Time = %d\n",
  467. GetTickCount());
  468. dwServiceId = (argc > 1) ? GetServiceIdFromString( argv[1]) : INET_HTTP;
  469. err = InetInfoGetAdminInformation( NULL, // g_lpszServerAddress,
  470. dwServiceId,
  471. &pConfig);
  472. printf( "Finished at Time = %d\n", GetTickCount());
  473. printf( "InetInfoGetAdminInformation returned Error Code = %d\n", err);
  474. if ( err == NO_ERROR) {
  475. PrintInetAdminInformation( pConfig);
  476. MIDL_user_free( ( LPVOID) pConfig);
  477. }
  478. SetLastError( err);
  479. return ( err == NO_ERROR);
  480. } // TestInetGetAdminInfo()
  481. DWORD
  482. SetInetAdminField(
  483. IN LPINETA_CONFIG_INFO pConfigIn,
  484. IN char * pszSubCmd,
  485. IN char * pszValue)
  486. {
  487. DWORD err = NO_ERROR;
  488. CmdStruct * pCmd = DecodeCommand( pszSubCmd); // get command struct
  489. if ( pCmd == NULL) {
  490. // ignore invalid commands
  491. printf( " Invalid SubCommand for set admin info %s. Ignoring...\n",
  492. pszSubCmd);
  493. return ( ERROR_INVALID_PARAMETER);
  494. }
  495. switch ( pCmd->cmdCode) {
  496. case CmdPortNumber:
  497. SetField( pConfigIn->FieldControl, FC_INET_INFO_PORT_NUMBER);
  498. pConfigIn->sPort = atoi( pszValue);
  499. break;
  500. case CmdConnectionTimeout:
  501. SetField( pConfigIn->FieldControl, FC_INET_COM_CONNECTION_TIMEOUT);
  502. pConfigIn->CommonConfigInfo.dwConnectionTimeout = atoi( pszValue);
  503. break;
  504. case CmdMaxConnections:
  505. SetField( pConfigIn->FieldControl, FC_INET_COM_MAX_CONNECTIONS);
  506. pConfigIn->CommonConfigInfo.dwMaxConnections = atoi( pszValue);
  507. break;
  508. case CmdLogAnonymous:
  509. SetField( pConfigIn->FieldControl, FC_INET_INFO_LOG_ANONYMOUS);
  510. pConfigIn->fLogAnonymous = atoi( pszValue);
  511. break;
  512. case CmdLogNonAnonymous:
  513. SetField( pConfigIn->FieldControl, FC_INET_INFO_LOG_NONANONYMOUS);
  514. pConfigIn->fLogNonAnonymous = atoi( pszValue);
  515. break;
  516. case CmdAnonUserName:
  517. SetField( pConfigIn->FieldControl, FC_INET_INFO_ANON_USER_NAME);
  518. pConfigIn->lpszAnonUserName = ConvertToUnicode( pszValue);
  519. if ( pConfigIn->lpszAnonUserName == NULL) {
  520. err = GetLastError();
  521. }
  522. break;
  523. case CmdAdminName:
  524. SetField( pConfigIn->FieldControl, FC_INET_COM_ADMIN_NAME);
  525. pConfigIn->CommonConfigInfo.lpszAdminName =
  526. ConvertToUnicode( pszValue);
  527. if ( pConfigIn->CommonConfigInfo.lpszAdminName == NULL) {
  528. err = GetLastError();
  529. }
  530. break;
  531. case CmdAdminEmail:
  532. SetField( pConfigIn->FieldControl, FC_INET_COM_ADMIN_EMAIL);
  533. pConfigIn->CommonConfigInfo.lpszAdminEmail =
  534. ConvertToUnicode( pszValue);
  535. if ( pConfigIn->CommonConfigInfo.lpszAdminEmail == NULL) {
  536. err = GetLastError();
  537. }
  538. break;
  539. case CmdServerComment:
  540. SetField( pConfigIn->FieldControl, FC_INET_COM_SERVER_COMMENT);
  541. pConfigIn->CommonConfigInfo.lpszServerComment =
  542. ConvertToUnicode( pszValue);
  543. if ( pConfigIn->CommonConfigInfo.lpszServerComment == NULL) {
  544. err = GetLastError();
  545. }
  546. break;
  547. default:
  548. printf( " Invalid Sub command %s for SetConfigInfo(). Ignoring.\n",
  549. pszSubCmd);
  550. err = ERROR_INVALID_PARAMETER;
  551. break;
  552. } // switch
  553. return ( err);
  554. } // SetAdminField()
  555. static VOID
  556. FreeBuffer( IN PVOID * ppBuffer)
  557. {
  558. if ( *ppBuffer != NULL) {
  559. free( * ppBuffer);
  560. *ppBuffer = NULL; // reset the old value
  561. }
  562. return;
  563. } // FreeBuffer()
  564. VOID
  565. FreeStringsInInetConfigInfo( IN OUT LPINETA_CONFIG_INFO pConfigInfo)
  566. {
  567. FreeBuffer( (PVOID *) & pConfigInfo->lpszAnonUserName);
  568. } // FreeStringsInInetConfigInfo()
  569. BOOL
  570. TestInetSetAdminInfo( int argc, char * argv[])
  571. /*++
  572. Arguments:
  573. argc = count of arguments
  574. argv array of strings for command
  575. argv[0] = isetadmininfo
  576. argv[1] = sub function within set info for testing
  577. argv[2] = value for sub function
  578. for all information to be set, give <sub command name> <value>
  579. --*/
  580. {
  581. DWORD err = ERROR_CALL_NOT_IMPLEMENTED;
  582. LPINETA_CONFIG_INFO * ppConfigOut = NULL;
  583. INETA_CONFIG_INFO configIn; // config values that are set
  584. if ( argc < 1 || ( (argc & 0x1) != 0x1 ) ) { // argc should be > 1 and odd
  585. printf( "Invalid Number of arguments for %s\n", argv[0]);
  586. SetLastError( ERROR_INVALID_PARAMETER);
  587. return ( FALSE);
  588. }
  589. //
  590. // form the admin info block to set the information
  591. //
  592. memset( ( LPVOID) &configIn, 0, sizeof( configIn)); // init to Zeros
  593. // extract each field and value to set in configIn
  594. for( ; --argc > 1; argc -= 2) {
  595. if ( SetInetAdminField( &configIn, argv[argc - 1], argv[argc])
  596. != NO_ERROR) {
  597. break;
  598. }
  599. } // for() to extract and set all fields
  600. if ( err != NO_ERROR) {
  601. // Now make RPC call to set the fields
  602. err = InetInfoSetAdminInformation( g_lpszServerAddress,
  603. INET_HTTP,
  604. &configIn);
  605. }
  606. // Need to free all the buffers allocated for the strings
  607. FreeStringsInInetConfigInfo( &configIn);
  608. SetLastError( err );
  609. return ( err == NO_ERROR );
  610. } // TestSetInetAdminInfo()
  611. int __cdecl
  612. main( int argc, char * argv[])
  613. {
  614. DWORD err = NO_ERROR;
  615. char ** ppszArgv; // arguments for command functions
  616. int cArgs; // arg count for command functions
  617. char * pszCmdName;
  618. CmdStruct * pCmd;
  619. CMDFUNC pCmdFunc = NULL;
  620. if ( argc < 3 || argv[1] == NULL ) {
  621. // Insufficient arguments
  622. GenUsageMessage( argc, argv);
  623. return ( 1);
  624. }
  625. pszCmdName = argv[2];
  626. if (( pCmd = DecodeCommand( pszCmdName)) == NULL || pCmd->cmdFunc == NULL) {
  627. printf( "Internal Error: Invalid Command %s\n", pszCmdName);
  628. GenUsageMessage( argc, argv);
  629. return ( 1);
  630. }
  631. g_lpszServerAddress = ConvertToUnicode( argv[1]); // get server address
  632. cArgs = argc - 2;
  633. ppszArgv = argv + 2; // position at the start of the command name
  634. if ( !(*pCmd->cmdFunc)( cArgs, ppszArgv)) { // call the test function
  635. // Test function failed.
  636. printf( "Command %s failed. Error = %d\n", pszCmdName, GetLastError());
  637. return ( 1);
  638. }
  639. printf( " Command %s succeeded\n", pszCmdName);
  640. return ( 0); // success
  641. } // main()
  642. /************************ End of File ***********************/