| 669 | | NSAutoreleasePool *pool; |
|---|
| 670 | | NSMutableDictionary *dict; |
|---|
| 671 | | |
|---|
| 672 | | pool = [[NSAutoreleasePool alloc] init]; |
|---|
| 673 | | |
|---|
| | 669 | NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; |
|---|
| | 670 | int currentPID = [self pid]; |
|---|
| | 671 | while (getpgid(currentPID) != -1) |
|---|
| | 672 | { |
|---|
| | 673 | /* The agent is still alive, so sleep for a while before checking again */ |
|---|
| | 674 | sleep(30); |
|---|
| | 675 | |
|---|
| | 676 | /* If the PID has changed while we were sleeping then the agent has been stopped and restarted. |
|---|
| | 677 | In this instance a new thread would have been spawned to monitor the new agent, and the agent |
|---|
| | 678 | we were monitoring will no longer exist. Exit early to avoid notifying the user that the old |
|---|
| | 679 | agent is gone */ |
|---|
| | 680 | if (currentPID != [self pid]) |
|---|
| | 681 | { |
|---|
| | 682 | [pool release]; |
|---|
| | 683 | return; |
|---|
| | 684 | } |
|---|
| | 685 | } |
|---|
| | 686 | |
|---|
| | 687 | [self stop]; |
|---|
| | 688 | |
|---|
| | 689 | /* Dictionary for the panel. */ |
|---|
| | 690 | NSMutableDictionary *dict = [NSMutableDictionary dictionary]; |
|---|
| | 691 | |
|---|
| | 692 | [dict setObject:local(@"AgentTerminatedPanelTitle") forKey:(NSString *)kCFUserNotificationAlertHeaderKey]; |
|---|
| | 693 | [dict setObject:local(@"AgentTerminatedPanelText") forKey:(NSString *)kCFUserNotificationAlertMessageKey]; |
|---|
| | 694 | |
|---|
| | 695 | [dict setObject:[NSURL fileURLWithPath:[[[NSBundle mainBundle] resourcePath] |
|---|
| | 696 | stringByAppendingString:@"/SSHKeychain.icns"]] forKey:(NSString *)kCFUserNotificationIconURLKey]; |
|---|
| | 697 | |
|---|
| | 698 | [dict setObject:local(@"Yes") forKey:(NSString *)kCFUserNotificationDefaultButtonTitleKey]; |
|---|
| | 699 | [dict setObject:local(@"No") forKey:(NSString *)kCFUserNotificationAlternateButtonTitleKey]; |
|---|
| | 700 | |
|---|
| | 701 | /* Display a passphrase request notification. */ |
|---|
| 677 | | |
|---|
| 678 | | while(true) |
|---|
| 679 | | { |
|---|
| 680 | | if(getpgid([self pid]) == -1) |
|---|
| 681 | | { |
|---|
| 682 | | [self stop]; |
|---|
| 683 | | |
|---|
| 684 | | /* Dictionary for the panel. */ |
|---|
| 685 | | dict = [NSMutableDictionary dictionary]; |
|---|
| 686 | | |
|---|
| 687 | | [dict setObject:local(@"AgentTerminatedPanelTitle") forKey:(NSString *)kCFUserNotificationAlertHeaderKey]; |
|---|
| 688 | | [dict setObject:local(@"AgentTerminatedPanelText") forKey:(NSString *)kCFUserNotificationAlertMessageKey]; |
|---|
| 689 | | |
|---|
| 690 | | [dict setObject:[NSURL fileURLWithPath:[[[NSBundle mainBundle] resourcePath] |
|---|
| 691 | | stringByAppendingString:@"/SSHKeychain.icns"]] forKey:(NSString *)kCFUserNotificationIconURLKey]; |
|---|
| 692 | | |
|---|
| 693 | | [dict setObject:local(@"Yes") forKey:(NSString *)kCFUserNotificationDefaultButtonTitleKey]; |
|---|
| 694 | | [dict setObject:local(@"No") forKey:(NSString *)kCFUserNotificationAlternateButtonTitleKey]; |
|---|
| 695 | | |
|---|
| 696 | | /* Display a passphrase request notification. */ |
|---|
| 697 | | notification = CFUserNotificationCreate(nil, 30, CFUserNotificationSecureTextField(0), &error, (CFDictionaryRef)dict); |
|---|
| 698 | | |
|---|
| 699 | | /* If we couldn't receive a response, return nil. */ |
|---|
| 700 | | if((error) || (CFUserNotificationReceiveResponse(notification, 0, &response))) |
|---|
| 701 | | { |
|---|
| 702 | | return; |
|---|
| 703 | | } |
|---|
| 704 | | |
|---|
| 705 | | /* If OK was pressed, add the keys. */ |
|---|
| 706 | | if((response & 0x3) == kCFUserNotificationDefaultResponse) |
|---|
| 707 | | { |
|---|
| 708 | | [self start]; |
|---|
| 709 | | } |
|---|
| 710 | | |
|---|
| 711 | | break; |
|---|
| 712 | | } |
|---|
| 713 | | sleep(30); |
|---|
| 714 | | } |
|---|
| | 704 | CFUserNotificationRef notification = CFUserNotificationCreate(nil, 30, CFUserNotificationSecureTextField(0), &error, (CFDictionaryRef)dict); |
|---|
| | 705 | |
|---|
| | 706 | /* If we couldn't receive a response, return nil. */ |
|---|
| | 707 | if (error || CFUserNotificationReceiveResponse(notification, 0, &response)) |
|---|
| | 708 | { |
|---|
| | 709 | [pool release]; |
|---|
| | 710 | return; |
|---|
| | 711 | } |
|---|
| | 712 | |
|---|
| | 713 | /* If OK was pressed, add the keys. */ |
|---|
| | 714 | if ((response & 0x3) == kCFUserNotificationDefaultResponse) |
|---|
| | 715 | [self start]; |
|---|
| | 716 | |
|---|