detect / alert non-admin users
This commit is contained in:
parent
9a6ee5811f
commit
f2490a083f
|
@ -242,7 +242,7 @@ bail:
|
||||||
if(YES != [defaultManager copyItemAtPath:app toPath:appCopy error:&error])
|
if(YES != [defaultManager copyItemAtPath:app toPath:appCopy error:&error])
|
||||||
{
|
{
|
||||||
//err msg
|
//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
|
//bail
|
||||||
goto bail;
|
goto bail;
|
||||||
|
|
|
@ -399,7 +399,7 @@ bail:
|
||||||
if(YES != [NSFileManager.defaultManager copyItemAtPath:applicationSrc toPath:applicationDest error:&error])
|
if(YES != [NSFileManager.defaultManager copyItemAtPath:applicationSrc toPath:applicationDest error:&error])
|
||||||
{
|
{
|
||||||
//err msg
|
//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
|
//bail
|
||||||
goto bail;
|
goto bail;
|
||||||
|
|
|
@ -36,6 +36,16 @@ int main(int argc, char *argv[])
|
||||||
options.debug = YES;
|
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?
|
//cmdline install?
|
||||||
if(YES == [NSProcessInfo.processInfo.arguments containsObject:CMD_INSTALL])
|
if(YES == [NSProcessInfo.processInfo.arguments containsObject:CMD_INSTALL])
|
||||||
{
|
{
|
||||||
|
|
|
@ -131,4 +131,6 @@ BOOL AppleSilicon(void);
|
||||||
//show an alert
|
//show an alert
|
||||||
NSModalResponse showAlert(NSString* messageText, NSString* informativeText);
|
NSModalResponse showAlert(NSString* messageText, NSString* informativeText);
|
||||||
|
|
||||||
|
BOOL hasAdminPrivileges(void);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -12,6 +12,8 @@
|
||||||
#import "consts.h"
|
#import "consts.h"
|
||||||
#import "utilities.h"
|
#import "utilities.h"
|
||||||
|
|
||||||
|
#import <pwd.h>
|
||||||
|
#import <grp.h>
|
||||||
#import <dlfcn.h>
|
#import <dlfcn.h>
|
||||||
#import <signal.h>
|
#import <signal.h>
|
||||||
#import <unistd.h>
|
#import <unistd.h>
|
||||||
|
@ -1647,3 +1649,44 @@ NSModalResponse showAlert(NSString* messageText, NSString* informativeText)
|
||||||
|
|
||||||
return response;
|
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;
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue