Skip to content

Instantly share code, notes, and snippets.

@specialunderwear
Created November 22, 2011 23:54
Show Gist options
  • Save specialunderwear/1387485 to your computer and use it in GitHub Desktop.
Save specialunderwear/1387485 to your computer and use it in GitHub Desktop.
unsafe
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