Changeset 67935 in vbox for trunk/src/VBox/Additions/WINNT/tools/VBoxCertUtil.cpp
- Timestamp:
- Jul 12, 2017 2:56:29 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Additions/WINNT/tools/VBoxCertUtil.cpp
r63092 r67935 29 29 #include <iprt/initterm.h> 30 30 #include <iprt/message.h> 31 #include <iprt/path.h> 31 32 #include <iprt/stream.h> 32 33 #include <iprt/string.h> … … 390 391 } 391 392 else 392 {393 393 RTMsgError("Path not implemented at line %d\n", __LINE__); 394 }395 394 396 395 CertCloseStore(hDstStore, CERT_CLOSE_STORE_CHECK_FLAG); … … 592 591 { 593 592 /* 594 * Parse arguments .593 * Parse arguments and execute imports as we move along. 595 594 */ 596 595 static const RTGETOPTDEF s_aOptions[] = … … 599 598 }; 600 599 601 const char *pszRootCert = NULL; 602 const char *pszTrustedCert = NULL; 603 604 int rc; 605 RTGETOPTUNION ValueUnion; 606 RTGETOPTSTATE GetState; 607 RTGetOptInit(&GetState, argc, argv, s_aOptions, RT_ELEMENTS(s_aOptions), 1, 0); 600 RTEXITCODE rcExit = RTEXITCODE_SUCCESS; 601 unsigned cImports = 0; 602 RTGETOPTUNION ValueUnion; 603 RTGETOPTSTATE GetState; 604 int rc = RTGetOptInit(&GetState, argc, argv, s_aOptions, RT_ELEMENTS(s_aOptions), 1, 0); 605 AssertRC(rc); 608 606 while ((rc = RTGetOpt(&GetState, &ValueUnion))) 609 607 { … … 619 617 620 618 case 'r': 621 if (pszRootCert) 622 return RTMsgErrorExit(RTEXITCODE_SUCCESS, 623 "You've already specified '%s' as root certificate.", 624 pszRootCert); 625 pszRootCert = ValueUnion.psz; 619 case VINF_GETOPT_NOT_OPTION: 620 { 621 const char * const pszStoreNm = rc == 'r' ? "Root" : "TrustedPublisher"; 622 const char * const pszStoreDesc = rc == 'r' ? "root" : "trusted publisher"; 623 PCRTPATHGLOBENTRY pResultHead; 624 rc = RTPathGlob(ValueUnion.psz, RTPATHGLOB_F_NO_DIRS, &pResultHead, NULL); 625 if (RT_SUCCESS(rc)) 626 { 627 for (PCRTPATHGLOBENTRY pCur = pResultHead; pCur; pCur = pCur->pNext) 628 { 629 if (addCertToStore(CERT_SYSTEM_STORE_LOCAL_MACHINE, pszStoreNm, pCur->szPath, CERT_STORE_ADD_NEW)) 630 RTMsgInfo("Successfully added '%s' as %s", pCur->szPath, pszStoreDesc); 631 else 632 rcExit = RTEXITCODE_FAILURE; 633 cImports++; 634 } 635 RTPathGlobFree(pResultHead); 636 } 637 else 638 { 639 rcExit = RTMsgErrorExit(RTEXITCODE_SUCCESS, "glob failed on '%s': %Rrc", ValueUnion.psz, rc); 640 cImports++; 641 } 626 642 break; 627 628 case VINF_GETOPT_NOT_OPTION: 629 if (pszTrustedCert) 630 return RTMsgErrorExit(RTEXITCODE_SUCCESS, 631 "You've already specified '%s' as trusted certificate.", 632 pszTrustedCert); 633 pszTrustedCert = ValueUnion.psz; 634 break; 643 } 635 644 636 645 default: … … 638 647 } 639 648 } 640 if (!pszTrustedCert) 641 return RTMsgErrorExit(RTEXITCODE_SUCCESS, "No trusted certificate specified."); 642 643 /* 644 * Do the job. 645 */ 646 /** @todo The root-cert part needs to be made more flexible. */ 647 if ( pszRootCert 648 && !addCertToStore(CERT_SYSTEM_STORE_LOCAL_MACHINE, "Root", pszRootCert, CERT_STORE_ADD_NEW)) 649 return RTEXITCODE_FAILURE; 650 651 if (!addCertToStore(CERT_SYSTEM_STORE_LOCAL_MACHINE, "TrustedPublisher", pszTrustedCert, CERT_STORE_ADD_NEW)) 652 return RTEXITCODE_FAILURE; 653 654 if (g_cVerbosityLevel > 0) 655 { 656 if (pszRootCert) 657 RTMsgInfo("Successfully added '%s' as root and '%s' as trusted publisher", pszRootCert, pszTrustedCert); 658 else 659 RTMsgInfo("Successfully added '%s' as trusted publisher", pszTrustedCert); 660 } 661 return RTEXITCODE_SUCCESS; 649 if (cImports == 0) 650 return RTMsgErrorExit(RTEXITCODE_SUCCESS, "No trusted or root certificates specified."); 651 return rcExit; 662 652 } 663 653
Note:
See TracChangeset
for help on using the changeset viewer.