diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 07:42:04 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 07:42:04 +0000 |
commit | 0d47952611198ef6b1163f366dc03922d20b1475 (patch) | |
tree | 3d840a3b8c0daef0754707bfb9f5e873b6b1ac13 /zenmap/install_scripts/macosx/zenmap_auth.m | |
parent | Initial commit. (diff) | |
download | nmap-0d47952611198ef6b1163f366dc03922d20b1475.tar.xz nmap-0d47952611198ef6b1163f366dc03922d20b1475.zip |
Adding upstream version 7.94+git20230807.3be01efb1+dfsg.upstream/7.94+git20230807.3be01efb1+dfsgupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'zenmap/install_scripts/macosx/zenmap_auth.m')
-rw-r--r-- | zenmap/install_scripts/macosx/zenmap_auth.m | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/zenmap/install_scripts/macosx/zenmap_auth.m b/zenmap/install_scripts/macosx/zenmap_auth.m new file mode 100644 index 0000000..b42e568 --- /dev/null +++ b/zenmap/install_scripts/macosx/zenmap_auth.m @@ -0,0 +1,49 @@ +// +// 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 \"%@\" with administrator privileges", executable_path]; +NSLog(@"Executing: >>%@<<", script); + NSAppleScript *appleScript = [[NSAppleScript alloc] initWithSource:script]; + if ([appleScript executeAndReturnError:&error]) { + NSLog(@"success!"); + } else { + NSLog(@"Failed to execute applescript with admin privileges: %@", error[@"NSAppleScriptErrorMessage"]); + NSDictionary *error = [NSDictionary new]; + NSString *script = [NSString stringWithFormat:@"do shell script \"%@\"", executable_path]; +NSLog(@"Executing: >>%@<<", script); + NSAppleScript *appleScript = [[NSAppleScript alloc] initWithSource:script]; + if ([appleScript executeAndReturnError:&error]) { + NSLog(@"success!"); + } else { + NSLog(@"Failed to execute applescript: %@", error[@"NSAppleScriptErrorMessage"]); + } + } + } + return 0; +} |