forked from git-for-windows/build-extra
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
git-extra: include an simple Win32
git askpass
This is a drop-in replacement for `git gui--askpass`. Since we added an option to use an external `ssh` found on the `PATH` (git-for-windows#367) we'll need an `askpass` implementation that can be called by any windows application even without understanding shebang lines. `git gui--askpass` probably also has the same problems with screenreaders that `git gui--askyesno` had(git-for-windows#234), so we'll likely get improved accessibility as a positive side-effect. Signed-off-by: Matthias Aßhauer <mha1993@live.de>
- Loading branch information
Showing
5 changed files
with
147 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
#define WIN32_LEAN_AND_MEAN | ||
#include <windows.h> | ||
#include <stdlib.h> | ||
#include <stdio.h> | ||
#include "git-askpass.h" | ||
|
||
INT_PTR CALLBACK PasswordProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) | ||
{ | ||
wchar_t *lpszPassword = NULL; | ||
WORD cchPassword; | ||
|
||
switch (message) | ||
{ | ||
case WM_INITDIALOG: | ||
/* Display the prompt */ | ||
SetDlgItemTextW(hDlg, IDC_PROMPT, (wchar_t *) lParam); | ||
if (GetDlgCtrlID((HWND) wParam) != IDE_PASSWORDEDIT) { | ||
SetFocus(GetDlgItem(hDlg, IDE_PASSWORDEDIT)); | ||
return FALSE; | ||
} | ||
return TRUE; | ||
case WM_COMMAND: | ||
switch(wParam) | ||
{ | ||
case IDOK: | ||
/* Get number of characters. */ | ||
cchPassword = (WORD) SendDlgItemMessage(hDlg, | ||
IDE_PASSWORDEDIT, | ||
EM_LINELENGTH, | ||
(WPARAM) 0, | ||
(LPARAM) 0); | ||
|
||
lpszPassword = (wchar_t *) malloc(sizeof(wchar_t) * (cchPassword + 1)); | ||
if (!lpszPassword) { | ||
MessageBoxW(NULL, L"Out of memory asking for a password", L"Error!", MB_OK); | ||
EndDialog(hDlg, FALSE); | ||
return TRUE; | ||
} | ||
/* Put the number of characters into first word of buffer. */ | ||
*((LPWORD)lpszPassword) = cchPassword; | ||
|
||
/* Get the characters. */ | ||
SendDlgItemMessageW(hDlg, | ||
IDE_PASSWORDEDIT, | ||
EM_GETLINE, | ||
(WPARAM) 0, /* line 0 */ | ||
(LPARAM) lpszPassword); | ||
|
||
/* Null-terminate the string. */ | ||
lpszPassword[cchPassword] = 0; | ||
|
||
wprintf(L"%ls\n", lpszPassword); | ||
|
||
EndDialog(hDlg, TRUE); | ||
free(lpszPassword); | ||
return TRUE; | ||
|
||
case IDCANCEL: | ||
EndDialog(hDlg, FALSE); | ||
return TRUE; | ||
} | ||
return 0; | ||
} | ||
return FALSE; | ||
|
||
UNREFERENCED_PARAMETER(lParam); | ||
} | ||
|
||
int wmain(int argc, wchar_t **wargv) | ||
{ | ||
INT_PTR res; | ||
wchar_t *prompt = NULL; | ||
|
||
if (argc < 2) { | ||
MessageBoxW(NULL, L"Usage: git askpass <prompt>", L"Error!", MB_OK); | ||
return 1; | ||
} | ||
|
||
if (argc > 2) { | ||
size_t count = wcslen(wargv[1]), i; | ||
|
||
for (i = 2; i < argc; i++) | ||
count += 1 + wcslen(wargv[i]); | ||
|
||
prompt = malloc((count + 1) * sizeof(*prompt)); | ||
if (!prompt) { | ||
MessageBoxW(NULL, L"Out of memory asking for a password", L"Error!", MB_OK); | ||
return 1; | ||
} | ||
|
||
wcscpy(prompt, wargv[1]); | ||
count = wcslen(wargv[1]); | ||
|
||
for (i = 2; i < argc; i++) { | ||
prompt[count++] = L' '; | ||
wcscpy(prompt + count, wargv[i]); | ||
count += wcslen(wargv[i]); | ||
} | ||
} | ||
|
||
res = DialogBoxParamW(NULL, /* application instance */ | ||
MAKEINTRESOURCEW(IDD_PASSWORD), /* dialog box resource */ | ||
NULL, /* owner window */ | ||
PasswordProc, /* dialog box window procedure */ | ||
(LPARAM) (prompt ? prompt : wargv[1])); | ||
|
||
free(prompt); | ||
return !res; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#define IDD_PASSWORD 129 | ||
#define IDE_PASSWORDEDIT 1000 | ||
#define IDC_PROMPT 1001 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#include "git-askpass.h" | ||
#include "windows.h" | ||
|
||
///////////////////////////////////////////////////////////////////////////// | ||
// | ||
// Dialog | ||
// | ||
|
||
IDD_PASSWORD DIALOGEX 0, 0, 253, 94 | ||
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | ||
CAPTION "Git for Windows" | ||
FONT 8, "MS Shell Dlg", 400, 0, 0x1 | ||
BEGIN | ||
DEFPUSHBUTTON "OK",IDOK,141,75,50,14 | ||
PUSHBUTTON "Cancel",IDCANCEL,195,75,50,14 | ||
EDITTEXT IDE_PASSWORDEDIT,7,43,239,14,ES_PASSWORD | ES_AUTOHSCROLL | ||
LTEXT "Enter Password",IDC_PROMPT,7,7,239,32,SS_NOPREFIX | ||
END |