File: zenmap_auth.m

package info (click to toggle)
nmap 7.93%2Bdfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 44,552 kB
  • sloc: cpp: 60,990; ansic: 30,785; python: 17,679; xml: 11,558; sh: 11,320; perl: 2,679; makefile: 1,000; java: 45; objc: 43
file content (47 lines) | stat: -rw-r--r-- 1,814 bytes parent folder | download | duplicates (3)
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
40
41
42
43
44
45
46
47
//
//  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(@"Failed to execute applescript with admin privileges, trying without.");
            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(@"Failed to execute applescript at all.");
            }
        }
    }
    return 0;
}