Changeset 42446 in vbox
- Timestamp:
- Jul 30, 2012 1:17:14 PM (12 years ago)
- Location:
- trunk/src/VBox/Frontends
- Files:
-
- 2 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 -
trunk/src/VBox/Frontends/VBoxSDL/VBoxSDL.cpp
r42382 r42446 63 63 #include <iprt/asm.h> 64 64 #include <iprt/assert.h> 65 #include <iprt/ctype.h> 65 66 #include <iprt/env.h> 66 67 #include <iprt/file.h> … … 157 158 static int WaitSDLEvent(SDL_Event *event); 158 159 static void SetFullscreen(bool enable); 160 static RTEXITCODE readPasswordFile(const char *pszFilename, com::Utf8Str *pPasswd); 161 static RTEXITCODE settingsPasswordFile(ComPtr<IVirtualBox> virtualBox, const char *pszFilename); 162 159 163 #ifdef VBOX_WITH_SDL13 160 164 static VBoxSDLFB * getFbFromWinId(SDL_WindowID id); … … 617 621 " --vrdp <ports> Listen for VRDP connections on one of specified ports (default if not specified)\n" 618 622 " --discardstate Discard saved state (if present) and revert to last snapshot (if present)\n" 623 " --settingspw Specify the settings password\n" 624 " --settingspwfile Specify a file containing the settings password\n" 619 625 #ifdef VBOX_SECURELABEL 620 626 " --securelabel Display a secure VM label at the top of the screen\n" … … 815 821 bool fXPCOMEventThreadSignaled = false; 816 822 #endif 817 c har *hdaFile = NULL;818 c har *cdromFile = NULL;819 c har *fdaFile = NULL;823 const char *pcszHdaFile = NULL; 824 const char *pcszCdromFile = NULL; 825 const char *pcszFdaFile = NULL; 820 826 const char *pszPortVRDP = NULL; 821 827 bool fDiscardState = false; 828 const char *pcszSettingsPw = NULL; 829 const char *pcszSettingsPwFile = NULL; 822 830 #ifdef VBOX_SECURELABEL 823 831 BOOL fSecureLabel = false; … … 1118 1126 /* resolve it. */ 1119 1127 if (RTPathExists(argv[curArg])) 1120 hdaFile = RTPathRealDup(argv[curArg]);1121 if (! hdaFile)1128 pcszHdaFile = RTPathRealDup(argv[curArg]); 1129 if (!pcszHdaFile) 1122 1130 { 1123 1131 RTPrintf("Error: The path to the specified harddisk, '%s', could not be resolved.\n", argv[curArg]); … … 1135 1143 /* resolve it. */ 1136 1144 if (RTPathExists(argv[curArg])) 1137 fdaFile = RTPathRealDup(argv[curArg]);1138 if (! fdaFile)1145 pcszFdaFile = RTPathRealDup(argv[curArg]); 1146 if (!pcszFdaFile) 1139 1147 { 1140 1148 RTPrintf("Error: The path to the specified floppy disk, '%s', could not be resolved.\n", argv[curArg]); … … 1152 1160 /* resolve it. */ 1153 1161 if (RTPathExists(argv[curArg])) 1154 cdromFile = RTPathRealDup(argv[curArg]);1155 if (! cdromFile)1162 pcszCdromFile = RTPathRealDup(argv[curArg]); 1163 if (!pcszCdromFile) 1156 1164 { 1157 1165 RTPrintf("Error: The path to the specified cdrom, '%s', could not be resolved.\n", argv[curArg]); … … 1177 1185 { 1178 1186 fDiscardState = true; 1187 } 1188 else if (!strcmp(argv[curArg], "--settingspw")) 1189 { 1190 if (++curArg >= argc) 1191 { 1192 RTPrintf("Error: missing password"); 1193 return 1; 1194 } 1195 pcszSettingsPw = argv[curArg]; 1196 } 1197 else if (!strcmp(argv[curArg], "--settingspwfile")) 1198 { 1199 if (++curArg >= argc) 1200 { 1201 RTPrintf("Error: missing password file\n"); 1202 return 1; 1203 } 1204 pcszSettingsPwFile = argv[curArg]; 1179 1205 } 1180 1206 #ifdef VBOX_SECURELABEL … … 1375 1401 } 1376 1402 1403 if (pcszSettingsPw) 1404 { 1405 CHECK_ERROR(pVirtualBox, SetSettingsSecret(Bstr(pcszSettingsPw).raw())); 1406 if (FAILED(rc)) 1407 goto leave; 1408 } 1409 else if (pcszSettingsPwFile) 1410 { 1411 int rcExit = settingsPasswordFile(pVirtualBox, pcszSettingsPwFile); 1412 if (rcExit != RTEXITCODE_SUCCESS) 1413 goto leave; 1414 } 1415 1377 1416 /* 1378 1417 * Do we have a UUID? … … 1453 1492 * Are we supposed to use a different hard disk file? 1454 1493 */ 1455 if ( hdaFile)1494 if (pcszHdaFile) 1456 1495 { 1457 1496 ComPtr<IMedium> pMedium; … … 1461 1500 * assign it. If not, register a new image and assign it to the VM. 1462 1501 */ 1463 Bstr bstrHdaFile( hdaFile);1502 Bstr bstrHdaFile(pcszHdaFile); 1464 1503 pVirtualBox->OpenMedium(bstrHdaFile.raw(), DeviceType_HardDisk, 1465 1504 AccessMode_ReadWrite, FALSE /* fForceNewUuid */, … … 1468 1507 { 1469 1508 /* we've not found the image */ 1470 RTPrintf("Adding hard disk '%s'...\n", hdaFile);1509 RTPrintf("Adding hard disk '%s'...\n", pcszHdaFile); 1471 1510 pVirtualBox->OpenMedium(bstrHdaFile.raw(), DeviceType_HardDisk, 1472 1511 AccessMode_ReadWrite, FALSE /* fForceNewUuid */, … … 1524 1563 * Mount a floppy if requested. 1525 1564 */ 1526 if ( fdaFile)1565 if (pcszFdaFile) 1527 1566 do 1528 1567 { … … 1530 1569 1531 1570 /* unmount? */ 1532 if (!strcmp( fdaFile, "none"))1571 if (!strcmp(pcszFdaFile, "none")) 1533 1572 { 1534 1573 /* nothing to do, NULL object will cause unmount */ … … 1536 1575 else 1537 1576 { 1538 Bstr bstrFdaFile( fdaFile);1577 Bstr bstrFdaFile(pcszFdaFile); 1539 1578 1540 1579 /* Assume it's a host drive name */ … … 1554 1593 { 1555 1594 /* try to add to the list */ 1556 RTPrintf("Adding floppy image '%s'...\n", fdaFile);1595 RTPrintf("Adding floppy image '%s'...\n", pcszFdaFile); 1557 1596 CHECK_ERROR_BREAK(pVirtualBox, 1558 1597 OpenMedium(bstrFdaFile.raw(), … … 1609 1648 * Mount a CD-ROM if requested. 1610 1649 */ 1611 if ( cdromFile)1650 if (pcszCdromFile) 1612 1651 do 1613 1652 { … … 1615 1654 1616 1655 /* unmount? */ 1617 if (!strcmp( cdromFile, "none"))1656 if (!strcmp(pcszCdromFile, "none")) 1618 1657 { 1619 1658 /* nothing to do, NULL object will cause unmount */ … … 1621 1660 else 1622 1661 { 1623 Bstr bstrCdromFile( cdromFile);1662 Bstr bstrCdromFile(pcszCdromFile); 1624 1663 1625 1664 /* Assume it's a host drive name */ … … 1638 1677 { 1639 1678 /* try to add to the list */ 1640 RTPrintf("Adding ISO image '%s'...\n", cdromFile);1679 RTPrintf("Adding ISO image '%s'...\n", pcszCdromFile); 1641 1680 CHECK_ERROR_BREAK(pVirtualBox, 1642 1681 OpenMedium(bstrCdromFile.raw(), … … 2921 2960 } 2922 2961 2962 static RTEXITCODE readPasswordFile(const char *pszFilename, com::Utf8Str *pPasswd) 2963 { 2964 size_t cbFile; 2965 char szPasswd[512]; 2966 int vrc = VINF_SUCCESS; 2967 RTEXITCODE rcExit = RTEXITCODE_SUCCESS; 2968 bool fStdIn = !strcmp(pszFilename, "stdin"); 2969 PRTSTREAM pStrm; 2970 if (!fStdIn) 2971 vrc = RTStrmOpen(pszFilename, "r", &pStrm); 2972 else 2973 pStrm = g_pStdIn; 2974 if (RT_SUCCESS(vrc)) 2975 { 2976 vrc = RTStrmReadEx(pStrm, szPasswd, sizeof(szPasswd)-1, &cbFile); 2977 if (RT_SUCCESS(vrc)) 2978 { 2979 if (cbFile >= sizeof(szPasswd)-1) 2980 { 2981 RTPrintf("Provided password in file '%s' is too long\n", pszFilename); 2982 rcExit = RTEXITCODE_FAILURE; 2983 } 2984 else 2985 { 2986 unsigned i; 2987 for (i = 0; i < cbFile && !RT_C_IS_CNTRL(szPasswd[i]); i++) 2988 ; 2989 szPasswd[i] = '\0'; 2990 *pPasswd = szPasswd; 2991 } 2992 } 2993 else 2994 { 2995 RTPrintf("Cannot read password from file '%s': %Rrc\n", pszFilename, vrc); 2996 rcExit = RTEXITCODE_FAILURE; 2997 } 2998 if (!fStdIn) 2999 RTStrmClose(pStrm); 3000 } 3001 else 3002 { 3003 RTPrintf("Cannot open password file '%s' (%Rrc)\n", pszFilename, vrc); 3004 rcExit = RTEXITCODE_FAILURE; 3005 } 3006 3007 return rcExit; 3008 } 3009 3010 static RTEXITCODE settingsPasswordFile(ComPtr<IVirtualBox> virtualBox, const char *pszFilename) 3011 { 3012 com::Utf8Str passwd; 3013 RTEXITCODE rcExit = readPasswordFile(pszFilename, &passwd); 3014 if (rcExit == RTEXITCODE_SUCCESS) 3015 { 3016 int rc; 3017 CHECK_ERROR(virtualBox, SetSettingsSecret(com::Bstr(passwd).raw())); 3018 if (FAILED(rc)) 3019 rcExit = RTEXITCODE_FAILURE; 3020 } 3021 3022 return rcExit; 3023 } 2923 3024 2924 3025 #ifndef VBOX_WITH_HARDENING
Note:
See TracChangeset
for help on using the changeset viewer.