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.

3293 lines
85 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1995 - 1999
  6. //
  7. // File: certutil.cpp
  8. //
  9. //--------------------------------------------------------------------------
  10. #include <pch.cpp>
  11. #pragma hdrstop
  12. #include <setupapi.h>
  13. #include <locale.h>
  14. #include <io.h>
  15. #include <fcntl.h>
  16. #include <ntverp.h>
  17. #include <common.ver>
  18. #include "ocmanage.h"
  19. #include "initcert.h"
  20. #include <winldap.h>
  21. #include "csldap.h"
  22. #include "setupids.h"
  23. #include "clibres.h"
  24. #include "csresstr.h"
  25. #define __dwFILE__ __dwFILE_CERTUTIL_CERTUTIL_CPP__
  26. #define WM_DOCERTUTILMAIN WM_USER+0
  27. WCHAR const wszAppName[] = L"CertUtilApp";
  28. WCHAR const *g_pwszProg = L"CertUtil";
  29. HINSTANCE g_hInstance;
  30. BOOL g_fIDispatch = FALSE;
  31. BOOL g_fEnterpriseRegistry = FALSE;
  32. BOOL g_fUserRegistry = FALSE;
  33. BOOL g_fUserTemplates = FALSE;
  34. BOOL g_fMachineTemplates = FALSE;
  35. BOOL g_fNoCR = FALSE;
  36. BOOL g_fFullUsage = FALSE;
  37. BOOL g_fReverse = FALSE;
  38. BOOL g_fForce = FALSE;
  39. BOOL g_fVerbose = FALSE;
  40. BOOL g_fGMT = FALSE;
  41. BOOL g_fSeconds = FALSE;
  42. DWORD g_DispatchFlags;
  43. BOOL g_fQuiet = FALSE;
  44. BOOL g_fCryptSilent = FALSE;
  45. BOOL g_fV1Interface = FALSE;
  46. BOOL g_fSplitASN = FALSE;
  47. BOOL g_fAdminInterface = FALSE;
  48. BOOL g_fProtect = FALSE;
  49. BOOL g_fWeakPFX = FALSE;
  50. BOOL g_fURLFetch = FALSE;
  51. DWORD g_EncodeFlags;
  52. DWORD g_CryptEncodeFlags;
  53. DWORD g_dwmsTimeout = 0;
  54. WCHAR *g_pwszConfig = NULL; // Don't free this one!
  55. WCHAR *g_pwszConfigAlloc = NULL; // Free this one instead!
  56. WCHAR *g_pwszDC = NULL;
  57. WCHAR *g_pwszOut = NULL;
  58. WCHAR *g_pwszPassword = NULL;
  59. WCHAR *g_pwszCSP = NULL;
  60. WCHAR *g_pwszRestrict = NULL;
  61. WCHAR *g_pwszDnsName = NULL;
  62. WCHAR *g_pwszOldName = NULL;
  63. WCHAR *g_pwszmsTimeout = NULL;
  64. WCHAR const g_wszEmpty[] = L"";
  65. WCHAR const g_wszPad2[] = L" ";
  66. WCHAR const g_wszPad4[] = L" ";
  67. WCHAR const g_wszPad6[] = L" ";
  68. WCHAR const g_wszPad8[] = L" ";
  69. WCHAR const wszNewLine[] = L"\n";
  70. UINT g_uiExtraErrorInfo = 0;
  71. CRITICAL_SECTION g_DBCriticalSection;
  72. #define CCOL_VERB 16
  73. #define CCOL_OPTIONBARE 16
  74. #define CCOL_OPTIONARG 24
  75. #define AF_ZERO 0
  76. #define AF_NEEDCOINIT 0x00000001
  77. #define AF_ACTIVECONFIG 0x00000002 // CA must be running
  78. #define AF_PRIVATE 0x00000004 // Undocumented, untested
  79. #define AF_OPTIONALCONFIG 0x00000008
  80. #define AF_RESTARTSERVER 0x00000010
  81. #define AF_STOPATMINUSSIGNARG 0x00000020 // no more '-xxx' args
  82. #define AF_STOPATMINUSSIGN 0x00000040 // no more '-' args
  83. #define AF_OPTION_TIMEOUT 0x00000080
  84. #define AF_OPTION_URLFETCH 0x00000100
  85. #define AF_OPTION_CSP 0x00000200
  86. #define AF_OPTION_PROTECT 0x00000400
  87. #define AF_OPTION_WEAKPFX 0x00000800
  88. #define AF_OPTION_DC 0x00001000
  89. #define AF_OPTION_PASSWORD 0x00002000
  90. #define AF_OPTION_ADMIN 0x00004000
  91. #define AF_OPTION_CONFIG 0x00008000
  92. #define AF_OPTION_ENTERPRISE 0x00010000
  93. #define AF_OPTION_FORCE 0x00020000
  94. #define AF_OPTION_GMT 0x00040000
  95. #define AF_OPTION_IDISPATCH 0x00080000
  96. #define AF_OPTION_MT 0x00100000
  97. #define AF_OPTION_NOCR 0x00200000
  98. #define AF_OPTION_OUT 0x00400000
  99. #define AF_OPTION_RESTRICT 0x00800000
  100. #define AF_OPTION_REVERSE 0x01000000
  101. #define AF_OPTION_SECONDS 0x02000000
  102. #define AF_OPTION_SILENT 0x04000000
  103. #define AF_OPTION_SPLIT 0x08000000
  104. #define AF_OPTION_USER 0x10000000
  105. #define AF_OPTION_UT 0x20000000
  106. #define AF_OPTION_V1 0x40000000
  107. #define AF_OPTION_VERBOSE 0x80000000
  108. #define AF_OPTION_GENERIC (AF_OPTION_SECONDS | AF_OPTION_GMT | AF_OPTION_VERBOSE)
  109. #define AF_OPTION_MASK 0xffffff80
  110. typedef struct _ARG
  111. {
  112. WCHAR const *pwszArg;
  113. int idsDescription;
  114. int idsUsage;
  115. int idsArgDescription;
  116. int cArgMin;
  117. int cArgMax;
  118. DWORD Flags;
  119. BOOL *pBool;
  120. WCHAR **ppString;
  121. FNVERB *pfnVerb;
  122. WCHAR const * const *papwszUsageConstants;
  123. WCHAR const *pwszUsage;
  124. WCHAR const *pwszDescription;
  125. } ARG;
  126. WCHAR const g_wszCACert[] = L"ca.cert";
  127. WCHAR const g_wszCAChain[] = L"ca.chain";
  128. WCHAR const g_wszGetCRL[] = L"GetCRL";
  129. WCHAR const g_wszCAInfo[] = L"CAInfo";
  130. WCHAR const g_wszSchema[] = L"schema";
  131. WCHAR const g_wszEncode[] = L"encode";
  132. WCHAR const g_wszEncodeHex[] = L"encodehex";
  133. WCHAR const g_wszViewDelStore[] = L"viewdelstore";
  134. WCHAR const *g_papwszUsageDeleteRow[] =
  135. { L"Request", L"Cert", L"Ext", L"Attrib", L"CRL", NULL };
  136. WCHAR const *g_papwszUsageCRL[] = { L"republish", L"delta", NULL };
  137. WCHAR const *g_papwszUsageGetCRL[] = { L"delta", NULL };
  138. WCHAR const *g_papwszUsageSchema[] = { L"Ext", L"Attrib", L"CRL", NULL };
  139. WCHAR const *g_papwszUsageView[] =
  140. { L"Queue", L"Log", L"LogFail", L"Revoked", L"Ext", L"Attrib", L"CRL", NULL };
  141. WCHAR const *g_papwszUsageBackup[] = { L"Incremental", L"KeepLog", NULL };
  142. WCHAR const *g_papwszUsageDSPublish[] =
  143. { L"NTAuthCA", L"RootCA", L"SubCA", L"CrossCA", L"KRA", L"User", L"Machine", L"-f", NULL };
  144. WCHAR const *g_papwszUsageDCInfo[] =
  145. { L"Verify", L"DeleteBad", L"DeleteAll", NULL };
  146. WCHAR const *g_papwszUsageGetCert[] = { L"ERA", L"KRA", NULL };
  147. WCHAR const *g_papwszUsageDelete[] = { L"delete", NULL };
  148. WCHAR const *g_papwszUsageURLCache[] =
  149. { L"CRL", L"*", L"delete", L"-f", NULL };
  150. WCHAR const *g_papwszUsageGetSetReg[] =
  151. { L"ca", L"restore", L"policy", L"exit", L"template", L"ProgId", NULL };
  152. WCHAR g_wszDefaultLangId[cwcDWORDSPRINTF];
  153. WCHAR const *g_papwszUsageOIDName[] =
  154. { L"delete", g_wszDefaultLangId, L"-f", NULL };
  155. WCHAR const *g_papwszUsageConvertEPF[] = { L"cast", L"cast-", NULL };
  156. WCHAR const *g_papwszUsageRevokeCertificate[] =
  157. {
  158. L"CRL_REASON_UNSPECIFIED",
  159. L"CRL_REASON_KEY_COMPROMISE",
  160. L"CRL_REASON_CA_COMPROMISE",
  161. L"CRL_REASON_AFFILIATION_CHANGED",
  162. L"CRL_REASON_SUPERSEDED",
  163. L"CRL_REASON_CESSATION_OF_OPERATION",
  164. L"CRL_REASON_CERTIFICATE_HOLD",
  165. L"CRL_REASON_REMOVE_FROM_CRL",
  166. L"Unrevoke",
  167. NULL
  168. };
  169. WCHAR const *g_papwszUsageMinusf[] = { L"-f", NULL };
  170. WCHAR const *g_papwszUsageRenew[] = { L"ReuseKeys", L"-f", NULL };
  171. WCHAR const *g_papwszUsageStore[] = {
  172. /* %1 */ L"My",
  173. /* %2 */ L"CA",
  174. /* %3 */ L"Root",
  175. /* %4 */ L"-enterprise",
  176. /* %5 */ L"-user",
  177. /* %6 */ L"-enterprise NTAuth",
  178. /* %7 */ L"-enterprise Root 37",
  179. /* %8 */ L"-user My 26e0aaaf000000000004",
  180. /* %9 */ L"CA .11",
  181. /* %10 */ g_wszEmpty, // View Root Certificates URL
  182. /* %11 */ g_wszEmpty, // Modify Root Certificates URL
  183. /* %12 */ g_wszEmpty, // View CRLs
  184. /* %13 */ g_wszEmpty, // Enterprise CA Certificates URL
  185. NULL
  186. };
  187. typedef struct _CUURLTEMPLATE {
  188. WCHAR const *pwszFmtPrefix;
  189. WCHAR const *pwszAttribute;
  190. WCHAR const **ppwszUsageLocation;
  191. } CUURLTEMPLATE;
  192. CUURLTEMPLATE g_aURLTemplates[] = {
  193. {
  194. L"ldap:///CN=Certification Authorities",
  195. wszDSSEARCHAIACERTATTRIBUTE,
  196. &g_papwszUsageStore[10 - 1],
  197. },
  198. {
  199. L"ldap:///CN=%ws,CN=Certification Authorities",
  200. wszDSSEARCHCACERTATTRIBUTE,
  201. &g_papwszUsageStore[11 - 1],
  202. },
  203. {
  204. L"ldap:///CN=%ws,CN=%ws,CN=CDP",
  205. wszDSSEARCHBASECRLATTRIBUTE,
  206. &g_papwszUsageStore[12 - 1],
  207. },
  208. {
  209. L"ldap:///CN=NTAuthCertificates",
  210. L"",
  211. &g_papwszUsageStore[13 - 1],
  212. },
  213. };
  214. VOID
  215. PatchStoreArgDescription()
  216. {
  217. HRESULT hr;
  218. DWORD i;
  219. WCHAR const *pwszCAName = myLoadResourceString(IDS_CANAME);
  220. WCHAR const *pwszMachineName = myLoadResourceString(IDS_MACHINENAME);
  221. WCHAR const *pwszDCName = L"DC=...";
  222. WCHAR const wszFmtURL[] = L"%ws,CN=Public Key Services,CN=Services,CN=Configuration,%ws%ws";
  223. WCHAR *pwszPrefix = NULL;
  224. BSTR strDomainDN = NULL;
  225. LDAP *pld = NULL;
  226. static BOOL fFirst = TRUE;
  227. if (fFirst)
  228. {
  229. fFirst = FALSE;
  230. hr = myLdapOpen(NULL, 0, &pld, &strDomainDN, NULL);
  231. _PrintIfError2(hr, "myLdapOpen", hr);
  232. if (S_OK == hr && NULL != strDomainDN)
  233. {
  234. pwszDCName = strDomainDN;
  235. }
  236. for (i = 0; i < ARRAYSIZE(g_aURLTemplates); i++)
  237. {
  238. DWORD cwc;
  239. WCHAR *pwsz = NULL;
  240. if (NULL != pwszPrefix)
  241. {
  242. LocalFree(pwszPrefix);
  243. pwszPrefix = NULL;
  244. }
  245. cwc = wcslen(g_aURLTemplates[i].pwszFmtPrefix) +
  246. wcslen(pwszCAName) +
  247. wcslen(pwszMachineName);
  248. pwszPrefix = (WCHAR *) LocalAlloc(
  249. LMEM_FIXED,
  250. (cwc + 1) * sizeof(WCHAR));
  251. if (NULL == pwszPrefix)
  252. {
  253. _PrintError(E_OUTOFMEMORY, "LocalAlloc");
  254. continue;
  255. }
  256. _snwprintf(
  257. pwszPrefix,
  258. cwc,
  259. g_aURLTemplates[i].pwszFmtPrefix,
  260. pwszCAName,
  261. pwszMachineName);
  262. pwszPrefix[cwc] = L'\0';
  263. cwc += ARRAYSIZE(wszFmtURL) +
  264. wcslen(pwszDCName) +
  265. wcslen(g_aURLTemplates[i].pwszAttribute);
  266. pwsz = (WCHAR *) LocalAlloc(
  267. LMEM_FIXED,
  268. (cwc + 1) * sizeof(WCHAR));
  269. if (NULL == pwsz)
  270. {
  271. _PrintError(E_OUTOFMEMORY, "LocalAlloc");
  272. }
  273. _snwprintf(
  274. pwsz,
  275. cwc,
  276. wszFmtURL,
  277. pwszPrefix,
  278. pwszDCName,
  279. g_aURLTemplates[i].pwszAttribute);
  280. pwsz[cwc] = L'\0';
  281. *g_aURLTemplates[i].ppwszUsageLocation = pwsz;
  282. }
  283. if (NULL != pwszPrefix)
  284. {
  285. LocalFree(pwszPrefix);
  286. }
  287. myLdapClose(pld, strDomainDN, NULL);
  288. }
  289. }
  290. VOID
  291. FreeStoreArgDescription()
  292. {
  293. DWORD i;
  294. for (i = 0; i < ARRAYSIZE(g_aURLTemplates); i++)
  295. {
  296. if (NULL != *g_aURLTemplates[i].ppwszUsageLocation &&
  297. g_wszEmpty != *g_aURLTemplates[i].ppwszUsageLocation)
  298. {
  299. LocalFree(const_cast<WCHAR *>(*g_aURLTemplates[i].ppwszUsageLocation));
  300. }
  301. }
  302. }
  303. #define pargDEFAULT (&aarg[0]) // Default to first entry
  304. ARG aarg[] =
  305. {
  306. { // In first position to be the default
  307. L"dump", // pwszArg
  308. IDS_DUMP_DESCRIPTION, // "dump configuration information or files"
  309. IDS_DUMP_USAGEARGS, // "[File]"
  310. 0, // idsArgDescription
  311. 0, // cArgMin
  312. 1, // cArgMax
  313. AF_OPTION_TIMEOUT | AF_OPTION_PASSWORD | AF_OPTION_SPLIT | AF_OPTION_IDISPATCH | AF_OPTION_FORCE | AF_NEEDCOINIT, // Flags
  314. NULL, // pBool
  315. NULL, // ppString
  316. verbDump, // pfnVerb
  317. NULL, // papwszUsageConstants
  318. },
  319. { L"", },
  320. {
  321. L"decodehex", // pwszArg
  322. IDS_DECODEHEX_DESCRIPTION, // "Decode hexadecimal-encoded file"
  323. IDS_INFILEOUTFILE_USAGEARGS, // "InFile OutFile"
  324. 0, // idsArgDescription
  325. 2, // cArgMin
  326. 2, // cArgMax
  327. AF_OPTION_FORCE, // Flags
  328. NULL, // pBool
  329. NULL, // ppString
  330. verbHexTranslate, // pfnVerb
  331. NULL, // papwszUsageConstants
  332. },
  333. {
  334. g_wszEncodeHex, // pwszArg
  335. IDS_ENCODEHEX_DESCRIPTION, // "Encode file in hexadecimal"
  336. IDS_ENCODEHEX_USAGEARGS, // "InFile OutFile [type]"
  337. 0, // idsArgDescription
  338. 2, // cArgMin
  339. 3, // cArgMax
  340. AF_OPTION_NOCR | AF_OPTION_FORCE | AF_PRIVATE, // Flags
  341. NULL, // pBool
  342. NULL, // ppString
  343. verbHexTranslate, // pfnVerb
  344. NULL, // papwszUsageConstants
  345. },
  346. {
  347. L"decode", // pwszArg
  348. IDS_DECODE_DESCRIPTION, // "Decode Base64-encoded file"
  349. IDS_INFILEOUTFILE_USAGEARGS, // "InFile OutFile"
  350. 0, // idsArgDescription
  351. 2, // cArgMin
  352. 2, // cArgMax
  353. AF_OPTION_FORCE, // Flags
  354. NULL, // pBool
  355. NULL, // ppString
  356. verbBase64Translate, // pfnVerb
  357. NULL, // papwszUsageConstants
  358. },
  359. {
  360. g_wszEncode, // pwszArg
  361. IDS_ENCODE_DESCRIPTION, // "Encode file to Base64"
  362. IDS_INFILEOUTFILE_USAGEARGS, // "InFile OutFile"
  363. 0, // idsArgDescription
  364. 2, // cArgMin
  365. 2, // cArgMax
  366. AF_OPTION_NOCR | AF_OPTION_FORCE, // Flags
  367. NULL, // pBool
  368. NULL, // ppString
  369. verbBase64Translate, // pfnVerb
  370. NULL, // papwszUsageConstants
  371. },
  372. { L"", },
  373. {
  374. L"deny", // pwszArg
  375. IDS_DENY_DESCRIPTION, // "Deny pending request"
  376. IDS_DENY_USAGEARGS, // "RequestId"
  377. 0, // idsArgDescription
  378. 1, // cArgMin
  379. 1, // cArgMax
  380. AF_OPTION_IDISPATCH | AF_OPTION_CONFIG | AF_ACTIVECONFIG | AF_NEEDCOINIT, // Flags
  381. NULL, // pBool
  382. NULL, // ppString
  383. verbDenyRequest, // pfnVerb
  384. NULL, // papwszUsageConstants
  385. },
  386. {
  387. L"resubmit", // pwszArg
  388. IDS_RESUBMIT_DESCRIPTION, // "Resubmit pending request"
  389. IDS_RESUBMIT_USAGEARGS, // "RequestId"
  390. 0, // idsArgDescription
  391. 1, // cArgMin
  392. 1, // cArgMax
  393. AF_OPTION_IDISPATCH | AF_OPTION_CONFIG | AF_ACTIVECONFIG | AF_NEEDCOINIT, // Flags
  394. NULL, // pBool
  395. NULL, // ppString
  396. verbResubmitRequest, // pfnVerb
  397. NULL, // papwszUsageConstants
  398. },
  399. {
  400. L"setattributes", // pwszArg
  401. IDS_SETATTRIBUTES_DESCRIPTION, // "Set attributes for pending request"
  402. IDS_SETATTRIBUTES_USAGEARGS, // "RequestId AttributeString"
  403. IDS_SETATTRIBUTES_ARGDESCRIPTION, // idsArgDescription
  404. 2, // cArgMin
  405. 2, // cArgMax
  406. AF_OPTION_IDISPATCH | AF_OPTION_CONFIG | AF_ACTIVECONFIG | AF_NEEDCOINIT, // Flags
  407. NULL, // pBool
  408. NULL, // ppString
  409. verbSetAttributes, // pfnVerb
  410. NULL, // papwszUsageConstants
  411. },
  412. {
  413. L"setextension", // pwszArg
  414. IDS_SETEXTENSION_DESCRIPTION, // "Set extension for pending request"
  415. IDS_SETEXTENSION_USAGEARGS, // "RequestId ExtensionName Flags {Long | Date | String | @InFile}"
  416. IDS_SETEXTENSION_ARGDESCRIPTION, // idsArgDescription
  417. 4, // cArgMin
  418. 4, // cArgMax
  419. AF_OPTION_IDISPATCH | AF_OPTION_CONFIG | AF_ACTIVECONFIG | AF_NEEDCOINIT, // Flags
  420. NULL, // pBool
  421. NULL, // ppString
  422. verbSetExtension, // pfnVerb
  423. NULL, // papwszUsageConstants
  424. },
  425. {
  426. L"revoke", // pwszArg
  427. IDS_REVOKE_DESCRIPTION, // "Revoke certificate"
  428. IDS_REVOKE_USAGEARGS, // "SerialNumber"
  429. IDS_REVOKE_ARGDESCRIPTION, // idsArgDescription
  430. 1, // cArgMin
  431. 2, // cArgMax
  432. AF_OPTION_IDISPATCH | AF_OPTION_CONFIG | AF_ACTIVECONFIG | AF_NEEDCOINIT, // Flags
  433. NULL, // pBool
  434. NULL, // ppString
  435. verbRevokeCertificate, // pfnVerb
  436. g_papwszUsageRevokeCertificate, // papwszUsageConstants
  437. },
  438. {
  439. L"isvalid", // pwszArg
  440. IDS_ISVALID_DESCRIPTION, // "Display current certificate disposition"
  441. IDS_ISVALID_USAGEARGS, // "SerialNumber | CertHash"
  442. 0, // idsArgDescription
  443. 1, // cArgMin
  444. 1, // cArgMax
  445. AF_OPTION_IDISPATCH | AF_OPTION_CONFIG | AF_ACTIVECONFIG | AF_NEEDCOINIT, // Flags
  446. NULL, // pBool
  447. NULL, // ppString
  448. verbIsValidCertificate, // pfnVerb
  449. NULL, // papwszUsageConstants
  450. },
  451. { L"", },
  452. {
  453. L"getconfig", // pwszArg
  454. IDS_GETCONFIG_DESCRIPTION, // "get default configuration string"
  455. 0, // idsUsage
  456. 0, // idsArgDescription
  457. 0, // cArgMin
  458. 0, // cArgMax
  459. AF_OPTION_IDISPATCH | AF_OPTION_CONFIG | AF_ACTIVECONFIG | AF_NEEDCOINIT, // Flags
  460. NULL, // pBool
  461. NULL, // ppString
  462. verbGetConfig, // pfnVerb
  463. NULL, // papwszUsageConstants
  464. },
  465. {
  466. L"getconfig2", // pwszArg
  467. IDS_GETCONFIG2_DESCRIPTION, // "get default configuration string via ICertGetConfig"
  468. 0, // idsUsage
  469. 0, // idsArgDescription
  470. 0, // cArgMin
  471. 1, // cArgMax
  472. AF_OPTION_IDISPATCH | AF_NEEDCOINIT | AF_PRIVATE, // Flags
  473. NULL, // pBool
  474. NULL, // ppString
  475. verbGetConfig2, // pfnVerb
  476. NULL, // papwszUsageConstants
  477. },
  478. {
  479. L"getconfig3", // pwszArg
  480. IDS_GETCONFIG3_DESCRIPTION, // "get configuration via ICertConfig"
  481. 0, // idsUsage
  482. 0, // idsArgDescription
  483. 0, // cArgMin
  484. 1, // cArgMax
  485. AF_OPTION_IDISPATCH | AF_NEEDCOINIT | AF_PRIVATE, // Flags
  486. NULL, // pBool
  487. NULL, // ppString
  488. verbGetConfig3, // pfnVerb
  489. NULL, // papwszUsageConstants
  490. },
  491. {
  492. L"ping", // pwszArg
  493. IDS_PING_DESCRIPTION, // "Ping Certificate Server"
  494. 0, // idsUsage
  495. 0, // idsArgDescription
  496. 0, // cArgMin
  497. 0, // cArgMax
  498. AF_OPTION_IDISPATCH | AF_OPTION_CONFIG | AF_NEEDCOINIT, // Flags
  499. NULL, // pBool
  500. NULL, // ppString
  501. verbPing, // pfnVerb
  502. NULL, // papwszUsageConstants
  503. },
  504. {
  505. L"pingadmin", // pwszArg
  506. IDS_PINGADMIN_DESCRIPTION, // "Ping Certificate Server Admin interface"
  507. 0, // idsUsage
  508. 0, // idsArgDescription
  509. 0, // cArgMin
  510. 0, // cArgMax
  511. AF_OPTION_IDISPATCH | AF_OPTION_CONFIG | AF_NEEDCOINIT, // Flags
  512. NULL, // pBool
  513. NULL, // ppString
  514. verbPingAdmin, // pfnVerb
  515. NULL, // papwszUsageConstants
  516. },
  517. {
  518. g_wszCAInfo, // pwszArg
  519. IDS_CAINFO_DESCRIPTION, // "Display CA Information"
  520. IDS_CAINFO_USAGEARGS, // "[InfoName [Index | ErrorCode]]"
  521. IDS_CAINFO_ARGDESCRIPTION, // idsArgDescription
  522. 0, // cArgMin
  523. 2, // cArgMax
  524. AF_OPTION_V1 | AF_OPTION_SPLIT | AF_OPTION_FORCE | AF_OPTION_ADMIN | AF_OPTION_IDISPATCH | AF_OPTION_CONFIG | AF_ACTIVECONFIG | AF_NEEDCOINIT, // Flags
  525. NULL, // pBool
  526. NULL, // ppString
  527. verbGetCAInfo, // pfnVerb
  528. NULL, // papwszUsageConstants
  529. },
  530. {
  531. L"CAPropInfo", // pwszArg
  532. IDS_CAPROPINFO_DESCRIPTION,// "Display CA Property Type Information"
  533. 0, // idsUsage
  534. 0, // idsArgDescription
  535. 0, // cArgMin
  536. 0, // cArgMax
  537. AF_OPTION_V1 | AF_OPTION_IDISPATCH | AF_OPTION_ADMIN | AF_OPTION_CONFIG | AF_ACTIVECONFIG | AF_NEEDCOINIT | AF_PRIVATE, // Flags
  538. NULL, // pBool
  539. NULL, // ppString
  540. verbGetCAPropInfo, // pfnVerb
  541. NULL, // papwszUsageConstants
  542. },
  543. {
  544. g_wszCACert, // pwszArg
  545. IDS_CACERT_DESCRIPTION, // "Retrieve the CA's certificate"
  546. IDS_CACERT_USAGEARGS, // "OutCACertFile [Index]"
  547. IDS_CACERT_ARGDESCRIPTION, // idsArgDescription
  548. 1, // cArgMin
  549. 2, // cArgMax
  550. AF_OPTION_V1 | AF_OPTION_SPLIT | AF_OPTION_FORCE | AF_OPTION_ADMIN | AF_OPTION_IDISPATCH | AF_OPTION_CONFIG | AF_ACTIVECONFIG | AF_NEEDCOINIT, // Flags
  551. NULL, // pBool
  552. NULL, // ppString
  553. verbGetCACertificate, // pfnVerb
  554. NULL, // papwszUsageConstants
  555. },
  556. {
  557. g_wszCAChain, // pwszArg
  558. IDS_CACHAIN_DESCRIPTION,// "Retrieve the CA's certificate chain"
  559. IDS_CACHAIN_USAGEARGS, // "OutCACertChainFile [Index]"
  560. IDS_CACHAIN_ARGDESCRIPTION, // idsArgDescription
  561. 1, // cArgMin
  562. 2, // cArgMax
  563. AF_OPTION_V1 | AF_OPTION_SPLIT | AF_OPTION_FORCE | AF_OPTION_ADMIN | AF_OPTION_IDISPATCH | AF_OPTION_CONFIG | AF_ACTIVECONFIG | AF_NEEDCOINIT, // Flags
  564. NULL, // pBool
  565. NULL, // ppString
  566. verbGetCACertificate, // pfnVerb
  567. NULL, // papwszUsageConstants
  568. },
  569. {
  570. g_wszGetCRL, // pwszArg
  571. IDS_GETCRL_DESCRIPTION, // "Get CRL"
  572. IDS_GETCRL_USAGEARGS, // "OutFile [Index] [%1]"
  573. IDS_GETCRL_ARGDESCRIPTION, // idsArgDescription
  574. 1, // cArgMin
  575. 3, // cArgMax
  576. AF_OPTION_V1 | AF_OPTION_SPLIT | AF_OPTION_IDISPATCH | AF_OPTION_FORCE | AF_OPTION_ADMIN | AF_OPTION_CONFIG | AF_ACTIVECONFIG | AF_NEEDCOINIT, // Flags
  577. NULL, // pBool
  578. NULL, // ppString
  579. verbGetCRL, // pfnVerb
  580. g_papwszUsageGetCRL, // papwszUsageConstants
  581. },
  582. {
  583. L"CRL", // pwszArg
  584. IDS_CRL_DESCRIPTION, // "Publish new CRL [optionally delta CRL only]"
  585. IDS_CRL_USAGEARGS, // "[dd:hh | %1] [%2]"
  586. IDS_CRL_ARGDESCRIPTION, // idsArgDescription
  587. 0, // cArgMin
  588. 2, // cArgMax
  589. AF_OPTION_V1 | AF_OPTION_SPLIT | AF_OPTION_IDISPATCH | AF_OPTION_CONFIG | AF_ACTIVECONFIG | AF_NEEDCOINIT, // Flags
  590. NULL, // pBool
  591. NULL, // ppString
  592. verbPublishCRL, // pfnVerb
  593. g_papwszUsageCRL, // papwszUsageConstants
  594. },
  595. {
  596. L"shutdown", // pwszArg
  597. IDS_SHUTDOWN_DESCRIPTION, // "Shutdown Certificate Server"
  598. 0, // idsUsage
  599. 0, // idsArgDescription
  600. 0, // cArgMin
  601. 0, // cArgMax
  602. AF_OPTION_IDISPATCH | AF_OPTION_CONFIG | AF_ACTIVECONFIG | AF_NEEDCOINIT, // Flags
  603. NULL, // pBool
  604. NULL, // ppString
  605. verbShutDownServer, // pfnVerb
  606. NULL, // papwszUsageConstants
  607. },
  608. { L"", },
  609. {
  610. L"installCert", // pwszArg
  611. IDS_INSTALLCERT_DESCRIPTION, // "Install Certification Authority certificate"
  612. IDS_INSTALLCERT_USAGEARGS, // "CACertFile"
  613. 0, // idsArgDescription
  614. 0, // cArgMin
  615. 1, // cArgMax
  616. AF_OPTION_SILENT | AF_OPTION_FORCE | AF_OPTION_CONFIG | AF_NEEDCOINIT | AF_RESTARTSERVER, // Flags
  617. NULL, // pBool
  618. NULL, // ppString
  619. verbInstallCACert, // pfnVerb
  620. NULL, // papwszUsageConstants
  621. },
  622. {
  623. L"renewCert", // pwszArg
  624. IDS_RENEWCERT_DESCRIPTION, // "Renew Certification Authority certificate"
  625. IDS_RENEWCERT_USAGEARGS, // "[%1] [Machine\\ParemtCAName]"
  626. IDS_RENEWCERT_ARGDESCRIPTION, // idsArgDescription
  627. 0, // cArgMin
  628. 2, // cArgMax
  629. AF_OPTION_SILENT | AF_OPTION_FORCE | AF_OPTION_CONFIG | AF_NEEDCOINIT | AF_RESTARTSERVER, // Flags
  630. NULL, // pBool
  631. NULL, // ppString
  632. verbRenewCACert, // pfnVerb
  633. g_papwszUsageRenew, // papwszUsageConstants
  634. },
  635. { L"", },
  636. {
  637. g_wszSchema, // pwszArg
  638. IDS_SCHEMA_DESCRIPTION, // "Dump certificate schema"
  639. IDS_SCHEMA_USAGE, // "[%1 | %2 | %3]"
  640. IDS_SCHEMA_ARGDESCRIPTION, // idsArgDescription
  641. 0, // cArgMin
  642. 1, // cArgMax
  643. AF_OPTION_SPLIT | AF_OPTION_CONFIG | AF_OPTION_IDISPATCH | AF_ACTIVECONFIG | AF_NEEDCOINIT, // Flags
  644. NULL, // pBool
  645. NULL, // ppString
  646. verbViewDump, // pfnVerb
  647. g_papwszUsageSchema, // papwszUsageConstants
  648. },
  649. {
  650. L"view", // pwszArg
  651. IDS_VIEW_DESCRIPTION, // "Dump certificate view"
  652. IDS_VIEW_USAGE, // "[%1 | %2 | %3 | %4 | %5 | %6 | %7]"
  653. IDS_VIEW_ARGDESCRIPTION, // idsArgDescription
  654. 0, // cArgMin
  655. 2, // cArgMax
  656. AF_OPTION_SILENT | AF_OPTION_SPLIT | AF_OPTION_REVERSE | AF_OPTION_IDISPATCH | AF_OPTION_CONFIG | AF_ACTIVECONFIG | AF_NEEDCOINIT | AF_OPTION_OUT | AF_OPTION_RESTRICT, // Flags
  657. NULL, // pBool
  658. NULL, // ppString
  659. verbViewDump, // pfnVerb
  660. g_papwszUsageView, // papwszUsageConstants
  661. },
  662. {
  663. L"db", // pwszArg
  664. IDS_DB_DESCRIPTION, // "Dump Raw Database"
  665. IDS_VIEW_USAGE, // "[%1 | %2 | %3 | %4 | %5 | %6 | %7]"
  666. 0, // idsArgDescription
  667. 0, // cArgMin
  668. 1, // cArgMax
  669. AF_OPTION_SILENT | AF_OPTION_SPLIT | AF_OPTION_FORCE | AF_OPTION_CONFIG | AF_NEEDCOINIT | AF_OPTION_OUT | AF_OPTION_RESTRICT | AF_PRIVATE, // Flags
  670. NULL, // pBool
  671. NULL, // ppString
  672. verbDBDump, // pfnVerb
  673. g_papwszUsageView, // papwszUsageConstants
  674. },
  675. {
  676. L"deleterow", // pwszArg
  677. IDS_DELETEROW_DESCRIPTION, // "Delete server database row"
  678. IDS_DELETEROW_USAGEARGS, // "RowId | Date [%1 | %2 | %3 | %4 | %5]"
  679. IDS_DELETEROW_ARGDESCRIPTION, // idsArgDescription
  680. 1, // cArgMin
  681. 2, // cArgMax
  682. AF_OPTION_IDISPATCH | AF_OPTION_FORCE | AF_OPTION_CONFIG | AF_ACTIVECONFIG | AF_NEEDCOINIT, // Flags
  683. NULL, // pBool
  684. NULL, // ppString
  685. verbDeleteRow, // pfnVerb
  686. g_papwszUsageDeleteRow, // papwszUsageConstants
  687. },
  688. { L"", },
  689. {
  690. L"backup", // pwszArg
  691. IDS_BACKUP_DESCRIPTION, // "backup certificate server"
  692. IDS_BACKUP_USAGEARGS, // "BackupDirectory [%1] [%2]"
  693. IDS_BACKUP_ARGDESCRIPTION, // idsArgDescription
  694. 1, // cArgMin
  695. 3, // cArgMax
  696. AF_OPTION_WEAKPFX | AF_OPTION_PASSWORD | AF_OPTION_FORCE | AF_OPTION_CONFIG | AF_ACTIVECONFIG | AF_NEEDCOINIT, // Flags
  697. NULL, // pBool
  698. NULL, // ppString
  699. verbBackup, // pfnVerb
  700. g_papwszUsageBackup, // papwszUsageConstants
  701. },
  702. {
  703. L"backupDB", // pwszArg
  704. IDS_BACKUPDB_DESCRIPTION, // "backup certificate server data base"
  705. IDS_BACKUPDB_USAGEARGS, // "BackupDirectory [%1] [%2]"
  706. IDS_BACKUPDB_ARGDESCRIPTION, // idsArgDescription
  707. 1, // cArgMin
  708. 3, // cArgMax
  709. AF_OPTION_FORCE | AF_OPTION_CONFIG | AF_ACTIVECONFIG | AF_NEEDCOINIT, // Flags
  710. NULL, // pBool
  711. NULL, // ppString
  712. verbBackupDB, // pfnVerb
  713. g_papwszUsageBackup, // papwszUsageConstants
  714. },
  715. {
  716. L"backupKey", // pwszArg
  717. IDS_BACKUPPFX_DESCRIPTION, // "backup certificate server certificate and private key"
  718. IDS_BACKUPPFX_USAGEARGS, // "BackupDirectory"
  719. IDS_BACKUPPFX_ARGDESCRIPTION, // idsArgDescription
  720. 1, // cArgMin
  721. 1, // cArgMax
  722. AF_OPTION_TIMEOUT | AF_OPTION_WEAKPFX | AF_OPTION_PASSWORD | AF_OPTION_FORCE | AF_OPTION_CONFIG | AF_ACTIVECONFIG | AF_NEEDCOINIT, // Flags
  723. NULL, // pBool
  724. NULL, // ppString
  725. verbBackupPFX, // pfnVerb
  726. NULL, // papwszUsageConstants
  727. },
  728. {
  729. L"restore", // pwszArg
  730. IDS_RESTORE_DESCRIPTION, // "restore certificate server"
  731. IDS_RESTORE_USAGEARGS, // "BackupDirectory"
  732. IDS_RESTORE_ARGDESCRIPTION, // idsArgDescription
  733. 1, // cArgMin
  734. 1, // cArgMax
  735. AF_OPTION_PASSWORD | AF_OPTION_FORCE | AF_OPTION_CONFIG | AF_ACTIVECONFIG | AF_NEEDCOINIT | AF_RESTARTSERVER, // Flags
  736. NULL, // pBool
  737. NULL, // ppString
  738. verbRestore, // pfnVerb
  739. NULL, // papwszUsageConstants
  740. },
  741. {
  742. L"restoreDB", // pwszArg
  743. IDS_RESTOREDB_DESCRIPTION, // "restore certificate server data base"
  744. IDS_RESTOREDB_USAGEARGS, // "BackupDirectory"
  745. IDS_RESTOREDB_ARGDESCRIPTION, // idsArgDescription
  746. 1, // cArgMin
  747. 1, // cArgMax
  748. AF_OPTION_FORCE | AF_OPTION_CONFIG | AF_NEEDCOINIT | AF_RESTARTSERVER, // Flags
  749. NULL, // pBool
  750. NULL, // ppString
  751. verbRestoreDB, // pfnVerb
  752. NULL, // papwszUsageConstants
  753. },
  754. {
  755. L"restoreKey", // pwszArg
  756. IDS_RESTOREPFX_DESCRIPTION, // "restore certificate server certificate and private key"
  757. IDS_RESTOREPFX_USAGEARGS, // "BackupDirectory | PFXFile"
  758. IDS_RESTOREPFX_ARGDESCRIPTION, // idsArgDescription
  759. 1, // cArgMin
  760. 1, // cArgMax
  761. AF_OPTION_PASSWORD | AF_OPTION_FORCE | AF_OPTION_CONFIG | AF_ACTIVECONFIG | AF_NEEDCOINIT | AF_RESTARTSERVER, // Flags
  762. NULL, // pBool
  763. NULL, // ppString
  764. verbRestorePFX, // pfnVerb
  765. NULL, // papwszUsageConstants
  766. },
  767. {
  768. L"exportPVK", // pwszArg
  769. IDS_EXPORTPVK_DESCRIPTION, // "export certificate and private key for code signing"
  770. IDS_EXPORTPVK_USAGEARGS, // "CertId PVKFileBaseName"
  771. 0, // idsArgDescription
  772. 2, // cArgMin
  773. 2, // cArgMax
  774. AF_OPTION_PASSWORD | AF_OPTION_USER | AF_OPTION_SPLIT | AF_OPTION_ENTERPRISE | AF_PRIVATE, // Flags
  775. NULL, // pBool
  776. NULL, // ppString
  777. verbExportPVK, // pfnVerb
  778. NULL, // papwszUsageConstants
  779. },
  780. {
  781. L"exportPFX", // pwszArg
  782. IDS_EXPORTPFX_DESCRIPTION, // "export certificate and private key"
  783. IDS_EXPORTPFX_USAGEARGS, // "CertId PFXFile"
  784. IDS_EXPORTPFX_ARGDESCRIPTION, // idsArgDescription
  785. 2, // cArgMin
  786. 2, // cArgMax
  787. AF_OPTION_TIMEOUT | AF_OPTION_WEAKPFX | AF_OPTION_PASSWORD | AF_OPTION_USER | AF_OPTION_SPLIT | AF_OPTION_FORCE | AF_OPTION_ENTERPRISE | AF_PRIVATE, // Flags
  788. NULL, // pBool
  789. NULL, // ppString
  790. verbExportPFX, // pfnVerb
  791. NULL, // papwszUsageConstants
  792. },
  793. {
  794. L"importPFX", // pwszArg
  795. IDS_IMPORTPFX_DESCRIPTION, // "import certificate and private key"
  796. IDS_IMPORTPFX_USAGEARGS, // "PFXFile"
  797. IDS_IMPORTPFX_ARGDESCRIPTION, // idsArgDescription
  798. 1, // cArgMin
  799. 1, // cArgMax
  800. AF_OPTION_CSP | AF_OPTION_PROTECT | AF_OPTION_PASSWORD | AF_OPTION_USER | AF_OPTION_FORCE | AF_PRIVATE, // Flags
  801. NULL, // pBool
  802. NULL, // ppString
  803. verbImportPFX, // pfnVerb
  804. NULL, // papwszUsageConstants
  805. },
  806. {
  807. L"dynamicfilelist",
  808. IDS_DYNAMICFILES_DESCRIPTION, // "Display Dynamic File List"
  809. 0, // idsUsage
  810. 0, // idsArgDescription
  811. 0, // cArgMin
  812. 0, // cArgMax
  813. AF_OPTION_CONFIG | AF_NEEDCOINIT, // Flags
  814. NULL, // pBool
  815. NULL, // ppString
  816. verbDynamicFileList, // pfnVerb
  817. NULL, // papwszUsageConstants
  818. },
  819. {
  820. L"databaselocations",
  821. IDS_DATABASELOCATIONS_DESCRIPTION, // "Display Database Locations"
  822. 0, // idsUsage
  823. 0, // idsArgDescription
  824. 0, // cArgMin
  825. 0, // cArgMax
  826. AF_OPTION_CONFIG | AF_NEEDCOINIT, // Flags
  827. NULL, // pBool
  828. NULL, // ppString
  829. verbDatabaseLocations, // pfnVerb
  830. NULL, // papwszUsageConstants
  831. },
  832. {
  833. L"hashfile", // pwszArg
  834. IDS_HASHFILE_DESCRIPTION, // "Generates and displays cryptographic hash over a file"
  835. IDS_HASHFILE_USAGEARGS, // "InFile"
  836. 0, // idsArgDescription
  837. 1, // cArgMin
  838. 1, // cArgMax
  839. AF_ZERO, // Flags
  840. NULL, // pBool
  841. NULL, // ppString
  842. verbMACFile, // pfnVerb
  843. NULL, // papwszUsageConstants
  844. },
  845. { L"", },
  846. {
  847. L"store", // pwszArg
  848. IDS_STORE_DESCRIPTION, // "dump certificate store"
  849. IDS_STORE_USAGEARGS, // "[CertificateStoreName [CertId [OutputFile]]]"
  850. IDS_STORE_ARGDESCRIPTION, // idsArgDescription
  851. 0, // cArgMin
  852. 3, // cArgMax
  853. AF_OPTION_DC | AF_OPTION_USER | AF_OPTION_SPLIT | AF_OPTION_FORCE | AF_OPTION_ENTERPRISE, // Flags
  854. NULL, // pBool
  855. NULL, // ppString
  856. verbStore, // pfnVerb
  857. g_papwszUsageStore, // papwszUsageConstants
  858. },
  859. {
  860. L"addstore", // pwszArg
  861. IDS_ADDSTORE_DESCRIPTION, // "add certificate to store"
  862. IDS_ADDSTORE_USAGEARGS, // "CertificateStoreName InFile"
  863. IDS_ADDSTORE_ARGDESCRIPTION, // idsArgDescription
  864. 2, // cArgMin
  865. 2, // cArgMax
  866. AF_OPTION_DC | AF_OPTION_USER | AF_OPTION_FORCE | AF_OPTION_ENTERPRISE, // Flags
  867. NULL, // pBool
  868. NULL, // ppString
  869. verbAddStore, // pfnVerb
  870. NULL, // papwszUsageConstants
  871. },
  872. {
  873. L"delstore", // pwszArg
  874. IDS_DELSTORE_DESCRIPTION, // "delete certificate from store"
  875. IDS_DELSTORE_USAGEARGS, // "CertificateStoreName CertId"
  876. IDS_DELSTORE_ARGDESCRIPTION, // idsArgDescription
  877. 2, // cArgMin
  878. 2, // cArgMax
  879. AF_OPTION_DC | AF_OPTION_USER | AF_OPTION_ENTERPRISE, // Flags
  880. NULL, // pBool
  881. NULL, // ppString
  882. verbDelStore, // pfnVerb
  883. NULL, // papwszUsageConstants
  884. },
  885. {
  886. L"verifystore", // pwszArg
  887. IDS_VERIFYSTORE_DESCRIPTION, // "verify certificate in store"
  888. IDS_VERIFYSTORE_USAGEARGS, // "CertificateStoreName [CertId]"
  889. IDS_DELSTORE_ARGDESCRIPTION, // idsArgDescription
  890. 0, // cArgMin
  891. 2, // cArgMax
  892. AF_OPTION_TIMEOUT | AF_OPTION_DC | AF_OPTION_USER | AF_OPTION_SPLIT | AF_OPTION_ENTERPRISE, // Flags
  893. NULL, // pBool
  894. NULL, // ppString
  895. verbVerifyStore, // pfnVerb
  896. NULL, // papwszUsageConstants
  897. },
  898. {
  899. L"repairstore", // pwszArg
  900. IDS_REPAIRSTORE_DESCRIPTION, // "repair certificate KeyPprovInfo in store"
  901. IDS_REPAIRSTORE_USAGEARGS, // "CertificateStoreName CertId"
  902. IDS_DELSTORE_ARGDESCRIPTION, // idsArgDescription
  903. 2, // cArgMin
  904. 2, // cArgMax
  905. AF_OPTION_FORCE | AF_OPTION_CSP | AF_OPTION_USER | AF_OPTION_SILENT | AF_OPTION_SPLIT | AF_OPTION_ENTERPRISE, // Flags
  906. NULL, // pBool
  907. NULL, // ppString
  908. verbRepairStore, // pfnVerb
  909. NULL, // papwszUsageConstants
  910. },
  911. {
  912. L"viewstore", // pwszArg
  913. IDS_STORE_DESCRIPTION, // "view certificate store"
  914. IDS_STORE_USAGEARGS, // "[CertificateStoreName [CertId [OutputFile]]]"
  915. IDS_STORE_ARGDESCRIPTION, // idsArgDescription
  916. 0, // cArgMin
  917. 3, // cArgMax
  918. AF_OPTION_DC | AF_OPTION_USER | AF_OPTION_FORCE | AF_OPTION_ENTERPRISE, // Flags
  919. NULL, // pBool
  920. NULL, // ppString
  921. verbViewOrDeleteStore, // pfnVerb
  922. g_papwszUsageStore, // papwszUsageConstants
  923. },
  924. {
  925. g_wszViewDelStore, // pwszArg
  926. IDS_DELSTORE_DESCRIPTION, // "delete certificate from store"
  927. IDS_STORE_USAGEARGS, // "[CertificateStoreName [CertId [OutputFile]]]"
  928. IDS_STORE_ARGDESCRIPTION, // idsArgDescription
  929. 0, // cArgMin
  930. 3, // cArgMax
  931. AF_OPTION_DC | AF_OPTION_USER | AF_OPTION_FORCE | AF_OPTION_ENTERPRISE, // Flags
  932. NULL, // pBool
  933. NULL, // ppString
  934. verbViewOrDeleteStore, // pfnVerb
  935. g_papwszUsageStore, // papwszUsageConstants
  936. },
  937. {
  938. L"getcert", // pwszArg
  939. IDS_GETCERT_DESCRIPTION,// "select a certificate from a selection UI"
  940. IDS_GETCERT_USAGEARGS, // "[ObjectId | %1 | %2 [CommonName]]"
  941. 0, // idsArgDescription
  942. 0, // cArgMin
  943. 2, // cArgMax
  944. AF_OPTION_SPLIT | AF_OPTION_SILENT | AF_PRIVATE, // Flags
  945. NULL, // pBool
  946. NULL, // ppString
  947. verbGetCertFromUI, // pfnVerb
  948. g_papwszUsageGetCert, // papwszUsageConstants
  949. },
  950. { L"", },
  951. {
  952. L"ds", // pwszArg
  953. IDS_DS_DESCRIPTION, // "Display DS DNs"
  954. IDS_DS_USAGEARGS, // "[CN]"
  955. 0, // idsArgDescription
  956. 0, // cArgMin
  957. 1, // cArgMax
  958. AF_OPTION_FORCE | AF_OPTION_DC | AF_OPTION_SPLIT | AF_PRIVATE, // Flags
  959. NULL, // pBool
  960. NULL, // ppString
  961. verbDS, // pfnVerb
  962. NULL, // papwszUsageConstants
  963. },
  964. {
  965. L"dsDel", // pwszArg
  966. IDS_DSDEL_DESCRIPTION, // "Delete DS DNs"
  967. IDS_DSDEL_USAGEARGS, // "CN"
  968. 0, // idsArgDescription
  969. 1, // cArgMin
  970. 1, // cArgMax
  971. AF_OPTION_DC | AF_OPTION_SPLIT | AF_PRIVATE, // Flags
  972. NULL, // pBool
  973. NULL, // ppString
  974. verbDSDel, // pfnVerb
  975. NULL, // papwszUsageConstants
  976. },
  977. {
  978. L"dsPublish", // pwszArg
  979. IDS_DSPUBLISH_DESCRIPTION, // "Publish Certificate or CRL to DS"
  980. IDS_DSPUBLISH_USAGEARGS, // "CertFile [%1 | %2 | %3 | %4 | %5 | %6 | %7]\nCRLFile [DSCDPContainer [DSCDPCN]]"
  981. IDS_DSPUBLISH_ARGDESCRIPTION, // idsArgDescription
  982. 1, // cArgMin
  983. 3, // cArgMax
  984. AF_OPTION_DC | AF_OPTION_USER | AF_OPTION_FORCE, // Flags
  985. NULL, // pBool
  986. NULL, // ppString
  987. verbDSPublish, // pfnVerb
  988. g_papwszUsageDSPublish, // papwszUsageConstants
  989. },
  990. {
  991. L"dsCert", // pwszArg
  992. IDS_DSCERT_DESCRIPTION, // "Display DS Certificates"
  993. IDS_DSCERT_USAGEARGS, // "[CertId [OutFile]]"
  994. 0, // idsArgDescription
  995. 0, // cArgMin
  996. 2, // cArgMax
  997. AF_OPTION_DC | AF_OPTION_USER | AF_OPTION_ENTERPRISE | AF_NEEDCOINIT | AF_PRIVATE, // Flags
  998. NULL, // pBool
  999. NULL, // ppString
  1000. verbDSCert, // pfnVerb
  1001. NULL, // papwszUsageConstants
  1002. },
  1003. {
  1004. L"dsCRL", // pwszArg
  1005. IDS_DSCRL_DESCRIPTION, // "Display DS CRLs"
  1006. IDS_DSCRL_USAGEARGS, // "[CRLIndex [OutFile]]"
  1007. 0, // idsArgDescription
  1008. 0, // cArgMin
  1009. 2, // cArgMax
  1010. AF_OPTION_DC | AF_OPTION_USER | AF_OPTION_IDISPATCH | AF_OPTION_ENTERPRISE | AF_NEEDCOINIT | AF_PRIVATE, // Flags
  1011. NULL, // pBool
  1012. NULL, // ppString
  1013. verbDSCRL, // pfnVerb
  1014. NULL, // papwszUsageConstants
  1015. },
  1016. {
  1017. L"dsDeltaCRL", // pwszArg
  1018. IDS_DSDELTACRL_DESCRIPTION, // "Display DS Delta CRLs"
  1019. IDS_DSDELTACRL_USAGEARGS, // "[CRLIndex [OutFile]]"
  1020. 0, // idsArgDescription
  1021. 0, // cArgMin
  1022. 2, // cArgMax
  1023. AF_OPTION_DC | AF_OPTION_USER | AF_OPTION_ENTERPRISE | AF_NEEDCOINIT | AF_PRIVATE, // Flags
  1024. NULL, // pBool
  1025. NULL, // ppString
  1026. verbDSDeltaCRL, // pfnVerb
  1027. NULL, // papwszUsageConstants
  1028. },
  1029. {
  1030. L"dsTemplate", // pwszArg
  1031. IDS_DSTEMPLATE_DESCRIPTION, // "Display DS Template Attributes"
  1032. IDS_DSTEMPLATE_USAGEARGS, // "[Template]"
  1033. 0, // idsArgDescription
  1034. 0, // cArgMin
  1035. 1, // cArgMax
  1036. AF_OPTION_SILENT | AF_OPTION_DC | AF_PRIVATE, // Flags
  1037. NULL, // pBool
  1038. NULL, // ppString
  1039. verbDSTemplate, // pfnVerb
  1040. NULL, // papwszUsageConstants
  1041. },
  1042. {
  1043. L"dsAddTemplate", // pwszArg
  1044. IDS_DSADDTEMPLATE_DESCRIPTION, // "Add DS Templates"
  1045. IDS_DSADDTEMPLATE_USAGEARGS, // "TemplateInfFile"
  1046. 0, // idsArgDescription
  1047. 1, // cArgMin
  1048. 1, // cArgMax
  1049. AF_OPTION_DC | AF_PRIVATE | AF_RESTARTSERVER, // Flags
  1050. NULL, // pBool
  1051. NULL, // ppString
  1052. verbDSAddTemplate, // pfnVerb
  1053. NULL, // papwszUsageConstants
  1054. },
  1055. { L"", },
  1056. {
  1057. L"Template", // pwszArg
  1058. IDS_TEMPLATE_DESCRIPTION, // "Display Templates"
  1059. IDS_TEMPLATE_USAGEARGS, // "[Template]"
  1060. 0, // idsArgDescription
  1061. 0, // cArgMin
  1062. 1, // cArgMax
  1063. AF_OPTION_FORCE | AF_OPTION_USER | AF_OPTION_UT | AF_OPTION_MT, // Flags
  1064. NULL, // pBool
  1065. NULL, // ppString
  1066. verbTemplate, // pfnVerb
  1067. NULL, // papwszUsageConstants
  1068. },
  1069. {
  1070. L"TemplateCAs", // pwszArg
  1071. IDS_TEMPLATECAS_DESCRIPTION, // "Display CAs for Template"
  1072. IDS_TEMPLATECAS_USAGEARGS, // "Template"
  1073. 0, // idsArgDescription
  1074. 1, // cArgMin
  1075. 1, // cArgMax
  1076. AF_OPTION_FORCE | AF_OPTION_DC | AF_OPTION_USER, // Flags
  1077. NULL, // pBool
  1078. NULL, // ppString
  1079. verbTemplateCAs, // pfnVerb
  1080. NULL, // papwszUsageConstants
  1081. },
  1082. {
  1083. L"CATemplates", // pwszArg
  1084. IDS_CATEMPLATES_DESCRIPTION, // "Display Templates for CA"
  1085. IDS_CATEMPLATES_USAGEARGS, // "[Template]"
  1086. 0, // idsArgDescription
  1087. 0, // cArgMin
  1088. 1, // cArgMax
  1089. AF_OPTION_FORCE | AF_OPTION_DC | AF_OPTION_USER | AF_OPTION_UT | AF_OPTION_MT | AF_OPTION_CONFIG | AF_NEEDCOINIT, // Flags
  1090. NULL, // pBool
  1091. NULL, // ppString
  1092. verbCATemplates, // pfnVerb
  1093. NULL, // papwszUsageConstants
  1094. },
  1095. {
  1096. L"SetCATemplates", // pwszArg
  1097. IDS_SETCATEMPLATES_DESCRIPTION, // "Set Templates for CA"
  1098. IDS_SETCATEMPLATES_USAGEARGS, // "[+ | -]TemplateList"
  1099. 0, // idsArgDescription
  1100. 1, // cArgMin
  1101. 1, // cArgMax
  1102. AF_STOPATMINUSSIGNARG | AF_OPTION_FORCE | AF_OPTION_DC | AF_OPTION_CONFIG | AF_NEEDCOINIT | AF_PRIVATE, // Flags
  1103. NULL, // pBool
  1104. NULL, // ppString
  1105. verbSetCATemplates, // pfnVerb
  1106. NULL, // papwszUsageConstants
  1107. },
  1108. {
  1109. L"URL", // pwszArg
  1110. IDS_URL_DESCRIPTION, // "Verify Certificate or CRL URLs"
  1111. IDS_URL_USAGEARGS, // "InFile | URL"
  1112. 0, // idsArgDescription
  1113. 1, // cArgMin
  1114. 1, // cArgMax
  1115. AF_OPTION_SPLIT | AF_OPTION_FORCE | AF_PRIVATE, // Flags
  1116. NULL, // pBool
  1117. NULL, // ppString
  1118. verbURL, // pfnVerb
  1119. NULL, // papwszUsageConstants
  1120. },
  1121. {
  1122. L"URLCache", // pwszArg
  1123. IDS_URLCACHE_DESCRIPTION, // "Display or delete URL Cache entries"
  1124. IDS_URLCACHE_USAGEARGS, // "[URL [%1]]"
  1125. IDS_URLCACHE_ARGDESCRIPTION, // idsArgDescription
  1126. 0, // cArgMin
  1127. 2, // cArgMax
  1128. AF_OPTION_SPLIT | AF_OPTION_FORCE, // Flags
  1129. NULL, // pBool
  1130. NULL, // ppString
  1131. verbURLCache, // pfnVerb
  1132. g_papwszUsageURLCache, // papwszUsageConstants
  1133. },
  1134. {
  1135. L"pulse", // pwszArg
  1136. IDS_PULSE_DESCRIPTION, // "Pulse autoenrollment events"
  1137. 0, // idsUsage
  1138. 0, // idsArgDescription
  1139. 0, // cArgMin
  1140. 0, // cArgMax
  1141. AF_ZERO, // Flags
  1142. NULL, // pBool
  1143. NULL, // ppString
  1144. verbPulse, // pfnVerb
  1145. NULL, // papwszUsageConstants
  1146. },
  1147. {
  1148. L"MachineInfo", // pwszArg
  1149. IDS_MACHINEINFO_DESCRIPTION, // "Display DS machine object information"
  1150. IDS_MACHINEINFO_USAGEARGS, // "DomainName\\MachineName$"
  1151. 0, // idsArgDescription
  1152. 1, // cArgMin
  1153. 1, // cArgMax
  1154. AF_ZERO, // Flags
  1155. NULL, // pBool
  1156. NULL, // ppString
  1157. verbMachineInfo, // pfnVerb
  1158. NULL, // papwszUsageConstants
  1159. },
  1160. {
  1161. L"DCInfo", // pwszArg
  1162. IDS_DCINFO_DESCRIPTION, // "Display DC information"
  1163. IDS_DCINFO_USAGEARGS, // "[%1 | %2 | %3]"
  1164. 0, // idsArgDescription
  1165. 0, // cArgMin
  1166. 1, // cArgMax
  1167. AF_OPTION_TIMEOUT | AF_OPTION_URLFETCH | AF_OPTION_USER | AF_OPTION_FORCE, // Flags
  1168. NULL, // pBool
  1169. NULL, // ppString
  1170. verbDCInfo, // pfnVerb
  1171. g_papwszUsageDCInfo, // papwszUsageConstants
  1172. },
  1173. {
  1174. L"EntInfo", // pwszArg
  1175. IDS_ENTINFO_DESCRIPTION, // "Display Enterprise information"
  1176. IDS_ENTINFO_USAGEARGS, // "DomainName\\MachineName$"
  1177. 0, // idsArgDescription
  1178. 1, // cArgMin
  1179. 1, // cArgMax
  1180. AF_OPTION_USER | AF_OPTION_FORCE, // Flags
  1181. NULL, // pBool
  1182. NULL, // ppString
  1183. verbEntInfo, // pfnVerb
  1184. NULL, // papwszUsageConstants
  1185. },
  1186. {
  1187. L"TCAInfo", // pwszArg
  1188. IDS_TCAINFO_DESCRIPTION, // "Display CA information"
  1189. IDS_TCAINFO_USAGEARGS, // "[DomainDN | -]"
  1190. 0, // idsArgDescription
  1191. 0, // cArgMin
  1192. 1, // cArgMax
  1193. AF_OPTION_TIMEOUT | AF_OPTION_URLFETCH | AF_STOPATMINUSSIGN | AF_OPTION_DC | AF_OPTION_FORCE | AF_OPTION_ENTERPRISE | AF_OPTION_USER | AF_NEEDCOINIT, // Flags
  1194. NULL, // pBool
  1195. NULL, // ppString
  1196. verbTCAInfo, // pfnVerb
  1197. NULL, // papwszUsageConstants
  1198. },
  1199. {
  1200. L"SCInfo", // pwszArg
  1201. IDS_SCINFO_DESCRIPTION, // "Display Smart Card information"
  1202. IDS_SCINFO_USAGEARGS, // "[Reader Name]"
  1203. 0, // idsArgDescription
  1204. 0, // cArgMin
  1205. 1, // cArgMax
  1206. AF_OPTION_TIMEOUT | AF_OPTION_URLFETCH | AF_OPTION_SPLIT | AF_OPTION_SILENT, // Flags
  1207. NULL, // pBool
  1208. NULL, // ppString
  1209. verbSCInfo, // pfnVerb
  1210. NULL, // papwszUsageConstants
  1211. },
  1212. { L"", },
  1213. {
  1214. L"key", // pwszArg
  1215. IDS_KEY_DESCRIPTION, // "list key containers"
  1216. IDS_KEY_USAGEARGS, // "[KeyContainerName | -]"
  1217. 0, // idsArgDescription
  1218. 0, // cArgMin
  1219. 1, // cArgMax
  1220. AF_OPTION_CSP | AF_OPTION_USER | AF_OPTION_SILENT | AF_PRIVATE, // Flags
  1221. NULL, // pBool
  1222. NULL, // ppString
  1223. verbKey, // pfnVerb
  1224. NULL, // papwszUsageConstants
  1225. },
  1226. {
  1227. L"delkey", // pwszArg
  1228. IDS_DELKEY_DESCRIPTION, // "delete named key container"
  1229. IDS_DELKEY_USAGEARGS, // "KeyContainerName"
  1230. 0, // idsArgDescription
  1231. 1, // cArgMin
  1232. 1, // cArgMax
  1233. AF_OPTION_CSP | AF_OPTION_USER | AF_OPTION_SILENT | AF_PRIVATE, // Flags
  1234. NULL, // pBool
  1235. NULL, // ppString
  1236. verbDelKey, // pfnVerb
  1237. NULL, // papwszUsageConstants
  1238. },
  1239. {
  1240. L"verifykeys", // pwszArg
  1241. IDS_VERIFYKEYS_DESCRIPTION, // "Verify public/private key set"
  1242. IDS_VERIFYKEYS_USAGEARGS, // "[KeyContainerName CACertFile]"
  1243. IDS_VERIFYKEYS_ARGDESCRIPTION, // idsArgDescription
  1244. 0, // cArgMin
  1245. 2, // cArgMax
  1246. AF_OPTION_FORCE | AF_OPTION_USER | AF_OPTION_SILENT | AF_OPTION_CONFIG | AF_NEEDCOINIT, // Flags
  1247. NULL, // pBool
  1248. NULL, // ppString
  1249. verbVerifyKeys, // pfnVerb
  1250. NULL, // papwszUsageConstants
  1251. },
  1252. {
  1253. L"verify", // pwszArg
  1254. IDS_VERIFY_DESCRIPTION, // "Verify certificate or chain"
  1255. IDS_VERIFY_USAGEARGS, // "CertFile [CACertFile [CrossedCACertFile]]"
  1256. IDS_VERIFY_ARGSDESCRIPTION, // idsArgDescription
  1257. 1, // cArgMin
  1258. 3, // cArgMax
  1259. AF_OPTION_TIMEOUT | AF_OPTION_URLFETCH | AF_OPTION_SPLIT | AF_OPTION_USER | AF_OPTION_SILENT | AF_OPTION_FORCE | AF_OPTION_ENTERPRISE, // Flags
  1260. NULL, // pBool
  1261. NULL, // ppString
  1262. verbVerifyCert, // pfnVerb
  1263. NULL, // papwszUsageConstants
  1264. },
  1265. {
  1266. L"csplist", // pwszArg
  1267. IDS_CSPLIST_DESCRIPTION,// "list all CSPs installed on this machine"
  1268. 0, // idsUsage
  1269. 0, // idsArgDescription
  1270. 0, // cArgMin
  1271. 0, // cArgMax
  1272. AF_OPTION_USER | AF_OPTION_SILENT | AF_PRIVATE, // Flags
  1273. NULL, // pBool
  1274. NULL, // ppString
  1275. verbCSPList, // pfnVerb
  1276. NULL, // papwszUsageConstants
  1277. },
  1278. {
  1279. L"csptest", // pwszArg
  1280. IDS_CSPTEST_DESCRIPTION,// "test one or all CSPs installed on this machine"
  1281. IDS_CSPTEST_USAGEARGS, // "[KeyContainerName]"
  1282. 0, // idsArgDescription
  1283. 0, // cArgMin
  1284. 1, // cArgMax
  1285. AF_OPTION_CSP | AF_OPTION_USER | AF_OPTION_SILENT | AF_PRIVATE, // Flags
  1286. NULL, // pBool
  1287. NULL, // ppString
  1288. verbCSPTest, // pfnVerb
  1289. NULL, // papwszUsageConstants
  1290. },
  1291. {
  1292. L"sign", // pwszArg
  1293. IDS_SIGN_DESCRIPTION, // "Re-sign CRL or Certificate"
  1294. IDS_SIGN_USAGEARGS, // "InFile OutFile [dd:hh] [+SerialNumberList | -SerialNumberList | -ObjectIdList]"
  1295. IDS_SIGN_ARGDESCRIPTION, // idsArgDescription
  1296. 2, // cArgMin
  1297. 4, // cArgMax
  1298. AF_OPTION_SILENT | AF_OPTION_FORCE, // Flags
  1299. NULL, // pBool
  1300. NULL, // ppString
  1301. verbSign, // pfnVerb
  1302. NULL, // papwszUsageConstants
  1303. },
  1304. { L"", },
  1305. {
  1306. L"vroot", // pwszArg
  1307. IDS_VROOT_DESCRIPTION, // "Create/Delete Web Virtual Roots and File Share"
  1308. IDS_VROOT_USAGEARGS, // "[%1]"
  1309. 0, // idsArgDescription
  1310. 0, // cArgMin
  1311. 1, // cArgMax
  1312. AF_ZERO, // Flags
  1313. NULL, // pBool
  1314. NULL, // ppString
  1315. verbCreateVRoots, // pfnVerb
  1316. g_papwszUsageDelete, // papwszUsageConstants
  1317. },
  1318. {
  1319. L"7f", // pwszArg
  1320. IDS_7F_DESCRIPTION, // "Check certificate for 0x7f length encodings"
  1321. IDS_7F_USAGEARGS, // "CertFile"
  1322. 0, // idsArgDescription
  1323. 1, // cArgMin
  1324. 1, // cArgMax
  1325. AF_PRIVATE, // Flags
  1326. NULL, // pBool
  1327. NULL, // ppString
  1328. verbCheck7f, // pfnVerb
  1329. NULL, // papwszUsageConstants
  1330. },
  1331. {
  1332. L"oid", // pwszArg
  1333. IDS_OIDNAME_DESCRIPTION,// "Display or set ObjectId display name"
  1334. IDS_OIDNAME_USAGEARGS, // "ObjectId [DisplayName | delete [LanguageId [Type]]]"
  1335. IDS_OIDNAME_ARGDESCRIPTION, // idsArgDescription
  1336. 1, // cArgMin
  1337. 4, // cArgMax
  1338. AF_OPTION_FORCE, // Flags
  1339. NULL, // pBool
  1340. NULL, // ppString
  1341. verbOIDName, // pfnVerb
  1342. g_papwszUsageOIDName, // papwszUsageConstants
  1343. },
  1344. {
  1345. L"error", // pwszArg
  1346. IDS_ERRCODE_DESCRIPTION,// "Display error code message text"
  1347. IDS_ERRCODE_USAGEARGS, // "ErrorCode"
  1348. 0, // idsArgDescription
  1349. 1, // cArgMin
  1350. 1, // cArgMax
  1351. AF_STOPATMINUSSIGNARG, // Flags
  1352. NULL, // pBool
  1353. NULL, // ppString
  1354. verbErrorDump, // pfnVerb
  1355. NULL, // papwszUsageConstants
  1356. },
  1357. {
  1358. L"getsmtpinfo", // pwszArg
  1359. IDS_GETMAPI_DESCRIPTION,// "get SMTP info"
  1360. 0, // idsUsage
  1361. 0, // idsArgDescription
  1362. 0, // cArgMin
  1363. 0, // cArgMax
  1364. AF_OPTION_CONFIG | AF_NEEDCOINIT | AF_PRIVATE, // Flags
  1365. NULL, // pBool
  1366. NULL, // ppString
  1367. verbGetMapiInfo, // pfnVerb
  1368. NULL, // papwszUsageConstants
  1369. },
  1370. {
  1371. L"setsmtpinfo", // pwszArg
  1372. IDS_SETMAPI_DESCRIPTION, // "set SMTP info"
  1373. IDS_SETMAPI_USAGEARGS, // "LogonName"
  1374. 0, // idsArgDescription
  1375. 1, // cArgMin
  1376. 1, // cArgMax
  1377. AF_OPTION_PASSWORD | AF_OPTION_CONFIG | AF_NEEDCOINIT | AF_PRIVATE, // Flags
  1378. NULL, // pBool
  1379. NULL, // ppString
  1380. verbSetMapiInfo, // pfnVerb
  1381. NULL, // papwszUsageConstants
  1382. },
  1383. {
  1384. L"getreg",
  1385. IDS_GETREG_DESCRIPTION, // "Display registry value"
  1386. IDS_GETREG_USAGEARGS, // "[{%1|%2|%3|%4|%5}\\[%6\\]][RegistryValueName]"
  1387. IDS_SETREG_ARGDESCRIPTION, // idsArgDescription
  1388. 0, // cArgMin
  1389. 1, // cArgMax
  1390. AF_OPTION_USER | AF_NEEDCOINIT | AF_OPTIONALCONFIG, // Flags
  1391. NULL, // pBool
  1392. NULL, // ppString
  1393. verbGetReg, // pfnVerb
  1394. g_papwszUsageGetSetReg, // papwszUsageConstants
  1395. },
  1396. {
  1397. L"setreg",
  1398. IDS_SETREG_DESCRIPTION, // "Set registry value"
  1399. IDS_SETREG_USAGEARGS, // "[{%1|%2|%3|%4|%5}\\[%6\\]]RegistryValueName Value"
  1400. IDS_SETREG_ARGDESCRIPTION, // idsArgDescription
  1401. 2, // cArgMin
  1402. 2, // cArgMax
  1403. AF_OPTION_FORCE | AF_OPTION_USER | AF_NEEDCOINIT | AF_OPTIONALCONFIG | AF_RESTARTSERVER, // Flags
  1404. NULL, // pBool
  1405. NULL, // ppString
  1406. verbSetReg, // pfnVerb
  1407. g_papwszUsageGetSetReg, // papwszUsageConstants
  1408. },
  1409. {
  1410. L"delreg",
  1411. IDS_DELREG_DESCRIPTION, // "Delete registry value"
  1412. IDS_GETREG_USAGEARGS, // "[{%1|%2|%3|%4|%5}\\[%6\\]RegistryValueName]"
  1413. IDS_SETREG_ARGDESCRIPTION, // idsArgDescription
  1414. 1, // cArgMin
  1415. 1, // cArgMax
  1416. AF_OPTION_FORCE | AF_OPTION_USER | AF_NEEDCOINIT | AF_OPTIONALCONFIG | AF_RESTARTSERVER, // Flags
  1417. NULL, // pBool
  1418. NULL, // ppString
  1419. verbDelReg, // pfnVerb
  1420. g_papwszUsageGetSetReg, // papwszUsageConstants
  1421. },
  1422. { L"", },
  1423. {
  1424. L"ImportKMS", // pwszArg
  1425. IDS_IMPORTKMS_DESCRIPTION, // "import user keys and certificates into server database for key archival"
  1426. IDS_IMPORTKMS_USAGEARGS, // "UserKeyAndCertFile [CertId]"
  1427. IDS_IMPORTKMS_ARGDESCRIPTION, // idsArgDescription
  1428. 1, // cArgMin
  1429. 2, // cArgMax
  1430. AF_OPTION_PASSWORD | AF_OPTION_SPLIT | AF_OPTION_SILENT | AF_OPTION_IDISPATCH | AF_OPTION_FORCE | AF_OPTION_CONFIG | AF_NEEDCOINIT, // Flags
  1431. NULL, // pBool
  1432. NULL, // ppString
  1433. verbImportKMS, // pfnVerb
  1434. g_papwszUsageMinusf, // papwszUsageConstants
  1435. },
  1436. {
  1437. L"ImportCert",
  1438. IDS_IMPORTCERT_DESCRIPTION, // "Import a certificate file into the database"
  1439. IDS_IMPORTCERT_USAGEARGS, // "Certfile"
  1440. IDS_IMPORTCERT_ARGDESCRIPTION, // idsArgDescription
  1441. 1, // cArgMin
  1442. 2, // cArgMax
  1443. AF_OPTION_IDISPATCH | AF_OPTION_FORCE | AF_OPTION_CONFIG | AF_NEEDCOINIT, // Flags
  1444. NULL, // pBool
  1445. NULL, // ppString
  1446. verbImportCertificate, // pfnVerb
  1447. g_papwszUsageMinusf, // papwszUsageConstants
  1448. },
  1449. {
  1450. L"GetKey",
  1451. IDS_GETKEY_DESCRIPTION, // "Retrieve archived private key recovery blob"
  1452. IDS_GETKEY_USAGEARGS, // "SearchToken [RecoveryBlobOutFile]"
  1453. IDS_GETKEY_ARGDESCRIPTION, // idsArgDescription
  1454. 1, // cArgMin
  1455. 2, // cArgMax
  1456. AF_OPTION_IDISPATCH | AF_OPTION_FORCE | AF_NEEDCOINIT | AF_OPTIONALCONFIG, // Flags
  1457. NULL, // pBool
  1458. NULL, // ppString
  1459. verbGetKey, // pfnVerb
  1460. NULL, // papwszUsageConstants
  1461. },
  1462. {
  1463. L"RecoverKey",
  1464. IDS_RECOVERKEY_DESCRIPTION, // "Recover archived private key"
  1465. IDS_RECOVERKEY_USAGEARGS, // "RecoveryBlobInFile [PFXOutFile [RecipientIndex]]"
  1466. 0, // idsArgDescription
  1467. 1, // cArgMin
  1468. 3, // cArgMax
  1469. AF_OPTION_TIMEOUT | AF_OPTION_WEAKPFX | AF_OPTION_USER | AF_OPTION_SPLIT | AF_OPTION_PASSWORD | AF_OPTION_FORCE | AF_NEEDCOINIT, // Flags
  1470. NULL, // pBool
  1471. NULL, // ppString
  1472. verbRecoverKey, // pfnVerb
  1473. NULL, // papwszUsageConstants
  1474. },
  1475. {
  1476. L"MergePFX",
  1477. IDS_MERGEPFX_DESCRIPTION, // "Merge PFX files"
  1478. IDS_MERGEPFX_USAGEARGS, // "PFXInFileList PFXOutFile"
  1479. IDS_MERGEPFX_ARGDESCRIPTION, // idsArgDescription
  1480. 2, // cArgMin
  1481. 2, // cArgMax
  1482. AF_OPTION_CSP | AF_OPTION_WEAKPFX | AF_OPTION_USER | AF_OPTION_SPLIT | AF_OPTION_PASSWORD | AF_OPTION_FORCE, // Flags
  1483. NULL, // pBool
  1484. NULL, // ppString
  1485. verbMergePFX, // pfnVerb
  1486. NULL, // papwszUsageConstants
  1487. },
  1488. {
  1489. L"ConvertEPF",
  1490. IDS_CONVERTEPF_DESCRIPTION, // "Convert PFX files to EPF file"
  1491. IDS_CONVERTEPF_USAGEARGS, // "PFXInFileList EPFOutFile [%1 | %2] [V3CACertId][,Salt]"
  1492. IDS_CONVERTPFX_ARGDESCRIPTION, // idsArgDescription
  1493. 2, // cArgMin
  1494. 4, // cArgMax
  1495. AF_OPTION_CSP | AF_OPTION_SPLIT | AF_OPTION_DC | AF_OPTION_SILENT | AF_OPTION_PASSWORD | AF_OPTION_FORCE, // Flags
  1496. NULL, // pBool
  1497. NULL, // ppString
  1498. verbConvertEPF, // pfnVerb
  1499. g_papwszUsageConvertEPF, // papwszUsageConstants
  1500. },
  1501. {
  1502. L"?", // pwszArg
  1503. IDS_USAGE_DESCRIPTION, // "Display this usage message"
  1504. 0, // idsUsage
  1505. 0, // idsArgDescription
  1506. 0, // cArgMin
  1507. 0, // cArgMax
  1508. AF_ZERO, // Flags
  1509. NULL, // pBool
  1510. NULL, // ppString
  1511. verbUsage, // pfnVerb
  1512. NULL, // papwszUsageConstants
  1513. },
  1514. { L"", },
  1515. {
  1516. L"f", // pwszArg
  1517. IDS_FORCE_DESCRIPTION, // "Force overwrite"
  1518. 0, // idsUsage
  1519. 0, // idsArgDescription
  1520. 0, // cArgMin
  1521. 0, // cArgMax
  1522. AF_OPTION_FORCE, // Flags
  1523. &g_fForce, // pBool
  1524. NULL, // ppString
  1525. NULL, // pfnVerb
  1526. NULL, // papwszUsageConstants
  1527. },
  1528. {
  1529. L"idispatch", // pwszArg
  1530. IDS_IDISPATCH_DESCRIPTION, // "Use IDispatch instead of COM"
  1531. 0, // idsUsage
  1532. 0, // idsArgDescription
  1533. 0, // cArgMin
  1534. 0, // cArgMax
  1535. AF_PRIVATE | AF_OPTION_IDISPATCH, // Flags
  1536. &g_fIDispatch, // pBool
  1537. NULL, // ppString
  1538. NULL, // pfnVerb
  1539. NULL, // papwszUsageConstants
  1540. },
  1541. {
  1542. L"enterprise", // pwszArg
  1543. IDS_ENTERPRISE_DESCRIPTION, // "Use Enterprise certificate store"
  1544. 0, // idsUsage
  1545. 0, // idsArgDescription
  1546. 0, // cArgMin
  1547. 0, // cArgMax
  1548. AF_OPTION_ENTERPRISE, // Flags
  1549. &g_fEnterpriseRegistry, // pBool
  1550. NULL, // ppString
  1551. NULL, // pfnVerb
  1552. NULL, // papwszUsageConstants
  1553. },
  1554. {
  1555. L"user", // pwszArg
  1556. IDS_USER_DESCRIPTION, // "Use HKEY_CURRENT_USER certificate store"
  1557. 0, // idsUsage
  1558. 0, // idsArgDescription
  1559. 0, // cArgMin
  1560. 0, // cArgMax
  1561. AF_OPTION_USER, // Flags
  1562. &g_fUserRegistry, // pBool
  1563. NULL, // ppString
  1564. NULL, // pfnVerb
  1565. NULL, // papwszUsageConstants
  1566. },
  1567. {
  1568. L"ut", // pwszArg
  1569. IDS_UT_DESCRIPTION, // "Display user templates"
  1570. 0, // idsUsage
  1571. 0, // idsArgDescription
  1572. 0, // cArgMin
  1573. 0, // cArgMax
  1574. AF_OPTION_UT, // Flags
  1575. &g_fUserTemplates, // pBool
  1576. NULL, // ppString
  1577. NULL, // pfnVerb
  1578. NULL, // papwszUsageConstants
  1579. },
  1580. {
  1581. L"mt", // pwszArg
  1582. IDS_MT_DESCRIPTION, // "Display machine templates"
  1583. 0, // idsUsage
  1584. 0, // idsArgDescription
  1585. 0, // cArgMin
  1586. 0, // cArgMax
  1587. AF_OPTION_MT, // Flags
  1588. &g_fMachineTemplates, // pBool
  1589. NULL, // ppString
  1590. NULL, // pfnVerb
  1591. NULL, // papwszUsageConstants
  1592. },
  1593. {
  1594. L"nocr", // pwszArg
  1595. IDS_NOCR_DESCRIPTION, // "Encode text without CR characters"
  1596. 0, // idsUsage
  1597. 0, // idsArgDescription
  1598. 0, // cArgMin
  1599. 0, // cArgMax
  1600. AF_PRIVATE | AF_OPTION_NOCR, // Flags
  1601. &g_fNoCR, // pBool
  1602. NULL, // ppString
  1603. NULL, // pfnVerb
  1604. NULL, // papwszUsageConstants
  1605. },
  1606. {
  1607. L"gmt", // pwszArg
  1608. IDS_GMT_DESCRIPTION, // "Display times as GMT"
  1609. 0, // idsUsage
  1610. 0, // idsArgDescription
  1611. 0, // cArgMin
  1612. 0, // cArgMax
  1613. AF_OPTION_GMT, // Flags
  1614. &g_fGMT, // pBool
  1615. NULL, // ppString
  1616. NULL, // pfnVerb
  1617. NULL, // papwszUsageConstants
  1618. },
  1619. {
  1620. L"seconds", // pwszArg
  1621. IDS_SECONDS_DESCRIPTION,// "Display times with seconds and milliseconds"
  1622. 0, // idsUsage
  1623. 0, // idsArgDescription
  1624. 0, // cArgMin
  1625. 0, // cArgMax
  1626. AF_OPTION_SECONDS, // Flags
  1627. &g_fSeconds, // pBool
  1628. NULL, // ppString
  1629. NULL, // pfnVerb
  1630. NULL, // papwszUsageConstants
  1631. },
  1632. {
  1633. L"silent", // pwszArg
  1634. IDS_SILENT_DESCRIPTION, // "Use silent flag to acquire crypt context"
  1635. 0, // idsUsage
  1636. 0, // idsArgDescription
  1637. 0, // cArgMin
  1638. 0, // cArgMax
  1639. AF_OPTION_SILENT, // Flags
  1640. &g_fCryptSilent, // pBool
  1641. NULL, // ppString
  1642. NULL, // pfnVerb
  1643. NULL, // papwszUsageConstants
  1644. },
  1645. {
  1646. L"split", // pwszArg
  1647. IDS_SPLIT_DESCRIPTION, // "Split embedded ASN.1 elements, and save to files"
  1648. 0, // idsUsage
  1649. 0, // idsArgDescription
  1650. 0, // cArgMin
  1651. 0, // cArgMax
  1652. AF_OPTION_SPLIT, // Flags
  1653. &g_fSplitASN, // pBool
  1654. NULL, // ppString
  1655. NULL, // pfnVerb
  1656. NULL, // papwszUsageConstants
  1657. },
  1658. {
  1659. L"v", // pwszArg
  1660. IDS_VERBOSE_DESCRIPTION, // "Verbose operation"
  1661. 0, // idsUsage
  1662. 0, // idsArgDescription
  1663. 0, // cArgMin
  1664. 0, // cArgMax
  1665. AF_OPTION_VERBOSE, // Flags
  1666. &g_fVerbose, // pBool
  1667. NULL, // ppString
  1668. NULL, // pfnVerb
  1669. NULL, // papwszUsageConstants
  1670. },
  1671. {
  1672. L"v1", // pwszArg
  1673. IDS_V1_DESCRIPTION, // "Use V1 COM interfaces"
  1674. 0, // idsUsage
  1675. 0, // idsArgDescription
  1676. 0, // cArgMin
  1677. 0, // cArgMax
  1678. AF_PRIVATE | AF_OPTION_V1, // Flags
  1679. &g_fV1Interface, // pBool
  1680. NULL, // ppString
  1681. NULL, // pfnVerb
  1682. NULL, // papwszUsageConstants
  1683. },
  1684. {
  1685. L"protect", // pwszArg
  1686. IDS_PROTECT_DESCRIPTION, // "Protect keys with password"
  1687. 0, // idsUsage
  1688. 0, // idsArgDescription
  1689. 0, // cArgMin
  1690. 0, // cArgMax
  1691. AF_PRIVATE | AF_OPTION_PROTECT, // Flags
  1692. &g_fProtect, // pBool
  1693. NULL, // ppString
  1694. NULL, // pfnVerb
  1695. NULL, // papwszUsageConstants
  1696. },
  1697. {
  1698. L"oldpfx", // pwszArg
  1699. IDS_WEAKPFX_DESCRIPTION, // "Use old PFX encryption"
  1700. 0, // idsUsage
  1701. 0, // idsArgDescription
  1702. 0, // cArgMin
  1703. 0, // cArgMax
  1704. AF_PRIVATE | AF_OPTION_WEAKPFX, // Flags
  1705. &g_fWeakPFX, // pBool
  1706. NULL, // ppString
  1707. NULL, // pfnVerb
  1708. NULL, // papwszUsageConstants
  1709. },
  1710. {
  1711. L"urlfetch", // pwszArg
  1712. IDS_URLFETCH_DESCRIPTION, // "Retrieve and verify AIA Certs and CDP CRLs"
  1713. 0, // idsUsage
  1714. 0, // idsArgDescription
  1715. 0, // cArgMin
  1716. 0, // cArgMax
  1717. AF_OPTION_URLFETCH, // Flags
  1718. &g_fURLFetch, // pBool
  1719. NULL, // ppString
  1720. NULL, // pfnVerb
  1721. NULL, // papwszUsageConstants
  1722. },
  1723. {
  1724. L"reverse", // pwszArg
  1725. IDS_REVERSE_DESCRIPTION, // "Reverse Log and Queue columns"
  1726. 0, // idsUsage
  1727. 0, // idsArgDescription
  1728. 0, // cArgMin
  1729. 0, // cArgMax
  1730. AF_PRIVATE | AF_OPTION_REVERSE, // Flags
  1731. &g_fReverse, // pBool
  1732. NULL, // ppString
  1733. NULL, // pfnVerb
  1734. NULL, // papwszUsageConstants
  1735. },
  1736. {
  1737. L"admin", // pwszArg
  1738. IDS_ADMIN_DESCRIPTION, // "Use ICertAdmin2 for CA Properties"
  1739. 0, // idsUsage
  1740. 0, // idsArgDescription
  1741. 0, // cArgMin
  1742. 0, // cArgMax
  1743. AF_PRIVATE | AF_OPTION_ADMIN, // Flags
  1744. &g_fAdminInterface, // pBool
  1745. NULL, // ppString
  1746. NULL, // pfnVerb
  1747. NULL, // papwszUsageConstants
  1748. },
  1749. {
  1750. L"config", // pwszArg
  1751. IDS_CONFIG_DESCRIPTION, // "CA and Machine name string"
  1752. IDS_CONFIG_USAGE, // "Machine\\CAName"
  1753. 0, // idsArgDescription
  1754. 0, // cArgMin
  1755. 0, // cArgMax
  1756. AF_OPTIONALCONFIG | AF_OPTION_CONFIG, // Flags
  1757. NULL, // pBool
  1758. &g_pwszConfig, // ppString
  1759. NULL, // pfnVerb
  1760. NULL, // papwszUsageConstants
  1761. },
  1762. {
  1763. L"dc", // pwszArg
  1764. IDS_DC_DESCRIPTION, // "Target a specific Domain Controller"
  1765. IDS_DC_USAGE, // "DCName"
  1766. 0, // idsArgDescription
  1767. 0, // cArgMin
  1768. 0, // cArgMax
  1769. AF_OPTION_DC, // Flags
  1770. NULL, // pBool
  1771. &g_pwszDC, // ppString
  1772. NULL, // pfnVerb
  1773. NULL, // papwszUsageConstants
  1774. },
  1775. {
  1776. L"restrict", // pwszArg
  1777. IDS_RESTRICT_DESCRIPTION, // "Comma separated Restriction List"
  1778. IDS_RESTRICT_USAGE, // "RestrictionList"
  1779. 0, // idsArgDescription
  1780. 0, // cArgMin
  1781. 0, // cArgMax
  1782. AF_OPTION_RESTRICT, // Flags
  1783. NULL, // pBool
  1784. &g_pwszRestrict, // ppString
  1785. NULL, // pfnVerb
  1786. NULL, // papwszUsageConstants
  1787. },
  1788. {
  1789. L"out", // pwszArg
  1790. IDS_OUT_DESCRIPTION, // "Comma separated Column List"
  1791. IDS_OUT_USAGE, // "ColumnList"
  1792. 0, // idsArgDescription
  1793. 0, // cArgMin
  1794. 0, // cArgMax
  1795. AF_OPTION_OUT, // Flags
  1796. NULL, // pBool
  1797. &g_pwszOut, // ppString
  1798. NULL, // pfnVerb
  1799. NULL, // papwszUsageConstants
  1800. },
  1801. {
  1802. L"p", // pwszArg
  1803. IDS_PASSWORD_DESCRIPTION, // "password"
  1804. IDS_PASSWORD_DESCRIPTION, // "password"
  1805. 0, // idsArgDescription
  1806. 0, // cArgMin
  1807. 0, // cArgMax
  1808. AF_OPTION_PASSWORD, // Flags
  1809. NULL, // pBool
  1810. &g_pwszPassword, // ppString
  1811. NULL, // pfnVerb
  1812. NULL, // papwszUsageConstants
  1813. },
  1814. {
  1815. L"csp", // pwszArg
  1816. IDS_CSP_DESCRIPTION, // "Provider"
  1817. IDS_CSP_DESCRIPTION, // "Provider"
  1818. 0, // idsArgDescription
  1819. 0, // cArgMin
  1820. 0, // cArgMax
  1821. AF_OPTION_CSP, // Flags
  1822. NULL, // pBool
  1823. &g_pwszCSP, // ppString
  1824. NULL, // pfnVerb
  1825. NULL, // papwszUsageConstants
  1826. },
  1827. {
  1828. L"t", // pwszArg
  1829. IDS_TIMEOUT_DESCRIPTION, // "URL fetch timeout in milliseconds"
  1830. IDS_TIMEOUT_USAGE, // "Timeout"
  1831. 0, // idsArgDescription
  1832. 0, // cArgMin
  1833. 0, // cArgMax
  1834. AF_OPTION_TIMEOUT, // Flags
  1835. NULL, // pBool
  1836. &g_pwszmsTimeout, // ppString
  1837. NULL, // pfnVerb
  1838. NULL, // papwszUsageConstants
  1839. },
  1840. };
  1841. VOID
  1842. cuPrintErrorAndString(
  1843. OPTIONAL IN WCHAR const *pwszProc,
  1844. IN DWORD idmsg,
  1845. IN HRESULT hr,
  1846. OPTIONAL IN WCHAR const *pwszString)
  1847. {
  1848. WCHAR const *pwsz;
  1849. WCHAR awchr[cwcHRESULTSTRING];
  1850. WCHAR const *pwszError = NULL;
  1851. if (NULL != pwszProc)
  1852. {
  1853. wprintf(L"%ws: ", pwszProc);
  1854. }
  1855. if (0 != idmsg)
  1856. {
  1857. pwsz = myLoadResourceString(idmsg); // "??? returned %ws"
  1858. if (NULL == pwsz)
  1859. {
  1860. pwsz = L"error %ws";
  1861. }
  1862. }
  1863. else
  1864. {
  1865. pwsz = L"%ws";
  1866. }
  1867. pwszError = myGetErrorMessageText(hr, TRUE);
  1868. if (NULL == pwszError)
  1869. {
  1870. pwszError = myHResultToString(awchr, hr);
  1871. }
  1872. wprintf(pwsz, pwszError);
  1873. if (NULL != pwszString)
  1874. {
  1875. wprintf(L" -- %ws", pwszString);
  1876. }
  1877. wprintf(wszNewLine);
  1878. if (NULL != pwszError && awchr != pwszError)
  1879. {
  1880. LocalFree(const_cast<WCHAR *>(pwszError));
  1881. }
  1882. }
  1883. VOID
  1884. cuPrintError(
  1885. IN DWORD idmsg,
  1886. IN HRESULT hr)
  1887. {
  1888. cuPrintErrorAndString(NULL, idmsg, hr, NULL);
  1889. }
  1890. VOID
  1891. cuPrintAPIError(
  1892. IN WCHAR const *pwszAPIName,
  1893. IN HRESULT hr)
  1894. {
  1895. cuPrintErrorAndString(pwszAPIName, 0, hr, NULL);
  1896. }
  1897. VOID
  1898. cuPrintErrorMessageText(
  1899. IN HRESULT hr)
  1900. {
  1901. WCHAR const *pwszMessage;
  1902. pwszMessage = myGetErrorMessageText(hr, FALSE);
  1903. if (NULL != pwszMessage)
  1904. {
  1905. wprintf(L"%ws: %ws\n", g_pwszProg, pwszMessage);
  1906. LocalFree(const_cast<WCHAR *>(pwszMessage));
  1907. }
  1908. }
  1909. VOID
  1910. LoadUsage(
  1911. IN OUT ARG *parg)
  1912. {
  1913. HRESULT hr;
  1914. if (0 != parg->idsUsage && NULL == parg->pwszUsage)
  1915. {
  1916. WCHAR const *pwszUsage = myLoadResourceString(parg->idsUsage);
  1917. if (NULL != pwszUsage)
  1918. {
  1919. if (NULL == parg->papwszUsageConstants)
  1920. {
  1921. parg->pwszUsage = pwszUsage;
  1922. }
  1923. else
  1924. {
  1925. if (0 == FormatMessage(
  1926. FORMAT_MESSAGE_ALLOCATE_BUFFER |
  1927. FORMAT_MESSAGE_FROM_STRING |
  1928. FORMAT_MESSAGE_ARGUMENT_ARRAY,
  1929. (VOID *) pwszUsage,
  1930. 0, // dwMessageID
  1931. 0, // dwLanguageID
  1932. (LPWSTR) &parg->pwszUsage,
  1933. 0,
  1934. (va_list *) parg->papwszUsageConstants))
  1935. {
  1936. hr = myHLastError();
  1937. _PrintError(hr, "FormatMessage");
  1938. }
  1939. }
  1940. }
  1941. }
  1942. }
  1943. VOID
  1944. FreeUsage(
  1945. IN OUT ARG *parg)
  1946. {
  1947. if (NULL != parg->pwszUsage)
  1948. {
  1949. if (NULL != parg->papwszUsageConstants)
  1950. {
  1951. LocalFree(const_cast<WCHAR *>(parg->pwszUsage));
  1952. }
  1953. parg->pwszUsage = NULL;
  1954. }
  1955. }
  1956. BOOL
  1957. DumpArgOptions(
  1958. IN DWORD dwOptionFlags)
  1959. {
  1960. ARG *parg;
  1961. BOOL fDisplayed = FALSE;
  1962. WCHAR const *pwszPrefix = g_wszPad4;
  1963. dwOptionFlags |= AF_OPTION_GENERIC;
  1964. dwOptionFlags &= AF_OPTION_MASK | AF_OPTIONALCONFIG;
  1965. for (parg = aarg ; parg < &aarg[ARRAYSIZE(aarg)]; parg++)
  1966. {
  1967. if (NULL != parg->pfnVerb)
  1968. {
  1969. continue;
  1970. }
  1971. if (!g_fFullUsage && (AF_PRIVATE & parg->Flags))
  1972. {
  1973. continue;
  1974. }
  1975. if (L'\0' == parg->pwszArg[0])
  1976. {
  1977. continue;
  1978. }
  1979. if (1 >= g_fVerbose && (AF_OPTION_GENERIC & parg->Flags))
  1980. {
  1981. continue;
  1982. }
  1983. if (dwOptionFlags & parg->Flags)
  1984. {
  1985. wprintf(
  1986. L"%ws%ws-%ws",
  1987. pwszPrefix,
  1988. wszLBRACKET,
  1989. parg->pwszArg);
  1990. if (0 != parg->idsUsage)
  1991. {
  1992. LoadUsage(parg);
  1993. wprintf(L" %ws", parg->pwszUsage);
  1994. }
  1995. wprintf(wszRBRACKET);
  1996. pwszPrefix = L" ";
  1997. fDisplayed = TRUE;
  1998. }
  1999. }
  2000. if (fDisplayed)
  2001. {
  2002. wprintf(wszNewLine);
  2003. }
  2004. return(fDisplayed);
  2005. }
  2006. VOID
  2007. DumpArgUsage(
  2008. IN ARG *parg)
  2009. {
  2010. WCHAR const *pwsz;
  2011. int *paidsUsage;
  2012. if (0 != parg->idsUsage)
  2013. {
  2014. LoadUsage(parg);
  2015. }
  2016. pwsz = parg->pwszUsage;
  2017. while (TRUE)
  2018. {
  2019. wprintf(
  2020. L" %ws [%ws] %ws-%ws%ws",
  2021. g_pwszProg,
  2022. myLoadResourceString(IDS_USAGE_OPTIONS),
  2023. pargDEFAULT == parg? wszLBRACKET : L"",
  2024. parg->pwszArg,
  2025. pargDEFAULT == parg? wszRBRACKET : L"");
  2026. if (NULL != pwsz)
  2027. {
  2028. DWORD cwc = 0;
  2029. cwc = wcscspn(pwsz, L"\r\n");
  2030. if (0 != cwc)
  2031. {
  2032. wprintf(L" %.*ws", cwc, pwsz);
  2033. pwsz += cwc;
  2034. }
  2035. while ('\r' == *pwsz || '\n' == *pwsz)
  2036. {
  2037. pwsz++;
  2038. }
  2039. }
  2040. wprintf(wszNewLine);
  2041. if (NULL == pwsz || L'\0' == *pwsz)
  2042. {
  2043. break;
  2044. }
  2045. }
  2046. if (0 != parg->idsDescription && NULL == parg->pwszDescription)
  2047. {
  2048. parg->pwszDescription = myLoadResourceString(
  2049. parg->idsDescription);
  2050. }
  2051. if (NULL != parg->pwszDescription)
  2052. {
  2053. wprintf(L" %ws\n", parg->pwszDescription);
  2054. }
  2055. if (0 != parg->idsArgDescription)
  2056. {
  2057. HRESULT hr;
  2058. WCHAR const *pwszArg = myLoadResourceString(parg->idsArgDescription);
  2059. WCHAR *pwszArgFormatted = NULL;
  2060. if (NULL != pwszArg && L'\0' != *pwszArg)
  2061. {
  2062. if (IDS_STORE_ARGDESCRIPTION == parg->idsArgDescription)
  2063. {
  2064. PatchStoreArgDescription();
  2065. }
  2066. if (0 == FormatMessage(
  2067. FORMAT_MESSAGE_ALLOCATE_BUFFER |
  2068. FORMAT_MESSAGE_FROM_STRING |
  2069. FORMAT_MESSAGE_ARGUMENT_ARRAY,
  2070. (VOID *) pwszArg,
  2071. 0, // dwMessageID
  2072. 0, // dwLanguageID
  2073. (LPWSTR) &pwszArgFormatted,
  2074. wcslen(pwszArg),
  2075. (va_list *) parg->papwszUsageConstants))
  2076. {
  2077. hr = myHLastError();
  2078. _PrintError(hr, "FormatMessage");
  2079. }
  2080. pwsz = NULL != pwszArgFormatted? pwszArgFormatted : pwszArg;
  2081. while (L'\0' != *pwsz)
  2082. {
  2083. DWORD cwc = 0;
  2084. cwc = wcscspn(pwsz, L"\r\n");
  2085. if (0 != cwc)
  2086. {
  2087. wprintf(L" %.*ws", cwc, pwsz);
  2088. pwsz += cwc;
  2089. }
  2090. wprintf(wszNewLine);
  2091. if ('\r' == *pwsz)
  2092. {
  2093. pwsz++;
  2094. }
  2095. if ('\n' == *pwsz)
  2096. {
  2097. pwsz++;
  2098. }
  2099. }
  2100. if (NULL != pwszArgFormatted)
  2101. {
  2102. LocalFree(pwszArgFormatted);
  2103. }
  2104. }
  2105. }
  2106. }
  2107. VOID
  2108. Usage(
  2109. IN DWORD msgid,
  2110. OPTIONAL WCHAR const *pwszMsg,
  2111. IN DWORD dwOption,
  2112. OPTIONAL IN ARG *pargVerb)
  2113. {
  2114. ARG *parg;
  2115. DWORD dwFlags = AF_OPTION_GENERIC;
  2116. WCHAR const *pwszArg;
  2117. DWORD i;
  2118. DWORD adwids[] =
  2119. {
  2120. IDS_USAGE_LIST_VERBS, // "display verb list (command list)"
  2121. IDS_FORMAT_USAGE_ONE_HELP, // "display help for the %ws verb"
  2122. IDS_USAGE_ALL_HELP, // "display help for all verbs"
  2123. };
  2124. WCHAR const *apwszCommandLine[] =
  2125. {
  2126. L"%ws -?", // IDS_USAGE_LIST_VERBS
  2127. L"%ws -%ws -?", // IDS_FORMAT_USAGE_ONE_HELP
  2128. L"%ws -v -?", // IDS_USAGE_ALL_HELP
  2129. };
  2130. wsprintf(g_wszDefaultLangId, L"%u", GetSystemDefaultLangID());
  2131. // Display the error message for the detected usage error. If the error
  2132. // message requires it, point at the optional arg string to be displayed
  2133. // along with the error message.
  2134. if (0 != msgid)
  2135. {
  2136. if (NULL == pwszMsg && 0 != dwOption)
  2137. {
  2138. for (parg = aarg ; parg < &aarg[ARRAYSIZE(aarg)]; parg++)
  2139. {
  2140. if (NULL != parg->pfnVerb)
  2141. {
  2142. continue;
  2143. }
  2144. if (dwOption & parg->Flags)
  2145. {
  2146. pwszMsg = parg->pwszArg;
  2147. break;
  2148. }
  2149. }
  2150. }
  2151. // Display a command line usage error message.
  2152. wprintf(L"%ws: ", g_pwszProg);
  2153. wprintf(myLoadResourceString(msgid), pwszMsg);
  2154. wprintf(L"\n\n");
  2155. }
  2156. else
  2157. {
  2158. // if no error and no verb selected, display all verbs & descriptions
  2159. if (NULL == pargVerb)
  2160. {
  2161. wprintf(L"\n%ws\n", myLoadResourceString(IDS_USAGE_VERBS));
  2162. for (parg = aarg ; parg < &aarg[ARRAYSIZE(aarg)]; parg++)
  2163. {
  2164. if (!g_fFullUsage && (AF_PRIVATE & parg->Flags))
  2165. {
  2166. continue;
  2167. }
  2168. if (L'\0' == parg->pwszArg[0])
  2169. {
  2170. wprintf(wszNewLine);
  2171. continue;
  2172. }
  2173. if (NULL != parg->pfnVerb)
  2174. {
  2175. dwFlags |= parg->Flags;
  2176. if (0 != parg->idsDescription &&
  2177. NULL == parg->pwszDescription)
  2178. {
  2179. parg->pwszDescription = myLoadResourceString(
  2180. parg->idsDescription);
  2181. }
  2182. wprintf(L" -");
  2183. myConsolePrintString(CCOL_VERB, parg->pwszArg);
  2184. wprintf(L" -- %ws\n", parg->pwszDescription);
  2185. }
  2186. }
  2187. }
  2188. }
  2189. // if in verbose mode, display full usage for all verbs.
  2190. // if verb was specified, display usage for one verb.
  2191. if ((0 == msgid && g_fVerbose) || NULL != pargVerb)
  2192. {
  2193. ARG *pargStart;
  2194. ARG *pargEnd;
  2195. wprintf(L"%ws\n", myLoadResourceString(IDS_USAGE_HEADER));
  2196. if (NULL != pargVerb)
  2197. {
  2198. pargStart = pargVerb; // display one verb
  2199. pargEnd = &pargVerb[1];
  2200. }
  2201. else
  2202. {
  2203. pargStart = aarg; // display all verbs
  2204. pargEnd = &aarg[ARRAYSIZE(aarg)];
  2205. }
  2206. for (parg = pargStart ; parg < pargEnd; parg++)
  2207. {
  2208. if (!g_fFullUsage &&
  2209. (AF_PRIVATE & parg->Flags) &&
  2210. parg != pargVerb)
  2211. {
  2212. continue; // skip private verbs unless specified
  2213. }
  2214. if (L'\0' == parg->pwszArg[0])
  2215. {
  2216. continue; // skip newline separator entries
  2217. }
  2218. if (NULL != parg->pfnVerb) // if it's a verb (not an option entry)
  2219. {
  2220. dwFlags |= parg->Flags;
  2221. DumpArgUsage(parg);
  2222. if (g_fVerbose)
  2223. {
  2224. DumpArgOptions(parg->Flags);
  2225. }
  2226. // Special case for CAInfo verb:
  2227. if (IDS_CAINFO_USAGEARGS == parg->idsUsage &&
  2228. (g_fFullUsage ||
  2229. (0 == msgid && g_fVerbose) ||
  2230. parg == pargVerb))
  2231. {
  2232. cuCAInfoUsage();
  2233. }
  2234. wprintf(wszNewLine);
  2235. }
  2236. }
  2237. // display options and descriptions for displayed verbs
  2238. wprintf(L"%ws\n", myLoadResourceString(IDS_OPTIONS_USAGEARGS));
  2239. for (parg = aarg ; parg < &aarg[ARRAYSIZE(aarg)]; parg++)
  2240. {
  2241. if (L'\0' == parg->pwszArg[0])
  2242. {
  2243. continue;
  2244. }
  2245. if (NULL != parg->pfnVerb)
  2246. {
  2247. continue;
  2248. }
  2249. if (!g_fFullUsage && (AF_PRIVATE & parg->Flags))
  2250. {
  2251. continue;
  2252. }
  2253. // skip options for undisplayed verbs,
  2254. // unless in verbose mode and no verb was specified
  2255. if ((!g_fVerbose || NULL != pargVerb) &&
  2256. 0 == ((AF_OPTION_MASK | AF_OPTIONALCONFIG) & dwFlags & parg->Flags))
  2257. {
  2258. continue;
  2259. }
  2260. wprintf(L" -");
  2261. if (0 != parg->idsUsage)
  2262. {
  2263. LONG ccol;
  2264. LONG ccolOption = NULL != parg->ppString?
  2265. CCOL_OPTIONARG : CCOL_OPTIONBARE;
  2266. LoadUsage(parg);
  2267. ccol = myConsolePrintString(0, parg->pwszArg);
  2268. wprintf(L" ");
  2269. ccol++;
  2270. myConsolePrintString(
  2271. ccolOption <= ccol? 0 : ccolOption - ccol,
  2272. parg->pwszUsage);
  2273. }
  2274. else
  2275. {
  2276. myConsolePrintString(CCOL_OPTIONBARE, parg->pwszArg);
  2277. }
  2278. if (0 != parg->idsDescription && NULL == parg->pwszDescription)
  2279. {
  2280. parg->pwszDescription = myLoadResourceString(
  2281. parg->idsDescription);
  2282. }
  2283. wprintf(L" -- %ws\n", parg->pwszDescription);
  2284. }
  2285. for (parg = aarg ; parg < &aarg[ARRAYSIZE(aarg)]; parg++)
  2286. {
  2287. FreeUsage(parg);
  2288. }
  2289. }
  2290. pwszArg = (NULL != pargVerb && NULL != pargVerb->pwszArg)?
  2291. pargVerb->pwszArg : pargDEFAULT->pwszArg;
  2292. wprintf(wszNewLine);
  2293. for (i = 0; i < ARRAYSIZE(adwids); i++)
  2294. {
  2295. LONG ccol;
  2296. WCHAR wsz[128];
  2297. _snwprintf(
  2298. wsz,
  2299. ARRAYSIZE(wsz) - 1,
  2300. apwszCommandLine[i],
  2301. g_pwszProg,
  2302. pwszArg);
  2303. wsz[ARRAYSIZE(wsz) - 1] = L'\0';
  2304. myConsolePrintString(CCOL_OPTIONARG, wsz);
  2305. wprintf(L" -- ");
  2306. wprintf(myLoadResourceString(adwids[i]), pwszArg);
  2307. wprintf(wszNewLine);
  2308. }
  2309. wprintf(wszNewLine);
  2310. }
  2311. HRESULT
  2312. verbUsage(
  2313. IN WCHAR const *pwszOption,
  2314. IN WCHAR const *pwszError,
  2315. IN WCHAR const *pwszArg2,
  2316. IN WCHAR const *pwszArg3,
  2317. IN WCHAR const *pwszArg4)
  2318. {
  2319. Usage(0, NULL, 0, NULL);
  2320. return(S_OK);
  2321. }
  2322. VOID
  2323. cuUnloadCert(
  2324. IN OUT CERT_CONTEXT const **ppCertContext)
  2325. {
  2326. if (NULL != *ppCertContext)
  2327. {
  2328. CertFreeCertificateContext(*ppCertContext);
  2329. *ppCertContext = NULL;
  2330. }
  2331. }
  2332. HRESULT
  2333. cuLoadCert(
  2334. IN WCHAR const *pwszfnCert,
  2335. OUT CERT_CONTEXT const **ppCertContext)
  2336. {
  2337. HRESULT hr;
  2338. BYTE *pbCert = NULL;
  2339. DWORD cbCert;
  2340. CERT_INFO *pCertInfo = NULL;
  2341. DWORD cbCertInfo;
  2342. *ppCertContext = NULL;
  2343. hr = DecodeFileW(pwszfnCert, &pbCert, &cbCert, CRYPT_STRING_ANY);
  2344. if (S_OK != hr)
  2345. {
  2346. cuPrintError(IDS_ERR_FORMAT_DECODEFILE, hr);
  2347. goto error;
  2348. }
  2349. // Decode certificate
  2350. cbCertInfo = 0;
  2351. if (!myDecodeObject(
  2352. X509_ASN_ENCODING,
  2353. X509_CERT_TO_BE_SIGNED,
  2354. pbCert,
  2355. cbCert,
  2356. CERTLIB_USE_LOCALALLOC,
  2357. (VOID **) &pCertInfo,
  2358. &cbCertInfo))
  2359. {
  2360. hr = myHLastError();
  2361. _JumpError2(hr, error, "myDecodeObject", CRYPT_E_ASN1_BADTAG);
  2362. }
  2363. *ppCertContext = CertCreateCertificateContext(
  2364. X509_ASN_ENCODING,
  2365. pbCert,
  2366. cbCert);
  2367. if (NULL == *ppCertContext)
  2368. {
  2369. hr = myHLastError();
  2370. _JumpError(hr, error, "CertCreateCertificateContext");
  2371. }
  2372. error:
  2373. if (NULL != pCertInfo)
  2374. {
  2375. LocalFree(pCertInfo);
  2376. }
  2377. if (NULL != pbCert)
  2378. {
  2379. LocalFree(pbCert);
  2380. }
  2381. return(hr);
  2382. }
  2383. VOID
  2384. cuUnloadCRL(
  2385. IN OUT CRL_CONTEXT const **ppCRLContext)
  2386. {
  2387. if (NULL != *ppCRLContext)
  2388. {
  2389. CertFreeCRLContext(*ppCRLContext);
  2390. *ppCRLContext = NULL;
  2391. }
  2392. }
  2393. HRESULT
  2394. cuLoadCRL(
  2395. IN WCHAR const *pwszfnCRL,
  2396. OUT CRL_CONTEXT const **ppCRLContext)
  2397. {
  2398. HRESULT hr;
  2399. BYTE *pbCRL = NULL;
  2400. DWORD cbCRL;
  2401. CRL_INFO *pCRLInfo = NULL;
  2402. DWORD cbCRLInfo;
  2403. *ppCRLContext = NULL;
  2404. hr = DecodeFileW(pwszfnCRL, &pbCRL, &cbCRL, CRYPT_STRING_ANY);
  2405. if (S_OK != hr)
  2406. {
  2407. cuPrintError(IDS_ERR_FORMAT_DECODEFILE, hr);
  2408. goto error;
  2409. }
  2410. // Decode CRL
  2411. cbCRLInfo = 0;
  2412. if (!myDecodeObject(
  2413. X509_ASN_ENCODING,
  2414. X509_CERT_CRL_TO_BE_SIGNED,
  2415. pbCRL,
  2416. cbCRL,
  2417. CERTLIB_USE_LOCALALLOC,
  2418. (VOID **) &pCRLInfo,
  2419. &cbCRLInfo))
  2420. {
  2421. hr = myHLastError();
  2422. _JumpError2(hr, error, "myDecodeObject", CRYPT_E_ASN1_BADTAG);
  2423. }
  2424. *ppCRLContext = CertCreateCRLContext(
  2425. X509_ASN_ENCODING,
  2426. pbCRL,
  2427. cbCRL);
  2428. if (NULL == *ppCRLContext)
  2429. {
  2430. hr = myHLastError();
  2431. _JumpError(hr, error, "CertCreateCRLContext");
  2432. }
  2433. error:
  2434. if (NULL != pCRLInfo)
  2435. {
  2436. LocalFree(pCRLInfo);
  2437. }
  2438. if (NULL != pbCRL)
  2439. {
  2440. LocalFree(pbCRL);
  2441. }
  2442. return(hr);
  2443. }
  2444. HRESULT
  2445. cuSetConfig()
  2446. {
  2447. HRESULT hr;
  2448. if (NULL == g_pwszConfig)
  2449. {
  2450. hr = myGetConfig(CC_LOCALCONFIG, &g_pwszConfigAlloc);
  2451. if (HRESULT_FROM_WIN32(ERROR_NO_MORE_ITEMS) == hr)
  2452. {
  2453. wprintf(
  2454. myLoadResourceString(IDS_ERR_FORMAT_NO_LOCAL_CONFIG), // "%ws: No local Certification Authority; use -config option"
  2455. g_pwszProg);
  2456. wprintf(wszNewLine);
  2457. }
  2458. _JumpIfError(hr, error, "myGetConfig");
  2459. }
  2460. else if (myIsMinusSignString(g_pwszConfig))
  2461. {
  2462. hr = myGetConfig(CC_UIPICKCONFIG, &g_pwszConfigAlloc);
  2463. if (S_OK != hr)
  2464. {
  2465. cuPrintError(IDS_ERR_CONFIGGETCONFIG, hr);
  2466. goto error;
  2467. }
  2468. }
  2469. if (NULL != g_pwszConfigAlloc)
  2470. {
  2471. g_pwszConfig = g_pwszConfigAlloc;
  2472. }
  2473. hr = S_OK;
  2474. error:
  2475. return(hr);
  2476. }
  2477. HRESULT
  2478. ArgvMain(
  2479. int argc,
  2480. WCHAR *argv[],
  2481. HWND hWndOwner)
  2482. {
  2483. WCHAR const *pwszArg1 = NULL;
  2484. WCHAR const *pwszArg2 = NULL;
  2485. WCHAR const *pwszArg3 = NULL;
  2486. WCHAR const *pwszArg4 = NULL;
  2487. BOOL fDlgResult;
  2488. ARG *pargVerb = NULL;
  2489. DWORD dwOptionFlags = 0;
  2490. DWORD dwExtraOptions;
  2491. ARG *parg;
  2492. HRESULT hr;
  2493. BOOL fCoInit = FALSE;
  2494. DWORD VerbFlags = 0;
  2495. BOOL fInitCS = FALSE;
  2496. __try
  2497. {
  2498. InitializeCriticalSection(&g_DBCriticalSection);
  2499. fInitCS = TRUE;
  2500. hr = S_OK;
  2501. }
  2502. __except(hr = myHEXCEPTIONCODE(), EXCEPTION_EXECUTE_HANDLER)
  2503. {
  2504. }
  2505. _JumpIfError(hr, error, "InitializeCriticalSection");
  2506. myVerifyResourceStrings(g_hInstance);
  2507. #ifdef TESTUUENCODE
  2508. RunTests();
  2509. #endif
  2510. while (1 < argc && myIsSwitchChar(argv[1][0]))
  2511. {
  2512. if (0 == LSTRCMPIS(&argv[1][1], L"stdio"))
  2513. {
  2514. myConsolePrintfDisable(TRUE);
  2515. }
  2516. else if (0 == lstrcmp(&argv[1][1], L"uSAGE"))
  2517. {
  2518. g_fFullUsage = TRUE;
  2519. Usage(0, NULL, 0, pargVerb);
  2520. hr = S_OK;
  2521. goto error;
  2522. }
  2523. else
  2524. {
  2525. if (myIsMinusSign(argv[1][0]) &&
  2526. (((AF_STOPATMINUSSIGN & VerbFlags) &&
  2527. L'\0' == argv[1][1]) ||
  2528. ((AF_STOPATMINUSSIGNARG & VerbFlags) &&
  2529. L'\0' != argv[1][1] &&
  2530. 0 != LSTRCMPIS(&argv[1][1], L"?"))))
  2531. {
  2532. break;
  2533. }
  2534. for (parg = aarg; ; parg++)
  2535. {
  2536. if (parg >= &aarg[ARRAYSIZE(aarg)])
  2537. {
  2538. Usage(
  2539. IDS_FORMAT_USAGE_UNKNOWNARG, // "Unknown arg: %ws"
  2540. argv[1],
  2541. 0,
  2542. pargVerb);
  2543. hr = S_FALSE;
  2544. goto error;
  2545. }
  2546. if (0 == mylstrcmpiS(&argv[1][1], parg->pwszArg))
  2547. {
  2548. break;
  2549. }
  2550. }
  2551. if (NULL != parg->pBool)
  2552. {
  2553. (*parg->pBool)++;
  2554. dwOptionFlags |= parg->Flags;
  2555. }
  2556. if (NULL != parg->ppString)
  2557. {
  2558. if (2 >= argc)
  2559. {
  2560. Usage(IDS_FORMAT_USAGE_MISSINGNAMEDARG, parg->pwszArg, 0, pargVerb); // "Missing %ws argument"
  2561. hr = S_FALSE;
  2562. goto error;
  2563. }
  2564. if (NULL != *parg->ppString)
  2565. {
  2566. Usage(IDS_FORMAT_USAGE_REPEATEDNAMEDARG, parg->pwszArg, 0, pargVerb); // "Repeated %ws option"
  2567. hr = S_FALSE;
  2568. goto error;
  2569. }
  2570. *parg->ppString = argv[2];
  2571. dwOptionFlags |= parg->Flags;
  2572. argc--;
  2573. argv++;
  2574. }
  2575. if (NULL != parg->pfnVerb)
  2576. {
  2577. if (NULL != pargVerb)
  2578. {
  2579. Usage(
  2580. verbUsage == parg->pfnVerb?
  2581. 0 :
  2582. IDS_FORMAT_USAGE_MULTIPLEVERBARGS, // "Multiple verb args: %ws"
  2583. argv[1],
  2584. 0,
  2585. pargVerb);
  2586. hr = S_FALSE;
  2587. goto error;
  2588. }
  2589. pargVerb = parg;
  2590. VerbFlags = pargVerb->Flags;
  2591. }
  2592. }
  2593. argc--;
  2594. argv++;
  2595. }
  2596. if (NULL == pargVerb)
  2597. {
  2598. pargVerb = pargDEFAULT;
  2599. }
  2600. if (pargVerb->cArgMin > argc - 1)
  2601. {
  2602. wprintf(
  2603. myLoadResourceString(IDS_ERR_FORMAT_SHOW_TOO_FEW_ARGS), // "Expected at least %u args, received %u"
  2604. pargVerb->cArgMin,
  2605. argc - 1);
  2606. wprintf(wszNewLine);
  2607. Usage(IDS_USAGE_MISSINGARG, NULL, 0, pargVerb); // "missing argument"
  2608. hr = S_FALSE;
  2609. goto error;
  2610. }
  2611. if (pargVerb->cArgMax < argc - 1)
  2612. {
  2613. wprintf(
  2614. myLoadResourceString(IDS_ERR_FORMAT_SHOW_TOO_MANY_ARGS), // "Expected no more than %u args, received %u"
  2615. pargVerb->cArgMax,
  2616. argc - 1);
  2617. wprintf(wszNewLine);
  2618. Usage(IDS_USAGE_TOOMANYARGS, NULL, 0, pargVerb); // "too many arguments"
  2619. hr = S_FALSE;
  2620. goto error;
  2621. }
  2622. g_DispatchFlags = DISPSETUP_COM;
  2623. if (g_fIDispatch)
  2624. {
  2625. g_DispatchFlags = DISPSETUP_IDISPATCH;
  2626. if (1 < g_fIDispatch)
  2627. {
  2628. g_DispatchFlags = DISPSETUP_COMFIRST;
  2629. }
  2630. }
  2631. if (g_fForce)
  2632. {
  2633. g_EncodeFlags = DECF_FORCEOVERWRITE;
  2634. }
  2635. if (g_fNoCR)
  2636. {
  2637. g_CryptEncodeFlags = CRYPT_STRING_NOCR;
  2638. }
  2639. if (NULL != g_pwszmsTimeout)
  2640. {
  2641. hr = myGetLong(g_pwszmsTimeout, (LONG *) &g_dwmsTimeout);
  2642. _JumpIfError(hr, error, "Timeout must be a number");
  2643. // zero implies a 15 second timeout in CAPI.
  2644. // If the timeut was explicitly set to 0, get as close as we can (1ms).
  2645. if (0 == g_dwmsTimeout)
  2646. {
  2647. g_dwmsTimeout = 1;
  2648. }
  2649. }
  2650. #if 0
  2651. wprintf(
  2652. L"-%ws: %ws %ws carg=%u-%u Flags=%x pfn=%x\n",
  2653. pargVerb->pwszArg,
  2654. pargVerb->pwszUsage,
  2655. pargVerb->pwszDescription,
  2656. pargVerb->cArgMin,
  2657. pargVerb->cArgMax,
  2658. pargVerb->Flags,
  2659. pargVerb->pfnVerb);
  2660. #endif
  2661. hr = myGetComputerNames(&g_pwszDnsName, &g_pwszOldName);
  2662. _JumpIfError(hr, error, "myGetComputerNames");
  2663. if (AF_NEEDCOINIT & pargVerb->Flags)
  2664. {
  2665. hr = CoInitialize(NULL);
  2666. if (S_OK != hr && S_FALSE != hr)
  2667. {
  2668. _JumpError(hr, error, "CoInitialize");
  2669. }
  2670. fCoInit = TRUE;
  2671. }
  2672. if (AF_OPTION_CONFIG & pargVerb->Flags)
  2673. {
  2674. if (0 == (AF_NEEDCOINIT & pargVerb->Flags))
  2675. {
  2676. Usage(IDS_USAGE_INTERNALVERBTABLEERROR, NULL, 0, pargVerb); // "Missing fCoInit flag"
  2677. hr = S_FALSE;
  2678. goto error;
  2679. }
  2680. hr = cuSetConfig();
  2681. _JumpIfError(hr, error, "cuSetConfig");
  2682. }
  2683. else if (0 == (AF_OPTIONALCONFIG & pargVerb->Flags))
  2684. {
  2685. if (NULL != g_pwszConfig)
  2686. {
  2687. Usage(IDS_FORMAT_USAGE_EXTRAOPTION, NULL, AF_OPTION_CONFIG, pargVerb); // "Unexpected -%ws"
  2688. hr = S_FALSE;
  2689. goto error;
  2690. }
  2691. }
  2692. if (NULL != g_pwszOut && 0 == (AF_OPTION_OUT & pargVerb->Flags))
  2693. {
  2694. Usage(IDS_FORMAT_USAGE_EXTRAOPTION, NULL, AF_OPTION_OUT, pargVerb); // "Unexpected %ws option"
  2695. hr = S_FALSE;
  2696. goto error;
  2697. }
  2698. if (NULL != g_pwszRestrict && 0 == (AF_OPTION_RESTRICT & pargVerb->Flags))
  2699. {
  2700. Usage(IDS_FORMAT_USAGE_EXTRAOPTION, NULL, AF_OPTION_RESTRICT, pargVerb); // "Unexpected %ws option"
  2701. hr = S_FALSE;
  2702. goto error;
  2703. }
  2704. dwExtraOptions = AF_OPTION_MASK &
  2705. ~AF_OPTION_GENERIC &
  2706. dwOptionFlags &
  2707. ~pargVerb->Flags;
  2708. if ((AF_OPTION_CONFIG & dwExtraOptions) &&
  2709. (AF_OPTIONALCONFIG & pargVerb->Flags))
  2710. {
  2711. dwExtraOptions &= ~AF_OPTION_CONFIG;
  2712. }
  2713. if (0 != dwExtraOptions)
  2714. {
  2715. DBGPRINT((
  2716. DBG_SS_CERTUTIL,
  2717. "Extra options: 0x%x\n",
  2718. dwExtraOptions));
  2719. Usage(IDS_FORMAT_USAGE_EXTRAOPTION, NULL, dwExtraOptions, pargVerb); // "Unexpected %ws option"
  2720. hr = S_FALSE;
  2721. goto error;
  2722. }
  2723. if (1 < argc)
  2724. {
  2725. pwszArg1 = argv[1];
  2726. if (2 < argc)
  2727. {
  2728. pwszArg2 = argv[2];
  2729. if (3 < argc)
  2730. {
  2731. pwszArg3 = argv[3];
  2732. if (4 < argc)
  2733. {
  2734. pwszArg4 = argv[4];
  2735. }
  2736. }
  2737. }
  2738. }
  2739. __try
  2740. {
  2741. hr = (*pargVerb->pfnVerb)(
  2742. pargVerb->pwszArg,
  2743. pwszArg1,
  2744. pwszArg2,
  2745. pwszArg3,
  2746. pwszArg4);
  2747. }
  2748. __except(hr = myHEXCEPTIONCODE(), EXCEPTION_EXECUTE_HANDLER)
  2749. {
  2750. }
  2751. if (S_OK != hr)
  2752. {
  2753. WCHAR awchr[cwcHRESULTSTRING];
  2754. wprintf(
  2755. myLoadResourceString(IDS_ERR_FORMAT_COMMAND_FAILED), // "%ws: -%ws command FAILED: %ws"
  2756. g_pwszProg,
  2757. pargVerb->pwszArg,
  2758. myHResultToString(awchr, hr));
  2759. wprintf(wszNewLine);
  2760. goto error;
  2761. }
  2762. if (!g_fCryptSilent)
  2763. {
  2764. wprintf(
  2765. myLoadResourceString(IDS_FORMAT_COMMAND_SUCCEEDED), // "%ws: -%ws command completed successfully."
  2766. g_pwszProg,
  2767. pargVerb->pwszArg);
  2768. wprintf(wszNewLine);
  2769. if (AF_RESTARTSERVER & pargVerb->Flags)
  2770. {
  2771. wprintf(
  2772. myLoadResourceString(IDS_FORMAT_RESTART_SERVER), // "The %ws service may need to be restarted for changes to take effect."
  2773. wszSERVICE_NAME);
  2774. wprintf(wszNewLine);
  2775. }
  2776. }
  2777. error:
  2778. if (S_OK != hr && S_FALSE != hr)
  2779. {
  2780. cuPrintErrorMessageText(hr);
  2781. if (0 != g_uiExtraErrorInfo)
  2782. {
  2783. wprintf(myLoadResourceString(g_uiExtraErrorInfo));
  2784. wprintf(wszNewLine);
  2785. }
  2786. if (NULL != g_pwszPassword)
  2787. {
  2788. myZeroDataString(g_pwszPassword); // password data
  2789. }
  2790. }
  2791. if (fCoInit)
  2792. {
  2793. CoUninitialize();
  2794. }
  2795. if (fInitCS)
  2796. {
  2797. DeleteCriticalSection(&g_DBCriticalSection);
  2798. }
  2799. return(hr);
  2800. }
  2801. //**************************************************************************
  2802. // FUNCTION: CertUtilPreMain
  2803. // NOTES: Based on vich's MkRootMain function; takes an LPSTR command
  2804. // line and chews it up into argc/argv form so that it can be
  2805. // passed on to a traditional C style main.
  2806. //**************************************************************************
  2807. #define ISBLANK(wc) (L' ' == (wc) || L'\t' == (wc))
  2808. HRESULT
  2809. CertUtilPreMain(
  2810. IN WCHAR const *pwszCmdLine,
  2811. IN HWND hWndOwner)
  2812. {
  2813. HRESULT hr;
  2814. WCHAR const *pwszCmdLineT;
  2815. WCHAR *pbuf;
  2816. WCHAR *apwszArg[20];
  2817. DWORD i;
  2818. DWORD cwc;
  2819. DWORD cArg = 0;
  2820. WCHAR *p;
  2821. WCHAR const *pchQuote;
  2822. WCHAR *pwszLog = NULL;
  2823. int carg;
  2824. BOOL fMainCompleted = FALSE;
  2825. UINT idsError = 0;
  2826. WCHAR wcQuote;
  2827. pbuf = (WCHAR *) LocalAlloc(
  2828. LMEM_FIXED,
  2829. (wcslen(pwszCmdLine) + 1) * sizeof(WCHAR));
  2830. if (NULL == pbuf)
  2831. {
  2832. hr = E_OUTOFMEMORY;
  2833. _JumpError(hr, error, "LocalAlloc");
  2834. }
  2835. p = pbuf;
  2836. apwszArg[cArg++] = TEXT("CertUtil");
  2837. pwszCmdLineT = pwszCmdLine;
  2838. while (*pwszCmdLineT != TEXT('\0'))
  2839. {
  2840. while (ISBLANK(*pwszCmdLineT))
  2841. {
  2842. pwszCmdLineT++;
  2843. }
  2844. if (*pwszCmdLineT != TEXT('\0'))
  2845. {
  2846. apwszArg[cArg++] = p;
  2847. if (sizeof(apwszArg)/sizeof(apwszArg[0]) <= cArg)
  2848. {
  2849. idsError = IDS_USAGE_TOOMANYARGS;
  2850. hr = E_INVALIDARG;
  2851. _JumpError(hr, error, "Too many args");
  2852. }
  2853. pchQuote = NULL;
  2854. while (*pwszCmdLineT != L'\0')
  2855. {
  2856. if (NULL != pchQuote)
  2857. {
  2858. if (*pwszCmdLineT == *pchQuote)
  2859. {
  2860. pwszCmdLineT++;
  2861. pchQuote = NULL;
  2862. continue;
  2863. }
  2864. }
  2865. else
  2866. {
  2867. if (ISBLANK(*pwszCmdLineT))
  2868. {
  2869. break;
  2870. }
  2871. if (L'"' == *pwszCmdLineT)
  2872. {
  2873. pchQuote = pwszCmdLineT++;
  2874. continue;
  2875. }
  2876. #define wcLENQUOTE (WCHAR) 0x201c
  2877. #define wcRENQUOTE (WCHAR) 0x201d
  2878. else if (wcLENQUOTE == *pwszCmdLineT)
  2879. {
  2880. pwszCmdLineT++;
  2881. wcQuote = wcRENQUOTE;
  2882. pchQuote = &wcQuote;
  2883. continue;
  2884. }
  2885. }
  2886. *p++ = *pwszCmdLineT++;
  2887. }
  2888. *p++ = TEXT('\0');
  2889. if (*pwszCmdLineT != TEXT('\0'))
  2890. {
  2891. pwszCmdLineT++; // skip whitespace or quote character
  2892. }
  2893. }
  2894. }
  2895. apwszArg[cArg] = NULL;
  2896. // Don't log passwords!
  2897. cwc = 0;
  2898. for (i = 0; i < cArg; i++)
  2899. {
  2900. cwc += 1 + wcslen(apwszArg[i]);
  2901. if (NULL != wcschr(apwszArg[i], L' '))
  2902. {
  2903. cwc += 2;
  2904. }
  2905. }
  2906. pwszLog = (WCHAR *) LocalAlloc(LMEM_FIXED, (cwc + 1) * sizeof(WCHAR));
  2907. if (NULL == pwszLog)
  2908. {
  2909. hr = E_OUTOFMEMORY;
  2910. _JumpError(hr, error, "LocalAlloc");
  2911. }
  2912. *pwszLog = L'\0';
  2913. for (i = 0; i < cArg; i++)
  2914. {
  2915. BOOL fQuote = NULL != wcschr(apwszArg[i], L' ');
  2916. if (0 != i)
  2917. {
  2918. wcscat(pwszLog, L" ");
  2919. }
  2920. if (0 == i ||
  2921. !myIsSwitchChar(apwszArg[i - 1][0]) ||
  2922. 0 != LSTRCMPIS(&apwszArg[i - 1][1], L"p"))
  2923. {
  2924. if (fQuote)
  2925. {
  2926. wcscat(pwszLog, L"\"");
  2927. }
  2928. wcscat(pwszLog, apwszArg[i]);
  2929. if (fQuote)
  2930. {
  2931. wcscat(pwszLog, L"\"");
  2932. }
  2933. }
  2934. else
  2935. {
  2936. WCHAR const *pwc = apwszArg[i];
  2937. while (TRUE)
  2938. {
  2939. WCHAR const *pwszCat = L"-";
  2940. switch (*pwc)
  2941. {
  2942. case L'*':
  2943. if (L'\0' == pwc[1])
  2944. {
  2945. pwszCat = L"*";
  2946. }
  2947. break;
  2948. case L',':
  2949. pwszCat = L""; // avoid buffer overflow
  2950. break;
  2951. }
  2952. wcscat(pwszLog, pwszCat);
  2953. pwc = wcschr(pwc, L',');
  2954. if (NULL == pwc)
  2955. {
  2956. break;
  2957. }
  2958. pwc++;
  2959. wcscat(pwszLog, L",");
  2960. }
  2961. }
  2962. }
  2963. CSASSERT(wcslen(pwszLog) <= cwc);
  2964. CSILOG(S_OK, IDS_LOG_COMMANDLINE, pwszLog, NULL, NULL);
  2965. hr = ArgvMain(cArg, apwszArg, hWndOwner);
  2966. fMainCompleted = TRUE;
  2967. _JumpIfError2(hr, error, "ArgvMain", S_FALSE);
  2968. error:
  2969. if (S_OK != hr && !fMainCompleted)
  2970. {
  2971. cuPrintErrorAndString(L"CertUtil", idsError, hr, pwszCmdLine);
  2972. }
  2973. if (NULL != pwszLog)
  2974. {
  2975. LocalFree(pwszLog);
  2976. }
  2977. if (NULL != pbuf)
  2978. {
  2979. LocalFree(pbuf);
  2980. }
  2981. CSILOG(hr, S_OK != hr? IDS_LOG_STATUS : IDS_LOG_STATUSOK, NULL, NULL, NULL);
  2982. return(hr);
  2983. }
  2984. //**************************************************************************
  2985. // FUNCTION: MainWndProc(...)
  2986. // ARGUMENTS:
  2987. //**************************************************************************
  2988. LRESULT APIENTRY
  2989. MainWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
  2990. {
  2991. HRESULT hr;
  2992. LRESULT lr = 0;
  2993. WCHAR *pwszCmdLine;
  2994. switch (msg)
  2995. {
  2996. case WM_CREATE:
  2997. case WM_SIZE:
  2998. break;
  2999. case WM_DESTROY:
  3000. PostQuitMessage(0);
  3001. break;
  3002. case WM_DOCERTUTILMAIN:
  3003. pwszCmdLine = (WCHAR*)lParam;
  3004. hr = CertUtilPreMain(pwszCmdLine, hWnd);
  3005. PostQuitMessage(hr);
  3006. break;
  3007. default:
  3008. lr = DefWindowProc(hWnd, msg, wParam, lParam);
  3009. break;
  3010. }
  3011. return(lr);
  3012. }
  3013. //+------------------------------------------------------------------------
  3014. //
  3015. // Function: wWinMain()
  3016. //
  3017. // Synopsis: Entry Point
  3018. //
  3019. // Arguments: [hInstance] -- Instance handle
  3020. // [hPrevInstance] -- Obsolete
  3021. // [pwszCmdLine] -- App command line
  3022. // [nCmdShow] -- Starting show state
  3023. //
  3024. // History: 12/07/96 JerryK Added this Comment
  3025. //
  3026. //-------------------------------------------------------------------------
  3027. extern "C" int APIENTRY
  3028. wWinMain(
  3029. HINSTANCE hInstance,
  3030. HINSTANCE hPrevInstance,
  3031. LPWSTR pwszCmdLine,
  3032. int nCmdShow)
  3033. {
  3034. int ret;
  3035. MSG msg;
  3036. WNDCLASS wcApp;
  3037. HWND hWndMain;
  3038. _setmode(_fileno(stdout), _O_TEXT);
  3039. _wsetlocale(LC_ALL, L".OCP");
  3040. mySetThreadUILanguage(0);
  3041. // Save the current instance
  3042. g_hInstance = hInstance;
  3043. csiLogOpen("+certutil.log");
  3044. CSILOGFILEVERSION(0, L"certutil.exe", szCSVER_STR);
  3045. // Set up the application's window class
  3046. wcApp.style = 0;
  3047. wcApp.lpfnWndProc = MainWndProc;
  3048. wcApp.cbClsExtra = 0;
  3049. wcApp.cbWndExtra = 0;
  3050. wcApp.hInstance = hInstance;
  3051. wcApp.hIcon = LoadIcon(NULL,IDI_APPLICATION);
  3052. wcApp.hCursor = LoadCursor(NULL,IDC_ARROW);
  3053. wcApp.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
  3054. wcApp.lpszMenuName = NULL;
  3055. wcApp.lpszClassName = wszAppName;
  3056. if (!RegisterClass(&wcApp))
  3057. {
  3058. ret = GetLastError();
  3059. goto error;
  3060. }
  3061. // Create Main Window
  3062. hWndMain = CreateWindow(
  3063. wszAppName,
  3064. L"CertUtil Application",
  3065. WS_OVERLAPPEDWINDOW,
  3066. CW_USEDEFAULT, CW_USEDEFAULT,
  3067. CW_USEDEFAULT, CW_USEDEFAULT,
  3068. NULL,
  3069. NULL,
  3070. hInstance,
  3071. NULL);
  3072. if (NULL == hWndMain)
  3073. {
  3074. ret = GetLastError();
  3075. goto error;
  3076. }
  3077. // Make window visible
  3078. // ShowWindow(hWndMain, nCmdShow);
  3079. // Update window client area
  3080. UpdateWindow(hWndMain);
  3081. // Send off the message to get things started
  3082. PostMessage(hWndMain, WM_DOCERTUTILMAIN, 0, (LPARAM) pwszCmdLine);
  3083. // Message Loop
  3084. while (GetMessage(&msg, NULL, 0, 0))
  3085. {
  3086. TranslateMessage(&msg);
  3087. DispatchMessage(&msg);
  3088. }
  3089. ret = (int) msg.wParam;
  3090. error:
  3091. if (NULL != g_pwszDnsName)
  3092. {
  3093. LocalFree(g_pwszDnsName);
  3094. }
  3095. if (NULL != g_pwszOldName)
  3096. {
  3097. LocalFree(g_pwszOldName);
  3098. }
  3099. if (NULL != g_pwszConfigAlloc)
  3100. {
  3101. LocalFree(g_pwszConfigAlloc);
  3102. }
  3103. FreeStoreArgDescription();
  3104. myFreeResourceStrings("certutil.exe");
  3105. myFreeColumnDisplayNames();
  3106. myRegisterMemDump();
  3107. csiLogClose();
  3108. return(ret);
  3109. }