Fix ProcessUtils compilation on Mac

* Enable the Security framework
 * Fix variable names in ProcessUtils::runElevatedMac()
This commit is contained in:
Robert Knight 2011-08-22 14:20:26 +01:00
parent 4bcf379839
commit 9516887d48
2 changed files with 22 additions and 9 deletions

View file

@ -43,6 +43,14 @@ add_executable(updater
main.cpp main.cpp
) )
if(APPLE)
set_target_properties(
updater
PROPERTIES LINK_FLAGS "-framework Security"
)
endif()
target_link_libraries(updater target_link_libraries(updater
updatershared updatershared
) )

View file

@ -17,6 +17,10 @@
#include <errno.h> #include <errno.h>
#endif #endif
#ifdef PLATFORM_MAC
#include <Security/Security.h>
#endif
int ProcessUtils::runSync(const std::string& executable, int ProcessUtils::runSync(const std::string& executable,
const std::list<std::string>& args) const std::list<std::string>& args)
{ {
@ -163,22 +167,23 @@ void ProcessUtils::runElevatedMac(const std::string& executable,
if (status == errAuthorizationSuccess) if (status == errAuthorizationSuccess)
{ {
char** args; char** argv;
args = (char**) malloc(sizeof(char*) * arguments.count() + 1); argv = (char**) malloc(sizeof(char*) * args.size() + 1);
int i; int i = 0;
for (i = 0; i < arguments.size(); i++) for (std::list<std::string>::const_iterator iter = args.begin(); iter != args.end(); iter++)
{ {
args[i] = strdup(arguments[i].c_str()); argv[i] = strdup(iter->c_str());
++i;
} }
args[i] = NULL; argv[i] = NULL;
FILE* pipe = NULL; FILE* pipe = NULL;
char* tool = strdup(executable.c_str()); char* tool = strdup(executable.c_str());
status = AuthorizationExecuteWithPrivileges(authorizationRef, tool, status = AuthorizationExecuteWithPrivileges(authorizationRef, tool,
kAuthorizationFlagDefaults, args, &pipe); kAuthorizationFlagDefaults, argv, &pipe);
if (status == errAuthorizationSuccess) if (status == errAuthorizationSuccess)
{ {
@ -224,9 +229,9 @@ void ProcessUtils::runElevatedMac(const std::string& executable,
// If we want to know more information about what has happened: // If we want to know more information about what has happened:
// http://developer.apple.com/mac/library/documentation/Security/Reference/authorization_ref/Reference/reference.html#//apple_ref/doc/uid/TP30000826-CH4g-CJBEABHG // http://developer.apple.com/mac/library/documentation/Security/Reference/authorization_ref/Reference/reference.html#//apple_ref/doc/uid/TP30000826-CH4g-CJBEABHG
free(tool); free(tool);
for (i = 0; i < arguments.count(); i++) for (i = 0; i < args.size(); i++)
{ {
free(args[i]); free(argv[i]);
} }
} }
else else