VirtualBox

Ignore:
Timestamp:
Jul 12, 2012 10:39:18 AM (13 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
79075
Message:

optional encrypted store of the iSCSI initiator secret

Location:
trunk/src/VBox/Frontends/VBoxManage
Files:
2 edited

Legend:

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

    r41100 r42125  
    3737#include <iprt/asm.h>
    3838#include <iprt/buildconfig.h>
     39#include <iprt/ctype.h>
    3940#include <iprt/initterm.h>
    4041#include <iprt/path.h>
     
    245246
    246247
     248#ifndef VBOX_ONLY_DOCS
     249static RTEXITCODE settingsPasswordFile(ComPtr<IVirtualBox> virtualBox, const char *pszFile)
     250{
     251    size_t cbFile;
     252    char szPasswd[512];
     253    int vrc = VINF_SUCCESS;
     254    RTEXITCODE rcExit = RTEXITCODE_SUCCESS;
     255    bool fStdIn = !strcmp(pszFile, "stdin");
     256    PRTSTREAM pStrm;
     257    if (!fStdIn)
     258        vrc = RTStrmOpen(pszFile, "r", &pStrm);
     259    else
     260        pStrm = g_pStdIn;
     261    if (RT_SUCCESS(vrc))
     262    {
     263        vrc = RTStrmReadEx(pStrm, szPasswd, sizeof(szPasswd)-1, &cbFile);
     264        if (RT_SUCCESS(vrc))
     265        {
     266            if (cbFile >= sizeof(szPasswd)-1)
     267                rcExit = RTMsgErrorExit(RTEXITCODE_FAILURE, "Provided password too long");
     268            else
     269            {
     270                unsigned i;
     271                for (i = 0; i < cbFile && !RT_C_IS_CNTRL(szPasswd[i]); i++)
     272                    ;
     273                szPasswd[i] = '\0';
     274                int rc;
     275                CHECK_ERROR(virtualBox, SetSettingsSecret(com::Bstr(szPasswd).raw()));
     276                if (FAILED(rc))
     277                    rcExit = RTEXITCODE_FAILURE;
     278            }
     279        }
     280        if (!fStdIn)
     281            RTStrmClose(pStrm);
     282    }
     283    else
     284        rcExit = RTMsgErrorExit(RTEXITCODE_FAILURE, "Cannot open password file '%s' (%Rrc)", pszFile);
     285
     286    return rcExit;
     287}
     288#endif
     289
    247290int main(int argc, char *argv[])
    248291{
     
    260303    int  iCmd      = 1;
    261304    int  iCmdArg;
     305    const char *g_pszSettingsPw = NULL;
     306    const char *g_pszSettingsPwFile = NULL;
    262307
    263308    for (int i = 1; i < argc || argc <= iCmd; i++)
     
    316361            iCmd++;
    317362        }
     363        else if (!strcmp(argv[i], "--settingspw"))
     364        {
     365            if (i >= argc-1)
     366                return RTMsgErrorExit(RTEXITCODE_FAILURE,
     367                                      "Password expected");
     368            /* password for certain settings */
     369            g_pszSettingsPw = argv[i+1];
     370            iCmd += 2;
     371        }
     372        else if (!strcmp(argv[i], "--settingspwfile"))
     373        {
     374            if (i >= argc-1)
     375                return RTMsgErrorExit(RTEXITCODE_FAILURE,
     376                                      "No password file specified");
     377            g_pszSettingsPwFile = argv[i+1];
     378            iCmd += 2;
     379        }
    318380        else
    319         {
    320381            break;
    321         }
    322382    }
    323383
     
    447507        };
    448508
     509        if (g_pszSettingsPw)
     510        {
     511            int rc;
     512            CHECK_ERROR(virtualBox, SetSettingsSecret(Bstr(g_pszSettingsPw).raw()));
     513            if (FAILED(rc))
     514            {
     515                rcExit = RTEXITCODE_FAILURE;
     516                break;
     517            }
     518        }
     519        else if (g_pszSettingsPwFile)
     520        {
     521            rcExit = settingsPasswordFile(virtualBox, g_pszSettingsPwFile);
     522            if (rcExit != RTEXITCODE_SUCCESS)
     523                break;
     524        }
     525
    449526        HandlerArg  handlerArg = { 0, NULL, virtualBox, session };
    450527        int         commandIndex;
  • trunk/src/VBox/Frontends/VBoxManage/VBoxManageHelp.cpp

    r41925 r42125  
    9999    if (u64Cmd == USAGE_ALL)
    100100        RTStrmPrintf(pStrm,
    101                      "VBoxManage [-v|--version]    print version number and exit\n"
    102                      "VBoxManage [-q|--nologo] ... suppress the logo\n"
     101                     "VBoxManage [-v|--version]          print version number and exit\n"
     102                     "VBoxManage [-q|--nologo]       ... suppress the logo\n"
     103                     "VBoxManage [--settingspw <pw>] ...\n"
     104                     "VBoxManage [--settingspwfile]  ... provide the settings password\n"
    103105                     "\n");
    104106
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