Created
November 22, 2011 23:54
-
-
Save specialunderwear/1387485 to your computer and use it in GitHub Desktop.
unsafe
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
AuthorizationRef authorizationRef; | |
OSStatus status; | |
status = AuthorizationCreate(NULL, kAuthorizationEmptyEnvironment, | |
kAuthorizationFlagDefaults, &authorizationRef); | |
// suppose we've got the new hosts file in an NSString called new_hosts_file | |
NSString *overwrite_hosts = [NSString stringWithFormat:@"echo %s > /private/etc/hosts", new_hosts_file]; | |
char *args[] = {[overwrite_hosts cstring]}; | |
status = AuthorizationExecuteWithPrivileges(authorizationRef, "/bin/sh", | |
kAuthorizationFlagDefaults, args, NULL); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment