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.

3180 lines
72 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1998 - 1998.
  5. //
  6. // File: Main.CXX
  7. //
  8. // Contents: Main file for DfsApi
  9. //
  10. //
  11. // Notes:
  12. //
  13. //--------------------------------------------------------------------------
  14. #include <nt.h>
  15. #include <ntrtl.h>
  16. #include <nturtl.h>
  17. #include <windows.h>
  18. #include <stdio.h>
  19. #include <stdlib.h>
  20. #include <stddef.h>
  21. #include <shellapi.h>
  22. #include <DfsReferralData.h>
  23. #include <DfsServerLibrary.hxx>
  24. #include <time.h>
  25. #include "lm.h"
  26. #include "lmdfs.h"
  27. #include "tchar.h"
  28. #include "dfswmi.h"
  29. #define RETURN return
  30. #undef ASSERT
  31. #define ASSERT(x)
  32. #define APINetDfsAdd DfsAdd
  33. #define APINetDfsRemove DfsRemove
  34. #define WPP_BIT_CLI_DRV 0x01
  35. #define WPP_LEVEL_FLAGS_LOGGER(lvl,flags) WPP_LEVEL_LOGGER(flags)
  36. #define WPP_LEVEL_FLAGS_ENABLED(lvl, flags) (WPP_LEVEL_ENABLED(flags) && WPP_CONTROL(WPP_BIT_CLI_DRV ).Level >= lvl)
  37. #define WPP_LEVEL_ERROR_FLAGS_LOGGER(lvl, error, flags) WPP_LEVEL_LOGGER(flags)
  38. #define WPP_LEVEL_ERROR_FLAGS_ENABLED(lvl, error, flags) \
  39. ((!NT_SUCCESS(error) || WPP_LEVEL_ENABLED(flags)) && WPP_CONTROL(WPP_BIT_CLI_DRV ).Level >= lvl)
  40. #include "apitest.tmh"
  41. extern
  42. void
  43. SetReferralControl(WPP_CB_TYPE * Control);
  44. DWORD
  45. APINetDfsAddStdRoot(
  46. LPWSTR machine,
  47. LPWSTR Share,
  48. LPWSTR comment,
  49. DWORD Options)
  50. {
  51. UNREFERENCED_PARAMETER(machine);
  52. return DfsAddStandaloneRoot(machine, Share, comment, Options);
  53. }
  54. DWORD
  55. APINetDfsRemoveStdRoot(
  56. LPWSTR machine,
  57. LPWSTR Share,
  58. DWORD Options)
  59. {
  60. UNREFERENCED_PARAMETER(Options);
  61. return DfsDeleteStandaloneRoot(machine, Share);
  62. }
  63. DWORD
  64. APINetDfsEnum(
  65. LPWSTR DfsPath,
  66. DWORD Level,
  67. DWORD PrefMaxLen,
  68. LPBYTE *pBuffer,
  69. LPDWORD pEntriesRead,
  70. LPDWORD pResumeHandle )
  71. {
  72. LONG SizeRequired = 0;
  73. ULONG StartingLen = PrefMaxLen;
  74. LPBYTE Buffer;
  75. DFSSTATUS Status;
  76. if (StartingLen == ~0)
  77. {
  78. StartingLen = 4096;
  79. }
  80. Status = NetApiBufferAllocate(StartingLen, (LPVOID *)&Buffer );
  81. if (Status != ERROR_SUCCESS)
  82. {
  83. return Status;
  84. }
  85. Status = DfsEnumerate( DfsPath,
  86. Level,
  87. PrefMaxLen,
  88. Buffer,
  89. StartingLen,
  90. pEntriesRead,
  91. pResumeHandle,
  92. &SizeRequired );
  93. if (Status == ERROR_BUFFER_OVERFLOW)
  94. {
  95. NetApiBufferFree(Buffer);
  96. Status = NetApiBufferAllocate( SizeRequired, (LPVOID *)&Buffer);
  97. if (Status != ERROR_SUCCESS)
  98. {
  99. return Status;
  100. }
  101. Status = DfsEnumerate( DfsPath,
  102. Level,
  103. PrefMaxLen,
  104. Buffer,
  105. SizeRequired,
  106. pEntriesRead,
  107. pResumeHandle,
  108. &SizeRequired );
  109. }
  110. if (Status != ERROR_SUCCESS)
  111. {
  112. NetApiBufferFree( Buffer );
  113. }
  114. else {
  115. *pBuffer = Buffer;
  116. }
  117. return Status;
  118. }
  119. DWORD
  120. APINetDfsGetInfo(
  121. LPWSTR DfsPath,
  122. LPWSTR Server,
  123. LPWSTR Share,
  124. DWORD Level,
  125. LPBYTE *pBuffer )
  126. {
  127. LONG SizeRequired = 0;
  128. ULONG StartingLen = 4096;
  129. LPBYTE Buffer;
  130. DFSSTATUS Status;
  131. UNREFERENCED_PARAMETER(Share);
  132. UNREFERENCED_PARAMETER(Server);
  133. Status = NetApiBufferAllocate(StartingLen, (LPVOID *)&Buffer );
  134. if (Status != ERROR_SUCCESS)
  135. {
  136. return Status;
  137. }
  138. Status = DfsGetInfo( DfsPath,
  139. Level,
  140. Buffer,
  141. StartingLen,
  142. &SizeRequired );
  143. if (Status == ERROR_BUFFER_OVERFLOW)
  144. {
  145. NetApiBufferFree(Buffer);
  146. Status = NetApiBufferAllocate(SizeRequired, (LPVOID *)&Buffer );
  147. if (Status != ERROR_SUCCESS)
  148. {
  149. return Status;
  150. }
  151. Status = DfsGetInfo( DfsPath,
  152. Level,
  153. Buffer,
  154. SizeRequired,
  155. &SizeRequired );
  156. }
  157. if (Status != ERROR_SUCCESS)
  158. {
  159. NetApiBufferFree( Buffer );
  160. }
  161. else {
  162. *pBuffer = Buffer;
  163. }
  164. return Status;
  165. }
  166. DFSSTATUS
  167. APINetDfsSetInfo(
  168. LPWSTR DfsPathName,
  169. LPWSTR ServerName,
  170. LPWSTR ShareName,
  171. DWORD Level,
  172. LPBYTE pBuffer )
  173. {
  174. return DfsSetInfo( DfsPathName,
  175. ServerName,
  176. ShareName,
  177. Level,
  178. pBuffer );
  179. }
  180. #if !defined(UNICODE) || !defined(_UNICODE)
  181. #error For UNICODE only
  182. #endif
  183. #define NOREBOOT 1
  184. #define CHECK_ERR(x)
  185. #define ASSERT(x)
  186. BOOL bDebug = FALSE;
  187. FILE* fDebug = NULL;
  188. #define MSG \
  189. if (bDebug) fprintf(fDebug, "File %s, %lu\n", __FILE__, __LINE__); \
  190. if (bDebug) fprintf
  191. ULONG Usage(LPSTR ptszAppNane);
  192. ULONG Add(DWORD dwArgc, LPTSTR* pptszArgv);
  193. ULONG Remove(DWORD dwArgc, LPTSTR* pptszArgv);
  194. ULONG Enum(DWORD dwArgc, LPTSTR* pptszArgv);
  195. ULONG GetInfo(DWORD dwArgc, LPTSTR* pptszArgv);
  196. ULONG AddStdRoot(DWORD dwArgc, LPTSTR* pptszArgv);
  197. ULONG RemoveStdRoot(DWORD dwArgc, LPTSTR* pptszArgv);
  198. ULONG SetInfo(DWORD dwArgc, LPTSTR* pptszArgv);
  199. #if 0
  200. ULONG GetClientInfo(DWORD dwArgc, LPTSTR* pptszArgv);
  201. ULONG SetClientInfo(DWORD dwArgc, LPTSTR* pptszArgv);
  202. ULONG AddFtRoot(DWORD dwArgc, LPTSTR* pptszArgv);
  203. ULONG RemoveFtRoot(DWORD dwArgc, LPTSTR* pptszArgv);
  204. ULONG RemoveFtRootForced(DWORD dwArgc, LPTSTR* pptszArgv);
  205. ULONG AddStdRootForced(DWORD dwArgc, LPTSTR* pptszArgv);
  206. ULONG GetDcAddress(DWORD dwArgc, LPTSTR* pptszArgv);
  207. ULONG SetDcAddress(DWORD dwArgc, LPTSTR* pptszArgv);
  208. ULONG AddConnection(DWORD dwArgc, LPTSTR* pptszArgv);
  209. ULONG AddConnection1(DWORD dwArgc, LPTSTR* pptszArgv);
  210. ULONG AddConnection2(DWORD dwArgc, LPTSTR* pptszArgv);
  211. ULONG CancelConnection(DWORD dwArgc, LPTSTR* pptszArgv);
  212. ULONG CancelConnection1(DWORD dwArgc, LPTSTR* pptszArgv);
  213. ULONG CancelConnection2(DWORD dwArgc, LPTSTR* pptszArgv);
  214. ULONG GetLocalName(LPTSTR ptszLocalName,
  215. ULONG ulLocalNameLen,
  216. LPTSTR ptszArg);
  217. ULONG GetNetResource(NETRESOURCE* pNetResource,
  218. LPTSTR ptszType,
  219. LPTSTR ptszLocalName,
  220. LPTSTR ptszRemoteName,
  221. LPTSTR ptszProvider);
  222. ULONG GetWNetConnectionFlags(DWORD* pdwFlags,
  223. DWORD dwArgc,
  224. LPTSTR* pptszArgv);
  225. ULONG AddressToSite(DWORD dwArgc,
  226. LPTSTR* pptszArgv);
  227. #endif
  228. ULONG PrintDfsInfo(DWORD dwLevel, LPBYTE pBuffer);
  229. ULONG PrintDfsInfo1(PDFS_INFO_1 pBuffer);
  230. ULONG PrintDfsInfo2(PDFS_INFO_2 pBuffer);
  231. ULONG PrintDfsInfo3(PDFS_INFO_3 pBuffer);
  232. ULONG PrintDfsInfo4(PDFS_INFO_4 pBuffer);
  233. ULONG PrintDfsInfo200(PDFS_INFO_200 pBuffer);
  234. ULONG PrintStgInfo(PDFS_STORAGE_INFO pStorage);
  235. LPTSTR GetStringParam(LPTSTR ptszParam);
  236. DFSSTATUS
  237. DfsAddHandledNamespace(
  238. LPWSTR Name,
  239. BOOLEAN Migrate );
  240. DFSSTATUS
  241. DfsServerInitialize(ULONG Flags);
  242. //+---------------------------------------------------------------------------
  243. //
  244. // Function: main
  245. //
  246. // Synopsis: Core function for the application.
  247. //
  248. // Arguments: [argc] -- The number of arguments
  249. // [argv] -- The arguments
  250. //
  251. // Returns: ERROR_SUCCESS -- Success
  252. //
  253. // Notes:
  254. //
  255. //----------------------------------------------------------------------------
  256. ULONG __cdecl main(int argc, char* argv[])
  257. {
  258. ULONG ulErr = ERROR_SUCCESS;
  259. DWORD dwArgc = 0;
  260. LPTSTR* pptszArgv = NULL;
  261. INT i = 0;
  262. INT nArgNdx = 0;
  263. DWORD Status;
  264. WPP_CB_TYPE *pLogger = NULL;
  265. pLogger = &WPP_CB[WPP_CTRL_NO(WPP_BIT_CLI_DRV)];
  266. WPP_INIT_TRACING(L"ApiTest");
  267. SetReferralControl(pLogger);
  268. Status = DfsServerInitialize(0);
  269. if (Status != ERROR_SUCCESS) {
  270. printf("Cannot continue: dfs server init error %d\n", Status);
  271. exit(-1);
  272. }
  273. Status = DfsAddHandledNamespace(L".", TRUE);
  274. if (Status != ERROR_SUCCESS) {
  275. printf("Cannot continue: dfs server add namespace error %d\n", Status);
  276. exit(-1);
  277. }
  278. Sleep(2000);
  279. printf("\n\nContinuing\n");
  280. if (argc < 2 ||
  281. argv[1][1]=='?' && (
  282. argv[1][0]=='-' ||
  283. argv[1][0]=='/'))
  284. {
  285. ulErr = Usage(argv[0]);
  286. RETURN(ulErr);
  287. }
  288. if (NULL == (pptszArgv =
  289. (LPTSTR*)malloc(sizeof(LPTSTR)*max(argc,32))))
  290. {
  291. _ftprintf(stderr,
  292. _T("Not enough memory\n"));
  293. ulErr = ERROR_NOT_ENOUGH_MEMORY;
  294. CHECK_ERR(ulErr);
  295. goto Error;
  296. }
  297. memset(pptszArgv, 0, sizeof(LPTSTR)*max(argc,32));
  298. for (i=0; i<argc; i++)
  299. {
  300. #ifdef UNICODE
  301. if (NULL == (pptszArgv[i] = (LPTSTR)malloc(
  302. sizeof(_TCHAR)*(1+strlen(argv[i])))))
  303. {
  304. _ftprintf(stderr,
  305. _T("Not enough memory\n"));
  306. ulErr = ERROR_NOT_ENOUGH_MEMORY;
  307. CHECK_ERR(ulErr);
  308. goto Error;
  309. }
  310. memset(pptszArgv[i],
  311. 0,
  312. sizeof(TCHAR)*(1+strlen(argv[i])));
  313. mbstowcs(pptszArgv[i], argv[i], strlen(argv[i]));
  314. #else
  315. pptszArgv[i]=argv[i];
  316. #endif
  317. ++dwArgc;
  318. } //for i
  319. if (pptszArgv[1] == _tcsstr(pptszArgv[1], _T("/debug")))
  320. {
  321. bDebug = TRUE;
  322. if (_T(':') == pptszArgv[1][strlen("/debug")])
  323. {
  324. if (NULL == (fDebug =
  325. _tfopen(pptszArgv[1]+strlen("/debug")+1, _T("wt+"))))
  326. {
  327. fprintf(stderr, "Opening %ws failed with %lu",
  328. pptszArgv[1]+strlen("/debug")+1,
  329. errno);
  330. }
  331. } //if
  332. if (NULL == fDebug)
  333. {
  334. fDebug = stderr;
  335. } //if
  336. MSG(fDebug,
  337. "\n\nDebug report for %ws\n",
  338. pptszArgv[0]);
  339. nArgNdx++;
  340. } //if
  341. for (i=0; i<argc; i++)
  342. {
  343. MSG(fDebug,
  344. "\tpptszArgv[%d]==\"%ws\"\n",
  345. i,
  346. pptszArgv[i]);
  347. }
  348. MSG(fDebug,
  349. "\tnArgNdx==%d\n",
  350. nArgNdx);
  351. if (0 == _tcsicmp(pptszArgv[nArgNdx+1], _T("add")))
  352. {
  353. ulErr = Add(dwArgc-nArgNdx-2, pptszArgv+nArgNdx+2);
  354. CHECK_ERR(ulErr);
  355. }
  356. else if (0 == _tcsicmp(pptszArgv[nArgNdx+1], _T("remove")))
  357. {
  358. ulErr = Remove(dwArgc-nArgNdx-2, pptszArgv+nArgNdx+2);
  359. CHECK_ERR(ulErr);
  360. }
  361. else if (0 == _tcsicmp(pptszArgv[nArgNdx+1], _T("enum")))
  362. {
  363. ulErr = Enum(dwArgc-nArgNdx-2, pptszArgv+nArgNdx+2);
  364. CHECK_ERR(ulErr);
  365. }
  366. else if (0 == _tcsicmp(pptszArgv[nArgNdx+1], _T("getinfo")))
  367. {
  368. ulErr = GetInfo(dwArgc-nArgNdx-2, pptszArgv+nArgNdx+2);
  369. CHECK_ERR(ulErr);
  370. }
  371. else if (0 == _tcsicmp(pptszArgv[nArgNdx+1], _T("addstdroot")))
  372. {
  373. ulErr = AddStdRoot(dwArgc-nArgNdx-2, pptszArgv+nArgNdx+2);
  374. CHECK_ERR(ulErr);
  375. }
  376. else if (0 == _tcsicmp(pptszArgv[nArgNdx+1], _T("removestdroot")))
  377. {
  378. ulErr = RemoveStdRoot(dwArgc-nArgNdx-2, pptszArgv+nArgNdx+2);
  379. CHECK_ERR(ulErr);
  380. }
  381. else if (0 == _tcsicmp(pptszArgv[nArgNdx+1], _T("setinfo")))
  382. {
  383. ulErr = SetInfo(dwArgc-nArgNdx-2, pptszArgv+nArgNdx+2);
  384. CHECK_ERR(ulErr);
  385. }
  386. #if 0
  387. else if (0 == _tcsicmp(pptszArgv[nArgNdx+1], _T("getclientinfo")))
  388. {
  389. ulErr = GetClientInfo(dwArgc-nArgNdx-2, pptszArgv+nArgNdx+2);
  390. CHECK_ERR(ulErr);
  391. }
  392. else if (0 == _tcsicmp(pptszArgv[nArgNdx+1], _T("setclientinfo")))
  393. {
  394. ulErr = SetClientInfo(dwArgc-nArgNdx-2, pptszArgv+nArgNdx+2);
  395. CHECK_ERR(ulErr);
  396. }
  397. else if (0 == _tcsicmp(pptszArgv[nArgNdx+1], _T("addftroot")))
  398. {
  399. ulErr = AddFtRoot(dwArgc-nArgNdx-2, pptszArgv+nArgNdx+2);
  400. CHECK_ERR(ulErr);
  401. }
  402. else if (0 == _tcsicmp(pptszArgv[nArgNdx+1], _T("removeftroot")))
  403. {
  404. ulErr = RemoveFtRoot(dwArgc-nArgNdx-2, pptszArgv+nArgNdx+2);
  405. CHECK_ERR(ulErr);
  406. }
  407. else if (0 == _tcsicmp(pptszArgv[nArgNdx+1], _T("removeftrootforced")))
  408. {
  409. ulErr = RemoveFtRootForced(dwArgc-nArgNdx-2, pptszArgv+nArgNdx+2);
  410. CHECK_ERR(ulErr);
  411. }
  412. else if (0 == _tcsicmp(pptszArgv[nArgNdx+1], _T("addstdrootforced")))
  413. {
  414. ulErr = AddStdRootForced(dwArgc-nArgNdx-2, pptszArgv+nArgNdx+2);
  415. CHECK_ERR(ulErr);
  416. }
  417. else if (0 == _tcsicmp(pptszArgv[nArgNdx+1], _T("getdcaddress")))
  418. {
  419. ulErr = GetDcAddress(dwArgc-nArgNdx-2, pptszArgv+nArgNdx+2);
  420. CHECK_ERR(ulErr);
  421. }
  422. else if (0 == _tcsicmp(pptszArgv[nArgNdx+1], _T("setdcaddress")))
  423. {
  424. ulErr = SetDcAddress(dwArgc-nArgNdx-2, pptszArgv+nArgNdx+2);
  425. CHECK_ERR(ulErr);
  426. }
  427. else if (0 == _tcsicmp(pptszArgv[nArgNdx+1], _T("wnetaddconnection")))
  428. {
  429. ulErr = AddConnection(dwArgc-nArgNdx-2, pptszArgv+nArgNdx+2);
  430. CHECK_ERR(ulErr);
  431. }
  432. else if (0 == _tcsicmp(pptszArgv[nArgNdx+1], _T("wnetcancelconnection")))
  433. {
  434. ulErr = CancelConnection(dwArgc-nArgNdx-2, pptszArgv+nArgNdx+2);
  435. CHECK_ERR(ulErr);
  436. }
  437. else if (0 == _tcsicmp(pptszArgv[nArgNdx+1], _T("addresstosite")))
  438. {
  439. ulErr = AddressToSite(dwArgc-nArgNdx-2, pptszArgv+nArgNdx+2);
  440. CHECK_ERR(ulErr);
  441. }
  442. #endif
  443. else
  444. {
  445. ulErr = ERROR_INVALID_PARAMETER;
  446. CHECK_ERR(ulErr);
  447. goto Error;
  448. }
  449. if (ERROR_SUCCESS != ulErr)
  450. {
  451. goto Error;
  452. }
  453. fprintf(stdout, "%ws completed successfully\n", pptszArgv[0]);
  454. goto Cleanup;
  455. Error:;
  456. fprintf(stderr, "%ws failed: %lu\n", pptszArgv[0], ulErr);
  457. goto Cleanup;
  458. Cleanup:;
  459. if (NULL != pptszArgv)
  460. {
  461. DWORD dwI = 0;
  462. for (dwI=0; dwI < dwArgc; dwI++)
  463. {
  464. #ifdef UNICODE
  465. if (NULL != pptszArgv[dwI])
  466. {
  467. free(pptszArgv[dwI]);
  468. pptszArgv[dwI] = NULL;
  469. } //if
  470. #endif
  471. } //for
  472. free(pptszArgv);
  473. pptszArgv = NULL;
  474. } //if
  475. if (fDebug != NULL && fDebug != stderr)
  476. {
  477. fclose(fDebug);
  478. }
  479. WPP_CLEANUP();
  480. RETURN(ulErr);
  481. }; //main
  482. //+---------------------------------------------------------------------------
  483. //
  484. // Function: Usage
  485. //
  486. // Synopsis: This function prints a help message to stderr
  487. //
  488. // Arguments: None.
  489. //
  490. // Returns: ERROR_INVALID_PARAMETER
  491. //
  492. // Notes:
  493. //
  494. //----------------------------------------------------------------------------
  495. ULONG Usage(LPSTR ptszAppName)
  496. {
  497. fprintf(stderr,
  498. "Usage: %s [/debug:[<filename>]] <command> <options>\n\n"
  499. "commands:\n"
  500. "\tadd <dfsentrypath> <server> <share> [<comment> [<options>]]\n"
  501. "\t [/range:<lo>-<hi>]\n"
  502. "\t\toptions=add|restore\n"
  503. "\t\t/range works with options=add only. When /range is present\n"
  504. "\t\tthe command adds multiple links\n"
  505. "\tremove <dfsentrypath> [<server> <share>]\n"
  506. "\tenum <dfsname> <level> [<prefmaxlen>]\n"
  507. "\t\tprefmaxlen=integer greater than 0 (resume only)\n"
  508. "\t\tlevel=1,2,3,4,200\n"
  509. "\tgetinfo <dfsentrypath> <server> <share> <level>\n"
  510. "\t\tlevel=1,2,3,4,100\n"
  511. "\tsetinfo <dfsentrypath> <server> <share> <level> <options>\n"
  512. "\t\tlevel=100, options=<comment>, no <server>, <share>\n"
  513. "\t\tlevel=101, options=[active] [offline] [online] when <server> is not null\n"
  514. "\t\tlevel=101, options=ok|inconsistent|offline|online when <server> is null\n"
  515. "\t\tlevel=102, options=<timeout>, no <server>, <share>\n"
  516. "\tgetclientinfo <dfsentrypath> [<server> <share>] <level>\n"
  517. "\t\tlevel=1,2,3,4\n"
  518. "\tsetclientinfo <dfsentrypath> [<server> <share>] <level> <options>\n"
  519. "\t\tlevel=101, options=[active] [offline] [online]\n"
  520. "\t\tlevel=102, options=<timeout>, no <server>, <share>\n"
  521. "\taddstdroot <servername> <rootshare> [<comment> [<options>]]\n"
  522. "\tremovestdroot <servername> <rootshare> [<options>]\n"
  523. #if 0
  524. "\taddftroot <servername> <rootshare> <ftdfsname> [<options>]\n"
  525. "\tremoveftroot <servername> <rootshare> <ftdfsname> [<options>]\n"
  526. "\tremoveftrootforced <domainname> <servername> <rootshare> "
  527. "<ftdfsname> [<options>]\n"
  528. "\taddstdrootforced <servername> <rootshare> [<comment>] <store>\n"
  529. "\tgetdcaddress <servername>\n"
  530. "\tsetdcaddress <servername> <dcipaddress> <timeout> [<flags>]\n"
  531. "\twnetaddconnection <level> <remotename> <password> [<localname>] [<level2params>]\n"
  532. #endif
  533. "\t\tlevel=1|2\n"
  534. "\t\tlocalname=<driverletter>:, *, LPT1, etc.\n"
  535. "\t\tlevel2params=<type> [<provider>] [<username>] [<flags>]\n"
  536. "\t\ttype=disk|print|any\n"
  537. "\t\tflags=[update_profile] [update_recent] "
  538. "[temporary] [interactive] [prompt] [need_drive] [refcount] "
  539. "[redirect] [localdrive] [current_media] [deferred]\n"
  540. "\twnetcancelconnection <level> <localname> [<flags>] [force]\n"
  541. "\t\tlevel=1|2\n"
  542. "\t\tlocalname=<driverletter>:, etc\n"
  543. "\t\tflags=[update_profile] [update_recent] "
  544. "[temporary] [interactive] [prompt] [need_drive] [refcount] "
  545. "[redirect] [localdrive] [current_media] [deferred]\n"
  546. "\t\tforce=if present, the deletion of the connection is forced\n"
  547. "\n"
  548. "\taddresstosite <dcname> <ipaddress>\n\n"
  549. "To specify a NULL string in the middle of the command, use "
  550. "\"\".\n"
  551. "Example: setinfo \\\\myserver\\myentrypath \"\" \"\" "
  552. "100 \"My comment\".\n",
  553. ptszAppName);
  554. RETURN(ERROR_INVALID_PARAMETER);
  555. };//Usage
  556. //+---------------------------------------------------------------------------
  557. //
  558. // Function: Add
  559. //
  560. // Synopsis: This function performs NetDfsAdd.
  561. //
  562. // Arguments: [dwArg] the number of arguments
  563. // [pptszArg] the arguments
  564. //
  565. // Returns: ERROR_INVALID_PARAMETER
  566. //
  567. // Notes:
  568. //
  569. //----------------------------------------------------------------------------
  570. ULONG Add(DWORD dwArgc, LPTSTR* pptszArgv)
  571. {
  572. ULONG ulErr = ERROR_SUCCESS;
  573. DWORD dwFlags = 0;
  574. ULONG ulLo = 0;
  575. ULONG ulHi = 0;
  576. LPTSTR ptszVolName = NULL;
  577. LPTSTR ptszRange = NULL;
  578. LPTSTR ptszMinus = NULL;
  579. MSG(fDebug, "Entering Add(%lu,...)\n", dwArgc);
  580. if (dwArgc < 3 || NULL == pptszArgv || dwArgc > 6)
  581. {
  582. MSG(fDebug, "%lu < 3 || NULL == pptszArgv || %lu > 6",
  583. dwArgc,
  584. dwArgc);
  585. RETURN(ERROR_INVALID_PARAMETER);
  586. }
  587. if (4 < dwArgc)
  588. {
  589. if (0 == _tcsicmp(pptszArgv[4], _T("add")))
  590. {
  591. dwFlags = DFS_ADD_VOLUME;
  592. }
  593. else if (0 == _tcsicmp(pptszArgv[4], _T("restore")))
  594. {
  595. dwFlags = DFS_RESTORE_VOLUME;
  596. }
  597. else
  598. {
  599. RETURN(ERROR_INVALID_PARAMETER);
  600. }
  601. }
  602. if (5 < dwArgc)
  603. {
  604. if (0 != _tcsnicmp(pptszArgv[5],
  605. _T("/range:"),
  606. _tcslen(_T("/range:"))))
  607. {
  608. RETURN(ERROR_INVALID_PARAMETER);
  609. }
  610. ptszRange = pptszArgv[5]+_tcslen(_T("/range:"));
  611. if (NULL == (ptszMinus = _tcschr(ptszRange, _T('-'))))
  612. {
  613. RETURN(ERROR_INVALID_PARAMETER);
  614. }
  615. *ptszMinus = _T('\0');
  616. ulLo = _ttol(ptszRange);
  617. *ptszMinus = _T('-');
  618. ulHi = _ttol(ptszMinus+1);
  619. if (ulLo > ulHi)
  620. {
  621. RETURN(ERROR_INVALID_PARAMETER);
  622. }
  623. }
  624. MSG(fDebug,
  625. "Calling NetDfsAdd(%ws, %ws, %ws, %ws, %lu)\n",
  626. GetStringParam(pptszArgv[0]),
  627. GetStringParam(pptszArgv[1]),
  628. GetStringParam(pptszArgv[2]),
  629. GetStringParam(pptszArgv[3]),
  630. dwFlags);
  631. if (0 == ulLo && 0 == ulHi)
  632. {
  633. ulErr = APINetDfsAdd(GetStringParam(pptszArgv[0]),
  634. GetStringParam(pptszArgv[1]),
  635. GetStringParam(pptszArgv[2]),
  636. GetStringParam(pptszArgv[3]),
  637. dwFlags);
  638. }
  639. else
  640. {
  641. ULONG ulLen = 0;
  642. if (NULL != GetStringParam(pptszArgv[0]))
  643. {
  644. ulLen += _tcslen(GetStringParam(pptszArgv[0]));
  645. }
  646. ptszVolName = new TCHAR[ulLen+11];
  647. if (NULL != ptszVolName)
  648. {
  649. memset(ptszVolName, 0, (11+ulLen) * sizeof(TCHAR));
  650. if (NULL != GetStringParam(pptszArgv[0]))
  651. {
  652. _tcscpy(ptszVolName, GetStringParam(pptszArgv[0]));
  653. }
  654. for (ULONG i=ulLo;
  655. i <= ulHi && ERROR_SUCCESS == ulErr;
  656. i++)
  657. {
  658. memset(ptszVolName+ulLen, 0, sizeof(TCHAR)*11);
  659. _ltot(i, ptszVolName+ulLen, 10);
  660. ulErr = APINetDfsAdd(ptszVolName,
  661. GetStringParam(pptszArgv[1]),
  662. GetStringParam(pptszArgv[2]),
  663. GetStringParam(pptszArgv[3]),
  664. dwFlags);
  665. MSG(fDebug,
  666. "NetDfsAdd(%ws, %ws, %ws, %ws, %lu) %s\n",
  667. ptszVolName,
  668. GetStringParam(pptszArgv[1]),
  669. GetStringParam(pptszArgv[2]),
  670. GetStringParam(pptszArgv[3]),
  671. dwFlags,
  672. ((ERROR_SUCCESS == ulErr) ? "succeded" : "failed"));
  673. } //for
  674. delete [] ptszVolName;
  675. }
  676. else
  677. {
  678. MSG(fDebug,
  679. "Error %lu: not enough memory\n",
  680. ulErr = ERROR_NOT_ENOUGH_MEMORY);
  681. } //else
  682. } //else
  683. MSG(fDebug, "Exiting Add(..) with %lu\n", ulErr);
  684. RETURN(ulErr);
  685. }; //Add
  686. //+---------------------------------------------------------------------------
  687. //
  688. // Function: Remove
  689. //
  690. // Synopsis: This function performs NetDfsRemove.
  691. //
  692. // Arguments: [dwArg] the number of arguments
  693. // [pptszArg] the arguments
  694. //
  695. // Returns: ERROR_INVALID_PARAMETER
  696. //
  697. // Notes:
  698. //
  699. //----------------------------------------------------------------------------
  700. ULONG Remove(DWORD dwArgc, LPTSTR* pptszArgv)
  701. {
  702. ULONG ulErr = ERROR_SUCCESS;
  703. MSG(fDebug, "Entering Remove(%lu,..)\n", dwArgc);
  704. if (dwArgc < 1 || dwArgc > 3 || NULL == pptszArgv ||
  705. dwArgc > 1 && NULL == pptszArgv[1] ||
  706. dwArgc > 2 && NULL == pptszArgv[2] ||
  707. 2 == dwArgc)
  708. {
  709. MSG(fDebug,
  710. "%lu < 1 || %lu > 3 || NULL == pptszArgv ||"
  711. " %lu > 1 && NULL == %ws ||"
  712. " %lu > 2 && NULL == %ws ||"
  713. " 2 == %lu",
  714. dwArgc, dwArgc, dwArgc, pptszArgv[1], dwArgc,
  715. pptszArgv[2], dwArgc);
  716. RETURN(ERROR_INVALID_PARAMETER);
  717. } //if
  718. MSG(fDebug, "Calling NetDfsRemove(%ws, %ws, %ws)\n",
  719. GetStringParam(pptszArgv[0]),
  720. GetStringParam(pptszArgv[1]),
  721. GetStringParam(pptszArgv[2]));
  722. ulErr = APINetDfsRemove(GetStringParam(pptszArgv[0]),
  723. GetStringParam(pptszArgv[1]),
  724. GetStringParam(pptszArgv[2]));
  725. MSG(fDebug, "Exiting Remove(..) with %lu\n", ulErr);
  726. RETURN(ulErr);
  727. }; //Remove
  728. //+---------------------------------------------------------------------------
  729. //
  730. // Function: Enum
  731. //
  732. // Synopsis: This function performs NetDfsEnum.
  733. //
  734. // Arguments: [dwArg] the number of arguments
  735. // [pptszArg] the arguments
  736. //
  737. // Returns: ERROR_INVALID_PARAMETER
  738. //
  739. // Notes:
  740. //
  741. //----------------------------------------------------------------------------
  742. ULONG Enum(DWORD dwArgc, LPTSTR* pptszArgv)
  743. {
  744. ULONG ulErr = ERROR_SUCCESS;
  745. DWORD dwLevel = 0;
  746. DWORD dwPrefMaxLen = (DWORD)-1;
  747. LPBYTE pBuffer = NULL;
  748. DWORD dwEntriesRead = 0;
  749. DWORD dwResumeHandle = 0;
  750. MSG(fDebug, "Entering Enum(%lu,..)\n",
  751. dwArgc);
  752. if (dwArgc < 2 ||
  753. NULL == pptszArgv)
  754. {
  755. MSG(fDebug,
  756. "%lu < 2 || NULL == pptszArgv\n",
  757. dwArgc);
  758. RETURN(ERROR_INVALID_PARAMETER);
  759. }
  760. if (0 == _tcsicmp(pptszArgv[1], _T("1")))
  761. {
  762. dwLevel = 1;
  763. dwPrefMaxLen = sizeof(DFS_INFO_1);
  764. }
  765. else if (0 == _tcsicmp(pptszArgv[1], _T("2")))
  766. {
  767. dwLevel = 2;
  768. dwPrefMaxLen = sizeof(DFS_INFO_2);
  769. }
  770. else if (0 == _tcsicmp(pptszArgv[1], _T("3")))
  771. {
  772. dwLevel = 3;
  773. dwPrefMaxLen = sizeof(DFS_INFO_3);
  774. }
  775. else if (0 == _tcsicmp(pptszArgv[1], _T("4")))
  776. {
  777. dwLevel = 4;
  778. dwPrefMaxLen = sizeof(DFS_INFO_4);
  779. }
  780. else if (0 == _tcsicmp(pptszArgv[1], _T("200")))
  781. {
  782. dwLevel = 200;
  783. dwPrefMaxLen = sizeof(DFS_INFO_200);
  784. }
  785. else
  786. {
  787. RETURN(ERROR_INVALID_PARAMETER);
  788. }
  789. if (2 == dwArgc)
  790. {
  791. dwPrefMaxLen = (DWORD)-1;
  792. }
  793. else
  794. {
  795. if (3 != dwArgc || NULL == pptszArgv[2] ||
  796. 0 >= _ttoi(pptszArgv[2]))
  797. {
  798. RETURN(ERROR_INVALID_PARAMETER);
  799. } //if
  800. dwPrefMaxLen *= _ttoi(pptszArgv[2]);
  801. }
  802. MSG(fDebug, "Calling NetDfsEnum(%ws,%lu,%lu,..,..,%lu)\n",
  803. pptszArgv[0], dwLevel, dwPrefMaxLen, dwResumeHandle);
  804. ulErr = APINetDfsEnum(GetStringParam(pptszArgv[0]),
  805. dwLevel,
  806. dwPrefMaxLen,
  807. &pBuffer,
  808. &dwEntriesRead,
  809. &dwResumeHandle);
  810. if (ERROR_SUCCESS != ulErr)
  811. {
  812. goto Error;
  813. }
  814. if ((DWORD)-1 == dwPrefMaxLen)
  815. {
  816. LPBYTE pCurBuffer = pBuffer;
  817. for (DWORD i=0; i<dwEntriesRead; i++)
  818. {
  819. ulErr = PrintDfsInfo(dwLevel, pCurBuffer);
  820. if (ERROR_SUCCESS != ulErr)
  821. {
  822. goto Error;
  823. }
  824. switch (dwLevel)
  825. {
  826. case 1:
  827. pCurBuffer = (LPBYTE)(((PDFS_INFO_1)pCurBuffer)+1);
  828. break;
  829. case 2:
  830. pCurBuffer = (LPBYTE)(((PDFS_INFO_2)pCurBuffer)+1);
  831. break;
  832. case 3:
  833. pCurBuffer = (LPBYTE)(((PDFS_INFO_3)pCurBuffer)+1);
  834. break;
  835. case 4:
  836. pCurBuffer = (LPBYTE)(((PDFS_INFO_4)pCurBuffer)+1);
  837. break;
  838. case 200:
  839. pCurBuffer = (LPBYTE)(((PDFS_INFO_200)pCurBuffer)+1);
  840. break;
  841. default:
  842. ulErr = ERROR_INVALID_PARAMETER;
  843. goto Error;
  844. } //switch
  845. } //for
  846. }
  847. else
  848. {
  849. do
  850. {
  851. LPBYTE pCurBuffer = pBuffer;
  852. for (DWORD i=0; i<dwEntriesRead; i++)
  853. {
  854. ulErr = PrintDfsInfo(dwLevel, pCurBuffer);
  855. if (ERROR_SUCCESS != ulErr)
  856. {
  857. goto Error;
  858. }
  859. switch (dwLevel)
  860. {
  861. case 1:
  862. pCurBuffer = (LPBYTE)(((PDFS_INFO_1)pCurBuffer)+1);
  863. break;
  864. case 2:
  865. pCurBuffer = (LPBYTE)(((PDFS_INFO_2)pCurBuffer)+1);
  866. break;
  867. case 3:
  868. pCurBuffer = (LPBYTE)(((PDFS_INFO_3)pCurBuffer)+1);
  869. break;
  870. case 4:
  871. pCurBuffer = (LPBYTE)(((PDFS_INFO_4)pCurBuffer)+1);
  872. break;
  873. case 200:
  874. pCurBuffer = (LPBYTE)(((PDFS_INFO_200)pCurBuffer)+1);
  875. break;
  876. default:
  877. ulErr = ERROR_INVALID_PARAMETER;
  878. goto Error;
  879. } //switch
  880. } //for
  881. if (NULL != pBuffer)
  882. {
  883. NetApiBufferFree(pBuffer);
  884. pBuffer = NULL;
  885. }
  886. MSG(fDebug,
  887. "Calling NetDfsEnum(%ws, %lu, %lu,..,..,%lu)\n",
  888. GetStringParam(pptszArgv[0]),
  889. dwLevel,
  890. dwPrefMaxLen,
  891. dwResumeHandle);
  892. ulErr = APINetDfsEnum(
  893. GetStringParam(pptszArgv[0]),
  894. dwLevel,
  895. dwPrefMaxLen,
  896. &pBuffer,
  897. &dwEntriesRead,
  898. &dwResumeHandle);
  899. if (ERROR_NO_MORE_ITEMS == ulErr)
  900. {
  901. if (0 != dwEntriesRead)
  902. {
  903. continue;
  904. }
  905. else
  906. {
  907. ulErr = ERROR_SUCCESS;
  908. break;
  909. }
  910. } //if
  911. if (ERROR_SUCCESS != ulErr)
  912. {
  913. goto Error;
  914. }
  915. }
  916. while(TRUE);
  917. } //else
  918. Error:;
  919. if (NULL != pBuffer)
  920. {
  921. NetApiBufferFree(pBuffer);
  922. pBuffer = NULL;
  923. }
  924. MSG(fDebug,
  925. "Exiting Enum with %lu\n",
  926. ulErr);
  927. RETURN(ulErr);
  928. }; //Enum
  929. //+---------------------------------------------------------------------------
  930. //
  931. // Function: GetInfo
  932. //
  933. // Synopsis: This function performs NetDfsGetInfo.
  934. //
  935. // Arguments: [dwArg] the number of arguments
  936. // [pptszArg] the arguments
  937. //
  938. // Returns: ERROR_INVALID_PARAMETER
  939. //
  940. // Notes:
  941. //
  942. //----------------------------------------------------------------------------
  943. ULONG GetInfo(DWORD dwArgc, LPTSTR* pptszArgv)
  944. {
  945. ULONG ulErr = ERROR_SUCCESS;
  946. DWORD dwLevel = 0;
  947. LPBYTE pBuffer = NULL;
  948. MSG(fDebug,
  949. "Entering GetInfo(%lu,..)\n",
  950. dwArgc);
  951. if (4 != dwArgc || NULL == pptszArgv)
  952. {
  953. MSG(fDebug, "4 != %lu || NULL == pptszArgv",
  954. dwArgc);
  955. RETURN(ERROR_INVALID_PARAMETER);
  956. }
  957. if (0 == _tcsicmp(pptszArgv[3], _T("1")))
  958. {
  959. dwLevel = 1;
  960. }
  961. else if (0 == _tcsicmp(pptszArgv[3], _T("2")))
  962. {
  963. dwLevel = 2;
  964. }
  965. else if (0 == _tcsicmp(pptszArgv[3], _T("3")))
  966. {
  967. dwLevel = 3;
  968. }
  969. else if (0 == _tcsicmp(pptszArgv[3], _T("4")))
  970. {
  971. dwLevel = 4;
  972. }
  973. else if (0 == _tcsicmp(pptszArgv[3], _T("100")))
  974. {
  975. dwLevel = 100;
  976. }
  977. else
  978. {
  979. RETURN(ERROR_INVALID_PARAMETER);
  980. }
  981. MSG(fDebug, "Calling NetDfsGetInfo(%ws,%ws,%ws,%lu,..)\n",
  982. GetStringParam(pptszArgv[0]),
  983. GetStringParam(pptszArgv[1]),
  984. GetStringParam(pptszArgv[2]),
  985. dwLevel);
  986. ulErr = APINetDfsGetInfo(
  987. GetStringParam(pptszArgv[0]),
  988. GetStringParam(pptszArgv[1]),
  989. GetStringParam(pptszArgv[2]),
  990. dwLevel,
  991. &pBuffer);
  992. if (ERROR_SUCCESS == ulErr)
  993. {
  994. ulErr = PrintDfsInfo(dwLevel, pBuffer);
  995. }
  996. if (NULL != pBuffer)
  997. {
  998. NetApiBufferFree(pBuffer);
  999. pBuffer = NULL;
  1000. }
  1001. MSG(fDebug, "Exiting GetInfo(..) with %lu\n", ulErr);
  1002. RETURN(ulErr);
  1003. }; //GetInfo
  1004. //+---------------------------------------------------------------------------
  1005. //
  1006. // Function: AddStdRoot
  1007. //
  1008. // Synopsis: This function performs NetDfsAddStdRoot.
  1009. //
  1010. // Arguments: [dwArg] the number of arguments
  1011. // [pptszArg] the arguments
  1012. //
  1013. // Returns: ERROR_INVALID_PARAMETER
  1014. //
  1015. // Notes:
  1016. //
  1017. //----------------------------------------------------------------------------
  1018. ULONG AddStdRoot(DWORD dwArgc, LPTSTR* pptszArgv)
  1019. {
  1020. ULONG ulErr = ERROR_SUCCESS;
  1021. DWORD dwOptions = 0;
  1022. MSG(fDebug,
  1023. "Entering AddStdRoot(%lu,..)\n",
  1024. dwArgc);
  1025. if (dwArgc < 2 || dwArgc > 4 || NULL == pptszArgv)
  1026. {
  1027. MSG(fDebug,
  1028. "%lu < 3 || "
  1029. "%lu > 4 || "
  1030. "NULL == pptszArgv\n",
  1031. dwArgc, dwArgc);
  1032. RETURN(ERROR_INVALID_PARAMETER);
  1033. } //if
  1034. if (4 == dwArgc)
  1035. {
  1036. dwOptions = _ttoi(pptszArgv[3]);
  1037. }
  1038. MSG(fDebug,
  1039. "Calling NetDfsAddStdRoot(%ws,%ws,%ws,%lu)\n",
  1040. GetStringParam(pptszArgv[0]),
  1041. GetStringParam(pptszArgv[1]),
  1042. GetStringParam(pptszArgv[2]),
  1043. dwOptions);
  1044. ulErr = APINetDfsAddStdRoot(
  1045. GetStringParam(pptszArgv[0]),
  1046. GetStringParam(pptszArgv[1]),
  1047. GetStringParam(pptszArgv[2]),
  1048. dwOptions);
  1049. MSG(fDebug, "Exiting AddStdRoot(..) with %lu\n", ulErr);
  1050. RETURN(ulErr);
  1051. }; //AddStdRoot
  1052. //+---------------------------------------------------------------------------
  1053. //
  1054. // Function: RemoveStdRoot
  1055. //
  1056. // Synopsis: This function performs NetDfsRemoveStdRoot.
  1057. //
  1058. // Arguments: [dwArg] the number of arguments
  1059. // [pptszArg] the arguments
  1060. //
  1061. // Returns: ERROR_INVALID_PARAMETER
  1062. //
  1063. // Notes:
  1064. //
  1065. //----------------------------------------------------------------------------
  1066. ULONG RemoveStdRoot(DWORD dwArgc, LPTSTR* pptszArgv)
  1067. {
  1068. ULONG ulErr = ERROR_SUCCESS;
  1069. DWORD dwOptions = 0;
  1070. MSG(fDebug,
  1071. "Entering RemoveStdRoot(%lu,..)\n",
  1072. dwArgc);
  1073. if (dwArgc < 2 || dwArgc > 3 || NULL == pptszArgv)
  1074. {
  1075. MSG(fDebug,
  1076. "%lu < 2 || %lu > 3 || NULL == pptszArgv\n",
  1077. dwArgc, dwArgc);
  1078. RETURN(ERROR_INVALID_PARAMETER);
  1079. } //if
  1080. if (3 == dwArgc)
  1081. {
  1082. dwOptions = _ttoi(pptszArgv[2]);
  1083. }
  1084. MSG(fDebug,
  1085. "Calling NetDfsRemoveStdRoot"
  1086. "(%ws,%ws,%lu)\n",
  1087. GetStringParam(pptszArgv[0]),
  1088. GetStringParam(pptszArgv[1]),
  1089. dwOptions);
  1090. ulErr = APINetDfsRemoveStdRoot(
  1091. GetStringParam(pptszArgv[0]),
  1092. GetStringParam(pptszArgv[1]),
  1093. dwOptions);
  1094. MSG(fDebug,
  1095. "Exiting RemoveStdRoot(..) with %lu\n",
  1096. ulErr);
  1097. RETURN(ulErr);
  1098. }; //RemoveStdRoot
  1099. //+---------------------------------------------------------------------------
  1100. //
  1101. // Function: SetInfo
  1102. //
  1103. // Synopsis: This function performs NetDfsSetInfo.
  1104. //
  1105. // Arguments: [dwArg] the number of arguments
  1106. // [pptszArg] the arguments
  1107. //
  1108. // Returns: ERROR_INVALID_PARAMETER
  1109. //
  1110. // Notes:
  1111. //
  1112. //----------------------------------------------------------------------------
  1113. ULONG SetInfo(DWORD dwArgc, LPTSTR* pptszArgv)
  1114. {
  1115. ULONG ulErr = ERROR_SUCCESS;
  1116. DWORD dwFlags = 0;
  1117. DWORD dwTimeout = 0;
  1118. DWORD i = 0;
  1119. MSG(fDebug,
  1120. "Calling SetInfo(%lu,..)\n",
  1121. dwArgc);
  1122. if (dwArgc < 4 || NULL == pptszArgv)
  1123. {
  1124. MSG(fDebug,
  1125. "%lu < 4 || NULL == pptszArgv",
  1126. dwArgc);
  1127. RETURN(ERROR_INVALID_PARAMETER);
  1128. } //if
  1129. if (0 == _tcsicmp(pptszArgv[3], _T("100")))
  1130. {
  1131. DFS_INFO_100 info;
  1132. if (4 < dwArgc)
  1133. {
  1134. if (5 != dwArgc)
  1135. {
  1136. MSG(fDebug,
  1137. "%ws == \"100\" && 5 != %dwArgc\n",
  1138. pptszArgv[3], dwArgc);
  1139. RETURN(ERROR_INVALID_PARAMETER);
  1140. }
  1141. info.Comment = pptszArgv[4];
  1142. } //if
  1143. MSG(fDebug,
  1144. "Calling NetDfsSetInfo(%ws,%ws,%ws,%lu,..)\n",
  1145. GetStringParam(pptszArgv[0]),
  1146. GetStringParam(pptszArgv[1]),
  1147. GetStringParam(pptszArgv[2]),
  1148. 100);
  1149. ulErr = APINetDfsSetInfo(
  1150. GetStringParam(pptszArgv[0]),
  1151. GetStringParam(pptszArgv[1]),
  1152. GetStringParam(pptszArgv[2]),
  1153. 100,
  1154. (LPBYTE)&info);
  1155. }
  1156. else if (0 == _tcsicmp(pptszArgv[3], _T("101")))
  1157. {
  1158. DFS_INFO_101 info;
  1159. info.State = 0;
  1160. if (4 < dwArgc)
  1161. {
  1162. if (8 < dwArgc)
  1163. {
  1164. MSG(fDebug,
  1165. "%ws==\"101\" && "
  1166. "4 < %lu && "
  1167. "8 < %lu",
  1168. pptszArgv[3], dwArgc, dwArgc);
  1169. RETURN(ERROR_INVALID_PARAMETER);
  1170. } //if
  1171. if (NULL != GetStringParam(pptszArgv[1]))
  1172. {
  1173. if (NULL == GetStringParam(pptszArgv[2]))
  1174. {
  1175. MSG(fDebug,
  1176. "4 < %lu && "
  1177. "NULL != %ws && "
  1178. "NULL == %ws\n",
  1179. dwArgc, GetStringParam(pptszArgv[1]),
  1180. GetStringParam(pptszArgv[2]));
  1181. RETURN(ERROR_INVALID_PARAMETER);
  1182. }
  1183. for (i = 4; i<dwArgc; i++)
  1184. {
  1185. if (0 == _tcsicmp(pptszArgv[i], _T("active")))
  1186. {
  1187. if (0 != (info.State & DFS_STORAGE_STATE_ACTIVE))
  1188. {
  1189. RETURN(ERROR_INVALID_PARAMETER);
  1190. }
  1191. info.State |= DFS_STORAGE_STATE_ACTIVE;
  1192. }
  1193. else if (0 == _tcsicmp(pptszArgv[i], _T("offline")))
  1194. {
  1195. if (0 != (info.State & DFS_STORAGE_STATE_OFFLINE))
  1196. {
  1197. RETURN(ERROR_INVALID_PARAMETER);
  1198. }
  1199. info.State |= DFS_STORAGE_STATE_OFFLINE;
  1200. }
  1201. else if (0 == _tcsicmp(pptszArgv[i], _T("online")))
  1202. {
  1203. if (0 != (info.State & DFS_STORAGE_STATE_ONLINE))
  1204. {
  1205. RETURN(ERROR_INVALID_PARAMETER);
  1206. }
  1207. info.State |= DFS_STORAGE_STATE_ONLINE;
  1208. }
  1209. else
  1210. {
  1211. RETURN(ERROR_INVALID_PARAMETER);
  1212. }
  1213. } //for i
  1214. }
  1215. else
  1216. {
  1217. if (0 == _tcsicmp(pptszArgv[i], _T("ok")))
  1218. {
  1219. info.State = DFS_VOLUME_STATE_OK;
  1220. }
  1221. else if (0 == _tcsicmp(pptszArgv[i], _T("inconsistent")))
  1222. {
  1223. info.State = DFS_VOLUME_STATE_INCONSISTENT;
  1224. }
  1225. else if (0 == _tcsicmp(pptszArgv[i], _T("offline")))
  1226. {
  1227. info.State = DFS_VOLUME_STATE_OFFLINE;
  1228. }
  1229. else if (0 == _tcsicmp(pptszArgv[i], _T("online")))
  1230. {
  1231. info.State = DFS_VOLUME_STATE_ONLINE;
  1232. }
  1233. else
  1234. {
  1235. RETURN(ERROR_INVALID_PARAMETER);
  1236. }
  1237. } //else
  1238. } //if
  1239. MSG(fDebug,
  1240. "Calling NetDfsSetInfo(%ws,%ws,%ws,%lu,..)\n",
  1241. GetStringParam(pptszArgv[0]),
  1242. GetStringParam(pptszArgv[1]),
  1243. GetStringParam(pptszArgv[2]),
  1244. 101);
  1245. ulErr = APINetDfsSetInfo(GetStringParam(pptszArgv[0]),
  1246. GetStringParam(pptszArgv[1]),
  1247. GetStringParam(pptszArgv[2]),
  1248. 101,
  1249. (LPBYTE)&info);
  1250. }
  1251. else if (0 == _tcsicmp(pptszArgv[3], _T("102")))
  1252. {
  1253. DFS_INFO_102 info;
  1254. if (5 != dwArgc)
  1255. {
  1256. MSG(fDebug,
  1257. "%ws==\"102\" && "
  1258. "5 != %lu\n",
  1259. pptszArgv[3], dwArgc);
  1260. RETURN(ERROR_INVALID_PARAMETER);
  1261. } //if
  1262. if (0 == _tcsicmp(pptszArgv[4], _T("0")))
  1263. {
  1264. dwTimeout = 0;
  1265. }
  1266. else
  1267. {
  1268. if (0 == (dwTimeout = _ttoi(pptszArgv[4])))
  1269. {
  1270. MSG(fDebug,
  1271. "%ws==\"102\" && "
  1272. "0 == %lu\n",
  1273. pptszArgv[4],
  1274. dwTimeout);
  1275. RETURN(ERROR_INVALID_PARAMETER);
  1276. } //if
  1277. } //else
  1278. info.Timeout = dwTimeout;
  1279. MSG(fDebug,
  1280. "Calling NetDfsSetInfo(%ws,%ws,%ws,%lu,..)\n",
  1281. GetStringParam(pptszArgv[0]),
  1282. GetStringParam(pptszArgv[1]),
  1283. GetStringParam(pptszArgv[2]),
  1284. 102);
  1285. ulErr = APINetDfsSetInfo(
  1286. GetStringParam(pptszArgv[0]),
  1287. GetStringParam(pptszArgv[1]),
  1288. GetStringParam(pptszArgv[2]),
  1289. 102,
  1290. (LPBYTE)&info);
  1291. }
  1292. else
  1293. {
  1294. MSG(fDebug, "Invalid first parameter\n");
  1295. RETURN(ERROR_INVALID_PARAMETER);
  1296. }
  1297. MSG(fDebug,
  1298. "Exiting SetInfo(..) with %lu", ulErr);
  1299. RETURN(ulErr);
  1300. }; //SetInfo
  1301. #if 0
  1302. //+---------------------------------------------------------------------------
  1303. //
  1304. // Function: GetClientInfo
  1305. //
  1306. // Synopsis: This function performs NetDfsGetClientInfo.
  1307. //
  1308. // Arguments: [dwArg] the number of arguments
  1309. // [pptszArg] the arguments
  1310. //
  1311. // Returns: ERROR_INVALID_PARAMETER
  1312. //
  1313. // Notes:
  1314. //
  1315. //----------------------------------------------------------------------------
  1316. ULONG GetClientInfo(DWORD dwArgc, LPTSTR* pptszArgv)
  1317. {
  1318. ULONG ulErr = ERROR_SUCCESS;
  1319. DWORD dwLevel = 0;
  1320. LPBYTE pBuffer = NULL;
  1321. MSG(fDebug,
  1322. "Entering GetClientInfo(%lu,..)\n",
  1323. dwArgc);
  1324. if (4 != dwArgc || NULL == pptszArgv)
  1325. {
  1326. MSG(fDebug,
  1327. "4 != %lu || NULL == pptszArgv",
  1328. dwArgc);
  1329. RETURN(ERROR_INVALID_PARAMETER);
  1330. }
  1331. if (0 == _tcsicmp(pptszArgv[3], _T("1")))
  1332. {
  1333. dwLevel = 1;
  1334. }
  1335. else if (0 == _tcsicmp(pptszArgv[3], _T("2")))
  1336. {
  1337. dwLevel = 2;
  1338. }
  1339. else if (0 == _tcsicmp(pptszArgv[3], _T("3")))
  1340. {
  1341. dwLevel = 3;
  1342. }
  1343. else if (0 == _tcsicmp(pptszArgv[3], _T("4")))
  1344. {
  1345. dwLevel = 4;
  1346. }
  1347. else
  1348. {
  1349. RETURN(ERROR_INVALID_PARAMETER);
  1350. }
  1351. MSG(fDebug,
  1352. "Calling NetDfsGetClientInfo"
  1353. "(%ws,%ws,%ws,%lu,..)\n",
  1354. GetStringParam(pptszArgv[0]),
  1355. GetStringParam(pptszArgv[1]),
  1356. GetStringParam(pptszArgv[2]),
  1357. dwLevel);
  1358. ulErr = NetDfsGetClientInfo(
  1359. GetStringParam(pptszArgv[0]),
  1360. GetStringParam(pptszArgv[1]),
  1361. GetStringParam(pptszArgv[2]),
  1362. dwLevel,
  1363. &pBuffer);
  1364. if (ERROR_SUCCESS == ulErr)
  1365. {
  1366. ulErr = PrintDfsInfo(dwLevel, pBuffer);
  1367. }
  1368. if (NULL != pBuffer)
  1369. {
  1370. NetApiBufferFree(pBuffer);
  1371. pBuffer = NULL;
  1372. }
  1373. MSG(fDebug, "Exiting GetClientInfo(..) with %lu\n", ulErr);
  1374. RETURN(ulErr);
  1375. }; //GetClientInfo
  1376. //+---------------------------------------------------------------------------
  1377. //
  1378. // Function: SetClientInfo
  1379. //
  1380. // Synopsis: This function performs NetDfsSetClientInfo.
  1381. //
  1382. // Arguments: [dwArg] the number of arguments
  1383. // [pptszArg] the arguments
  1384. //
  1385. // Returns: ERROR_INVALID_PARAMETER
  1386. //
  1387. // Notes:
  1388. //
  1389. //----------------------------------------------------------------------------
  1390. ULONG SetClientInfo(DWORD dwArgc, LPTSTR* pptszArgv)
  1391. {
  1392. ULONG ulErr = ERROR_SUCCESS;
  1393. DWORD dwFlags = 0;
  1394. DWORD dwTimeout = 0;
  1395. DWORD i = 0;
  1396. MSG(fDebug, "Entering SetClientInfo(%lu,..)\n",
  1397. dwArgc);
  1398. if (dwArgc < 4 || NULL == pptszArgv)
  1399. {
  1400. MSG(fDebug,
  1401. "%lu < 4 || NULL == pptszArgv\n",
  1402. dwArgc);
  1403. RETURN(ERROR_INVALID_PARAMETER);
  1404. } //if
  1405. if (0 == _tcsicmp(pptszArgv[3], _T("101")))
  1406. {
  1407. DFS_INFO_101 info;
  1408. info.State = 0;
  1409. if (4 < dwArgc)
  1410. {
  1411. if (8 < dwArgc)
  1412. {
  1413. MSG(fDebug,
  1414. "%ws == \"101\" && "
  1415. "4 < %lu && "
  1416. "8 < %lu\n",
  1417. pptszArgv[3],
  1418. dwArgc,
  1419. dwArgc);
  1420. RETURN(ERROR_INVALID_PARAMETER);
  1421. } //if
  1422. for (i = 4; i<dwArgc; i++)
  1423. {
  1424. if (0 == _tcsicmp(pptszArgv[i], _T("active")))
  1425. {
  1426. if (0 != (info.State & DFS_STORAGE_STATE_ACTIVE))
  1427. {
  1428. RETURN(ERROR_INVALID_PARAMETER);
  1429. }
  1430. info.State |= DFS_STORAGE_STATE_ACTIVE;
  1431. }
  1432. else if (0 == _tcsicmp(pptszArgv[i], _T("offline")))
  1433. {
  1434. if (0 != (info.State & DFS_STORAGE_STATE_OFFLINE))
  1435. {
  1436. RETURN(ERROR_INVALID_PARAMETER);
  1437. }
  1438. info.State |= DFS_STORAGE_STATE_OFFLINE;
  1439. }
  1440. else if (0 == _tcsicmp(pptszArgv[i], _T("online")))
  1441. {
  1442. if (0 != (info.State & DFS_STORAGE_STATE_ONLINE))
  1443. {
  1444. RETURN(ERROR_INVALID_PARAMETER);
  1445. }
  1446. info.State |= DFS_STORAGE_STATE_ONLINE;
  1447. }
  1448. else
  1449. {
  1450. RETURN(ERROR_INVALID_PARAMETER);
  1451. }
  1452. } //for i
  1453. } //if
  1454. MSG(fDebug,
  1455. "Calling NetDfsSetClientInfo(%ws,%ws,%ws,%lu,..)\n",
  1456. GetStringParam(pptszArgv[0]),
  1457. GetStringParam(pptszArgv[1]),
  1458. GetStringParam(pptszArgv[2]),
  1459. 101);
  1460. ulErr = NetDfsSetClientInfo(GetStringParam(pptszArgv[0]),
  1461. GetStringParam(pptszArgv[1]),
  1462. GetStringParam(pptszArgv[2]),
  1463. 101,
  1464. (LPBYTE)&info);
  1465. }
  1466. else if (0 == _tcsicmp(pptszArgv[3], _T("102")))
  1467. {
  1468. DFS_INFO_102 info;
  1469. if (5 != dwArgc)
  1470. {
  1471. MSG(fDebug,
  1472. "%ws==\"102\" && "
  1473. "5 != %lu\n",
  1474. pptszArgv[3], dwArgc);
  1475. RETURN(ERROR_INVALID_PARAMETER);
  1476. }
  1477. if (0 == _tcsicmp(pptszArgv[4], _T("0")))
  1478. {
  1479. dwTimeout = 0;
  1480. }
  1481. else
  1482. {
  1483. if (0 == (dwTimeout = _ttoi(pptszArgv[4])))
  1484. {
  1485. MSG(fDebug,
  1486. "%ws==\"102\" && "
  1487. "0 == %lu\n",
  1488. pptszArgv[3], dwArgc);
  1489. RETURN(ERROR_INVALID_PARAMETER);
  1490. } //if
  1491. } //else
  1492. info.Timeout = dwTimeout;
  1493. MSG(fDebug,
  1494. "Calling NetDfsSetClientInfo"
  1495. "(%ws,%ws,%ws,%lu,..)\n",
  1496. GetStringParam(pptszArgv[0]),
  1497. GetStringParam(pptszArgv[1]),
  1498. GetStringParam(pptszArgv[2]),
  1499. 102);
  1500. ulErr = NetDfsSetClientInfo(GetStringParam(pptszArgv[0]),
  1501. GetStringParam(pptszArgv[1]),
  1502. GetStringParam(pptszArgv[2]),
  1503. 102,
  1504. (LPBYTE)&info);
  1505. }
  1506. else
  1507. {
  1508. MSG(fDebug, "Invalid first parameter\n");
  1509. RETURN(ERROR_INVALID_PARAMETER);
  1510. }
  1511. MSG(fDebug, "Exiting SetClientInfo(..) with %lu\n", ulErr);
  1512. RETURN(ulErr);
  1513. }; //SetClientInfo
  1514. //+---------------------------------------------------------------------------
  1515. //
  1516. // Function: AddFtRoot
  1517. //
  1518. // Synopsis: This function performs NetDfsAddFtRoot.
  1519. //
  1520. // Arguments: [dwArg] the number of arguments
  1521. // [pptszArg] the arguments
  1522. //
  1523. // Returns: ERROR_INVALID_PARAMETER
  1524. //
  1525. // Notes:
  1526. //
  1527. //----------------------------------------------------------------------------
  1528. ULONG AddFtRoot(DWORD dwArgc, LPTSTR* pptszArgv)
  1529. {
  1530. ULONG ulErr = ERROR_SUCCESS;
  1531. DWORD dwOptions = 0;
  1532. MSG(fDebug,
  1533. "Entering AddFtRoot(%lu,..)\n",
  1534. dwArgc);
  1535. if (dwArgc < 3 || dwArgc > 5 || NULL == pptszArgv)
  1536. {
  1537. MSG(fDebug,
  1538. "%lu < 3 || "
  1539. "%lu > 4 || "
  1540. "NULL == pptszArgv\n",
  1541. dwArgc, dwArgc);
  1542. RETURN(ERROR_INVALID_PARAMETER);
  1543. } //if
  1544. if (5 == dwArgc)
  1545. {
  1546. dwOptions = _ttoi(pptszArgv[4]);
  1547. }
  1548. MSG(fDebug,
  1549. "Calling NetDfsAddFtRoot(%ws,%ws,%ws,%ws,%lu)\n",
  1550. GetStringParam(pptszArgv[0]),
  1551. GetStringParam(pptszArgv[1]),
  1552. GetStringParam(pptszArgv[2]),
  1553. GetStringParam(pptszArgv[3]),
  1554. dwOptions);
  1555. ulErr = NetDfsAddFtRoot(GetStringParam(pptszArgv[0]),
  1556. GetStringParam(pptszArgv[1]),
  1557. GetStringParam(pptszArgv[2]),
  1558. GetStringParam(pptszArgv[3]),
  1559. dwOptions);
  1560. MSG(fDebug, "Exiting AddFtRoot(..) with %lu\n", ulErr);
  1561. RETURN(ulErr);
  1562. }; //AddFtRoot
  1563. //+---------------------------------------------------------------------------
  1564. //
  1565. // Function: RemoveFtRoot
  1566. //
  1567. // Synopsis: This function performs NetDfsRemoveFtRoot.
  1568. //
  1569. // Arguments: [dwArg] the number of arguments
  1570. // [pptszArg] the arguments
  1571. //
  1572. // Returns: ERROR_INVALID_PARAMETER
  1573. //
  1574. // Notes:
  1575. //
  1576. //----------------------------------------------------------------------------
  1577. ULONG RemoveFtRoot(DWORD dwArgc, LPTSTR* pptszArgv)
  1578. {
  1579. ULONG ulErr = ERROR_SUCCESS;
  1580. DWORD dwOptions = 0;
  1581. MSG(fDebug,
  1582. "Entering RemoveFtRoot(%lu,..)\n",
  1583. dwArgc);
  1584. if (dwArgc < 3 || dwArgc > 4 || NULL == pptszArgv)
  1585. {
  1586. MSG(fDebug,
  1587. "%lu < 3 || %lu > 4 || NULL == pptszArgv\n",
  1588. dwArgc, dwArgc);
  1589. RETURN(ERROR_INVALID_PARAMETER);
  1590. } //if
  1591. if (4 == dwArgc)
  1592. {
  1593. dwOptions = _ttoi(pptszArgv[3]);
  1594. }
  1595. //
  1596. // BUGBUG
  1597. //
  1598. // for the time being we ignore every option
  1599. //
  1600. dwOptions = 0;
  1601. MSG(fDebug,
  1602. "Calling NetDfsRemoveFtRoot"
  1603. "(%ws,%ws,%ws,%lu)\n",
  1604. GetStringParam(pptszArgv[0]),
  1605. GetStringParam(pptszArgv[1]),
  1606. GetStringParam(pptszArgv[2]),
  1607. dwOptions);
  1608. ulErr = NetDfsRemoveFtRoot(GetStringParam(pptszArgv[0]),
  1609. GetStringParam(pptszArgv[1]),
  1610. GetStringParam(pptszArgv[2]),
  1611. dwOptions);
  1612. MSG(fDebug,
  1613. "Exiting RemoveFtRoot(..) with %lu\n",
  1614. ulErr);
  1615. RETURN(ulErr);
  1616. }; //RemoveFtRoot
  1617. //+---------------------------------------------------------------------------
  1618. //
  1619. // Function: RemoveFtRootForced
  1620. //
  1621. // Synopsis: This function performs NetDfsRemoveFtRootForced.
  1622. //
  1623. // Arguments: [dwArg] the number of arguments
  1624. // [pptszArg] the arguments
  1625. //
  1626. // Returns: ERROR_INVALID_PARAMETER
  1627. //
  1628. // Notes:
  1629. //
  1630. //----------------------------------------------------------------------------
  1631. ULONG RemoveFtRootForced(DWORD dwArgc, LPTSTR* pptszArgv)
  1632. {
  1633. ULONG ulErr = ERROR_SUCCESS;
  1634. DWORD dwOptions = 0;
  1635. MSG(fDebug,
  1636. "Entering RemoveFtRootForced(%lu,..)\n",
  1637. dwArgc);
  1638. if (dwArgc < 4 || dwArgc > 5 || NULL == pptszArgv)
  1639. {
  1640. MSG(fDebug,
  1641. "%lu < 4 || %lu > 5 || NULL == pptszArgv\n",
  1642. dwArgc, dwArgc);
  1643. RETURN(ERROR_INVALID_PARAMETER);
  1644. } //if
  1645. if (5 == dwArgc)
  1646. {
  1647. dwOptions = _ttoi(pptszArgv[3]);
  1648. }
  1649. //
  1650. // BUGBUG
  1651. //
  1652. // for the time being we ignore every option
  1653. //
  1654. dwOptions = 0;
  1655. MSG(fDebug,
  1656. "Calling NetDfsRemoveFtRootForced"
  1657. "(%ws,%ws,%ws,%ws,%lu)\n",
  1658. GetStringParam(pptszArgv[0]),
  1659. GetStringParam(pptszArgv[1]),
  1660. GetStringParam(pptszArgv[2]),
  1661. GetStringParam(pptszArgv[3]),
  1662. dwOptions);
  1663. ulErr = NetDfsRemoveFtRootForced(GetStringParam(pptszArgv[0]),
  1664. GetStringParam(pptszArgv[1]),
  1665. GetStringParam(pptszArgv[2]),
  1666. GetStringParam(pptszArgv[3]),
  1667. dwOptions);
  1668. MSG(fDebug,
  1669. "Exiting RemoveFtRootForced(..) with %lu\n",
  1670. ulErr);
  1671. RETURN(ulErr);
  1672. }; //RemoveFtRootForced
  1673. //+---------------------------------------------------------------------------
  1674. //
  1675. // Function: AddStdRootForced
  1676. //
  1677. // Synopsis: This function performs NetDfsAddStdRootForced.
  1678. //
  1679. // Arguments: [dwArg] the number of arguments
  1680. // [pptszArg] the arguments
  1681. //
  1682. // Returns: ERROR_INVALID_PARAMETER
  1683. //
  1684. // Notes:
  1685. //
  1686. //----------------------------------------------------------------------------
  1687. ULONG AddStdRootForced(DWORD dwArgc, LPTSTR* pptszArgv)
  1688. {
  1689. ULONG ulErr = ERROR_SUCCESS;
  1690. DWORD dwOptions = 0;
  1691. MSG(fDebug,
  1692. "Entering AddStdRootForced(%lu,..)\n",
  1693. dwArgc);
  1694. if (dwArgc < 2 || dwArgc > 4 || NULL == pptszArgv)
  1695. {
  1696. MSG(fDebug,
  1697. "%lu < 3 || "
  1698. "%lu > 4 || "
  1699. "NULL == pptszArgv\n",
  1700. dwArgc,
  1701. dwArgc);
  1702. RETURN(ERROR_INVALID_PARAMETER);
  1703. } //if
  1704. MSG(fDebug,
  1705. "Calling NetDfsAddStdRootForced(%ws,%ws,%ws,%ws)\n",
  1706. GetStringParam(pptszArgv[0]),
  1707. GetStringParam(pptszArgv[1]),
  1708. GetStringParam(pptszArgv[2]),
  1709. GetStringParam(pptszArgv[3]));
  1710. ulErr = NetDfsAddStdRootForced(GetStringParam(pptszArgv[0]),
  1711. GetStringParam(pptszArgv[1]),
  1712. GetStringParam(pptszArgv[2]),
  1713. GetStringParam(pptszArgv[3]));
  1714. MSG(fDebug, "Exiting AddStdRootForced(..) with %lu\n", ulErr);
  1715. RETURN(ulErr);
  1716. }; //AddStdRoot
  1717. //+---------------------------------------------------------------------------
  1718. //
  1719. // Function: GetDcAddress
  1720. //
  1721. // Synopsis: This function performs NetDfsGetDcAddress.
  1722. //
  1723. // Arguments: [dwArg] the number of arguments
  1724. // [pptszArg] the arguments
  1725. //
  1726. // Returns: ERROR_INVALID_PARAMETER
  1727. //
  1728. // Notes:
  1729. //
  1730. //----------------------------------------------------------------------------
  1731. ULONG GetDcAddress(DWORD dwArgc, LPTSTR* pptszArgv)
  1732. {
  1733. ULONG ulErr = ERROR_SUCCESS;
  1734. DWORD dwOptions = 0;
  1735. LPTSTR ptszIpAddress = NULL;
  1736. BOOLEAN bIsRoot = FALSE;
  1737. ULONG ulTimeout = 0;
  1738. MSG(fDebug,
  1739. "Entering AddStdRootForced(%lu,..)\n",
  1740. dwArgc);
  1741. if (1 != dwArgc || NULL == pptszArgv)
  1742. {
  1743. MSG(fDebug,
  1744. "%lu != 1 || NULL == pptszArgv\n",
  1745. dwArgc,
  1746. dwArgc);
  1747. RETURN(ERROR_INVALID_PARAMETER);
  1748. } //if
  1749. MSG(fDebug,
  1750. "Calling NetDfsGetDcAddress(%ws,...)\n",
  1751. GetStringParam(pptszArgv[0]));
  1752. ulErr = NetDfsGetDcAddress(GetStringParam(pptszArgv[0]),
  1753. &ptszIpAddress,
  1754. &bIsRoot,
  1755. &ulTimeout);
  1756. if (ERROR_SUCCESS == ulErr)
  1757. {
  1758. LPTSTR ptszIs = bIsRoot?_T("is"):_T("is not");
  1759. fprintf(stdout,
  1760. "%ws %ws a Dfs server and it will be "
  1761. "sticking to the DC having the %ws "
  1762. "address for %lu seconds\n",
  1763. GetStringParam(pptszArgv[0]),
  1764. ptszIs,
  1765. ptszIpAddress,
  1766. ulTimeout);
  1767. }
  1768. else
  1769. {
  1770. fprintf(stderr,
  1771. "Error %lu: cannot retrieve DC address "
  1772. "for %ws\n",
  1773. ulErr,
  1774. GetStringParam(pptszArgv[0]));
  1775. }
  1776. if (NULL != ptszIpAddress)
  1777. {
  1778. NetApiBufferFree(ptszIpAddress);
  1779. }
  1780. MSG(fDebug, "Exiting AddStdRootForced(..) with %lu\n", ulErr);
  1781. RETURN(ulErr);
  1782. }; //GetDcAddress
  1783. //+---------------------------------------------------------------------------
  1784. //
  1785. // Function: SetDcAddress
  1786. //
  1787. // Synopsis: This function performs NetDfsSetDcAddress.
  1788. //
  1789. // Arguments: [dwArg] the number of arguments
  1790. // [pptszArg] the arguments
  1791. //
  1792. // Returns: ERROR_INVALID_PARAMETER
  1793. //
  1794. // Notes:
  1795. //
  1796. //----------------------------------------------------------------------------
  1797. ULONG SetDcAddress(DWORD dwArgc, LPTSTR* pptszArgv)
  1798. {
  1799. ULONG ulErr = ERROR_SUCCESS;
  1800. ULONG ulTimeout = 0;
  1801. ULONG ulFlags = 0;
  1802. MSG(fDebug,
  1803. "Entering SetDcAddress(%lu,..)\n",
  1804. dwArgc);
  1805. if (dwArgc < 2 || dwArgc > 4 || NULL == pptszArgv)
  1806. {
  1807. MSG(fDebug,
  1808. "%lu < 3 || "
  1809. "%lu > 4 || "
  1810. "NULL == pptszArgv\n",
  1811. dwArgc,
  1812. dwArgc);
  1813. RETURN(ERROR_INVALID_PARAMETER);
  1814. } //if
  1815. ulTimeout = (ULONG)_ttol(GetStringParam(pptszArgv[2]));
  1816. ulFlags = 0;
  1817. MSG(fDebug,
  1818. "Calling NetDfsSetDcAddress(%ws,%ws,%lu,%lu)\n",
  1819. GetStringParam(pptszArgv[0]),
  1820. GetStringParam(pptszArgv[1]),
  1821. ulTimeout,
  1822. ulFlags);
  1823. ulErr = NetDfsSetDcAddress(GetStringParam(pptszArgv[0]),
  1824. GetStringParam(pptszArgv[1]),
  1825. ulTimeout,
  1826. ulFlags);
  1827. MSG(fDebug, "Exiting NetDfsSetDcAddress(..) with %lu\n", ulErr);
  1828. RETURN(ulErr);
  1829. }; //AddStdRoot
  1830. //+---------------------------------------------------------------------------
  1831. //
  1832. // Function: AddConnection
  1833. //
  1834. // Synopsis: This function performs WNetAddConnectionX.
  1835. //
  1836. // Arguments: [dwArg] the number of arguments
  1837. // [pptszArg] the arguments
  1838. //
  1839. // Returns: ERROR_INVALID_PARAMETER
  1840. //
  1841. // Notes:
  1842. //
  1843. //----------------------------------------------------------------------------
  1844. ULONG AddConnection(DWORD dwArgc, LPTSTR* pptszArgv)
  1845. {
  1846. ULONG ulErr = ERROR_SUCCESS;
  1847. if (0 == dwArgc || NULL == pptszArgv)
  1848. {
  1849. RETURN(ERROR_INVALID_PARAMETER);
  1850. }
  1851. if (0 == _tcsicmp(pptszArgv[0], _T("1")))
  1852. {
  1853. ulErr = AddConnection1(dwArgc-1, pptszArgv+1);
  1854. }
  1855. else if (0 == _tcsicmp(pptszArgv[0], _T("2")))
  1856. {
  1857. ulErr = AddConnection2(dwArgc-1, pptszArgv+1);
  1858. }
  1859. else
  1860. {
  1861. MSG(fDebug,
  1862. "Error %lu: invalid level: %ws\n",
  1863. ulErr = ERROR_INVALID_PARAMETER,
  1864. pptszArgv[0]);
  1865. }
  1866. RETURN(ulErr);
  1867. }; //AddConnection
  1868. //+---------------------------------------------------------------------------
  1869. //
  1870. // Function: AddConnection1
  1871. //
  1872. // Synopsis: This function performs WNetAddConnection.
  1873. //
  1874. // Arguments: [dwArg] the number of arguments
  1875. // [pptszArg] the arguments
  1876. //
  1877. // Returns: ERROR_INVALID_PARAMETER
  1878. //
  1879. // Notes:
  1880. //
  1881. //----------------------------------------------------------------------------
  1882. ULONG AddConnection1(DWORD dwArgc, LPTSTR* pptszArgv)
  1883. {
  1884. RETURN(ERROR_INVALID_FUNCTION);
  1885. }; //AddConnection1
  1886. //+---------------------------------------------------------------------------
  1887. //
  1888. // Function: AddConnection2
  1889. //
  1890. // Synopsis: This function performs WNetAddConnection2.
  1891. //
  1892. // Arguments: [dwArg] the number of arguments
  1893. // [pptszArg] the arguments
  1894. //
  1895. // Returns: ERROR_INVALID_PARAMETER
  1896. //
  1897. // Notes:
  1898. //
  1899. //----------------------------------------------------------------------------
  1900. ULONG AddConnection2(DWORD dwArgc, LPTSTR* pptszArgv)
  1901. {
  1902. ULONG ulErr = ERROR_SUCCESS;
  1903. NETRESOURCE NetResource;
  1904. DWORD dwFlags = 0;
  1905. TCHAR tszLocalName[128+1];
  1906. ULONG ulLocalNameLen = 128;
  1907. MSG(fDebug,
  1908. "Entering AddConnection2(%lu, ..)\n",
  1909. dwArgc);
  1910. if (NULL == pptszArgv || dwArgc <= 5)
  1911. {
  1912. RETURN(ERROR_INVALID_PARAMETER);
  1913. }
  1914. memset(tszLocalName, 0, sizeof(tszLocalName));
  1915. ulErr = GetLocalName(tszLocalName,
  1916. ulLocalNameLen,
  1917. GetStringParam(pptszArgv[2]));
  1918. if (ERROR_SUCCESS != ulErr)
  1919. {
  1920. goto Error;
  1921. }
  1922. ulErr = GetNetResource(&NetResource,
  1923. GetStringParam(pptszArgv[3]), // type
  1924. tszLocalName, // localname
  1925. GetStringParam(pptszArgv[0]), // remotename
  1926. GetStringParam(pptszArgv[4])); // provider
  1927. if (ERROR_SUCCESS != ulErr)
  1928. {
  1929. goto Error;
  1930. }
  1931. ulErr = GetWNetConnectionFlags(&dwFlags,
  1932. dwArgc-6,
  1933. pptszArgv+6);
  1934. if (ERROR_SUCCESS != ulErr)
  1935. {
  1936. goto Error;
  1937. }
  1938. MSG(fDebug,
  1939. "Calling WNetAddConnection2(.., %ws, %ws, %lu)\n",
  1940. GetStringParam(pptszArgv[1]),
  1941. GetStringParam(pptszArgv[5]),
  1942. dwFlags);
  1943. ulErr = WNetAddConnection2(&NetResource,
  1944. GetStringParam(pptszArgv[1]),
  1945. GetStringParam(pptszArgv[5]),
  1946. dwFlags);
  1947. Error:;
  1948. MSG(fDebug,
  1949. "Exiting AddConnection2(..) with %lu\n",
  1950. ulErr);
  1951. RETURN(ulErr);
  1952. }; //AddConnection2
  1953. //+---------------------------------------------------------------------------
  1954. //
  1955. // Function: CancelConnection
  1956. //
  1957. // Synopsis: This function performs WNetCancelConnectionX.
  1958. //
  1959. // Arguments: [dwArg] the number of arguments
  1960. // [pptszArg] the arguments
  1961. //
  1962. // Returns: ERROR_INVALID_PARAMETER
  1963. //
  1964. // Notes:
  1965. //
  1966. //----------------------------------------------------------------------------
  1967. ULONG CancelConnection(DWORD dwArgc, LPTSTR* pptszArgv)
  1968. {
  1969. ULONG ulErr = ERROR_SUCCESS;
  1970. if (0 == dwArgc || NULL == pptszArgv)
  1971. {
  1972. RETURN(ERROR_INVALID_PARAMETER);
  1973. }
  1974. if (0 == _tcsicmp(pptszArgv[0], _T("1")))
  1975. {
  1976. ulErr = CancelConnection1(dwArgc-1, pptszArgv+1);
  1977. }
  1978. else if (0 == _tcsicmp(pptszArgv[0], _T("2")))
  1979. {
  1980. ulErr = CancelConnection2(dwArgc-1, pptszArgv+1);
  1981. }
  1982. else
  1983. {
  1984. MSG(fDebug,
  1985. "Error %lu: invalid level: %ws\n",
  1986. ulErr = ERROR_INVALID_PARAMETER,
  1987. pptszArgv[0]);
  1988. }
  1989. RETURN(ulErr);
  1990. }; //CancelConnection
  1991. //+---------------------------------------------------------------------------
  1992. //
  1993. // Function: CancelConnection1
  1994. //
  1995. // Synopsis: This function performs WNetCancelConnection.
  1996. //
  1997. // Arguments: [dwArg] the number of arguments
  1998. // [pptszArg] the arguments
  1999. //
  2000. // Returns: ERROR_INVALID_PARAMETER
  2001. //
  2002. // Notes:
  2003. //
  2004. //----------------------------------------------------------------------------
  2005. ULONG CancelConnection1(DWORD dwArgc, LPTSTR* pptszArgv)
  2006. {
  2007. RETURN(ERROR_INVALID_FUNCTION);
  2008. }; //CancelConnection1
  2009. //+---------------------------------------------------------------------------
  2010. //
  2011. // Function: CancelConnection2
  2012. //
  2013. // Synopsis: This function performs WNetCancelConnection2.
  2014. //
  2015. // Arguments: [dwArg] the number of arguments
  2016. // [pptszArg] the arguments
  2017. //
  2018. // Returns: ERROR_INVALID_PARAMETER
  2019. //
  2020. // Notes:
  2021. //
  2022. //----------------------------------------------------------------------------
  2023. ULONG CancelConnection2(DWORD dwArgc, LPTSTR* pptszArgv)
  2024. {
  2025. ULONG ulErr = ERROR_SUCCESS;
  2026. DWORD dwFlags = 0;
  2027. BOOL bForce = FALSE;
  2028. MSG(fDebug,
  2029. "Entering CancelConnection2(%lu, ..)\n",
  2030. dwArgc);
  2031. if (NULL == pptszArgv || dwArgc <= 0)
  2032. {
  2033. RETURN(ERROR_INVALID_PARAMETER);
  2034. }
  2035. if (2 == dwArgc &&
  2036. 0 == _tcsicmp(_T("force"), pptszArgv[dwArgc-1]))
  2037. {
  2038. bForce = TRUE;
  2039. --dwArgc;
  2040. }
  2041. ulErr = GetWNetConnectionFlags(&dwFlags,
  2042. dwArgc-1,
  2043. pptszArgv+1);
  2044. if (ERROR_SUCCESS != ulErr)
  2045. {
  2046. goto Error;
  2047. }
  2048. MSG(fDebug,
  2049. "Calling WNetCancelConnection2(%ws, %lu, %ws)\n",
  2050. GetStringParam(pptszArgv[0]),
  2051. dwFlags,
  2052. bForce ? _T("TRUE") : _T("FALSE"));
  2053. ulErr = WNetCancelConnection2(GetStringParam(pptszArgv[0]),
  2054. dwFlags,
  2055. bForce);
  2056. Error:;
  2057. MSG(fDebug,
  2058. "Exiting CancelConnection2(..) with %lu\n",
  2059. ulErr);
  2060. RETURN(ulErr);
  2061. }; //CancelConnection2
  2062. //+---------------------------------------------------------------------------
  2063. //
  2064. // Function: GetLocalName
  2065. //
  2066. // Synopsis: This function returns the first available letter for net
  2067. // use
  2068. //
  2069. // Arguments: [...]
  2070. //
  2071. // Returns: ERROR_INVALID_PARAMETER
  2072. //
  2073. // Notes:
  2074. //
  2075. //----------------------------------------------------------------------------
  2076. ULONG GetLocalName(LPTSTR ptszLocalName,
  2077. ULONG ulLocalNameLen,
  2078. LPTSTR ptszArg)
  2079. {
  2080. ULONG ulErr = ERROR_SUCCESS;
  2081. CHAR szDrive[4];
  2082. BOOL bFound = FALSE;
  2083. MSG(fDebug,
  2084. "Entering GetNetResource(%ws, %lu, %ws)\n",
  2085. ptszLocalName,
  2086. ulLocalNameLen,
  2087. ptszArg);
  2088. if (NULL != ptszArg &&
  2089. 0 != _tcsicmp(ptszArg, _T("available")) &&
  2090. 0 != _tcsicmp(ptszArg, _T("*")))
  2091. {
  2092. if (ulLocalNameLen < _tcslen(ptszArg))
  2093. {
  2094. RETURN(ERROR_NO_SYSTEM_RESOURCES);
  2095. }
  2096. _tcscpy(ptszLocalName, ptszArg);
  2097. }
  2098. else
  2099. {
  2100. if (ulLocalNameLen < 2)
  2101. {
  2102. RETURN(ERROR_INVALID_PARAMETER);
  2103. }
  2104. }
  2105. szDrive[1] = ':';
  2106. szDrive[2] = '\\';
  2107. szDrive[3] = '\0';
  2108. for (CHAR C='C'; !bFound && C<='Z'; C++)
  2109. {
  2110. ULONG ulType = 0;
  2111. szDrive[0] = C;
  2112. switch (ulType = GetDriveTypeA(szDrive))
  2113. {
  2114. case 0:
  2115. case DRIVE_REMOVABLE:
  2116. case DRIVE_FIXED:
  2117. case DRIVE_REMOTE:
  2118. case DRIVE_CDROM:
  2119. case DRIVE_RAMDISK:
  2120. MSG(fDebug,
  2121. "%s is of type %lu\n",
  2122. szDrive,
  2123. ulType);
  2124. continue;
  2125. case 1:
  2126. bFound = TRUE;
  2127. break;
  2128. default:
  2129. ASSERT(FALSE);
  2130. }// switch
  2131. } //for
  2132. if (!bFound)
  2133. {
  2134. ulErr = ERROR_NO_SYSTEM_RESOURCES;
  2135. }
  2136. else
  2137. {
  2138. szDrive[2] = '\0';
  2139. #ifdef UNICODE
  2140. mbstowcs(ptszLocalName, szDrive, ulLocalNameLen);
  2141. #else
  2142. _strcpy(ptszLocalName, szDrive);
  2143. #endif
  2144. }
  2145. MSG(fDebug,
  2146. "Entering GetNetResource(%ws, %lu, %ws) with %lu\n",
  2147. ptszLocalName,
  2148. ulLocalNameLen,
  2149. ptszArg,
  2150. ulErr);
  2151. RETURN(ulErr);
  2152. }; //GetLocalName
  2153. //+---------------------------------------------------------------------------
  2154. //
  2155. // Function: GetNetResource
  2156. //
  2157. // Synopsis: This function fils a NETRESOURCE structure out
  2158. //
  2159. // Arguments: [...]
  2160. //
  2161. // Returns: ERROR_INVALID_PARAMETER
  2162. //
  2163. // Notes:
  2164. //
  2165. //----------------------------------------------------------------------------
  2166. ULONG GetNetResource(NETRESOURCE* pNetResource,
  2167. LPTSTR ptszType,
  2168. LPTSTR ptszLocalName,
  2169. LPTSTR ptszRemoteName,
  2170. LPTSTR ptszProvider)
  2171. {
  2172. ULONG ulErr = ERROR_SUCCESS;
  2173. DWORD dwType = 0;
  2174. MSG(fDebug,
  2175. "Entering GetNetResource(.., %ws, %ws, %ws, %ws)\n",
  2176. ptszType,
  2177. ptszLocalName,
  2178. ptszRemoteName,
  2179. ptszProvider);
  2180. if (NULL == pNetResource ||
  2181. NULL == ptszType)
  2182. {
  2183. RETURN(ERROR_INVALID_PARAMETER);
  2184. }
  2185. memset(pNetResource, 0, sizeof(NETRESOURCE));
  2186. if (0 == _tcsicmp(ptszType, _T("disk")))
  2187. {
  2188. dwType = RESOURCETYPE_DISK;
  2189. }
  2190. else if (0 == _tcsicmp(ptszType, _T("print")))
  2191. {
  2192. dwType = RESOURCETYPE_PRINT;
  2193. }
  2194. else if (0 == _tcsicmp(ptszType, _T("any")))
  2195. {
  2196. dwType = RESOURCETYPE_ANY;
  2197. }
  2198. else
  2199. {
  2200. MSG(fDebug,
  2201. "%ws is an invalid type\n",
  2202. ptszType);
  2203. RETURN(ERROR_INVALID_PARAMETER);
  2204. }
  2205. pNetResource->dwType = dwType;
  2206. pNetResource->lpLocalName = ptszLocalName;
  2207. pNetResource->lpRemoteName = ptszRemoteName;
  2208. pNetResource->lpProvider = ptszProvider;
  2209. MSG(fDebug,
  2210. "Entering GetNetResource(.., %ws, %ws, %ws, %ws) with %lu\n",
  2211. ptszType,
  2212. ptszLocalName,
  2213. ptszRemoteName,
  2214. ptszProvider,
  2215. ulErr);
  2216. RETURN(ulErr);
  2217. }; //GetNetResource
  2218. //+---------------------------------------------------------------------------
  2219. //
  2220. // Function: GetWNetConnectionFlags
  2221. //
  2222. // Synopsis: This function returns flags for WNetAddConnection2
  2223. //
  2224. // Arguments: [...]
  2225. //
  2226. // Returns: ERROR_INVALID_PARAMETER
  2227. //
  2228. // Notes:
  2229. //
  2230. //----------------------------------------------------------------------------
  2231. ULONG GetWNetConnectionFlags(DWORD* pdwFlags,
  2232. DWORD dwArgc,
  2233. LPTSTR* pptszArgv)
  2234. {
  2235. ULONG ulErr = ERROR_SUCCESS;
  2236. MSG(fDebug,
  2237. "Entering CWNetAddConnection2Flags(.., %lu, ..)\n",
  2238. dwArgc);
  2239. if (NULL == pdwFlags ||
  2240. NULL == pptszArgv)
  2241. {
  2242. RETURN(ERROR_INVALID_PARAMETER);
  2243. }
  2244. *pdwFlags = 0;
  2245. for (ULONG i=0; i<dwArgc; i++)
  2246. {
  2247. if (0 == _tcsicmp(_T("update_profile"), pptszArgv[i]))
  2248. {
  2249. *pdwFlags |= CONNECT_UPDATE_PROFILE;
  2250. }
  2251. else if (0 == _tcsicmp(_T("update_recent"), pptszArgv[i]))
  2252. {
  2253. *pdwFlags |= CONNECT_UPDATE_RECENT;
  2254. }
  2255. else if (0 == _tcsicmp(_T("temporary"), pptszArgv[i]))
  2256. {
  2257. *pdwFlags |= CONNECT_TEMPORARY;
  2258. }
  2259. else if (0 == _tcsicmp(_T("interactive"), pptszArgv[i]))
  2260. {
  2261. *pdwFlags |= CONNECT_INTERACTIVE;
  2262. }
  2263. else if (0 == _tcsicmp(_T("prompt"), pptszArgv[i]))
  2264. {
  2265. *pdwFlags |= CONNECT_PROMPT;
  2266. }
  2267. else if (0 == _tcsicmp(_T("need_drive"), pptszArgv[i]))
  2268. {
  2269. *pdwFlags |= CONNECT_NEED_DRIVE;
  2270. }
  2271. else if (0 == _tcsicmp(_T("refcount"), pptszArgv[i]))
  2272. {
  2273. *pdwFlags |= CONNECT_REFCOUNT;
  2274. }
  2275. else if (0 == _tcsicmp(_T("redirect"), pptszArgv[i]))
  2276. {
  2277. *pdwFlags |= CONNECT_REDIRECT;
  2278. }
  2279. else if (0 == _tcsicmp(_T("localdrive"), pptszArgv[i]))
  2280. {
  2281. *pdwFlags |= CONNECT_LOCALDRIVE;
  2282. }
  2283. else if (0 == _tcsicmp(_T("current_media"), pptszArgv[i]))
  2284. {
  2285. *pdwFlags |= CONNECT_CURRENT_MEDIA;
  2286. }
  2287. else if (0 == _tcsicmp(_T("deferred"), pptszArgv[i]))
  2288. {
  2289. *pdwFlags |= CONNECT_DEFERRED;
  2290. }
  2291. else
  2292. {
  2293. MSG(fDebug,
  2294. "Error %lu: %ws is an invalid flag\n",
  2295. ulErr = ERROR_INVALID_PARAMETER,
  2296. pptszArgv[i]);
  2297. }
  2298. } //for
  2299. MSG(fDebug,
  2300. "Exiting CWNetAddConnection2Flags(.., %lu, ..) with %lu\n",
  2301. dwArgc,
  2302. ulErr);
  2303. RETURN(ulErr);
  2304. }; //GetWNetAddconnection2Flags
  2305. //+---------------------------------------------------------------------------
  2306. //
  2307. // Function: AddressToSite
  2308. //
  2309. // Synopsis: This function performs DsAddressToSiteNames
  2310. //
  2311. // Arguments: [dwArg] the number of arguments
  2312. // [pptszArg] the arguments
  2313. //
  2314. // Returns: ERROR_INVALID_PARAMETER
  2315. //
  2316. // Notes:
  2317. //
  2318. //----------------------------------------------------------------------------
  2319. ULONG AddressToSite(DWORD dwArgc,
  2320. LPTSTR* pptszArgv)
  2321. {
  2322. ULONG ulErr = ERROR_SUCCESS;
  2323. CString sIp;
  2324. CStringA sIpA;
  2325. ULONG ulIP = 0;
  2326. WSADATA wsaData;
  2327. PHOSTENT pHost = NULL;
  2328. SOCKET_ADDRESS SocketAddress;
  2329. SOCKADDR_IN SockAddrIn;
  2330. LPTSTR* pptszSites = NULL;
  2331. MSG(fDebug,
  2332. "Entering AddressToSite(%lu, ...)\n",
  2333. dwArgc);
  2334. if (2 != dwArgc || NULL == pptszArgv)
  2335. {
  2336. RETURN(ERROR_INVALID_PARAMETER);
  2337. }
  2338. if (NULL == GetStringParam(pptszArgv[1]))
  2339. {
  2340. RETURN(ERROR_INVALID_PARAMETER);
  2341. }
  2342. ulErr = sIp.Set(GetStringParam(pptszArgv[1]));
  2343. if (ERROR_SUCCESS != ulErr)
  2344. {
  2345. RETURN(ulErr);
  2346. }
  2347. ulErr = sIpA.Set(sIp);
  2348. if (ERROR_SUCCESS != ulErr)
  2349. {
  2350. RETURN(ulErr);
  2351. }
  2352. ulIP = inet_addr(sIpA.GetStringA());
  2353. if (INADDR_NONE == ulIP)
  2354. {
  2355. fprintf(stderr,
  2356. "Error %lu: invalid address %s\n",
  2357. ulErr = ERROR_INVALID_PARAMETER,
  2358. sIpA.GetStringA());
  2359. RETURN(ulErr);
  2360. }
  2361. ulErr = WSAStartup(MAKEWORD(2,2),
  2362. &wsaData);
  2363. if (ERROR_SUCCESS != ulErr)
  2364. {
  2365. fprintf(stderr,
  2366. "Error %lu: cannot startup sockets",
  2367. ulErr);
  2368. RETURN(ulErr);
  2369. }
  2370. pHost = gethostbyaddr((LPCSTR)&ulIP,
  2371. sizeof(ulIP),
  2372. AF_INET);
  2373. if (NULL == pHost)
  2374. {
  2375. fprintf(stderr,
  2376. "Error %lu: cannot retrieve host address "
  2377. "for %ws",
  2378. ulErr = WSAGetLastError(),
  2379. GetStringParam(pptszArgv[1]));
  2380. WSACleanup();
  2381. RETURN(ulErr);
  2382. }
  2383. SockAddrIn.sin_family = pHost->h_addrtype;
  2384. SockAddrIn.sin_port = 0;
  2385. memcpy(&SockAddrIn.sin_addr,
  2386. pHost->h_addr,
  2387. pHost->h_length);
  2388. SocketAddress.iSockaddrLength = sizeof(SockAddrIn);
  2389. SocketAddress.lpSockaddr = (LPSOCKADDR)&SockAddrIn;
  2390. ulErr = DsAddressToSiteNames(GetStringParam(pptszArgv[0]),
  2391. 1,
  2392. &SocketAddress,
  2393. &pptszSites);
  2394. if (ERROR_SUCCESS == ulErr && NULL != pptszSites[0])
  2395. {
  2396. fprintf(stdout,
  2397. "The site of %ws on DC \\\\%ws is %ws\n",
  2398. GetStringParam(pptszArgv[1]),
  2399. GetStringParam(pptszArgv[0]),
  2400. pptszSites[0]);
  2401. NetApiBufferFree(pptszSites);
  2402. }
  2403. else if (ERROR_SUCCESS == ulErr && NULL == pptszSites[0])
  2404. {
  2405. fprintf(stdout,
  2406. "Error %lu: address %ws is not associated "
  2407. "to a site or it has an invalid format\n",
  2408. ulErr = ERROR_INVALID_PARAMETER,
  2409. GetStringParam(pptszArgv[1]));
  2410. }
  2411. else
  2412. {
  2413. fprintf(stderr,
  2414. "Error %lu: cannot retrieve site of "
  2415. "%ws from DC \\\\%ws\n",
  2416. ulErr,
  2417. GetStringParam(pptszArgv[0]),
  2418. GetStringParam(pptszArgv[1]));
  2419. }
  2420. WSACleanup();
  2421. MSG(fDebug,
  2422. "Exiting AddressToSite(%lu, ...) with %lu\n",
  2423. dwArgc,
  2424. ulErr);
  2425. RETURN(ulErr);
  2426. }; // AddressToSite
  2427. #endif
  2428. //+---------------------------------------------------------------------------
  2429. //
  2430. // Function: PrintDfsInfo
  2431. //
  2432. // Synopsis: This function prints a DFS_INFO_XXX buffer out.
  2433. //
  2434. // Arguments: [dwLevel] the info level
  2435. // [pBuffer] the info buffer
  2436. //
  2437. // Returns: ERROR_INVALID_PARAMETER
  2438. //
  2439. // Notes:
  2440. //
  2441. //----------------------------------------------------------------------------
  2442. ULONG PrintDfsInfo(DWORD dwLevel, LPBYTE pBuffer)
  2443. {
  2444. ULONG ulErr = ERROR_SUCCESS;
  2445. MSG(fDebug,
  2446. "Entering PrintDfsInfo(%lu,..)\n",
  2447. dwLevel);
  2448. if (NULL == pBuffer)
  2449. {
  2450. RETURN(ERROR_INVALID_PARAMETER);
  2451. }
  2452. switch (dwLevel)
  2453. {
  2454. case 1:
  2455. ulErr = PrintDfsInfo1((PDFS_INFO_1)pBuffer);
  2456. break;
  2457. case 2:
  2458. ulErr = PrintDfsInfo2((PDFS_INFO_2)pBuffer);
  2459. break;
  2460. case 3:
  2461. ulErr = PrintDfsInfo3((PDFS_INFO_3)pBuffer);
  2462. break;
  2463. case 4:
  2464. ulErr = PrintDfsInfo4((PDFS_INFO_4)pBuffer);
  2465. break;
  2466. case 200:
  2467. ulErr = PrintDfsInfo200((PDFS_INFO_200)pBuffer);
  2468. break;
  2469. default:
  2470. RETURN(ERROR_INVALID_PARAMETER);
  2471. } //switch
  2472. MSG(fDebug,
  2473. "Exiting PrintDfsInfo(..) with %lu\n",
  2474. ulErr);
  2475. RETURN(ulErr);
  2476. }; //PrintDfsInfo
  2477. //+---------------------------------------------------------------------------
  2478. //
  2479. // Function: PrintDfsInfo1
  2480. //
  2481. // Synopsis: This function prints a DFS_INFO_1 buffer out.
  2482. //
  2483. // Arguments: [pBuffer] the info buffer
  2484. //
  2485. // Returns: ERROR_INVALID_PARAMETER
  2486. //
  2487. // Notes:
  2488. //
  2489. //----------------------------------------------------------------------------
  2490. ULONG PrintDfsInfo1(PDFS_INFO_1 pBuffer)
  2491. {
  2492. ULONG ulErr = ERROR_SUCCESS;
  2493. MSG(fDebug,
  2494. "Entering PrintDfsInfo1(..)\n");
  2495. if (NULL == pBuffer)
  2496. {
  2497. RETURN(ERROR_INVALID_PARAMETER);
  2498. }
  2499. fprintf(stdout, "%ws\n", pBuffer->EntryPath);
  2500. MSG(fDebug,
  2501. "Exiting PrintDfsInfo1(..) witb %lu\n",
  2502. ulErr);
  2503. RETURN(ulErr);
  2504. }; //PrintDfsInfo1
  2505. //+---------------------------------------------------------------------------
  2506. //
  2507. // Function: PrintDfsInfo2
  2508. //
  2509. // Synopsis: This function prints a DFS_INFO_2 buffer out.
  2510. //
  2511. // Arguments: [pBuffer] the info buffer
  2512. //
  2513. // Returns: ERROR_INVALID_PARAMETER
  2514. //
  2515. // Notes:
  2516. //
  2517. //----------------------------------------------------------------------------
  2518. ULONG PrintDfsInfo2(PDFS_INFO_2 pBuffer)
  2519. {
  2520. ULONG ulErr = ERROR_SUCCESS;
  2521. MSG(fDebug,
  2522. "Entering PrintDfsInfo2(..)\n");
  2523. if (NULL == pBuffer)
  2524. {
  2525. RETURN(ERROR_INVALID_PARAMETER);
  2526. }
  2527. fprintf(stdout, "%ws ", pBuffer->EntryPath);
  2528. fprintf(stdout, "\"%ws\" ", pBuffer->Comment);
  2529. switch (pBuffer->State)
  2530. {
  2531. case DFS_VOLUME_STATE_OK:
  2532. fprintf(stdout, "OK ");
  2533. break;
  2534. case DFS_VOLUME_STATE_INCONSISTENT:
  2535. fprintf(stdout, "INCONS ");
  2536. break;
  2537. case DFS_VOLUME_STATE_ONLINE:
  2538. fprintf(stdout, "ONLINE ");
  2539. break;
  2540. case DFS_VOLUME_STATE_OFFLINE:
  2541. fprintf(stdout, "OFFLINE ");
  2542. break;
  2543. default:
  2544. RETURN(ERROR_INVALID_PARAMETER);
  2545. } //switch
  2546. fprintf(stdout, "%lu\n", pBuffer->NumberOfStorages);
  2547. MSG(fDebug,
  2548. "Exiting PrintDfsInfo2(..) with %lu\n",
  2549. ulErr);
  2550. RETURN(ulErr);
  2551. }; //PrintDfsInfo2
  2552. //+---------------------------------------------------------------------------
  2553. //
  2554. // Function: PrintDfsInfo3
  2555. //
  2556. // Synopsis: This function prints a DFS_INFO_3 buffer out.
  2557. //
  2558. // Arguments: [pBuffer] the info buffer
  2559. //
  2560. // Returns: ERROR_INVALID_PARAMETER
  2561. //
  2562. // Notes:
  2563. //
  2564. //----------------------------------------------------------------------------
  2565. ULONG PrintDfsInfo3(PDFS_INFO_3 pBuffer)
  2566. {
  2567. ULONG ulErr = ERROR_SUCCESS;
  2568. DWORD i = 0;
  2569. PDFS_STORAGE_INFO pStorage = NULL;
  2570. MSG(fDebug,
  2571. "Entering PrintDfsInfo3(..)\n");
  2572. if (NULL == pBuffer)
  2573. {
  2574. RETURN(ERROR_INVALID_PARAMETER);
  2575. }
  2576. fprintf(stdout, "%ws ", pBuffer->EntryPath);
  2577. fprintf(stdout, "\"%ws\" ", pBuffer->Comment);
  2578. switch (pBuffer->State)
  2579. {
  2580. case DFS_VOLUME_STATE_OK:
  2581. fprintf(stdout, "OK ");
  2582. break;
  2583. case DFS_VOLUME_STATE_INCONSISTENT:
  2584. fprintf(stdout, "INCONS ");
  2585. break;
  2586. case DFS_VOLUME_STATE_ONLINE:
  2587. fprintf(stdout, "ONLINE ");
  2588. break;
  2589. case DFS_VOLUME_STATE_OFFLINE:
  2590. fprintf(stdout, "OFFLINE ");
  2591. break;
  2592. default:
  2593. RETURN(ERROR_INVALID_PARAMETER);
  2594. } //switch
  2595. fprintf(stdout, "%lu\n", pBuffer->NumberOfStorages);
  2596. for (i=0, pStorage=pBuffer->Storage;
  2597. i<pBuffer->NumberOfStorages && ERROR_SUCCESS == ulErr;
  2598. i++,pStorage=pBuffer->Storage+i)
  2599. {
  2600. ulErr = PrintStgInfo(pStorage);
  2601. }
  2602. MSG(fDebug,
  2603. "Exiting PrintDfsInfo3(..) with %lu\n", ulErr);
  2604. RETURN(ulErr);
  2605. }; //PrintDfsInfo3
  2606. //+---------------------------------------------------------------------------
  2607. //
  2608. // Function: PrintDfsInfo4
  2609. //
  2610. // Synopsis: This function prints a DFS_INFO_4 buffer out.
  2611. //
  2612. // Arguments: [pBuffer] the info buffer
  2613. //
  2614. // Returns: ERROR_INVALID_PARAMETER
  2615. //
  2616. // Notes:
  2617. //
  2618. //----------------------------------------------------------------------------
  2619. ULONG PrintDfsInfo4(PDFS_INFO_4 pBuffer)
  2620. {
  2621. ULONG ulErr = ERROR_SUCCESS;
  2622. DWORD i = 0;
  2623. PDFS_STORAGE_INFO pStorage = NULL;
  2624. MSG(fDebug,
  2625. "Entering PrintDfsInfo4(..)\n");
  2626. if (NULL == pBuffer)
  2627. {
  2628. RETURN(ERROR_INVALID_PARAMETER);
  2629. }
  2630. fprintf(stdout, "%ws ", pBuffer->EntryPath);
  2631. fprintf(stdout, "\"%ws\" ", pBuffer->Comment);
  2632. switch (pBuffer->State)
  2633. {
  2634. case DFS_VOLUME_STATE_OK:
  2635. fprintf(stdout, "OK ");
  2636. break;
  2637. case DFS_VOLUME_STATE_INCONSISTENT:
  2638. fprintf(stdout, "INCONS ");
  2639. break;
  2640. case DFS_VOLUME_STATE_ONLINE:
  2641. fprintf(stdout, "ONLINE ");
  2642. break;
  2643. case DFS_VOLUME_STATE_OFFLINE:
  2644. fprintf(stdout, "OFFLINE ");
  2645. break;
  2646. default:
  2647. RETURN(ERROR_INVALID_PARAMETER);
  2648. } //switch
  2649. fprintf(stdout, "%lus ", pBuffer->Timeout);
  2650. fprintf(stdout, "%lu storage(s)\n", pBuffer->NumberOfStorages);
  2651. for (i=0, pStorage=pBuffer->Storage;
  2652. i<pBuffer->NumberOfStorages && ERROR_SUCCESS == ulErr;
  2653. i++,pStorage=pBuffer->Storage+i)
  2654. {
  2655. ulErr = PrintStgInfo(pStorage);
  2656. }
  2657. MSG(fDebug,
  2658. "Exiting PrintDfsInfo4(..) with %lu\n",
  2659. ulErr);
  2660. RETURN(ulErr);
  2661. }; //PrintDfsInfo4
  2662. //+---------------------------------------------------------------------------
  2663. //
  2664. // Function: PrintDfsInfo200
  2665. //
  2666. // Synopsis: This function prints a DFS_INFO_200 buffer out.
  2667. //
  2668. // Arguments: [pBuffer] the info buffer
  2669. //
  2670. // Returns: ERROR_INVALID_PARAMETER
  2671. //
  2672. // Notes:
  2673. //
  2674. //----------------------------------------------------------------------------
  2675. ULONG PrintDfsInfo200(PDFS_INFO_200 pBuffer)
  2676. {
  2677. ULONG ulErr = ERROR_SUCCESS;
  2678. MSG(fDebug,
  2679. "Entering PrintDfsInfo200(..)\n");
  2680. if (NULL == pBuffer)
  2681. {
  2682. RETURN(ERROR_INVALID_PARAMETER);
  2683. }
  2684. fprintf(stdout, "%ws\n", pBuffer->FtDfsName);
  2685. MSG(fDebug,
  2686. "Exiting PrintDfsInfo200(..) with %lu\n",
  2687. ulErr);
  2688. RETURN(ulErr);
  2689. }; //PrintDfsInfo4
  2690. //+---------------------------------------------------------------------------
  2691. //
  2692. // Function: PrintStgInfo
  2693. //
  2694. // Synopsis: This function prints a DFS_STORAGE_INFO buffer out.
  2695. //
  2696. // Arguments: [pBuffer] the info buffer
  2697. //
  2698. // Returns: ERROR_INVALID_PARAMETER
  2699. //
  2700. // Notes:
  2701. //
  2702. //----------------------------------------------------------------------------
  2703. ULONG PrintStgInfo(PDFS_STORAGE_INFO pBuffer)
  2704. {
  2705. ULONG ulErr = ERROR_SUCCESS;
  2706. MSG(fDebug,
  2707. "Entering PrintStgInfo(..)\n");
  2708. if (NULL == pBuffer)
  2709. {
  2710. RETURN(ERROR_INVALID_PARAMETER);
  2711. }
  2712. fprintf(stdout, "\t\\\\%ws\\%ws\t",
  2713. pBuffer->ServerName, pBuffer->ShareName);
  2714. if (pBuffer->State & DFS_STORAGE_STATE_ONLINE)
  2715. {
  2716. fprintf(stdout, "online ");
  2717. if (pBuffer->State & DFS_STORAGE_STATE_OFFLINE)
  2718. {
  2719. RETURN(ERROR_INVALID_DATA);
  2720. }
  2721. } //if
  2722. if (pBuffer->State & DFS_STORAGE_STATE_OFFLINE)
  2723. {
  2724. fprintf(stdout, "offline ");
  2725. if (pBuffer->State & DFS_STORAGE_STATE_ONLINE)
  2726. {
  2727. RETURN(ERROR_INVALID_DATA);
  2728. }
  2729. } //if
  2730. if (pBuffer->State & DFS_STORAGE_STATE_ACTIVE)
  2731. {
  2732. fprintf(stdout, "active ");
  2733. }
  2734. fprintf(stdout, "\n");
  2735. MSG(fDebug,
  2736. "Exiting PrintStgInfo(..) with %lu\n",
  2737. ulErr);
  2738. RETURN(ulErr);
  2739. }; //PrintStgInfo
  2740. //+---------------------------------------------------------------------------
  2741. //
  2742. // Function: GetStringParam
  2743. //
  2744. // Synopsis: This function receives a string and it returns the
  2745. // string itself if it is a "good" one (not null, not
  2746. // empty, etc).
  2747. //
  2748. // Arguments: [ptszParam] the string to evaluate
  2749. //
  2750. // Returns: the string itself or NULL.
  2751. //
  2752. // Notes:
  2753. //
  2754. //----------------------------------------------------------------------------
  2755. LPTSTR GetStringParam(LPTSTR ptszParam)
  2756. {
  2757. if (NULL == ptszParam ||
  2758. _T('\0') == ptszParam[0] ||
  2759. 0 == _tcscmp(_T("\"\""), ptszParam))
  2760. {
  2761. return(NULL);
  2762. }
  2763. return(ptszParam);
  2764. }; //GetStringParam