963d7ef8655c2a941472dfbb726ad5bd1fc945e4
[openafs.git] / src / platform / DARWIN / AFSPreference / AFSCommanderPref.m
1 //
2 //  AFSCommanderPref.m
3 //  AFSCommander
4 //
5 //  Created by Claudio Bisegni on 10/05/07.
6 //  Copyright (c) 2007 INFN - National Institute of Nuclear Physics. All rights reserved.
7 //
8
9 #import "AFSCommanderPref.h"
10 #import "IpConfiguratorCommander.h"
11 #import "TokenCredentialController.h"
12 #import "InfoController.h"
13 #import "TaskUtil.h"
14 #import "PListManager.h"
15 #import "DialogUtility.h"
16 #import "NSString+search.h"
17 #include <sys/param.h>
18 #include <sys/stat.h>
19 #include <sys/wait.h>
20 #include <sys/types.h>
21 #include <sys/fcntl.h>
22 #include <sys/errno.h>
23 #include <unistd.h>
24 #include <stdlib.h>
25 #include <string.h>
26 #import <CoreServices/CoreServices.h>
27
28
29 #define ADD_CELL_CONTROL_TAG 1
30 #define REMOVE_CELL_CONTROL_TAG 2
31
32 #define TABLE_TOKENS_LIST 1
33 #define TABLE_CELL_LIST 2
34
35 #define TAB_TOKENS 1
36 #define TAB_CELL_SERV_DB 2
37 #define TAB_CACHE 3
38 #define TAB_LINK 4
39
40 //CellServDB table id
41 #define CELLSRVDB_TABLE_USR_DFLT_CHECK_COLUMN   0
42 #define CELLSRVDB_TABLE_DFLT_CHECK_COLUMN               1
43 #define CELLSRVDB_TABLE_NAME_COLUMN                             2
44 #define CELLSRVDB_TABLE_DESCRIPTION_COLUMN              3
45
46 @implementation AFSCommanderPref
47
48 // -------------------------------------------------------------------------------
49 //  initWithBundle:
50 // -------------------------------------------------------------------------------
51 - (id)initWithBundle:(NSBundle *)bundle
52 {
53     if ( ( self = [super initWithBundle:bundle] ) != nil ) {
54         //appID = kAfsCommanderID;
55                 prefStartUp = 1;
56     }
57     return self;
58 }
59
60 // -------------------------------------------------------------------------------
61 //  mainView:
62 // -------------------------------------------------------------------------------
63 - (NSView *) mainView {
64         if (prefStartUp == 1){
65                 SInt32 osxMJVers = 0;
66                 SInt32 osxMnVers = 0;
67                 if (Gestalt(gestaltSystemVersionMajor, &osxMJVers) == noErr && Gestalt(gestaltSystemVersionMinor, &osxMnVers) == noErr) {
68                         if (osxMJVers == 10 && osxMnVers>= 5) {
69                                 [afsCommanderView  setFrameSize:NSMakeSize(668, [afsCommanderView frame].size.height)];
70                 prefStartUp = 0;
71                         }
72                 }
73         }
74         
75     return afsCommanderView;
76 }
77
78 // -------------------------------------------------------------------------------
79 //  mainViewDidLoad:
80 // -------------------------------------------------------------------------------
81 - (void) mainViewDidLoad
82 {
83         //CellServDB Table
84         [((NSTableView*)cellList) setDelegate:self];
85         [((NSTableView*)cellList) setTarget:self];
86         [((NSTableView*)cellList) setDoubleAction:@selector(tableDoubleAction:)];
87         
88         
89 }
90
91 // -------------------------------------------------------------------------------
92 //  didSelect:
93 // -------------------------------------------------------------------------------
94 - (void) didSelect
95 {
96         //try to install the launchd file for backgrounder
97         //Remove launchd ctrl file
98         @try {
99                 [PListManager installBackgrounderLaunchdFile:YES 
100                                                                                 resourcePath:[[self bundle] resourcePath]];
101         }
102         @catch (NSException * e) {
103                 NSDictionary *excecptDic = [e userInfo];
104                 NSNumber *keyNum = [excecptDic objectForKey:@"agent_folder_error"];
105                 if(keyNum && [keyNum boolValue]) {
106                         // the dir HOME_LAUNCHD_AGENT_FOLDER (PListManager.h) must be created
107                         NSBeginAlertSheet([[NSString stringWithString:kDoYouWantCreateTheDirectory] stringByAppendingString:HOME_LAUNCHD_AGENT_FOLDER],
108                                                           @"Create", @"Cancel", nil,                                                                            
109                                                           [[self mainView] window],     self, @selector(credentialAtLoginTimeEventCreationLaunchAgentDir:returnCode:contextInfo:), NULL, 
110                                                           nil, @"", nil);
111                 }
112         }
113         @finally {
114                 
115         }
116         
117         
118         // Set Developer info
119         [textFieldDevInfoLabel setStringValue:kDevelopInfo];
120         // creating the lock
121         tokensLock = [[NSLock alloc] init];
122         
123         //Initialization cellservdb and token list
124         filteredCellDB = nil;
125         tokenList = nil;
126         
127         [self readPreferenceFile];
128                         
129         // alloc the afs property mananger
130         afsProperty = [[AFSPropertyManager alloc] init];
131         
132         // register preference pane to detect menuextra killed by user
133 /*      [[NSDistributedNotificationCenter defaultCenter] addObserver:self 
134                                                                                                                 selector:@selector(mextraChangeActivation:) 
135                                                                                                                         name:kAfsCommanderID 
136                                                                                                                   object:kMExtraClosedNotification];*/
137          
138         [[NSDistributedNotificationCenter defaultCenter] addObserver:self 
139                                                                                                                 selector:@selector(refreshGui:) 
140                                                                                                                         name:kAfsCommanderID 
141                                                                                                                   object:kMenuExtraEventOccured];
142         
143         //Register for mount/unmount afs volume
144         [[[NSWorkspace sharedWorkspace] notificationCenter] addObserver:self 
145                                                                                                                    selector:@selector(afsVolumeMountChange:) 
146                                                                                                                            name:NSWorkspaceDidMountNotification object:nil];
147         
148         [[[NSWorkspace sharedWorkspace] notificationCenter] addObserver:self 
149                                                                                                                    selector:@selector(afsVolumeMountChange:) 
150                                                                                                                            name:NSWorkspaceDidUnmountNotification object:nil];
151         
152         // set self as table data source
153         [((NSTableView*)cellList) setDataSource:self];
154         [((NSTableView*)tokensTable) setDataSource:self];
155         
156         //check the afs state
157         [self setAfsStatus];
158         
159         // let show the configuration after prefpane is open
160         [self refreshConfiguration:nil];
161         
162         // refresh the token list
163         //[self refreshTokens:nil];
164         
165         //refresh table to reflect the NSSearchField contained text
166         [self searchCellTextEvent:nil];
167 }
168
169 // -------------------------------------------------------------------------------
170 //  credentialAtLoginTimeEventCreationLaunchAgentDir:
171 // -------------------------------------------------------------------------------
172 - (void) credentialAtLoginTimeEventCreationLaunchAgentDir:(NSWindow*)alert returnCode:(int)returnCode contextInfo:(void *)contextInfo {
173         [alert close];
174         switch (returnCode) {
175                 case  1:
176                         if([[NSFileManager defaultManager] createDirectoryAtPath:[HOME_LAUNCHD_AGENT_FOLDER stringByExpandingTildeInPath] 
177                                                                                                                   attributes:nil]) {
178                                 
179                                 //Create the file
180                                 [PListManager installBackgrounderLaunchdFile:YES
181                                                                                                 resourcePath:[[self bundle] resourcePath]];
182                                 [self showMessage:kDirectoryCreated];
183                         } else {
184                                 [self showMessage:kErrorCreatingDirectory];
185                         }
186                         break;
187                 case 0:
188                         break;
189         }
190 }
191
192
193 // -------------------------------------------------------------------------------
194 //  willUnselect:
195 // -------------------------------------------------------------------------------
196 - (void)willUnselect
197 {
198         // remove self as datasource
199         [((NSTableView*)cellList) setDataSource:nil];
200         [((NSTableView*)tokensTable) setDataSource:nil];
201
202         //release the afs property manager
203         if(afsProperty) [afsProperty release];
204         //release tokens list
205         if(tokenList) [tokenList release];      
206         //Remove the cell temp array
207         if(filteredCellDB) [filteredCellDB release];
208         
209         [self writePreferenceFile];
210         
211         // unregister preference pane to detect menuextra killed by user
212         [[NSDistributedNotificationCenter defaultCenter] removeObserver:self 
213                                                                                                                            name:kAfsCommanderID 
214                                                                                                                          object:kMExtraClosedNotification];
215         [[NSDistributedNotificationCenter defaultCenter] removeObserver:self 
216                                                                                                                            name:kAfsCommanderID 
217                                                                                                                          object:kMenuExtraEventOccured];
218         [[[NSWorkspace sharedWorkspace] notificationCenter] removeObserver:self 
219                                                                                                                                   name:NSWorkspaceDidMountNotification object:nil];
220         [[[NSWorkspace sharedWorkspace] notificationCenter] removeObserver:self 
221                                                                                                                                   name:NSWorkspaceDidUnmountNotification object:nil];
222         
223         [self stopTimer];
224         [tokensLock release];
225 }
226
227
228 // -------------------------------------------------------------------------------
229 //  startTimer:
230 // -------------------------------------------------------------------------------
231 - (void)startTimer{
232         //start the time for check tokens validity
233         if(timerForCheckTokensList) return;
234         timerForCheckTokensList = [NSTimer scheduledTimerWithTimeInterval:TOKENS_REFRESH_TIME_IN_SEC 
235                                                                                                                            target:self 
236                                                                                                                          selector:@selector(refreshTokens:) 
237                                                                                                                          userInfo:nil 
238                                                                                                                           repeats:YES];
239         [timerForCheckTokensList fire]; 
240 }
241
242 // -------------------------------------------------------------------------------
243 //  stopTimer:
244 // -------------------------------------------------------------------------------
245 - (void)stopTimer{
246         if(!timerForCheckTokensList) return;
247         [timerForCheckTokensList invalidate];   
248         timerForCheckTokensList = nil;
249 }
250
251
252 // -------------------------------------------------------------------------------
253 //  readPreferenceFile:
254 // -------------------------------------------------------------------------------
255 - (void) readPreferenceFile
256 {
257         
258         // read the preference for aklog use
259         NSNumber *useAklogPrefValue = (NSNumber*)CFPreferencesCopyValue((CFStringRef)PREFERENCE_USE_AKLOG, (CFStringRef)kAfsCommanderID,  
260                                                                                                                                         kCFPreferencesCurrentUser, kCFPreferencesAnyHost);
261         NSNumber *aklogTokenAtLogin = (NSNumber*)CFPreferencesCopyValue((CFStringRef)PREFERENCE_AKLOG_TOKEN_AT_LOGIN, (CFStringRef)kAfsCommanderID,  
262                                                                                                                                         kCFPreferencesCurrentUser, kCFPreferencesAnyHost);
263         [useAklogCheck setState:[useAklogPrefValue intValue]];
264         [aklogCredentialAtLoginTime setEnabled:useAklogPrefValue && [useAklogPrefValue boolValue]];
265         [aklogCredentialAtLoginTime setState:aklogTokenAtLogin && [aklogTokenAtLogin boolValue]];
266
267         //check krb5 at login time
268         [installKRB5AuthAtLoginButton setState:[PListManager checkKrb5AtLoginTimeLaunchdEnable]];
269
270         //check for AFS enable at startup
271         NSNumber *afsEnableStartupTime = (NSNumber*)CFPreferencesCopyValue((CFStringRef)PREFERENCE_START_AFS_AT_STARTUP, 
272                                                                                                                                            (CFStringRef)kAfsCommanderID,  kCFPreferencesAnyUser, kCFPreferencesAnyHost);
273         if(afsEnableStartupTime) 
274                 startAFSAtLogin = [afsEnableStartupTime boolValue];
275         else 
276                 startAFSAtLogin = false;
277         //set the check button state
278         [checkButtonAfsAtBootTime setState:startAFSAtLogin];
279         
280         NSNumber *showStatusMenu =  (NSNumber*)CFPreferencesCopyValue((CFStringRef)PREFERENCE_SHOW_STATUS_MENU,  (CFStringRef)kAfsCommanderID,  kCFPreferencesCurrentUser, kCFPreferencesAnyHost);
281         [(NSButton*)afsMenucheckBox setState: [showStatusMenu boolValue]];
282         
283         //backgrounder state
284         [backgrounderActivationCheck setState:[PListManager launchdJobState:BACKGROUNDER_P_FILE]];
285 }
286
287 // -------------------------------------------------------------------------------
288 //  willUnselect:
289 // -------------------------------------------------------------------------------
290 - (void) writePreferenceFile
291 {
292         //Set the preference for afs path
293         /*CFPreferencesSetValue((CFStringRef)PREFERENCE_AFS_SYS_PAT, 
294                                                   (CFStringRef)[((NSTextField*) installationPathTextField ) stringValue], 
295                                                   (CFStringRef)kAfsCommanderID, kCFPreferencesAnyUser, kCFPreferencesAnyHost);*/
296         
297         //Set the preference for aklog use
298         CFPreferencesSetValue((CFStringRef)PREFERENCE_USE_AKLOG, 
299                                                   (CFNumberRef)[NSNumber numberWithInt:[useAklogCheck state]], 
300                                                   (CFStringRef)kAfsCommanderID, kCFPreferencesCurrentUser, kCFPreferencesAnyHost);
301
302         //set AFS enable state at startup
303         CFPreferencesSetValue((CFStringRef)PREFERENCE_START_AFS_AT_STARTUP, 
304                                                   (CFNumberRef)[NSNumber numberWithBool:startAFSAtLogin], 
305                                                   (CFStringRef)kAfsCommanderID, kCFPreferencesAnyUser, kCFPreferencesAnyHost);
306         
307         //set aklog at login
308         CFPreferencesSetValue((CFStringRef)PREFERENCE_AKLOG_TOKEN_AT_LOGIN, 
309                                                   (CFNumberRef)[NSNumber numberWithBool:[aklogCredentialAtLoginTime state]], 
310                                                   (CFStringRef)kAfsCommanderID, kCFPreferencesCurrentUser, kCFPreferencesAnyHost);
311         
312         //set aklog at login
313         CFPreferencesSetValue((CFStringRef)PREFERENCE_SHOW_STATUS_MENU, 
314                                                   (CFNumberRef)[NSNumber numberWithBool:[afsMenucheckBox state]], 
315                                                   (CFStringRef)kAfsCommanderID, kCFPreferencesCurrentUser, kCFPreferencesAnyHost);
316         
317         CFPreferencesSynchronize((CFStringRef)kAfsCommanderID,  kCFPreferencesAnyUser, kCFPreferencesAnyHost);
318         CFPreferencesSynchronize((CFStringRef)kAfsCommanderID,  kCFPreferencesCurrentUser, kCFPreferencesAnyHost);
319         
320         [[NSDistributedNotificationCenter defaultCenter] postNotificationName:kAFSMenuExtraID object:kPrefChangeNotification];
321 }
322
323 // -------------------------------------------------------------------------------
324 //  saveConfiguration:
325 // -------------------------------------------------------------------------------
326 - (IBAction) saveConfiguration:(id) sender
327 {
328         @try{
329                 
330                 //[afsProperty setCellName:[cellNameTextEdit stringValue]];
331                 [afsProperty setCellName:[afsProperty getDefaultCellName]];
332                 
333                 //save configurations
334                 [afsProperty saveConfigurationFiles:YES];
335                 
336                 
337                 //Reload all configuration
338                 [self refreshConfiguration:nil];
339                 
340                 //refresh table to reflect the NSSearchField contained text
341                 [self searchCellTextEvent:nil];
342                 
343                 //Show dialog for notifity al saving process ar gone ell
344                 [self showMessage:kConfigurationSaved];
345         }@catch(NSException *e){
346                 [self showMessage:[e reason]];
347         } @finally {
348                 [((NSTableView*)cellList) reloadData];
349         }
350         
351 }
352
353 // -------------------------------------------------------------------------------
354 //  saveCacheManagerParam:
355 // -------------------------------------------------------------------------------
356 - (IBAction) saveCacheManagerParam:(id) sender
357 {
358         @try{
359                 //Update the value form view to afs property manager class
360                 [self updateCacheParamFromView];
361                 [afsProperty saveCacheConfigurationFiles:YES];
362                 [self showMessage:kSavedCacheConfiguration];
363         }@catch(NSException *e){
364                 [self showMessage:[e reason]];
365         } @finally {
366                 [((NSTableView*)cellList) reloadData];
367         }
368 }
369
370 // -------------------------------------------------------------------------------
371 //  refreshConfiguration:
372 // -------------------------------------------------------------------------------
373 - (IBAction) refreshConfiguration:(id) sender
374 {
375         NSString *afsBasePath = PREFERENCE_AFS_SYS_PAT_STATIC;
376         @try{
377                 // set the afs path
378                 [afsProperty setPath:afsBasePath];
379                 
380                 // load configuration
381                 [afsProperty loadConfiguration];
382                 
383                 //set the afs version label
384                 [afsVersionLabel setStringValue:[afsProperty getAfsVersion]];
385                 
386                 //set the current default cell
387                 [afsDefaultCellLabel setStringValue:[afsProperty getDefaultCellName]];
388                 
389                 // Update cache view
390                 [self fillCacheParamView];
391                 
392                 //Filter the cellServDb and allocate filtered array
393                 [self filterCellServDB:nil];
394                 
395         }@catch(NSException *e){
396                 [self showMessage:[e reason]];
397         } @finally {
398                 [((NSTableView*)cellList) reloadData];
399         }
400 }
401
402 // -------------------------------------------------------------------------------
403 //  fillCacheParamView:
404 // -------------------------------------------------------------------------------
405 -(void) fillCacheParamView
406 {
407         [dynRoot setState:[afsProperty dynRoot]?NSOnState:NSOffState];
408         [afsDB setState:[afsProperty afsDB]?NSOnState:NSOffState];
409         [statCacheEntry setIntValue:[afsProperty statCacheEntry]];
410         [dCacheDim setIntValue:[afsProperty dCacheDim]];
411         [cacheDimension setIntValue:[afsProperty cacheDimension]];
412         [daemonNumber setIntValue:[afsProperty daemonNumber]];
413         [afsRootMountPoint setStringValue:[afsProperty afsRootMountPoint]];
414         [nVolEntry setIntValue:[afsProperty nVolEntry]];
415         
416         //new version property
417         //[verbose setEnabled:[afsProperty useAfsdConfConfigFile]];
418         [verbose setState:[afsProperty verbose]?NSOnState:NSOffState];
419         
420 }
421
422 // -------------------------------------------------------------------------------
423 //  updateCacheParamFromView:
424 // -------------------------------------------------------------------------------
425 -(void) updateCacheParamFromView
426 {
427         NSString *tmpAfsPath = [afsRootMountPoint stringValue];
428         if(!tmpAfsPath || ([tmpAfsPath length] == 0) || ([tmpAfsPath characterAtIndex:0] != '/')) 
429                 @throw [NSException exceptionWithName:@"updateCacheParamFromView" 
430                                                                            reason:kBadAfsRootMountPoint
431                                                                          userInfo:nil];
432
433         
434         [afsProperty setDynRoot:[dynRoot state]==NSOnState];
435         [afsProperty setAfsDB:[afsDB state]==NSOnState];
436         [afsProperty setStatCacheEntry:[statCacheEntry intValue]];
437         [afsProperty setDCacheDim:[dCacheDim intValue]]; 
438         [afsProperty setCacheDimension:[cacheDimension intValue]]; 
439         [afsProperty setDaemonNumber:[daemonNumber intValue]];
440         [afsProperty setAfsRootMountPoint:tmpAfsPath];
441         [afsProperty setNVolEntry:[nVolEntry intValue]];
442         [afsProperty setVerbose:[verbose state]==NSOnState];
443 }
444
445
446 // -------------------------------------------------------------------------------
447 //  showCellIP:
448 // -------------------------------------------------------------------------------
449 - (IBAction) showCellIP:(id) sender
450 {
451         int rowSelected = [((NSTableView *) cellList) selectedRow];
452         [self modifyCellByIDX:rowSelected];
453 }
454
455 // -------------------------------------------------------------------------------
456 //  modifyCellByIDX:
457 // -------------------------------------------------------------------------------
458 -(void) modifyCellByIDX:(int) idx
459 {
460         [self modifyCell:[self getCellByIDX:idx]];
461 }
462
463 // -------------------------------------------------------------------------------
464 //  modifyCellByIDX:
465 // -------------------------------------------------------------------------------
466 -(void) modifyCell:(DBCellElement*) cellElement
467 {
468         [NSBundle loadNibNamed:@"IpPanel" owner:self];
469         [((IpConfiguratorCommander*) ipConfControllerCommander) setWorkCell:cellElement];
470         [NSApp beginSheet: ipConfigurationSheet
471            modalForWindow: [[self mainView] window]
472                 modalDelegate: self
473            didEndSelector: @selector(didEndSheet:returnCode:contextInfo:)
474                   contextInfo: nil];
475 }
476
477 // -------------------------------------------------------------------------------
478 //  addMoifyCell:
479 // -------------------------------------------------------------------------------
480 - (IBAction) addRemoveCell:(id) sender
481 {
482         switch([((NSControl*) sender) tag]){
483                 case ADD_CELL_CONTROL_TAG:
484                 {
485                         DBCellElement *newCell = [[DBCellElement alloc] init];
486                         if(!newCell) break;
487                         
488                         [newCell setCellName:kNewCellName];
489                         [newCell setCellComment:kNewCellComment];
490                         //cellArray = ;
491                         [[afsProperty getCellList] addObject:newCell];
492                         [newCell release];
493                         
494                         //Modify new cell
495                         [self modifyCell:newCell];
496                 }
497                 break;
498                         
499                 case REMOVE_CELL_CONTROL_TAG:
500                 {
501                         int index = 0;
502                         NSIndexSet *selectedIndex = [(NSTableView*)cellList selectedRowIndexes];
503                         if( [selectedIndex count] > 0) {
504                                 index = [selectedIndex firstIndex]; 
505                                 do {
506                                         DBCellElement *cellElement =  (DBCellElement*)[filteredCellDB objectAtIndex:index];
507                                         [[afsProperty getCellList] removeObject:cellElement];
508                                 } while ((index = [selectedIndex indexGreaterThanIndex: index]) != NSNotFound);
509                         }
510                 }
511                 break;
512         }
513         //Filter the cellServDb and allocate filtered array
514         [self searchCellTextEvent:nil];
515         [(NSTableView*)cellList deselectAll:nil];
516         [(NSTableView*)cellList reloadData];
517 }
518
519 // -------------------------------------------------------------------------------
520 //  repairHelperTool:
521 // -------------------------------------------------------------------------------
522 - (void) repairHelperTool
523 {
524         struct stat st;
525     int fdTool;
526         int status = 0;
527         NSLog(@"repairHelperTool"); 
528         NSString *afshlpPath = [[self bundle] pathForResource:@"afshlp" ofType:nil];
529         
530         
531     
532     // Open tool exclusively, so nobody can change it while we bless it.
533     fdTool = open([afshlpPath UTF8String], O_NONBLOCK | O_RDONLY | O_EXLOCK, 0);
534     
535     if(fdTool == -1)
536     {
537         NSLog(@"Exclusive open while repairing tool failed: %d.", errno);
538         exit(-1);
539     }
540     
541     if(fstat(fdTool, &st))
542     {
543         NSLog(@"fstat failed.");
544         exit(-1);
545     }
546     
547     if(st.st_uid != 0)
548     {
549                 status = [[AuthUtil shared] autorize];
550                 if(status == noErr){
551                         fchown(fdTool, 0, st.st_gid);
552                         
553                         // Disable group and world writability and make setuid root.
554                         fchmod(fdTool, (st.st_mode & (~(S_IWGRP | S_IWOTH)))/* | S_ISUID*/);
555                         const char *args[] = {"root", [afshlpPath UTF8String],0L};
556                         [[AuthUtil shared] execUnixCommand:"/usr/sbin/chown" 
557                                                                                   args:args
558                                                                                 output:nil];
559                         [[AuthUtil shared] deautorize];
560                 }
561     } else  NSLog(@"st_uid = 0");
562     
563         
564     
565     close(fdTool);
566     
567     NSLog(@"Self-repair done.");
568         
569 }
570
571
572 // -------------------------------------------------------------------------------
573 //  startStopAfs:
574 // -------------------------------------------------------------------------------
575 - (IBAction) startStopAfs:(id) sender
576 {
577         OSStatus status = noErr;
578         NSString *afsdPath = [TaskUtil searchExecutablePath:@"afsd"];
579         //NSString *startStopScript = nil;
580         NSString *rootHelperApp = nil;
581         BOOL currentAfsState = NO;
582         
583         @try {
584                 if(afsdPath == nil) return;
585                 currentAfsState = [afsProperty checkAfsStatus];
586                 rootHelperApp = [[self bundle] pathForResource:@"afshlp" ofType:@""];
587                         
588                 //[startStopScript setString: resourcePath];
589                 NSLog(@"Launch repair HelperTool");
590                 //Check helper app
591                 [self repairHelperTool];
592                 
593                 // make the parameter to call the root helper app
594                 status = [[AuthUtil shared] autorize];
595                 if(status == noErr){
596                         if(currentAfsState){
597                                 //shutdown afs
598                                 NSLog(@"Shutting down afs");
599                                 NSMutableString *afsKextPath = [[NSMutableString alloc] initWithCapacity:256];
600                                 [afsKextPath setString:[afsProperty path]];
601                                 [afsKextPath appendString:@"/etc/afs.kext"];
602                                 
603                                 //Make the array for arguments
604                                 NSLog(@"executeTaskWithAuth");
605                                 const char *stopAfsArgs[] = {"stop_afs", [afsKextPath  UTF8String], [afsdPath UTF8String], 0L};
606                                 [[AuthUtil shared] execUnixCommand:[rootHelperApp UTF8String] 
607                                                                                           args:stopAfsArgs
608                                                                                         output:nil];
609                                 
610                         } else {
611                                 NSLog(@"Starting up afs");
612                                 const char *startAfsArgs[] = {[[[self bundle] pathForResource:@"start_afs" ofType:@"sh"]  UTF8String], [[afsProperty path]  UTF8String], [afsdPath UTF8String], 0L};
613                                 [[AuthUtil shared] execUnixCommand:[rootHelperApp UTF8String] 
614                                                                                           args:startAfsArgs
615                                                                                         output:nil];
616                         }
617                 }
618                 [self refreshGui:nil];
619         }
620         @catch (NSException * e) {
621                 [self showMessage:[e reason]];
622         }
623         @finally {
624                 [[AuthUtil shared] deautorize];
625         }
626 }
627
628 // -------------------------------------------------------------------------------
629 //  info:
630 // -------------------------------------------------------------------------------
631 - (void) refreshGui:(NSNotification *)notification{
632         BOOL afsIsUp = [afsProperty checkAfsStatus];
633         [self setAfsStatus];
634         //[self refreshTokens:nil];
635         [tokensButton setEnabled:afsIsUp];
636         [unlogButton setEnabled:afsIsUp];
637 }
638
639 // -------------------------------------------------------------------------------
640 //  afsVolumeMountChange: Track the afs volume state change
641 // -------------------------------------------------------------------------------
642 - (void) afsVolumeMountChange:(NSNotification *)notification{
643         // Cehck if is mounted or unmounted afs
644         if([[[notification userInfo] objectForKey:@"NSDevicePath"] isEqualToString:@"/afs"]){
645                 [self setAfsStatus];
646                 [self refreshTokens:nil];
647         }
648 }
649
650 // -------------------------------------------------------------------------------
651 //  info:
652 // -------------------------------------------------------------------------------
653 - (IBAction) info:(id) sender
654 {
655         [((InfoController*) infoController) showHtmlResource:[[self bundle] pathForResource:@"licenza" ofType:@"rtf"]];
656
657         [NSApp beginSheet: infoSheet
658            modalForWindow: [[self mainView] window]
659                 modalDelegate: self
660            didEndSelector:  @selector(didEndInfoSheet:returnCode:contextInfo:)
661                   contextInfo: nil];
662 }
663
664 // -------------------------------------------------------------------------------
665 //  tableDoubleAction:
666 // -------------------------------------------------------------------------------
667 - (IBAction) tableDoubleAction:(id) sender
668 {
669         [self showCellIP:nil];
670 }
671
672 // -------------------------------------------------------------------------------
673 //  getNewToken:
674 // -------------------------------------------------------------------------------
675 - (IBAction) getNewToken:(id) sender
676 {
677         BOOL useAklog = [useAklogCheck state] == NSOnState;
678         if(useAklog){
679                 //[AFSPropertyManager aklog];
680                 [afsProperty getTokens:false 
681                                                    usr:nil 
682                                                    pwd:nil];
683                 [self refreshTokens:nil];
684                 //Inform afs menuextra to updata afs status
685                 [[NSDistributedNotificationCenter defaultCenter] postNotificationName:kAFSMenuExtraID object:kMExtraAFSStateChange];
686
687         } else {
688                 [NSBundle loadNibNamed:@"CredentialPanel" owner:self];
689                 [NSApp beginSheet: credentialSheet
690                    modalForWindow: [[self mainView] window]
691                         modalDelegate: self
692                    didEndSelector: @selector(didEndCredentialSheet:returnCode:contextInfo:)
693                           contextInfo: nil];
694         }
695 }
696
697
698 // -------------------------------------------------------------------------------
699 //  getCurrentCellInDB:
700 // -------------------------------------------------------------------------------
701 - (IBAction) unlog:(id) sender
702 {
703         int index = -1;
704         NSIndexSet *selectedIndex = [(NSTableView*)tokensTable selectedRowIndexes];
705         if( [selectedIndex count] > 0) {
706                 index = [selectedIndex firstIndex]; 
707                 do {
708                         NSString *tokenDesc = [tokenList objectAtIndex:index];
709                         NSString *cellToUnlog = [tokenDesc estractTokenByDelimiter:@"afs@" 
710                                                                                                                           endToken:@" "];
711                         [afsProperty unlog:cellToUnlog];
712                 } while ((index = [selectedIndex indexGreaterThanIndex: index]) != NSNotFound);
713         } else {
714                 [afsProperty unlog:nil];
715         }
716         [self refreshTokens:nil];
717         //Inform afs menuextra to updata afs status
718         [[NSDistributedNotificationCenter defaultCenter] postNotificationName:kAFSMenuExtraID object:kMExtraAFSStateChange];
719
720 }
721
722
723 // -------------------------------------------------------------------------------
724 //  aklogSwitchEvent:
725 // -------------------------------------------------------------------------------
726 - (IBAction) aklogSwitchEvent:(id) sender
727 {
728         //afs menu extra is loaded inform it to read preference
729         @try {
730                 if(![useAklogCheck state]) {
731                         //deselect the checkbox
732                         [aklogCredentialAtLoginTime setState:NO];
733                 }
734                 
735                 [self writePreferenceFile];
736                 
737                 //Enable disable aklog at login time checkbox according the useAklog checkbox
738                 [aklogCredentialAtLoginTime setEnabled:[useAklogCheck state]];
739                 
740         }
741         @catch (NSException * e) {
742                 [self showMessage:[e reason]];
743         }
744         
745                 
746 }
747
748 // -------------------------------------------------------------------------------
749 //  credentialAtLoginTimeEvent:
750 // -------------------------------------------------------------------------------
751 - (IBAction) credentialAtLoginTimeEvent:(id) sender {
752         [self writePreferenceFile];
753 }
754
755 // -------------------------------------------------------------------------------
756 //  afsStartupSwitchEvent:
757 // -------------------------------------------------------------------------------
758 - (IBAction) afsStartupSwitchEvent:(id) sender {
759         NSString *rootHelperApp = [[self bundle] pathForResource:@"afshlp" ofType:@""];
760         //get the new state
761         NSString *afsdPath = [TaskUtil searchExecutablePath:@"afsd"];
762         NSString *afsStartupScriptPath = [[self bundle] pathForResource:@"start_afs" ofType:@"sh"];
763         startAFSAtLogin = [checkButtonAfsAtBootTime state];
764         const char                      *startAfsArgs[] = {"load", "-w", [AFS_STARTUP_CONTROL_FILE UTF8String], 0L};
765         const char                      *stopAfsArgs[] = {"unload", "-w", [AFS_STARTUP_CONTROL_FILE UTF8String], 0L};
766         const char                      *launchctlExecutable = "/bin/launchctl";
767         /*      [PListManager manageAfsStartupLaunchdFile:startAFSAtLogin 
768          afsStartupScript:afsStartupScriptPath 
769          afsBasePath:[afsProperty path] afsdPath:afsdPath];
770          */
771         const char *startupConfigureOption[] = {"start_afs_at_startup", [afsStartupScriptPath  UTF8String],  [afsdPath UTF8String], [[afsProperty path]  UTF8String], 0L};
772         if([[AuthUtil shared] autorize] == noErr) {
773                 if(startAFSAtLogin) {
774                         [[AuthUtil shared] execUnixCommand:[rootHelperApp UTF8String] 
775                                                                                   args:startupConfigureOption
776                                                                                 output:nil];
777                         
778                         [[AuthUtil shared] execUnixCommand:launchctlExecutable 
779                                                                                   args:startAfsArgs
780                                                                                 output:nil];
781                 } else {
782                         //now disable the launchd configuration
783                         [[AuthUtil shared] execUnixCommand:launchctlExecutable
784                                                                                   args:stopAfsArgs
785                                                                                 output:nil];
786                 }
787         }
788 }
789
790
791 // -------------------------------------------------------------------------------
792 //  afsMenuActivationEvent:
793 // -------------------------------------------------------------------------------
794 - (IBAction) krb5KredentialAtLoginTimeEvent:(id) sender {
795         //
796         NSString *rootHelperApp = [[self bundle] pathForResource:@"afshlp" ofType:@""];
797         const char *args[] = {"enable_krb5_startup", [[installKRB5AuthAtLoginButton stringValue] UTF8String], "", 0L};
798         
799         //Check helper app
800         [self repairHelperTool];
801         if([[AuthUtil shared] autorize] == noErr) {
802                 [[AuthUtil shared] execUnixCommand:[rootHelperApp UTF8String] 
803                                                                           args:args
804                                                                         output:nil];
805                 
806                 //check if all is gone well
807                 [installKRB5AuthAtLoginButton setState:[PListManager checkKrb5AtLoginTimeLaunchdEnable]];
808         }
809 }
810
811 // -------------------------------------------------------------------------------
812 //  afsMenuActivationEvent:
813 // -------------------------------------------------------------------------------
814 -(IBAction) afsMenuActivationEvent:(id) sender
815 {
816         CFPreferencesSetValue((CFStringRef)PREFERENCE_SHOW_STATUS_MENU, 
817                                                   (CFNumberRef)[NSNumber numberWithBool:[afsMenucheckBox state]], 
818                                                   (CFStringRef)kAfsCommanderID, kCFPreferencesCurrentUser, kCFPreferencesAnyHost);
819         
820         CFPreferencesSynchronize((CFStringRef)kAfsCommanderID,  kCFPreferencesAnyUser, kCFPreferencesAnyHost);
821         CFPreferencesSynchronize((CFStringRef)kAfsCommanderID,  kCFPreferencesCurrentUser, kCFPreferencesAnyHost);
822         
823         //notify the backgrounder
824         [[NSDistributedNotificationCenter defaultCenter] postNotificationName:kAFSMenuExtraID object:kMExtraAFSMenuChangeState];
825 }
826
827 // -------------------------------------------------------------------------------
828 //  searchCellTextEvent:
829 //              Fileter the CellServDB list according to NSSearch content
830 // -------------------------------------------------------------------------------
831 - (IBAction) searchCellTextEvent:(id) sender
832 {
833         
834         NSString *searchText = [[textSearchField stringValue] lowercaseString]; //filter string
835         [self filterCellServDB:searchText];
836         [((NSTableView*)cellList) reloadData];
837 }
838
839 // -------------------------------------------------------------------------------
840 //  clearCellServDBFiltering:
841 //              clear the NSSearchField and showw all CellServDB table
842 // -------------------------------------------------------------------------------
843 - (void) clearCellServDBFiltering {
844         //Clear the text search
845         [textSearchField setStringValue:@""];
846         //load the temp array with all cell servdb
847         [self searchCellTextEvent:nil];
848 }
849 // --------------------------------------o-----------------------------------------
850 //  filterCellServDB:
851 //  make the NSMutableArray with all cellservdb or filtered element
852 // -------------------------------------------------------------------------------
853 - (void) filterCellServDB:(NSString*)textToFilter {
854         DBCellElement *cellElement; //Filtered element
855         BOOL doFilter = !(textToFilter == nil || ([textToFilter length] == 0));
856         
857         // We can do filtering and make the temp array
858         if(filteredCellDB){
859                 [filteredCellDB release];
860         }
861         filteredCellDB = [[NSMutableArray alloc] init];
862         NSEnumerator *e = [[afsProperty getCellList] objectEnumerator];
863         while(cellElement = (DBCellElement*)[e nextObject]) {
864                 // check if the element can be get
865                 if(doFilter) {
866                         //Get the CellServDB array enumerator
867                         NSRange rsltRng = [[[cellElement getCellName] lowercaseString] rangeOfString:textToFilter];
868                    if(rsltRng.location != NSNotFound) {
869                         //we can add this cell to filtered
870                         [filteredCellDB addObject:[cellElement retain]];
871                    }
872                 } else {
873                         [filteredCellDB addObject:[cellElement retain]];
874
875                 }
876         }
877 }
878                    
879 // -------------------------------------------------------------------------------
880 //  getCurrentCellInDB:
881 // -------------------------------------------------------------------------------
882 - (DBCellElement*) getCurrentCellInDB
883 {
884         int rowSelected = [((NSTableView *) cellList) selectedRow];
885         return [self getCellByIDX:rowSelected];
886 }
887
888 // -------------------------------------------------------------------------------
889 //  getCurrentCellInDB:
890 // -------------------------------------------------------------------------------
891 - (DBCellElement*) getCellByIDX:(int) idx
892 {
893         //NSMutableArray *cellArray = [afsProperty getCellList];
894         DBCellElement *cellElement =  (DBCellElement*)[filteredCellDB objectAtIndex:idx];
895         return cellElement;
896 }
897
898 // -------------------------------------------------------------------------------
899 //  showMessage:
900 // -------------------------------------------------------------------------------
901 -(void) showMessage:(NSString*) message{
902         NSAlert *alert = [[NSAlert alloc] init];
903         
904         [alert setMessageText:message];
905         [alert beginSheetModalForWindow:[[self mainView] window]
906                                           modalDelegate:nil 
907                                          didEndSelector:nil
908                                                 contextInfo:nil];
909         [alert release];
910 }
911
912 // -------------------------------------------------------------------------------
913 //  manageButtonState:
914 // -------------------------------------------------------------------------------
915 -(void) manageButtonState:(int) rowSelected {
916         [((NSControl*) cellIpButton) setEnabled:rowSelected >= 0];
917         [((NSControl*) removeCellButton) setEnabled:rowSelected >= 0];
918 }
919
920 // -------------------------------------------------------------------------------
921 //  setAfsStatus:
922 // -------------------------------------------------------------------------------
923 -(void) setAfsStatus
924 {
925         BOOL afsIsUp = [afsProperty checkAfsStatus];
926         [((NSButton *)startStopButton) setTitle: (afsIsUp?kAfsButtonShutdown:kAfsButtonStartup)];
927         
928         NSMutableAttributedString *colorTitle =[[NSMutableAttributedString alloc] initWithAttributedString:[((NSButton *)startStopButton) attributedTitle]];
929     NSRange titleRange = NSMakeRange(0, [colorTitle length]);
930         
931     [colorTitle addAttribute:NSForegroundColorAttributeName
932                        value:(afsIsUp?[NSColor redColor]:[NSColor blackColor])
933                        range:titleRange];
934         
935     [((NSButton *)startStopButton) setAttributedTitle:colorTitle];
936         
937         if(afsIsUp) {
938                 [self startTimer];
939         } else {
940                 [self stopTimer];
941         }
942 }
943
944 // -------------------------------------------------------------------------------
945 //  refreshToken:
946 // -------------------------------------------------------------------------------
947 - (void) refreshTokens:(NSTimer*)theTimer;
948 {
949         if(![tokensLock tryLock]) return;
950         if(tokenList){
951                 [tokenList release];
952         }
953         
954         tokenList = [afsProperty getTokenList];
955         [((NSTableView*)tokensTable) reloadData];
956         [tokensLock unlock];
957 }
958
959 // -------------------------------------------------------------------------------
960 //  removeExtra:
961 // -------------------------------------------------------------------------------
962 - (IBAction) addLink:(id) sender {
963         [NSBundle loadNibNamed:@"SymLinkEdit" owner:self];
964         
965         [NSApp beginSheet: lyncCreationSheet
966            modalForWindow: [[self mainView] window]
967                 modalDelegate: self
968            didEndSelector: @selector(didEndSymlinkSheet:returnCode:contextInfo:)
969                   contextInfo: nil];
970         
971 }
972
973 // -------------------------------------------------------------------------------
974 //  removeExtra:
975 // -------------------------------------------------------------------------------
976 - (IBAction) removeLink:(id) sender {
977         
978 }
979
980 // -------------------------------------------------------------------------------
981 //  removeExtra:
982 // -------------------------------------------------------------------------------
983 - (IBAction) enableLink:(id) sender {
984         
985 }
986
987 // -------------------------------------------------------------------------------
988 //  removeExtra:
989 // -------------------------------------------------------------------------------
990 - (IBAction) manageBackgrounderActivation:(id)sender {
991         [PListManager launchctlCommand:[(NSButton*)sender state] 
992                                                 userDomain:YES 
993                                                         option:[NSArray arrayWithObjects:@"-S", @"Aqua", nil] 
994                                                  plistName:[NSString stringWithFormat:@"%@.plist", BACKGROUNDER_P_FILE]];
995         //re ad the status to check taht all is gone well
996         [backgrounderActivationCheck setState:[PListManager launchdJobState:BACKGROUNDER_P_FILE]];
997 }
998
999
1000 // -------------------------------------------------------------------------------
1001 //  - (void)tabView:(NSTabView *)tabView willSelectTabViewItem: (NSTabViewItem *)tabViewItem
1002 // -------------------------------------------------------------------------------
1003 - (void)tabView:(NSTabView *)tabView willSelectTabViewItem: (NSTabViewItem *)tabViewItem 
1004 {
1005         //check to see if the cache param tab is the tab that will be selected
1006         if([((NSString*)[tabViewItem identifier]) intValue] == TAB_LINK)
1007         {
1008                 [ViewUtility enbleDisableControlView:[tabViewItem view]
1009                                                                 controlState:NO];
1010         }
1011 }
1012
1013 @end
1014
1015 @implementation AFSCommanderPref (NSTableDataSource)
1016
1017
1018 // -------------------------------------------------------------------------------
1019 //  tableView:
1020 //              Manage the checkbox of CellServDB Table
1021
1022 // -------------------------------------------------------------------------------
1023 - (void)tableView:(NSTableView *)table 
1024    setObjectValue:(id)data 
1025    forTableColumn:(NSTableColumn *)col 
1026                           row:(int)row
1027 {
1028         NSString *identifier = (NSString*)[col identifier];
1029         switch([table tag]){
1030                 case TABLE_TOKENS_LIST:
1031                         break;
1032                         
1033                 case TABLE_CELL_LIST:
1034                         // we are editing checkbox for cellservdb table
1035                         if([identifier intValue] == CELLSRVDB_TABLE_USR_DFLT_CHECK_COLUMN) {
1036                                 // set the user default cell
1037                                 DBCellElement *cellElement =  (DBCellElement*)[filteredCellDB objectAtIndex:row];
1038                                 [afsProperty setDefaultCellByName:[cellElement getCellName]];
1039                                 //[afsDefaultCellLabel setStringValue:[afsProperty getDefaultCellName]];
1040                                 [((NSTableView*)cellList) reloadData];
1041                         } else if([identifier intValue] == CELLSRVDB_TABLE_DFLT_CHECK_COLUMN) {
1042                                 // set the cell for wich the user want to get token
1043                                 DBCellElement *cellElement =  (DBCellElement*)[filteredCellDB objectAtIndex:row];
1044                                 [cellElement setUserDefaultForToken:![cellElement userDefaultForToken]];
1045                         }  
1046                         break;
1047         }
1048         
1049 }
1050
1051
1052 // -------------------------------------------------------------------------------
1053 //  tableView:
1054 //              refresh delegate method for two AFSCommander table
1055 // -------------------------------------------------------------------------------
1056 - (id)  tableView:(NSTableView *) aTableView
1057         objectValueForTableColumn:(NSTableColumn *) aTableColumn
1058                                                   row:(int) rowIndex
1059 {  
1060         
1061         id result = nil;
1062         NSString *identifier = (NSString*)[aTableColumn identifier];
1063         switch([aTableView tag]){
1064                 case TABLE_TOKENS_LIST:
1065                         //We are refreshing tokens table
1066                         result = [self getTableTokensListValue:[identifier intValue] row:rowIndex];
1067                         break;
1068                         
1069                 case TABLE_CELL_LIST:
1070                         //We are refreshing cell db table
1071                         result = [self getTableCelListValue:[identifier intValue] row:rowIndex];
1072                         break;
1073                 
1074         }
1075         return result;  
1076 }
1077
1078
1079 // -------------------------------------------------------------------------------
1080 //  getTableCelListValue:
1081 // -------------------------------------------------------------------------------
1082 - (id)getTableTokensListValue:(int) colId row:(int)row
1083 {
1084         id result = nil;
1085         if(!tokenList) return nil;
1086         switch(colId){
1087                 case 0:
1088                         result = (NSString*)[tokenList objectAtIndex:row];
1089                         break;
1090         }
1091         return result;
1092 }
1093
1094
1095 // -------------------------------------------------------------------------------
1096 //  getTableCelListValue:
1097 // -------------------------------------------------------------------------------
1098 - (id)getTableCelListValue:(int) colId row:(int)row
1099 {
1100         id result = nil;
1101         //NSMutableArray *cellArray = [afsProperty getCellList];
1102         DBCellElement *cellElement =  (DBCellElement*)[filteredCellDB objectAtIndex:row];
1103         switch(colId){
1104                 case CELLSRVDB_TABLE_USR_DFLT_CHECK_COLUMN:
1105                         result = [NSNumber numberWithInt:[cellElement userDefaultForCell]];
1106                         break;
1107                         
1108                 case CELLSRVDB_TABLE_DFLT_CHECK_COLUMN:
1109                         result = [NSNumber numberWithInt:[cellElement userDefaultForToken]];
1110                         break;
1111                 case CELLSRVDB_TABLE_NAME_COLUMN:
1112                         result = [cellElement getCellName];
1113                         break;
1114                         
1115                 case CELLSRVDB_TABLE_DESCRIPTION_COLUMN:
1116                         result = [cellElement getCellComment];
1117                         break;
1118         }
1119         return result;
1120 }
1121
1122 // -------------------------------------------------------------------------------
1123 //  numberOfRowsInTableView:
1124 // -------------------------------------------------------------------------------
1125 - (int)numberOfRowsInTableView:(NSTableView *)aTableView
1126 {
1127         int rowCount = 0;
1128         //NSMutableArray *cellArray = nil;
1129         switch([aTableView tag]){
1130                 case TABLE_TOKENS_LIST:
1131                         if(tokenList)  rowCount = [tokenList count];
1132                         break;
1133                         
1134                 case TABLE_CELL_LIST:
1135                         //cellArray = [afsProperty getCellList];
1136                         if(filteredCellDB)  rowCount = [filteredCellDB count];
1137                         break;
1138                         
1139         }       
1140         return rowCount;  
1141 }
1142 @end
1143
1144
1145 @implementation AFSCommanderPref (TableDelegate)
1146 // -------------------------------------------------------------------------------
1147 //  selectionShouldChangeInTableView:
1148 // -------------------------------------------------------------------------------
1149 - (BOOL)selectionShouldChangeInTableView:(NSTableView *)aTable
1150 {
1151         [self manageButtonState:[aTable selectedRow]];
1152         return YES;
1153 }
1154
1155 // -------------------------------------------------------------------------------
1156 //  tableView:
1157 // -------------------------------------------------------------------------------
1158 - (BOOL)tableView:(NSTableView *)aTable shouldSelectRow:(int)aRow
1159 {
1160         [self manageButtonState:aRow];
1161         return YES;
1162 }
1163
1164 @end
1165
1166
1167 @implementation AFSCommanderPref (ModalDelegate)
1168 // -------------------------------------------------------------------------------
1169 //  didEndSheet:
1170 // -------------------------------------------------------------------------------
1171 - (void)didEndSheet:(NSWindow *)sheet returnCode:(int)returnCode contextInfo:(void *)contextInfo
1172 {
1173     [sheet orderOut:self];
1174         //Filter the cellServDb and allocate filtered array
1175         [self searchCellTextEvent:nil];
1176         [((NSTableView*)cellList) reloadData];
1177 }
1178
1179 // -------------------------------------------------------------------------------
1180 //  Klog credential request
1181 // -------------------------------------------------------------------------------
1182 - (void)didEndCredentialSheet:(NSWindow *)sheet returnCode:(int)returnCode contextInfo:(void *)contextInfo
1183 {
1184         if([((TokenCredentialController*)credentialCommander) takenToken] == YES){
1185                 /*[AFSPropertyManager klog:[((TokenCredentialController*)credentialCommander) uName] 
1186                                                         uPwd:[((TokenCredentialController*)credentialCommander) uPwd] ];*/
1187                 [afsProperty getTokens:true 
1188                                                    usr:[((TokenCredentialController*)credentialCommander) uName] 
1189                                                    pwd:[((TokenCredentialController*)credentialCommander) uPwd]];
1190         }
1191     [sheet orderOut:self];
1192         [self refreshTokens:nil];
1193         //Inform afs menuextra to updata afs status
1194         [[NSDistributedNotificationCenter defaultCenter] postNotificationName:kAFSMenuExtraID object:kMExtraAFSStateChange];
1195
1196 }
1197
1198 // -------------------------------------------------------------------------------
1199 //  Klog credential request
1200 // -------------------------------------------------------------------------------
1201 - (void)didEndInfoSheet:(NSWindow *)sheet returnCode:(int)returnCode contextInfo:(void *)contextInfo
1202 {
1203         [sheet orderOut:self];
1204 }
1205
1206 // -------------------------------------------------------------------------------
1207 //  symlink edite
1208 // -------------------------------------------------------------------------------
1209 - (void)didEndSymlinkSheet:(NSWindow *)sheet returnCode:(int)returnCode contextInfo:(void *)contextInfo
1210 {
1211         [lyncCreationSheet orderOut:self];
1212 }
1213 @end