Source code of Windows XP (NT5)
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.

731 lines
24 KiB

  1. //--------------------------------------------------------------------------
  2. //
  3. // Copyright (C) 1999, Microsoft Corporation
  4. //
  5. // File: dfsutil.cxx
  6. //
  7. //--------------------------------------------------------------------------
  8. #define UNICODE
  9. #include <stdio.h>
  10. #include <nt.h>
  11. #include <ntrtl.h>
  12. #include <nturtl.h>
  13. #include <windows.h>
  14. #include <shellapi.h>
  15. #include <winldap.h>
  16. #include <stdlib.h>
  17. #include <dsgetdc.h>
  18. #include <lm.h>
  19. #include <dfsstr.h>
  20. #include <dfsmrshl.h>
  21. #include <marshal.hxx>
  22. #include <lmdfs.h>
  23. #include <dfspriv.h>
  24. #include <csites.hxx>
  25. #include <dfsm.hxx>
  26. #include <recon.hxx>
  27. #include <fsctrl.h>
  28. #include <rpc.h>
  29. #include "struct.hxx"
  30. #include "ftsup.hxx"
  31. #include "stdsup.hxx"
  32. #include "rootsup.hxx"
  33. #include "flush.hxx"
  34. #include "info.hxx"
  35. #include "misc.hxx"
  36. #include "messages.h"
  37. #include "fileio.hxx"
  38. INIT_FILE_TIME_INFO();
  39. INIT_DFS_ID_PROPS_INFO();
  40. INIT_DFS_REPLICA_INFO_MARSHAL_INFO();
  41. INIT_DFS_SITENAME_INFO_MARSHAL_INFO();
  42. INIT_DFS_SITELIST_INFO_MARSHAL_INFO();
  43. INIT_DFSM_SITE_ENTRY_MARSHAL_INFO();
  44. INIT_LDAP_OBJECT_MARSHAL_INFO();
  45. INIT_LDAP_PKT_MARSHAL_INFO()
  46. INIT_LDAP_DFS_VOLUME_PROPERTIES_MARSHAL_INFO();
  47. //
  48. // Globals
  49. //
  50. WCHAR DfsConfigContainer[] = L"CN=Dfs-Configuration,CN=System";
  51. WCHAR DfsSpecialContainer[] = L"CN=Dfs-SpecialConfig,CN=System";
  52. WCHAR DfsSpecialObject[] = L"SpecialTable";
  53. WCHAR wszDfsRootName[] = L".";
  54. ULONG GTimeout = 300;
  55. WCHAR wszNameBuffer[MAX_PATH+1] = { 0 };
  56. WCHAR wszDcName[MAX_PATH+1] = { 0 };
  57. WCHAR wszDomainName[MAX_PATH+1] = { 0 };
  58. LPWSTR pwszNameBuffer = NULL;
  59. LPWSTR pwszRootName = NULL;
  60. LPWSTR pwszServerName = NULL;
  61. LPWSTR pwszHexValue = NULL;
  62. LPWSTR pwszDcName = NULL;
  63. LPWSTR pwszDomainName = NULL;
  64. LPWSTR pwszEntryToFlush = NULL;
  65. LPWSTR pwszDumpArg = NULL;
  66. LPWSTR pwszImportArg = NULL;
  67. LPWSTR pwszExportArg = NULL;
  68. LPWSTR pwszComment = NULL;
  69. LPWSTR pwszShareName = NULL;
  70. //
  71. // Supplied credentials
  72. //
  73. PSEC_WINNT_AUTH_IDENTITY pAuthIdent = NULL;
  74. WCHAR wszUserDomain[MAX_PATH+1] = { 0 };
  75. LPWSTR pwszUserDomain = NULL;
  76. WCHAR wszUser[MAX_PATH+1] = { 0 };
  77. LPWSTR pwszUser = NULL;
  78. WCHAR wszPassword[MAX_PATH+1] = { 0 };
  79. LPWSTR pwszPassword = NULL;
  80. #define DFSREFERRALLIMIT_VAL L"DfsReferralLimit"
  81. #define NETAPIDFSDEBUG_VALUE L"NetApiDfsDebug"
  82. //
  83. // Arguments (ie '/arg:')
  84. //
  85. MAKEARG(WhatIs);
  86. MAKEARG(View);
  87. MAKEARG(Verify);
  88. MAKEARG(AddRoot);
  89. MAKEARG(RemRoot);
  90. MAKEARG(Comment);
  91. MAKEARG(Server);
  92. MAKEARG(Share);
  93. MAKEARG(Unmap);
  94. MAKEARG(Clean);
  95. MAKEARG(ReInit);
  96. MAKEARG(Verbose);
  97. MAKEARG(EventLog);
  98. MAKEARG(Domain);
  99. MAKEARG(DcName);
  100. MAKEARG(User);
  101. MAKEARG(Password);
  102. MAKEARG(Sfp);
  103. MAKEARG(Dns);
  104. MAKEARG(Value);
  105. MAKEARG(NetApiDfsDebug);
  106. MAKEARG(DfsSvcVerbose);
  107. MAKEARG(LoggingDfs);
  108. MAKEARG(SyncInterval);
  109. MAKEARG(DfsAlt);
  110. MAKEARG(TraceLevel);
  111. MAKEARG(Level);
  112. MAKEARG(SetDc);
  113. MAKEARG(Root);
  114. MAKEARG(Trusts);
  115. MAKEARG(DcList);
  116. MAKEARG(CscOnLine);
  117. MAKEARG(CscOffLine);
  118. MAKEARG(DfsReferralLimit);
  119. MAKEARG(InSite);
  120. MAKEARG(SiteInfo);
  121. MAKEARG(Import);
  122. MAKEARG(Export);
  123. //
  124. // Switches (ie '/arg')
  125. //
  126. SWITCH(Debug);
  127. SWITCH(Help);
  128. SWITCH(HelpHelp);
  129. SWITCH(ScriptHelp);
  130. SWITCH(ReadReg);
  131. SWITCH(Dfs);
  132. SWITCH(All);
  133. SWITCH(StdDfs);
  134. SWITCH(On);
  135. SWITCH(Off);
  136. SWITCH(PktInfo);
  137. SWITCH(MarkStale);
  138. SWITCH(FlushStale);
  139. SWITCH(StopDfs);
  140. SWITCH(StartDfs);
  141. SWITCH(Set);
  142. SWITCH(ReSet);
  143. //
  144. // Either a switch or an arg
  145. //
  146. MAKEARG(PktFlush);
  147. SWITCH(PktFlush);
  148. MAKEARG(SpcFlush);
  149. SWITCH(SpcFlush);
  150. MAKEARG(List);
  151. SWITCH(List);
  152. MAKEARG(SpcInfo);
  153. SWITCH(SpcInfo);
  154. //
  155. // The macro can not make these
  156. //
  157. WCHAR SwQ[] = L"/?";
  158. BOOLEAN fSwQ;
  159. WCHAR SwQQ[] = L"/??";
  160. BOOLEAN fSwQQ;
  161. DWORD
  162. Usage(
  163. BOOLEAN fHelpHelp);
  164. DWORD
  165. ScriptUsage(VOID);
  166. DWORD
  167. CmdProcessUserCreds(
  168. VOID);
  169. BOOLEAN
  170. CmdProcessArg(
  171. LPWSTR Arg);
  172. _cdecl
  173. main(int argc, char *argv[])
  174. {
  175. DWORD dwErr = ERROR_SUCCESS;
  176. LPWSTR CommandLine;
  177. LPWSTR *argvw;
  178. SEC_WINNT_AUTH_IDENTITY AuthIdent = { 0 };
  179. int argx;
  180. int argcw;
  181. // fSwDebug = TRUE;
  182. //
  183. // Get the command line in Unicode
  184. //
  185. CommandLine = GetCommandLine();
  186. argvw = CommandLineToArgvW(CommandLine, &argcw);
  187. if ( argvw == NULL ) {
  188. MyPrintf(L"dfsutil:Can't convert command line to Unicode: %d\r\n", GetLastError() );
  189. return 1;
  190. }
  191. //
  192. // Get the arguments
  193. //
  194. if (argcw <= 1) {
  195. Usage(FALSE);
  196. dwErr = ERROR_SUCCESS;
  197. goto Cleanup;
  198. }
  199. //
  200. // Process arguments
  201. //
  202. for (argx = 1; argx < argcw; argx++) {
  203. if (CmdProcessArg(argvw[argx]) != TRUE) {
  204. dwErr = ERROR_INVALID_PARAMETER;
  205. goto Cleanup;
  206. }
  207. }
  208. //
  209. // Did we get supplied creds?
  210. //
  211. if (fArgUser == TRUE || fArgPassword != NULL) {
  212. dwErr = CmdProcessUserCreds();
  213. if (dwErr != ERROR_SUCCESS)
  214. goto Cleanup;
  215. }
  216. if (pwszUser != NULL || pwszUserDomain != NULL || pwszPassword != NULL) {
  217. pAuthIdent = &AuthIdent;
  218. pAuthIdent->Flags = SEC_WINNT_AUTH_IDENTITY_UNICODE;
  219. if (pwszUser != NULL) {
  220. pAuthIdent->User = (USHORT *)pwszUser;
  221. pAuthIdent->UserLength = wcslen(pwszUser);
  222. }
  223. if (pwszUserDomain != NULL) {
  224. pAuthIdent->Domain = (USHORT *)pwszUserDomain;
  225. pAuthIdent->DomainLength = wcslen(pwszUserDomain);
  226. }
  227. if (pwszPassword != NULL) {
  228. pAuthIdent->Password = (USHORT *)pwszPassword;
  229. pAuthIdent->PasswordLength = wcslen(pwszPassword);
  230. }
  231. }
  232. if (fSwDebug == TRUE) {
  233. MyPrintf(L"NameBuffer=%ws\r\n", pwszNameBuffer);
  234. MyPrintf(L"DcName=%ws\r\n", pwszDcName);
  235. MyPrintf(L"DomainName=%ws\r\n", pwszDomainName);
  236. MyPrintf(L"EntryToFlush=%ws\r\n", pwszEntryToFlush);
  237. }
  238. //
  239. // Do the work
  240. //
  241. if (fSwHelp == TRUE || fSwQ == TRUE) {
  242. dwErr = Usage(FALSE);
  243. } else if (fSwScriptHelp == TRUE) {
  244. dwErr = ScriptUsage();
  245. } else if (fSwPktFlush == TRUE || fArgPktFlush == TRUE) {
  246. dwErr = PktFlush(pwszEntryToFlush);
  247. } else if (fSwSpcFlush == TRUE || fArgSpcFlush == TRUE) {
  248. dwErr = SpcFlush(pwszEntryToFlush);
  249. } else if (fArgImport == TRUE) {
  250. dwErr = CmdImport(pwszImportArg);
  251. } else if (fArgExport == TRUE) {
  252. dwErr = CmdExport(pwszExportArg, pwszNameBuffer, pwszDcName, pAuthIdent);
  253. } else if (fSwPktInfo == TRUE) {
  254. dwErr = PktInfo(fSwDfs, pwszHexValue);
  255. } else if (fSwSpcInfo == TRUE) {
  256. dwErr = SpcInfo(fSwAll);
  257. } else if (fArgAddRoot == TRUE) {
  258. dwErr = CmdAddRoot(
  259. pwszNameBuffer,
  260. pwszServerName,
  261. pwszShareName,
  262. pwszComment);
  263. } else if (fArgRemRoot == TRUE) {
  264. dwErr = CmdRemRoot(
  265. pwszNameBuffer,
  266. pwszServerName,
  267. pwszShareName);
  268. } else if (fArgUnmap == TRUE) {
  269. dwErr = CmdDomUnmap(pwszNameBuffer, pwszRootName, pwszDcName, pAuthIdent);
  270. } else if (fArgClean == TRUE) {
  271. dwErr = CmdClean(pwszNameBuffer);
  272. if (dwErr == ERROR_SUCCESS)
  273. NetDfsManagerInitialize(pwszNameBuffer, 0);
  274. } else if (fArgView == TRUE) {
  275. dwErr = CmdView(pwszNameBuffer, pwszDcName, pAuthIdent, pwszHexValue);
  276. } else if (fArgReInit == TRUE) {
  277. dwErr = NetDfsManagerInitialize(pwszNameBuffer, 0);
  278. } else if (fArgWhatIs == TRUE) {
  279. dwErr = CmdWhatIs(pwszNameBuffer);
  280. }
  281. else if (fArgInSite == TRUE) {
  282. dwErr = CmdSetOnSite(pwszNameBuffer, pwszDcName, pAuthIdent, fSwSet?1:0);
  283. } else if (fArgSiteInfo == TRUE) {
  284. dwErr = CmdSiteInfo(pwszNameBuffer);
  285. } else if (fSwHelpHelp == TRUE || fSwQQ == TRUE) {
  286. dwErr = Usage(TRUE);
  287. } else if (fArgSfp == TRUE) {
  288. dwErr = CmdSfp(pwszNameBuffer, fSwOn, fSwOff);
  289. } else if (fArgTrusts == TRUE) {
  290. dwErr = CmdTrusts(pwszDomainName, pwszDcName, pAuthIdent, fSwAll);
  291. } else if (fArgNetApiDfsDebug == TRUE) {
  292. dwErr = CmdRegistry(pwszNameBuffer, REG_KEY_DFSSVC, NETAPIDFSDEBUG_VALUE, pwszHexValue);
  293. } else if (fArgDfsSvcVerbose == TRUE) {
  294. dwErr = CmdRegistry(pwszNameBuffer, REG_KEY_DFSSVC, REG_VALUE_VERBOSE, pwszHexValue);
  295. } else if (fArgDns == TRUE) {
  296. dwErr = CmdRegistry(pwszNameBuffer, REG_KEY_DFSSVC, REG_VALUE_DFSDNSCONFIG, pwszHexValue);
  297. } else if (fArgSyncInterval == TRUE) {
  298. dwErr = CmdRegistry(pwszNameBuffer, REG_KEY_DFSSVC, SYNC_INTERVAL_NAME, pwszHexValue);
  299. } else if (fArgDfsReferralLimit == TRUE) {
  300. dwErr = CmdRegistry(pwszNameBuffer, REG_KEY_DFSDRIVER, DFSREFERRALLIMIT_VAL, pwszHexValue);
  301. } else if (fArgLoggingDfs == TRUE) {
  302. dwErr = CmdRegistry(pwszNameBuffer, REG_KEY_EVENTLOG, REG_VALUE_EVENTLOG_DFS, pwszHexValue);
  303. } else if (fArgSetDc == TRUE) {
  304. dwErr = CmdSetDc(pwszNameBuffer);
  305. } else if (fSwMarkStale == TRUE) {
  306. dwErr = CmdDfsFsctlDfs(DFS_SERVER_NAME, FSCTL_DFS_MARK_STALE_PKT_ENTRIES);
  307. } else if (fSwFlushStale == TRUE) {
  308. dwErr = CmdDfsFsctlDfs(DFS_SERVER_NAME, FSCTL_DFS_FLUSH_STALE_PKT_ENTRIES);
  309. } else if (fSwStartDfs == TRUE) {
  310. dwErr = CmdDfsFsctlDfs(DFS_SERVER_NAME, FSCTL_DFS_START_DFS);
  311. } else if (fSwStopDfs == TRUE) {
  312. dwErr = CmdDfsFsctlDfs(DFS_SERVER_NAME, FSCTL_DFS_STOP_DFS);
  313. } else if (fArgVerbose == TRUE) {
  314. dwErr = CmdMupFlags(FSCTL_DFS_VERBOSE_FLAGS, pwszHexValue);
  315. } else if (fArgEventLog == TRUE) {
  316. dwErr = CmdMupFlags(FSCTL_DFS_EVENTLOG_FLAGS, pwszHexValue);
  317. } else if (fArgTraceLevel == TRUE) {
  318. dwErr = CmdMupFlags(FSCTL_DFS_DBG_FLAGS, pwszHexValue);
  319. } else if (fSwReadReg == TRUE) {
  320. dwErr = CmdMupReadReg(fSwDfs);
  321. } else if (fArgCscOnLine == TRUE) {
  322. dwErr = CmdCscOnLine(pwszNameBuffer);
  323. } else if (fArgCscOffLine == TRUE) {
  324. dwErr = CmdCscOffLine(pwszNameBuffer);
  325. } else if (fArgDfsAlt == TRUE) {
  326. dwErr = CmdDfsAlt(pwszNameBuffer);
  327. } else if (fArgDcList == TRUE) {
  328. dwErr = CmdDcList(pwszDomainName, pwszDcName, pAuthIdent);
  329. } else if (fSwList == TRUE && fSwStdDfs == TRUE) {
  330. dwErr = CmdStdList(pwszDomainName);
  331. } else if (fSwList == TRUE && fSwStdDfs == FALSE) {
  332. dwErr = CmdDomList(pwszDcName, pwszDomainName, pAuthIdent);
  333. } else if (fArgVerify == TRUE) {
  334. dwErr = CmdVerify(pwszNameBuffer, pwszDcName, pAuthIdent, pwszHexValue);
  335. }
  336. else {
  337. dwErr = Usage(FALSE);
  338. // ErrorMessage(MSG_NOTHING_TO_DO);
  339. }
  340. Cleanup:
  341. if (dwErr == STATUS_SUCCESS) {
  342. ErrorMessage(MSG_SUCCESSFUL);
  343. } else {
  344. LPWSTR MessageBuffer;
  345. DWORD dwBufferLength;
  346. dwBufferLength = FormatMessage(
  347. FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
  348. NULL,
  349. dwErr,
  350. MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
  351. (LPWSTR) &MessageBuffer,
  352. 0,
  353. NULL);
  354. ErrorMessage(MSG_ERROR, dwErr);
  355. if (dwBufferLength > 0) {
  356. MyPrintf(L"%ws\r\n", MessageBuffer);
  357. LocalFree(MessageBuffer);
  358. }
  359. }
  360. return dwErr;
  361. }
  362. DWORD
  363. CmdProcessUserCreds(
  364. VOID)
  365. {
  366. DWORD dwErr = ERROR_SUCCESS;
  367. PWCHAR wCp = NULL;
  368. if (fSwDebug == TRUE) {
  369. MyPrintf(L"ProcessUserCreds:\r\n");
  370. MyPrintf(L" UserName:%ws\r\n", pwszUser);
  371. MyPrintf(L" Password:%ws\r\n", pwszPassword);
  372. }
  373. //
  374. // Scan pwszUser for backslash or '@'
  375. //
  376. for (wCp = pwszUser; *wCp != L'\0' && *wCp != L'\\' && *wCp != L'@'; wCp++)
  377. ;
  378. //
  379. // If backslash, treat as domain\user
  380. //
  381. if (*wCp == L'\\') {
  382. pwszUserDomain = pwszUser;
  383. *wCp++ = '\0';
  384. pwszUser = wCp;
  385. if (fSwDebug == TRUE)
  386. MyPrintf(L"User:%ws Domain:%ws Password:%ws\r\n",
  387. pwszUser,
  388. pwszUserDomain,
  389. pwszPassword);
  390. }
  391. //
  392. // If @, treat as user@domain
  393. //
  394. if (*wCp == L'@') {
  395. *wCp++ = '\0';
  396. pwszUserDomain = wCp;
  397. if (fSwDebug == TRUE)
  398. MyPrintf(L"User:%ws Domain:%ws Password:%ws\r\n",
  399. pwszUser,
  400. pwszUserDomain,
  401. pwszPassword);
  402. }
  403. if (fSwDebug == TRUE)
  404. MyPrintf(L"ProcessUserCreds exit %d\r\n", dwErr);
  405. return dwErr;
  406. }
  407. BOOLEAN
  408. CmdProcessArg(LPWSTR Arg)
  409. {
  410. LONG ArgLen;
  411. BOOLEAN dwErr = FALSE;
  412. BOOLEAN FoundAnArg = FALSE;
  413. if (fSwDebug == TRUE)
  414. MyPrintf(L"ProcessArg(%ws)\r\n", Arg);
  415. if ( Arg != NULL && wcslen(Arg) > 1) {
  416. dwErr = TRUE;
  417. ArgLen = wcslen(Arg);
  418. if (_wcsnicmp(Arg, ArgView, ArgLenView) == 0) {
  419. FoundAnArg = fArgView = TRUE;
  420. if (ArgLen > ArgLenView)
  421. pwszNameBuffer = &Arg[ArgLenView];
  422. } else if (_wcsnicmp(Arg, ArgInSite, ArgLenInSite) == 0) {
  423. FoundAnArg = fArgInSite = TRUE;
  424. if (ArgLen > ArgLenInSite)
  425. pwszNameBuffer = &Arg[ArgLenInSite];
  426. } else if (_wcsnicmp(Arg, ArgSiteInfo, ArgLenSiteInfo) == 0) {
  427. FoundAnArg = fArgSiteInfo = TRUE;
  428. if (ArgLen > ArgLenSiteInfo)
  429. pwszNameBuffer = &Arg[ArgLenSiteInfo];
  430. } else if (_wcsnicmp(Arg, ArgDcName, ArgLenDcName) == 0) {
  431. FoundAnArg = fArgDcName = TRUE;
  432. if (ArgLen > ArgLenDcName)
  433. pwszDcName = &Arg[ArgLenDcName];
  434. } else if (_wcsnicmp(Arg, ArgTrusts, ArgLenTrusts) == 0) {
  435. FoundAnArg = fArgTrusts = TRUE;
  436. if (ArgLen > ArgLenTrusts)
  437. pwszDomainName = &Arg[ArgLenTrusts];
  438. } else if (_wcsnicmp(Arg, ArgImport, ArgLenImport) == 0) {
  439. FoundAnArg = fArgImport = TRUE;
  440. if (ArgLen > ArgLenImport)
  441. pwszImportArg = &Arg[ArgLenImport];
  442. } else if (_wcsnicmp(Arg, ArgExport, ArgLenExport) == 0) {
  443. FoundAnArg = fArgExport = TRUE;
  444. if (ArgLen > ArgLenExport)
  445. pwszExportArg = &Arg[ArgLenExport];
  446. } else if (_wcsnicmp(Arg, ArgSetDc, ArgLenSetDc) == 0) {
  447. FoundAnArg = fArgSetDc = TRUE;
  448. if (ArgLen > ArgLenSetDc)
  449. pwszNameBuffer = &Arg[ArgLenSetDc];
  450. } else if (_wcsnicmp(Arg, ArgRoot, ArgLenRoot) == 0) {
  451. FoundAnArg = fArgRoot = TRUE;
  452. if (ArgLen > ArgLenRoot)
  453. pwszRootName = &Arg[ArgLenRoot];
  454. } else if (_wcsnicmp(Arg, ArgAddRoot, ArgLenAddRoot) == 0) {
  455. FoundAnArg = fArgAddRoot = TRUE;
  456. if (ArgLen > ArgLenAddRoot)
  457. pwszNameBuffer = &Arg[ArgLenAddRoot];
  458. } else if (_wcsnicmp(Arg, ArgRemRoot, ArgLenRemRoot) == 0) {
  459. FoundAnArg = fArgRemRoot = TRUE;
  460. if (ArgLen > ArgLenRemRoot)
  461. pwszNameBuffer = &Arg[ArgLenRemRoot];
  462. } else if (_wcsnicmp(Arg, ArgShare, ArgLenShare) == 0) {
  463. FoundAnArg = fArgShare = TRUE;
  464. if (ArgLen > ArgLenShare)
  465. pwszShareName = &Arg[ArgLenShare];
  466. } else if (_wcsnicmp(Arg, ArgComment, ArgLenComment) == 0) {
  467. FoundAnArg = fArgComment = TRUE;
  468. if (ArgLen > ArgLenComment)
  469. pwszComment = &Arg[ArgLenComment];
  470. } else if (_wcsnicmp(Arg, ArgServer, ArgLenServer) == 0) {
  471. FoundAnArg = fArgServer = TRUE;
  472. if (ArgLen > ArgLenServer)
  473. pwszServerName = &Arg[ArgLenServer];
  474. } else if (_wcsnicmp(Arg, ArgUnmap, ArgLenUnmap) == 0) {
  475. FoundAnArg = fArgUnmap = TRUE;
  476. if (ArgLen > ArgLenUnmap)
  477. pwszNameBuffer = &Arg[ArgLenUnmap];
  478. } else if (_wcsnicmp(Arg, ArgClean, ArgLenClean) == 0) {
  479. FoundAnArg = fArgClean = TRUE;
  480. if (ArgLen > ArgLenClean)
  481. pwszNameBuffer = &Arg[ArgLenClean];
  482. } else if (_wcsnicmp(Arg, ArgDomain, ArgLenDomain) == 0) {
  483. FoundAnArg = fArgDomain = TRUE;
  484. if (ArgLen > ArgLenDomain)
  485. pwszDomainName = &Arg[ArgLenDomain];
  486. } else if (_wcsnicmp(Arg, ArgWhatIs, ArgLenWhatIs) == 0) {
  487. FoundAnArg = fArgWhatIs = TRUE;
  488. if (ArgLen > ArgLenWhatIs)
  489. pwszNameBuffer = &Arg[ArgLenWhatIs];
  490. } else if (_wcsnicmp(Arg, ArgCscOnLine, ArgLenCscOnLine) == 0) {
  491. FoundAnArg = fArgCscOnLine = TRUE;
  492. if (ArgLen > ArgLenCscOnLine)
  493. pwszNameBuffer = &Arg[ArgLenCscOnLine];
  494. } else if (_wcsnicmp(Arg, ArgCscOffLine, ArgLenCscOffLine) == 0) {
  495. FoundAnArg = fArgCscOffLine = TRUE;
  496. if (ArgLen > ArgLenCscOffLine)
  497. pwszNameBuffer = &Arg[ArgLenCscOffLine];
  498. } else if (_wcsnicmp(Arg, ArgDfsAlt, ArgLenDfsAlt) == 0) {
  499. FoundAnArg = fArgDfsAlt = TRUE;
  500. if (ArgLen > ArgLenDfsAlt)
  501. pwszNameBuffer = &Arg[ArgLenDfsAlt];
  502. } else if (_wcsnicmp(Arg, ArgList, ArgLenList) == 0) {
  503. FoundAnArg = fArgList = fSwList = TRUE;
  504. if (ArgLen > ArgLenList)
  505. pwszDomainName = &Arg[ArgLenList];
  506. } else if (_wcsnicmp(Arg, ArgDcList, ArgLenDcList) == 0) {
  507. FoundAnArg = fArgDcList = TRUE;
  508. if (ArgLen > ArgLenDcList)
  509. pwszDomainName = &Arg[ArgLenDcList];
  510. } else if (_wcsnicmp(Arg, ArgSfp, ArgLenSfp) == 0) {
  511. FoundAnArg = fArgSfp = TRUE;
  512. if (ArgLen > ArgLenSfp)
  513. pwszNameBuffer = &Arg[ArgLenSfp];
  514. } else if (_wcsnicmp(Arg, ArgDns, ArgLenDns) == 0) {
  515. FoundAnArg = fArgDns = TRUE;
  516. if (ArgLen > ArgLenDns)
  517. pwszNameBuffer = &Arg[ArgLenDns];
  518. } else if (_wcsnicmp(Arg, ArgNetApiDfsDebug, ArgLenNetApiDfsDebug) == 0) {
  519. FoundAnArg = fArgNetApiDfsDebug = TRUE;
  520. if (ArgLen > ArgLenNetApiDfsDebug)
  521. pwszNameBuffer = &Arg[ArgLenNetApiDfsDebug];
  522. } else if (_wcsnicmp(Arg, ArgDfsSvcVerbose, ArgLenDfsSvcVerbose) == 0) {
  523. FoundAnArg = fArgDfsSvcVerbose = TRUE;
  524. if (ArgLen > ArgLenDfsSvcVerbose)
  525. pwszNameBuffer = &Arg[ArgLenDfsSvcVerbose];
  526. } else if (_wcsnicmp(Arg, ArgLoggingDfs, ArgLenLoggingDfs) == 0) {
  527. FoundAnArg = fArgLoggingDfs = TRUE;
  528. if (ArgLen > ArgLenLoggingDfs)
  529. pwszNameBuffer = &Arg[ArgLenLoggingDfs];
  530. } else if (_wcsnicmp(Arg, ArgDfsReferralLimit, ArgLenDfsReferralLimit) == 0) {
  531. FoundAnArg = fArgDfsReferralLimit = TRUE;
  532. if (ArgLen > ArgLenDfsReferralLimit)
  533. pwszNameBuffer = &Arg[ArgLenDfsReferralLimit];
  534. } else if (_wcsnicmp(Arg, ArgSyncInterval, ArgLenSyncInterval) == 0) {
  535. FoundAnArg = fArgSyncInterval = TRUE;
  536. if (ArgLen > ArgLenSyncInterval)
  537. pwszNameBuffer = &Arg[ArgLenSyncInterval];
  538. } else if (_wcsnicmp(Arg, ArgVerify, ArgLenVerify) == 0) {
  539. FoundAnArg = fArgVerify = TRUE;
  540. if (ArgLen > ArgLenVerify)
  541. pwszNameBuffer = &Arg[ArgLenVerify];
  542. } else if (_wcsnicmp(Arg, ArgPktFlush, ArgLenPktFlush) == 0) {
  543. FoundAnArg = fArgPktFlush = TRUE;
  544. if (ArgLen > ArgLenPktFlush)
  545. pwszEntryToFlush = &Arg[ArgLenPktFlush];
  546. } else if (_wcsnicmp(Arg, ArgSpcFlush, ArgLenSpcFlush) == 0) {
  547. FoundAnArg = fArgSpcFlush = TRUE;
  548. if (ArgLen > ArgLenSpcFlush)
  549. pwszEntryToFlush = &Arg[ArgLenSpcFlush];
  550. } else if (_wcsnicmp(Arg, ArgReInit, ArgLenReInit) == 0) {
  551. FoundAnArg = fArgReInit = TRUE;
  552. if (ArgLen > ArgLenReInit)
  553. pwszNameBuffer = &Arg[ArgLenReInit];
  554. } else if (_wcsnicmp(Arg, ArgUser, ArgLenUser) == 0) {
  555. FoundAnArg = fArgUser = TRUE;
  556. if (ArgLen > ArgLenUser)
  557. pwszUser = &Arg[ArgLenUser];
  558. } else if (_wcsnicmp(Arg, ArgPassword, ArgLenPassword) == 0) {
  559. FoundAnArg = fArgPassword = TRUE;
  560. if (ArgLen > ArgLenPassword)
  561. pwszPassword = &Arg[ArgLenPassword];
  562. } else if (_wcsnicmp(Arg, ArgVerbose, ArgLenVerbose) == 0) {
  563. FoundAnArg = fArgVerbose = TRUE;
  564. if (ArgLen > ArgLenVerbose)
  565. pwszHexValue = &Arg[ArgLenVerbose];
  566. } else if (_wcsnicmp(Arg, ArgValue, ArgLenValue) == 0) {
  567. FoundAnArg = fArgValue = TRUE;
  568. if (ArgLen > ArgLenValue)
  569. pwszHexValue = &Arg[ArgLenValue];
  570. } else if (_wcsnicmp(Arg, ArgTraceLevel, ArgLenTraceLevel) == 0) {
  571. FoundAnArg = fArgTraceLevel = TRUE;
  572. if (ArgLen > ArgLenTraceLevel)
  573. pwszHexValue = &Arg[ArgLenTraceLevel];
  574. } else if (_wcsnicmp(Arg, ArgLevel, ArgLenLevel) == 0) {
  575. FoundAnArg = fArgLevel = TRUE;
  576. if (ArgLen > ArgLenLevel)
  577. pwszHexValue = &Arg[ArgLenLevel];
  578. } else if (_wcsnicmp(Arg, ArgEventLog, ArgLenEventLog) == 0) {
  579. FoundAnArg = fArgEventLog = TRUE;
  580. if (ArgLen > ArgLenEventLog)
  581. pwszHexValue = &Arg[ArgLenEventLog];
  582. }
  583. // Switches go at the end!!
  584. if (_wcsicmp(Arg, SwDebug) == 0) {
  585. FoundAnArg = fSwDebug = TRUE;
  586. } else if (_wcsicmp(Arg, SwList) == 0) {
  587. FoundAnArg = fSwList = TRUE;
  588. } else if (_wcsicmp(Arg, SwReadReg) == 0) {
  589. FoundAnArg = fSwReadReg = TRUE;
  590. } else if (_wcsicmp(Arg, SwPktFlush) == 0) {
  591. FoundAnArg = fSwPktFlush = TRUE;
  592. } else if (_wcsicmp(Arg, SwSpcFlush) == 0) {
  593. FoundAnArg = fSwSpcFlush = TRUE;
  594. } else if (_wcsicmp(Arg, SwPktInfo) == 0) {
  595. FoundAnArg = fSwPktInfo = TRUE;
  596. } else if (_wcsicmp(Arg, SwMarkStale) == 0) {
  597. FoundAnArg = fSwMarkStale = TRUE;
  598. } else if (_wcsicmp(Arg, SwFlushStale) == 0) {
  599. FoundAnArg = fSwFlushStale = TRUE;
  600. } else if (_wcsicmp(Arg, SwStartDfs) == 0) {
  601. FoundAnArg = fSwStartDfs = TRUE;
  602. } else if (_wcsicmp(Arg, SwStopDfs) == 0) {
  603. FoundAnArg = fSwStopDfs = TRUE;
  604. } else if (_wcsicmp(Arg, SwSpcInfo) == 0) {
  605. FoundAnArg = fSwSpcInfo = TRUE;
  606. } else if (_wcsicmp(Arg, SwDfs) == 0) {
  607. FoundAnArg = fSwDfs = TRUE;
  608. } else if (_wcsicmp(Arg, SwAll) == 0) {
  609. FoundAnArg = fSwAll = TRUE;
  610. } else if (_wcsicmp(Arg, SwOn) == 0) {
  611. FoundAnArg = fSwOn = TRUE;
  612. } else if (_wcsicmp(Arg, SwOff) == 0) {
  613. FoundAnArg = fSwOff = TRUE;
  614. } else if (_wcsicmp(Arg, SwStdDfs) == 0) {
  615. FoundAnArg = fSwStdDfs = TRUE;
  616. } else if (_wcsicmp(Arg, SwHelpHelp) == 0) {
  617. FoundAnArg = fSwHelpHelp = TRUE;
  618. } else if (_wcsicmp(Arg, SwScriptHelp) == 0) {
  619. FoundAnArg = fSwScriptHelp = TRUE;
  620. } else if (_wcsicmp(Arg, SwHelp) == 0) {
  621. FoundAnArg = fSwHelp = TRUE;
  622. } else if (_wcsicmp(Arg, SwQQ) == 0) {
  623. FoundAnArg = fSwQQ = TRUE;
  624. } else if (_wcsicmp(Arg, SwQ) == 0) {
  625. FoundAnArg = fSwQ = TRUE;
  626. } else if (_wcsicmp(Arg, SwSet) == 0) {
  627. FoundAnArg = fSwSet = TRUE;
  628. } else if (_wcsicmp(Arg, SwReSet) == 0) {
  629. FoundAnArg = fSwReSet = TRUE;
  630. }
  631. if (wszNameBuffer[0] == L'\0' && pwszNameBuffer != NULL) {
  632. wcscpy(wszNameBuffer, L"\\\\");
  633. wcscat(wszNameBuffer, pwszNameBuffer);
  634. pwszNameBuffer = wszNameBuffer;
  635. while (pwszNameBuffer[0] == L'\\' && pwszNameBuffer[1] == L'\\')
  636. pwszNameBuffer++;
  637. pwszNameBuffer--;
  638. }
  639. if (FoundAnArg == FALSE) {
  640. ErrorMessage(MSG_UNRECOGNIZED_OPTION, &Arg[1]);
  641. dwErr = FALSE;
  642. goto AllDone;
  643. }
  644. }
  645. AllDone:
  646. if (fSwDebug == TRUE)
  647. MyPrintf(L"ProcessArg exit %d\r\n", dwErr);
  648. return dwErr;
  649. }
  650. DWORD
  651. Usage(
  652. BOOLEAN fHelpHelp)
  653. {
  654. #if (MASTER_UTIL == 1)
  655. ErrorMessage(MSG_USAGE);
  656. if (fHelpHelp == TRUE)
  657. ErrorMessage(MSG_USAGE_EX);
  658. #else
  659. ErrorMessage(MSG_USAGE_LTD);
  660. #endif
  661. return ERROR_SUCCESS;
  662. }
  663. DWORD
  664. ScriptUsage(VOID)
  665. {
  666. ErrorMessage(MSG_USAGE_EX_EX);
  667. return ERROR_SUCCESS;
  668. }