VirtualBox

Ignore:
Timestamp:
Jul 30, 2012 1:17:14 PM (13 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
79576
Message:

added --settingspw and --settingspwfile to VBoxHeadless and VBoxSDL

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VBoxHeadless/VBoxHeadless.cpp

    r42382 r42446  
    471471             "                                         \"TCP/Address\" - interface IP the VRDE server\n"
    472472             "                                         will bind to\n"
     473             "   --settingspw                          Specify the settings password\n"
     474             "   --settingspwfile                      Specify a file containing the settings password\n"
    473475#ifdef VBOX_WITH_VIDEO_REC
    474476             "   -c, -capture, --capture               Record the VM screen output to a file\n"
     
    476478             "   -h, --height                          Frame height when recording\n"
    477479             "   -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"
    481482#endif
    482483             "\n");
     
    528529}
    529530#endif /* VBOX_WITH_VIDEO_REC defined */
     531
     532static 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
     580static 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}
    530594
    531595#ifdef RT_OS_WINDOWS
     
    577641        OPT_CSAM,
    578642        OPT_NO_CSAM,
     643        OPT_SETTINGSPW,
     644        OPT_SETTINGSPW_FILE,
    579645        OPT_COMMENT
    580646    };
     
    610676        { "-nocsam", OPT_NO_CSAM, 0 },
    611677        { "--nocsam", OPT_NO_CSAM, 0 },
     678        { "--settingspw", OPT_SETTINGSPW, RTGETOPT_REQ_STRING },
     679        { "--settingspwfile", OPT_SETTINGSPW_FILE, RTGETOPT_REQ_STRING },
    612680#ifdef VBOX_WITH_VIDEO_REC
    613681        { "-capture", 'c', 0 },
     
    626694    // parse the command line
    627695    int ch;
     696    const char *pcszSettingsPw = NULL;
     697    const char *pcszSettingsPwFile = NULL;
    628698    RTGETOPTUNION ValueUnion;
    629699    RTGETOPTSTATE GetState;
     
    676746            case OPT_NO_CSAM:
    677747                fCSAM = false;
     748                break;
     749            case OPT_SETTINGSPW:
     750                pcszSettingsPw = ValueUnion.psz;
     751                break;
     752            case OPT_SETTINGSPW_FILE:
     753                pcszSettingsPwFile = ValueUnion.psz;
    678754                break;
    679755#ifdef VBOX_WITH_VIDEO_REC
     
    807883            RTPrintf("Failed to get session object (rc=%Rhrc)!\n", rc);
    808884            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;
    809898        }
    810899
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette