diff --git a/Installer/Helper/HelperInterface.m b/Installer/Helper/HelperInterface.m index 4fc8e5c..123b7ab 100644 --- a/Installer/Helper/HelperInterface.m +++ b/Installer/Helper/HelperInterface.m @@ -242,7 +242,7 @@ bail: if(YES != [defaultManager copyItemAtPath:app toPath:appCopy error:&error]) { //err msg - os_log_error(logHandle, "ERROR: failed to copy %@ to %@ (error: %@)", app, appCopy, error.description); + os_log_error(logHandle, "ERROR: failed to copy %{public}@ to %{public}@ (error: %@)", app, appCopy, error.description); //bail goto bail; diff --git a/Installer/Source/Configure.m b/Installer/Source/Configure.m index 68291eb..c58c41b 100644 --- a/Installer/Source/Configure.m +++ b/Installer/Source/Configure.m @@ -399,7 +399,7 @@ bail: if(YES != [NSFileManager.defaultManager copyItemAtPath:applicationSrc toPath:applicationDest error:&error]) { //err msg - os_log_error(logHandle, "ERROR: failed to copy %@ -> %@ (error: %@)", applicationSrc, applicationDest, error); + os_log_error(logHandle, "ERROR: failed to copy %{public}@ -> %{public}@ (error: %@)", applicationSrc, applicationDest, error); //bail goto bail; diff --git a/Installer/Source/main.m b/Installer/Source/main.m index 9d8de08..f44de50 100644 --- a/Installer/Source/main.m +++ b/Installer/Source/main.m @@ -36,6 +36,16 @@ int main(int argc, char *argv[]) options.debug = YES; }]; + //user gotta be admin + if(YES != hasAdminPrivileges()) + { + //show alert + showAlert(@"ERROR: Insuffient Privileges.", @"Administrator privileges are required to monitor the camera & microphone."); + + //bail + goto bail; + } + //cmdline install? if(YES == [NSProcessInfo.processInfo.arguments containsObject:CMD_INSTALL]) { diff --git a/Shared/Utilities.h b/Shared/Utilities.h index b2a780f..923cce2 100644 --- a/Shared/Utilities.h +++ b/Shared/Utilities.h @@ -131,4 +131,6 @@ BOOL AppleSilicon(void); //show an alert NSModalResponse showAlert(NSString* messageText, NSString* informativeText); +BOOL hasAdminPrivileges(void); + #endif diff --git a/Shared/Utilities.m b/Shared/Utilities.m index 2002dcd..36f5c4f 100644 --- a/Shared/Utilities.m +++ b/Shared/Utilities.m @@ -12,6 +12,8 @@ #import "consts.h" #import "utilities.h" +#import +#import #import #import #import @@ -1647,3 +1649,44 @@ NSModalResponse showAlert(NSString* messageText, NSString* informativeText) return response; } + + +//checks if user has admin privs +// ->based off http://stackoverflow.com/questions/30000443/asking-for-admin-privileges-for-only-standard-accounts +BOOL hasAdminPrivileges() +{ + //flag + BOOL isAdmin = NO; + + //password entry + struct passwd* pwentry = NULL; + + //admin group + struct group* adminGroup = NULL; + + //get password entry for current user + pwentry = getpwuid(getuid()); + + //get admin group + adminGroup = getgrnam("admin"); + + //iterate over entries + // ->check if current user is part of the admin group + while(*adminGroup->gr_mem != NULL) + { + //check if admin + if (strcmp(pwentry->pw_name, *adminGroup->gr_mem) == 0) + { + //yay! + isAdmin = YES; + + //exit loop + break; + } + + //try next + adminGroup->gr_mem++; + } + + return isAdmin; +}