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.

1461 lines
43 KiB

  1. /*++
  2. Copyright (c) 1994 Microsoft Corporation
  3. Module Name :
  4. ftpadmin.cxx
  5. Abstract:
  6. main program to test the working of RPC APIs of ftp server
  7. Author:
  8. Murali R. Krishnan ( MuraliK ) 25-July-1995
  9. Project:
  10. FTP 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. # define _INETASRV_H_
  25. # include "ftpd.h"
  26. # include "apiutil.h"
  27. //
  28. // size of half dword in bits
  29. //
  30. # define HALF_DWORD_SIZE ( sizeof(DWORD) * 8 / 2)
  31. //
  32. // To Avoid overflows I multiply using two parts
  33. //
  34. # define LargeIntegerToDouble( li) \
  35. ( ( 1 << HALF_DWORD_SIZE) * \
  36. (( double) (li).HighPart) * ( 1 << HALF_DWORD_SIZE) + \
  37. ((li).LowPart) \
  38. )
  39. static LPWSTR g_lpszServerAddress = NULL;
  40. //
  41. // Prototypes of Functions
  42. //
  43. BOOL GenUsageMessage( int argc, char * argv[]);
  44. BOOL TestGetCommonStatistics( int argc, char * argv[] );
  45. BOOL TestGetStatistics( int argc, char * argv[]);
  46. BOOL TestClearStatistics( int argc, char * argv[]);
  47. BOOL TestGetAdminInfo( int argc, char * argv[]);
  48. BOOL TestSetAdminInfo( int argc, char * argv[]);
  49. BOOL TestInetGetAdminInfo( int argc, char * argv[]);
  50. BOOL TestInetSetAdminInfo( int argc, char * argv[]);
  51. BOOL TestEnumUserInfo( int argc, char * argv[]);
  52. BOOL TestDisconnectUser( int argc, char * argv[]);
  53. //
  54. // The following DefineAllCommands() defines a template for all commands.
  55. // Format: CmdCodeName CommandName Function Pointer Comments
  56. //
  57. // To add addditional test commands, add just another line to the list
  58. // Dont touch any macros below, they are all automatically generated.
  59. // Always the first entry should be usage function.
  60. //
  61. #define DefineAllCommands() \
  62. Cmd( CmdUsage, "usage", GenUsageMessage, \
  63. " Commands Available" ) \
  64. Cmd( CmdGetStatistics, "getstatistics", TestGetStatistics, \
  65. " Get Server Statistics " ) \
  66. Cmd( CmdGetStatisticsShort, "getstats", TestGetStatistics, \
  67. " Get Server Statistics " ) \
  68. Cmd( CmdGetStats, "stats", TestGetStatistics, \
  69. " Get Server Statistics " ) \
  70. Cmd( CmdGetCommonStats, "istats", TestGetCommonStatistics, \
  71. " Get Common Statistics " ) \
  72. Cmd( CmdClearStatistics, "clearstatistics", TestClearStatistics,\
  73. " Clear Server Statistics" ) \
  74. Cmd( CmdGetAdminInfo, "getadmininfo", TestGetAdminInfo, \
  75. " Get Administrative Information" ) \
  76. Cmd( CmdSetAdminInfo, "setadmininfo", TestSetAdminInfo, \
  77. " Set Administrative Information" ) \
  78. Cmd( CmdEnumUserInfo, "enumusers", TestEnumUserInfo, \
  79. " Enumerate connected users" ) \
  80. Cmd( CmdKillUser, "killuser", TestDisconnectUser, \
  81. " Disconnects a specified user" ) \
  82. Cmd( CmdInetGetAdminInfo, "igetadmininfo", TestInetGetAdminInfo, \
  83. " Get common Internet Administrative Information" ) \
  84. Cmd( CmdInetSetAdminInfo, "isetadmininfo", TestInetSetAdminInfo, \
  85. " Set common Internet Administrative Information" ) \
  86. Cmd( CmdDebugFlags, "debug", NULL, \
  87. " isetadmininfo: Set Debugging flags for the server" ) \
  88. Cmd( CmdPortNumber, "port", NULL, \
  89. " isetadmininfo: Set the port number for server") \
  90. Cmd( CmdMaxConnections, "maxconn", NULL, \
  91. " isetadmininfo: Set the max connections allowed in server") \
  92. Cmd( CmdConnectionTimeout, "timeout", NULL, \
  93. " isetadmininfo: Set the Connection Timeout interval( in seconds)") \
  94. Cmd( CmdLogAnonymous, "loganon", NULL, \
  95. " isetadmininfo: Set the LogAnonymous Flag") \
  96. Cmd( CmdLogNonAnonymous, "lognonanon", NULL, \
  97. " isetadmininfo: Set the LogNonAnonymous Flag") \
  98. Cmd( CmdAnonUserName, "anonuser", NULL, \
  99. " isetadmininfo: Set the Anonymous User Name ") \
  100. Cmd( CmdAdminName, "adminname", NULL, \
  101. " isetadmininfo: Set the Administrator name ") \
  102. Cmd( CmdAdminEmail, "adminemail", NULL, \
  103. " isetadmininfo: Set the Administrator Email ") \
  104. Cmd( CmdServerComment, "servercomment", NULL, \
  105. " isetadmininfo: Set the Server Comments for server ") \
  106. Cmd( CmdGreetingMessage, "greeting", NULL, \
  107. " setadmininfo: Sets the Greeting Message ") \
  108. Cmd( CmdExitMessage, "exitmsg", NULL, \
  109. " setadmininfo: Sets the Exit Message ") \
  110. Cmd( CmdMaxClientsMessage, "maxclientsmsg", NULL, \
  111. " setadmininfo: Sets the Max Clients Message ") \
  112. Cmd( CmdAllowAnonymous, "allowanon", NULL, \
  113. " setadmininfo: Sets the allow anonymous flag ") \
  114. Cmd( CmdAllowGuest, "allowguest", NULL, \
  115. " setadmininfo: Sets the allow guest access flag ") \
  116. Cmd( CmdAllowAnonOnly, "allowanononly", NULL, \
  117. " setadmininfo: Sets the allow anonymous only flag ") \
  118. Cmd( CmdAnnotateDirs, "annotatedirs", NULL, \
  119. " setadmininfo: Sets the Annotate Directories flag ") \
  120. Cmd( CmdListenBacklog, "listenbacklog", NULL, \
  121. " setadmininfo: Sets the Listen Backlog value ") \
  122. Cmd( CmdMsdosDir, "msdosdir", NULL, \
  123. " setadmininfo: Sets the MsDos Directory listing flag ") \
  124. // Define command codes
  125. # define Cmd( CmdCode, CmdName, CmdFunc, CmdComments) CmdCode,
  126. typedef enum _CmdCodes {
  127. DefineAllCommands()
  128. maxCmdCode
  129. } CmdCodes;
  130. #undef Cmd
  131. // Define the functions and array of mappings
  132. // General command function type
  133. typedef BOOL ( * CMDFUNC)( int argc, char * argv[]);
  134. typedef struct _CmdStruct {
  135. CmdCodes cmdCode;
  136. char * pszCmdName;
  137. CMDFUNC cmdFunc;
  138. char * pszCmdComments;
  139. } CmdStruct;
  140. // Define Prototypes of command functions
  141. # define Cmd( CmdCode, CmdName, CmdFunc, CmdComments) \
  142. BOOL CmdFunc(int argc, char * argv[]);
  143. // Cause an expansion to generate prototypes
  144. // DefineAllCommands()
  145. // Automatic generation causes a problem when we have NULL in Function ptrs :(
  146. // Let the user explicitly define the prototypes
  147. #undef Cmd
  148. //
  149. // Define the global array of commands
  150. //
  151. # define Cmd( CmdCode, CmdName, CmdFunc, CmdComments) \
  152. { CmdCode, CmdName, CmdFunc, CmdComments},
  153. static CmdStruct g_cmds[] = {
  154. DefineAllCommands()
  155. { maxCmdCode, NULL, NULL} // sentinel command
  156. };
  157. #undef Cmd
  158. /************************************************************
  159. * Functions
  160. ************************************************************/
  161. BOOL
  162. GenUsageMessage( int argc, char * argv[])
  163. {
  164. CmdStruct * pCmd;
  165. printf( " Usage:\n %s <server-name/address> <cmd name> <cmd arguments>\n",
  166. argv[0]);
  167. for( pCmd = g_cmds; pCmd != NULL && pCmd->cmdCode != maxCmdCode; pCmd++) {
  168. printf( "\t%s\t%s\n", pCmd->pszCmdName, pCmd->pszCmdComments);
  169. }
  170. return ( TRUE);
  171. } // GenUsageMessage()
  172. static
  173. CmdStruct * DecodeCommand( char * pszCmd)
  174. {
  175. CmdStruct * pCmd;
  176. if ( pszCmd != NULL) {
  177. for( pCmd = g_cmds;
  178. pCmd != NULL && pCmd->cmdCode != maxCmdCode; pCmd++) {
  179. if ( _stricmp( pszCmd, pCmd->pszCmdName) == 0) {
  180. return ( pCmd);
  181. }
  182. } // for
  183. }
  184. return ( &g_cmds[0]); // No match found, return usage message
  185. } // DecodeCommand()
  186. static
  187. LPWSTR
  188. ConvertToUnicode( char * psz)
  189. /*++
  190. Converts a given string into unicode string (after allocating buffer space)
  191. Returns NULL on failure. Use GetLastError() for details.
  192. --*/
  193. {
  194. LPWSTR pszUnicode;
  195. int cch;
  196. cch = strlen( psz) + 1;
  197. pszUnicode = ( LPWSTR ) malloc( cch * sizeof( WCHAR));
  198. if ( pszUnicode != NULL) {
  199. // Success. Copy the string now
  200. int iRet;
  201. iRet = MultiByteToWideChar( CP_ACP, MB_PRECOMPOSED,
  202. psz, cch,
  203. pszUnicode, cch);
  204. if ( iRet == 0 || iRet != cch) {
  205. free( pszUnicode); // failure so free the block
  206. pszUnicode = NULL;
  207. }
  208. } else {
  209. SetLastError( ERROR_NOT_ENOUGH_MEMORY);
  210. }
  211. return ( pszUnicode);
  212. } // ConvertToUnicode()
  213. static
  214. VOID
  215. PrintStatisticsInfo( IN FTP_STATISTICS_0 * pStat)
  216. {
  217. if ( pStat == NULL) {
  218. return ;
  219. }
  220. printf( " Printing Statistics Information: \n");
  221. printf( "%20s = %10.3g\n", "BytesSent",
  222. LargeIntegerToDouble(pStat->TotalBytesSent));
  223. printf( "%20s = %4.3g\n", "BytesReceived",
  224. LargeIntegerToDouble(pStat->TotalBytesReceived));
  225. printf( "%20s = %ld\n", "Files Sent ", pStat->TotalFilesSent);
  226. printf( "%20s = %ld\n", "Files Received ", pStat->TotalFilesReceived);
  227. printf( "%20s = %ld\n", "Current Anon Users",pStat->CurrentAnonymousUsers);
  228. printf( "%20s = %ld\n", "Current NonAnon",
  229. pStat->CurrentNonAnonymousUsers);
  230. printf( "%20s = %ld\n", "Total Anon Users", pStat->TotalAnonymousUsers);
  231. printf( "%20s = %ld\n", "Total NonAnon Users",
  232. pStat->TotalNonAnonymousUsers);
  233. printf( "%20s = %ld\n", "Max Anon Users", pStat->MaxAnonymousUsers);
  234. printf( "%20s = %ld\n", "Max NonAnon Users", pStat->MaxNonAnonymousUsers);
  235. printf( "%20s = %ld\n", "Current Connections", pStat->CurrentConnections);
  236. printf( "%20s = %ld\n", "Max Connections", pStat->MaxConnections);
  237. printf( "%20s = %ld\n", "Connection Attempts", pStat->ConnectionAttempts);
  238. printf( "%20s = %ld\n", "Logon Attempts", pStat->LogonAttempts);
  239. printf( "%20s = %s\n", "Time of Last Clear",
  240. asctime( localtime( (time_t *)&pStat->TimeOfLastClear ) ) );
  241. return;
  242. } // PrintStatisticsInfo()
  243. static
  244. VOID
  245. PrintStatsForTime( IN FTP_STATISTICS_0 * pStatStart,
  246. IN FTP_STATISTICS_0 * pStatEnd,
  247. IN DWORD sInterval)
  248. /*++
  249. Print the statistics information over a time interval sInterval seconds.
  250. Arguments:
  251. pStatStart pointer to statistics information for starting sample
  252. pStatEnd pointer to statistics information for ending sample
  253. sInterval Time interval in seconds for the sample
  254. Returns:
  255. None
  256. --*/
  257. {
  258. LARGE_INTEGER liDiff;
  259. double dDiff;
  260. if ( pStatStart == NULL || pStatEnd == NULL || sInterval == 0 ) {
  261. return ;
  262. }
  263. printf( "Statistics for Interval = %u seconds\n", sInterval);
  264. printf( "%20s\t %10s\t%10s\t%10s\t%6s\n\n",
  265. "Item ", "Start Sample", "End Sample", "Difference", "Rate/s");
  266. liDiff.QuadPart = ( pStatEnd->TotalBytesSent.QuadPart -
  267. pStatStart->TotalBytesSent.QuadPart);
  268. dDiff = LargeIntegerToDouble( liDiff);
  269. printf( "%20s\t %10.3g\t %10.3g\t %10.3g\t%6.3g\n",
  270. "Bytes Sent",
  271. LargeIntegerToDouble( pStatStart->TotalBytesSent),
  272. LargeIntegerToDouble( pStatEnd->TotalBytesSent),
  273. dDiff,
  274. dDiff/sInterval
  275. );
  276. liDiff.QuadPart = ( pStatEnd->TotalBytesReceived.QuadPart -
  277. pStatStart->TotalBytesReceived.QuadPart);
  278. dDiff = LargeIntegerToDouble( liDiff);
  279. printf( "%20s\t %10.3g\t %10.3g\t %10.3g\t%6.3g\n",
  280. "Bytes Received",
  281. LargeIntegerToDouble(pStatStart->TotalBytesReceived),
  282. LargeIntegerToDouble(pStatEnd->TotalBytesReceived),
  283. dDiff,
  284. dDiff/sInterval
  285. );
  286. printf( "%20s\t %10ld\t %10ld\t %10ld\t%6ld\n",
  287. "Files Sent ",
  288. pStatStart->TotalFilesSent,
  289. pStatEnd->TotalFilesSent,
  290. pStatEnd->TotalFilesSent - pStatStart->TotalFilesSent,
  291. (pStatEnd->TotalFilesSent - pStatStart->TotalFilesSent)/sInterval
  292. );
  293. printf( "%20s\t %10ld\t %10ld\t %10ld\t%6ld\n",
  294. "Files Received ",
  295. pStatStart->TotalFilesReceived,
  296. pStatEnd->TotalFilesReceived,
  297. pStatEnd->TotalFilesReceived - pStatStart->TotalFilesReceived,
  298. (pStatEnd->TotalFilesReceived -
  299. pStatStart->TotalFilesReceived)/sInterval
  300. );
  301. printf( "%20s\t %10ld\t %10ld\t %10ld\t%6ld\n",
  302. "Current Anon Users",
  303. pStatStart->CurrentAnonymousUsers,
  304. pStatEnd->CurrentAnonymousUsers,
  305. pStatEnd->CurrentAnonymousUsers - pStatStart->CurrentAnonymousUsers,
  306. (int ) (pStatEnd->CurrentAnonymousUsers -
  307. pStatStart->CurrentAnonymousUsers)/sInterval
  308. );
  309. printf( "%20s\t %10ld\t %10ld\t %10ld\t%6ld\n",
  310. "Current NonAnon Users",
  311. pStatStart->CurrentNonAnonymousUsers,
  312. pStatEnd->CurrentNonAnonymousUsers,
  313. (pStatStart->CurrentNonAnonymousUsers -
  314. pStatEnd->CurrentNonAnonymousUsers),
  315. (int ) (pStatStart->CurrentNonAnonymousUsers -
  316. pStatEnd->CurrentNonAnonymousUsers)/sInterval
  317. );
  318. printf( "%20s\t %10ld\t %10ld\t %10ld\t%6ld\n",
  319. "Total Anon Users",
  320. pStatStart->TotalAnonymousUsers,
  321. pStatEnd->TotalAnonymousUsers,
  322. pStatEnd->TotalAnonymousUsers - pStatStart->TotalAnonymousUsers,
  323. (pStatEnd->TotalAnonymousUsers - pStatStart->TotalAnonymousUsers)/
  324. sInterval
  325. );
  326. printf( "%20s\t %10ld\t %10ld\t %10ld\t%6ld\n",
  327. "Total NonAnon Users",
  328. pStatStart->TotalNonAnonymousUsers,
  329. pStatEnd->TotalNonAnonymousUsers,
  330. (pStatEnd->TotalNonAnonymousUsers -
  331. pStatStart->TotalNonAnonymousUsers),
  332. (pStatEnd->TotalNonAnonymousUsers -
  333. pStatStart->TotalNonAnonymousUsers)/sInterval
  334. );
  335. printf( "%20s\t %10ld\t %10ld\t %10ld\t%6ld\n",
  336. "Max Anon Users",
  337. pStatStart->MaxAnonymousUsers,
  338. pStatEnd->MaxAnonymousUsers,
  339. pStatEnd->MaxAnonymousUsers - pStatStart->MaxAnonymousUsers,
  340. (pStatEnd->MaxAnonymousUsers - pStatStart->MaxAnonymousUsers)
  341. /sInterval
  342. );
  343. printf( "%20s\t %10ld\t %10ld\t %10ld\t%6ld\n",
  344. "Max NonAnon Users",
  345. pStatStart->MaxNonAnonymousUsers,
  346. pStatEnd->MaxNonAnonymousUsers,
  347. pStatEnd->MaxNonAnonymousUsers - pStatStart->MaxNonAnonymousUsers,
  348. (pStatEnd->MaxNonAnonymousUsers - pStatStart->MaxNonAnonymousUsers)/
  349. sInterval
  350. );
  351. printf( "%20s\t %10ld\t %10ld\t %10ld\t%6ld\n",
  352. "Current Connections",
  353. pStatStart->CurrentConnections,
  354. pStatEnd->CurrentConnections,
  355. pStatEnd->CurrentConnections - pStatStart->CurrentConnections,
  356. (int )
  357. (pStatEnd->CurrentConnections - pStatStart->CurrentConnections)/
  358. sInterval
  359. );
  360. printf( "%20s\t %10ld\t %10ld\t %10ld\t%6ld\n",
  361. "Max Connections",
  362. pStatStart->MaxConnections,
  363. pStatEnd->MaxConnections,
  364. pStatEnd->MaxConnections - pStatStart->MaxConnections,
  365. (pStatEnd->MaxConnections - pStatStart->MaxConnections)/sInterval
  366. );
  367. printf( "%20s\t %10ld\t %10ld\t %10ld\t%6ld\n",
  368. "Connection Attempts",
  369. pStatStart->ConnectionAttempts,
  370. pStatEnd->ConnectionAttempts,
  371. pStatEnd->ConnectionAttempts - pStatStart->ConnectionAttempts,
  372. (pStatEnd->ConnectionAttempts - pStatStart->ConnectionAttempts)/
  373. sInterval
  374. );
  375. printf( "%20s\t %10ld\t %10ld\t %10ld\t%6ld\n",
  376. "Logon Attempts",
  377. pStatStart->LogonAttempts,
  378. pStatEnd->LogonAttempts,
  379. pStatEnd->LogonAttempts - pStatStart->LogonAttempts,
  380. (pStatEnd->LogonAttempts - pStatStart->LogonAttempts)/sInterval
  381. );
  382. printf( "%20s = %s\n", "Time of Last Clear",
  383. asctime( localtime( (time_t *)&pStatStart->TimeOfLastClear ) ) );
  384. return;
  385. } // PrintStatsForTime()
  386. static
  387. VOID
  388. PrintCommonStatisticsInfo( IN INET_INFO_STATISTICS_0 * pStat)
  389. {
  390. DWORD i;
  391. if ( pStat == NULL) {
  392. return ;
  393. }
  394. printf( " Printing Common Statistics Information: \n");
  395. printf( "%20s = %d\n", "Cache Bytes Total",
  396. (pStat->CacheCtrs.CacheBytesTotal));
  397. printf( "%20s = %d\n", "Cache Bytes In Use",
  398. (pStat->CacheCtrs.CacheBytesInUse));
  399. printf( "%20s = %ld\n", "CurrentOpenFileHandles ",
  400. pStat->CacheCtrs.CurrentOpenFileHandles);
  401. printf( "%20s = %ld\n", "CurrentDirLists ",
  402. pStat->CacheCtrs.CurrentDirLists);
  403. printf( "%20s = %ld\n", "CurrentObjects ",
  404. pStat->CacheCtrs.CurrentObjects);
  405. printf( "%20s = %ld\n", "CurrentObjects ",
  406. pStat->CacheCtrs.CurrentObjects);
  407. printf( "%20s = %ld\n", "Cache Flushes ",
  408. pStat->CacheCtrs.FlushesFromDirChanges);
  409. printf( "%20s = %ld\n", "CacheHits ",
  410. pStat->CacheCtrs.CacheHits);
  411. printf( "%20s = %ld\n", "CacheMisses ",
  412. pStat->CacheCtrs.CacheMisses);
  413. printf( "%20s = %ld\n", "Atq Allowed Requests ",
  414. pStat->AtqCtrs.TotalAllowedRequests);
  415. printf( "%20s = %ld\n", "Atq Blocked Requests ",
  416. pStat->AtqCtrs.TotalBlockedRequests);
  417. printf( "%20s = %ld\n", "Atq Rejected Requests ",
  418. pStat->AtqCtrs.TotalRejectedRequests);
  419. printf( "%20s = %ld\n", "Atq Current Blocked Requests ",
  420. pStat->AtqCtrs.CurrentBlockedRequests);
  421. printf( "%20s = %ld\n", "Atq Measured Bandwidth ",
  422. pStat->AtqCtrs.MeasuredBandwidth);
  423. #ifndef NO_AUX_PERF
  424. printf( " Auxiliary Counters # = %u\n",
  425. pStat->nAuxCounters);
  426. for ( i = 0; i < pStat->nAuxCounters; i++) {
  427. printf( "Aux Counter[%u] = %u\n", i, pStat->rgCounters[i]);
  428. } //for
  429. #endif // NO_AUX_PERF
  430. return;
  431. } // PrintStatisticsInfo()
  432. static
  433. VOID
  434. PrintCommonStatsForTime( IN INET_INFO_STATISTICS_0 * pStatStart,
  435. IN INET_INFO_STATISTICS_0 * pStatEnd,
  436. IN DWORD sInterval)
  437. /*++
  438. Print the statistics information over a time interval sInterval seconds.
  439. Arguments:
  440. pStatStart pointer to statistics information for starting sample
  441. pStatEnd pointer to statistics information for ending sample
  442. sInterval Time interval in seconds for the sample
  443. Returns:
  444. None
  445. --*/
  446. {
  447. DWORD dwDiff;
  448. if ( pStatStart == NULL || pStatEnd == NULL || sInterval == 0 ) {
  449. return ;
  450. }
  451. printf( "Statistics for Interval = %u seconds\n", sInterval);
  452. printf( "%20s\t %10s\t%10s\t%10s\t%6s\n\n",
  453. "Item ", "Start Sample", "End Sample", "Difference", "Rate/s");
  454. dwDiff = (pStatEnd->CacheCtrs.CacheBytesTotal -
  455. pStatStart->CacheCtrs.CacheBytesTotal);
  456. printf( "%20s\t %10.3g\t %10ld\t %10ld\t%6ld\n",
  457. "Cache Bytes Total",
  458. (pStatStart->CacheCtrs.CacheBytesTotal),
  459. (pStatEnd->CacheCtrs.CacheBytesTotal),
  460. dwDiff,
  461. dwDiff/sInterval
  462. );
  463. dwDiff = (pStatEnd->CacheCtrs.CacheBytesInUse -
  464. pStatStart->CacheCtrs.CacheBytesInUse);
  465. printf( "%20s\t %10.3g\t %10ld\t %10ld\t%6ld\n",
  466. "Cache Bytes In Use",
  467. (pStatStart->CacheCtrs.CacheBytesInUse),
  468. (pStatEnd->CacheCtrs.CacheBytesInUse),
  469. dwDiff,
  470. dwDiff/sInterval
  471. );
  472. dwDiff = (pStatEnd->CacheCtrs.CurrentOpenFileHandles -
  473. pStatStart->CacheCtrs.CurrentOpenFileHandles);
  474. printf( "%20s\t %10ld\t %10ld\t %10ld\t%6ld\n",
  475. "File Handle Cached ",
  476. (pStatStart->CacheCtrs.CurrentOpenFileHandles),
  477. (pStatEnd->CacheCtrs.CurrentOpenFileHandles),
  478. dwDiff,
  479. dwDiff/sInterval
  480. );
  481. dwDiff = (pStatEnd->CacheCtrs.CurrentDirLists -
  482. pStatStart->CacheCtrs.CurrentDirLists);
  483. printf( "%20s\t %10ld\t %10ld\t %10ld\t%6ld\n",
  484. "Current Dir Lists ",
  485. (pStatStart->CacheCtrs.CurrentDirLists),
  486. (pStatEnd->CacheCtrs.CurrentDirLists),
  487. dwDiff,
  488. dwDiff/sInterval
  489. );
  490. dwDiff = (pStatEnd->CacheCtrs.CurrentObjects -
  491. pStatStart->CacheCtrs.CurrentObjects);
  492. printf( "%20s\t %10ld\t %10ld\t %10ld\t%6ld\n",
  493. "Current Objects Cached",
  494. (pStatStart->CacheCtrs.CurrentObjects),
  495. (pStatEnd->CacheCtrs.CurrentObjects),
  496. dwDiff,
  497. dwDiff/sInterval
  498. );
  499. dwDiff = (pStatEnd->CacheCtrs.FlushesFromDirChanges -
  500. pStatStart->CacheCtrs.FlushesFromDirChanges);
  501. printf( "%20s\t %10ld\t %10ld\t %10ld\t%6ld\n",
  502. "Cache Flushes",
  503. (pStatStart->CacheCtrs.FlushesFromDirChanges),
  504. (pStatEnd->CacheCtrs.FlushesFromDirChanges),
  505. dwDiff,
  506. dwDiff/sInterval
  507. );
  508. dwDiff = (pStatEnd->CacheCtrs.CacheHits -
  509. pStatStart->CacheCtrs.CacheHits);
  510. printf( "%20s\t %10ld\t %10ld\t %10ld\t%6ld\n",
  511. "Cache Hits",
  512. (pStatStart->CacheCtrs.CacheHits),
  513. (pStatEnd->CacheCtrs.CacheHits),
  514. dwDiff,
  515. dwDiff/sInterval
  516. );
  517. dwDiff = (pStatEnd->CacheCtrs.CacheMisses -
  518. pStatStart->CacheCtrs.CacheMisses);
  519. printf( "%20s\t %10ld\t %10ld\t %10ld\t%6ld\n",
  520. "Cache Misses",
  521. (pStatStart->CacheCtrs.CacheMisses),
  522. (pStatEnd->CacheCtrs.CacheMisses),
  523. dwDiff,
  524. dwDiff/sInterval
  525. );
  526. dwDiff = (pStatEnd->AtqCtrs.TotalAllowedRequests -
  527. pStatStart->AtqCtrs.TotalAllowedRequests);
  528. printf( "%20s\t %10ld\t %10ld\t %10ld\t%6ld\n",
  529. "Total Atq Allowed Requests",
  530. (pStatStart->AtqCtrs.TotalAllowedRequests),
  531. (pStatEnd->AtqCtrs.TotalAllowedRequests),
  532. dwDiff,
  533. dwDiff/sInterval
  534. );
  535. dwDiff = (pStatEnd->AtqCtrs.TotalBlockedRequests -
  536. pStatStart->AtqCtrs.TotalBlockedRequests);
  537. printf( "%20s\t %10ld\t %10ld\t %10ld\t%6ld\n",
  538. "Total Atq Blocked Requests",
  539. (pStatStart->AtqCtrs.TotalBlockedRequests),
  540. (pStatEnd->AtqCtrs.TotalBlockedRequests),
  541. dwDiff,
  542. dwDiff/sInterval
  543. );
  544. dwDiff = (pStatEnd->AtqCtrs.TotalRejectedRequests -
  545. pStatStart->AtqCtrs.TotalRejectedRequests);
  546. printf( "%20s\t %10ld\t %10ld\t %10ld\t%6ld\n",
  547. "Total Atq Rejected Requests",
  548. (pStatStart->AtqCtrs.TotalRejectedRequests),
  549. (pStatEnd->AtqCtrs.TotalRejectedRequests),
  550. dwDiff,
  551. dwDiff/sInterval
  552. );
  553. dwDiff = (pStatEnd->AtqCtrs.CurrentBlockedRequests -
  554. pStatStart->AtqCtrs.CurrentBlockedRequests);
  555. printf( "%20s\t %10ld\t %10ld\t %10ld\t%6ld\n",
  556. "Current Atq Blocked Requests",
  557. (pStatStart->AtqCtrs.CurrentBlockedRequests),
  558. (pStatEnd->AtqCtrs.CurrentBlockedRequests),
  559. dwDiff,
  560. dwDiff/sInterval
  561. );
  562. dwDiff = (pStatEnd->AtqCtrs.MeasuredBandwidth -
  563. pStatStart->AtqCtrs.MeasuredBandwidth);
  564. printf( "%20s\t %10ld\t %10ld\t %10ld\t%6ld\n",
  565. "Measured Bandwidth",
  566. (pStatStart->AtqCtrs.MeasuredBandwidth),
  567. (pStatEnd->AtqCtrs.MeasuredBandwidth),
  568. dwDiff,
  569. dwDiff/sInterval
  570. );
  571. return;
  572. } // PrintStatisticsInfo()
  573. BOOL
  574. TestGetStatistics( int argc, char * argv[] )
  575. /*++
  576. Gets Statistics from server and prints it.
  577. If the optional time information is given, then this function
  578. obtains the statistics, sleeps for specified time interval and then
  579. again obtains new statistics and prints the difference, neatly formatted.
  580. Arguments:
  581. argc = count of arguments
  582. argv array of strings for command
  583. argv[0] = stats or getstatistics
  584. argv[1] = time interval if specified in seconds
  585. --*/
  586. {
  587. DWORD err;
  588. DWORD timeToSleep = 0;
  589. FTP_STATISTICS_0 * pStat1 = NULL; // this should be freed ? NYI
  590. if ( argc > 1 && argv[1] != NULL) {
  591. timeToSleep = atoi( argv[1]);
  592. }
  593. err = I_FtpQueryStatistics(g_lpszServerAddress,
  594. 0,
  595. (LPBYTE *) &pStat1);
  596. if ( err == NO_ERROR) {
  597. if ( timeToSleep <= 0) {
  598. PrintStatisticsInfo( pStat1);
  599. } else {
  600. FTP_STATISTICS_0 * pStat2 = NULL;
  601. printf( "Statistics For Time Interval %u seconds\n\n",
  602. timeToSleep);
  603. Sleep( timeToSleep * 1000); // sleep for the interval
  604. err = I_FtpQueryStatistics(g_lpszServerAddress,
  605. 0,
  606. (LPBYTE *) &pStat2);
  607. if ( err == NO_ERROR) {
  608. PrintStatsForTime( pStat1, pStat2, timeToSleep);
  609. }
  610. if ( pStat2 != NULL) {
  611. MIDL_user_free( pStat2);
  612. }
  613. }
  614. }
  615. if ( pStat1 != NULL) {
  616. MIDL_user_free( pStat1);
  617. }
  618. SetLastError( err);
  619. return ( err == NO_ERROR);
  620. } // TestGetStatistics()
  621. BOOL
  622. TestClearStatistics( int argc, char * argv[])
  623. {
  624. DWORD err;
  625. err = I_FtpClearStatistics( g_lpszServerAddress);
  626. printf( "Cleared the statistics Err = %d\n", err);
  627. SetLastError( err);
  628. return ( err == NO_ERROR);
  629. } // TestClearStatistics()
  630. BOOL
  631. TestGetCommonStatistics( int argc, char * argv[] )
  632. /*++
  633. Gets common Statistics from server and prints it.
  634. If the optional time information is given, then this function
  635. obtains the statistics, sleeps for specified time interval and then
  636. again obtains new statistics and prints the difference, neatly formatted.
  637. Arguments:
  638. argc = count of arguments
  639. argv array of strings for command
  640. argv[0] = stats or getstatistics
  641. argv[1] = time interval if specified in seconds
  642. --*/
  643. {
  644. DWORD err;
  645. DWORD timeToSleep = 0;
  646. INET_INFO_STATISTICS_0 * pStat1 = NULL;
  647. if ( argc > 1 && argv[1] != NULL) {
  648. timeToSleep = atoi( argv[1]);
  649. }
  650. err = InetInfoQueryStatistics(g_lpszServerAddress,
  651. 0,
  652. 0,
  653. (LPBYTE *) &pStat1);
  654. if ( err == NO_ERROR) {
  655. if ( timeToSleep <= 0) {
  656. PrintCommonStatisticsInfo( pStat1);
  657. } else {
  658. INET_INFO_STATISTICS_0 * pStat2 = NULL;
  659. printf( "Statistics For Time Interval %u seconds\n\n",
  660. timeToSleep);
  661. Sleep( timeToSleep * 1000); // sleep for the interval
  662. err = InetInfoQueryStatistics(g_lpszServerAddress,
  663. 0,
  664. 0,
  665. (LPBYTE *) &pStat2);
  666. if ( err == NO_ERROR) {
  667. PrintCommonStatsForTime( pStat1, pStat2, timeToSleep);
  668. }
  669. if ( pStat2 != NULL) {
  670. MIDL_user_free( pStat2);
  671. }
  672. }
  673. }
  674. if ( pStat1 != NULL) {
  675. MIDL_user_free( pStat1);
  676. }
  677. SetLastError( err);
  678. return ( err == NO_ERROR);
  679. } // TestGetCommonStatistics()
  680. static VOID
  681. PrintAdminInformation( IN FTP_CONFIG_INFO * pConfigInfo)
  682. {
  683. if ( pConfigInfo == NULL)
  684. return;
  685. printf( "\n Printing Config Information in %08x\n", pConfigInfo);
  686. printf( "%20s= %08x\n", "Field Control", pConfigInfo->FieldControl);
  687. printf( "%20s= %u\n", "AllowAnonymous", pConfigInfo->fAllowAnonymous);
  688. printf( "%20s= %u\n", "AllowGuestAccess",pConfigInfo->fAllowGuestAccess);
  689. printf( "%20s= %u\n", "AnnotateDirectories",
  690. pConfigInfo->fAnnotateDirectories);
  691. printf( "%20s= %u\n", "Anonymous Only", pConfigInfo->fAnonymousOnly);
  692. printf( "%20s= %u\n", "Listen Backlog", pConfigInfo->dwListenBacklog);
  693. printf( "%20s= %u\n", "Lowercase files", pConfigInfo->fLowercaseFiles);
  694. printf( "%20s= %u\n", "MsDos Dir Output", pConfigInfo->fMsdosDirOutput);
  695. printf( "%20s= %S\n", "Home Directory", pConfigInfo->lpszHomeDirectory);
  696. printf( "%20s= %S\n", "Greetings Message",
  697. pConfigInfo->lpszGreetingMessage);
  698. printf( "%20s= %S\n", "Exit Message", pConfigInfo->lpszExitMessage);
  699. printf( "%20s= %S\n", "Max Clients Message",
  700. pConfigInfo->lpszMaxClientsMessage);
  701. return;
  702. } // PrintAdminInformation()
  703. static BOOL
  704. TestGetAdminInfo( int argc, char * argv[] )
  705. {
  706. DWORD err;
  707. FTP_CONFIG_INFO * pConfig = NULL;
  708. err = FtpGetAdminInformation( g_lpszServerAddress, &pConfig);
  709. printf( "FtpGetAdminInformation returned Error Code = %d\n", err);
  710. if ( err == NO_ERROR) {
  711. PrintAdminInformation( pConfig);
  712. MIDL_user_free( ( LPVOID) pConfig);
  713. }
  714. SetLastError( err);
  715. return ( err == NO_ERROR);
  716. } // TestGetAdminInfo()
  717. DWORD
  718. SetAdminField(
  719. IN FTP_CONFIG_INFO * pConfigIn,
  720. IN char * pszSubCmd,
  721. IN char * pszValue)
  722. {
  723. DWORD err = NO_ERROR;
  724. CmdStruct * pCmd = DecodeCommand( pszSubCmd); // get command struct
  725. if ( pCmd == NULL) {
  726. // ignore invalid commands
  727. printf( " Invalid SubCommand for set admin info %s. Ignoring...\n",
  728. pszSubCmd);
  729. return ( ERROR_INVALID_PARAMETER);
  730. }
  731. switch ( pCmd->cmdCode) {
  732. case CmdMaxClientsMessage:
  733. SetField( pConfigIn->FieldControl, FC_FTP_MAX_CLIENTS_MESSAGE);
  734. pConfigIn->lpszMaxClientsMessage = ConvertToUnicode( pszValue);
  735. if ( pConfigIn->lpszMaxClientsMessage == NULL) {
  736. err = GetLastError();
  737. }
  738. break;
  739. case CmdExitMessage:
  740. SetField( pConfigIn->FieldControl, FC_FTP_EXIT_MESSAGE);
  741. pConfigIn->lpszExitMessage = ConvertToUnicode( pszValue);
  742. if ( pConfigIn->lpszExitMessage == NULL) {
  743. err = GetLastError();
  744. }
  745. break;
  746. case CmdGreetingMessage:
  747. SetField( pConfigIn->FieldControl, FC_FTP_GREETING_MESSAGE);
  748. pConfigIn->lpszGreetingMessage = ConvertToUnicode( pszValue);
  749. if ( pConfigIn->lpszGreetingMessage == NULL) {
  750. err = GetLastError();
  751. }
  752. break;
  753. case CmdAllowAnonymous:
  754. SetField( pConfigIn->FieldControl, FC_FTP_ALLOW_ANONYMOUS);
  755. pConfigIn->fAllowAnonymous = (atoi(pszValue) == 1);
  756. break;
  757. case CmdAllowGuest:
  758. SetField( pConfigIn->FieldControl, FC_FTP_ALLOW_GUEST_ACCESS);
  759. pConfigIn->fAllowGuestAccess = (atoi(pszValue) == 1);
  760. break;
  761. case CmdAllowAnonOnly:
  762. SetField( pConfigIn->FieldControl, FC_FTP_ANONYMOUS_ONLY);
  763. pConfigIn->fAnonymousOnly = (atoi(pszValue) == 1);
  764. break;
  765. case CmdAnnotateDirs:
  766. SetField( pConfigIn->FieldControl, FC_FTP_ANNOTATE_DIRECTORIES);
  767. pConfigIn->fAnnotateDirectories = (atoi(pszValue) == 1);
  768. break;
  769. case CmdListenBacklog:
  770. SetField( pConfigIn->FieldControl, FC_FTP_LISTEN_BACKLOG);
  771. pConfigIn->dwListenBacklog = atoi(pszValue);
  772. break;
  773. case CmdMsdosDir:
  774. SetField( pConfigIn->FieldControl, FC_FTP_MSDOS_DIR_OUTPUT);
  775. pConfigIn->fMsdosDirOutput = (atoi(pszValue) == 1);
  776. break;
  777. default:
  778. printf( " Invalid Sub command %s for SetConfigInfo(). Ignoring.\n",
  779. pszSubCmd);
  780. err = ERROR_INVALID_PARAMETER;
  781. break;
  782. } // switch
  783. return ( err);
  784. } // SetAdminField()
  785. BOOL
  786. TestSetAdminInfo( int argc, char * argv[])
  787. /*++
  788. Arguments:
  789. argc = count of arguments
  790. argv array of strings for command
  791. argv[0] = setadmininfo
  792. argv[1] = sub function within set info for testing
  793. argv[2] = value for sub function
  794. for all information to be set, give <sub command name> <value>
  795. --*/
  796. {
  797. DWORD err = ERROR_CALL_NOT_IMPLEMENTED;
  798. FTP_CONFIG_INFO * pConfigOut = NULL; // config value obtained from server
  799. if ( argc < 1 || ( (argc & 0x1) != 0x1 ) ) { // argc should be > 1 and odd
  800. printf( "Invalid Number of arguments for %s\n", argv[0]);
  801. SetLastError( ERROR_INVALID_PARAMETER);
  802. return ( FALSE);
  803. }
  804. // Get the config from server to start with
  805. err = FtpGetAdminInformation( g_lpszServerAddress, &pConfigOut);
  806. if ( err != NO_ERROR) {
  807. printf( " GetAdminInformation() failed with error = %u\n",
  808. err);
  809. SetLastError( err);
  810. return (FALSE);
  811. }
  812. // extract each field and value to set in configIn
  813. for( ; --argc > 1; argc -= 2) {
  814. if ( (err = SetAdminField( pConfigOut, argv[argc - 1], argv[argc]) )
  815. != NO_ERROR) {
  816. break;
  817. }
  818. } // for() to extract and set all fields
  819. if ( err == NO_ERROR) {
  820. // Now make RPC call to set the fields
  821. err = FtpSetAdminInformation( g_lpszServerAddress,
  822. pConfigOut);
  823. }
  824. MIDL_user_free( pConfigOut);
  825. SetLastError( err );
  826. return ( err == NO_ERROR );
  827. } // TestSetAdminInfo()
  828. static VOID
  829. PrintInetAdminInformation( IN LPINETA_CONFIG_INFO pConfigInfo)
  830. {
  831. if ( pConfigInfo == NULL)
  832. return;
  833. printf( "\n Printing InetA Config Information in %08x\n", pConfigInfo);
  834. printf( "%20s= %d\n", "LogAnonymous", pConfigInfo->fLogAnonymous);
  835. printf( "%20s= %d\n", "LogNonAnonymous",pConfigInfo->fLogNonAnonymous);
  836. printf( "%20s= %08x\n", "Authentication Flags",
  837. pConfigInfo->dwAuthentication);
  838. printf( "%20s= %d\n", "Port", pConfigInfo->sPort);
  839. printf( "%20s= %d\n", "Connection Timeout",
  840. pConfigInfo->dwConnectionTimeout);
  841. printf( "%20s= %d\n", "Max Connections",
  842. pConfigInfo->dwMaxConnections);
  843. printf( "%20s= %S\n", "AnonUserName",
  844. pConfigInfo->lpszAnonUserName);
  845. printf( "%20s= %S\n", "AnonPassword",
  846. pConfigInfo->szAnonPassword);
  847. printf( "%20s= %S\n", "Admin Name",
  848. pConfigInfo->lpszAdminName);
  849. printf( "%20s= %S\n", "Admin Email",
  850. pConfigInfo->lpszAdminEmail);
  851. printf( "%20s= %S\n", "Server Comments",
  852. pConfigInfo->lpszServerComment);
  853. //
  854. // IP lists and Grant lists, Virtual Roots are not included now. Later.
  855. //
  856. return;
  857. } // PrintInetAdminInformation()
  858. static DWORD
  859. GetServiceIdFromString( IN LPCSTR pszService)
  860. {
  861. if ( pszService != NULL) {
  862. if ( !_stricmp(pszService, "HTTP")) {
  863. return ( INET_HTTP_SVC_ID);
  864. } else if (!_stricmp( pszService, "GOPHER")) {
  865. return (INET_GOPHER_SVC_ID);
  866. } else if ( !_stricmp( pszService, "FTP")) {
  867. return (INET_FTP_SVC_ID);
  868. } else if ( !_stricmp( pszService, "DNS")) {
  869. return (INET_DNS_SVC_ID);
  870. }
  871. }
  872. return ( INET_HTTP_SVC_ID);
  873. } // GetServiceIdFromString()
  874. static BOOL
  875. TestInetGetAdminInfo( int argc, char * argv[] )
  876. /*++
  877. Gets the configuration information using InetInfoGetAdminInformation()
  878. argv[0] = igetadmininfo
  879. argv[1] = service name ( gopher, http, ftp, catapult)
  880. --*/
  881. {
  882. DWORD err;
  883. LPINETA_CONFIG_INFO pConfig = NULL;
  884. DWORD dwServiceId;
  885. printf( " InetInfoGetAdminInformation() called at: Time = %d\n",
  886. GetTickCount());
  887. dwServiceId = (argc > 1) ? GetServiceIdFromString( argv[1]) : INET_HTTP_SVC_ID;
  888. err = InetInfoGetAdminInformation( g_lpszServerAddress,
  889. dwServiceId,
  890. &pConfig);
  891. printf( "Finished at Time = %d\n", GetTickCount());
  892. printf( "InetInfoGetAdminInformation returned Error Code = %d\n", err);
  893. if ( err == NO_ERROR) {
  894. PrintInetAdminInformation( pConfig);
  895. MIDL_user_free( ( LPVOID) pConfig);
  896. }
  897. SetLastError( err);
  898. return ( err == NO_ERROR);
  899. } // TestInetGetAdminInfo()
  900. DWORD
  901. SetInetAdminField(
  902. IN LPINETA_CONFIG_INFO pConfigIn,
  903. IN char * pszSubCmd,
  904. IN char * pszValue)
  905. {
  906. DWORD err = NO_ERROR;
  907. CmdStruct * pCmd = DecodeCommand( pszSubCmd); // get command struct
  908. if ( pCmd == NULL) {
  909. // ignore invalid commands
  910. printf( " Invalid SubCommand for set admin info %s. Ignoring...\n",
  911. pszSubCmd);
  912. return ( ERROR_INVALID_PARAMETER);
  913. }
  914. switch ( pCmd->cmdCode) {
  915. case CmdPortNumber:
  916. SetField( pConfigIn->FieldControl, FC_INET_INFO_PORT_NUMBER);
  917. pConfigIn->sPort = atoi( pszValue);
  918. break;
  919. case CmdConnectionTimeout:
  920. SetField( pConfigIn->FieldControl, FC_INET_INFO_CONNECTION_TIMEOUT);
  921. pConfigIn->dwConnectionTimeout = atoi( pszValue);
  922. break;
  923. case CmdMaxConnections:
  924. SetField( pConfigIn->FieldControl, FC_INET_INFO_MAX_CONNECTIONS);
  925. pConfigIn->dwMaxConnections = atoi( pszValue);
  926. break;
  927. case CmdLogAnonymous:
  928. SetField( pConfigIn->FieldControl, FC_INET_INFO_LOG_ANONYMOUS);
  929. pConfigIn->fLogAnonymous = atoi( pszValue);
  930. break;
  931. case CmdLogNonAnonymous:
  932. SetField( pConfigIn->FieldControl, FC_INET_INFO_LOG_NONANONYMOUS);
  933. pConfigIn->fLogNonAnonymous = atoi( pszValue);
  934. break;
  935. case CmdAnonUserName:
  936. SetField( pConfigIn->FieldControl, FC_INET_INFO_ANON_USER_NAME);
  937. pConfigIn->lpszAnonUserName = ConvertToUnicode( pszValue);
  938. if ( pConfigIn->lpszAnonUserName == NULL) {
  939. err = GetLastError();
  940. }
  941. break;
  942. case CmdAdminName:
  943. SetField( pConfigIn->FieldControl, FC_INET_INFO_ADMIN_NAME);
  944. pConfigIn->lpszAdminName =
  945. ConvertToUnicode( pszValue);
  946. if ( pConfigIn->lpszAdminName == NULL) {
  947. err = GetLastError();
  948. }
  949. break;
  950. case CmdAdminEmail:
  951. SetField( pConfigIn->FieldControl, FC_INET_INFO_ADMIN_EMAIL);
  952. pConfigIn->lpszAdminEmail =
  953. ConvertToUnicode( pszValue);
  954. if ( pConfigIn->lpszAdminEmail == NULL) {
  955. err = GetLastError();
  956. }
  957. break;
  958. case CmdServerComment:
  959. SetField( pConfigIn->FieldControl, FC_INET_INFO_SERVER_COMMENT);
  960. pConfigIn->lpszServerComment =
  961. ConvertToUnicode( pszValue);
  962. if ( pConfigIn->lpszServerComment == NULL) {
  963. err = GetLastError();
  964. }
  965. break;
  966. default:
  967. printf( " Invalid Sub command %s for SetConfigInfo(). Ignoring.\n",
  968. pszSubCmd);
  969. err = ERROR_INVALID_PARAMETER;
  970. break;
  971. } // switch
  972. return ( err);
  973. } // SetAdminField()
  974. static VOID
  975. FreeBuffer( IN PVOID * ppBuffer)
  976. {
  977. if ( *ppBuffer != NULL) {
  978. free( * ppBuffer);
  979. *ppBuffer = NULL; // reset the old value
  980. }
  981. return;
  982. } // FreeBuffer()
  983. VOID
  984. FreeStringsInInetConfigInfo( IN OUT LPINETA_CONFIG_INFO pConfigInfo)
  985. {
  986. FreeBuffer( (PVOID *) & pConfigInfo->lpszAnonUserName);
  987. } // FreeStringsInInetConfigInfo()
  988. BOOL
  989. TestInetSetAdminInfo( int argc, char * argv[])
  990. /*++
  991. Arguments:
  992. argc = count of arguments
  993. argv array of strings for command
  994. argv[0] = isetadmininfo
  995. argv[1] = sub function within set info for testing
  996. argv[2] = value for sub function
  997. for all information to be set, give <sub command name> <value>
  998. --*/
  999. {
  1000. DWORD err = ERROR_CALL_NOT_IMPLEMENTED;
  1001. LPINETA_CONFIG_INFO * ppConfigOut = NULL;
  1002. INETA_CONFIG_INFO configIn; // config values that are set
  1003. if ( argc < 1 || ( (argc & 0x1) != 0x1 ) ) { // argc should be > 1 and odd
  1004. printf( "Invalid Number of arguments for %s\n", argv[0]);
  1005. SetLastError( ERROR_INVALID_PARAMETER);
  1006. return ( FALSE);
  1007. }
  1008. //
  1009. // form the admin info block to set the information
  1010. //
  1011. memset( ( LPVOID) &configIn, 0, sizeof( configIn)); // init to Zeros
  1012. // extract each field and value to set in configIn
  1013. for( ; --argc > 1; argc -= 2) {
  1014. if ( SetInetAdminField( &configIn, argv[argc - 1], argv[argc])
  1015. != NO_ERROR) {
  1016. break;
  1017. }
  1018. } // for() to extract and set all fields
  1019. if ( err != NO_ERROR) {
  1020. // Now make RPC call to set the fields
  1021. err = InetInfoSetAdminInformation( g_lpszServerAddress,
  1022. INET_HTTP_SVC_ID,
  1023. &configIn);
  1024. }
  1025. // Need to free all the buffers allocated for the strings
  1026. FreeStringsInInetConfigInfo( &configIn);
  1027. SetLastError( err );
  1028. return ( err == NO_ERROR );
  1029. } // TestSetInetAdminInfo()
  1030. BOOL
  1031. TestEnumUserInfo( int argc, char * argv[])
  1032. {
  1033. DWORD err;
  1034. FTP_USER_INFO * pUserInfo;
  1035. DWORD cEntries;
  1036. printf( "Invoking FtpEnumerateUsers..." );
  1037. err = I_FtpEnumerateUsers(g_lpszServerAddress,
  1038. &cEntries,
  1039. &pUserInfo );
  1040. if( err == NO_ERROR )
  1041. {
  1042. printf( " %lu connected users\n", cEntries );
  1043. while( cEntries-- )
  1044. {
  1045. IN_ADDR addr;
  1046. DWORD tConn;
  1047. addr.s_addr = (u_long)pUserInfo->inetHost;
  1048. printf( "idUser = %lu\n"
  1049. "pszUser = %S\n"
  1050. "fAnonymous = %lu\n"
  1051. "inetHost = %s\n",
  1052. pUserInfo->idUser,
  1053. pUserInfo->pszUser,
  1054. pUserInfo->fAnonymous,
  1055. inet_ntoa( addr ));
  1056. tConn = pUserInfo->tConnect;
  1057. printf( " tConnect = %lu:%lu:%lu (%lu seconds)\n",
  1058. tConn/3600,
  1059. (tConn%3600)/60,
  1060. tConn % 60,
  1061. tConn);
  1062. pUserInfo++;
  1063. }
  1064. }
  1065. SetLastError( err);
  1066. return ( err == NO_ERROR);
  1067. } // TestEnumUserInfo()
  1068. BOOL
  1069. TestDisconnectUser( int argc, char * argv[])
  1070. {
  1071. DWORD idUser;
  1072. DWORD err;
  1073. LPCSTR pszUserId = argv[1];
  1074. idUser = (DWORD ) strtoul( pszUserId, NULL, 0);
  1075. err = I_FtpDisconnectUser( g_lpszServerAddress, idUser);
  1076. SetLastError(err);
  1077. return (err == NO_ERROR);
  1078. } // TestDisconnectUser()
  1079. int __cdecl
  1080. main( int argc, char * argv[])
  1081. {
  1082. DWORD err = NO_ERROR;
  1083. char ** ppszArgv; // arguments for command functions
  1084. int cArgs; // arg count for command functions
  1085. char * pszCmdName;
  1086. CmdStruct * pCmd;
  1087. CMDFUNC pCmdFunc = NULL;
  1088. if ( argc < 3 || argv[1] == NULL ) {
  1089. // Insufficient arguments
  1090. GenUsageMessage( argc, argv);
  1091. return ( 1);
  1092. }
  1093. pszCmdName = argv[2];
  1094. if (( pCmd = DecodeCommand( pszCmdName)) == NULL || pCmd->cmdFunc == NULL) {
  1095. printf( "Internal Error: Invalid Command %s\n", pszCmdName);
  1096. GenUsageMessage( argc, argv);
  1097. return ( 1);
  1098. }
  1099. g_lpszServerAddress = ConvertToUnicode( argv[1]); // get server address
  1100. cArgs = argc - 2;
  1101. ppszArgv = argv + 2; // position at the start of the command name
  1102. if ( !(*pCmd->cmdFunc)( cArgs, ppszArgv)) { // call the test function
  1103. // Test function failed.
  1104. printf( "Command %s failed. Error = %d\n", pszCmdName, GetLastError());
  1105. return ( 1);
  1106. }
  1107. printf( " Command %s succeeded\n", pszCmdName);
  1108. return ( 0); // success
  1109. } // main()
  1110. /************************ End of File ***********************/