Changeset 116
- Timestamp:
- 08/20/07 20:41:56 (1 year ago)
- Files:
-
- branches/eric/AgentController.m (modified) (6 diffs)
- branches/eric/Controller.m (modified) (1 diff)
- branches/eric/Libs/SSHAgent.m (modified) (1 diff)
- branches/eric/Libs/SSHKeychain.h (modified) (2 diffs)
- branches/eric/Libs/SSHKeychain.m (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/eric/AgentController.m
r111 r116 143 143 if((status & 1) && ([agent isRunning])) 144 144 { 145 [NSThread detachNewThreadSelector:@selector(addKeysToAgentWithoutInteractionInNewThread) 146 toTarget:self withObject:self]; 145 [keychain addKeysToAgentWithInteraction:NO]; 147 146 } 148 147 } … … 222 221 223 222 [allKeysOnAgentLock unlock]; 224 225 [NSThread detachNewThreadSelector:@selector(addKeysToAgentWithoutInteractionInNewThread) 226 toTarget:self withObject:self]; 223 224 [keychain addKeysToAgentWithInteraction:NO]; 227 225 } 228 226 } … … 281 279 allKeysOnAgent = YES; 282 280 [allKeysOnAgentLock unlock]; 281 282 if ([[NSUserDefaults standardUserDefaults] integerForKey:KeyTimeoutString] > 0) 283 { 284 // Self firing timer with reset 285 [[self class] cancelPreviousPerformRequestsWithTarget: self ]; 286 [self performSelector: @selector(removeKeysFromAgent:) 287 withObject: nil 288 afterDelay: [[NSUserDefaults standardUserDefaults] integerForKey:KeyTimeoutString] * 60.00 ]; 289 290 } 283 291 284 292 [[Controller sharedController] setStatus:YES]; … … 336 344 && (![keychain addingKeys]) && (status & 1) && ([agent isRunning])) 337 345 { 338 [NSThread detachNewThreadSelector:@selector(addKeysToAgentWithoutInteractionInNewThread) 339 toTarget:self withObject:self]; 346 [keychain addKeysToAgentWithInteraction:NO]; 340 347 } 341 348 … … 444 451 if([agent isRunning]) 445 452 { 453 446 454 [NSThread detachNewThreadSelector:@selector(addKeysToAgentInNewThread) 447 455 toTarget:self withObject:nil]; … … 465 473 inMainThread:YES]; 466 474 } 467 468 [pool release];469 }470 471 - (void)addKeysToAgentWithoutInteractionInNewThread472 {473 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];474 475 [keychain addKeysToAgentWithInteraction:NO];476 475 477 476 [pool release]; branches/eric/Controller.m
r110 r116 39 39 40 40 conn = [NSConnection defaultConnection]; 41 41 42 42 [conn runInNewThread]; 43 43 [conn removeRunLoop:[NSRunLoop currentRunLoop]]; branches/eric/Libs/SSHAgent.m
r115 r116 639 639 [self setKeysOnAgent:nil]; 640 640 641 else if ([[notification name] isEqualToString:@"AgentFilled"]) 641 else if ([[notification name] isEqualToString:@"AgentFilled"]) 642 642 [self setKeysOnAgent:[[SSHAgent currentAgent] currentKeysOnAgent]]; 643 643 } branches/eric/Libs/SSHKeychain.h
r91 r116 10 10 BOOL addingKeys; 11 11 12 int lastScheduled;13 14 12 /* Locks */ 15 13 NSLock *keychainLock; 16 14 NSLock *addingKeysLock; 17 NSLock *lastScheduledLock;18 15 } 19 16 … … 40 37 - (BOOL)addKeysToAgent; 41 38 - (BOOL)addKeysToAgentWithInteraction:(BOOL)interaction; 42 - (void)removeKeysAfterTimeout:(id)object;43 39 - (BOOL)removeKeysFromAgent; 44 40 branches/eric/Libs/SSHKeychain.m
r92 r116 4 4 #import "SSHKey.h" 5 5 #import "SSHTool.h" 6 #import "SSHAgent.h" 6 7 7 8 #include <unistd.h> … … 33 34 keychainLock = [[NSLock alloc] init]; 34 35 addingKeysLock = [[NSLock alloc] init]; 35 lastScheduledLock = [[NSLock alloc] init];36 lastScheduled = -1;37 36 38 37 [self resetToKeysWithPaths:paths]; … … 51 50 [keychainLock release]; 52 51 [addingKeysLock release]; 53 [lastScheduledLock release];54 52 [agentSocketPath release]; 55 53 … … 109 107 } 110 108 111 - (int) lastScheduled112 {113 [lastScheduledLock lock];114 int returnInt = lastScheduled;115 [lastScheduledLock unlock];116 117 return returnInt;118 }119 120 - (void) setLastScheduled:(int) scheduledTime121 {122 [lastScheduledLock lock];123 lastScheduled = scheduledTime;124 [lastScheduledLock unlock];125 }126 109 127 110 /* Returns the SSHKey at Index nr. */ … … 208 191 return YES; 209 192 210 if (! agentSocketPath || ![[NSFileManager defaultManager] isReadableFileAtPath:agentSocketPath])193 if (![[SSHAgent currentAgent] isRunning]) 211 194 return NO; 212 195 … … 247 230 } 248 231 249 if ([[NSUserDefaults standardUserDefaults] integerForKey:KeyTimeoutString] > 0)250 {251 int timeScheduled = time(nil);252 [self setLastScheduled:timeScheduled];253 254 [NSThread detachNewThreadSelector:@selector(removeKeysAfterTimeout:) toTarget:self255 withObject:[NSNumber numberWithInt:timeScheduled]];256 }257 258 232 [[NSNotificationCenter defaultCenter] postNotificationName:@"AgentFilled" object:nil]; 259 233 260 234 [self setAddingKeys:NO]; 261 235 return YES; 262 }263 264 /* Remove all keys from the ssh-agent from a NSTimer object. */265 - (void)removeKeysAfterTimeout:(id)object266 {267 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];268 int timeScheduled = [object intValue];269 270 sleep([[NSUserDefaults standardUserDefaults] integerForKey:KeyTimeoutString] * 60);271 272 /* If the time this timeout was scheduled is still the most recent, go ahead and remove the keys */273 if (timeScheduled == [self lastScheduled])274 [self removeKeysFromAgent];275 276 [pool release];277 236 } 278 237 … … 282 241 SSHTool *theTool = [SSHTool toolWithName:@"ssh-add"]; 283 242 284 [self setLastScheduled:-1]; 285 286 if (!agentSocketPath || ![[NSFileManager defaultManager] isReadableFileAtPath:agentSocketPath]) 243 if (![[SSHAgent currentAgent] isRunning]) 287 244 return NO; 288 245
