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.

577 lines
19 KiB

  1. /*++
  2. Copyright (c) 1991 Microsoft Corporation
  3. Module Name:
  4. wstsend.c
  5. Abstract:
  6. Test program for the NetServerEnum API. Run this test after
  7. starting the Workstation service.
  8. wstenum [domain]
  9. Author:
  10. Rita Wong (ritaw) 24-Oct-1991
  11. Revision History:
  12. --*/
  13. #include <stdio.h>
  14. #include <string.h>
  15. #include <stdlib.h>
  16. #include <nt.h>
  17. #include <ntrtl.h>
  18. #include <nturtl.h>
  19. #include <winerror.h>
  20. #include <windef.h> // Win32 type definitions
  21. #include <winbase.h> // Win32 base API prototypes
  22. #include <lm.h> // LAN Man definitions
  23. #include <lmserver.h>
  24. #include <tstring.h>
  25. #include <netdebug.h> // NetpDbgDisplay routines.
  26. #include <dlserver.h>
  27. #define FIXED_WIDTH_STRING "%-30ws: "
  28. #define INDENT " "
  29. VOID
  30. DisplayServerInfo(
  31. IN DWORD Level,
  32. IN LPVOID Info
  33. );
  34. VOID
  35. DisplayDword(
  36. IN LPTSTR Tag,
  37. IN DWORD Value
  38. );
  39. VOID
  40. DisplayBool(
  41. IN LPTSTR Tag,
  42. IN BOOL Value
  43. );
  44. VOID
  45. TestServerEnum(
  46. IN LPTSTR DomainName OPTIONAL,
  47. IN DWORD PreferedMaximumLength,
  48. IN OUT LPDWORD ResumeHandle OPTIONAL
  49. );
  50. VOID __cdecl
  51. main(
  52. int argc,
  53. char *argv[]
  54. )
  55. {
  56. LPTSTR DomainName = NULL;
  57. if (argc > 2) {
  58. printf("Usage: wstenum [domain].\n");
  59. return;
  60. }
  61. if (argc == 2) {
  62. #ifdef UNICODE
  63. DomainName = NetpAllocWStrFromStr(argv[1]);
  64. #else
  65. DomainName = argv[1];
  66. #endif
  67. }
  68. //
  69. // Enumerate all servers
  70. //
  71. TestServerEnum(DomainName, MAXULONG, NULL);
  72. #ifdef UNICODE
  73. NetApiBufferFree(DomainName);
  74. #endif
  75. }
  76. VOID
  77. TestServerEnum(
  78. IN LPTSTR DomainName OPTIONAL,
  79. IN DWORD PreferedMaximumLength,
  80. IN OUT LPDWORD ResumeHandle OPTIONAL
  81. )
  82. {
  83. DWORD i;
  84. NET_API_STATUS status;
  85. DWORD EntriesRead,
  86. TotalEntries;
  87. PSERVER_INFO_101 ServerInfo, saveptr;
  88. if (ARGUMENT_PRESENT(ResumeHandle)) {
  89. printf("\nInput ResumeHandle=x%08lx\n", *ResumeHandle);
  90. }
  91. status = NetServerEnum(
  92. NULL,
  93. 101,
  94. (LPBYTE *) &ServerInfo,
  95. PreferedMaximumLength,
  96. &EntriesRead,
  97. &TotalEntries,
  98. SV_TYPE_ALL,
  99. DomainName,
  100. ResumeHandle
  101. );
  102. saveptr = ServerInfo;
  103. if (status != NERR_Success && status != ERROR_MORE_DATA) {
  104. printf("NetServerEnum FAILED %lu\n", status);
  105. }
  106. else {
  107. printf("Return code from NetServerEnum %lu\n", status);
  108. printf("EntriesRead=%lu, TotalEntries=%lu\n",
  109. EntriesRead, TotalEntries);
  110. if (ARGUMENT_PRESENT(ResumeHandle)) {
  111. printf("Output ResumeHandle=x%08lx\n", *ResumeHandle);
  112. }
  113. for (i = 0; i < EntriesRead; i++, ServerInfo++) {
  114. DisplayServerInfo(101, ServerInfo);
  115. }
  116. //
  117. // Free buffer allocated for us.
  118. //
  119. NetApiBufferFree(saveptr);
  120. }
  121. }
  122. VOID
  123. DisplayTag(
  124. IN LPTSTR Tag
  125. )
  126. {
  127. printf(INDENT FIXED_WIDTH_STRING, Tag);
  128. } // NetpDbgDisplayTag
  129. VOID
  130. DisplayString(
  131. IN LPTSTR Tag,
  132. IN LPTSTR Value
  133. )
  134. {
  135. DisplayTag( Tag );
  136. if (Value != NULL) {
  137. printf(FORMAT_LPTSTR "\n", Value);
  138. } else {
  139. printf("(none)\n");
  140. }
  141. } // NetpDbgDisplayString
  142. VOID
  143. DisplayDwordHex(
  144. IN LPTSTR Tag,
  145. IN DWORD Value
  146. )
  147. {
  148. DisplayTag( Tag );
  149. printf(FORMAT_HEX_DWORD, Value);
  150. printf("\n");
  151. } // NetpDbgDisplayDwordHex
  152. DBGSTATIC VOID
  153. DisplayServerType(
  154. IN DWORD Type
  155. )
  156. {
  157. // Longest name is "DOMAIN_BAKCTRL" (14 chars)
  158. TCHAR str[(14+2)*11]; // 14 chars per name, 2 spaces, for 11 names.
  159. str[0] = '\0';
  160. #define DO(name) \
  161. if (Type & SV_TYPE_ ## name) { \
  162. (void) STRCAT(str, # name); \
  163. (void) STRCAT(str, L" "); \
  164. Type &= ~(SV_TYPE_ ## name); \
  165. }
  166. NetpAssert(Type != 0);
  167. DO(WORKSTATION);
  168. DO(SERVER);
  169. DO(SQLSERVER);
  170. DO(DOMAIN_CTRL);
  171. DO(DOMAIN_BAKCTRL);
  172. DO(TIME_SOURCE);
  173. DO(AFP);
  174. DO(NOVELL);
  175. DO(DOMAIN_MEMBER);
  176. DO(PRINTQ_SERVER);
  177. DO(DIALIN_SERVER);
  178. DisplayString(L"server type", str);
  179. if (Type != 0) {
  180. DisplayDwordHex( L"UNEXPECTED TYPE BIT(S)", Type );
  181. }
  182. } // DisplayServerType
  183. VOID
  184. DisplayLanManVersion(
  185. IN DWORD MajorVersion,
  186. IN DWORD MinorVersion
  187. )
  188. {
  189. DisplayTag( L"LanMan version" );
  190. printf(FORMAT_DWORD "." FORMAT_DWORD "\n",
  191. (DWORD) (MajorVersion & (MAJOR_VERSION_MASK)),
  192. (DWORD) (MinorVersion) );
  193. } // DisplayLanManVersion
  194. DBGSTATIC VOID
  195. DisplayDisconnectTime(
  196. IN LONG DiscTime
  197. )
  198. {
  199. DisplayTag(L"Idle session time (min)" );
  200. if (DiscTime == SV_NODISC) {
  201. printf("infinite\n" );
  202. } else {
  203. printf(FORMAT_LONG "\n", DiscTime );
  204. }
  205. } // NetpDbgDisplayDisconnectTime
  206. DBGSTATIC VOID
  207. DisplayLicenses(
  208. IN DWORD MajorVersion,
  209. IN DWORD Licenses
  210. )
  211. {
  212. UNREFERENCED_PARAMETER( MajorVersion );
  213. DisplayDword(L"Licenses (NOT users)", Licenses );
  214. } // NetpDbgDisplayLicenses
  215. VOID
  216. DisplayPlatformId(
  217. IN DWORD Value
  218. )
  219. {
  220. LPTSTR String;
  221. switch (Value) {
  222. case PLATFORM_ID_DOS : String =L"DOS"; break;
  223. case PLATFORM_ID_OS2 : String =L"OS2"; break;
  224. case PLATFORM_ID_NT : String =L"NT"; break;
  225. default : String =L"unknown"; break;
  226. }
  227. DisplayString(L"Platform ID", String );
  228. }
  229. VOID
  230. DisplayBool(
  231. IN LPTSTR Tag,
  232. IN BOOL Value
  233. )
  234. {
  235. DisplayTag( Tag );
  236. printf(Value ? "Yes" : "No");
  237. printf("\n");
  238. }
  239. VOID
  240. DisplayDword(
  241. IN LPTSTR Tag,
  242. IN DWORD Value
  243. )
  244. {
  245. DisplayTag( Tag );
  246. printf(FORMAT_DWORD, Value);
  247. printf("\n");
  248. } // DbgDisplayDword
  249. VOID
  250. DisplayServerInfo(
  251. IN DWORD Level,
  252. IN LPVOID Info
  253. )
  254. {
  255. printf("server info (level " FORMAT_DWORD ") at "
  256. FORMAT_LPVOID ":\n", Level, (LPVOID) Info);
  257. NetpAssert(Info != NULL);
  258. switch (Level) {
  259. case 0 :
  260. {
  261. LPSERVER_INFO_0 psv0 = Info;
  262. DisplayString(L"name", psv0->sv0_name);
  263. }
  264. break;
  265. case 1 :
  266. {
  267. LPSERVER_INFO_1 psv1 = Info;
  268. DisplayString(L"name", psv1->sv1_name);
  269. DisplayLanManVersion(
  270. psv1->sv1_version_major,
  271. psv1->sv1_version_minor);
  272. DisplayServerType( psv1->sv1_type );
  273. DisplayString(L"comment", psv1->sv1_comment);
  274. }
  275. break;
  276. case 2 :
  277. {
  278. LPSERVER_INFO_2 psv2 = Info;
  279. DisplayString(L"name", psv2->sv2_name);
  280. DisplayLanManVersion(
  281. psv2->sv2_version_major,
  282. psv2->sv2_version_minor);
  283. DisplayServerType( psv2->sv2_type );
  284. DisplayString(L"comment", psv2->sv2_comment);
  285. DisplayDword(L"ulist_mtime", psv2->sv2_ulist_mtime);
  286. DisplayDword(L"glist_mtime", psv2->sv2_glist_mtime);
  287. DisplayDword(L"alist_mtime", psv2->sv2_alist_mtime);
  288. DisplayDword(L"users", psv2->sv2_users);
  289. DisplayDisconnectTime( psv2->sv2_disc);
  290. DisplayString(L"alerts", psv2->sv2_alerts);
  291. DisplayDword(L"security", psv2->sv2_security);
  292. DisplayDword(L"auditing", psv2->sv2_auditing);
  293. DisplayDword(L"numadmin", psv2->sv2_numadmin);
  294. DisplayDword(L"lanmask", psv2->sv2_lanmask);
  295. DisplayDword(L"hidden", psv2->sv2_hidden);
  296. DisplayDword(L"announce", psv2->sv2_announce);
  297. DisplayDword(L"anndelta", psv2->sv2_anndelta);
  298. DisplayString(L"guestacct", psv2->sv2_guestacct);
  299. DisplayLicenses(
  300. psv2->sv2_version_major,
  301. psv2->sv2_licenses );
  302. DisplayString(L"userpath", psv2->sv2_userpath);
  303. DisplayDword(L"chdevs", psv2->sv2_chdevs);
  304. DisplayDword(L"chdevq", psv2->sv2_chdevq);
  305. DisplayDword(L"chdevjobs", psv2->sv2_chdevjobs);
  306. DisplayDword(L"connections", psv2->sv2_connections);
  307. DisplayDword(L"shares", psv2->sv2_shares);
  308. DisplayDword(L"openfiles", psv2->sv2_openfiles);
  309. DisplayDword(L"sessopens", psv2->sv2_sessopens);
  310. DisplayDword(L"sessvcs", psv2->sv2_sessvcs);
  311. DisplayDword(L"sessreqs", psv2->sv2_sessreqs);
  312. DisplayDword(L"opensearch", psv2->sv2_opensearch);
  313. DisplayDword(L"activelocks", psv2->sv2_activelocks);
  314. DisplayDword(L"numreqbuf", psv2->sv2_numreqbuf);
  315. DisplayDword(L"sizreqbuf", psv2->sv2_sizreqbuf);
  316. DisplayDword(L"numbigbuf", psv2->sv2_numbigbuf);
  317. DisplayDword(L"numfiletasks", psv2->sv2_numfiletasks);
  318. DisplayDword(L"alertsched", psv2->sv2_alertsched);
  319. DisplayDword(L"erroralert", psv2->sv2_erroralert);
  320. DisplayDword(L"logonalert", psv2->sv2_logonalert);
  321. DisplayDword(L"accessalert", psv2->sv2_accessalert);
  322. DisplayDword(L"diskalert", psv2->sv2_diskalert);
  323. DisplayDword(L"netioalert", psv2->sv2_netioalert);
  324. DisplayDword(L"maxauditsz", psv2->sv2_maxauditsz);
  325. DisplayString(L"srvheuristics", psv2->sv2_srvheuristics);
  326. }
  327. break;
  328. case 3 :
  329. {
  330. LPSERVER_INFO_3 psv3 = Info;
  331. DisplayString(L"name", psv3->sv3_name);
  332. DisplayLanManVersion(
  333. psv3->sv3_version_major,
  334. psv3->sv3_version_minor);
  335. DisplayServerType( psv3->sv3_type );
  336. DisplayString(L"comment", psv3->sv3_comment);
  337. DisplayDword(L"ulist_mtime", psv3->sv3_ulist_mtime);
  338. DisplayDword(L"glist_mtime", psv3->sv3_glist_mtime);
  339. DisplayDword(L"alist_mtime", psv3->sv3_alist_mtime);
  340. DisplayDword(L"users", psv3->sv3_users);
  341. DisplayDisconnectTime( psv3->sv3_disc );
  342. DisplayString(L"alerts", psv3->sv3_alerts);
  343. DisplayDword(L"security", psv3->sv3_security);
  344. DisplayDword(L"auditing", psv3->sv3_auditing);
  345. DisplayDword(L"numadmin", psv3->sv3_numadmin);
  346. DisplayDword(L"lanmask", psv3->sv3_lanmask);
  347. DisplayDword(L"hidden", psv3->sv3_hidden);
  348. DisplayDword(L"announce", psv3->sv3_announce);
  349. DisplayDword(L"anndelta", psv3->sv3_anndelta);
  350. DisplayString(L"guestacct", psv3->sv3_guestacct);
  351. DisplayLicenses(
  352. psv3->sv3_version_major,
  353. psv3->sv3_licenses );
  354. DisplayString(L"userpath", psv3->sv3_userpath);
  355. DisplayDword(L"chdevs", psv3->sv3_chdevs);
  356. DisplayDword(L"chdevq", psv3->sv3_chdevq);
  357. DisplayDword(L"chdevjobs", psv3->sv3_chdevjobs);
  358. DisplayDword(L"connections", psv3->sv3_connections);
  359. DisplayDword(L"shares", psv3->sv3_shares);
  360. DisplayDword(L"openfiles", psv3->sv3_openfiles);
  361. DisplayDword(L"sessopens", psv3->sv3_sessopens);
  362. DisplayDword(L"sessvcs", psv3->sv3_sessvcs);
  363. DisplayDword(L"sessreqs", psv3->sv3_sessreqs);
  364. DisplayDword(L"opensearch", psv3->sv3_opensearch);
  365. DisplayDword(L"activelocks", psv3->sv3_activelocks);
  366. DisplayDword(L"numreqbuf", psv3->sv3_numreqbuf);
  367. DisplayDword(L"sizreqbuf", psv3->sv3_sizreqbuf);
  368. DisplayDword(L"numbigbuf", psv3->sv3_numbigbuf);
  369. DisplayDword(L"numfiletasks", psv3->sv3_numfiletasks);
  370. DisplayDword(L"alertsched", psv3->sv3_alertsched);
  371. DisplayDword(L"erroralert", psv3->sv3_erroralert);
  372. DisplayDword(L"logonalert", psv3->sv3_logonalert);
  373. DisplayDword(L"accessalert", psv3->sv3_accessalert);
  374. DisplayDword(L"diskalert", psv3->sv3_diskalert);
  375. DisplayDword(L"netioalert", psv3->sv3_netioalert);
  376. DisplayDword(L"maxauditsz", psv3->sv3_maxauditsz);
  377. DisplayString(L"srvheuristics", psv3->sv3_srvheuristics);
  378. DisplayDword(L"auditedevents", psv3->sv3_auditedevents);
  379. DisplayDword(L"autoprofile", psv3->sv3_autoprofile);
  380. DisplayString(L"autopath", psv3->sv3_autopath);
  381. }
  382. break;
  383. case 100 :
  384. {
  385. LPSERVER_INFO_100 psv100 = Info;
  386. DisplayPlatformId( psv100->sv100_platform_id );
  387. DisplayString(L"Server Name", psv100->sv100_name);
  388. }
  389. break;
  390. case 101 :
  391. {
  392. LPSERVER_INFO_101 psv101 = Info;
  393. DisplayPlatformId( psv101->sv101_platform_id );
  394. DisplayString(L"Server Name", psv101->sv101_name);
  395. DisplayLanManVersion(
  396. psv101->sv101_version_major,
  397. psv101->sv101_version_minor);
  398. DisplayServerType( psv101->sv101_type );
  399. DisplayString(L"Server Comment", psv101->sv101_comment);
  400. }
  401. break;
  402. case 102 :
  403. {
  404. LPSERVER_INFO_102 psv102 = Info;
  405. DisplayPlatformId( psv102->sv102_platform_id );
  406. DisplayString(L"Server Name", psv102->sv102_name);
  407. DisplayLanManVersion(
  408. psv102->sv102_version_major,
  409. psv102->sv102_version_minor );
  410. DisplayServerType( psv102->sv102_type );
  411. DisplayString(L"Server Comment", psv102->sv102_comment );
  412. DisplayDword(L"users", psv102->sv102_users );
  413. DisplayBool(L"Server hidden", psv102->sv102_hidden );
  414. DisplayDword(L"announce", psv102->sv102_announce );
  415. DisplayDword(L"announce delta", psv102->sv102_anndelta );
  416. DisplayLicenses(
  417. psv102->sv102_version_major,
  418. psv102->sv102_licenses );
  419. DisplayString(L"user path", psv102->sv102_userpath );
  420. }
  421. break;
  422. case 402 :
  423. {
  424. LPSERVER_INFO_402 psv402 = Info;
  425. DisplayDword(L"ulist mtime", psv402->sv402_ulist_mtime);
  426. DisplayDword(L"glist mtime", psv402->sv402_glist_mtime);
  427. DisplayDword(L"alist mtime", psv402->sv402_alist_mtime);
  428. DisplayString(L"alerts", psv402->sv402_alerts);
  429. DisplayDword(L"security", psv402->sv402_security);
  430. DisplayDword(L"numadmin", psv402->sv402_numadmin);
  431. DisplayDwordHex(L"lanmask", psv402->sv402_lanmask);
  432. DisplayString(L"guestacct", psv402->sv402_guestacct);
  433. DisplayDword(L"chdevs", psv402->sv402_chdevs);
  434. DisplayDword(L"chdevq", psv402->sv402_chdevq);
  435. DisplayDword(L"chdevjobs", psv402->sv402_chdevjobs);
  436. DisplayDword(L"connections", psv402->sv402_connections);
  437. DisplayDword(L"shares", psv402->sv402_shares);
  438. DisplayDword(L"openfiles", psv402->sv402_openfiles);
  439. DisplayDword(L"sessopens", psv402->sv402_sessopens);
  440. DisplayDword(L"sessvcs", psv402->sv402_sessvcs);
  441. DisplayDword(L"sessreqs", psv402->sv402_sessreqs);
  442. DisplayDword(L"opensearch", psv402->sv402_opensearch);
  443. DisplayDword(L"activelocks", psv402->sv402_activelocks);
  444. DisplayDword(L"numreqbuf", psv402->sv402_numreqbuf);
  445. DisplayDword(L"sizreqbuf", psv402->sv402_sizreqbuf);
  446. DisplayDword(L"numbigbuf", psv402->sv402_numbigbuf);
  447. DisplayDword(L"numfiletasks", psv402->sv402_numfiletasks);
  448. DisplayDword(L"alertsched", psv402->sv402_alertsched);
  449. DisplayDword(L"erroralert", psv402->sv402_erroralert);
  450. DisplayDword(L"logonalert", psv402->sv402_logonalert);
  451. DisplayDword(L"diskalert", psv402->sv402_diskalert);
  452. DisplayDword(L"accessalert", psv402->sv402_accessalert);
  453. DisplayDword(L"diskalert", psv402->sv402_diskalert);
  454. DisplayDword(L"netioalert", psv402->sv402_netioalert);
  455. DisplayDword(L"maxauditsz", psv402->sv402_maxauditsz);
  456. DisplayString(L"srvheuristics", psv402->sv402_srvheuristics);
  457. }
  458. break;
  459. case 403 :
  460. {
  461. LPSERVER_INFO_403 psv403 = Info;
  462. DisplayDword(L"ulist mtime", psv403->sv403_ulist_mtime);
  463. DisplayDword(L"glist mtime", psv403->sv403_glist_mtime);
  464. DisplayDword(L"alist mtime", psv403->sv403_alist_mtime);
  465. DisplayString(L"alerts", psv403->sv403_alerts);
  466. DisplayDword(L"security", psv403->sv403_security);
  467. DisplayDword(L"numadmin", psv403->sv403_numadmin);
  468. DisplayDwordHex(L"lanmask", psv403->sv403_lanmask);
  469. DisplayString(L"guestacct", psv403->sv403_guestacct);
  470. DisplayDword(L"chdevs", psv403->sv403_chdevs);
  471. DisplayDword(L"chdevq", psv403->sv403_chdevq);
  472. DisplayDword(L"chdevjobs", psv403->sv403_chdevjobs);
  473. DisplayDword(L"connections", psv403->sv403_connections);
  474. DisplayDword(L"shares", psv403->sv403_shares);
  475. DisplayDword(L"openfiles", psv403->sv403_openfiles);
  476. DisplayDword(L"sessopens", psv403->sv403_sessopens);
  477. DisplayDword(L"sessvcs", psv403->sv403_sessvcs);
  478. DisplayDword(L"sessreqs", psv403->sv403_sessreqs);
  479. DisplayDword(L"opensearch", psv403->sv403_opensearch);
  480. DisplayDword(L"activelocks", psv403->sv403_activelocks);
  481. DisplayDword(L"numreqbuf", psv403->sv403_numreqbuf);
  482. DisplayDword(L"sizreqbuf", psv403->sv403_sizreqbuf);
  483. DisplayDword(L"numbigbuf", psv403->sv403_numbigbuf);
  484. DisplayDword(L"numfiletasks", psv403->sv403_numfiletasks);
  485. DisplayDword(L"alertsched", psv403->sv403_alertsched);
  486. DisplayDword(L"erroralert", psv403->sv403_erroralert);
  487. DisplayDword(L"logonalert", psv403->sv403_logonalert);
  488. DisplayDword(L"diskalert", psv403->sv403_diskalert);
  489. DisplayDword(L"accessalert", psv403->sv403_accessalert);
  490. DisplayDword(L"diskalert", psv403->sv403_diskalert);
  491. DisplayDword(L"netioalert", psv403->sv403_netioalert);
  492. DisplayDword(L"maxauditsz", psv403->sv403_maxauditsz);
  493. DisplayString(L"srvheuristics", psv403->sv403_srvheuristics);
  494. DisplayDword(L"auditedevents", psv403->sv403_auditedevents);
  495. DisplayDword(L"autoprofile", psv403->sv403_autoprofile);
  496. DisplayString(L"autopath", psv403->sv403_autopath);
  497. }
  498. break;
  499. // RpcXlate doesn't need support for info levels 502, 503, 599.
  500. // Feel free to add them here if you need them.
  501. default :
  502. NetpAssert(FALSE);
  503. }
  504. } // DisplayServerInfo