@@ -137,7 +137,6 @@ -(NSPanel*)passwordPanel:(NSString *)prompt remember:(BOOL)remember
137
137
[rememberCheck setButtonType: NSSwitchButton ];
138
138
[rememberCheck setTarget: self ];
139
139
[rememberCheck setTitle: @" Remenber" ]; // +++ Localize.
140
- [rememberCheck setKeyEquivalent: @" \r " ];
141
140
[[mPasswordPanel contentView ] addSubview: rememberCheck];
142
141
}
143
142
@@ -162,15 +161,17 @@ -(NSPanel*)passwordPanel:(NSString *)prompt remember:(BOOL)remember
162
161
-(IBAction ) doOKButton : (id )sender
163
162
{
164
163
NSString *pas=[mPasswordField stringValue ];
165
- printf ( " %s \n " , [pas UTF8String ] );
166
164
167
- StorePasswordKeychain ([url cStringUsingEncoding: NSASCIIStringEncoding],
168
- [url lengthOfBytesUsingEncoding: NSASCIIStringEncoding],
169
- [pas cStringUsingEncoding: NSASCIIStringEncoding],
170
- [pas lengthOfBytesUsingEncoding: NSASCIIStringEncoding]); // Call
171
-
172
-
173
- [[NSApplication sharedApplication ] stopModalWithCode: 0 ];
165
+ if ((rememberCheck!=nil ) && [rememberCheck state ]==NSOnState ) {
166
+ OSStatus status = StorePasswordKeychain ([url cStringUsingEncoding: NSASCIIStringEncoding],
167
+ [url lengthOfBytesUsingEncoding: NSASCIIStringEncoding],
168
+ [pas cStringUsingEncoding: NSASCIIStringEncoding],
169
+ [pas lengthOfBytesUsingEncoding: NSASCIIStringEncoding]); // Call
170
+ if (status != noErr) {
171
+ [[NSApplication sharedApplication ] stopModalWithCode: -1 ];
172
+ }
173
+ }
174
+ [[NSApplication sharedApplication ] stopModalWithCode: 0 ];
174
175
}
175
176
176
177
@@ -179,7 +180,7 @@ -(IBAction) doOKButton: (id)sender
179
180
// many times the remote server allows failed attempts.
180
181
-(IBAction ) doCancelButton : (id )sender
181
182
{
182
- [[NSApplication sharedApplication ] stopModalWithCode: 1 ];
183
+ [[NSApplication sharedApplication ] stopModalWithCode: - 1 ];
183
184
}
184
185
185
186
@end
@@ -310,36 +311,41 @@ int main( int argc, const char* argv[] )
310
311
311
312
url=@" poipoi" ;
312
313
314
+ BOOL remember=NO ;
315
+
313
316
if ([cmd hasPrefix: @" git-remote-https" ]){
314
317
NSArray *args=[cmd componentsSeparatedByString: @" " ];
315
318
url=[args objectAtIndex: [args count ]-1 ];
319
+ prompt=[NSString stringWithFormat: @" %@ %@ " ,[NSString stringWithCString: argv[1 ] encoding: NSASCIIStringEncoding],url];
320
+ remember=YES ;
316
321
}else if ((sizeof (argv)/sizeof (char *))>1 ){
317
322
prompt=[NSString stringWithCString: argv[1 ] encoding: NSASCIIStringEncoding];
318
- }else {
319
- prompt=@" null" ;
323
+ }else { // only for test
324
+ remember=YES ;
325
+ prompt=[NSString stringWithFormat: @" %???? %@ " ,url];
320
326
}
321
327
322
-
323
- OSStatus status,status1;
324
328
void *passwordData = nil ;
325
329
SecKeychainItemRef itemRef = nil ;
326
330
UInt32 passwordLength = nil ;
327
331
328
- status1 = GetPasswordKeychain ([url cStringUsingEncoding: NSASCIIStringEncoding],[url lengthOfBytesUsingEncoding: NSASCIIStringEncoding],&passwordData,&passwordLength,&itemRef);
329
- if (status1 == noErr) {
332
+ OSStatus status = GetPasswordKeychain ([url cStringUsingEncoding: NSASCIIStringEncoding],[url lengthOfBytesUsingEncoding: NSASCIIStringEncoding],&passwordData,&passwordLength,&itemRef);
333
+ printf ( " status= %d \n " ,status);
334
+ if (status == noErr) {
330
335
SecKeychainItemFreeContent (NULL ,passwordData);
336
+ NSString *pas=[NSString stringWithCString: passwordData encoding: NSASCIIStringEncoding];
337
+ printf ( " %s \n " , [pas UTF8String ] );
338
+ return 0 ;
339
+ }else if (status != errSecItemNotFound) {
340
+ return -1 ;
331
341
}
332
-
342
+
333
343
NSInteger code;
334
344
335
- if (passwordLength>0 ){
336
- NSString *pass=[NSString stringWithCString: passwordData encoding: NSASCIIStringEncoding];
337
- }else {
338
- NSWindow *passPanel = [appDel passwordPanel: prompt remember: NO ];
339
- [app activateIgnoringOtherApps: YES ];
340
- [passPanel makeKeyAndOrderFront: nil ];
341
- code = [app runModalForWindow: passPanel];
342
- }
345
+ NSWindow *passPanel = [appDel passwordPanel: prompt remember: remember];
346
+ [app activateIgnoringOtherApps: YES ];
347
+ [passPanel makeKeyAndOrderFront: nil ];
348
+ code = [app runModalForWindow: passPanel];
343
349
344
350
[defaults synchronize ];
345
351
0 commit comments