Changeset 42446 in vbox for trunk/src/VBox/Frontends/VBoxHeadless
- Timestamp:
- Jul 30, 2012 1:17:14 PM (13 years ago)
- svn:sync-xref-src-repo-rev:
- 79576
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VBoxHeadless/VBoxHeadless.cpp
r42382 r42446 471 471 " \"TCP/Address\" - interface IP the VRDE server\n" 472 472 " will bind to\n" 473 " --settingspw Specify the settings password\n" 474 " --settingspwfile Specify a file containing the settings password\n" 473 475 #ifdef VBOX_WITH_VIDEO_REC 474 476 " -c, -capture, --capture Record the VM screen output to a file\n" … … 476 478 " -h, --height Frame height when recording\n" 477 479 " -r, --bitrate Recording bit rate when recording\n" 478 " -f, --filename File name when recording. The codec\n" 479 " used will be chosen based on the\n" 480 " file extension\n" 480 " -f, --filename File name when recording. The codec used\n" 481 " will be chosen based on the file extension\n" 481 482 #endif 482 483 "\n"); … … 528 529 } 529 530 #endif /* VBOX_WITH_VIDEO_REC defined */ 531 532 static RTEXITCODE readPasswordFile(const char *pszFilename, com::Utf8Str *pPasswd) 533 { 534 size_t cbFile; 535 char szPasswd[512]; 536 int vrc = VINF_SUCCESS; 537 RTEXITCODE rcExit = RTEXITCODE_SUCCESS; 538 bool fStdIn = !strcmp(pszFilename, "stdin"); 539 PRTSTREAM pStrm; 540 if (!fStdIn) 541 vrc = RTStrmOpen(pszFilename, "r", &pStrm); 542 else 543 pStrm = g_pStdIn; 544 if (RT_SUCCESS(vrc)) 545 { 546 vrc = RTStrmReadEx(pStrm, szPasswd, sizeof(szPasswd)-1, &cbFile); 547 if (RT_SUCCESS(vrc)) 548 { 549 if (cbFile >= sizeof(szPasswd)-1) 550 { 551 RTPrintf("Provided password in file '%s' is too long\n", pszFilename); 552 rcExit = RTEXITCODE_FAILURE; 553 } 554 else 555 { 556 unsigned i; 557 for (i = 0; i < cbFile && !RT_C_IS_CNTRL(szPasswd[i]); i++) 558 ; 559 szPasswd[i] = '\0'; 560 *pPasswd = szPasswd; 561 } 562 } 563 else 564 { 565 RTPrintf("Cannot read password from file '%s': %Rrc\n", pszFilename, vrc); 566 rcExit = RTEXITCODE_FAILURE; 567 } 568 if (!fStdIn) 569 RTStrmClose(pStrm); 570 } 571 else 572 { 573 RTPrintf("Cannot open password file '%s' (%Rrc)\n", pszFilename, vrc); 574 rcExit = RTEXITCODE_FAILURE; 575 } 576 577 return rcExit; 578 } 579 580 static RTEXITCODE settingsPasswordFile(ComPtr<IVirtualBox> virtualBox, const char *pszFilename) 581 { 582 com::Utf8Str passwd; 583 RTEXITCODE rcExit = readPasswordFile(pszFilename, &passwd); 584 if (rcExit == RTEXITCODE_SUCCESS) 585 { 586 int rc; 587 CHECK_ERROR(virtualBox, SetSettingsSecret(com::Bstr(passwd).raw())); 588 if (FAILED(rc)) 589 rcExit = RTEXITCODE_FAILURE; 590 } 591 592 return rcExit; 593 } 530 594 531 595 #ifdef RT_OS_WINDOWS … … 577 641 OPT_CSAM, 578 642 OPT_NO_CSAM, 643 OPT_SETTINGSPW, 644 OPT_SETTINGSPW_FILE, 579 645 OPT_COMMENT 580 646 }; … … 610 676 { "-nocsam", OPT_NO_CSAM, 0 }, 611 677 { "--nocsam", OPT_NO_CSAM, 0 }, 678 { "--settingspw", OPT_SETTINGSPW, RTGETOPT_REQ_STRING }, 679 { "--settingspwfile", OPT_SETTINGSPW_FILE, RTGETOPT_REQ_STRING }, 612 680 #ifdef VBOX_WITH_VIDEO_REC 613 681 { "-capture", 'c', 0 }, … … 626 694 // parse the command line 627 695 int ch; 696 const char *pcszSettingsPw = NULL; 697 const char *pcszSettingsPwFile = NULL; 628 698 RTGETOPTUNION ValueUnion; 629 699 RTGETOPTSTATE GetState; … … 676 746 case OPT_NO_CSAM: 677 747 fCSAM = false; 748 break; 749 case OPT_SETTINGSPW: 750 pcszSettingsPw = ValueUnion.psz; 751 break; 752 case OPT_SETTINGSPW_FILE: 753 pcszSettingsPwFile = ValueUnion.psz; 678 754 break; 679 755 #ifdef VBOX_WITH_VIDEO_REC … … 807 883 RTPrintf("Failed to get session object (rc=%Rhrc)!\n", rc); 808 884 break; 885 } 886 887 if (pcszSettingsPw) 888 { 889 CHECK_ERROR(virtualBox, SetSettingsSecret(Bstr(pcszSettingsPw).raw())); 890 if (FAILED(rc)) 891 break; 892 } 893 else if (pcszSettingsPwFile) 894 { 895 int rcExit = settingsPasswordFile(virtualBox, pcszSettingsPwFile); 896 if (rcExit != RTEXITCODE_SUCCESS) 897 break; 809 898 } 810 899
Note:
See TracChangeset
for help on using the changeset viewer.