1
0
mirror of https://github.com/nmap/nmap.git synced 2025-12-08 05:31:31 +00:00
Files
nmap/zenmap/install_scripts/macosx/zenmap_auth.m
2016-07-27 10:29:20 +00:00

48 lines
1.7 KiB
Objective-C

//
// zenmap_auth.m
// Objective-C
//
// This program attempts to run an applescript script which asks for root
// privileges. If the authorization fails or is canceled, Zenmap is run
// without privileges using applescript.
//
// This program is the first link in the chain:
// zenmap_auth -> zenmap_wrapper.py -> zenmap.bin
//
#import <Foundation/Foundation.h>
#import <libgen.h>
#define EXECUTABLE_NAME "zenmap.bin"
int main(int argc, const char * argv[]) {
@autoreleasepool {
NSString *executable_path;
NSString *cwd;
size_t len_cwd;
cwd = [[NSBundle mainBundle] bundlePath];
len_cwd = [cwd length];
executable_path = cwd;
executable_path = [NSString stringWithFormat:@"%@/Contents/MacOS/%s", executable_path, EXECUTABLE_NAME];
NSLog(@"%@",executable_path);
NSDictionary *error = [NSDictionary new];
NSString *script = [NSString stringWithFormat:@"do shell script \"%@ %s\" with administrator privileges", executable_path, (char*)argv];
NSAppleScript *appleScript = [[NSAppleScript alloc] initWithSource:script];
if ([appleScript executeAndReturnError:&error]) {
NSLog(@"success!");
} else {
NSLog(@"failure!");
NSDictionary *error = [NSDictionary new];
NSString *script = [NSString stringWithFormat:@"do shell script \"%@ %s\"", executable_path, (char*)argv];
NSAppleScript *appleScript = [[NSAppleScript alloc] initWithSource:script];
if ([appleScript executeAndReturnError:&error]) {
NSLog(@"success!");
} else {
NSLog(@"total failure!");
}
}
}
return 0;
}