root/trunk/PassphraseRequester.m

Revision 118, 1.2 kB (checked in by bart, 1 year ago)

--

Line 
1 #import "Controller.h"
2
3 int main(int argc, const char *argv[])
4 {
5         NSProcessInfo *procinfo;
6         id UI;
7         NSAutoreleasePool *pool;
8         char *interaction;
9         NSString *passphrase;
10         NSString *sshkeychainToken = nil;
11
12         if(argc == 2)
13         {
14                 procinfo = [NSProcessInfo processInfo];
15                 pool = [[NSAutoreleasePool alloc] init];
16
17                 UI = [NSConnection rootProxyForConnectionWithRegisteredName:@"SSHKeychain" host:nil];
18
19                 if(UI == nil) {
20                         fprintf(stderr, "Can't connect to SSHKeychain\n");
21                         [pool release];
22                         exit(1);
23                 }
24                
25                 if(getenv("SSHKeychainToken"))
26                 {
27                         sshkeychainToken = [NSString stringWithCString:getenv("SSHKeychainToken")];
28                 }
29                
30                 [UI setProtocolForProxy:@protocol(UI)];
31
32                 interaction = getenv("INTERACTION");
33
34                 if((interaction) && (strcmp(interaction, "1") == 0))
35                 {
36                         passphrase = [UI askPassphrase:[[procinfo arguments] objectAtIndex:1] withToken:sshkeychainToken andInteraction:YES];
37                        
38                         if(passphrase == nil)
39                         {
40                                 [pool release];
41                                 exit(1);
42                         }
43                 }
44
45                 else
46                 {
47                         passphrase = [UI askPassphrase:[[procinfo arguments] objectAtIndex:1] withToken:sshkeychainToken andInteraction:NO];
48                        
49                         if(passphrase == nil)
50                         {
51                                 [pool release];
52                                 exit(1);
53                         }
54                 }
55
56                 printf("%s\n", [passphrase UTF8String]);
57
58                 [pool release];
59
60                 return 0;
61         }
62
63         return 1;
64 }
Note: See TracBrowser for help on using the browser.