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.

506 lines
9.6 KiB

  1. #include "StdAfx.h"
  2. #include "Argument.h"
  3. #include "Parameter.h"
  4. #include "Migration.h"
  5. #include "Switch.h"
  6. #include "MonitorThread.h"
  7. #include "GenerateKey.h"
  8. namespace PrintUsage
  9. {
  10. void __stdcall PrintADMTUsage();
  11. void __stdcall PrintUserUsage();
  12. void __stdcall PrintGroupUsage();
  13. void __stdcall PrintComputerUsage();
  14. void __stdcall PrintSecurityUsage();
  15. void __stdcall PrintServiceUsage();
  16. void __stdcall PrintReportUsage();
  17. void __stdcall PrintKeyUsage();
  18. void __stdcall PrintUsage(UINT uId[], UINT cId);
  19. void __stdcall GetString(UINT uId, LPTSTR pszBuffer, int cchBuffer);
  20. }
  21. using namespace PrintUsage;
  22. //---------------------------------------------------------------------------
  23. // Main
  24. //---------------------------------------------------------------------------
  25. int __cdecl _tmain(int argc, LPTSTR argv[])
  26. {
  27. HRESULT hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
  28. if (SUCCEEDED(hr))
  29. {
  30. _RPT0(_CRT_WARN, _T("{ADMT.exe}_tmain() : Enter\n"));
  31. _CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF|_CRTDBG_LEAK_CHECK_DF);
  32. CMonitorThread mtMonitor;
  33. try
  34. {
  35. CArguments aArgs(argc, argv);
  36. CParameterMap mapParams(aArgs);
  37. long lTask;
  38. if (mapParams.GetValue(SWITCH_TASK, lTask))
  39. {
  40. bool bHelp;
  41. if (!mapParams.GetValue(SWITCH_HELP, bHelp))
  42. {
  43. bHelp = false;
  44. }
  45. switch (lTask)
  46. {
  47. case TASK_USER:
  48. {
  49. if (bHelp)
  50. {
  51. PrintUserUsage();
  52. }
  53. else
  54. {
  55. mtMonitor.Start();
  56. CUserMigration(CMigration(mapParams), mapParams);
  57. mtMonitor.Stop();
  58. }
  59. break;
  60. }
  61. case TASK_GROUP:
  62. {
  63. if (bHelp)
  64. {
  65. PrintGroupUsage();
  66. }
  67. else
  68. {
  69. mtMonitor.Start();
  70. CGroupMigration(CMigration(mapParams), mapParams);
  71. mtMonitor.Stop();
  72. }
  73. break;
  74. }
  75. case TASK_COMPUTER:
  76. {
  77. if (bHelp)
  78. {
  79. PrintComputerUsage();
  80. }
  81. else
  82. {
  83. mtMonitor.Start();
  84. CComputerMigration(CMigration(mapParams), mapParams);
  85. mtMonitor.Stop();
  86. }
  87. break;
  88. }
  89. case TASK_SECURITY:
  90. {
  91. if (bHelp)
  92. {
  93. PrintSecurityUsage();
  94. }
  95. else
  96. {
  97. mtMonitor.Start();
  98. CSecurityTranslation(CMigration(mapParams), mapParams);
  99. mtMonitor.Stop();
  100. }
  101. break;
  102. }
  103. case TASK_SERVICE:
  104. {
  105. if (bHelp)
  106. {
  107. PrintServiceUsage();
  108. }
  109. else
  110. {
  111. mtMonitor.Start();
  112. CServiceEnumeration(CMigration(mapParams), mapParams);
  113. mtMonitor.Stop();
  114. }
  115. break;
  116. }
  117. case TASK_REPORT:
  118. {
  119. if (bHelp)
  120. {
  121. PrintReportUsage();
  122. }
  123. else
  124. {
  125. mtMonitor.Start();
  126. CReportGeneration(CMigration(mapParams), mapParams);
  127. mtMonitor.Stop();
  128. }
  129. break;
  130. }
  131. case TASK_KEY:
  132. {
  133. if (bHelp)
  134. {
  135. PrintKeyUsage();
  136. }
  137. else
  138. {
  139. _bstr_t strKeyId;
  140. if (!mapParams.GetValue(SWITCH_KEY_IDENTIFIER, strKeyId))
  141. {
  142. ThrowError(E_INVALIDARG, IDS_E_NO_KEY_DOMAIN);
  143. }
  144. _bstr_t strDrive;
  145. if (!mapParams.GetValue(SWITCH_KEY_FOLDER, strDrive))
  146. {
  147. ThrowError(E_INVALIDARG, IDS_E_NO_KEY_FOLDER);
  148. }
  149. _bstr_t strPassword;
  150. mapParams.GetValue(SWITCH_KEY_PASSWORD, strPassword);
  151. GeneratePasswordKey(strKeyId, strPassword, strDrive);
  152. }
  153. break;
  154. }
  155. default:
  156. {
  157. _ASSERT(false);
  158. break;
  159. }
  160. }
  161. }
  162. else
  163. {
  164. PrintADMTUsage();
  165. }
  166. }
  167. catch (_com_error& ce)
  168. {
  169. mtMonitor.Stop();
  170. _com_error ceNew(ce);
  171. _bstr_t strDescription = ceNew.Description();
  172. if (!strDescription)
  173. {
  174. IErrorInfo* pErrorInfo = NULL;
  175. if (GetErrorInfo(0, &pErrorInfo) == S_OK)
  176. {
  177. ceNew = _com_error(ceNew.Error(), pErrorInfo);
  178. }
  179. }
  180. _tprintf(_T("%s : %s (0x%08lX)\n"), (LPCTSTR)ceNew.Description(), ceNew.ErrorMessage(), ceNew.Error());
  181. }
  182. catch (...)
  183. {
  184. mtMonitor.Stop();
  185. _tprintf(_T("%s (0x%08lX)\n"), _com_error(E_FAIL).ErrorMessage(), E_FAIL);
  186. }
  187. _RPT0(_CRT_WARN, _T("{ADMT.exe}_tmain() : Leave\n"));
  188. CoUninitialize();
  189. }
  190. return 0;
  191. }
  192. // Print Usage --------------------------------------------------------------
  193. namespace PrintUsage
  194. {
  195. void __stdcall PrintADMTUsage()
  196. {
  197. static UINT s_uId[] =
  198. {
  199. IDS_USAGE_SYNTAX,
  200. IDS_USAGE_ADMT,
  201. };
  202. PrintUsage(s_uId, countof(s_uId));
  203. }
  204. void __stdcall PrintUserUsage()
  205. {
  206. static UINT s_uId[] =
  207. {
  208. // user command
  209. IDS_USAGE_SYNTAX,
  210. IDS_USAGE_USER,
  211. // common options
  212. IDS_USAGE_OPTIONFILE,
  213. IDS_USAGE_TESTMIGRATION,
  214. IDS_USAGE_INTRAFOREST,
  215. IDS_USAGE_SOURCEDOMAIN,
  216. IDS_USAGE_SOURCEOU,
  217. IDS_USAGE_TARGETDOMAIN,
  218. IDS_USAGE_TARGETOU,
  219. // user migration options
  220. IDS_USAGE_PASSWORDOPTION,
  221. IDS_USAGE_PASSWORDSERVER,
  222. IDS_USAGE_PASSWORDFILE,
  223. IDS_USAGE_DISABLEOPTION,
  224. IDS_USAGE_SOURCEEXPIRATION,
  225. IDS_USAGE_MIGRATESIDS,
  226. IDS_USAGE_TRANSLATEROAMINGPROFILE,
  227. IDS_USAGE_UPDATEUSERRIGHTS,
  228. IDS_USAGE_MIGRATEGROUPS,
  229. IDS_USAGE_UPDATEPREVIOUSLYMIGRATEDOBJECTS,
  230. IDS_USAGE_FIXGROUPMEMBERSHIP,
  231. IDS_USAGE_MIGRATESERVICEACCOUNTS,
  232. IDS_USAGE_RENAMEOPTION,
  233. IDS_USAGE_RENAMEPREFIXORSUFFIX,
  234. IDS_USAGE_CONFLICTOPTIONS_U,
  235. IDS_USAGE_CONFLICTPREFIXORSUFFIX,
  236. IDS_USAGE_USERPROPERTIESTOEXCLUDE,
  237. // users to migrate
  238. IDS_USAGE_INCLUDE_A,
  239. IDS_USAGE_EXCLUDE,
  240. IDS_USAGE_FOOTER,
  241. };
  242. PrintUsage(s_uId, countof(s_uId));
  243. }
  244. void __stdcall PrintGroupUsage()
  245. {
  246. static UINT s_uId[] =
  247. {
  248. // group command
  249. IDS_USAGE_SYNTAX,
  250. IDS_USAGE_GROUP,
  251. // common options
  252. IDS_USAGE_OPTIONFILE,
  253. IDS_USAGE_TESTMIGRATION,
  254. IDS_USAGE_INTRAFOREST,
  255. IDS_USAGE_SOURCEDOMAIN,
  256. IDS_USAGE_SOURCEOU,
  257. IDS_USAGE_TARGETDOMAIN,
  258. IDS_USAGE_TARGETOU,
  259. // group migration options
  260. IDS_USAGE_UPDATEGROUPRIGHTS,
  261. IDS_USAGE_FIXGROUPMEMBERSHIP,
  262. IDS_USAGE_MIGRATESIDS,
  263. IDS_USAGE_RENAMEOPTION,
  264. IDS_USAGE_RENAMEPREFIXORSUFFIX,
  265. IDS_USAGE_CONFLICTOPTIONS_G,
  266. IDS_USAGE_CONFLICTPREFIXORSUFFIX,
  267. IDS_USAGE_GROUPPROPERTIESTOEXCLUDE,
  268. // member migration options
  269. IDS_USAGE_MIGRATEMEMBERS,
  270. IDS_USAGE_UPDATEPREVIOUSLYMIGRATEDOBJECTS,
  271. IDS_USAGE_PASSWORDOPTION,
  272. IDS_USAGE_PASSWORDSERVER,
  273. IDS_USAGE_PASSWORDFILE,
  274. IDS_USAGE_DISABLEOPTION,
  275. IDS_USAGE_SOURCEEXPIRATION,
  276. IDS_USAGE_TRANSLATEROAMINGPROFILE,
  277. // groups to migrate
  278. IDS_USAGE_INCLUDE_A,
  279. IDS_USAGE_EXCLUDE,
  280. IDS_USAGE_FOOTER,
  281. };
  282. PrintUsage(s_uId, countof(s_uId));
  283. }
  284. void __stdcall PrintComputerUsage()
  285. {
  286. static UINT s_uId[] =
  287. {
  288. // computer command
  289. IDS_USAGE_SYNTAX,
  290. IDS_USAGE_COMPUTER,
  291. // common options
  292. IDS_USAGE_OPTIONFILE,
  293. IDS_USAGE_TESTMIGRATION,
  294. IDS_USAGE_INTRAFOREST,
  295. IDS_USAGE_SOURCEDOMAIN,
  296. IDS_USAGE_SOURCEOU,
  297. IDS_USAGE_TARGETDOMAIN,
  298. IDS_USAGE_TARGETOU,
  299. // computer migration options
  300. IDS_USAGE_TRANSLATIONOPTION,
  301. IDS_USAGE_TRANSLATEFILESANDFOLDERS,
  302. IDS_USAGE_TRANSLATELOCALGROUPS,
  303. IDS_USAGE_TRANSLATEPRINTERS,
  304. IDS_USAGE_TRANSLATEREGISTRY,
  305. IDS_USAGE_TRANSLATESHARES,
  306. IDS_USAGE_TRANSLATEUSERPROFILES,
  307. IDS_USAGE_TRANSLATEUSERRIGHTS,
  308. IDS_USAGE_RENAMEOPTION,
  309. IDS_USAGE_RENAMEPREFIXORSUFFIX,
  310. IDS_USAGE_CONFLICTOPTIONS_C,
  311. IDS_USAGE_CONFLICTPREFIXORSUFFIX,
  312. IDS_USAGE_RESTARTDELAY,
  313. IDS_USAGE_COMPUTERPROPERTIESTOEXCLUDE,
  314. // computers to migrate
  315. IDS_USAGE_INCLUDE_A,
  316. IDS_USAGE_EXCLUDE,
  317. IDS_USAGE_FOOTER,
  318. };
  319. PrintUsage(s_uId, countof(s_uId));
  320. }
  321. void __stdcall PrintSecurityUsage()
  322. {
  323. static UINT s_uId[] =
  324. {
  325. // security command
  326. IDS_USAGE_SYNTAX,
  327. IDS_USAGE_SECURITY,
  328. // common options
  329. IDS_USAGE_OPTIONFILE,
  330. IDS_USAGE_TESTMIGRATION,
  331. IDS_USAGE_SOURCEDOMAIN,
  332. IDS_USAGE_SOURCEOU,
  333. IDS_USAGE_TARGETDOMAIN,
  334. // security migration options
  335. IDS_USAGE_TRANSLATIONOPTION,
  336. IDS_USAGE_TRANSLATEFILESANDFOLDERS,
  337. IDS_USAGE_TRANSLATELOCALGROUPS,
  338. IDS_USAGE_TRANSLATEPRINTERS,
  339. IDS_USAGE_TRANSLATEREGISTRY,
  340. IDS_USAGE_TRANSLATESHARES,
  341. IDS_USAGE_TRANSLATEUSERPROFILES,
  342. IDS_USAGE_TRANSLATEUSERRIGHTS,
  343. IDS_USAGE_SIDMAPPINGFILE,
  344. // computers to perform security translation on
  345. IDS_USAGE_INCLUDE_C,
  346. IDS_USAGE_EXCLUDE,
  347. IDS_USAGE_FOOTER,
  348. };
  349. PrintUsage(s_uId, countof(s_uId));
  350. }
  351. void __stdcall PrintServiceUsage()
  352. {
  353. static UINT s_uId[] =
  354. {
  355. // security command
  356. IDS_USAGE_SYNTAX,
  357. IDS_USAGE_SERVICE,
  358. // common options
  359. IDS_USAGE_OPTIONFILE,
  360. IDS_USAGE_SOURCEDOMAIN,
  361. IDS_USAGE_SOURCEOU,
  362. // computers to perform security translation on
  363. IDS_USAGE_INCLUDE_C,
  364. IDS_USAGE_EXCLUDE,
  365. IDS_USAGE_FOOTER,
  366. };
  367. PrintUsage(s_uId, countof(s_uId));
  368. }
  369. void __stdcall PrintReportUsage()
  370. {
  371. static UINT s_uId[] =
  372. {
  373. // report command
  374. IDS_USAGE_SYNTAX,
  375. IDS_USAGE_REPORT,
  376. // common options
  377. IDS_USAGE_OPTIONFILE,
  378. IDS_USAGE_SOURCEDOMAIN,
  379. IDS_USAGE_SOURCEOU,
  380. IDS_USAGE_TARGETDOMAIN,
  381. // report options
  382. IDS_USAGE_REPORTTYPE,
  383. IDS_USAGE_REPORTFOLDER,
  384. // computers to generate reports for
  385. IDS_USAGE_INCLUDE_D,
  386. IDS_USAGE_EXCLUDE,
  387. IDS_USAGE_FOOTER,
  388. };
  389. PrintUsage(s_uId, countof(s_uId));
  390. }
  391. void __stdcall PrintKeyUsage()
  392. {
  393. static UINT s_uId[] =
  394. {
  395. IDS_USAGE_SYNTAX,
  396. IDS_USAGE_KEY,
  397. };
  398. PrintUsage(s_uId, countof(s_uId));
  399. }
  400. void __stdcall PrintUsage(UINT uId[], UINT cId)
  401. {
  402. _TCHAR szBuffer[512];
  403. // print this is command syntax line
  404. if (cId > 0)
  405. {
  406. GetString(uId[0], szBuffer, countof(szBuffer));
  407. _tprintf(_T("%s\n\n"), szBuffer);
  408. }
  409. // print command
  410. if (cId > 1)
  411. {
  412. GetString(uId[1], szBuffer, countof(szBuffer));
  413. _tprintf(_T("%s\n\n"), szBuffer);
  414. }
  415. // print options
  416. if (cId > 2)
  417. {
  418. for (UINT i = 2; i < cId; i++)
  419. {
  420. GetString(uId[i], szBuffer, countof(szBuffer));
  421. _tprintf(_T("%s\n"), szBuffer);
  422. }
  423. }
  424. }
  425. void __stdcall GetString(UINT uId, LPTSTR pszBuffer, int cchBuffer)
  426. {
  427. if (pszBuffer)
  428. {
  429. if (LoadString(GetModuleHandle(NULL), uId, pszBuffer, cchBuffer) == 0)
  430. {
  431. pszBuffer[0] = _T('\0');
  432. }
  433. }
  434. }
  435. }