}
// -------------------------------------------------------------------------------
-// -(void) readPreferenceFile
-// -------------------------------------------------------------------------------
-- (void)startStopAfs:(id)sender
-{
- if(!afsSysPath) return;
-
- OSStatus status = noErr;
- NSString *afsdPath = [TaskUtil searchExecutablePath:@"afsd"];
- NSString *rootHelperApp = nil;
- BOOL currentAfsState = NO;
-
- @try {
- if(afsdPath == nil) return;
- AFSPropertyManager *afsMngr = [[AFSPropertyManager alloc] initWithAfsPath:afsSysPath];
- currentAfsState = [afsMngr checkAfsStatus];
- [afsMngr release];
-
- rootHelperApp = [[self bundle] pathForResource:@"afshlp" ofType:@""];
-
- //Check helper app
- [self repairHelperTool];
-
- // make the parameter to call the root helper app
- status = [[AuthUtil shared] autorize];
- if(status == noErr){
- if(currentAfsState){
- //shutdown afs
- NSMutableString *afsKextPath = [[NSMutableString alloc] initWithCapacity:256];
- [afsKextPath setString:afsSysPath];
- [afsKextPath appendString:@"/etc/afs.kext"];
-
- const char *stopAfsArgs[] = {"stop_afs", [afsKextPath UTF8String], [afsdPath UTF8String], 0L};
- [[AuthUtil shared] execUnixCommand:[rootHelperApp UTF8String]
- args:stopAfsArgs
- output:nil];
- } else {
- const char *startAfsArgs[] = {[[[self bundle] pathForResource:@"start_afs" ofType:@"sh"] UTF8String], [afsSysPath UTF8String], [afsdPath UTF8String], 0L};
- [[AuthUtil shared] execUnixCommand:[rootHelperApp UTF8String]
- args:startAfsArgs
- output:nil];
- }
- }
- }
- @catch (NSException * e) {
- NSLog([e reason]);
- }
- @finally {
- [[AuthUtil shared] deautorize];
- [self updateAfsStatus:nil];
- //Send notification to preferencepane
- [[NSDistributedNotificationCenter defaultCenter] postNotificationName:afsCommanderID object:kMenuExtraEventOccured];
- }
-
-}
-
-// -------------------------------------------------------------------------------
// -(void) getToken
// -------------------------------------------------------------------------------
- (void)getToken:(id)sender
if(useAklogPrefValue) return [useAklogPrefValue intValue] == NSOnState;
else return NSOffState;
}
-
-// -------------------------------------------------------------------------------
-// repairHelperTool:
-// -------------------------------------------------------------------------------
-- (void) repairHelperTool
-{
- struct stat st;
- int fdTool;
- int status = 0;
- NSString *afshlpPath = [[self bundle] pathForResource:@"afshlp" ofType:nil];
-
-
-
- // Open tool exclusively, so nobody can change it while we bless it.
- fdTool = open([afshlpPath UTF8String], O_NONBLOCK | O_RDONLY | O_EXLOCK, 0);
-
- if(fdTool == -1)
- {
- NSLog(@"Exclusive open while repairing tool failed: %d.", errno);
- exit(-1);
- }
-
- if(fstat(fdTool, &st))
- {
- NSLog(@"fstat failed.");
- exit(-1);
- }
-
- if(st.st_uid != 0)
- {
- status = [[AuthUtil shared] autorize];
- if(status == noErr){
- fchown(fdTool, 0, st.st_gid);
-
- // Disable group and world writability and make setuid root.
- fchmod(fdTool, (st.st_mode & (~(S_IWGRP | S_IWOTH)))/* | S_ISUID*/);
- const char *args[] = {"root", [afshlpPath UTF8String],0L};
- [[AuthUtil shared] execUnixCommand:"/usr/sbin/chown"
- args:args
- output:nil];
- [[AuthUtil shared] deautorize];
- }
- } else NSLog(@"st_uid = 0");
-
-
-
- close(fdTool);
- NSLog(@"Self-repair done.");
-
-}@end
+@end