VirtualBox

Changeset 35204 in vbox


Ignore:
Timestamp:
Dec 16, 2010 5:59:42 PM (14 years ago)
Author:
vboxsync
Message:

ExtPack: Require authentication to install extension packs on linux and solaris.

Location:
trunk/src/VBox
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Installer/linux/install.sh

    r34679 r35204  
    354354        test -e $INSTALLATION_DIR/VBoxHeadless  && chmod 4511 $INSTALLATION_DIR/VBoxHeadless
    355355        test -e $INSTALLATION_DIR/VBoxNetDHCP   && chmod 4511 $INSTALLATION_DIR/VBoxNetDHCP
    356         test -e $INSTALLATION_DIR/VBoxExtPackHelperApp && chmod 4511 $INSTALLATION_DIR/VBoxExtPackHelperApp
    357356
    358357        ln -sf $INSTALLATION_DIR/VBoxVMM.so   $INSTALLATION_DIR/components/VBoxVMM.so
  • trunk/src/VBox/Installer/solaris/makepackage.sh

    r35054 r35204  
    208208        ||  $3 == "opt/VirtualBox/amd64/VBoxNetDHCP" \
    209209        ||  $3 == "opt/VirtualBox/i386/VBoxNetDHCP" \
    210         ||  $3 == "opt/VirtualBox/amd64/VBoxExtPackHelperApp" \
    211         ||  $3 == "opt/VirtualBox/i386/VBoxExtPackHelperApp" \
    212210        ) \
    213211   { $4 = "4755" } { print }' prototype > prototype2
  • trunk/src/VBox/Main/VBoxExtPackHelperApp.cpp

    r35188 r35204  
    2424#include <iprt/buildconfig.h>
    2525#include <iprt/dir.h>
     26#include <iprt/env.h>
    2627#include <iprt/file.h>
    2728#include <iprt/fs.h>
     
    4445#include <VBox/version.h>
    4546
    46 #if defined(RT_OS_DARWIN)
    47 # include <sys/types.h>
    48 # include <unistd.h>                    /* geteuid */
    49 #endif
    50 
    5147#ifdef RT_OS_WINDOWS
    5248# define _WIN32_WINNT 0x0501
     
    6460#endif
    6561
    66 #if defined(RT_OS_DARWIN) || defined(RT_OS_WINDOWS)
     62#if !defined(RT_OS_OS2)
    6763# include <stdio.h>
    6864# include <errno.h>
     65# if !defined(RT_OS_WINDOWS)
     66#  include <sys/types.h>
     67#  include <unistd.h>                   /* geteuid */
     68# endif
    6969#endif
    7070
     
    7474*******************************************************************************/
    7575/** Enable elevation on Windows and Darwin. */
    76 #if defined(RT_OS_WINDOWS) || defined(RT_OS_DARWIN) || defined(DOXYGEN_RUNNING)
     76#if !defined(RT_OS_OS2) || defined(DOXYGEN_RUNNING)
    7777# define WITH_ELEVATION
    7878#endif
    7979
     80
     81/** @name Command and option names
     82 * @{ */
     83#define CMD_INSTALL         1000
     84#define CMD_UNINSTALL       1001
     85#define CMD_CLEANUP         1002
     86#ifdef WITH_ELEVATION
     87# define OPT_ELEVATED       1090
     88# define OPT_STDOUT         1091
     89# define OPT_STDERR         1092
     90#endif
     91/** @}  */
    8092
    8193
     
    10481060#ifdef WITH_ELEVATION
    10491061
     1062#if !defined(RT_OS_WINDOWS) && !defined(RT_OS_DARWIN)
     1063/**
     1064 * Looks in standard locations for a suitable exec tool.
     1065 *
     1066 * @returns true if found, false if not.
     1067 * @param   pszPath             Where to store the path to the tool on
     1068 *                              successs.
     1069 * @param   cbPath              The size of the buffer @a pszPath points to.
     1070 * @param   pszName             The name of the tool we're looking for.
     1071 */
     1072static bool FindExecTool(char *pszPath, size_t cbPath, const char *pszName)
     1073{
     1074    static const char * const s_apszPaths[] =
     1075    {
     1076        "/bin",
     1077        "/usr/bin",
     1078        "/usr/local/bin",
     1079        "/sbin",
     1080        "/usr/sbin",
     1081        "/usr/local/sbin",
     1082#ifdef RT_OS_SOLARIS
     1083        "/usr/sfw/bin",
     1084        "/usr/gnu/bin",
     1085        "/usr/xpg4/bin",
     1086        "/usr/xpg6/bin",
     1087        "/usr/ucb"
     1088#endif
     1089    };
     1090
     1091    for (unsigned i = 0; i < RT_ELEMENTS(s_apszPaths); i++)
     1092    {
     1093        int rc = RTPathJoin(pszPath, cbPath, s_apszPaths[i], pszName);
     1094        if (RT_SUCCESS(rc))
     1095        {
     1096            RTFSOBJINFO ObjInfo;
     1097            rc = RTPathQueryInfoEx(pszPath, &ObjInfo, RTFSOBJATTRADD_UNIX, RTPATH_F_FOLLOW_LINK);
     1098            if (RT_SUCCESS(rc))
     1099            {
     1100                if (!(ObjInfo.Attr.fMode & RTFS_UNIX_IWOTH))
     1101                    return true;
     1102            }
     1103        }
     1104    }
     1105    return false;
     1106}
     1107#endif
     1108
     1109
    10501110/**
    10511111 * Copies the content of a file to a stream.
     
    10911151 * @returns Program exit code.
    10921152 * @param   pszExecPath         The executable path.
    1093  * @param   cArgs               The number of arguments.
    10941153 * @param   papszArgs           The arguments.
    1095  */
    1096 static RTEXITCODE RelaunchElevatedNative(const char *pszExecPath, int cArgs, const char * const *papszArgs)
     1154 * @param   cSuArgs             The number of argument entries reserved for the
     1155 *                              'su' like programs at the start of papszArgs.
     1156 * @param   cMyArgs             The number of arguments following @a cSuArgs.
     1157 * @param   iCmd                The command that is being executed. (For
     1158 *                              selecting messages.)
     1159 */
     1160static RTEXITCODE RelaunchElevatedNative(const char *pszExecPath, const char **papszArgs, int cSuArgs, int cMyArgs,
     1161                                         int iCmd)
    10971162{
    10981163    RTEXITCODE rcExit = RTEXITCODE_FAILURE;
    10991164#ifdef RT_OS_WINDOWS
     1165    NOREF(iCmd);
    11001166
    11011167    CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE);
     
    11111177    {
    11121178        char *pszCmdLine;
    1113         rc = RTGetOptArgvToString(&pszCmdLine, &papszArgs[1], RTGETOPTARGV_CNV_QUOTE_MS_CRT);
     1179        rc = RTGetOptArgvToString(&pszCmdLine, &papszArgs[cSuArgs + 1], RTGETOPTARGV_CNV_QUOTE_MS_CRT);
    11141180        if (RT_SUCCESS(rc))
    11151181        {
     
    11981264        AuthorizationRights AuthRights      = { 1, &AuthItem };
    11991265
     1266        NOREF(iCmd);
    12001267        static char         s_szPrompt[]    = "VirtualBox needs further rights to make changes to your installation.\n\n";
    12011268        AuthorizationItem   aAuthEnvItems[] =
     
    12171284            FILE *pSocketStrm;
    12181285            orc = AuthorizationExecuteWithPrivileges(AuthRef, pszExecPath, kAuthorizationFlagDefaults,
    1219                                                      (char * const *)&papszArgs[3],
     1286                                                     (char * const *)&papszArgs[cSuArgs + 3],
    12201287                                                     &pSocketStrm);
    12211288            if (orc == errAuthorizationSuccess)
     
    12481315
    12491316#else
    1250 # error "PORT ME"
     1317    /*
     1318     * Look for various standard stuff for executing a program as root.
     1319     *
     1320     * N.B. When adding new arguments, please make 100% sure RelaunchElevated
     1321     *      allocates enough array entries.
     1322     *
     1323     * TODO: Feel free to contribute code for using PolicyKit directly.
     1324     */
     1325    bool        fHaveDisplayVar = RTEnvExist("DISPLAY");
     1326    int         iSuArg          = cSuArgs;
     1327    char       *pszCmdLine      = NULL;
     1328    PRTHANDLE   pStdNull        = NULL;
     1329    RTHANDLE    StdNull;
     1330    char        szExecTool[260];
     1331    char        szXterm[260];
     1332    int         rc;
     1333
     1334    /*
     1335     * gksu is our favorite as it is very well integrated.
     1336     *
     1337     * gksu is chatty, so we need to send stderr and stdout to /dev/null or the
     1338     * error detection logic in Main will fail.  This is a bit unfortunate as
     1339     * error messages gets lost, but wtf.
     1340     */
     1341    if (fHaveDisplayVar && FindExecTool(szExecTool, sizeof(szExecTool), "gksu"))
     1342    {
     1343        rc = RTFileOpenBitBucket(&StdNull.u.hFile, RTFILE_O_WRITE);
     1344        if (RT_SUCCESS(rc))
     1345        {
     1346            StdNull.enmType = RTHANDLETYPE_FILE;
     1347            pStdNull = &StdNull;
     1348
     1349            iSuArg = cSuArgs - 4;
     1350            papszArgs[cSuArgs - 4] = szExecTool;
     1351            papszArgs[cSuArgs - 3] = "--description";
     1352            papszArgs[cSuArgs - 2] = iCmd == CMD_INSTALL
     1353                                   ? "VirtualBox extension pack installer"
     1354                                   : iCmd == CMD_UNINSTALL
     1355                                   ? "VirtualBox extension pack uninstaller"
     1356                                   : "VirtualBox extension pack maintainer";
     1357            papszArgs[cSuArgs - 1] = "--";
     1358        }
     1359        else
     1360            RTMsgError("Failed to open /dev/null: %Rrc");
     1361    }
     1362    /*
     1363     * pkexec may work for ssh console sessions as well if the right agents
     1364     * are installed.  However it is very generic and does not allow for any
     1365     * custom messages.  Thus it comes after gksu.
     1366     */
     1367    else if (FindExecTool(szExecTool, sizeof(szExecTool), "pkexec"))
     1368    {
     1369        iSuArg = cSuArgs - 1;
     1370        papszArgs[cSuArgs - 1] = szExecTool;
     1371    }
     1372    /*
     1373     * The ultimate fallback is running 'su -' within an xterm.  We use the
     1374     * title of the xterm to tell what is going on.
     1375     */
     1376    else if (   fHaveDisplayVar
     1377             && FindExecTool(szExecTool, sizeof(szExecTool), "su")
     1378             && FindExecTool(szXterm, sizeof(szXterm), "xterm"))
     1379    {
     1380        rc = RTGetOptArgvToString(&pszCmdLine, &papszArgs[cSuArgs], RTGETOPTARGV_CNV_QUOTE_BOURNE_SH);
     1381        if (RT_SUCCESS(rc))
     1382        {
     1383            iSuArg = cSuArgs - 8;
     1384            papszArgs[cSuArgs - 8] = szXterm;
     1385            papszArgs[cSuArgs - 7] = "-T";
     1386            papszArgs[cSuArgs - 6] = papszArgs[cSuArgs - 1] = iCmd == CMD_INSTALL
     1387                                   ? "VirtualBox extension pack installer - su"
     1388                                   : iCmd == CMD_UNINSTALL
     1389                                   ? "VirtualBox extension pack uninstaller - su"
     1390                                   : "VirtualBox extension pack maintainer - su";
     1391            papszArgs[cSuArgs - 5] = "-e";
     1392            papszArgs[cSuArgs - 4] = szExecTool;
     1393            papszArgs[cSuArgs - 3] = "-c";
     1394            papszArgs[cSuArgs - 2] = pszCmdLine;
     1395            papszArgs[cSuArgs - 1] = "-";
     1396            papszArgs[cSuArgs] = NULL;
     1397        }
     1398        else
     1399            RTMsgError("RTGetOptArgvToString failed: %Rrc");
     1400    }
     1401    else if (fHaveDisplayVar)
     1402        RTMsgError("Unable to locate 'pkexec', 'pksu' or 'su+xterm'. Try perform the operation using VBoxManage running as root");
     1403    else
     1404        RTMsgError("Unable to locate 'pkexec'. Try perform the operation using VBoxManage running as root");
     1405    if (iSuArg != cSuArgs)
     1406    {
     1407        AssertRelease(iSuArg >= 0);
     1408
     1409        /*
     1410         * Argument list constructed, execute it and wait for the exec
     1411         * program to complete.
     1412         */
     1413        RTPROCESS hProcess;
     1414        rc = RTProcCreateEx(papszArgs[iSuArg], &papszArgs[iSuArg], RTENV_DEFAULT, 0 /*fFlags*/,
     1415                            NULL /*phStdIn*/, pStdNull, pStdNull, NULL /*pszAsUser*/,  NULL /*pszPassword*/,
     1416                            &hProcess);
     1417        if (RT_SUCCESS(rc))
     1418        {
     1419            RTPROCSTATUS Status;
     1420            rc = RTProcWait(hProcess, RTPROCWAIT_FLAGS_BLOCK, &Status);
     1421            if (RT_SUCCESS(rc))
     1422            {
     1423                if (Status.enmReason == RTPROCEXITREASON_NORMAL)
     1424                    rcExit = (RTEXITCODE)Status.iStatus;
     1425                else
     1426                    rcExit = RTEXITCODE_FAILURE;
     1427            }
     1428            else
     1429                RTMsgError("Error while waiting for '%s': %Rrc", papszArgs[iSuArg], rc);
     1430        }
     1431        else
     1432            RTMsgError("Failed to execute '%s': %Rrc", papszArgs[iSuArg], rc);
     1433    }
     1434    RTStrFree(pszCmdLine);
     1435    RTFileClose(StdNull.u.hFile);
     1436
    12511437#endif
    12521438    return rcExit;
     
    12601446 * @param   argc                The number of arguments.
    12611447 * @param   argv                The arguments.
    1262  */
    1263 static RTEXITCODE RelaunchElevated(int argc, char **argv)
     1448 * @param   iCmd                The command that is being executed.
     1449 */
     1450static RTEXITCODE RelaunchElevated(int argc, char **argv, int iCmd)
    12641451{
    12651452    /*
     
    13071494                 * change the order here.
    13081495                 */
     1496                int const    cSuArgs   = 10;
    13091497                int          cArgs     = argc + 5 + 1;
    1310                 char const **papszArgs = (char const **)RTMemTmpAllocZ((cArgs + 1) * sizeof(const char *));
     1498                char const **papszArgs = (char const **)RTMemTmpAllocZ((cSuArgs + cArgs + 1) * sizeof(const char *));
    13111499                if (papszArgs)
    13121500                {
    1313                     int iDst = 0;
     1501                    int iDst = cSuArgs;
    13141502                    papszArgs[iDst++] = argv[0];
    13151503                    papszArgs[iDst++] = "--stdout";
     
    13241512                     * Do the platform specific process execution (waiting included).
    13251513                     */
    1326                     rcExit = RelaunchElevatedNative(szExecPath, cArgs, papszArgs);
     1514                    rcExit = RelaunchElevatedNative(szExecPath, papszArgs, cSuArgs, cArgs, iCmd);
    13271515
    13281516                    /*
     
    15031691    static const RTGETOPTDEF s_aOptions[] =
    15041692    {
    1505 #define CMD_INSTALL     1000
    15061693        { "install",    CMD_INSTALL,    RTGETOPT_REQ_NOTHING },
    1507 #define CMD_UNINSTALL   1001
    15081694        { "uninstall",  CMD_UNINSTALL,  RTGETOPT_REQ_NOTHING },
    1509 #define CMD_CLEANUP     1002
    15101695        { "cleanup",    CMD_CLEANUP,    RTGETOPT_REQ_NOTHING },
    15111696#ifdef WITH_ELEVATION
    1512 # define OPT_ELEVATED    1090
    15131697        { "--elevated", OPT_ELEVATED,   RTGETOPT_REQ_NOTHING },
    1514 # define OPT_STDOUT      1091
    15151698        { "--stdout",   OPT_STDOUT,     RTGETOPT_REQ_STRING  },
    1516 # define OPT_STDERR      1092
    15171699        { "--stderr",   OPT_STDERR,     RTGETOPT_REQ_STRING  },
    15181700#endif
     
    15371719#ifdef WITH_ELEVATION
    15381720                if (!fElevated)
    1539                     return RelaunchElevated(argc, argv);
     1721                    return RelaunchElevated(argc, argv, ch);
    15401722#endif
    15411723                int         cCmdargs     = argc - GetState.iNext;
Note: See TracChangeset for help on using the changeset viewer.

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