mirror of
https://github.com/kennethreitz-archive/gitx.git
synced 2026-06-05 23:40:18 +00:00
initial test
This commit is contained in:
@@ -82,6 +82,9 @@
|
||||
91B103CC0E898EC300C84364 /* PBIconAndTextCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 91B103CB0E898EC300C84364 /* PBIconAndTextCell.m */; };
|
||||
93CB42C20EAB7B2200530609 /* PBGitDefaults.m in Sources */ = {isa = PBXBuildFile; fileRef = 93CB42C10EAB7B2200530609 /* PBGitDefaults.m */; };
|
||||
93F7857F0EA3ABF100C1F443 /* PBCommitMessageView.m in Sources */ = {isa = PBXBuildFile; fileRef = 93F7857E0EA3ABF100C1F443 /* PBCommitMessageView.m */; };
|
||||
C3B13DD812F3A89D0045437C /* SecurityFoundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C3B13DD712F3A89D0045437C /* SecurityFoundation.framework */; };
|
||||
C3B13DE412F3A8D70045437C /* Security.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C3B13DE312F3A8D70045437C /* Security.framework */; };
|
||||
C3B13E2312F3A9130045437C /* Security.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C3B13DE312F3A8D70045437C /* Security.framework */; };
|
||||
D26DC6450E782C9000C777B2 /* gitx.icns in Resources */ = {isa = PBXBuildFile; fileRef = D26DC6440E782C9000C777B2 /* gitx.icns */; };
|
||||
D8022FE811E124A0003C21F6 /* PBGitXMessageSheet.xib in Resources */ = {isa = PBXBuildFile; fileRef = D8022FE711E124A0003C21F6 /* PBGitXMessageSheet.xib */; };
|
||||
D8022FED11E124C8003C21F6 /* PBGitXMessageSheet.m in Sources */ = {isa = PBXBuildFile; fileRef = D8022FEC11E124C8003C21F6 /* PBGitXMessageSheet.m */; };
|
||||
@@ -375,6 +378,8 @@
|
||||
93F7857D0EA3ABF100C1F443 /* PBCommitMessageView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PBCommitMessageView.h; sourceTree = "<group>"; };
|
||||
93F7857E0EA3ABF100C1F443 /* PBCommitMessageView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PBCommitMessageView.m; sourceTree = "<group>"; };
|
||||
93FCCBA80EA8AF450061B02B /* PBGitConfig.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PBGitConfig.m; sourceTree = "<group>"; };
|
||||
C3B13DD712F3A89D0045437C /* SecurityFoundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SecurityFoundation.framework; path = System/Library/Frameworks/SecurityFoundation.framework; sourceTree = SDKROOT; };
|
||||
C3B13DE312F3A8D70045437C /* Security.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Security.framework; path = System/Library/Frameworks/Security.framework; sourceTree = SDKROOT; };
|
||||
D26DC6440E782C9000C777B2 /* gitx.icns */ = {isa = PBXFileReference; lastKnownFileType = image.icns; path = gitx.icns; sourceTree = "<group>"; };
|
||||
D8022A3411DFCCA5003C21F6 /* build_libgit2.sh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.sh; path = build_libgit2.sh; sourceTree = "<group>"; };
|
||||
D8022FE711E124A0003C21F6 /* PBGitXMessageSheet.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = PBGitXMessageSheet.xib; sourceTree = "<group>"; };
|
||||
@@ -573,6 +578,7 @@
|
||||
isa = PBXFrameworksBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
C3B13E2312F3A9130045437C /* Security.framework in Frameworks */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
@@ -588,6 +594,8 @@
|
||||
F5C580E50EDA250900995434 /* libgit2.a in Frameworks */,
|
||||
D8E3B2B810DC9FB2001096A3 /* ScriptingBridge.framework in Frameworks */,
|
||||
D87127011229A21C00012334 /* QuartzCore.framework in Frameworks */,
|
||||
C3B13DD812F3A89D0045437C /* SecurityFoundation.framework in Frameworks */,
|
||||
C3B13DE412F3A8D70045437C /* Security.framework in Frameworks */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
@@ -759,6 +767,7 @@
|
||||
F5886A120ED5D33D0066E74C /* SpeedTest-Info.plist */,
|
||||
F567CC3A106E6B910059BB9D /* GitXTesting-Info.plist */,
|
||||
D89E9AB21218A9DA0097A90B /* ScriptingBridge.framework */,
|
||||
C3B13DD712F3A89D0045437C /* SecurityFoundation.framework */,
|
||||
);
|
||||
name = GitTest;
|
||||
sourceTree = "<group>";
|
||||
@@ -838,6 +847,7 @@
|
||||
F5C580E40EDA250900995434 /* libgit2.a */,
|
||||
1058C7A0FEA54F0111CA2CBB /* Linked Frameworks */,
|
||||
1058C7A2FEA54F0111CA2CBB /* Other Frameworks */,
|
||||
C3B13DE312F3A8D70045437C /* Security.framework */,
|
||||
);
|
||||
name = Frameworks;
|
||||
sourceTree = "<group>";
|
||||
|
||||
+183
-11
@@ -9,6 +9,17 @@
|
||||
|
||||
#include <ApplicationServices/ApplicationServices.h>
|
||||
#import <AppKit/AppKit.h>
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
#include <sys/sysctl.h>
|
||||
#include <Security/Security.h>
|
||||
#include <CoreServices/CoreServices.h>
|
||||
#include <Security/SecKeychain.h>
|
||||
#include <Security/SecKeychainItem.h>
|
||||
#include <Security/SecAccess.h>
|
||||
#include <Security/SecTrustedApplication.h>
|
||||
#include <Security/SecACL.h>
|
||||
#include <CoreFoundation/CoreFoundation.h>
|
||||
|
||||
#define OKBUTTONWIDTH 100.0
|
||||
#define OKBUTTONHEIGHT 24.0
|
||||
@@ -23,19 +34,22 @@
|
||||
{
|
||||
NSPanel* mPasswordPanel;
|
||||
NSSecureTextField* mPasswordField;
|
||||
NSButton* rememberCheck;
|
||||
}
|
||||
|
||||
-(NSPanel*) passwordPanel;
|
||||
-(NSPanel*) passwordPanel;
|
||||
|
||||
-(IBAction) doOKButton: (id)sender;
|
||||
-(IBAction) doCancelButton: (id)sender;
|
||||
|
||||
@end
|
||||
|
||||
NSString* url;
|
||||
|
||||
|
||||
@implementation GAPAppDelegate
|
||||
|
||||
-(NSPanel*) passwordPanel
|
||||
-(NSPanel*)passwordPanel:(NSString *)prompt remember:(BOOL)remember
|
||||
{
|
||||
if( !mPasswordPanel )
|
||||
{
|
||||
@@ -67,7 +81,7 @@
|
||||
[okButton setBordered: YES];
|
||||
[okButton setBezelStyle: NSRoundedBezelStyle];
|
||||
[[mPasswordPanel contentView] addSubview: okButton];
|
||||
|
||||
|
||||
// Cancel:
|
||||
NSRect cancelBox = box;
|
||||
cancelBox.origin.x = NSMinX( okBox ) -CANCELBUTTONWIDTH -6;
|
||||
@@ -109,9 +123,24 @@
|
||||
[passwordLabel setBordered: NO];
|
||||
[passwordLabel setBezeled: NO];
|
||||
[passwordLabel setDrawsBackground: NO];
|
||||
[passwordLabel setStringValue: @"Please enter your password:"]; // +++ Localize.
|
||||
[passwordLabel setStringValue: prompt];
|
||||
[[mPasswordPanel contentView] addSubview: passwordLabel];
|
||||
|
||||
// remember buton:
|
||||
if(remember){
|
||||
NSRect rememberBox = box;
|
||||
rememberBox.origin.x = 100;
|
||||
rememberBox.size.width = CANCELBUTTONWIDTH;
|
||||
rememberBox.origin.y += 20;
|
||||
rememberBox.size.height = CANCELBUTTONHEIGHT;
|
||||
rememberCheck = [[NSButton alloc] initWithFrame: rememberBox];
|
||||
[rememberCheck setButtonType:NSSwitchButton];
|
||||
[rememberCheck setTarget: self];
|
||||
[rememberCheck setTitle: @"Remenber"]; // +++ Localize.
|
||||
[rememberCheck setKeyEquivalent: @"\r"];
|
||||
[[mPasswordPanel contentView] addSubview: rememberCheck];
|
||||
}
|
||||
|
||||
// GitX icon:
|
||||
NSRect gitxIconBox = box;
|
||||
gitxIconBox.origin.y = NSMaxY(box) - 78;
|
||||
@@ -132,7 +161,15 @@
|
||||
|
||||
-(IBAction) doOKButton: (id)sender
|
||||
{
|
||||
printf( "%s\n", [[mPasswordField stringValue] UTF8String] );
|
||||
NSString *pas=[mPasswordField stringValue];
|
||||
printf( "%s\n", [pas UTF8String] );
|
||||
|
||||
StorePasswordKeychain ([url cStringUsingEncoding:NSASCIIStringEncoding],
|
||||
[url lengthOfBytesUsingEncoding:NSASCIIStringEncoding],
|
||||
[pas cStringUsingEncoding:NSASCIIStringEncoding],
|
||||
[pas lengthOfBytesUsingEncoding:NSASCIIStringEncoding]); //Call
|
||||
|
||||
|
||||
[[NSApplication sharedApplication] stopModalWithCode: 0];
|
||||
}
|
||||
|
||||
@@ -147,9 +184,111 @@
|
||||
|
||||
@end
|
||||
|
||||
void getproclline(pid_t pid, char *command_name);
|
||||
|
||||
void getproclline(pid_t pid, char *command_name)
|
||||
{
|
||||
int mib[3], argmax, nargs, c = 0;
|
||||
size_t size;
|
||||
char *procargs, *sp, *np, *cp;
|
||||
|
||||
mib[0] = CTL_KERN;
|
||||
mib[1] = KERN_ARGMAX;
|
||||
|
||||
size = sizeof(argmax);
|
||||
if (sysctl(mib, 2, &argmax, &size, NULL, 0) == -1) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* Allocate space for the arguments. */
|
||||
procargs = (char *)malloc(argmax);
|
||||
if (procargs == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
mib[0] = CTL_KERN;
|
||||
mib[1] = KERN_PROCARGS2;
|
||||
mib[2] = pid;
|
||||
|
||||
size = (size_t)argmax;
|
||||
if (sysctl(mib, 3, procargs, &size, NULL, 0) == -1) {
|
||||
return;
|
||||
}
|
||||
|
||||
memcpy(&nargs, procargs, sizeof(nargs));
|
||||
cp = procargs + sizeof(nargs);
|
||||
|
||||
/* Skip the saved exec_path. */
|
||||
for (; cp < &procargs[size]; cp++) {
|
||||
if (*cp == '\0') {
|
||||
/* End of exec_path reached. */
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (cp == &procargs[size]) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* Skip trailing '\0' characters. */
|
||||
for (; cp < &procargs[size]; cp++) {
|
||||
if (*cp != '\0') {
|
||||
/* Beginning of first argument reached. */
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (cp == &procargs[size]) {
|
||||
return;
|
||||
}
|
||||
/* Save where the argv[0] string starts. */
|
||||
sp = cp;
|
||||
|
||||
for (np = NULL; c < nargs && cp < &procargs[size]; cp++) {
|
||||
if (*cp == '\0') {
|
||||
c++;
|
||||
if (np != NULL) {
|
||||
*np = ' ';
|
||||
}
|
||||
np = cp;
|
||||
}
|
||||
}
|
||||
sprintf(command_name, "%s",sp);
|
||||
}
|
||||
|
||||
OSStatus StorePasswordKeychain (const char *url, UInt32 urlLength, void* password,UInt32 passwordLength)
|
||||
{
|
||||
OSStatus status;
|
||||
status = SecKeychainAddGenericPassword (
|
||||
NULL, // default keychain
|
||||
4, // length of service name
|
||||
"GitX", // service name
|
||||
urlLength, // length of account name
|
||||
url, // account name
|
||||
passwordLength, // length of password
|
||||
password, // pointer to password data
|
||||
NULL // the item reference
|
||||
);
|
||||
return (status);
|
||||
}
|
||||
|
||||
OSStatus GetPasswordKeychain (const char *url, UInt32 urlLength ,void *passwordData,UInt32 *passwordLength,
|
||||
SecKeychainItemRef *itemRef)
|
||||
{
|
||||
OSStatus status ;
|
||||
status = SecKeychainFindGenericPassword (
|
||||
NULL, // default keychain
|
||||
4, // length of service name
|
||||
"GitX", // service name
|
||||
urlLength, // length of account name
|
||||
url, // account name
|
||||
passwordLength, // length of password
|
||||
passwordData, // pointer to password data
|
||||
itemRef // the item reference
|
||||
);
|
||||
return (status);
|
||||
}
|
||||
|
||||
|
||||
int main( int argc, const char** argv )
|
||||
int main( int argc, const char* argv[] )
|
||||
{
|
||||
// close stderr to stop cocoa log messages from being picked up by GitX
|
||||
close(STDERR_FILENO);
|
||||
@@ -162,14 +301,47 @@ int main( int argc, const char** argv )
|
||||
NSApplication *app = [NSApplication sharedApplication];
|
||||
GAPAppDelegate *appDel = [[GAPAppDelegate alloc] init];
|
||||
[app setDelegate: appDel];
|
||||
NSWindow *passPanel = [appDel passwordPanel];
|
||||
|
||||
[app activateIgnoringOtherApps: YES];
|
||||
[passPanel makeKeyAndOrderFront: nil];
|
||||
NSInteger code = [app runModalForWindow: passPanel];
|
||||
char args[4024];
|
||||
getproclline(getppid(),args);
|
||||
NSString *cmd=[NSString stringWithFormat:@"%@",[NSString stringWithUTF8String:args]];
|
||||
|
||||
NSString *prompt=@"???";
|
||||
|
||||
url=@"poipoi";
|
||||
|
||||
if([cmd hasPrefix:@"git-remote-https"]){
|
||||
NSArray *args=[cmd componentsSeparatedByString:@" "];
|
||||
url=[args objectAtIndex:[args count]-1];
|
||||
}else if((sizeof(argv)/sizeof(char*))>1){
|
||||
prompt=[NSString stringWithCString:argv[1] encoding:NSASCIIStringEncoding];
|
||||
}else{
|
||||
prompt=@"null";
|
||||
}
|
||||
|
||||
|
||||
OSStatus status,status1;
|
||||
void *passwordData = nil;
|
||||
SecKeychainItemRef itemRef = nil;
|
||||
UInt32 passwordLength = nil;
|
||||
|
||||
status1 = GetPasswordKeychain ([url cStringUsingEncoding:NSASCIIStringEncoding],[url lengthOfBytesUsingEncoding:NSASCIIStringEncoding],&passwordData,&passwordLength,&itemRef);
|
||||
if (status1 == noErr) {
|
||||
SecKeychainItemFreeContent (NULL,passwordData);
|
||||
}
|
||||
|
||||
NSInteger code;
|
||||
|
||||
if(passwordLength>0){
|
||||
NSString *pass=[NSString stringWithCString:passwordData encoding:NSASCIIStringEncoding];
|
||||
}else {
|
||||
NSWindow *passPanel = [appDel passwordPanel:prompt remember:NO];
|
||||
[app activateIgnoringOtherApps: YES];
|
||||
[passPanel makeKeyAndOrderFront: nil];
|
||||
code = [app runModalForWindow: passPanel];
|
||||
}
|
||||
|
||||
[defaults synchronize];
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user