Changeset 35204 in vbox
- Timestamp:
- Dec 16, 2010 5:59:42 PM (14 years ago)
- Location:
- trunk/src/VBox
- Files:
-
- 3 edited
-
Installer/linux/install.sh (modified) (1 diff)
-
Installer/solaris/makepackage.sh (modified) (1 diff)
-
Main/VBoxExtPackHelperApp.cpp (modified) (15 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Installer/linux/install.sh
r34679 r35204 354 354 test -e $INSTALLATION_DIR/VBoxHeadless && chmod 4511 $INSTALLATION_DIR/VBoxHeadless 355 355 test -e $INSTALLATION_DIR/VBoxNetDHCP && chmod 4511 $INSTALLATION_DIR/VBoxNetDHCP 356 test -e $INSTALLATION_DIR/VBoxExtPackHelperApp && chmod 4511 $INSTALLATION_DIR/VBoxExtPackHelperApp357 356 358 357 ln -sf $INSTALLATION_DIR/VBoxVMM.so $INSTALLATION_DIR/components/VBoxVMM.so -
trunk/src/VBox/Installer/solaris/makepackage.sh
r35054 r35204 208 208 || $3 == "opt/VirtualBox/amd64/VBoxNetDHCP" \ 209 209 || $3 == "opt/VirtualBox/i386/VBoxNetDHCP" \ 210 || $3 == "opt/VirtualBox/amd64/VBoxExtPackHelperApp" \211 || $3 == "opt/VirtualBox/i386/VBoxExtPackHelperApp" \212 210 ) \ 213 211 { $4 = "4755" } { print }' prototype > prototype2 -
trunk/src/VBox/Main/VBoxExtPackHelperApp.cpp
r35188 r35204 24 24 #include <iprt/buildconfig.h> 25 25 #include <iprt/dir.h> 26 #include <iprt/env.h> 26 27 #include <iprt/file.h> 27 28 #include <iprt/fs.h> … … 44 45 #include <VBox/version.h> 45 46 46 #if defined(RT_OS_DARWIN)47 # include <sys/types.h>48 # include <unistd.h> /* geteuid */49 #endif50 51 47 #ifdef RT_OS_WINDOWS 52 48 # define _WIN32_WINNT 0x0501 … … 64 60 #endif 65 61 66 #if defined(RT_OS_DARWIN) || defined(RT_OS_WINDOWS)62 #if !defined(RT_OS_OS2) 67 63 # include <stdio.h> 68 64 # include <errno.h> 65 # if !defined(RT_OS_WINDOWS) 66 # include <sys/types.h> 67 # include <unistd.h> /* geteuid */ 68 # endif 69 69 #endif 70 70 … … 74 74 *******************************************************************************/ 75 75 /** 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) 77 77 # define WITH_ELEVATION 78 78 #endif 79 79 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 /** @} */ 80 92 81 93 … … 1048 1060 #ifdef WITH_ELEVATION 1049 1061 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 */ 1072 static 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 1050 1110 /** 1051 1111 * Copies the content of a file to a stream. … … 1091 1151 * @returns Program exit code. 1092 1152 * @param pszExecPath The executable path. 1093 * @param cArgs The number of arguments.1094 1153 * @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 */ 1160 static RTEXITCODE RelaunchElevatedNative(const char *pszExecPath, const char **papszArgs, int cSuArgs, int cMyArgs, 1161 int iCmd) 1097 1162 { 1098 1163 RTEXITCODE rcExit = RTEXITCODE_FAILURE; 1099 1164 #ifdef RT_OS_WINDOWS 1165 NOREF(iCmd); 1100 1166 1101 1167 CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE); … … 1111 1177 { 1112 1178 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); 1114 1180 if (RT_SUCCESS(rc)) 1115 1181 { … … 1198 1264 AuthorizationRights AuthRights = { 1, &AuthItem }; 1199 1265 1266 NOREF(iCmd); 1200 1267 static char s_szPrompt[] = "VirtualBox needs further rights to make changes to your installation.\n\n"; 1201 1268 AuthorizationItem aAuthEnvItems[] = … … 1217 1284 FILE *pSocketStrm; 1218 1285 orc = AuthorizationExecuteWithPrivileges(AuthRef, pszExecPath, kAuthorizationFlagDefaults, 1219 (char * const *)&papszArgs[ 3],1286 (char * const *)&papszArgs[cSuArgs + 3], 1220 1287 &pSocketStrm); 1221 1288 if (orc == errAuthorizationSuccess) … … 1248 1315 1249 1316 #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 1251 1437 #endif 1252 1438 return rcExit; … … 1260 1446 * @param argc The number of arguments. 1261 1447 * @param argv The arguments. 1262 */ 1263 static RTEXITCODE RelaunchElevated(int argc, char **argv) 1448 * @param iCmd The command that is being executed. 1449 */ 1450 static RTEXITCODE RelaunchElevated(int argc, char **argv, int iCmd) 1264 1451 { 1265 1452 /* … … 1307 1494 * change the order here. 1308 1495 */ 1496 int const cSuArgs = 10; 1309 1497 int cArgs = argc + 5 + 1; 1310 char const **papszArgs = (char const **)RTMemTmpAllocZ((c Args + 1) * sizeof(const char *));1498 char const **papszArgs = (char const **)RTMemTmpAllocZ((cSuArgs + cArgs + 1) * sizeof(const char *)); 1311 1499 if (papszArgs) 1312 1500 { 1313 int iDst = 0;1501 int iDst = cSuArgs; 1314 1502 papszArgs[iDst++] = argv[0]; 1315 1503 papszArgs[iDst++] = "--stdout"; … … 1324 1512 * Do the platform specific process execution (waiting included). 1325 1513 */ 1326 rcExit = RelaunchElevatedNative(szExecPath, cArgs, papszArgs);1514 rcExit = RelaunchElevatedNative(szExecPath, papszArgs, cSuArgs, cArgs, iCmd); 1327 1515 1328 1516 /* … … 1503 1691 static const RTGETOPTDEF s_aOptions[] = 1504 1692 { 1505 #define CMD_INSTALL 10001506 1693 { "install", CMD_INSTALL, RTGETOPT_REQ_NOTHING }, 1507 #define CMD_UNINSTALL 10011508 1694 { "uninstall", CMD_UNINSTALL, RTGETOPT_REQ_NOTHING }, 1509 #define CMD_CLEANUP 10021510 1695 { "cleanup", CMD_CLEANUP, RTGETOPT_REQ_NOTHING }, 1511 1696 #ifdef WITH_ELEVATION 1512 # define OPT_ELEVATED 10901513 1697 { "--elevated", OPT_ELEVATED, RTGETOPT_REQ_NOTHING }, 1514 # define OPT_STDOUT 10911515 1698 { "--stdout", OPT_STDOUT, RTGETOPT_REQ_STRING }, 1516 # define OPT_STDERR 10921517 1699 { "--stderr", OPT_STDERR, RTGETOPT_REQ_STRING }, 1518 1700 #endif … … 1537 1719 #ifdef WITH_ELEVATION 1538 1720 if (!fElevated) 1539 return RelaunchElevated(argc, argv );1721 return RelaunchElevated(argc, argv, ch); 1540 1722 #endif 1541 1723 int cCmdargs = argc - GetState.iNext;
Note:
See TracChangeset
for help on using the changeset viewer.

