Changeset 55531 in vbox for trunk/src/VBox/Additions
- Timestamp:
- Apr 29, 2015 6:06:09 PM (10 years ago)
- svn:sync-xref-src-repo-rev:
- 99890
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Additions/common/VBoxService/VBoxServiceControlProcess.cpp
r51205 r55531 1065 1065 * @param pszArgv0 First argument (argv0), either original or modified version. Optional. 1066 1066 * @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. 1067 1068 * @param ppapszArgv Pointer to a pointer with the new argv command line. 1068 1069 * Needs to be freed with RTGetOptArgvFree. 1069 1070 */ 1070 static int gstcntlProcessAllocateArgv(const char *pszArgv0, 1071 const char * const *papszArgs, 1072 bool fExpandArgs, char ***ppapszArgv) 1071 static int gstcntlProcessAllocateArgv(const char *pszArgv0, const char * const *papszArgs, uint32_t fFlags, 1072 char ***ppapszArgv) 1073 1073 { 1074 1074 AssertPtrReturn(ppapszArgv, VERR_INVALID_POINTER); 1075 1075 1076 VBoxServiceVerbose(3, "GstCntlProcessPrepareArgv: pszArgv0=%p, papszArgs=%p, f ExpandArgs=%RTbool, ppapszArgv=%p\n",1077 pszArgv0, papszArgs, f ExpandArgs, ppapszArgv);1076 VBoxServiceVerbose(3, "GstCntlProcessPrepareArgv: pszArgv0=%p, papszArgs=%p, fFlags=%#x, ppapszArgv=%p\n", 1077 pszArgv0, papszArgs, fFlags, ppapszArgv); 1078 1078 1079 1079 int rc = VINF_SUCCESS; … … 1096 1096 #endif 1097 1097 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 } 1101 1122 if (RT_SUCCESS(rc)) 1102 1123 { 1103 for (; i < cArgs; i++) 1124 size_t i; 1125 for (i = 0; i < cArgs; i++) 1104 1126 { 1105 1127 char *pszArg; 1106 1128 #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. */ 1109 1133 /* According to MSDN the limit on older Windows version is 32K, whereas 1110 1134 * Vista+ there are no limits anymore. We still stick to 4K. */ … … 1136 1160 1137 1161 *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--) 1144 1167 RTStrFree(papszNewArgv[i]); 1145 RTMemFree(papszNewArgv); 1146 } 1147 1168 } 1169 RTMemFree(papszNewArgv); 1148 1170 return rc; 1149 1171 } … … 1239 1261 char szExecExp[RTPATH_MAX]; 1240 1262 1241 /* Do we need to expand environment variables in arguments? */1242 bool fExpandArgs = (fFlags & EXECUTEPROCESSFLAG_EXPAND_ARGUMENTS) ? true : false;1243 1244 1263 #ifdef RT_OS_WINDOWS 1245 1264 /* … … 1295 1314 { 1296 1315 char **papszArgsExp; 1297 rc = gstcntlProcessAllocateArgv(szSysprepCmd /* argv0 */, papszArgs, 1298 fExpandArgs, &papszArgsExp); 1316 rc = gstcntlProcessAllocateArgv(szSysprepCmd /* argv0 */, papszArgs, fFlags, &papszArgsExp); 1299 1317 if (RT_SUCCESS(rc)) 1300 1318 { … … 1336 1354 { 1337 1355 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! */ 1338 1358 rc = gstcntlProcessAllocateArgv(pszExec /* Always use the unmodified executable name as argv0. */, 1339 1359 papszArgs /* Append the rest of the argument vector (if any). */, 1340 f ExpandArgs, &papszArgsExp);1360 fFlags, &papszArgsExp); 1341 1361 if (RT_FAILURE(rc)) 1342 1362 { … … 1353 1373 if (fFlags & EXECUTEPROCESSFLAG_NO_PROFILE) 1354 1374 uProcFlags |= RTPROC_FLAGS_NO_PROFILE; 1375 if (fFlags & EXECUTEPROCESSFLAG_UNQUOTED_ARGS) 1376 uProcFlags |= RTPROC_FLAGS_UNQUOTED_ARGS; 1355 1377 } 1356 1378 … … 1591 1613 bool fNeedsImpersonation = !(pProcess->pSession->uFlags & VBOXSERVICECTRLSESSION_FLAG_FORK); 1592 1614 1593 rc = gstcntlProcessCreateProcess(pProcess->StartupInfo.szCmd, papszArgs, hEnv, pProcess->StartupInfo.uFlags, 1615 rc = gstcntlProcessCreateProcess(pProcess->StartupInfo.szCmd, papszArgs, hEnv, 1616 pProcess->StartupInfo.uFlags, 1594 1617 phStdIn, phStdOut, phStdErr, 1595 1618 fNeedsImpersonation ? pProcess->StartupInfo.szUser : NULL,
Note:
See TracChangeset
for help on using the changeset viewer.