Fix compile warning

Fix crash if smc failed to get current authorization during first use
This commit is contained in:
Anakin Zheng
2014-03-25 15:13:47 -04:00
parent 063d53b06c
commit 3dbea4bd98
6 changed files with 68 additions and 31 deletions

View File

@ -586,8 +586,10 @@ NSUserDefaults *defaults;
//just a helper to bringt update-info-window to the front
- (IBAction)updateCheck:(id)sender{
[[[SUUpdater alloc] init] checkForUpdates:sender];
SUUpdater *updater = [[SUUpdater alloc] init];
[updater checkForUpdates:sender];
[[NSApplication sharedApplication] activateIgnoringOtherApps:YES];
[updater release];
}
- (IBAction)visitHomepage:(id)sender{
@ -651,7 +653,7 @@ NSUserDefaults *defaults;
LSSharedFileListRef loginItems = LSSharedFileListCreate(kCFAllocatorDefault, kLSSharedFileListSessionLoginItems, /*options*/ NULL);
NSString *path = [[NSBundle mainBundle] bundlePath];
CFURLRef URLToToggle = (CFURLRef)[NSURL fileURLWithPath:path];
LSSharedFileListItemRef existingItem = NULL;
//LSSharedFileListItemRef existingItem = NULL;
UInt32 seed = 0U;
NSArray *currentLoginItems = [NSMakeCollectable(LSSharedFileListCopySnapshot(loginItems, &seed)) autorelease];
@ -667,7 +669,7 @@ NSUserDefaults *defaults;
CFRelease(URL);
if (foundIt) {
existingItem = item;
//existingItem = item;
found = YES;
break;
}
@ -728,8 +730,6 @@ NSUserDefaults *defaults;
LSSharedFileListItemRemove(loginItems, existingItem);
}
#pragma mark **SMC-Binary Owner/Right Check**
//TODO: It looks like this function is called inefficiently.
//call smc binary with sudo rights and apply
@ -748,6 +748,15 @@ NSUserDefaults *defaults;
AuthorizationRights gencright = { 1, &gencitem };
int flags = kAuthorizationFlagExtendRights | kAuthorizationFlagInteractionAllowed;
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]];
[alert setAlertStyle:2];
NSInteger result = [alert runModal];
if (result == NSAlertDefaultReturn) {
[[NSApplication sharedApplication] terminate:self];
}
}
NSString *tool=@"/usr/sbin/chown";
NSArray *argsArray = [NSArray arrayWithObjects: @"root:admin",smcpath,nil];
int i;
@ -757,6 +766,15 @@ NSUserDefaults *defaults;
}
args[i] = NULL;
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]];
[alert setAlertStyle:2];
NSInteger result = [alert runModal];
if (result == NSAlertDefaultReturn) {
[[NSApplication sharedApplication] terminate:self];
}
}
//second call for suid-bit
tool=@"/bin/chmod";
argsArray = [NSArray arrayWithObjects: @"6555",smcpath,nil];
@ -765,6 +783,15 @@ NSUserDefaults *defaults;
}
args[i] = NULL;
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]];
[alert setAlertStyle:2];
NSInteger result = [alert runModal];
if (result == NSAlertDefaultReturn) {
[[NSApplication sharedApplication] terminate:self];
}
}
}