macos prefs pane more reliable running indicator
[openafs.git] / src / platform / DARWIN / AFSPreference / AFSPropertyManager.m
index b82226e..a5fb45e 100644 (file)
        NSString *afsdOptionStrData = [[NSString alloc] initWithData:fileHData
                                                                                                                encoding:NSASCIIStringEncoding];*/
        if(!filePath) return;
-       [self readAFSDParamLineContent:[[NSString stringWithContentsOfFile:filePath] stringByStandardizingPath]];
+       [self readAFSDParamLineContent:[[NSString stringWithContentsOfFile:filePath 
+                                                                                                                         encoding:NSUTF8StringEncoding 
+                                                                                                                                error:nil] stringByStandardizingPath]];
 }
 
 // -------------------------------------------------------------------------------
        NSScanner *lineScanner = nil;
        
        //Get file content
-       NSString *newAFSDConfContent = [NSString stringWithContentsOfFile:filePath];
+       NSString *newAFSDConfContent = [NSString stringWithContentsOfFile:filePath 
+                                                                                                                        encoding:NSUTF8StringEncoding 
+                                                                                                                               error:nil];
        
        //get lines in array
        NSArray *confLines = [newAFSDConfContent componentsSeparatedByString:@"\n"];
 //  +(void) aklog
 // -------------------------------------------------------------------------------
 -(void) aklog:(NSString*)theCell noKerberosCall:(BOOL)krb5CallEnable {
-       KLPrincipal  princ = nil;
-       KLStatus kstatus = noErr;
-       char *princName = malloc(255);
+       KLPrincipal             princ = nil;
+       KLStatus                kstatus = noErr;
+       char                    *princName = 0L;
+       KLBoolean       outFoundValidTickets = false;
        @try {
                // trying to ket kerberos ticket
                if(krb5CallEnable) {
-                       kstatus =  KLAcquireInitialTickets (0L, 0L, &princ,  &princName);
-                       if(kstatus != noErr && kstatus != klUserCanceledErr) @throw [NSException exceptionWithName:@"aklog" 
-                                                                                                                                                                                               reason:kPathNotEmpty 
-                                                                                                                                                                                         userInfo:nil];
+                       kstatus = KLCacheHasValidTickets(nil, nil, &outFoundValidTickets, nil, nil);
+                       //kstatus =  KLAcquireInitialTickets (0L, 0L, &princ,  &princName);
+                       if(!outFoundValidTickets) {
+                               kstatus = KLAcquireNewInitialTickets(nil, nil, &princ, &princName);
+                               if(kstatus != noErr && kstatus != klUserCanceledErr) @throw [NSException exceptionWithName:@"aklog" 
+                                                                                                                                                                                                       reason:@"KLAcquireInitialTickets" 
+                                                                                                                                                                                                 userInfo:nil];
+                       }
                } else kstatus = klNoErr;
                
-                //ok to launch aklog
+               
+               //ok to launch aklog
                if(kstatus == klNoErr) [TaskUtil executeTaskSearchingPath:@"aklog" 
                                                                                                                         args:(theCell==nil?[NSArray arrayWithObjects:nil]:[NSArray arrayWithObjects:@"-c", theCell, nil])];
                
        }
        @finally {
                // destory the kerberos va
-               if(princName && princ != nil) 
-                       KLDisposeString(princName);
-               else if(princName) free(princName);
+               if (kstatus == klNoErr) {
+                       KLDisposeString (princName);
+                       KLDisposePrincipal (princ);
+               }
        }
                
 }
 // -------------------------------------------------------------------------------
 -(void) shutdown
 {
-       NSMutableString *filePath = [[NSMutableString alloc] initWithCapacity:256];
        @try {
-               if([[AuthUtil shared] autorize] != noErr)
-                       return;
-               
-               /*const char *args0[] = {"stop", 0L};
-               [[AuthUtil shared] execUnixCommand:"/Library/StartupItems/OpenAFS/OpenAFS_stop"
-                                                                         args:args0 
-                                                                       output:0L];*/
-               
-               // unmount afs
-               const char *args1[] = {"-f", "/afs", 0L};
-               [[AuthUtil shared] execUnixCommand:"/sbin/umount"
-                                                                         args:args1 
-                                                                       output:0L];
-               
-               const char *args2[] = {"-shutdown", 0L};
-               [[AuthUtil shared] execUnixCommand:"/usr/sbin/afsd"
-                                                                         args:args2 
-                                                                       output:0L];
-                               
-               const char *args3[] = {[filePath UTF8String], 0L};
-               [[AuthUtil shared] execUnixCommand:"/sbin/kextunload"
-                                                                         args:args3 
-                                                                       output:0L];
-               
+               const char *stopArgs[] = {"stop", 0L};
+               if([[AuthUtil shared] autorize] == noErr) {
+                       [[AuthUtil shared] execUnixCommand:AFS_DAEMON_STARTUPSCRIPT
+                                                                                 args:stopArgs
+                                                                               output:nil];
+               }
+
        }
        @catch (NSException * e) {
                @throw e;
        
 }
 
+
+// -------------------------------------------------------------------------------
+//  -(void) shutdown
+// -------------------------------------------------------------------------------
+-(void) startup
+{
+       @try {
+               const char *startArgs[] = {"start", 0L};
+               if([[AuthUtil shared] autorize] == noErr) {
+                       [[AuthUtil shared] execUnixCommand:AFS_DAEMON_STARTUPSCRIPT
+                                                                                 args:startArgs
+                                                                               output:nil];
+               }
+
+       }
+       @catch (NSException * e) {
+               @throw e;
+       }
+       @finally {
+
+       }
+
+
+}
 // -------------------------------------------------------------------------------
 //  -(void) saveConfigurationFiles
 // -------------------------------------------------------------------------------
                if(filePath) [filePath release];
        }
 }
+
 // -------------------------------------------------------------------------------
 //  checkAfsStatus:[NSArray arrayWithObjects:@"checkserver", nil];
 // -------------------------------------------------------------------------------
 }
 
 // -------------------------------------------------------------------------------
+//  checkAfsStatus:[NSArray arrayWithObjects:@"checkserver", nil];
+// -------------------------------------------------------------------------------
+-(BOOL) checkAfsStatusForStartup {
+       BOOL result = NO;
+       NSString *dfResult = [TaskUtil executeTaskSearchingPath:@"/bin/df" args:[NSArray arrayWithObjects:nil]];
+       result = (dfResult?([dfResult rangeOfString:@AFS_FS_MOUNT].location != NSNotFound):NO);
+       return result;
+}
+
+// -------------------------------------------------------------------------------
 //  makeChaceParamString
 // -------------------------------------------------------------------------------
 -(NSString*) makeChaceParamString