29
29
#define PASSLABELHEIGHT 16.0
30
30
#define WINDOWAUTOSAVENAME @" GitXAskPasswordWindowFrame"
31
31
32
+ // In 10.6, some NSObject categories (like NSWindowDelegate) were changed to
33
+ // protocols. Thus to avoid warnings we need to add protocol specifiers, but
34
+ // only when compiling for 10.6+.
35
+ #ifndef MAC_OS_X_VERSION_10_6
36
+ #define MAC_OS_X_VERSION_10_6 1060
37
+ #endif
32
38
33
- @interface GAPAppDelegate : NSObject /* <NSApplicationDelegate>*/
39
+ #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
40
+ #define PROTOCOL_10_6 (...) <__VA_ARGS__>
41
+ #else
42
+ #define PROTOCOL_10_6 (...)
43
+ #endif
44
+
45
+ @interface GAPAppDelegate : NSObject PROTOCOL_10_6(NSApplicationDelegate)
34
46
{
35
47
}
36
48
@@ -50,7 +62,7 @@ -(void)yesNo:(NSString *)prompt url:(NSString *)url{
50
62
[alert setInformativeText: prompt];
51
63
[alert setAlertStyle: NSWarningAlertStyle ];
52
64
NSInteger result = [alert runModal ];
53
-
65
+
54
66
Boolean yes=NO ;
55
67
if ( result == NSAlertFirstButtonReturn ) {
56
68
yes=YES ;
@@ -213,38 +225,49 @@ int main( int argc, const char* argv[] )
213
225
214
226
NSApplication *app = [NSApplication sharedApplication ];
215
227
GAPAppDelegate *appDel = [[GAPAppDelegate alloc ] init ];
216
- [app setDelegate: appDel];
228
+ [app setDelegate: appDel];
217
229
218
230
219
- char args [4024 ];
220
- getproclline (getppid (),args );
221
- NSString *cmd=[NSString stringWithFormat: @" %@ " ,[NSString stringWithUTF8String: args ]];
231
+ char c_args [4024 ];
232
+ getproclline (getppid (),c_args );
233
+ NSString *cmd=[NSString stringWithFormat: @" %@ " ,[NSString stringWithUTF8String: c_args ]];
222
234
223
235
NSLog (@" cmd: '%@ '" ,cmd);
224
236
225
- if ([cmd hasPrefix: @" git-remote" ]){
226
- NSArray *args=[cmd componentsSeparatedByString: @" " ];
227
- NSString *url=[args objectAtIndex: [args count ]-1 ];
228
-
229
- void *passwordData = nil ;
230
- SecKeychainItemRef itemRef = nil ;
231
- UInt32 passwordLength = 0 ;
232
-
233
- OSStatus status = GetPasswordKeychain ([url cStringUsingEncoding: NSASCIIStringEncoding],[url lengthOfBytesUsingEncoding: NSASCIIStringEncoding],&passwordData,&passwordLength,&itemRef);
234
- if (status == noErr) {
235
- SecKeychainItemFreeContent (NULL ,passwordData);
236
- NSString *pas=[[NSString stringWithCString: passwordData encoding: NSASCIIStringEncoding] substringToIndex: passwordLength];
237
- printf ( " %s " , [pas UTF8String ] );
238
- return 0 ;
237
+ NSString *prompt;
238
+ NSString *url;
239
+ BOOL yesno=NO ;
240
+ NSArray *args=[cmd componentsSeparatedByString: @" " ];
241
+
242
+ if (argc<1 ){
243
+ prompt=@" Enter your OpenSSH passphrase:" ;
244
+ url=@" private key" ;
245
+ }else {
246
+ prompt=[NSString stringWithFormat: @" %@ " ,[NSString stringWithCString: argv[1 ] encoding: NSASCIIStringEncoding]];
247
+ if ([[prompt lowercaseString ] rangeOfString: @" yes/no" ].location ==NSNotFound ){
248
+ url=[args objectAtIndex: [args count ]-1 ];
249
+ }else {
250
+ yesno=YES ;
251
+ url=[args objectAtIndex: 1 ];
239
252
}
240
-
241
- NSString *prompt=[NSString stringWithFormat: @" %@ " ,[NSString stringWithCString: argv[1 ] encoding: NSASCIIStringEncoding]];
242
- [appDel pasword: prompt url: url];
243
- }else { // yes/no?
244
- NSString *prompt=[NSString stringWithFormat: @" %@ " ,[NSString stringWithCString: argv[1 ] encoding: NSASCIIStringEncoding]];
245
- NSArray *args=[cmd componentsSeparatedByString: @" " ];
246
- NSString *url=[args objectAtIndex: 1 ];
253
+ }
254
+
255
+ void *passwordData = nil ;
256
+ SecKeychainItemRef itemRef = nil ;
257
+ UInt32 passwordLength = 0 ;
258
+
259
+ OSStatus status = GetPasswordKeychain ([url cStringUsingEncoding: NSASCIIStringEncoding],[url lengthOfBytesUsingEncoding: NSASCIIStringEncoding],&passwordData,&passwordLength,&itemRef);
260
+ if (status == noErr) {
261
+ SecKeychainItemFreeContent (NULL ,passwordData);
262
+ NSString *pas=[[NSString stringWithCString: passwordData encoding: NSASCIIStringEncoding] substringToIndex: passwordLength];
263
+ printf ( " %s " , [pas UTF8String ] );
264
+ return 0 ;
265
+ }
266
+
267
+ if (yesno){
247
268
[appDel yesNo: prompt url: url];
269
+ }else {
270
+ [appDel pasword: prompt url: url];
248
271
}
249
272
250
273
return 0 ;
0 commit comments