@matheusbsbs / matheus-bagliano / commits / 8c76212529
Fork 0

git-gui: Add a simple implementation of SSH_ASKPASS.

OpenSSH allows specifying an external program to use for direct user interaction. While most Linux systems already have such programs, some environments, for instance, msysgit, lack it. This patch adds a simple fallback Tcl implementation of the tool. In msysgit it is also necessary to set a fake value of the DISPLAY variable, because otherwise ssh won't even try to use SSH_ASKPASS handlers. Signed-off-by: Alexander Gavrilov <angavrilov@gmail.com> Acked-by: Johannes Sixt <johannes.sixt@telecom.at> Signed-off-by: Shawn O. Pearce <spearce@spearce.org>

Alexander Gavrilov committed Oct 15, 2008 at 13:28 UTC 8c76212529570aed70c46d6f252cb1a4010f3f2e
3 files changed +73
Makefile
+2
@@ -285,6 +285,7 @@ all:: $(GITGUI_MAIN) lib/tclIndex $(ALL_MSGFILES)
285 install: all
286 $(QUIET)$(INSTALL_D0)'$(DESTDIR_SQ)$(gitexecdir_SQ)' $(INSTALL_D1)
287 $(QUIET)$(INSTALL_X0)git-gui $(INSTALL_X1) '$(DESTDIR_SQ)$(gitexecdir_SQ)'
288 + $(QUIET)$(INSTALL_X0)git-gui--askpass $(INSTALL_X1) '$(DESTDIR_SQ)$(gitexecdir_SQ)'
289 $(QUIET)$(foreach p,$(GITGUI_BUILT_INS), $(INSTALL_L0)'$(DESTDIR_SQ)$(gitexecdir_SQ)/$p' $(INSTALL_L1)'$(DESTDIR_SQ)$(gitexecdir_SQ)/git-gui' $(INSTALL_L2)'$(DESTDIR_SQ)$(gitexecdir_SQ)/$p' $(INSTALL_L3) &&) true
290 ifdef GITGUI_WINDOWS_WRAPPER
291 $(QUIET)$(INSTALL_R0)git-gui.tcl $(INSTALL_R1) '$(DESTDIR_SQ)$(gitexecdir_SQ)'
@@ -302,6 +303,7 @@ endif
303 uninstall:
304 $(QUIET)$(CLEAN_DST) '$(DESTDIR_SQ)$(gitexecdir_SQ)'
305 $(QUIET)$(REMOVE_F0)'$(DESTDIR_SQ)$(gitexecdir_SQ)'/git-gui $(REMOVE_F1)
306 + $(QUIET)$(REMOVE_F0)'$(DESTDIR_SQ)$(gitexecdir_SQ)'/git-gui--askpass $(REMOVE_F1)
307 $(QUIET)$(foreach p,$(GITGUI_BUILT_INS), $(REMOVE_F0)'$(DESTDIR_SQ)$(gitexecdir_SQ)'/$p $(REMOVE_F1) &&) true
308 ifdef GITGUI_WINDOWS_WRAPPER
309 $(QUIET)$(REMOVE_F0)'$(DESTDIR_SQ)$(gitexecdir_SQ)'/git-gui.tcl $(REMOVE_F1)
git-gui--askpass new
+59
@@ -0,0 +1,59 @@
1 +#!/bin/sh
2 +# Tcl ignores the next line -*- tcl -*- \
3 +exec wish "$0" -- "$@"
4 +
5 +# This is a trivial implementation of an SSH_ASKPASS handler.
6 +# Git-gui uses this script if none are already configured.
7 +
8 +set answer {}
9 +set yesno 0
10 +set rc 255
11 +
12 +if {$argc < 1} {
13 + set prompt "Enter your OpenSSH passphrase:"
14 +} else {
15 + set prompt [join $argv " "]
16 + if {[regexp -nocase {\(yes\/no\)\?\s*$} $prompt]} {
17 + set yesno 1
18 + }
19 +}
20 +
21 +message .m -text $prompt -justify center -aspect 4000
22 +pack .m -side top -fill x -padx 20 -pady 20 -expand 1
23 +
24 +entry .e -textvariable answer -width 50
25 +pack .e -side top -fill x -padx 10 -pady 10
26 +
27 +if {!$yesno} {
28 + .e configure -show "*"
29 +}
30 +
31 +frame .b
32 +button .b.ok -text OK -command finish
33 +button .b.cancel -text Cancel -command {destroy .}
34 +
35 +pack .b.ok -side left -expand 1
36 +pack .b.cancel -side right -expand 1
37 +pack .b -side bottom -fill x -padx 10 -pady 10
38 +
39 +bind . <Visibility> {focus -force .e}
40 +bind . <Key-Return> finish
41 +bind . <Key-Escape> {destroy .}
42 +bind . <Destroy> {exit $rc}
43 +
44 +proc finish {} {
45 + if {$::yesno} {
46 + if {$::answer ne "yes" && $::answer ne "no"} {
47 + tk_messageBox -icon error -title "Error" -type ok \
48 + -message "Only 'yes' or 'no' input allowed."
49 + return
50 + }
51 + }
52 +
53 + set ::rc 0
54 + puts $::answer
55 + destroy .
56 +}
57 +
58 +wm title . "OpenSSH"
59 +tk::PlaceWindow .
git-gui.sh
+12
@@ -592,6 +592,11 @@ bind . <Visibility> {
592 if {[is_Windows]} {
593 wm iconbitmap . -default $oguilib/git-gui.ico
594 set ::tk::AlwaysShowSelection 1
595 +
596 + # Spoof an X11 display for SSH
597 + if {![info exists env(DISPLAY)]} {
598 + set env(DISPLAY) :9999
599 + }
600 }
601
602 ######################################################################
@@ -1070,6 +1075,13 @@ set nullid2 "0000000000000000000000000000000000000001"
1075
1076 set have_tk85 [expr {[package vcompare $tk_version "8.5"] >= 0}]
1077
1078 +######################################################################
1079 +
1080 +# Suggest our implementation of askpass, if none is set
1081 +if {![info exists env(SSH_ASKPASS)]} {
1082 + set env(SSH_ASKPASS) [gitexec git-gui--askpass]
1083 +}
1084 +
1085 ######################################################################
1086 ##
1087 ## task management