Changeset 96765 in vbox for trunk/src/VBox
- Timestamp:
- Sep 16, 2022 11:58:36 AM (2 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Additions/WINNT/tools/VBoxCertUtil.cpp
r96685 r96765 488 488 * @param dwDisposition The disposition towards existing certificates when 489 489 * adding it. CERT_STORE_ADD_NEW is a safe one. 490 */ 491 static bool addCertToStoreByFile(DWORD dwDst, const char *pszStoreNm, const char *pszCertFile, DWORD dwDisposition) 492 { 490 * @param pfAlreadyExists Where to indicate whether the certificate was 491 * already present and not replaced. 492 */ 493 static bool addCertToStoreByFile(DWORD dwDst, const char *pszStoreNm, const char *pszCertFile, DWORD dwDisposition, 494 bool *pfAlreadyExists) 495 { 496 *pfAlreadyExists = false; 497 493 498 /* 494 499 * Read the certificate file first. … … 514 519 fRc = true; 515 520 else 516 RTMsgError("CertAddCertificateContextToStore returned %s", errorToString(GetLastError())); 521 { 522 DWORD const dwErr = GetLastError(); 523 *pfAlreadyExists = fRc = dwErr == CRYPT_E_EXISTS; 524 if (!fRc) 525 RTMsgError("CertAddCertificateContextToStore returned %s", errorToString(dwErr)); 526 } 517 527 } 518 528 else … … 533 543 */ 534 544 static RTEXITCODE addCertToStoreByFilePattern(DWORD dwDst, const char *pszStoreNm, const char *pszStoreDesc, 535 const char *pszFilePattern, RTEXITCODE rcExit, uint32_t *pcImports)545 const char *pszFilePattern, bool fForce, RTEXITCODE rcExit, uint32_t *pcImports) 536 546 { 537 547 PCRTPATHGLOBENTRY pResultHead; … … 541 551 for (PCRTPATHGLOBENTRY pCur = pResultHead; pCur; pCur = pCur->pNext) 542 552 { 543 if (addCertToStoreByFile(dwDst, pszStoreNm, pCur->szPath, CERT_STORE_ADD_NEW)) 544 RTMsgInfo("Successfully added '%s' as %s", pCur->szPath, pszStoreDesc); 553 bool fAlreadyExists = false; 554 if (addCertToStoreByFile(dwDst, pszStoreNm, pCur->szPath, 555 !fForce ? CERT_STORE_ADD_NEW : CERT_STORE_ADD_REPLACE_EXISTING, 556 &fAlreadyExists)) 557 { 558 if (!fAlreadyExists) 559 RTMsgInfo("Successfully added '%s' to the %s store", pCur->szPath, pszStoreDesc); 560 else 561 RTMsgInfo("Certificate '%s' is already present in the %s store and was not re-added or updated.", 562 pCur->szPath, pszStoreNm); 563 } 545 564 else 546 565 rcExit = RTEXITCODE_FAILURE; … … 551 570 else 552 571 { 553 rcExit = RTMsgErrorExit (RTEXITCODE_SUCCESS,"glob failed on '%s': %Rrc", pszFilePattern, rc);572 rcExit = RTMsgErrorExitFailure("glob failed on '%s': %Rrc", pszFilePattern, rc); 554 573 *pcImports += 1; 555 574 } … … 678 697 679 698 case 'h': 680 RTPrintf("Usage: VBoxCertUtil display-all [-v|--verbose] [-q|--quiet]\n"); 699 RTStrmWrappedPrintf(g_pStdOut, RTSTRMWRAPPED_F_HANGING_INDENT, 700 "Usage: VBoxCertUtil display-all [-v|--verbose] [-q|--quiet]\n"); 681 701 return RTEXITCODE_SUCCESS; 682 702 … … 723 743 724 744 case 'h': 725 RTPrintf("Usage: VBoxCertUtil root-exists <full-subject-name> [alternative-subject-name [...]]\n" 726 "\n" 727 "Exit code: 10 if not found, 0 if found.\n" 728 "\n" 729 "The names are on the form 'C=US; O=Company; OU=some unit; CN=a cert name'\n" 730 "where semi-colon is the X.500 attribute separator and spaces surrounding it\n" 731 "the type (CN, OU, ) and '=' are generally ignored.\n" 732 "\n" 733 "At verbosity level 2, the full subject name of each certificate in the store\n" 734 "will be listed as the search progresses. These can be used as search input.\n" 735 ); 745 RTStrmWrappedPrintf(g_pStdOut, RTSTRMWRAPPED_F_HANGING_INDENT, 746 "Usage: VBoxCertUtil root-exists <full-subject-name> [alternative-subject-name [...]]\n"); 747 RTStrmWrappedPrintf(g_pStdOut, 0, 748 "\n" 749 "Exit code: 10 if not found, 0 if found.\n" 750 "\n" 751 "The names are on the form 'C=US; O=Company; OU=some unit; CN=a cert name' " 752 "where semi-colon is the X.500 attribute separator and spaces surrounding it " 753 "the type (CN, OU, ) and '=' are generally ignored.\n" 754 "\n" 755 "At verbosity level 2, the full subject name of each certificate in the store " 756 "will be listed as the search progresses. These can be used as search input.\n" 757 ); 736 758 return RTEXITCODE_SUCCESS; 737 759 … … 781 803 782 804 case 'h': 783 RTPrintf("Usage: VBoxCertUtil remove-root <root-cert-file>\n"); 805 RTStrmWrappedPrintf(g_pStdOut, RTSTRMWRAPPED_F_HANGING_INDENT, 806 "Usage: VBoxCertUtil remove-root <root-cert-file>\n"); 784 807 return RTEXITCODE_SUCCESS; 785 808 … … 827 850 828 851 case 'h': 829 RTPrintf("Usage: VBoxCertUtil remove-trusted-publisher [--root <root-cert>] <trusted-cert>\n"); 852 RTStrmWrappedPrintf(g_pStdOut, RTSTRMWRAPPED_F_HANGING_INDENT, 853 "Usage: VBoxCertUtil remove-trusted-publisher [--root <root-cert>] <trusted-cert>\n"); 830 854 return RTEXITCODE_SUCCESS; 831 855 … … 861 885 static const RTGETOPTDEF s_aOptions[] = 862 886 { 887 { "--add-if-new", 'a', RTGETOPT_REQ_NOTHING }, 888 { "--force", 'f', RTGETOPT_REQ_NOTHING }, 863 889 VCU_COMMON_OPTION_DEFINITIONS(), 864 890 }; 865 891 866 RTEXITCODE rcExit = RTEXITCODE_SUCCESS; 867 unsigned cImports = 0; 892 RTEXITCODE rcExit = RTEXITCODE_SUCCESS; 893 unsigned cImports = 0; 894 bool fForce = false; 868 895 RTGETOPTUNION ValueUnion; 869 896 RTGETOPTSTATE GetState; … … 876 903 VCU_COMMON_OPTION_HANDLING(); 877 904 905 case 'a': 906 fForce = false; 907 break; 908 909 case 'f': 910 fForce = false; 911 break; 912 878 913 case 'h': 879 RTPrintf("Usage: VBoxCertUtil add-root <root-cert>\n"); 914 RTStrmWrappedPrintf(g_pStdOut, RTSTRMWRAPPED_F_HANGING_INDENT, 915 "Usage: VBoxCertUtil add-root [--force|--add-if-new] <root-cert>\n"); 880 916 return RTEXITCODE_SUCCESS; 881 917 882 918 case VINF_GETOPT_NOT_OPTION: 883 919 rcExit = addCertToStoreByFilePattern(CERT_SYSTEM_STORE_LOCAL_MACHINE, "Root", "root", 884 ValueUnion.psz, rcExit, &cImports);920 ValueUnion.psz, fForce, rcExit, &cImports); 885 921 break; 886 922 … … 905 941 static const RTGETOPTDEF s_aOptions[] = 906 942 { 907 { "--root", 'r', RTGETOPT_REQ_STRING }, 943 { "--root", 'r', RTGETOPT_REQ_STRING }, 944 { "--add-if-new", 'a', RTGETOPT_REQ_NOTHING }, 945 { "--force", 'f', RTGETOPT_REQ_NOTHING }, 908 946 VCU_COMMON_OPTION_DEFINITIONS(), 909 947 }; 910 948 911 RTEXITCODE rcExit = RTEXITCODE_SUCCESS; 912 unsigned cImports = 0; 949 RTEXITCODE rcExit = RTEXITCODE_SUCCESS; 950 bool fForce = false; 951 unsigned cImports = 0; 913 952 RTGETOPTUNION ValueUnion; 914 953 RTGETOPTSTATE GetState; … … 921 960 VCU_COMMON_OPTION_HANDLING(); 922 961 962 case 'a': 963 fForce = false; 964 break; 965 966 case 'f': 967 fForce = false; 968 break; 969 923 970 case 'h': 924 RTPrintf("Usage: VBoxCertUtil add-trusted-publisher [--root <root-cert>] <trusted-cert>\n"); 971 RTStrmWrappedPrintf(g_pStdOut, RTSTRMWRAPPED_F_HANGING_INDENT, 972 "Usage: VBoxCertUtil add-trusted-publisher [--force|--add-if-new] " 973 "[--root <root-cert>] <trusted-cert>\n"); 925 974 return RTEXITCODE_SUCCESS; 926 975 927 976 case 'r': 928 977 rcExit = addCertToStoreByFilePattern(CERT_SYSTEM_STORE_LOCAL_MACHINE, "Root", "root", 929 ValueUnion.psz, rcExit, &cImports);978 ValueUnion.psz, fForce, rcExit, &cImports); 930 979 break; 931 980 932 981 case VINF_GETOPT_NOT_OPTION: 933 982 rcExit = addCertToStoreByFilePattern(CERT_SYSTEM_STORE_LOCAL_MACHINE, "TrustedPublisher", "trusted publisher", 934 ValueUnion.psz, rcExit, &cImports);983 ValueUnion.psz, fForce, rcExit, &cImports); 935 984 break; 936 985
Note:
See TracChangeset
for help on using the changeset viewer.