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.

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