Skip to content

Commit

Permalink
git-extra: include an simple Win32 git askpass
Browse files Browse the repository at this point in the history
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
rimrul authored and dscho committed Aug 14, 2021
1 parent 7784359 commit da9ba5d
Show file tree
Hide file tree
Showing 5 changed files with 147 additions and 2 deletions.
8 changes: 8 additions & 0 deletions git-extra/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ CXXFLAGS ?= -Wall
all: $(BUILDDIR)/create-shortcut.exe $(BUILDDIR)/WhoUses.exe \
$(BUILDDIR)/blocked-file-util.exe $(BUILDDIR)/proxy-lookup.exe \
$(BUILDDIR)/git-askyesno.exe \
$(BUILDDIR)/git-askpass.exe \
$(BUILDDIR)/git-credential-helper-selector.exe

$(BUILDDIR)/create-shortcut.exe: $(BUILDDIR)/create-shortcut.o
Expand Down Expand Up @@ -44,6 +45,13 @@ $(BUILDDIR)/git-credential-helper-selector.exe: \
$(BUILDDIR)/git-credential-helper-selector.o \
$(BUILDDIR)/git-credential-helper-selector.res
$(CC) -municode $(CFLAGS) -o $@ $^ -lgdi32 -lcomctl32

$(BUILDDIR)/git-askpass.o: CFLAGS += -DUNICODE

$(BUILDDIR)/git-askpass.exe: \
$(BUILDDIR)/git-askpass.o \
$(BUILDDIR)/git-askpass.res
$(CC) -municode $(CFLAGS) -o $@ $^
clean:
$(RM) $(BUILDDIR)/create-shortcut.exe $(BUILDDIR)/create-shortcut.o
$(RM) $(BUILDDIR)/WhoUses.exe $(BUILDDIR)/WhoUses.o \
Expand Down
11 changes: 9 additions & 2 deletions git-extra/PKGBUILD
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,10 @@ source=('inputrc'
'update-via-pacman.bat'
'git-credential-helper-selector.c'
'git-credential-helper-selector.manifest'
'git-credential-helper-selector.rc')
'git-credential-helper-selector.rc'
'git-askpass.c'
'git-askpass.h'
'git-askpass.rc')
sha256sums=('2a8b8630bc2b0c6667790d1ba11534cdf685fff58b026cc4e01b21a10085db1d'
'c26d22aaa1d3dc615d474e0d60c5c0f19598d61d9205e19ec87aac1b28bb07c1'
'640d04d2a2da709419188a986d5e5550ad30df23c7ea9be1a389c37a6b917994'
Expand Down Expand Up @@ -83,7 +86,10 @@ sha256sums=('2a8b8630bc2b0c6667790d1ba11534cdf685fff58b026cc4e01b21a10085db1d'
'25c4cff9fa0d82d87ce7f9cf34d2558dd051a398d33e6c3440e9371ebb72471e'
'febd9504ed7a9e07771d9ae35ddface253a6160a8df9f4c18e4111eb45386712'
'247dc84535c89d2e00c6a741d4317cd76ae5958c91ac867e2e74d4e73bc3c998'
'78307cd6c04a16240f68197e9155697bc75d5df8e4c8514ff67712bb93a1cd4a')
'78307cd6c04a16240f68197e9155697bc75d5df8e4c8514ff67712bb93a1cd4a'
'f2f64cc0d49598089a84de72ce78f3e5949f6c2d6c09a499d3c3760fcf6aef57'
'51e31c6ce824f66b9a8310f1ac10ccdc06b60967a557c996868bc0d9c9866ccf'
'0dd30dc3acd406e70b5ff08fb0bf180ec3782119455989af18c05cf59d09df64')

prepare() {
test $startdir/$pkgname.install -nt $startdir/$pkgname.install.in &&
Expand Down Expand Up @@ -128,6 +134,7 @@ package() {
install -m755 $builddir/proxy-lookup.exe $pkgdir${MINGW_PREFIX}/bin
install -m755 $builddir/git-askyesno.exe $pkgdir${MINGW_PREFIX}/bin
install -m755 $builddir/git-credential-helper-selector.exe $pkgdir${MINGW_PREFIX}/bin
install -m755 $builddir/git-askpass.exe $pkgdir${MINGW_PREFIX}/bin
install -m755 git-prompt.sh $pkgdir/etc/profile.d
install -m755 aliases.sh $pkgdir/etc/profile.d
install -m755 env.sh $pkgdir/etc/profile.d
Expand Down
109 changes: 109 additions & 0 deletions git-extra/git-askpass.c
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;
}
3 changes: 3 additions & 0 deletions git-extra/git-askpass.h
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
18 changes: 18 additions & 0 deletions git-extra/git-askpass.rc
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

0 comments on commit da9ba5d

Please sign in to comment.