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