VirtualBox

Changeset 55531 in vbox for trunk/src/VBox/Additions


Ignore:
Timestamp:
Apr 29, 2015 6:06:09 PM (10 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
99890
Message:

Main,VBoxService: Added ProcessCreateFlag_UnquotedArguments.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Additions/common/VBoxService/VBoxServiceControlProcess.cpp

    r51205 r55531  
    10651065 * @param  pszArgv0         First argument (argv0), either original or modified version.  Optional.
    10661066 * @param  papszArgs        Original argv command line from the host, starting at argv[1].
     1067 * @param  fFlags           The process creation flags pass to us from the host.
    10671068 * @param  ppapszArgv       Pointer to a pointer with the new argv command line.
    10681069 *                          Needs to be freed with RTGetOptArgvFree.
    10691070 */
    1070 static int gstcntlProcessAllocateArgv(const char *pszArgv0,
    1071                                       const char * const *papszArgs,
    1072                                       bool fExpandArgs, char ***ppapszArgv)
     1071static int gstcntlProcessAllocateArgv(const char *pszArgv0, const char * const *papszArgs, uint32_t fFlags,
     1072                                      char ***ppapszArgv)
    10731073{
    10741074    AssertPtrReturn(ppapszArgv, VERR_INVALID_POINTER);
    10751075
    1076     VBoxServiceVerbose(3, "GstCntlProcessPrepareArgv: pszArgv0=%p, papszArgs=%p, fExpandArgs=%RTbool, ppapszArgv=%p\n",
    1077                        pszArgv0, papszArgs, fExpandArgs, ppapszArgv);
     1076    VBoxServiceVerbose(3, "GstCntlProcessPrepareArgv: pszArgv0=%p, papszArgs=%p, fFlags=%#x, ppapszArgv=%p\n",
     1077                       pszArgv0, papszArgs, fFlags, ppapszArgv);
    10781078
    10791079    int rc = VINF_SUCCESS;
     
    10961096#endif
    10971097
    1098     size_t i = 0; /* Keep the argument counter in scope for cleaning up on failure. */
    1099 
    1100     rc = RTStrDupEx(&papszNewArgv[0], pszArgv0);
     1098
     1099    /* HACK ALERT! Since we still don't allow the user to really specify the first
     1100                   argument separately from the executable image, we have to fudge
     1101                   a little in the unquoted argument case to deal with executables
     1102                   containing spaces. */
     1103    /** @todo Fix the stupid host/guest protocol so the user can do this for us! */
     1104    if (   !(fFlags & EXECUTEPROCESSFLAG_UNQUOTED_ARGS)
     1105        || !strpbrk(pszArgv0, " \t\n\r")
     1106        || pszArgv0[0] == '"')
     1107        rc = RTStrDupEx(&papszNewArgv[0], pszArgv0);
     1108    else
     1109    {
     1110        size_t cchArgv0 = strlen(pszArgv0);
     1111        rc = RTStrAllocEx(&papszNewArgv[0], 1 + cchArgv0 + 1 + 1);
     1112        if (RT_SUCCESS(rc))
     1113        {
     1114            char *pszDst = papszNewArgv[0];
     1115            *pszDst++ = '"';
     1116            memcpy(pszDst, pszArgv0, cchArgv0);
     1117            pszDst += cchArgv0;
     1118            *pszDst++ = '"';
     1119            *pszDst   = '\0';
     1120        }
     1121    }
    11011122    if (RT_SUCCESS(rc))
    11021123    {
    1103         for (; i < cArgs; i++)
     1124        size_t i;
     1125        for (i = 0; i < cArgs; i++)
    11041126        {
    11051127            char *pszArg;
    11061128#if 0 /* Arguments expansion -- untested. */
    1107             if (fExpandArgs)
    1108             {
     1129            if (fFlags & EXECUTEPROCESSFLAG_EXPAND_ARGUMENTS)
     1130            {
     1131/** @todo r=bird: If you want this, we need a generic implementation, preferably in RTEnv or somewhere like that.  The marking
     1132 * up of the variables must be the same on all platforms.  */
    11091133                /* According to MSDN the limit on older Windows version is 32K, whereas
    11101134                 * Vista+ there are no limits anymore. We still stick to 4K. */
     
    11361160
    11371161            *ppapszArgv = papszNewArgv;
    1138         }
    1139     }
    1140 
    1141     if (RT_FAILURE(rc))
    1142     {
    1143         for (i; i > 0; i--)
     1162            return VINF_SUCCESS;
     1163        }
     1164
     1165        /* Failed, bail out. */
     1166        for (; i > 0; i--)
    11441167            RTStrFree(papszNewArgv[i]);
    1145         RTMemFree(papszNewArgv);
    1146     }
    1147 
     1168    }
     1169    RTMemFree(papszNewArgv);
    11481170    return rc;
    11491171}
     
    12391261    char szExecExp[RTPATH_MAX];
    12401262
    1241     /* Do we need to expand environment variables in arguments? */
    1242     bool fExpandArgs = (fFlags & EXECUTEPROCESSFLAG_EXPAND_ARGUMENTS) ? true  : false;
    1243 
    12441263#ifdef RT_OS_WINDOWS
    12451264    /*
     
    12951314        {
    12961315            char **papszArgsExp;
    1297             rc = gstcntlProcessAllocateArgv(szSysprepCmd /* argv0 */, papszArgs,
    1298                                             fExpandArgs, &papszArgsExp);
     1316            rc = gstcntlProcessAllocateArgv(szSysprepCmd /* argv0 */, papszArgs, fFlags, &papszArgsExp);
    12991317            if (RT_SUCCESS(rc))
    13001318            {
     
    13361354    {
    13371355        char **papszArgsExp;
     1356        /** @todo r-bird: pszExec != argv[0]! When are you going to get that?!? How many
     1357         * times does this need to be pointed out?  HOST/GUEST INTERFACE IS MISDESIGNED! */
    13381358        rc = gstcntlProcessAllocateArgv(pszExec /* Always use the unmodified executable name as argv0. */,
    13391359                                        papszArgs /* Append the rest of the argument vector (if any). */,
    1340                                         fExpandArgs, &papszArgsExp);
     1360                                        fFlags, &papszArgsExp);
    13411361        if (RT_FAILURE(rc))
    13421362        {
     
    13531373                if (fFlags & EXECUTEPROCESSFLAG_NO_PROFILE)
    13541374                    uProcFlags |= RTPROC_FLAGS_NO_PROFILE;
     1375                if (fFlags & EXECUTEPROCESSFLAG_UNQUOTED_ARGS)
     1376                    uProcFlags |= RTPROC_FLAGS_UNQUOTED_ARGS;
    13551377            }
    13561378
     
    15911613                                bool fNeedsImpersonation = !(pProcess->pSession->uFlags & VBOXSERVICECTRLSESSION_FLAG_FORK);
    15921614
    1593                                 rc = gstcntlProcessCreateProcess(pProcess->StartupInfo.szCmd, papszArgs, hEnv, pProcess->StartupInfo.uFlags,
     1615                                rc = gstcntlProcessCreateProcess(pProcess->StartupInfo.szCmd, papszArgs, hEnv,
     1616                                                                 pProcess->StartupInfo.uFlags,
    15941617                                                                 phStdIn, phStdOut, phStdErr,
    15951618                                                                 fNeedsImpersonation ? pProcess->StartupInfo.szUser : NULL,
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