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.

2742 lines
70 KiB

  1. /*++
  2. Copyright (c) 1991 Microsoft Corporation
  3. Module Name:
  4. mprtest.cxx
  5. Abstract:
  6. Test routine for MPR entry Points.
  7. Author:
  8. Dan Lafferty (danl) 17-Dec-1991
  9. Environment:
  10. User Mode -Win32
  11. Revision History:
  12. 17-Dec-1991 danl
  13. created
  14. --*/
  15. #include "precomp.hxx"
  16. extern "C" {
  17. #include <ntmsv1_0.h>
  18. }
  19. #include <stdlib.h> // atoi
  20. #include <stdio.h> // printf
  21. #include <conio.h> // getch
  22. #include <string.h> // strcmp
  23. #include <tstr.h> // Unicode
  24. #include <debugfmt.h> // FORMAT_LPTSTR
  25. //
  26. // Defines
  27. //
  28. #define ERR_BUF_SIZE 260
  29. #define NAME_BUF_SIZE 260
  30. //
  31. // Local Functions
  32. //
  33. BOOL
  34. ProcessArgs(
  35. DWORD argc,
  36. LPTSTR argv[]
  37. );
  38. VOID
  39. RecursiveEnum(
  40. DWORD RecursionLevel,
  41. DWORD ResourceUsage,
  42. LPNETRESOURCE EnumNetResource
  43. );
  44. BOOL
  45. ConvertToUnicode(
  46. OUT LPWSTR *UnicodeOut,
  47. IN LPSTR AnsiIn
  48. );
  49. BOOL
  50. GetStringFromFile(
  51. LPDWORD LoopCount,
  52. LPSTR buffer
  53. );
  54. BOOL
  55. MakeArgsUnicode (
  56. DWORD argc,
  57. PCHAR argv[]
  58. );
  59. VOID
  60. TestAddConnect2(
  61. LPTSTR RemoteName,
  62. LPTSTR RedirName);
  63. VOID
  64. TestAddConnect3(
  65. LPTSTR RemoteName,
  66. LPTSTR RedirName);
  67. VOID
  68. TestGetConnect(
  69. LPTSTR lpDeviceName,
  70. DWORD bufferSize);
  71. VOID
  72. TestGetUniversal(
  73. LPTSTR lpDeviceName,
  74. DWORD level,
  75. DWORD bufferSize);
  76. VOID
  77. TestGetUser(
  78. LPTSTR lpDevice,
  79. DWORD bufferSize);
  80. VOID
  81. TestEnumConnect(
  82. DWORD scope,
  83. DWORD type);
  84. VOID
  85. TestEnumNet(VOID);
  86. VOID
  87. TestSetError(VOID);
  88. VOID
  89. TestMultiError(VOID);
  90. VOID
  91. TestDirStuff(VOID);
  92. VOID
  93. TestRestoreConnect(
  94. LPTSTR lpDrive);
  95. VOID
  96. TestLotsOfStuff(VOID);
  97. VOID
  98. DisplayExtendedError(VOID);
  99. VOID
  100. DisplayMultiError(VOID);
  101. VOID
  102. DisplayResourceArray(
  103. LPNETRESOURCE NetResource,
  104. DWORD NumElements
  105. );
  106. VOID
  107. DisplayResource(
  108. LPNETRESOURCE NetResource
  109. );
  110. VOID
  111. TestClearConnect(
  112. VOID
  113. );
  114. VOID
  115. Usage(VOID);
  116. VOID
  117. InvalidParms(VOID);
  118. LONG
  119. wtol(
  120. IN LPWSTR string
  121. );
  122. VOID
  123. TestLogonNotify(
  124. LPTSTR argv[],
  125. DWORD argc
  126. );
  127. VOID
  128. TestChangePassword(
  129. LPTSTR argv[],
  130. DWORD argc
  131. );
  132. VOID __cdecl
  133. main (
  134. VOID
  135. )
  136. /*++
  137. Routine Description:
  138. Allows manual testing of the MPR API.
  139. mprtest
  140. Arguments:
  141. Return Value:
  142. --*/
  143. {
  144. UCHAR i;
  145. DWORD j;
  146. LPTSTR *argv;
  147. CHAR buffer[255];
  148. LPSTR argvA[20];
  149. DWORD argc=0;
  150. BOOL KeepGoing;
  151. DWORD LoopCount = 0;
  152. do {
  153. //
  154. // Get input from the user
  155. //
  156. buffer[0] = 90-2;
  157. if (LoopCount != 0) {
  158. GetStringFromFile(&LoopCount, buffer);
  159. printf("%s\n",buffer+2);
  160. }
  161. else {
  162. printf("\nwaiting for instructions... \n");
  163. cgets(buffer);
  164. }
  165. if (buffer[1] > 0) {
  166. //
  167. // put the string in argv/argc format.
  168. //
  169. buffer[1]+=2; // make this an end offset
  170. argc=0;
  171. for (i=2,j=0; i<buffer[1]; i++,j++) {
  172. argc++;
  173. argvA[j] = &(buffer[i]);
  174. while ((buffer[i] != ' ') && (buffer[i] != '\0')) {
  175. i++;
  176. }
  177. buffer[i] = '\0';
  178. }
  179. //
  180. // Make the arguments unicode if necessary.
  181. //
  182. #ifdef UNICODE
  183. if (!MakeArgsUnicode(argc, argvA)) {
  184. return;
  185. }
  186. #endif
  187. argv = (LPTSTR *)argvA;
  188. if (STRICMP (argv[0], TEXT("Loop")) == 0) {
  189. if (argc == 1) {
  190. LoopCount=1;
  191. }
  192. else {
  193. #ifdef UNICODE
  194. LoopCount = wtol(argv[1]);
  195. #else
  196. LoopCount = atol(argv[1]);
  197. #endif
  198. }
  199. KeepGoing = TRUE;
  200. }
  201. else if (STRICMP (argv[0], TEXT("done")) == 0) {
  202. LoopCount=0;
  203. KeepGoing = TRUE;
  204. }
  205. else {
  206. KeepGoing = ProcessArgs(argc, argv);
  207. }
  208. #ifdef UNICODE
  209. //
  210. // Free up the unicode strings if there are any
  211. //
  212. for(j=0; j<argc; j++) {
  213. LocalFree(argv[j]);
  214. }
  215. #endif
  216. }
  217. } while (KeepGoing);
  218. return;
  219. }
  220. BOOL
  221. ProcessArgs(
  222. DWORD argc,
  223. LPTSTR argv[]
  224. )
  225. /*++
  226. Routine Description:
  227. Arguments:
  228. Return Value:
  229. --*/
  230. {
  231. DWORD status;
  232. LPTSTR remoteName;
  233. LPTSTR redirName;
  234. DWORD i;
  235. DWORD type;
  236. //
  237. // Check Arguments
  238. //
  239. if (*argv[0] == TEXT('\0')) {
  240. printf("ERROR: no function was requested!\n");
  241. Usage();
  242. return(TRUE);
  243. }
  244. //
  245. // Make the arguments unicode if necessary.
  246. //
  247. //**************
  248. // AddConnect1
  249. //**************
  250. if (STRICMP (argv[0], TEXT("AddConnect1")) == 0) {
  251. //
  252. // If the connection information was passed in, use it. Otherwise,
  253. // use the default.
  254. //
  255. if (argc == 3) {
  256. remoteName = argv[2];
  257. redirName = argv[1];
  258. }
  259. else {
  260. remoteName = TEXT("\\\\popcorn\\public");
  261. redirName = TEXT("f:");
  262. }
  263. //
  264. // Add the Connection.
  265. //
  266. status = WNetAddConnection(
  267. remoteName,
  268. NULL,
  269. redirName);
  270. if ( status != WN_SUCCESS) {
  271. printf("WNetAddConnection failed %d\n",status);
  272. //
  273. // If there is an extended error, display it.
  274. //
  275. if (status == WN_EXTENDED_ERROR) {
  276. DisplayExtendedError();
  277. }
  278. }
  279. else {
  280. printf("WNetAddConnection Success\n");
  281. }
  282. }
  283. //**************
  284. // AddConnect2
  285. //**************
  286. else if (STRICMP (argv[0], TEXT("AddConnect2")) == 0) {
  287. //
  288. // If the connection information was passed in, use it. Otherwise,
  289. // use the default.
  290. //
  291. if (argc == 3) {
  292. remoteName = argv[2];
  293. redirName = argv[1];
  294. }
  295. else {
  296. remoteName = TEXT("\\\\popcorn\\public");
  297. redirName = TEXT("f:");
  298. }
  299. //
  300. // Call the test program
  301. //
  302. TestAddConnect2(remoteName, redirName);
  303. printf("Call it again without a redirected drive letter\n");
  304. TestAddConnect2(remoteName, NULL);
  305. }
  306. //**************
  307. // AddConnect3
  308. //**************
  309. else if (STRICMP (argv[0], TEXT("AddConnect3")) == 0) {
  310. //
  311. // If the connection information was passed in, use it. Otherwise,
  312. // use the default.
  313. //
  314. if (argc == 3) {
  315. remoteName = argv[2];
  316. redirName = argv[1];
  317. }
  318. else {
  319. remoteName = TEXT("\\\\popcorn\\public");
  320. redirName = TEXT("f:");
  321. }
  322. //
  323. // Call the test program
  324. //
  325. TestAddConnect3(remoteName, redirName);
  326. printf("Call it again without a redirected drive letter\n");
  327. TestAddConnect3(remoteName, NULL);
  328. }
  329. //**************
  330. // CancelConnect
  331. //**************
  332. else if (STRICMP (argv[0], TEXT("CancelConnect")) == 0) {
  333. BOOL rememberFlag = FALSE;
  334. BOOL ForceFlag = FALSE;
  335. //
  336. // See if the redirected name was passed in.
  337. //
  338. if (argc >= 2) {
  339. redirName = argv[1];
  340. }
  341. else {
  342. redirName = TEXT("f:");
  343. }
  344. for (i=2; argc>i; i++) {
  345. if (STRICMP (argv[i], TEXT("r")) ==0) {
  346. rememberFlag = TRUE;
  347. }
  348. if (STRICMP (argv[i], TEXT("f")) ==0) {
  349. ForceFlag = TRUE;
  350. }
  351. }
  352. if (rememberFlag) {
  353. status = WNetCancelConnection(redirName, ForceFlag);
  354. }
  355. else {
  356. status = WNetCancelConnection2(redirName, 0, ForceFlag);
  357. }
  358. if ( status != WN_SUCCESS) {
  359. printf("WNetCancelConnection failed %d\n",status);
  360. //
  361. // If there is an extended error, display it.
  362. //
  363. if (status == WN_EXTENDED_ERROR) {
  364. DisplayExtendedError();
  365. }
  366. }
  367. else {
  368. printf("WNetCancelConnection Success\n");
  369. }
  370. }
  371. //**************
  372. // GetConnect
  373. //**************
  374. else if (STRICMP (argv[0], TEXT("GetConnect")) == 0) {
  375. LPTSTR deviceName = NULL;
  376. DWORD bufSize = NAME_BUF_SIZE;
  377. if (argc >= 2) {
  378. deviceName = argv[1];
  379. }
  380. if (argc >= 3) {
  381. bufSize = ATOL(argv[2]);
  382. }
  383. TestGetConnect( deviceName, bufSize);
  384. }
  385. //******************
  386. // GetUniversalName
  387. //******************
  388. else if (STRICMP (argv[0], TEXT("GetUniversalName")) == 0) {
  389. LPTSTR deviceName = NULL;
  390. DWORD bufSize = NAME_BUF_SIZE;
  391. DWORD infoLevel = UNIVERSAL_NAME_INFO_LEVEL;
  392. if (argc >= 2) {
  393. deviceName = argv[1];
  394. }
  395. if (argc >= 3) {
  396. infoLevel = ATOL(argv[2]);
  397. }
  398. if (argc >= 4) {
  399. bufSize = ATOL(argv[3]);
  400. }
  401. TestGetUniversal( deviceName, infoLevel, bufSize);
  402. }
  403. //**************
  404. // GetUser
  405. //**************
  406. else if (STRICMP (argv[0], TEXT("GetUser")) == 0) {
  407. LPTSTR deviceName = NULL;
  408. DWORD bufSize = NAME_BUF_SIZE;
  409. i=1;
  410. while (argc > (i)) {
  411. if (STRICMP(argv[i], TEXT("bufSize=")) == 0) {
  412. bufSize = ATOL(argv[i+1]);
  413. i++;
  414. }
  415. if (STRICMP(argv[i], TEXT("device=")) == 0) {
  416. deviceName = argv[i+1];
  417. i++;
  418. }
  419. i++;
  420. }
  421. TestGetUser(deviceName,bufSize);
  422. }
  423. //**************
  424. // Enum
  425. //**************
  426. else if (STRICMP (argv[0], TEXT("EnumConnect")) == 0 ||
  427. STRICMP (argv[0], TEXT("EnumContext")) == 0) {
  428. DWORD scope = STRICMP (argv[0], TEXT("EnumConnect")) ?
  429. RESOURCE_CONTEXT : RESOURCE_CONNECTED;
  430. type = RESOURCETYPE_ANY;
  431. for (i=1; i<argc; i++) {
  432. if (STRICMP(argv[i], TEXT("r")) == 0) {
  433. scope = RESOURCE_REMEMBERED;
  434. }
  435. else if (STRICMP(argv[i], TEXT("ANY")) == 0) {
  436. type = RESOURCETYPE_ANY;
  437. }
  438. else if (STRICMP(argv[i], TEXT("DISK")) == 0) {
  439. type = RESOURCETYPE_DISK;
  440. }
  441. else if (STRICMP(argv[i], TEXT("PRINT")) == 0) {
  442. type = RESOURCETYPE_PRINT;
  443. }
  444. else {
  445. printf("Bad argument\n");
  446. Usage();
  447. return(TRUE);
  448. }
  449. }
  450. TestEnumConnect(scope, type);
  451. }
  452. else if (STRICMP (argv[0], TEXT("EnumNet")) == 0) {
  453. RecursiveEnum(0, 0, NULL);
  454. //TestEnumNet();
  455. }
  456. //**************
  457. // SetLastError
  458. //**************
  459. else if (STRICMP (argv[0], TEXT("SetError")) == 0) {
  460. TestSetError();
  461. }
  462. //*********************
  463. // MultinetGetErrorText
  464. //*********************
  465. else if (STRICMP (argv[0], TEXT("MultiError")) == 0) {
  466. TestMultiError();
  467. }
  468. //************************************
  469. // GetDirectoryType & DirectoryNotify
  470. //************************************
  471. else if (STRICMP (argv[0], TEXT("DirApi")) == 0) {
  472. TestDirStuff();
  473. }
  474. //****************
  475. // RestoreConnect
  476. //****************
  477. else if (STRICMP (argv[0], TEXT("RestoreConnect")) == 0) {
  478. if (argc == 2) {
  479. TestRestoreConnect(argv[1]);
  480. }
  481. else {
  482. TestRestoreConnect(NULL);
  483. }
  484. }
  485. //****************
  486. // ClearConnect
  487. //****************
  488. else if (STRICMP (argv[0], TEXT("ClearConnect")) == 0) {
  489. TestClearConnect();
  490. }
  491. //****************
  492. // LogonNotify
  493. //****************
  494. else if (STRICMP (argv[0], TEXT("LogonNotify")) == 0) {
  495. TestLogonNotify(&argv[1],argc-1);
  496. }
  497. //****************
  498. // LogonNotify
  499. //****************
  500. else if (STRICMP (argv[0], TEXT("ChangePassword")) == 0) {
  501. TestChangePassword(&argv[1],argc-1);
  502. }
  503. //************************************
  504. // ALL
  505. //************************************
  506. else if (STRICMP (argv[0], TEXT("all")) == 0) {
  507. TestLotsOfStuff();
  508. }
  509. //****************
  510. // InvalidParms
  511. //****************
  512. else if (STRICMP (argv[0], TEXT("InvalidParms")) == 0) {
  513. InvalidParms();
  514. }
  515. //****************
  516. // Exit Program
  517. //****************
  518. else if (STRICMP (argv[0], TEXT("Exit")) == 0) {
  519. return(FALSE);
  520. }
  521. else {
  522. printf("Bad argument\n");
  523. Usage();
  524. }
  525. return(TRUE);
  526. }
  527. VOID
  528. TestAddConnect2(
  529. LPTSTR RemoteName,
  530. LPTSTR RedirName)
  531. {
  532. LPNETRESOURCE netResource;
  533. DWORD status;
  534. DWORD numchars = 0;
  535. netResource = (LPNETRESOURCE) LocalAlloc(LPTR, sizeof(NETRESOURCE));
  536. if (netResource == NULL) {
  537. printf("TestAddConnect2:LocalAlloc Failed %d\n",GetLastError);
  538. return;
  539. }
  540. netResource->lpRemoteName = RemoteName;
  541. netResource->lpLocalName = RedirName;
  542. if (RedirName != NULL) {
  543. numchars = STRLEN(RedirName);
  544. }
  545. if (numchars == 0) {
  546. netResource->dwType = RESOURCETYPE_ANY;
  547. }
  548. else if (numchars > 2) {
  549. netResource->dwType = RESOURCETYPE_PRINT;
  550. }
  551. else {
  552. netResource->dwType = RESOURCETYPE_DISK;
  553. }
  554. status = WNetAddConnection2(
  555. netResource,
  556. NULL,
  557. NULL,
  558. 0L);
  559. if ( status != WN_SUCCESS) {
  560. printf("WNetAddConnection2 failed %d\n",status);
  561. //
  562. // If there is an extended error, display it.
  563. //
  564. if (status == WN_EXTENDED_ERROR) {
  565. DisplayExtendedError();
  566. }
  567. }
  568. else {
  569. printf("WNetAddConnection2 Success\n");
  570. }
  571. LocalFree(netResource);
  572. return;
  573. }
  574. VOID
  575. TestAddConnect3(
  576. LPTSTR RemoteName,
  577. LPTSTR RedirName)
  578. {
  579. LPNETRESOURCE netResource;
  580. DWORD status;
  581. DWORD numchars = 0;
  582. netResource = (LPNETRESOURCE) LocalAlloc(LPTR, sizeof(NETRESOURCE));
  583. if (netResource == NULL) {
  584. printf("TestAddConnect3:LocalAlloc Failed %d\n",GetLastError);
  585. return;
  586. }
  587. netResource->lpRemoteName = RemoteName;
  588. netResource->lpLocalName = RedirName;
  589. if (RedirName != NULL) {
  590. numchars = STRLEN(RedirName);
  591. }
  592. if (numchars == 0) {
  593. netResource->dwType = RESOURCETYPE_ANY;
  594. }
  595. else if (numchars > 2) {
  596. netResource->dwType = RESOURCETYPE_PRINT;
  597. }
  598. else {
  599. netResource->dwType = RESOURCETYPE_DISK;
  600. }
  601. status = WNetAddConnection3(
  602. (HWND)0x33113322,
  603. netResource,
  604. NULL,
  605. NULL,
  606. 0L);
  607. if ( status != WN_SUCCESS) {
  608. printf("WNetAddConnection3 failed %d\n",status);
  609. //
  610. // If there is an extended error, display it.
  611. //
  612. if (status == WN_EXTENDED_ERROR) {
  613. DisplayExtendedError();
  614. }
  615. }
  616. else {
  617. printf("WNetAddConnection3 Success\n");
  618. }
  619. LocalFree(netResource);
  620. return;
  621. }
  622. VOID
  623. TestGetConnect(
  624. LPTSTR lpDeviceName,
  625. DWORD bufferSize)
  626. {
  627. LPTSTR remoteName = NULL;
  628. DWORD status;
  629. TCHAR defaultDevice[]=TEXT("f:");
  630. LPTSTR lpDevice;
  631. if (lpDeviceName == NULL) {
  632. lpDevice = defaultDevice;
  633. }
  634. else {
  635. lpDevice = lpDeviceName;
  636. }
  637. remoteName = (LPTSTR)LocalAlloc(LMEM_FIXED, bufferSize);
  638. if (remoteName == NULL) {
  639. printf("TestGetConnect: Couldn't allocate memory\n");
  640. return;
  641. }
  642. //
  643. // 1st Time
  644. //
  645. status = WNetGetConnection(
  646. lpDevice,
  647. remoteName,
  648. &bufferSize);
  649. if (( status != WN_SUCCESS) && (status != ERROR_CONNECTION_UNAVAIL)) {
  650. printf("WNetGetConnection failed %d\n",status);
  651. //
  652. // If there is an extended error, display it.
  653. //
  654. if (status == WN_EXTENDED_ERROR) {
  655. DisplayExtendedError();
  656. }
  657. //
  658. // If insufficient buffer, display needed size.
  659. //
  660. if (status == WN_MORE_DATA) {
  661. printf("Insufficient buffer size. Need %d bytes\n",bufferSize);
  662. }
  663. }
  664. else {
  665. if (status == ERROR_CONNECTION_UNAVAIL) {
  666. printf("Not Currently Connected, but it is remembered\n");
  667. }
  668. else {
  669. printf("WNetGetConnection Success\n");
  670. }
  671. printf(""FORMAT_LPTSTR" is connected to "FORMAT_LPTSTR"\n",lpDevice,remoteName);
  672. }
  673. //
  674. // 2nd Time
  675. //
  676. if (remoteName != NULL) {
  677. LocalFree(remoteName);
  678. }
  679. printf("Allocating a new buffer of %d bytes\n",bufferSize);
  680. remoteName = (LPTSTR)LocalAlloc(LMEM_FIXED, bufferSize);
  681. if (remoteName == NULL) {
  682. printf("TestGetConnect: Couldn't allocate memory(2nd time)\n");
  683. return;
  684. }
  685. status = WNetGetConnection(
  686. lpDevice,
  687. remoteName,
  688. &bufferSize);
  689. if (( status != WN_SUCCESS) && (status != ERROR_CONNECTION_UNAVAIL)) {
  690. printf("WNetGetConnection failed %d\n",status);
  691. //
  692. // If there is an extended error, display it.
  693. //
  694. if (status == WN_EXTENDED_ERROR) {
  695. DisplayExtendedError();
  696. }
  697. //
  698. // If insufficient buffer, display needed size.
  699. //
  700. if (status == WN_MORE_DATA) {
  701. printf("Insufficient buffer size. Need %d bytes\n",bufferSize);
  702. }
  703. }
  704. else {
  705. if (status == ERROR_CONNECTION_UNAVAIL) {
  706. printf("Not Currently Connected, but it is remembered\n");
  707. }
  708. else {
  709. printf("WNetGetConnection Success\n");
  710. }
  711. printf(""FORMAT_LPTSTR" is connected to "FORMAT_LPTSTR"\n",lpDevice,remoteName);
  712. }
  713. if (remoteName != NULL) {
  714. LocalFree(remoteName);
  715. }
  716. return;
  717. }
  718. VOID
  719. TestGetUniversal(
  720. LPTSTR lpDeviceName,
  721. DWORD level,
  722. DWORD bufferSize)
  723. {
  724. LPBYTE buffer = NULL;
  725. DWORD status;
  726. TCHAR defaultDevice[]=TEXT("");
  727. LPTSTR lpDevice;
  728. LPTSTR pNothing = TEXT("<nothing>");
  729. LPUNIVERSAL_NAME_INFO pUniversalInfo = NULL;
  730. LPREMOTE_NAME_INFO pRemoteInfo = NULL;
  731. if (lpDeviceName == NULL) {
  732. lpDevice = defaultDevice;
  733. }
  734. else {
  735. lpDevice = lpDeviceName;
  736. }
  737. buffer = (LPBYTE)LocalAlloc(LMEM_FIXED, bufferSize);
  738. if (buffer == NULL) {
  739. printf("TestGetConnect: Couldn't allocate memory\n");
  740. return;
  741. }
  742. //----------------
  743. // 1st Time
  744. //----------------
  745. status = WNetGetUniversalName(
  746. lpDevice,
  747. level,
  748. buffer,
  749. &bufferSize);
  750. if (( status != WN_SUCCESS) && (status != ERROR_CONNECTION_UNAVAIL)) {
  751. printf("WNetGetUniversalName failed %d\n",status);
  752. //
  753. // If there is an extended error, display it.
  754. //
  755. if (status == WN_EXTENDED_ERROR) {
  756. DisplayExtendedError();
  757. }
  758. //
  759. // If insufficient buffer, display needed size.
  760. //
  761. if (status == WN_MORE_DATA) {
  762. printf("Insufficient buffer size. Need %d bytes\n",bufferSize);
  763. }
  764. }
  765. else {
  766. if (status == ERROR_CONNECTION_UNAVAIL) {
  767. printf("Not Currently Connected, but it is remembered\n");
  768. }
  769. else {
  770. printf("WNetGetUniversalName Success\n");
  771. }
  772. switch (level) {
  773. case UNIVERSAL_NAME_INFO_LEVEL:
  774. pUniversalInfo = (LPUNIVERSAL_NAME_INFO)buffer;
  775. printf(""FORMAT_LPTSTR" is connected to "FORMAT_LPTSTR"\n",
  776. lpDevice,pUniversalInfo->lpUniversalName);
  777. break;
  778. case REMOTE_NAME_INFO_LEVEL:
  779. pRemoteInfo = (LPREMOTE_NAME_INFO)buffer;
  780. if (pRemoteInfo->lpUniversalName == NULL) {
  781. pRemoteInfo->lpUniversalName = pNothing;
  782. }
  783. printf(""FORMAT_LPTSTR" is connected to: \n"
  784. " UniversalName = "FORMAT_LPTSTR"\n"
  785. " ConnectionName = "FORMAT_LPTSTR"\n"
  786. " RemainingPath = "FORMAT_LPTSTR"\n\n",
  787. lpDevice,
  788. pRemoteInfo->lpUniversalName,
  789. pRemoteInfo->lpConnectionName,
  790. pRemoteInfo->lpRemainingPath);
  791. break;
  792. default:
  793. printf("PROBLEM: Invalid Level didn't produce an error\n");
  794. }
  795. }
  796. //---------------
  797. // 2nd Time
  798. //---------------
  799. if (buffer != NULL) {
  800. LocalFree(buffer);
  801. }
  802. printf("Allocating a new buffer of %d bytes\n",bufferSize);
  803. buffer = (LPBYTE)LocalAlloc(LMEM_FIXED, bufferSize);
  804. if (buffer == NULL) {
  805. printf("TestGetConnect: Couldn't allocate memory(2nd time)\n");
  806. return;
  807. }
  808. status = WNetGetUniversalName(
  809. lpDevice,
  810. level,
  811. buffer,
  812. &bufferSize);
  813. if (( status != WN_SUCCESS) && (status != ERROR_CONNECTION_UNAVAIL)) {
  814. printf("WNetGetUniversalName failed %d\n",status);
  815. //
  816. // If there is an extended error, display it.
  817. //
  818. if (status == WN_EXTENDED_ERROR) {
  819. DisplayExtendedError();
  820. }
  821. //
  822. // If insufficient buffer, display needed size.
  823. //
  824. if (status == WN_MORE_DATA) {
  825. printf("Insufficient buffer size. Need %d bytes\n",bufferSize);
  826. }
  827. }
  828. else {
  829. if (status == ERROR_CONNECTION_UNAVAIL) {
  830. printf("Not Currently Connected, but it is remembered\n");
  831. }
  832. else {
  833. printf("WNetGetUniversalName Success\n");
  834. }
  835. switch (level) {
  836. case UNIVERSAL_NAME_INFO_LEVEL:
  837. pUniversalInfo = (LPUNIVERSAL_NAME_INFO)buffer;
  838. printf(""FORMAT_LPTSTR" is connected to "FORMAT_LPTSTR"\n",
  839. lpDevice,pUniversalInfo->lpUniversalName);
  840. break;
  841. case REMOTE_NAME_INFO_LEVEL:
  842. pRemoteInfo = (LPREMOTE_NAME_INFO)buffer;
  843. if (pRemoteInfo->lpUniversalName == NULL) {
  844. pRemoteInfo->lpUniversalName = pNothing;
  845. }
  846. printf(""FORMAT_LPTSTR" is connected to: \n"
  847. " UniversalName = "FORMAT_LPTSTR"\n"
  848. " ConnectionName = "FORMAT_LPTSTR"\n"
  849. " RemainingPath = "FORMAT_LPTSTR"\n\n",
  850. lpDevice,
  851. pRemoteInfo->lpUniversalName,
  852. pRemoteInfo->lpConnectionName,
  853. pRemoteInfo->lpRemainingPath);
  854. break;
  855. default:
  856. printf("PROBLEM: Invalid Level didn't produce an error\n");
  857. }
  858. }
  859. if (buffer != NULL) {
  860. LocalFree(buffer);
  861. }
  862. return;
  863. }
  864. VOID
  865. TestGetUser(
  866. LPTSTR lpDevice,
  867. DWORD cBuffer)
  868. {
  869. DWORD status;
  870. LPTSTR userName = NULL;
  871. DWORD saveBufSize;
  872. userName = (LPTSTR)LocalAlloc(LMEM_FIXED, cBuffer);
  873. if (userName == NULL) {
  874. printf("TestGetUser: Couldn't allocate memory\n");
  875. return;
  876. }
  877. saveBufSize = cBuffer;
  878. //
  879. // Get the currently logged on user
  880. //
  881. status = WNetGetUser (NULL, userName, &cBuffer);
  882. if ( status != WN_SUCCESS) {
  883. printf("WNetGetUser failed %d\n",status);
  884. //
  885. // If there is an extended error, display it.
  886. //
  887. if (status == WN_EXTENDED_ERROR) {
  888. DisplayExtendedError();
  889. }
  890. //
  891. // If insufficient buffer, display needed size.
  892. //
  893. if (status == WN_MORE_DATA) {
  894. printf("Insufficient buffer size. Need %d bytes\n",cBuffer);
  895. }
  896. }
  897. else {
  898. printf("WNetGetUser Success\n");
  899. printf("CurrentUser = "FORMAT_LPTSTR"\n", userName);
  900. }
  901. //
  902. // If there is a local device given, get the user for that.
  903. //
  904. if (lpDevice != NULL){
  905. cBuffer = saveBufSize;
  906. status = WNetGetUser (lpDevice, userName, &cBuffer);
  907. if ( status != WN_SUCCESS) {
  908. printf("WNetGetUser failed %d\n",status);
  909. //
  910. // If there is an extended error, display it.
  911. //
  912. if (status == WN_EXTENDED_ERROR) {
  913. DisplayExtendedError();
  914. }
  915. //
  916. // If insufficient buffer, display needed size.
  917. //
  918. if (status == WN_MORE_DATA) {
  919. printf("Insufficient buffer size. Need %d bytes\n",cBuffer);
  920. }
  921. }
  922. else {
  923. printf("WNetGetUser Success\n");
  924. printf("User for "FORMAT_LPTSTR" is "FORMAT_LPTSTR"\n", lpDevice, userName);
  925. }
  926. }
  927. if (userName != NULL) {
  928. LocalFree(userName);
  929. }
  930. return;
  931. }
  932. VOID
  933. TestEnumConnect(
  934. DWORD dwScope,
  935. DWORD type)
  936. {
  937. DWORD status;
  938. HANDLE enumHandle;
  939. LPNETRESOURCE netResource;
  940. DWORD numElements;
  941. DWORD bufferSize;
  942. //
  943. // Attempt to allow for 10 connections
  944. //
  945. bufferSize = (10*sizeof(NETRESOURCE))+1024;
  946. netResource = (LPNETRESOURCE) LocalAlloc(LPTR, bufferSize);
  947. if (netResource == NULL) {
  948. printf("TestEnum:LocalAlloc Failed %d\n",GetLastError);
  949. return;
  950. }
  951. //-----------------------------------
  952. // Get a handle for a top level enum
  953. //-----------------------------------
  954. status = WNetOpenEnum(
  955. dwScope,
  956. type,
  957. 0,
  958. NULL,
  959. &enumHandle);
  960. if ( status != WN_SUCCESS) {
  961. printf("WNetOpenEnum failed %d\n",status);
  962. //
  963. // If there is an extended error, display it.
  964. //
  965. if (status == WN_EXTENDED_ERROR) {
  966. DisplayExtendedError();
  967. }
  968. goto CleanExit;
  969. }
  970. else {
  971. printf("WNetOpenEnum Success\n");
  972. }
  973. //-----------------------------------
  974. // Enumerate the resources
  975. //-----------------------------------
  976. do
  977. {
  978. numElements = 0xffffffff;
  979. status = WNetEnumResource(
  980. enumHandle,
  981. &numElements,
  982. netResource,
  983. &bufferSize);
  984. if ( status == WN_SUCCESS )
  985. {
  986. CHAR response;
  987. printf("WNetEnumResource Success - resources follow\n");
  988. DisplayResourceArray(netResource, numElements);
  989. printf("Get more resources? ");
  990. response = getch();
  991. response = toupper(response);
  992. if (response == 'N')
  993. {
  994. break;
  995. }
  996. printf("\r");
  997. }
  998. else if ( status == WN_NO_MORE_ENTRIES)
  999. {
  1000. printf("WNetEnumResource Success - no more resources to display\n");
  1001. }
  1002. else
  1003. {
  1004. printf("WNetEnumResource failed %d\n",status);
  1005. //
  1006. // If there is an extended error, display it.
  1007. //
  1008. if (status == WN_EXTENDED_ERROR)
  1009. {
  1010. DisplayExtendedError();
  1011. }
  1012. }
  1013. } while ( status == WN_SUCCESS );
  1014. //------------------------------------------
  1015. // Close the EnumHandle & print the results
  1016. //------------------------------------------
  1017. status = WNetCloseEnum(enumHandle);
  1018. if (status != WN_SUCCESS) {
  1019. printf("WNetCloseEnum failed %d\n",status);
  1020. //
  1021. // If there is an extended error, display it.
  1022. //
  1023. if (status == WN_EXTENDED_ERROR) {
  1024. DisplayExtendedError();
  1025. }
  1026. goto CleanExit;
  1027. }
  1028. CleanExit:
  1029. LocalFree(netResource);
  1030. return;
  1031. }
  1032. VOID
  1033. TestEnumNet(VOID)
  1034. {
  1035. DWORD status;
  1036. HANDLE enumHandle;
  1037. LPNETRESOURCE netResource;
  1038. DWORD numElements;
  1039. DWORD bufferSize;
  1040. DWORD saveBufSize;
  1041. DWORD i;
  1042. DWORD numProviders=5;
  1043. HANDLE providerArray[5];
  1044. //
  1045. // Attempt to allow for 10 resource structures
  1046. //
  1047. saveBufSize = bufferSize = (10*sizeof(NETRESOURCE))+1024;
  1048. netResource = (LPNETRESOURCE) LocalAlloc(LPTR, bufferSize);
  1049. if (netResource == NULL) {
  1050. printf("TestEnum:LocalAlloc Failed %d\n",GetLastError);
  1051. return;
  1052. }
  1053. //-----------------------------------
  1054. // Get a handle for a top level enum
  1055. //-----------------------------------
  1056. status = WNetOpenEnum(
  1057. RESOURCE_GLOBALNET,
  1058. RESOURCETYPE_ANY,
  1059. 0,
  1060. NULL,
  1061. &enumHandle);
  1062. if ( status != WN_SUCCESS) {
  1063. printf("WNetOpenEnum failed %d\n",status);
  1064. //
  1065. // If there is an extended error, display it.
  1066. //
  1067. if (status == WN_EXTENDED_ERROR) {
  1068. DisplayExtendedError();
  1069. }
  1070. goto CleanExit;
  1071. }
  1072. else {
  1073. printf("WNetOpenEnum Success!\n");
  1074. }
  1075. //-----------------------------------
  1076. // Enumerate the top level
  1077. //-----------------------------------
  1078. numElements = 0xffffffff;
  1079. printf("\n*------------- TOP LEVEL ENUM ------------*\n");
  1080. status = WNetEnumResource(
  1081. enumHandle,
  1082. &numElements,
  1083. netResource,
  1084. &bufferSize);
  1085. if ( status != WN_SUCCESS) {
  1086. printf("WNetEnumResource failed %d\n",status);
  1087. //
  1088. // If there is an extended error, display it.
  1089. //
  1090. if (status == WN_EXTENDED_ERROR) {
  1091. DisplayExtendedError();
  1092. }
  1093. WNetCloseEnum(enumHandle);
  1094. goto CleanExit;
  1095. }
  1096. else {
  1097. //
  1098. // Success! Display the returned array
  1099. // and close the top-level handle.
  1100. //
  1101. printf("WNetEnumResource Success\n");
  1102. DisplayResourceArray(netResource, numElements);
  1103. WNetCloseEnum(enumHandle);
  1104. }
  1105. //-------------------------------------------
  1106. // Open a handle to the next level container
  1107. // *** DOMAINS ***
  1108. //-------------------------------------------
  1109. if (numElements < numProviders) {
  1110. numProviders = numElements;
  1111. }
  1112. for (i=0; i<numProviders; i++ ) {
  1113. status = WNetOpenEnum(
  1114. RESOURCE_GLOBALNET,
  1115. RESOURCETYPE_ANY,
  1116. RESOURCEUSAGE_CONTAINER,
  1117. netResource,
  1118. &enumHandle);
  1119. if ( status != WN_SUCCESS) {
  1120. printf("WNetOpenEnum 2 failed %d\n",status);
  1121. //
  1122. // If there is an extended error, display it.
  1123. //
  1124. if (status == WN_EXTENDED_ERROR) {
  1125. DisplayExtendedError();
  1126. }
  1127. goto CleanExit;
  1128. }
  1129. else {
  1130. printf("WNetOpenEnum 2 Success\n");
  1131. providerArray[i]= enumHandle;
  1132. }
  1133. }
  1134. //-----------------------------------------------------------------
  1135. // Enumerate the next level
  1136. // *** DOMAINS ***
  1137. //
  1138. // providerArray contains handles for
  1139. // all the providers.
  1140. //
  1141. //-----------------------------------------------------------------
  1142. printf("\n*------------- 2nd LEVEL ENUM (Domains) ------------*\n");
  1143. for (i=0; i<numProviders; i++) {
  1144. numElements = 0xffffffff;
  1145. bufferSize = saveBufSize;
  1146. status = WNetEnumResource(
  1147. providerArray[i],
  1148. &numElements,
  1149. netResource,
  1150. &bufferSize);
  1151. if ( status != WN_SUCCESS) {
  1152. printf("WNetEnumResource 2 failed %d\n",status);
  1153. //
  1154. // If there is an extended error, display it.
  1155. //
  1156. if (status == WN_EXTENDED_ERROR) {
  1157. DisplayExtendedError();
  1158. }
  1159. for (i=0; i<numProviders; i++ ) {
  1160. WNetCloseEnum(providerArray[i]);
  1161. }
  1162. goto CleanExit;
  1163. }
  1164. else {
  1165. //
  1166. // Success! Display the returned array
  1167. // and close the handle.
  1168. //
  1169. printf("*** WNetEnumResource 2 Success for provider %D ***\n",i);
  1170. DisplayResourceArray(netResource, numElements);
  1171. WNetCloseEnum(providerArray[i]);
  1172. }
  1173. }
  1174. //-------------------------------------------
  1175. // Open a handle to the next level container
  1176. // *** SERVERS ***
  1177. //-------------------------------------------
  1178. status = WNetOpenEnum(
  1179. RESOURCE_GLOBALNET,
  1180. RESOURCETYPE_ANY,
  1181. RESOURCEUSAGE_CONTAINER,
  1182. netResource,
  1183. &enumHandle);
  1184. if ( status != WN_SUCCESS) {
  1185. printf("WNetOpenEnum 3 failed %d\n",status);
  1186. //
  1187. // If there is an extended error, display it.
  1188. //
  1189. if (status == WN_EXTENDED_ERROR) {
  1190. DisplayExtendedError();
  1191. }
  1192. goto CleanExit;
  1193. }
  1194. else {
  1195. printf("WNetOpenEnum 3 Success\n");
  1196. }
  1197. //-----------------------------------
  1198. // Enumerate the next level
  1199. // *** SERVERS ***
  1200. //-----------------------------------
  1201. numElements = 0xffffffff;
  1202. printf("\n*------------- 3rd LEVEL ENUM (Servers) ------------*\n");
  1203. status = WNetEnumResource(
  1204. enumHandle,
  1205. &numElements,
  1206. netResource,
  1207. &bufferSize);
  1208. if ( status == WN_NO_MORE_ENTRIES) {
  1209. //
  1210. // Success! Display the returned array
  1211. // and close the handle.
  1212. //
  1213. printf("WNetEnumResource 3 Success - no more data to display\n");
  1214. }
  1215. else if (status == WN_SUCCESS) {
  1216. if (numElements != 0) {
  1217. printf("WNetEnumResource 3 Success - but MORE DATA\n");
  1218. DisplayResourceArray(netResource, numElements);
  1219. }
  1220. else
  1221. {
  1222. printf("WNetEnumResource 3 Success, and MORE DATA indicated --"
  1223. " but no data returned??\n");
  1224. }
  1225. }
  1226. else {
  1227. printf("WNetEnumResource 3 failed %d\n",status);
  1228. //
  1229. // If there is an extended error, display it.
  1230. //
  1231. if (status == WN_EXTENDED_ERROR) {
  1232. DisplayExtendedError();
  1233. }
  1234. }
  1235. WNetCloseEnum(enumHandle);
  1236. CleanExit:
  1237. LocalFree(netResource);
  1238. return;
  1239. }
  1240. VOID
  1241. TestSetError(VOID)
  1242. {
  1243. //
  1244. // Store and Get the 1st Error
  1245. //
  1246. printf("Setting Error WN_BAD_NETNAME. Code = %d\n", WN_BAD_NETNAME);
  1247. WNetSetLastError( WN_BAD_NETNAME, TEXT("WN_BAD_NETNAME"), TEXT("Dan's Provider"));
  1248. DisplayExtendedError();
  1249. //
  1250. // Store and Get the 2nd Error
  1251. //
  1252. printf("Setting Error WN_NO_NETWORK. Code = %d\n", WN_NO_NETWORK);
  1253. WNetSetLastError( WN_NO_NETWORK, TEXT("WN_NO_NETWORK"), TEXT("Dan's Provider"));
  1254. DisplayExtendedError();
  1255. return;
  1256. }
  1257. VOID
  1258. TestMultiError(VOID)
  1259. {
  1260. //
  1261. // Store and Get the 1st Error
  1262. //
  1263. printf("Setting Error WN_BAD_NETNAME. Code = %d\n", WN_BAD_NETNAME);
  1264. WNetSetLastError( WN_BAD_NETNAME, TEXT("WN_BAD_NETNAME"), TEXT("Dan's Provider"));
  1265. DisplayMultiError();
  1266. //
  1267. // Store and Get the 2nd Error
  1268. //
  1269. printf("Setting Error WN_NO_NETWORK. Code = %d\n", WN_NO_NETWORK);
  1270. WNetSetLastError( WN_NO_NETWORK, TEXT("WN_NO_NETWORK"), TEXT("Dan's Provider"));
  1271. DisplayMultiError();
  1272. //
  1273. // Store and Get a non-WNet Error, with no text or provider
  1274. //
  1275. printf("Setting Error ERROR_SHARING_VIOLATION, no text or provider. Code = %d\n", ERROR_SHARING_VIOLATION);
  1276. WNetSetLastError( ERROR_SHARING_VIOLATION, NULL, NULL);
  1277. DisplayMultiError();
  1278. //
  1279. // Store and Get an unknown Error, with no text
  1280. //
  1281. printf("Setting arbitrary error with no text. Code = %d\n", 654321);
  1282. WNetSetLastError( 654321, NULL, TEXT("Dan's Provider"));
  1283. DisplayMultiError();
  1284. return;
  1285. }
  1286. VOID
  1287. TestDirStuff(VOID)
  1288. {
  1289. DWORD status;
  1290. INT type;
  1291. //
  1292. // Test GetDirectoryType
  1293. //
  1294. status = WNetGetDirectoryType((LPTSTR)TEXT("f:\\"), (LPINT)&type, TRUE);
  1295. if ( status != WN_SUCCESS) {
  1296. printf("WNetGetDirectoryType failed %d\n",status);
  1297. //
  1298. // If there is an extended error, display it.
  1299. //
  1300. if (status == WN_EXTENDED_ERROR) {
  1301. DisplayExtendedError();
  1302. }
  1303. }
  1304. else {
  1305. //
  1306. // Success!
  1307. //
  1308. printf("WNetGetDirctoryType Success type = %d \n",type);
  1309. }
  1310. //
  1311. // Test DirectoryNotify
  1312. //
  1313. status = WNetDirectoryNotify(0,TEXT("f:\\"), 2);
  1314. if ( status != WN_SUCCESS) {
  1315. printf("WNetDirectoryNotify failed %d\n",status);
  1316. //
  1317. // If there is an extended error, display it.
  1318. //
  1319. if (status == WN_EXTENDED_ERROR) {
  1320. DisplayExtendedError();
  1321. }
  1322. }
  1323. else {
  1324. //
  1325. // Success!
  1326. //
  1327. printf("WNetDirectoryNotify Success \n");
  1328. }
  1329. return;
  1330. }
  1331. VOID
  1332. TestRestoreConnect(
  1333. LPTSTR lpDrive
  1334. )
  1335. {
  1336. DWORD status;
  1337. #ifdef UNICODE
  1338. status = WNetRestoreConnection(
  1339. (HWND)0,
  1340. lpDrive);
  1341. #else
  1342. status = RestoreConnectionA0 (
  1343. (HWND)0,
  1344. lpDrive);
  1345. #endif
  1346. if (status == NO_ERROR) {
  1347. printf("WNetRestoreConnection success\n");
  1348. }
  1349. else {
  1350. printf("WNetRestoreConnection failure %d\n",status);
  1351. }
  1352. }
  1353. VOID
  1354. TestClearConnect(
  1355. VOID
  1356. )
  1357. {
  1358. DWORD status;
  1359. status = WNetClearConnections(
  1360. (HWND)0);
  1361. if (status == NO_ERROR) {
  1362. printf("WNetClearConnection success\n");
  1363. }
  1364. else {
  1365. printf("WNetClearConnection failure %d\n",status);
  1366. }
  1367. }
  1368. VOID
  1369. TestLotsOfStuff(VOID)
  1370. {
  1371. DWORD status;
  1372. BOOL KeepGoing=TRUE;
  1373. do {
  1374. printf("\n*** RUNNING TestAddConnect2 for g:\n");
  1375. TestAddConnect2(TEXT("\\\\popcorn\\public"), TEXT("g:"));
  1376. printf("\n*** RUNNING TestAddConnect2 for t:\n");
  1377. TestAddConnect2(TEXT("\\\\products3\\release"), TEXT("t:"));
  1378. printf("\n*** RUNNING TestAddConnect2 for k:\n");
  1379. TestAddConnect2(TEXT("\\\\kernel\\razzle2"), TEXT("k:"));
  1380. printf("\n*** TESTING AddConnect1 for NP2 on z:\n");
  1381. status = WNetAddConnection(TEXT("!Rastaman"),NULL,TEXT("z:"));
  1382. if (status != WN_SUCCESS) {
  1383. printf("AddConnect1 for NP2 failed %d"
  1384. "- Do we have a 2nd provider?\n",status);
  1385. }
  1386. else {
  1387. printf("AddConnect1 success\n");
  1388. }
  1389. printf("\n*** RUNNING TestGetConnect\n");
  1390. TestGetConnect(TEXT("g:"),NAME_BUF_SIZE);
  1391. printf("\n*** RUNNING TestSetError\n");
  1392. TestSetError();
  1393. printf("\n*** RUNNING TestMultiError\n");
  1394. TestMultiError();
  1395. printf("\n*** RUNNING TestGetUser\n");
  1396. TestGetUser(NULL,NAME_BUF_SIZE);
  1397. printf("\n*** RUNNING TestEnumConnect (non-remembered)\n");
  1398. TestEnumConnect(RESOURCE_CONNECTED,RESOURCETYPE_DISK);
  1399. printf("\n*** RUNNING TestEnumConnect (remembered)\n");
  1400. TestEnumConnect(RESOURCE_REMEMBERED,RESOURCETYPE_DISK);
  1401. printf("\n*** RUNNING TestEnumConnect (context)\n");
  1402. TestEnumConnect(RESOURCE_CONTEXT,RESOURCETYPE_DISK);
  1403. printf("\n*** ATTEMPT to Cancel connection to t:\n");
  1404. status = WNetCancelConnection(TEXT("t:"),FALSE);
  1405. if ( status != WN_SUCCESS) {
  1406. printf("WNetCancelConnection failed %d\n",status);
  1407. //
  1408. // If there is an extended error, display it.
  1409. //
  1410. if (status == WN_EXTENDED_ERROR) {
  1411. DisplayExtendedError();
  1412. }
  1413. }
  1414. else {
  1415. printf("WNetCancelConnection Success\n");
  1416. }
  1417. printf("\n*** ATTEMPT to Cancel connection to g:\n");
  1418. WNetCancelConnection(TEXT("g:"),FALSE);
  1419. if ( status != WN_SUCCESS) {
  1420. printf("WNetCancelConnection failed %d\n",status);
  1421. //
  1422. // If there is an extended error, display it.
  1423. //
  1424. if (status == WN_EXTENDED_ERROR) {
  1425. DisplayExtendedError();
  1426. }
  1427. }
  1428. else {
  1429. printf("WNetCancelConnection Success\n");
  1430. }
  1431. printf("\n*** ATTEMPT to Cancel connection to k:\n");
  1432. WNetCancelConnection(TEXT("k:"),FALSE);
  1433. if ( status != WN_SUCCESS) {
  1434. printf("WNetCancelConnection failed %d\n",status);
  1435. //
  1436. // If there is an extended error, display it.
  1437. //
  1438. if (status == WN_EXTENDED_ERROR) {
  1439. DisplayExtendedError();
  1440. }
  1441. }
  1442. else {
  1443. printf("WNetCancelConnection Success\n");
  1444. }
  1445. printf("\n*** ATTEMPT to Cancel connection to z:\n");
  1446. WNetCancelConnection(TEXT("z:"),TRUE);
  1447. if ( status != WN_SUCCESS) {
  1448. printf("WNetCancelConnection failed %d\n",status);
  1449. //
  1450. // If there is an extended error, display it.
  1451. //
  1452. if (status == WN_EXTENDED_ERROR) {
  1453. DisplayExtendedError();
  1454. }
  1455. }
  1456. else {
  1457. printf("WNetCancelConnection Success\n");
  1458. }
  1459. printf("\n*** RUNNING TestEnumNet\n");
  1460. TestEnumNet();
  1461. printf(" - Do it again? (type 'n' to stop)\n");
  1462. if (getch() == 'n') {
  1463. KeepGoing = FALSE;
  1464. }
  1465. } while (KeepGoing);
  1466. return;
  1467. }
  1468. VOID
  1469. DisplayExtendedError(VOID)
  1470. {
  1471. TCHAR errorBuf[ERR_BUF_SIZE];
  1472. TCHAR nameBuf[NAME_BUF_SIZE];
  1473. DWORD errorCode;
  1474. DWORD status;
  1475. DWORD smallErrorSize;
  1476. DWORD smallNameSize;
  1477. status = WNetGetLastError(
  1478. &errorCode,
  1479. errorBuf,
  1480. ERR_BUF_SIZE,
  1481. nameBuf,
  1482. NAME_BUF_SIZE);
  1483. if(status != WN_SUCCESS) {
  1484. printf("WNetGetLastError failed %d\n",status);
  1485. return;
  1486. }
  1487. printf("EXTENDED ERROR INFORMATION: (from GetLastError)\n");
  1488. printf(" Code: %d\n",errorCode);
  1489. printf(" Description: "FORMAT_LPTSTR"\n",errorBuf);
  1490. printf(" Provider: "FORMAT_LPTSTR"\n\n",nameBuf);
  1491. //---------------------------------------------------------
  1492. // Now try it with a buffer that's one character too small.
  1493. //---------------------------------------------------------
  1494. printf("Try it with buffer that is one char too small\n");
  1495. smallErrorSize = STRLEN(errorBuf);
  1496. smallNameSize = STRLEN(nameBuf);
  1497. status = WNetGetLastError(
  1498. &errorCode,
  1499. errorBuf,
  1500. smallErrorSize,
  1501. nameBuf,
  1502. smallNameSize);
  1503. if(status != WN_SUCCESS) {
  1504. printf("WNetGetLastError failed %d\n",status);
  1505. return;
  1506. }
  1507. printf("EXTENDED ERROR INFORMATION (truncated): (from GetLastError)\n");
  1508. printf(" Code: %d\n",errorCode);
  1509. printf(" Description: "FORMAT_LPTSTR"\n",errorBuf);
  1510. printf(" Provider: "FORMAT_LPTSTR"\n\n",nameBuf);
  1511. //---------------------------------------------------------
  1512. // Now try it with a zero length buffer.
  1513. //---------------------------------------------------------
  1514. printf("Try it with zero length buffers\n");
  1515. smallErrorSize = 0;
  1516. smallNameSize = 0;
  1517. status = WNetGetLastError(
  1518. &errorCode,
  1519. errorBuf,
  1520. smallErrorSize,
  1521. nameBuf,
  1522. smallNameSize);
  1523. if(status != WN_SUCCESS) {
  1524. printf("WNetGetLastError failed %d\n",status);
  1525. return;
  1526. }
  1527. printf("EXTENDED ERROR INFORMATION (zero length): (from GetLastError)\n");
  1528. printf(" Code: %d\n",errorCode);
  1529. printf(" Description: "FORMAT_LPTSTR"\n",errorBuf);
  1530. printf(" Provider: "FORMAT_LPTSTR"\n\n",nameBuf);
  1531. //---------------------------------------------------------
  1532. // Now try it with invalid buffer.
  1533. //---------------------------------------------------------
  1534. printf("Try it with invalid buffers\n");
  1535. smallErrorSize = 0;
  1536. smallNameSize = 0;
  1537. status = WNetGetLastError(
  1538. &errorCode,
  1539. (LPTSTR)0xffffeeee,
  1540. 0,
  1541. (LPTSTR)0xffffeeee,
  1542. 0);
  1543. if(status != WN_SUCCESS) {
  1544. printf("WNetGetLastError failed %d\n",status);
  1545. return;
  1546. }
  1547. printf("EXTENDED ERROR INFORMATION (NO BUFFER): (from GetLastError)\n");
  1548. printf(" Code: %d\n",errorCode);
  1549. printf(" Description: "FORMAT_LPTSTR"\n",errorBuf);
  1550. printf(" Provider: "FORMAT_LPTSTR"\n\n",nameBuf);
  1551. //---------------------------------------------------------
  1552. // Now try it with invalid buffer & lie about size.
  1553. //---------------------------------------------------------
  1554. printf("Try it with invalid buffers\n");
  1555. smallErrorSize = 0;
  1556. smallNameSize = 0;
  1557. status = WNetGetLastError(
  1558. &errorCode,
  1559. (LPTSTR)0xffffeeee,
  1560. 2000,
  1561. (LPTSTR)0xffffeeee,
  1562. 2000);
  1563. if(status != WN_SUCCESS) {
  1564. printf("WNetGetLastError failed %d\n",status);
  1565. return;
  1566. }
  1567. printf("EXTENDED ERROR INFORMATION (NO BUFFER): (from GetLastError)\n");
  1568. printf(" Code: %d\n",errorCode);
  1569. printf(" Description: "FORMAT_LPTSTR"\n",errorBuf);
  1570. printf(" Provider: "FORMAT_LPTSTR"\n\n",nameBuf);
  1571. return;
  1572. }
  1573. VOID
  1574. DisplayMultiError(VOID)
  1575. {
  1576. TCHAR errorBuf[ERR_BUF_SIZE];
  1577. TCHAR nameBuf[NAME_BUF_SIZE];
  1578. DWORD status;
  1579. DWORD smallErrorSize;
  1580. DWORD smallNameSize;
  1581. DWORD ErrorSize = ERR_BUF_SIZE;
  1582. DWORD NameSize = NAME_BUF_SIZE;
  1583. status = MultinetGetErrorText(
  1584. errorBuf,
  1585. &ErrorSize,
  1586. nameBuf,
  1587. &NameSize);
  1588. if(status != WN_SUCCESS) {
  1589. printf("MultinetGetErrorText failed %d\n",status);
  1590. return;
  1591. }
  1592. printf("EXTENDED ERROR INFORMATION: (from MultinetGetErrorText)\n");
  1593. printf(" Description: "FORMAT_LPTSTR"\n",errorBuf);
  1594. printf(" Provider: "FORMAT_LPTSTR"\n\n",nameBuf);
  1595. //---------------------------------------------------------
  1596. // Now try it with a buffer that's one character too small.
  1597. //---------------------------------------------------------
  1598. printf("Try it with buffer that is one char too small\n");
  1599. smallErrorSize = STRLEN(errorBuf);
  1600. smallNameSize = STRLEN(nameBuf);
  1601. status = MultinetGetErrorText(
  1602. errorBuf,
  1603. &smallErrorSize,
  1604. nameBuf,
  1605. &smallNameSize);
  1606. if(status != WN_MORE_DATA) {
  1607. printf("MultinetGetErrorText FAILED %d\n",status);
  1608. return;
  1609. }
  1610. printf("EXTENDED ERROR INFORMATION (truncated): (from MultinetGetErrorText)\n");
  1611. printf(" Error size: %d\n", smallErrorSize);
  1612. printf(" Name size: %d\n", smallNameSize);
  1613. //---------------------------------------------------------
  1614. // Now try it with a zero length buffer.
  1615. //---------------------------------------------------------
  1616. printf("Try it with zero length buffers\n");
  1617. smallErrorSize = 0;
  1618. smallNameSize = 0;
  1619. status = MultinetGetErrorText(
  1620. errorBuf,
  1621. &smallErrorSize,
  1622. nameBuf,
  1623. &smallNameSize);
  1624. if(status != WN_MORE_DATA) {
  1625. printf("MultinetGetErrorText FAILED %d\n",status);
  1626. return;
  1627. }
  1628. printf("EXTENDED ERROR INFORMATION (zero length): (from MultinetGetErrorText)\n");
  1629. printf(" Error size: %d\n", smallErrorSize);
  1630. printf(" Name size: %d\n", smallNameSize);
  1631. //---------------------------------------------------------
  1632. // Now try it with invalid buffer.
  1633. //---------------------------------------------------------
  1634. printf("Try it with invalid buffers\n");
  1635. smallErrorSize = 0;
  1636. smallNameSize = 0;
  1637. status = MultinetGetErrorText(
  1638. (LPTSTR)0xffffeeee,
  1639. &smallErrorSize,
  1640. (LPTSTR)0xffffeeee,
  1641. 0);
  1642. if(status != WN_BAD_POINTER) {
  1643. printf("MultinetGetErrorText failed %d\n",status);
  1644. return;
  1645. }
  1646. printf("Worked OK, returned WN_BAD_POINTER\n");
  1647. //---------------------------------------------------------
  1648. // Now try it with invalid buffer & lie about size.
  1649. //---------------------------------------------------------
  1650. printf("Try it with invalid buffers\n");
  1651. smallErrorSize = 2000;
  1652. smallNameSize = 2000;
  1653. status = MultinetGetErrorText(
  1654. (LPTSTR)0xffffeeee,
  1655. &smallErrorSize,
  1656. (LPTSTR)0xffffeeee,
  1657. &smallNameSize);
  1658. if(status != WN_BAD_POINTER) {
  1659. printf("MultinetGetErrorText failed %d\n",status);
  1660. return;
  1661. }
  1662. printf("Worked OK, returned WN_BAD_POINTER\n");
  1663. return;
  1664. }
  1665. VOID
  1666. DisplayResourceArray(
  1667. LPNETRESOURCE NetResource,
  1668. DWORD NumElements
  1669. )
  1670. {
  1671. DWORD i;
  1672. for (i=0; i<NumElements ;i++ ) {
  1673. DisplayResource(&(NetResource[i]));
  1674. }
  1675. return;
  1676. }
  1677. VOID
  1678. DisplayResource(
  1679. LPNETRESOURCE NetResource
  1680. )
  1681. {
  1682. printf( "*** RESOURCE ***\n");
  1683. printf( "Scope\t0x%x\n", NetResource->dwScope);
  1684. printf( "Type\t0x%x\n", NetResource->dwType);
  1685. printf( "Usage\t0x%x\n", NetResource->dwUsage);
  1686. printf( "LocalName\t"FORMAT_LPTSTR"\n", NetResource->lpLocalName);
  1687. printf( "RemoteName\t"FORMAT_LPTSTR"\n", NetResource->lpRemoteName);
  1688. printf( "Comment\t"FORMAT_LPTSTR"\n", NetResource->lpComment);
  1689. printf( "Provider\t"FORMAT_LPTSTR"\n\n", NetResource->lpProvider);
  1690. }
  1691. BOOL
  1692. MakeArgsUnicode (
  1693. DWORD argc,
  1694. PCHAR argv[]
  1695. )
  1696. /*++
  1697. Routine Description:
  1698. Arguments:
  1699. Return Value:
  1700. Note:
  1701. --*/
  1702. {
  1703. DWORD i;
  1704. //
  1705. // ScConvertToUnicode allocates storage for each string.
  1706. // We will rely on process termination to free the memory.
  1707. //
  1708. for(i=0; i<argc; i++) {
  1709. if(!ConvertToUnicode( (LPWSTR *)&(argv[i]), argv[i])) {
  1710. printf("Couldn't convert argv[%d] to unicode\n",i);
  1711. return(FALSE);
  1712. }
  1713. }
  1714. return(TRUE);
  1715. }
  1716. BOOL
  1717. ConvertToUnicode(
  1718. OUT LPWSTR *UnicodeOut,
  1719. IN LPSTR AnsiIn
  1720. )
  1721. /*++
  1722. Routine Description:
  1723. This function translates an AnsiString into a Unicode string.
  1724. A new string buffer is created by this function. If the call to
  1725. this function is successful, the caller must take responsibility for
  1726. the unicode string buffer that was allocated by this function.
  1727. The allocated buffer should be free'd with a call to LocalFree.
  1728. NOTE: This function allocates memory for the Unicode String.
  1729. Arguments:
  1730. AnsiIn - This is a pointer to an ansi string that is to be converted.
  1731. UnicodeOut - This is a pointer to a location where the pointer to the
  1732. unicode string is to be placed.
  1733. Return Value:
  1734. TRUE - The conversion was successful.
  1735. FALSE - The conversion was unsuccessful. In this case a buffer for
  1736. the unicode string was not allocated.
  1737. --*/
  1738. {
  1739. NTSTATUS ntStatus;
  1740. DWORD bufSize;
  1741. UNICODE_STRING unicodeString;
  1742. ANSI_STRING ansiString;
  1743. //
  1744. // Allocate a buffer for the unicode string.
  1745. //
  1746. bufSize = (strlen(AnsiIn)+1) * sizeof(WCHAR);
  1747. *UnicodeOut = (LPWSTR) LocalAlloc(LPTR, bufSize);
  1748. if (*UnicodeOut == NULL) {
  1749. printf("ScConvertToUnicode:LocalAlloc Failure %ld\n",GetLastError());
  1750. return(FALSE);
  1751. }
  1752. //
  1753. // Initialize the string structures
  1754. //
  1755. RtlInitAnsiString( &ansiString, AnsiIn);
  1756. unicodeString.Buffer = *UnicodeOut;
  1757. unicodeString.MaximumLength = (USHORT)bufSize;
  1758. unicodeString.Length = 0;
  1759. //
  1760. // Call the conversion function.
  1761. //
  1762. ntStatus = RtlAnsiStringToUnicodeString (
  1763. &unicodeString, // Destination
  1764. &ansiString, // Source
  1765. FALSE); // Allocate the destination
  1766. if (!NT_SUCCESS(ntStatus)) {
  1767. printf("ScConvertToUnicode:RtlAnsiStringToUnicodeString Failure %lx\n",
  1768. ntStatus);
  1769. return(FALSE);
  1770. }
  1771. //
  1772. // Fill in the pointer location with the unicode string buffer pointer.
  1773. //
  1774. *UnicodeOut = unicodeString.Buffer;
  1775. return(TRUE);
  1776. }
  1777. VOID
  1778. InvalidParms(
  1779. VOID
  1780. )
  1781. /*++
  1782. Routine Description:
  1783. Tests Invalid parameters sent to Winnet API.
  1784. Arguments:
  1785. Return Value:
  1786. --*/
  1787. {
  1788. DWORD status;
  1789. DWORD dwFlags;
  1790. LPNETRESOURCE netResource;
  1791. HANDLE enumHandle;
  1792. DWORD dwType;
  1793. DWORD dwScope;
  1794. DWORD dwUsage;
  1795. NETRESOURCE NetResource;
  1796. netResource = (LPNETRESOURCE) LocalAlloc(LPTR, sizeof(NETRESOURCE));
  1797. if (netResource == NULL) {
  1798. printf("InvalidParms:LocalAlloc Failed %d\n",GetLastError);
  1799. return;
  1800. }
  1801. netResource->lpRemoteName = TEXT("\\popcorn\\public");
  1802. netResource->lpLocalName = TEXT("p:");
  1803. netResource->dwType = RESOURCETYPE_DISK;
  1804. //==============================================
  1805. // WNetAddConnect2 - set dwFlags to something other than 0 or
  1806. // CONNECT_UPDATE_PROFILE.
  1807. //==============================================
  1808. dwFlags = CONNECT_UPDATE_PROFILE + 1;
  1809. status = WNetAddConnection2(netResource,NULL,NULL,dwFlags);
  1810. if (status == WN_BAD_VALUE) {
  1811. printf("InvalidParms Test #1 success\n");
  1812. }
  1813. else {
  1814. printf("InvalidParms Test #1 failed\n");
  1815. }
  1816. //==============================================
  1817. // WNetAddConnect2 - dwType = RESOURCETYPE_ANY.
  1818. // dwFlags != CONNECT_UPDATE_PROFILE.
  1819. //==============================================
  1820. netResource->dwType = RESOURCETYPE_DISK;
  1821. dwFlags = CONNECT_UPDATE_PROFILE+1;
  1822. status = WNetAddConnection2(netResource,NULL,NULL,dwFlags);
  1823. if (status == WN_BAD_VALUE) {
  1824. printf("InvalidParms Test #2 success\n");
  1825. }
  1826. else {
  1827. printf("InvalidParms Test #2 failed\n");
  1828. }
  1829. //==============================================
  1830. // WNetAddConnect2 - dwType = RESOURCETYPE_DISK.
  1831. // dwFlags = 0
  1832. //==============================================
  1833. netResource->dwType = RESOURCETYPE_DISK;
  1834. dwFlags = 0;
  1835. status = WNetAddConnection2(netResource,NULL,NULL,dwFlags);
  1836. if (status != WN_BAD_VALUE) {
  1837. printf("InvalidParms Test #3 success\n");
  1838. }
  1839. else {
  1840. printf("InvalidParms Test #3 failed\n");
  1841. }
  1842. //==============================================
  1843. // WNetAddConnect2 - lpRemoteName = NULL
  1844. //==============================================
  1845. netResource->dwType = RESOURCETYPE_DISK;
  1846. dwFlags = 0;
  1847. netResource->lpRemoteName = NULL;
  1848. status = WNetAddConnection2(netResource,NULL,NULL,dwFlags);
  1849. if (status == WN_BAD_NETNAME) {
  1850. printf("InvalidParms Test #4 success\n");
  1851. }
  1852. else {
  1853. printf("InvalidParms Test #4 failed\n");
  1854. }
  1855. //======================================================================
  1856. // WNetOpenEnum - dwScope = RESOURCE_CONNECTED | RESOURCE_GLOBALNET
  1857. //======================================================================
  1858. dwScope = RESOURCE_CONNECTED | RESOURCE_GLOBALNET | RESOURCE_REMEMBERED+1;
  1859. dwType = RESOURCETYPE_ANY;
  1860. status = WNetOpenEnum(
  1861. dwScope,
  1862. dwType,
  1863. 0,
  1864. NULL,
  1865. &enumHandle);
  1866. if (status == WN_BAD_VALUE) {
  1867. printf("InvalidParms Test #5 success\n");
  1868. }
  1869. else {
  1870. printf("InvalidParms Test #5 failed\n");
  1871. }
  1872. //======================================================================
  1873. // WNetOpenEnum - dwType = RESOURCETYPE_DISK | RESOURCETYPE_PRINT |
  1874. // RESOURCETYPE_ANY + 1;
  1875. //======================================================================
  1876. dwScope = RESOURCE_CONNECTED;
  1877. dwType = (RESOURCETYPE_DISK | RESOURCETYPE_PRINT | RESOURCETYPE_ANY)+1;
  1878. status = WNetOpenEnum(
  1879. dwScope,
  1880. dwType,
  1881. 0,
  1882. NULL,
  1883. &enumHandle);
  1884. if (status == WN_BAD_VALUE) {
  1885. printf("InvalidParms Test #6 success\n");
  1886. }
  1887. else {
  1888. printf("InvalidParms Test #6 failed\n");
  1889. }
  1890. //======================================================================
  1891. // WNetOpenEnum - dwUsage = RESOURCEUSAGE_CONNECTABLE |
  1892. // RESOURCEUSAGE_CONTAINER + 1
  1893. //======================================================================
  1894. dwScope = RESOURCE_GLOBALNET;
  1895. dwType = RESOURCETYPE_DISK;
  1896. dwUsage = (RESOURCEUSAGE_CONNECTABLE | RESOURCEUSAGE_CONTAINER) + 1;
  1897. status = WNetOpenEnum(
  1898. dwScope,
  1899. dwType,
  1900. dwUsage,
  1901. NULL,
  1902. &enumHandle);
  1903. if (status == WN_BAD_VALUE) {
  1904. printf("InvalidParms Test #7 success\n");
  1905. }
  1906. else {
  1907. printf("InvalidParms Test #7 failed\n");
  1908. }
  1909. //======================================================================
  1910. // WNetOpenEnum - NetResource Structure is filled with 0.
  1911. //======================================================================
  1912. memset(&NetResource, 0,sizeof(NetResource));
  1913. dwScope = RESOURCE_GLOBALNET;
  1914. dwType = RESOURCETYPE_ANY;
  1915. dwUsage = 0;
  1916. status = WNetOpenEnum(
  1917. dwScope,
  1918. dwType,
  1919. dwUsage,
  1920. NULL,
  1921. &enumHandle);
  1922. if (status == WN_SUCCESS) {
  1923. printf("InvalidParms Test #8 success\n");
  1924. WNetCloseEnum(enumHandle);
  1925. }
  1926. else {
  1927. printf("InvalidParms Test #8 failed\n");
  1928. }
  1929. //======================================================================
  1930. // WNetCancelConnection2 - dwFlags != CONNECT_UPDATE_PROFILE | 0.
  1931. //======================================================================
  1932. status = WNetCancelConnection2(TEXT("p:"), CONNECT_UPDATE_PROFILE + 1, FALSE);
  1933. if (status == WN_BAD_VALUE) {
  1934. printf("InvalidParms Test #9 success\n");
  1935. }
  1936. else {
  1937. printf("InvalidParms Test #9 failed\n");
  1938. }
  1939. printf("InvalidParms Test Complete\n");
  1940. LocalFree(netResource);
  1941. return;
  1942. }
  1943. VOID
  1944. RecursiveEnum(
  1945. DWORD RecursionLevel,
  1946. DWORD ResourceUsage,
  1947. LPNETRESOURCE EnumNetResource
  1948. )
  1949. /*++
  1950. Routine Description:
  1951. Arguments:
  1952. Return Value:
  1953. --*/
  1954. {
  1955. DWORD status;
  1956. HANDLE enumHandle;
  1957. LPNETRESOURCE netResource=NULL;
  1958. DWORD numElements;
  1959. DWORD bufferSize;
  1960. DWORD saveBufferSize;
  1961. DWORD i;
  1962. DWORD usage;
  1963. CHAR response;
  1964. //-------------------------------------------
  1965. // Open a handle to the next level container
  1966. //-------------------------------------------
  1967. status = WNetOpenEnum(
  1968. RESOURCE_GLOBALNET,
  1969. RESOURCETYPE_ANY,
  1970. ResourceUsage,
  1971. EnumNetResource,
  1972. &enumHandle);
  1973. if ( status != WN_SUCCESS) {
  1974. printf("WNetOpenEnum %d failed %d\n",RecursionLevel,status);
  1975. //
  1976. // If there is an extended error, display it.
  1977. //
  1978. if (status == WN_EXTENDED_ERROR) {
  1979. DisplayExtendedError();
  1980. }
  1981. return;
  1982. }
  1983. else {
  1984. printf("WNetOpenEnum %d Success\n",RecursionLevel);
  1985. }
  1986. //-------------------------------------
  1987. // Allocate memory for the enumeration
  1988. //-------------------------------------
  1989. //
  1990. // Attempt to allow for 10 resource structures
  1991. //
  1992. bufferSize = (10*sizeof(NETRESOURCE))+2048;
  1993. netResource = (LPNETRESOURCE) LocalAlloc(LPTR, bufferSize);
  1994. if (netResource == NULL) {
  1995. printf("TestEnum:LocalAlloc Failed %d\n",GetLastError);
  1996. return;
  1997. }
  1998. saveBufferSize = bufferSize;
  1999. //-----------------------------------
  2000. // Enumerate the next level
  2001. //-----------------------------------
  2002. numElements = 0xffffffff;
  2003. status = WNetEnumResource(
  2004. enumHandle,
  2005. &numElements,
  2006. netResource,
  2007. &bufferSize);
  2008. if ((status == WN_NO_MORE_ENTRIES) ||
  2009. (status == WN_SUCCESS) ) {
  2010. if (numElements != 0) {
  2011. //
  2012. // Success! Display the returned array
  2013. // and close the handle.
  2014. //
  2015. if (status == WN_SUCCESS){
  2016. printf("WNetEnumResource %d Success - but MORE DATA\n",
  2017. RecursionLevel);
  2018. }
  2019. else {
  2020. printf("WNetEnumResource %d Success\n",RecursionLevel);
  2021. }
  2022. usage = RESOURCEUSAGE_CONTAINER;
  2023. switch(RecursionLevel) {
  2024. case 0:
  2025. printf("\n*------------- NETWORK PROVIDERS ------------*\n");
  2026. break;
  2027. case 1:
  2028. printf("\n*------------- DOMAINS FOR "FORMAT_LPTSTR" PROVIDER ------------*\n",
  2029. EnumNetResource->lpRemoteName);
  2030. break;
  2031. case 2:
  2032. printf("\n*------------- SERVERS ON "FORMAT_LPTSTR" DOMAIN ------------*\n",
  2033. EnumNetResource->lpRemoteName);
  2034. break;
  2035. case 3:
  2036. printf("\n*------------- SHARES ON "FORMAT_LPTSTR" SERVER ------------*\n",
  2037. EnumNetResource->lpRemoteName);
  2038. usage = RESOURCEUSAGE_CONNECTABLE;
  2039. break;
  2040. default:
  2041. break;
  2042. }
  2043. printf("continue? ");
  2044. response = getch();
  2045. response = toupper(response);
  2046. if (response == 'N') {
  2047. WNetCloseEnum(enumHandle);
  2048. return;
  2049. }
  2050. if (response == 'Q') {
  2051. ExitProcess(0);
  2052. }
  2053. printf("\r");
  2054. DisplayResourceArray(netResource, numElements);
  2055. for (i=0;i<numElements ;i++ ) {
  2056. RecursiveEnum(
  2057. RecursionLevel+1,
  2058. usage,
  2059. &(netResource[i]));
  2060. }
  2061. }
  2062. else {
  2063. printf("No entries to enumerate for "FORMAT_LPTSTR" rc=%d\n",
  2064. EnumNetResource->lpRemoteName,status);
  2065. }
  2066. }
  2067. else if (status == WN_MORE_DATA) {
  2068. printf("The buffer (%d bytes) was too small for one entry, need %d bytes\n",
  2069. saveBufferSize, bufferSize);
  2070. }
  2071. else {
  2072. printf("WNetEnumResource %d failed %d\n",RecursionLevel,status);
  2073. //
  2074. // If there is an extended error, display it.
  2075. //
  2076. if (status == WN_EXTENDED_ERROR) {
  2077. DisplayExtendedError();
  2078. }
  2079. }
  2080. WNetCloseEnum(enumHandle);
  2081. if (netResource != NULL) {
  2082. LocalFree(netResource);
  2083. }
  2084. }
  2085. VOID
  2086. TestLogonNotify(
  2087. LPTSTR argv[],
  2088. DWORD argc
  2089. )
  2090. /*++
  2091. Routine Description:
  2092. Arguments:
  2093. Return Value:
  2094. --*/
  2095. {
  2096. DWORD status;
  2097. MSV1_0_INTERACTIVE_LOGON NewLogon;
  2098. MSV1_0_INTERACTIVE_LOGON OldLogon;
  2099. LUID LogonId;
  2100. LPWSTR LogonScripts;
  2101. LPWSTR pScript;
  2102. NewLogon.MessageType = MsV1_0InteractiveLogon;
  2103. RtlInitUnicodeString(&(NewLogon.LogonDomainName),L"Domain");
  2104. RtlInitUnicodeString(&(NewLogon.UserName),L"SAMMY");
  2105. RtlInitUnicodeString(&(NewLogon.Password),L"SECRET");
  2106. OldLogon.MessageType = MsV1_0InteractiveLogon;
  2107. RtlInitUnicodeString(&(OldLogon.LogonDomainName),L"Domain");
  2108. RtlInitUnicodeString(&(OldLogon.UserName),L"SAMMY");
  2109. RtlInitUnicodeString(&(OldLogon.Password),L"NEWSECRET");
  2110. LogonId.HighPart = 5;
  2111. LogonId.LowPart = 53;
  2112. status = WNetLogonNotify(
  2113. L"Windows NT Network Provider",
  2114. &LogonId,
  2115. L"MSV1_0:Interactive",
  2116. &NewLogon,
  2117. L"MSV1_0:Interactive",
  2118. &OldLogon,
  2119. L"Dan's Station",
  2120. (LPVOID)L"POINTER",
  2121. &LogonScripts);
  2122. if (status == NO_ERROR) {
  2123. printf("WNetLogonNotify Success\n");
  2124. if (LogonScripts != NULL) {
  2125. pScript = LogonScripts;
  2126. do {
  2127. printf("LogonScripts: %ws\n",pScript);
  2128. pScript += (wcslen(pScript) + 1);
  2129. }
  2130. while (*pScript != L'\0');
  2131. LocalFree(LogonScripts);
  2132. }
  2133. }
  2134. else {
  2135. printf("WNetLogonNotify Failure %d\n",status);
  2136. }
  2137. return;
  2138. }
  2139. VOID
  2140. TestChangePassword(
  2141. LPTSTR argv[],
  2142. DWORD argc
  2143. )
  2144. /*++
  2145. Routine Description:
  2146. Arguments:
  2147. Return Value:
  2148. --*/
  2149. {
  2150. DWORD status;
  2151. MSV1_0_INTERACTIVE_LOGON NewLogon;
  2152. MSV1_0_INTERACTIVE_LOGON OldLogon;
  2153. NewLogon.MessageType = MsV1_0InteractiveLogon;
  2154. RtlInitUnicodeString(&(NewLogon.LogonDomainName),L"Domain");
  2155. RtlInitUnicodeString(&(NewLogon.UserName),L"SAMMY");
  2156. RtlInitUnicodeString(&(NewLogon.Password),L"SECRET");
  2157. OldLogon.MessageType = MsV1_0InteractiveLogon;
  2158. RtlInitUnicodeString(&(OldLogon.LogonDomainName),L"Domain");
  2159. RtlInitUnicodeString(&(OldLogon.UserName),L"SAMMY");
  2160. RtlInitUnicodeString(&(OldLogon.Password),L"NEWSECRET");
  2161. status = WNetPasswordChangeNotify(
  2162. L"Windows Nt Network Provider",
  2163. L"MSV1_0:Interactive",
  2164. &NewLogon,
  2165. L"MSV1_0:Interactive",
  2166. &OldLogon,
  2167. L"Dan's Station",
  2168. (LPVOID)L"POINTER",
  2169. 44);
  2170. if (status == NO_ERROR) {
  2171. printf("WNetPasswordChangeNotify Success\n");
  2172. }
  2173. else {
  2174. printf("WNetPasswordChangeNotify Failure %d\n",status);
  2175. }
  2176. return;
  2177. }
  2178. BOOL
  2179. GetStringFromFile(
  2180. LPDWORD lpLoopCount,
  2181. LPSTR buffer
  2182. )
  2183. /*++
  2184. Routine Description:
  2185. The following behaviour is desired, however, I don't have time to
  2186. write it right now:
  2187. This function reads the next line of instructions from a file called
  2188. "mprtest.txt". When it reaches the end of the file, it begins again
  2189. at the beginning of the file. The first line in the file indicates how
  2190. many times to pass through the file. (Loop count). When the last pass
  2191. occurs, the instruction "done" is passed back in the buffer.
  2192. Arguments:
  2193. Return Value:
  2194. --*/
  2195. {
  2196. if (*lpLoopCount == 0) {
  2197. strcpy(buffer+2, "done");
  2198. buffer[1]=strlen(buffer+2);
  2199. }
  2200. else {
  2201. if (*lpLoopCount & 1) {
  2202. buffer[1]=28;
  2203. strcpy(buffer+2, "AddConnect1 x: \\\\danl1\\roote");
  2204. buffer[1]=strlen(buffer+2);
  2205. }
  2206. else {
  2207. strcpy(buffer+2, "CancelConnect x: r");
  2208. buffer[1]=strlen(buffer+2);
  2209. }
  2210. (*lpLoopCount)--;
  2211. }
  2212. return(TRUE);
  2213. }
  2214. LONG
  2215. wtol(
  2216. IN LPWSTR string
  2217. )
  2218. {
  2219. LONG value = 0;
  2220. while((*string != L'\0') &&
  2221. (*string >= L'0') &&
  2222. ( *string <= L'9')) {
  2223. value = value * 10 + (*string - L'0');
  2224. string++;
  2225. }
  2226. return(value);
  2227. }
  2228. VOID
  2229. Usage(VOID)
  2230. {
  2231. printf("USAGE:\n");
  2232. printf("<server> <function>\n");
  2233. printf("SYNTAX EXAMPLES \n");
  2234. printf("AddConnect1 <drive> <remote name> - "
  2235. "these are remembered\n");
  2236. printf("AddConnect2 <drive> <remote name> - "
  2237. "these are not remembered\n");
  2238. printf("CancelConnect <drive> <r>\n");
  2239. printf("GetConnect <connection> <buffer size>\n");
  2240. printf("GetUniversalName <connection> <info level> <buffer size>\n");
  2241. printf("GetUser <device= ?> <bufsize= ?>\n");
  2242. printf("EnumConnect <type= ANY|DISK|PRINT> <r> \n");
  2243. printf("EnumContext <type= ANY|DISK|PRINT> \n");
  2244. printf("RestoreConnect <drive> \n");
  2245. printf("EnumNet\n");
  2246. printf("SetError\n");
  2247. printf("MultiError\n");
  2248. printf("DirApi\n");
  2249. printf("ClearConnect\n");
  2250. printf("LogonNotify\n");
  2251. printf("ChangePassword\n");
  2252. printf("ALL\n");
  2253. printf("InvalidParms\n");
  2254. printf("Loop <number> - Add and cancel n connections \n");
  2255. printf("Exit\n");
  2256. }