Changeset 34723 in vbox for trunk/src/VBox/Main
- Timestamp:
- Dec 5, 2010 3:08:35 AM (14 years ago)
- Location:
- trunk/src/VBox/Main
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/Makefile.kmk
r34713 r34723 739 739 PROGRAMS += VBoxExtPackHelperApp 740 740 VBoxExtPackHelperApp_TEMPLATE = VBoxR3SetUidToRoot 741 VBoxExtPackHelperApp_LDFLAGS.darwin = -framework Security 741 742 VBoxExtPackHelperApp_LDFLAGS.win = /SUBSYSTEM:windows 742 743 VBoxExtPackHelperApp_SOURCES = \ -
trunk/src/VBox/Main/VBoxExtPackHelperApp.cpp
r34713 r34723 55 55 #endif 56 56 57 #ifdef RT_OS_DARWIN 58 # include <Security/Authorization.h> 59 # include <Security/AuthorizationTags.h> 60 # include <CoreFoundation/CoreFoundation.h> 61 #endif 62 57 63 #if defined(RT_OS_DARWIN) || defined(RT_OS_WINDOWS) 58 64 # include <stdio.h> … … 64 70 * Defined Constants And Macros * 65 71 *******************************************************************************/ 66 /* Enable elevation on windows and darwin. */67 #if defined(RT_OS_WINDOWS) 72 /** Enable elevation on Windows and Darwin. */ 73 #if defined(RT_OS_WINDOWS) || defined(RT_OS_DARWIN) || defined(DOXYGEN_RUNNING) 68 74 # define WITH_ELEVATION 69 75 #endif … … 471 477 return rcExit; 472 478 } 479 473 480 474 481 /** … … 1540 1547 RTMsgError("RTStrToUtf16 failed: %Rc", rc); 1541 1548 1549 #elif defined(RT_OS_DARWIN) 1550 char szIconName[RTPATH_MAX]; 1551 int rc = RTPathAppPrivateArch(szIconName, sizeof(szIconName)); 1552 if (RT_SUCCESS(rc)) 1553 rc = RTPathAppend(szIconName, sizeof(szIconName), "../Resources/virtualbox-vbox-128px.png"); 1554 if (RT_FAILURE(rc)) 1555 return RTMsgErrorExit(RTEXITCODE_FAILURE, "Failed to construct icon path: %Rrc", rc); 1556 1557 AuthorizationRef AuthRef; 1558 OSStatus orc = AuthorizationCreate(NULL, 0, kAuthorizationFlagDefaults, &AuthRef); 1559 if (orc == errAuthorizationSuccess) 1560 { 1561 /* 1562 * Preautorize the privileged execution of ourselves. 1563 */ 1564 AuthorizationItem AuthItem = { kAuthorizationRightExecute, 0, NULL, 0 }; 1565 AuthorizationRights AuthRights = { 1, &AuthItem }; 1566 1567 static char s_szPrompt[] = "VirtualBox needs further rights to make changes to your installation.\n\n"; 1568 AuthorizationItem aAuthEnvItems[] = 1569 { 1570 { kAuthorizationEnvironmentPrompt, strlen(s_szPrompt), s_szPrompt, 0 }, 1571 { kAuthorizationEnvironmentIcon, strlen(szIconName), szIconName, 0 } 1572 }; 1573 AuthorizationEnvironment AuthEnv = { RT_ELEMENTS(aAuthEnvItems), aAuthEnvItems }; 1574 1575 orc = AuthorizationCopyRights(AuthRef, &AuthRights, &AuthEnv, 1576 kAuthorizationFlagPreAuthorize | kAuthorizationFlagInteractionAllowed 1577 | kAuthorizationFlagExtendRights, 1578 NULL); 1579 if (orc == errAuthorizationSuccess) 1580 { 1581 /* 1582 * Execute with extra permissions 1583 */ 1584 FILE *pSocketStrm; 1585 orc = AuthorizationExecuteWithPrivileges(AuthRef, pszExecPath, kAuthorizationFlagDefaults, 1586 (char * const *)&papszArgs[3], 1587 &pSocketStrm); 1588 if (orc == errAuthorizationSuccess) 1589 { 1590 /* 1591 * Read the output of the tool, the read will fail when it quits. 1592 */ 1593 for (;;) 1594 { 1595 char achBuf[1024]; 1596 size_t cbRead = fread(achBuf, 1, sizeof(achBuf), pSocketStrm); 1597 if (!cbRead) 1598 break; 1599 fwrite(achBuf, 1, cbRead, stdout); 1600 } 1601 rcExit = RTEXITCODE_SUCCESS; 1602 } 1603 else 1604 RTMsgError("AuthorizationExecuteWithPrivileges failed: %d", orc); 1605 } 1606 else if (orc == errAuthorizationCanceled) 1607 RTMsgError("Authorization canceled by the user"); 1608 else 1609 RTMsgError("AuthorizationCopyRights failed: %d", orc); 1610 AuthorizationFree(AuthRef, kAuthorizationFlagDefaults); 1611 } 1612 else 1613 RTMsgError("AuthorizationCreate failed: %d", orc); 1614 1542 1615 #else 1543 1616 # error "PORT ME" … … 1597 1670 /* 1598 1671 * Insert the --elevated and stdout/err names into the argument 1599 * list. 1672 * list. Note that darwin skips the --stdout bit, so don't 1673 * change the order here. 1600 1674 */ 1601 1675 int cArgs = argc + 5 + 1; … … 1603 1677 if (papszArgs) 1604 1678 { 1605 papszArgs[0] = argv[0]; 1606 papszArgs[1] = "--elevated"; 1607 papszArgs[2] = "--stdout"; 1608 papszArgs[3] = szStdOut; 1609 papszArgs[4] = "--stderr"; 1610 papszArgs[5] = szStdErr; 1611 for (int i = 1; i <= argc; i++) 1612 papszArgs[i + 5] = argv[i]; 1679 int iDst = 0; 1680 papszArgs[iDst++] = argv[0]; 1681 papszArgs[iDst++] = "--stdout"; 1682 papszArgs[iDst++] = szStdOut; 1683 papszArgs[iDst++] = "--stderr"; 1684 papszArgs[iDst++] = szStdErr; 1685 papszArgs[iDst++] = "--elevated"; 1686 for (int iSrc = 1; iSrc <= argc; iSrc++) 1687 papszArgs[iDst++] = argv[iSrc]; 1613 1688 1614 1689 /* … … 1702 1777 */ 1703 1778 char szExecPath[RTPATH_MAX]; 1704 int rc = RTProcGetExecutablePath(szExecPath,sizeof(szExecPath)); 1779 if (RTProcGetExecutablePath(szExecPath, sizeof(szExecPath)) == NULL) 1780 { 1781 RTMsgError("RTProcGetExecutablePath failed"); 1782 return false; 1783 } 1784 1785 RTFSOBJINFO ObjInfo; 1786 int rc = RTPathQueryInfoEx(szExecPath, &ObjInfo, RTFSOBJATTRADD_UNIX, RTPATH_F_ON_LINK); 1705 1787 if (RT_FAILURE(rc)) 1706 1788 { … … 1709 1791 } 1710 1792 1711 RTFSOBJINFO ObjInfo; 1712 rc = RTPathQueryInfoEx(szExecPath, &ObjInfo, RTFSOBJATTRADD_UNIX, RTPATH_F_ON_LINK); 1713 if (RT_FAILURE(rc) 1714 { 1715 RTMsgError("RTProcGetExecutablePath failed: %Rrc", rc); 1716 return false; 1717 } 1718 1719 RTUID uid = geteuid(); 1720 return uid == ObjInfo.Attr.u.Unix.Uid; 1793 return ObjInfo.Attr.u.Unix.uid == geteuid() 1794 || ObjInfo.Attr.u.Unix.uid == getuid(); 1721 1795 # endif 1722 1796 }
Note:
See TracChangeset
for help on using the changeset viewer.