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.

971 lines
22 KiB

  1. /*++
  2. Copyright (c) 1991 Microsoft Corporation
  3. Module Name:
  4. wstest.c
  5. Abstract:
  6. Test program for the NetWksta and NetUse APIs. Run this test after
  7. starting the Workstation service.
  8. Author:
  9. Rita Wong (ritaw) 12-Mar-1991
  10. Revision History:
  11. --*/
  12. #include <stdio.h>
  13. #include <string.h>
  14. #include <stdlib.h>
  15. #include <nt.h>
  16. #include <ntrtl.h>
  17. #include <nturtl.h>
  18. #include <winerror.h>
  19. #include <windef.h> // Win32 type definitions
  20. #include <winbase.h> // Win32 base API prototypes
  21. #include <lm.h> // LAN Man definitions
  22. #include <netdebug.h> // NetpDbgDisplayWksta()
  23. #include <netlib.h>
  24. #include <tstring.h>
  25. #ifdef UNICODE
  26. #define FORMAT_STR "ws "
  27. #else
  28. #define FORMAT_STR "s "
  29. #endif
  30. #define CHANGE_HEURISTICS \
  31. for (i = 0, ptr = &(redir->wki502_use_opportunistic_locking); i < 14; \
  32. i++, ptr++) { \
  33. if (*ptr) { \
  34. *ptr = FALSE; \
  35. } \
  36. else { \
  37. *ptr = TRUE; \
  38. } \
  39. }
  40. CHAR WorkBuffer[(DEVLEN + RMLEN + PWLEN + UNLEN + DNLEN + 5) * sizeof(TCHAR)
  41. + sizeof(PUSE_INFO_2)];
  42. LPWSTR TargetMachine = NULL;
  43. VOID
  44. WsTestWkstaInfo(
  45. VOID
  46. );
  47. VOID
  48. WsTestWkstaTransportEnum(
  49. VOID
  50. );
  51. VOID
  52. WsTestUse(
  53. VOID
  54. );
  55. VOID
  56. TestUseAdd(
  57. IN LPBYTE Buffer,
  58. IN DWORD ExpectedStatus
  59. );
  60. VOID
  61. TestUseDel(
  62. IN LPTSTR UseName,
  63. IN DWORD ForceLevel,
  64. IN DWORD ExpectedStatus
  65. );
  66. VOID
  67. TestUseEnum(
  68. DWORD PreferedMaximumLength,
  69. IN OUT LPDWORD ResumeHandle OPTIONAL
  70. );
  71. VOID
  72. TestUseGetInfo(
  73. LPTSTR UseName,
  74. DWORD ExpectedStatus
  75. );
  76. VOID
  77. PrintUseInfo1(
  78. PUSE_INFO_1 UseInfo
  79. );
  80. VOID
  81. PrintUseInfo2(
  82. PUSE_INFO_2 UseInfo
  83. );
  84. VOID __cdecl
  85. main(
  86. int argc,
  87. char *argv[]
  88. )
  89. {
  90. if (argc > 1) {
  91. if (argc == 3) {
  92. TargetMachine = NetpAllocWStrFromStr(argv[2]);
  93. if (TargetMachine != NULL) {
  94. printf("New Target is %ws\n", TargetMachine);
  95. }
  96. }
  97. WsTestWkstaInfo();
  98. WsTestWkstaTransportEnum();
  99. if (TargetMachine != NULL) {
  100. NetApiBufferFree(TargetMachine);
  101. }
  102. }
  103. WsTestUse();
  104. }
  105. VOID
  106. WsTestWkstaInfo(
  107. VOID
  108. )
  109. {
  110. NET_API_STATUS status;
  111. PWKSTA_INFO_502 redir;
  112. PWKSTA_INFO_102 systeminfo102;
  113. PWKSTA_INFO_100 systeminfo100;
  114. PWKSTA_INFO_101 systeminfo101;
  115. PWKSTA_USER_INFO_0 UserInfo0;
  116. PWKSTA_USER_INFO_1 UserInfo;
  117. DWORD ErrorParameter;
  118. DWORD i = 0;
  119. BOOL *ptr = NULL;
  120. DWORD ResumeHandle = 0;
  121. DWORD EntriesRead;
  122. DWORD TotalEntries;
  123. printf("In wstest.exe\n\n");
  124. status = NetWkstaGetInfo(
  125. TargetMachine,
  126. 502,
  127. (LPBYTE *) &redir
  128. );
  129. printf("NetWkstaGetInfo Test:status=%lu\n", status);
  130. if (status != NERR_Success) {
  131. goto TrySomethingElse;
  132. }
  133. redir->wki502_char_wait++;
  134. redir->wki502_maximum_collection_count++;
  135. redir->wki502_collection_time++;
  136. redir->wki502_keep_conn++;
  137. redir->wki502_siz_char_buf++;
  138. redir->wki502_max_cmds++; // Not settable: should be ignored
  139. redir->wki502_sess_timeout++;
  140. redir->wki502_lock_quota++;
  141. redir->wki502_lock_increment++;
  142. redir->wki502_lock_maximum++;
  143. redir->wki502_pipe_increment++;
  144. redir->wki502_pipe_maximum++;
  145. redir->wki502_cache_file_timeout++;
  146. CHANGE_HEURISTICS;
  147. status = NetWkstaSetInfo(
  148. TargetMachine,
  149. 502,
  150. (LPBYTE) redir,
  151. &ErrorParameter
  152. );
  153. printf("NetWkstaSetInfo Test:status=%lu\n", status);
  154. //
  155. // Free the get info buffer. We are getting another buffer from the
  156. // next get.
  157. //
  158. NetApiBufferFree(redir);
  159. if (status != NERR_Success) {
  160. if (status == ERROR_INVALID_PARAMETER) {
  161. printf(
  162. "NetWkstaSetInfo parameter %lu causes ERROR_INVALID_PARAMETER\n",
  163. ErrorParameter
  164. );
  165. }
  166. goto TrySomethingElse;
  167. }
  168. status = NetWkstaGetInfo(
  169. TargetMachine,
  170. 502,
  171. (LPBYTE *) &redir
  172. );
  173. printf("NetWkstaGetInfo again: status=%lu\n", status);
  174. if (status != NERR_Success) {
  175. goto TrySomethingElse;
  176. }
  177. printf("\nAfter NetWkstaSetInfo, all values should be 1 extra"
  178. " maxcmds\n");
  179. redir->wki502_char_wait--;
  180. redir->wki502_collection_time--;
  181. redir->wki502_maximum_collection_count--;
  182. redir->wki502_keep_conn--;
  183. redir->wki502_siz_char_buf--;
  184. //redir->wki502_max_cmds--; // Not settable
  185. redir->wki502_sess_timeout--;
  186. redir->wki502_lock_quota--;
  187. redir->wki502_lock_increment--;
  188. redir->wki502_lock_maximum--;
  189. redir->wki502_pipe_increment--;
  190. redir->wki502_pipe_maximum--;
  191. redir->wki502_cache_file_timeout--;
  192. CHANGE_HEURISTICS;
  193. status = NetWkstaSetInfo(
  194. TargetMachine,
  195. 502,
  196. (LPBYTE) redir,
  197. NULL
  198. );
  199. NetApiBufferFree(redir);
  200. printf("NetWkstaGetInfo to reset to original values: status=%lu\n", status);
  201. TrySomethingElse:
  202. //
  203. // Get system info 102
  204. //
  205. status = NetWkstaGetInfo(
  206. TargetMachine,
  207. 102,
  208. (LPBYTE *) &systeminfo102
  209. );
  210. if (status == NERR_Success) {
  211. NetApiBufferFree(systeminfo102);
  212. }
  213. else {
  214. printf("NetWkstaGetInfo level 102: FAILED %lu\n", status);
  215. }
  216. //
  217. // Get system info 100
  218. //
  219. status = NetWkstaGetInfo(
  220. TargetMachine,
  221. 100,
  222. (LPBYTE *) &systeminfo100
  223. );
  224. if (status == NERR_Success) {
  225. NetApiBufferFree(systeminfo100);
  226. }
  227. else {
  228. printf("NetWkstaGetInfo level 100: FAILED %lu\n", status);
  229. }
  230. //
  231. // Get system info 101
  232. //
  233. status = NetWkstaGetInfo(
  234. TargetMachine,
  235. 101,
  236. (LPBYTE *) &systeminfo101
  237. );
  238. if (status == NERR_Success) {
  239. NetApiBufferFree(systeminfo101);
  240. }
  241. else {
  242. printf("NetWkstaGetInfo level 101: FAILED %lu\n", status);
  243. }
  244. //
  245. // Get user info level 1
  246. //
  247. status = NetWkstaUserGetInfo(
  248. NULL,
  249. 1,
  250. (LPBYTE *) &UserInfo
  251. );
  252. if (status == NERR_Success) {
  253. printf("NetWkstaUserGetInfo level 1:\n"
  254. "username=" FORMAT_LPTSTR "\nlogon domain=" FORMAT_LPTSTR "\nother domains=" FORMAT_LPTSTR "\nlogon server=" FORMAT_LPTSTR "\n",
  255. UserInfo->wkui1_username,
  256. UserInfo->wkui1_logon_domain,
  257. UserInfo->wkui1_oth_domains,
  258. UserInfo->wkui1_logon_server
  259. );
  260. NetApiBufferFree(UserInfo);
  261. }
  262. else {
  263. printf("NetWkstaUserGetInfo level 1: FAILED %lu", status);
  264. }
  265. //
  266. // Get user info level 0
  267. //
  268. status = NetWkstaUserGetInfo(
  269. NULL,
  270. 0,
  271. (LPBYTE *) &UserInfo0
  272. );
  273. if (status == NERR_Success) {
  274. printf("NetWkstaUserGetInfo level 0:\nusername=" FORMAT_LPTSTR "\n",
  275. UserInfo0->wkui0_username
  276. );
  277. NetApiBufferFree(UserInfo0);
  278. }
  279. else {
  280. printf("NetWkstaUserGetInfo level 0: FAILED %lu", status);
  281. }
  282. status = NetWkstaUserEnum (
  283. TargetMachine,
  284. 1,
  285. (LPBYTE *) &UserInfo,
  286. MAXULONG,
  287. &EntriesRead,
  288. &TotalEntries,
  289. &ResumeHandle
  290. );
  291. if (status == NERR_Success) {
  292. PWKSTA_USER_INFO_1 TmpPtr = UserInfo;
  293. printf("NetWkstaUserEnum level 1: EntriesRead=%lu, TotalEntries=%lu\n",
  294. EntriesRead, TotalEntries);
  295. for (i = 0; i < EntriesRead; i++, UserInfo++) {
  296. printf(" username=" FORMAT_LPTSTR "\nlogon domain=" FORMAT_LPTSTR "\nother domains=" FORMAT_LPTSTR "\nlogon server=" FORMAT_LPTSTR "\n",
  297. UserInfo->wkui1_username,
  298. UserInfo->wkui1_logon_domain,
  299. UserInfo->wkui1_oth_domains,
  300. UserInfo->wkui1_logon_server
  301. );
  302. }
  303. NetApiBufferFree(TmpPtr);
  304. }
  305. else {
  306. printf("NetWkstaUserEnum level 1: FAILED %lu", status);
  307. }
  308. }
  309. VOID
  310. WsTestWkstaTransportEnum(
  311. VOID
  312. )
  313. {
  314. NET_API_STATUS status;
  315. LPBYTE Buffer;
  316. DWORD EntriesRead,
  317. TotalEntries,
  318. ResumeHandle = 0;
  319. status = NetWkstaTransportEnum(
  320. NULL,
  321. 0,
  322. &Buffer,
  323. MAXULONG,
  324. &EntriesRead,
  325. &TotalEntries,
  326. &ResumeHandle
  327. );
  328. printf("NetWkstaTransportEnum Test:status=%lu\n", status);
  329. if (status == NERR_Success) {
  330. printf(" EntriesRead=%lu, TotalEntries=%lu\n", EntriesRead,
  331. TotalEntries);
  332. NetApiBufferFree(Buffer);
  333. }
  334. }
  335. VOID
  336. WsTestUse(
  337. VOID
  338. )
  339. {
  340. PUSE_INFO_2 UseInfo = (PUSE_INFO_2) WorkBuffer;
  341. DWORD ResumeHandle = 0;
  342. DWORD i;
  343. LPTSTR PasswordSavePtr;
  344. LPTSTR UserNameSavePtr;
  345. LPTSTR DomainNameSavePtr;
  346. //
  347. // Initialize string pointers. Local device points to the bottom
  348. // of Info 2 structure; Shared resource points to the middle of
  349. // buffer (away from everything so there's no chance of overwriting
  350. // or being overwritten.
  351. //
  352. UseInfo->ui2_local = (LPTSTR) &WorkBuffer[sizeof(USE_INFO_2)];
  353. UseInfo->ui2_remote = (LPTSTR) ((DWORD) UseInfo->ui2_local) +
  354. (DEVLEN + 1) * sizeof(TCHAR);
  355. UseInfo->ui2_password = NULL;
  356. PasswordSavePtr = (LPTSTR) ((DWORD) UseInfo->ui2_remote) +
  357. (RMLEN + 1) * sizeof(TCHAR);
  358. UseInfo->ui2_username = NULL;
  359. UserNameSavePtr = (LPTSTR) ((DWORD) PasswordSavePtr) +
  360. (PWLEN + 1) * sizeof(TCHAR);
  361. UseInfo->ui2_domainname = NULL;
  362. DomainNameSavePtr = (LPTSTR) ((DWORD) UserNameSavePtr) +
  363. (DNLEN + 1) * sizeof(TCHAR);
  364. UseInfo->ui2_asg_type = USE_DISKDEV;
  365. //
  366. // Test with explicit username and password
  367. //
  368. UseInfo->ui2_username = UserNameSavePtr;
  369. UseInfo->ui2_password = PasswordSavePtr;
  370. UseInfo->ui2_domainname = DomainNameSavePtr;
  371. STRCPY(UseInfo->ui2_username, TEXT("NTBUILD"));
  372. STRCPY(UseInfo->ui2_password, TEXT("NTBUILD"));
  373. STRCPY(UseInfo->ui2_domainname, TEXT("NtWins"));
  374. STRCPY(UseInfo->ui2_local, TEXT("k:"));
  375. STRCPY(UseInfo->ui2_remote, TEXT("\\\\kernel\\razzle2"));
  376. TestUseAdd(WorkBuffer, NERR_Success);
  377. TestUseGetInfo(TEXT("K:"), NERR_Success);
  378. UseInfo->ui2_password = NULL;
  379. UseInfo->ui2_domainname = NULL;
  380. //
  381. // Connect to \\kernel\razzle2 again with only the username
  382. //
  383. STRCPY(UseInfo->ui2_local, TEXT("j:"));
  384. TestUseAdd(WorkBuffer, NERR_Success);
  385. //
  386. // Add 5 \\ritaw2\public
  387. //
  388. UseInfo->ui2_username = NULL;
  389. STRCPY(UseInfo->ui2_local, TEXT(""));
  390. STRCPY(UseInfo->ui2_remote, TEXT("\\\\ritaw2\\public"));
  391. for (i = 0; i < 5; i++) {
  392. TestUseAdd(WorkBuffer, NERR_Success);
  393. }
  394. TestUseDel(
  395. TEXT("j:"),
  396. USE_LOTS_OF_FORCE,
  397. NERR_Success
  398. );
  399. TestUseDel(
  400. TEXT("k:"),
  401. USE_LOTS_OF_FORCE,
  402. NERR_Success
  403. );
  404. //
  405. // Add p: \\ritaw2\public
  406. //
  407. STRCPY(UseInfo->ui2_local, TEXT("p:"));
  408. TestUseAdd(WorkBuffer, NERR_Success);
  409. //
  410. // Add U: \\ritaw2\public
  411. //
  412. STRCPY(UseInfo->ui2_local, TEXT("U:"));
  413. TestUseAdd(WorkBuffer, NERR_Success);
  414. //
  415. // Add s: \\ritaw2\testdir
  416. //
  417. STRCPY(UseInfo->ui2_local, TEXT("s:"));
  418. STRCPY(UseInfo->ui2_remote, TEXT("\\\\ritaw2\\testdir"));
  419. TestUseAdd(WorkBuffer, NERR_Success);
  420. TestUseAdd(WorkBuffer, ERROR_ALREADY_ASSIGNED);
  421. TestUseGetInfo(TEXT("\\\\ritaw2\\testdir"), NERR_UseNotFound);
  422. //
  423. // Add 3 \\ritaw2\testdir
  424. //
  425. STRCPY(UseInfo->ui2_local, TEXT(""));
  426. for (i = 0; i < 3; i++) {
  427. TestUseAdd(WorkBuffer, NERR_Success);
  428. }
  429. //
  430. // Create implicit connections
  431. //
  432. system("ls \\\\ritaw2\\pub2");
  433. system("ls \\\\ritaw2\\tmp");
  434. //
  435. // Delete implicit connection \\ritaw2\tmp USE_NOFORCE.
  436. //
  437. TestUseDel(
  438. TEXT("\\\\ritaw2\\tmp"),
  439. USE_NOFORCE,
  440. NERR_Success
  441. );
  442. //
  443. // Enumerate all connections
  444. //
  445. TestUseEnum(MAXULONG, NULL);
  446. TestUseEnum(150, &ResumeHandle);
  447. TestUseEnum(100, &ResumeHandle);
  448. for (i = 0; i < 3; i++) {
  449. TestUseEnum(50, &ResumeHandle);
  450. }
  451. TestUseEnum(150, NULL);
  452. //
  453. // Get info
  454. //
  455. TestUseGetInfo(TEXT("\\\\ritaw2\\public"), NERR_Success);
  456. TestUseGetInfo(TEXT("p:"), NERR_Success);
  457. TestUseGetInfo(TEXT("\\\\ritaw2\\Z"), NERR_UseNotFound);
  458. TestUseGetInfo(TEXT("\\\\ritaw2\\Testdir"), NERR_Success);
  459. TestUseGetInfo(TEXT("S:"), NERR_Success);
  460. //
  461. // Delete \\ritaw2\public USE_NOFORCE. Decrements usecount from 5 to 4.
  462. //
  463. TestUseDel(
  464. TEXT("\\\\ritaw2\\public"),
  465. USE_NOFORCE,
  466. NERR_Success
  467. );
  468. //
  469. // Delete \\ritaw2\public USE_FORCE. This should delete all 4 usecounts.
  470. //
  471. TestUseDel(
  472. TEXT("\\\\ritaw2\\public"),
  473. USE_FORCE,
  474. NERR_Success
  475. );
  476. TestUseDel(
  477. TEXT("\\\\ritaw2\\public"),
  478. USE_FORCE,
  479. NERR_UseNotFound
  480. );
  481. //
  482. // Delete s: USE_FORCE
  483. //
  484. TestUseDel(
  485. TEXT("s:"),
  486. USE_LOTS_OF_FORCE,
  487. NERR_Success
  488. );
  489. //
  490. // Add s: \\ritaw2\z
  491. //
  492. STRCPY(UseInfo->ui2_local, TEXT("s:"));
  493. STRCPY(UseInfo->ui2_remote, TEXT("\\\\ritaw2\\z"));
  494. TestUseAdd(WorkBuffer, NERR_Success);
  495. //
  496. // Delete p: USE_NOFORCE. Second time should get NERR_UseNotFound.
  497. //
  498. TestUseDel(
  499. TEXT("p:"),
  500. USE_LOTS_OF_FORCE,
  501. NERR_Success
  502. );
  503. TestUseDel(
  504. TEXT("p:"),
  505. USE_LOTS_OF_FORCE,
  506. NERR_UseNotFound
  507. );
  508. //
  509. // Delete \\ritaw2\testdir USE_NOFORCE. 4th time should be
  510. // NERR_UseNotFound.
  511. //
  512. for (i = 0; i < 3; i++) {
  513. TestUseDel(
  514. TEXT("\\\\ritaw2\\testdir"),
  515. USE_NOFORCE,
  516. NERR_Success
  517. );
  518. }
  519. TestUseDel(
  520. TEXT("\\\\ritaw2\\testdir"),
  521. USE_NOFORCE,
  522. NERR_UseNotFound
  523. );
  524. //
  525. // Add prn: \\ritaw2\prn
  526. //
  527. UseInfo->ui2_asg_type = USE_SPOOLDEV;
  528. STRCPY(UseInfo->ui2_local, TEXT("prn"));
  529. STRCPY(UseInfo->ui2_remote, TEXT("\\\\prt21088\\laserii"));
  530. TestUseAdd(WorkBuffer, NERR_Success);
  531. //
  532. // Add lpt1: \\ritaw2\laser, should get ERROR_ALREADY_ASSIGNED because prn:
  533. // is converted to lpt1.
  534. //
  535. STRCPY(UseInfo->ui2_local, TEXT("lpt1:"));
  536. STRCPY(UseInfo->ui2_remote, TEXT("\\\\prt21088\\laserii"));
  537. TestUseAdd(WorkBuffer, ERROR_ALREADY_ASSIGNED);
  538. //
  539. // Delete LPT1 USE_LOTS_OF_FORCE, should succeed
  540. //
  541. TestUseDel(
  542. TEXT("prn:"),
  543. USE_LOTS_OF_FORCE,
  544. NERR_Success
  545. );
  546. //
  547. // Bad device type
  548. //
  549. STRCPY(UseInfo->ui2_local, TEXT(""));
  550. STRCPY(UseInfo->ui2_remote, TEXT("\\\\ritaw2\\public"));
  551. UseInfo->ui2_asg_type = 12345678;
  552. TestUseAdd(WorkBuffer, NERR_BadAsgType);
  553. TestUseDel(
  554. TEXT("S:"),
  555. USE_LOTS_OF_FORCE,
  556. NERR_Success
  557. );
  558. TestUseDel(
  559. TEXT("U:"),
  560. USE_LOTS_OF_FORCE,
  561. NERR_Success
  562. );
  563. }
  564. VOID
  565. TestUseAdd(
  566. IN LPBYTE Buffer,
  567. IN DWORD ExpectedStatus
  568. )
  569. {
  570. NET_API_STATUS status;
  571. DWORD ErrorParameter;
  572. status = NetUseAdd(
  573. NULL,
  574. 2,
  575. Buffer,
  576. &ErrorParameter
  577. );
  578. printf("NetUseAdd %-5" FORMAT_STR "%-25" FORMAT_STR, ((PUSE_INFO_2) Buffer)->ui2_local,
  579. ((PUSE_INFO_2) Buffer)->ui2_remote);
  580. if (status != ExpectedStatus) {
  581. printf("FAILED: Got %lu, expected %lu\n", status, ExpectedStatus);
  582. }
  583. else {
  584. printf("OK: Got expected status %lu\n", status);
  585. }
  586. if (status == ERROR_INVALID_PARAMETER) {
  587. printf("NetUseAdd parameter %lu is cause of ERROR_INVALID_PARAMETER\n",
  588. ErrorParameter);
  589. }
  590. }
  591. VOID
  592. TestUseDel(
  593. IN LPTSTR UseName,
  594. IN DWORD ForceLevel,
  595. IN DWORD ExpectedStatus
  596. )
  597. {
  598. NET_API_STATUS status;
  599. PWCHAR Force[3] = {
  600. L"NOFORCE",
  601. L"FORCE",
  602. L"LOTS_OF_FORCE"
  603. };
  604. printf("NetUseDel %-17" FORMAT_STR "%-13" FORMAT_STR, UseName, Force[ForceLevel]);
  605. status = NetUseDel(
  606. NULL,
  607. UseName,
  608. ForceLevel
  609. );
  610. if (status != ExpectedStatus) {
  611. printf("FAILED: Got %lu, expected %lu\n", status, ExpectedStatus);
  612. }
  613. else {
  614. printf("OK: Got expected status %lu\n", status);
  615. }
  616. }
  617. VOID
  618. TestUseGetInfo(
  619. LPTSTR UseName,
  620. DWORD ExpectedStatus
  621. )
  622. {
  623. NET_API_STATUS status;
  624. PUSE_INFO_2 UseInfo;
  625. printf("NetUseGetInfo %-27" FORMAT_STR, UseName);
  626. status = NetUseGetInfo(
  627. NULL,
  628. UseName,
  629. 2,
  630. (LPBYTE *) &UseInfo
  631. );
  632. if (status != ExpectedStatus) {
  633. printf("FAILED: Got %lu, expected %lu\n", status, ExpectedStatus);
  634. }
  635. else {
  636. printf("OK: Got expected status %lu\n", status);
  637. }
  638. if (status == NERR_Success) {
  639. PrintUseInfo2(UseInfo);
  640. NetApiBufferFree(UseInfo);
  641. }
  642. }
  643. VOID
  644. TestUseEnum(
  645. IN DWORD PreferedMaximumLength,
  646. IN OUT LPDWORD ResumeHandle OPTIONAL
  647. )
  648. {
  649. DWORD i;
  650. NET_API_STATUS status;
  651. DWORD EntriesRead,
  652. TotalEntries;
  653. PUSE_INFO_1 UseInfo, saveptr;
  654. if (ARGUMENT_PRESENT(ResumeHandle)) {
  655. printf("\nInput ResumeHandle=x%08lx\n", *ResumeHandle);
  656. }
  657. status = NetUseEnum(
  658. NULL,
  659. 1,
  660. (LPBYTE *) &UseInfo,
  661. PreferedMaximumLength,
  662. &EntriesRead,
  663. &TotalEntries,
  664. ResumeHandle
  665. );
  666. saveptr = UseInfo;
  667. if (status != NERR_Success && status != ERROR_MORE_DATA) {
  668. printf("NetUseEnum FAILED %lu\n", status);
  669. }
  670. else {
  671. printf("Return code from NetUseEnum %lu\n", status);
  672. printf("EntriesRead=%lu, TotalEntries=%lu\n",
  673. EntriesRead, TotalEntries);
  674. if (ARGUMENT_PRESENT(ResumeHandle)) {
  675. printf("Output ResumeHandle=x%08lx\n", *ResumeHandle);
  676. }
  677. for (i = 0; i < EntriesRead; i++, UseInfo++) {
  678. PrintUseInfo1(UseInfo);
  679. }
  680. //
  681. // Free buffer allocated for us.
  682. //
  683. NetApiBufferFree(saveptr);
  684. }
  685. }
  686. VOID
  687. PrintUseInfo1(
  688. PUSE_INFO_1 UseInfo
  689. )
  690. {
  691. switch(UseInfo->ui1_status) {
  692. case USE_OK:
  693. printf("OK ");
  694. break;
  695. case USE_PAUSED:
  696. printf("Paused ");
  697. break;
  698. case USE_SESSLOST:
  699. printf("Disconnected ");
  700. break;
  701. case USE_NETERR:
  702. printf("Net error ");
  703. break;
  704. case USE_CONN:
  705. printf("Connecting ");
  706. break;
  707. case USE_RECONN:
  708. printf("Reconnecting ");
  709. break;
  710. default:
  711. printf("Unknown ");
  712. }
  713. printf(" %-7" FORMAT_STR "%-25" FORMAT_STR, UseInfo->ui1_local,
  714. UseInfo->ui1_remote);
  715. printf("usecount=%lu, refcount=%lu\n",
  716. UseInfo->ui1_usecount, UseInfo->ui1_refcount);
  717. }
  718. VOID
  719. PrintUseInfo2(
  720. PUSE_INFO_2 UseInfo
  721. )
  722. {
  723. switch(UseInfo->ui2_status) {
  724. case USE_OK:
  725. printf("OK ");
  726. break;
  727. case USE_PAUSED:
  728. printf("Paused ");
  729. break;
  730. case USE_SESSLOST:
  731. printf("Disconnected ");
  732. break;
  733. case USE_NETERR:
  734. printf("Net error ");
  735. break;
  736. case USE_CONN:
  737. printf("Connecting ");
  738. break;
  739. case USE_RECONN:
  740. printf("Reconnecting ");
  741. break;
  742. default:
  743. printf("Unknown ");
  744. }
  745. printf(" %-7" FORMAT_STR "%-" FORMAT_STR, UseInfo->ui2_local,
  746. UseInfo->ui2_remote);
  747. printf("\n %-25" FORMAT_STR "%-" FORMAT_STR, UseInfo->ui2_username,
  748. UseInfo->ui2_domainname);
  749. printf("\n usecount=%02lu, refcount=%02lu\n",
  750. UseInfo->ui2_usecount, UseInfo->ui2_refcount);
  751. }