1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
| #import <Foundation/Foundation.h>
// Add Security.framework to the Xcode project
int main (int argc, const char * argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
// Create authorization reference
AuthorizationRef authorizationRef;
OSStatus status;
status = AuthorizationCreate(NULL, kAuthorizationEmptyEnvironment, kAuthorizationFlagDefaults, &authorizationRef);
// Run the tool using the authorization reference
// char *tool = "/sbin/dmesg";
// char *args[] = {NULL};
char *tool = "/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport";
char *args[] = {"-z"};
FILE *pipe = NULL;
status = AuthorizationExecuteWithPrivileges(authorizationRef, tool, kAuthorizationFlagDefaults, args, &pipe);
// Print to standard output
char readBuffer[128];
if (status == errAuthorizationSuccess) {
for (;;) {
int bytesRead = read(fileno(pipe), readBuffer, sizeof(readBuffer));
if (bytesRead < 1) break;
write(fileno(stdout), readBuffer, bytesRead);
}
} else {
NSLog(@"Authorization Result Code: %d", status);
}
[pool drain];
return 0;
} |
Partager