mirror of
https://github.com/hholtmann/smcFanControl.git
synced 2025-11-04 19:49:16 +01:00
Use a function to do right check
This commit is contained in:
@ -31,9 +31,10 @@
|
|||||||
#import "SystemVersion.h"
|
#import "SystemVersion.h"
|
||||||
|
|
||||||
@interface FanControl ()
|
@interface FanControl ()
|
||||||
+(void)copyMachinesIfNecessary;
|
+ (void)copyMachinesIfNecessary;
|
||||||
- (BOOL)isInAutoStart;
|
- (BOOL)isInAutoStart;
|
||||||
- (void) setStartAtLogin:(BOOL)enabled;
|
- (void)setStartAtLogin:(BOOL)enabled;
|
||||||
|
+ (void)checkRightStatus:(OSStatus)status;
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@implementation FanControl
|
@implementation FanControl
|
||||||
@ -730,6 +731,20 @@ NSUserDefaults *defaults;
|
|||||||
LSSharedFileListItemRemove(loginItems, existingItem);
|
LSSharedFileListItemRemove(loginItems, existingItem);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
+(void) checkRightStatus:(OSStatus) status
|
||||||
|
{
|
||||||
|
if (status != errAuthorizationSuccess) {
|
||||||
|
NSAlert *alert = [NSAlert alertWithMessageText:@"Authorization failed" defaultButton:@"Quit" alternateButton:nil otherButton:nil informativeTextWithFormat:[NSString stringWithFormat:@"Authorization failed with code %d",status]];
|
||||||
|
[alert setAlertStyle:2];
|
||||||
|
NSInteger result = [alert runModal];
|
||||||
|
|
||||||
|
if (result == NSAlertDefaultReturn) {
|
||||||
|
[[NSApplication sharedApplication] terminate:self];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#pragma mark **SMC-Binary Owner/Right Check**
|
#pragma mark **SMC-Binary Owner/Right Check**
|
||||||
//TODO: It looks like this function is called inefficiently.
|
//TODO: It looks like this function is called inefficiently.
|
||||||
//call smc binary with sudo rights and apply
|
//call smc binary with sudo rights and apply
|
||||||
@ -748,16 +763,10 @@ NSUserDefaults *defaults;
|
|||||||
AuthorizationRights gencright = { 1, &gencitem };
|
AuthorizationRights gencright = { 1, &gencitem };
|
||||||
int flags = kAuthorizationFlagExtendRights | kAuthorizationFlagInteractionAllowed;
|
int flags = kAuthorizationFlagExtendRights | kAuthorizationFlagInteractionAllowed;
|
||||||
OSStatus status = AuthorizationCreate(&gencright, kAuthorizationEmptyEnvironment, flags, &authorizationRef);
|
OSStatus status = AuthorizationCreate(&gencright, kAuthorizationEmptyEnvironment, flags, &authorizationRef);
|
||||||
if (status != errAuthorizationSuccess) {
|
|
||||||
NSAlert *alert = [NSAlert alertWithMessageText:@"Authorization failed" defaultButton:@"Quit" alternateButton:nil otherButton:nil informativeTextWithFormat:[NSString stringWithFormat:@"Authorization failed with code %d",status]];
|
[self checkRightStatus:status];
|
||||||
[alert setAlertStyle:2];
|
|
||||||
NSInteger result = [alert runModal];
|
NSString *tool=@"/usr/sbin/chown";
|
||||||
|
|
||||||
if (result == NSAlertDefaultReturn) {
|
|
||||||
[[NSApplication sharedApplication] terminate:self];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
NSString *tool=@"/usr/sbin/chown";
|
|
||||||
NSArray *argsArray = [NSArray arrayWithObjects: @"root:admin",smcpath,nil];
|
NSArray *argsArray = [NSArray arrayWithObjects: @"root:admin",smcpath,nil];
|
||||||
int i;
|
int i;
|
||||||
char *args[255];
|
char *args[255];
|
||||||
@ -766,16 +775,10 @@ NSUserDefaults *defaults;
|
|||||||
}
|
}
|
||||||
args[i] = NULL;
|
args[i] = NULL;
|
||||||
status=AuthorizationExecuteWithPrivileges(authorizationRef,[tool UTF8String],0,args,&commPipe);
|
status=AuthorizationExecuteWithPrivileges(authorizationRef,[tool UTF8String],0,args,&commPipe);
|
||||||
if (status != errAuthorizationSuccess) {
|
|
||||||
NSAlert *alert = [NSAlert alertWithMessageText:@"Authorization failed" defaultButton:@"Quit" alternateButton:nil otherButton:nil informativeTextWithFormat:[NSString stringWithFormat:@"Authorization failed with code %d",status]];
|
[self checkRightStatus:status];
|
||||||
[alert setAlertStyle:2];
|
|
||||||
NSInteger result = [alert runModal];
|
//second call for suid-bit
|
||||||
|
|
||||||
if (result == NSAlertDefaultReturn) {
|
|
||||||
[[NSApplication sharedApplication] terminate:self];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//second call for suid-bit
|
|
||||||
tool=@"/bin/chmod";
|
tool=@"/bin/chmod";
|
||||||
argsArray = [NSArray arrayWithObjects: @"6555",smcpath,nil];
|
argsArray = [NSArray arrayWithObjects: @"6555",smcpath,nil];
|
||||||
for(i = 0;i < [argsArray count];i++){
|
for(i = 0;i < [argsArray count];i++){
|
||||||
@ -783,15 +786,8 @@ NSUserDefaults *defaults;
|
|||||||
}
|
}
|
||||||
args[i] = NULL;
|
args[i] = NULL;
|
||||||
status=AuthorizationExecuteWithPrivileges(authorizationRef,[tool UTF8String],0,args,&commPipe);
|
status=AuthorizationExecuteWithPrivileges(authorizationRef,[tool UTF8String],0,args,&commPipe);
|
||||||
if (status != errAuthorizationSuccess) {
|
|
||||||
NSAlert *alert = [NSAlert alertWithMessageText:@"Authorization failed" defaultButton:@"Quit" alternateButton:nil otherButton:nil informativeTextWithFormat:[NSString stringWithFormat:@"Authorization failed with code %d",status]];
|
[self checkRightStatus:status];
|
||||||
[alert setAlertStyle:2];
|
|
||||||
NSInteger result = [alert runModal];
|
|
||||||
|
|
||||||
if (result == NSAlertDefaultReturn) {
|
|
||||||
[[NSApplication sharedApplication] terminate:self];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user