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.

527 lines
12 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 "iisinfo.h"
  22. # include "apiutil.h"
  23. WCHAR Server[255];
  24. DWORD Level = 1;
  25. //
  26. // From tsunami.hxx
  27. //
  28. void
  29. get( DWORD instance)
  30. {
  31. DWORD err;
  32. LPINET_INFO_CONFIG_INFO buffer = NULL;
  33. err = InetInfoGetAdminInformation( Server,
  34. INET_HTTP_SVC_ID,
  35. &buffer );
  36. printf("err %d buffer %x\n",err,buffer);
  37. if ( err == NO_ERROR ) {
  38. DWORD i;
  39. printf( "dwConnectionTime = %8d\n", buffer->dwConnectionTimeout );
  40. printf( "dwAuthentication = 0x%08x\n", buffer->dwAuthentication );
  41. printf( "Port = %8d\n", (DWORD) buffer->sPort);
  42. printf("vroot 0x%08x\n",buffer->VirtualRoots);
  43. printf("vr entries is %d\n",buffer->VirtualRoots->cEntries);
  44. for (i=0 ; i < buffer->VirtualRoots->cEntries ;i++ ) {
  45. printf("\nroot %S\n",
  46. buffer->VirtualRoots->aVirtRootEntry[i].pszRoot);
  47. printf("directory %S\n",
  48. buffer->VirtualRoots->aVirtRootEntry[i].pszDirectory);
  49. printf("account %S\n",
  50. buffer->VirtualRoots->aVirtRootEntry[i].pszAccountName);
  51. printf("mask %x\n",
  52. buffer->VirtualRoots->aVirtRootEntry[i].dwMask);
  53. printf("error %x\n",
  54. buffer->VirtualRoots->aVirtRootEntry[i].dwError);
  55. }
  56. midl_user_free( buffer );
  57. }
  58. }
  59. void
  60. getftp( DWORD instance)
  61. {
  62. DWORD err;
  63. DWORD numEntries;
  64. LPIIS_USER_INFO_1 info;
  65. LPIIS_USER_INFO_1 scan;
  66. IN_ADDR addr;
  67. err = IISEnumerateUsers(
  68. Server,
  69. 1,
  70. INET_FTP_SVC_ID,
  71. instance,
  72. &numEntries,
  73. (LPBYTE *)&info
  74. );
  75. printf( "err %lu, buffer %x\n", err, info );
  76. if( err == NO_ERROR ) {
  77. printf( "%lu connected users\n", numEntries );
  78. for( scan = info ; numEntries > 0 ; numEntries--, scan++ ) {
  79. addr.s_addr = (u_long)scan->inetHost;
  80. printf(
  81. "idUser = %lu\n"
  82. "pszUser = %S\n"
  83. "fAnonymous = %lu\n"
  84. "inetHost = %s\n"
  85. "tConnect = %lu\n"
  86. "\n",
  87. scan->idUser,
  88. scan->pszUser,
  89. scan->fAnonymous,
  90. inet_ntoa( addr ),
  91. scan->tConnect
  92. );
  93. }
  94. midl_user_free( info );
  95. }
  96. }
  97. void
  98. getweb( DWORD instance)
  99. {
  100. printf( "Not supported\n" );
  101. #if 0
  102. DWORD err;
  103. if (instance == 0 ) {
  104. instance = INET_INSTANCE_ROOT;
  105. }
  106. if ( Level == 1 )
  107. {
  108. W3_CONFIG_INFO_1 * buffer = NULL;
  109. err = W3GetAdminInformation2(
  110. Server,
  111. Level,
  112. instance,
  113. (LPBYTE*)&buffer
  114. );
  115. printf("err %d buffer 0x%08x\n",err,buffer);
  116. if ( err == NO_ERROR ) {
  117. printf( "csecCGIScriptTimeout = %8d\n", buffer->csecCGIScriptTimeout );
  118. printf( "csecPoolODBCConnections = %8d\n", buffer->csecPoolODBCConnections );
  119. printf( "fCacheISAPIApps = %s\n", buffer->fCacheISAPIApps ? "TRUE" : "FALSE" );
  120. printf( "fUseKeepAlives = %s\n", buffer->fUseKeepAlives ? "TRUE" : "FALSE" );
  121. }
  122. }
  123. #endif
  124. }
  125. void
  126. set( DWORD instance )
  127. {
  128. DWORD err;
  129. LPINET_INFO_CONFIG_INFO buffer = NULL;
  130. err = InetInfoGetAdminInformation( Server,
  131. INET_HTTP_SVC_ID,
  132. &buffer );
  133. printf("err %d buffer %x\n",err,buffer);
  134. if ( err == NO_ERROR ) {
  135. printf("Port is %d\n",buffer->sPort);
  136. printf("vroot %x\n",buffer->VirtualRoots);
  137. printf("vr entries is %d\n",buffer->VirtualRoots->cEntries);
  138. } else {
  139. return;
  140. }
  141. err = InetInfoSetAdminInformation( Server,
  142. INET_HTTP_SVC_ID,
  143. buffer );
  144. printf("err %d \n",err);
  145. if ( err == NO_ERROR ) {
  146. get(instance);
  147. }
  148. midl_user_free( buffer );
  149. }
  150. void
  151. setvr( DWORD instance )
  152. {
  153. #if 1
  154. printf( "Not supported\n" );
  155. #else
  156. DWORD err;
  157. IIS_INSTANCE_INFO_1 newt;
  158. ZeroMemory(&newt,sizeof(IIS_INSTANCE_INFO_1));
  159. LPIIS_INSTANCE_INFO_1 buffer = NULL;
  160. err = IISGetAdminInformation(
  161. Server,
  162. Level,
  163. INET_HTTP_SVC_ID,
  164. instance,
  165. (LPBYTE*)&buffer
  166. );
  167. printf("err %d buffer %x\n",err,buffer);
  168. if ( err == NO_ERROR ) {
  169. printf("Port is %d\n",buffer->sPort);
  170. printf("vroot %x\n",buffer->VirtualRoots);
  171. printf("vr entries is %d\n",buffer->VirtualRoots->cEntries);
  172. } else {
  173. return;
  174. }
  175. newt.FieldControl = FC_INET_INFO_VIRTUAL_ROOTS;
  176. newt.VirtualRoots = buffer->VirtualRoots;
  177. buffer->VirtualRoots->aVirtRootEntry[1].pszDirectory = L"d:\\nt40";
  178. err = IISSetAdminInformation(
  179. Server,
  180. Level,
  181. INET_HTTP_SVC_ID,
  182. instance,
  183. (LPBYTE)&newt
  184. );
  185. printf("err %d \n",err);
  186. if ( err == NO_ERROR ) {
  187. get(instance);
  188. }
  189. midl_user_free( buffer );
  190. #endif
  191. }
  192. void
  193. enumer()
  194. {
  195. #if 1
  196. printf( "Not Supported\n" );
  197. #else
  198. DWORD err;
  199. DWORD nRead = 0;
  200. DWORD i;
  201. LPIIS_INSTANCE_INFO_2 buffer = NULL;
  202. LPIIS_INSTANCE_INFO_2 p;
  203. //
  204. // set the port
  205. //
  206. err = IISEnumerateInstances(
  207. Server,
  208. Level,
  209. INET_HTTP_SVC_ID,
  210. &nRead,
  211. (LPBYTE*)&buffer
  212. );
  213. printf("err %d read %d buffer %x \n",err,nRead, buffer);
  214. if ( err == NO_ERROR ) {
  215. for (i=0,p=buffer; i < nRead;i++,p++ ) {
  216. printf("instance %d state %d comment %S\n",
  217. p->dwInstance, p->dwServerState, p->lpszServerComment);
  218. }
  219. }
  220. #endif
  221. }
  222. void
  223. add( PDWORD instance )
  224. {
  225. #if 1
  226. printf( "not supported\n" );
  227. #else
  228. DWORD err;
  229. DWORD nRead = 0;
  230. LPIIS_INSTANCE_INFO_1 buffer = NULL;
  231. LPW3_CONFIG_INFO_1 w3Buffer = NULL;
  232. err = IISGetAdminInformation(
  233. Server,
  234. Level,
  235. INET_HTTP_SVC_ID,
  236. INET_INSTANCE_ROOT,
  237. (LPBYTE*)&buffer
  238. );
  239. printf("IISGetAdminInfo err %d buffer %x\n",err,buffer);
  240. if ( err != NO_ERROR ) {
  241. return;
  242. }
  243. printf("password %ws\n",buffer->szAnonPassword);
  244. printf("instance %x\n",buffer->dwInstance);
  245. printf("port %x\n",buffer->sPort);
  246. printf("vroot %x\n",buffer->VirtualRoots);
  247. if ( buffer->VirtualRoots != NULL ) {
  248. printf("vr entries is %d\n",buffer->VirtualRoots->cEntries);
  249. }
  250. err = W3GetAdminInformation2(
  251. Server,
  252. Level,
  253. INET_INSTANCE_ROOT,
  254. (LPBYTE*)&w3Buffer
  255. );
  256. printf("W3GetAdminInfo err %d w3Buffer %x\n",err,w3Buffer);
  257. if ( err != NO_ERROR ) {
  258. midl_user_free( buffer );
  259. return;
  260. }
  261. //
  262. // set the port
  263. //
  264. buffer->sPort = 8081;
  265. err = IISAddInstance(
  266. Server,
  267. INET_HTTP_SVC_ID,
  268. 1,
  269. (LPBYTE)buffer,
  270. 1,
  271. (LPBYTE)w3Buffer,
  272. instance
  273. );
  274. printf("IISAddInstance err %d InstanceId %d\n",err,*instance);
  275. #endif
  276. } // Add instance
  277. void
  278. del( DWORD instance )
  279. {
  280. #if 1
  281. printf( "not supported\n" );
  282. #else
  283. DWORD err;
  284. err = IISDeleteInstance(
  285. Server,
  286. INET_HTTP_SVC_ID,
  287. instance
  288. );
  289. printf("err %d\n",err);
  290. #endif
  291. }
  292. void
  293. ctrl( DWORD instance, DWORD Code )
  294. {
  295. #if 1
  296. printf(" not supported\n" );
  297. #else
  298. DWORD err;
  299. err = IISControlInstance(
  300. Server,
  301. INET_HTTP_SVC_ID,
  302. instance,
  303. Code
  304. );
  305. printf("err %d\n",err);
  306. #endif
  307. }
  308. void
  309. flush( DWORD Service )
  310. {
  311. DWORD err;
  312. err = InetInfoFlushMemoryCache( NULL, 4 ); // '4' is the webserver
  313. printf("Flush Memory Cache returned %d\n", err );
  314. }
  315. int __cdecl
  316. main( int argc, char * argv[])
  317. {
  318. CHAR op;
  319. DWORD instance;
  320. DWORD iArg = 1;
  321. if ( argc < 2 ) {
  322. printf( "infotest.exe [Server] [add | get | enum | web | ... ] \n" );
  323. printf( "cacheflush to flush the object cache\n" );
  324. printf( "only add and get are currently supported\n" );
  325. return 1;
  326. }
  327. if ( *argv[iArg] == '\\' ){
  328. wsprintfW( Server, L"%S", argv[iArg++] );
  329. }
  330. if ( argc > 2 ){
  331. op = argv[iArg++][0];
  332. printf("operation %c\n",op);
  333. }else{
  334. op = 'e';
  335. }
  336. if ( argc > 4 ){
  337. Level = atoi(argv[iArg+1]);
  338. printf("Level %d\n", Level);
  339. } else {
  340. Level = 1;
  341. }
  342. switch (op) {
  343. case 'a':
  344. add( &instance );
  345. break;
  346. case 'b':
  347. instance = atoi(argv[iArg]);
  348. set( instance );
  349. break;
  350. case 'v':
  351. instance = atoi(argv[iArg]);
  352. setvr( instance );
  353. break;
  354. case 'd':
  355. if ( argc > 2 ) {
  356. instance = atoi(argv[iArg]);
  357. printf("instance %d\n",instance);
  358. del(instance);
  359. }
  360. break;
  361. case 'e':
  362. enumer();
  363. break;
  364. case 'c':
  365. flush( 0 );
  366. break;
  367. #if 0
  368. case 's':
  369. if ( argc > 2 ) {
  370. instance = atoi(argv[iArg]);
  371. printf("starting instance %d\n",instance);
  372. ctrl(instance,IIS_CONTROL_CODE_START);
  373. }
  374. break;
  375. case 'p':
  376. if ( argc > 2 ) {
  377. instance = atoi(argv[iArg]);
  378. printf("instance %d\n",instance);
  379. ctrl(instance,IIS_CONTROL_CODE_PAUSE);
  380. }
  381. break;
  382. case 'c':
  383. if ( argc > 2 ) {
  384. instance = atoi(argv[iArg]);
  385. printf("instance %d\n",instance);
  386. ctrl(instance,IIS_CONTROL_CODE_CONTINUE);
  387. }
  388. break;
  389. case 'x':
  390. if ( argc > 2 ) {
  391. instance = atoi(argv[iArg]);
  392. printf("instance %d\n",instance);
  393. ctrl(instance,IIS_CONTROL_CODE_STOP);
  394. }
  395. break;
  396. #endif
  397. case 'g':
  398. get(0);
  399. break;
  400. case 'w':
  401. if ( argc > 2 ) {
  402. instance = atoi(argv[iArg]);
  403. printf("instance %d\n",instance);
  404. getweb(instance);
  405. }
  406. break;
  407. case 'f':
  408. if ( argc > 2 ) {
  409. instance = atoi(argv[iArg]);
  410. printf("instance %d\n",instance);
  411. getftp(instance);
  412. }
  413. break;
  414. default:
  415. printf( "unknown command\n" );
  416. break;
  417. }
  418. return(0);
  419. } // main()