Skip to content

Commit da9ba5d

Browse files
rimruldscho
authored andcommitted
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 <[email protected]>
1 parent 7784359 commit da9ba5d

File tree

5 files changed

+147
-2
lines changed

5 files changed

+147
-2
lines changed

git-extra/Makefile

+8
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ CXXFLAGS ?= -Wall
77
all: $(BUILDDIR)/create-shortcut.exe $(BUILDDIR)/WhoUses.exe \
88
$(BUILDDIR)/blocked-file-util.exe $(BUILDDIR)/proxy-lookup.exe \
99
$(BUILDDIR)/git-askyesno.exe \
10+
$(BUILDDIR)/git-askpass.exe \
1011
$(BUILDDIR)/git-credential-helper-selector.exe
1112

1213
$(BUILDDIR)/create-shortcut.exe: $(BUILDDIR)/create-shortcut.o
@@ -44,6 +45,13 @@ $(BUILDDIR)/git-credential-helper-selector.exe: \
4445
$(BUILDDIR)/git-credential-helper-selector.o \
4546
$(BUILDDIR)/git-credential-helper-selector.res
4647
$(CC) -municode $(CFLAGS) -o $@ $^ -lgdi32 -lcomctl32
48+
49+
$(BUILDDIR)/git-askpass.o: CFLAGS += -DUNICODE
50+
51+
$(BUILDDIR)/git-askpass.exe: \
52+
$(BUILDDIR)/git-askpass.o \
53+
$(BUILDDIR)/git-askpass.res
54+
$(CC) -municode $(CFLAGS) -o $@ $^
4755
clean:
4856
$(RM) $(BUILDDIR)/create-shortcut.exe $(BUILDDIR)/create-shortcut.o
4957
$(RM) $(BUILDDIR)/WhoUses.exe $(BUILDDIR)/WhoUses.o \

git-extra/PKGBUILD

+9-2
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,10 @@ source=('inputrc'
5252
'update-via-pacman.bat'
5353
'git-credential-helper-selector.c'
5454
'git-credential-helper-selector.manifest'
55-
'git-credential-helper-selector.rc')
55+
'git-credential-helper-selector.rc'
56+
'git-askpass.c'
57+
'git-askpass.h'
58+
'git-askpass.rc')
5659
sha256sums=('2a8b8630bc2b0c6667790d1ba11534cdf685fff58b026cc4e01b21a10085db1d'
5760
'c26d22aaa1d3dc615d474e0d60c5c0f19598d61d9205e19ec87aac1b28bb07c1'
5861
'640d04d2a2da709419188a986d5e5550ad30df23c7ea9be1a389c37a6b917994'
@@ -83,7 +86,10 @@ sha256sums=('2a8b8630bc2b0c6667790d1ba11534cdf685fff58b026cc4e01b21a10085db1d'
8386
'25c4cff9fa0d82d87ce7f9cf34d2558dd051a398d33e6c3440e9371ebb72471e'
8487
'febd9504ed7a9e07771d9ae35ddface253a6160a8df9f4c18e4111eb45386712'
8588
'247dc84535c89d2e00c6a741d4317cd76ae5958c91ac867e2e74d4e73bc3c998'
86-
'78307cd6c04a16240f68197e9155697bc75d5df8e4c8514ff67712bb93a1cd4a')
89+
'78307cd6c04a16240f68197e9155697bc75d5df8e4c8514ff67712bb93a1cd4a'
90+
'f2f64cc0d49598089a84de72ce78f3e5949f6c2d6c09a499d3c3760fcf6aef57'
91+
'51e31c6ce824f66b9a8310f1ac10ccdc06b60967a557c996868bc0d9c9866ccf'
92+
'0dd30dc3acd406e70b5ff08fb0bf180ec3782119455989af18c05cf59d09df64')
8793

8894
prepare() {
8995
test $startdir/$pkgname.install -nt $startdir/$pkgname.install.in &&
@@ -128,6 +134,7 @@ package() {
128134
install -m755 $builddir/proxy-lookup.exe $pkgdir${MINGW_PREFIX}/bin
129135
install -m755 $builddir/git-askyesno.exe $pkgdir${MINGW_PREFIX}/bin
130136
install -m755 $builddir/git-credential-helper-selector.exe $pkgdir${MINGW_PREFIX}/bin
137+
install -m755 $builddir/git-askpass.exe $pkgdir${MINGW_PREFIX}/bin
131138
install -m755 git-prompt.sh $pkgdir/etc/profile.d
132139
install -m755 aliases.sh $pkgdir/etc/profile.d
133140
install -m755 env.sh $pkgdir/etc/profile.d

git-extra/git-askpass.c

+109
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
#define WIN32_LEAN_AND_MEAN
2+
#include <windows.h>
3+
#include <stdlib.h>
4+
#include <stdio.h>
5+
#include "git-askpass.h"
6+
7+
INT_PTR CALLBACK PasswordProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
8+
{
9+
wchar_t *lpszPassword = NULL;
10+
WORD cchPassword;
11+
12+
switch (message)
13+
{
14+
case WM_INITDIALOG:
15+
/* Display the prompt */
16+
SetDlgItemTextW(hDlg, IDC_PROMPT, (wchar_t *) lParam);
17+
if (GetDlgCtrlID((HWND) wParam) != IDE_PASSWORDEDIT) {
18+
SetFocus(GetDlgItem(hDlg, IDE_PASSWORDEDIT));
19+
return FALSE;
20+
}
21+
return TRUE;
22+
case WM_COMMAND:
23+
switch(wParam)
24+
{
25+
case IDOK:
26+
/* Get number of characters. */
27+
cchPassword = (WORD) SendDlgItemMessage(hDlg,
28+
IDE_PASSWORDEDIT,
29+
EM_LINELENGTH,
30+
(WPARAM) 0,
31+
(LPARAM) 0);
32+
33+
lpszPassword = (wchar_t *) malloc(sizeof(wchar_t) * (cchPassword + 1));
34+
if (!lpszPassword) {
35+
MessageBoxW(NULL, L"Out of memory asking for a password", L"Error!", MB_OK);
36+
EndDialog(hDlg, FALSE);
37+
return TRUE;
38+
}
39+
/* Put the number of characters into first word of buffer. */
40+
*((LPWORD)lpszPassword) = cchPassword;
41+
42+
/* Get the characters. */
43+
SendDlgItemMessageW(hDlg,
44+
IDE_PASSWORDEDIT,
45+
EM_GETLINE,
46+
(WPARAM) 0, /* line 0 */
47+
(LPARAM) lpszPassword);
48+
49+
/* Null-terminate the string. */
50+
lpszPassword[cchPassword] = 0;
51+
52+
wprintf(L"%ls\n", lpszPassword);
53+
54+
EndDialog(hDlg, TRUE);
55+
free(lpszPassword);
56+
return TRUE;
57+
58+
case IDCANCEL:
59+
EndDialog(hDlg, FALSE);
60+
return TRUE;
61+
}
62+
return 0;
63+
}
64+
return FALSE;
65+
66+
UNREFERENCED_PARAMETER(lParam);
67+
}
68+
69+
int wmain(int argc, wchar_t **wargv)
70+
{
71+
INT_PTR res;
72+
wchar_t *prompt = NULL;
73+
74+
if (argc < 2) {
75+
MessageBoxW(NULL, L"Usage: git askpass <prompt>", L"Error!", MB_OK);
76+
return 1;
77+
}
78+
79+
if (argc > 2) {
80+
size_t count = wcslen(wargv[1]), i;
81+
82+
for (i = 2; i < argc; i++)
83+
count += 1 + wcslen(wargv[i]);
84+
85+
prompt = malloc((count + 1) * sizeof(*prompt));
86+
if (!prompt) {
87+
MessageBoxW(NULL, L"Out of memory asking for a password", L"Error!", MB_OK);
88+
return 1;
89+
}
90+
91+
wcscpy(prompt, wargv[1]);
92+
count = wcslen(wargv[1]);
93+
94+
for (i = 2; i < argc; i++) {
95+
prompt[count++] = L' ';
96+
wcscpy(prompt + count, wargv[i]);
97+
count += wcslen(wargv[i]);
98+
}
99+
}
100+
101+
res = DialogBoxParamW(NULL, /* application instance */
102+
MAKEINTRESOURCEW(IDD_PASSWORD), /* dialog box resource */
103+
NULL, /* owner window */
104+
PasswordProc, /* dialog box window procedure */
105+
(LPARAM) (prompt ? prompt : wargv[1]));
106+
107+
free(prompt);
108+
return !res;
109+
}

git-extra/git-askpass.h

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#define IDD_PASSWORD 129
2+
#define IDE_PASSWORDEDIT 1000
3+
#define IDC_PROMPT 1001

git-extra/git-askpass.rc

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#include "git-askpass.h"
2+
#include "windows.h"
3+
4+
/////////////////////////////////////////////////////////////////////////////
5+
//
6+
// Dialog
7+
//
8+
9+
IDD_PASSWORD DIALOGEX 0, 0, 253, 94
10+
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION
11+
CAPTION "Git for Windows"
12+
FONT 8, "MS Shell Dlg", 400, 0, 0x1
13+
BEGIN
14+
DEFPUSHBUTTON "OK",IDOK,141,75,50,14
15+
PUSHBUTTON "Cancel",IDCANCEL,195,75,50,14
16+
EDITTEXT IDE_PASSWORDEDIT,7,43,239,14,ES_PASSWORD | ES_AUTOHSCROLL
17+
LTEXT "Enter Password",IDC_PROMPT,7,7,239,32,SS_NOPREFIX
18+
END

0 commit comments

Comments
 (0)