Skip to contentSkip to conversation

fallback SSH_ASKPASS when GIT_ASKPASS not set

PATCH Superseded Frank Li 3 participants 5 messages Jun 15, 2016

v1 of 5 Superseded Latest is v5 →

lore
Share & tools
lore

Frank Li

author
#0 lore raw

PATCH 3/3 fallback SSH_ASKPASS when GIT_ASKPASS not set

If GIT_ASKPASS is not set and SSH_ASKPASS set, GIT_ASKPASS will use SSH_ASKPASS. If GIT_ASKPASS set and SSH_ASKPASS is not set, SSH_ASKPASS will use GIT_ASKPASS.

---
 git.c |    5 +++++
 1 files changed, 5 insertions(+), 0 deletions(-)
git.c +5 -0
index 90c6daf..39e1eba 100644
@@ -54,6 +54,11 @@ static int handle_options(const char ***argv, int *argc, int *envchanged)
 {
 	int handled = 0;
 
+	if (getenv("GIT_ASKPASS") && !getenv("SSH_ASKPASS"))
+		setenv("SSH_ASKPASS", getenv("GIT_ASKPASS"), 1);
+	if (!getenv("GIT_ASKPASS") && getenv("SSH_ASKPASS"))
+		setenv("GIT_ASKPASS", getenv("SSH_ASKPASS"), 1);
+
 	while (*argc > 0) {
 		const char *cmd = (*argv)[0];
 		if (cmd[0] != '-')
Signature · 1 line
1.7.0.85.g37fda.dirty
#1 lore raw
Quoted 3 lines · Frank Li

If GIT_ASKPASS is not set and SSH_ASKPASS set, GIT_ASKPASS will use SSH_ASKPASS. If GIT_ASKPASS set and SSH_ASKPASS is not set, SSH_ASKPASS will use GIT_ASKPASS.

If both are set and to different values, what should happen?

I think the basic idea is sound, but I am not sure if we should fallback on both ways. If both GIT_ASKPASS and SSH_ASKPASS are set, the user is probably telling us to use GIT_ASKPASS when git does something, similar to how GIT_EDITOR and EDITOR interacts.

So probably the patch to implement the fallback should be more like

if (SSH_ASKPASS is set but not GIT_ASKPASS)
set GIT_ASKPASS from SSH_ASKPASS

and then the password prompter should use GIT_ASKPASS exclusively.

Of course, when we _do_ spawn ssh ourselves internally in connect.c, we may have to export the value of GIT_ASKPASS as SSH_ASKPASS at the call site to honor the user's request to use GIT_ASKPASS while in git (that is part of "use GIT_ASKPASS exclusively").

But it feels wrong if we exported SSH_ASKPASS set from GIT_ASKPASS when spawning processes in other codepaths, especially if SSH_ASKPASS is set (or unset) differently from GIT_ASKPASS.

Shawn is CC'ed as git-gui currently honors only SSH_ASKPASS and this patch changes the behaviour slightly.

author
#2 lore raw
Quoted 5 lines

So probably the patch to implement the fallback should be more like

       if (SSH_ASKPASS is set but not GIT_ASKPASS) set GIT_ASKPASS from SSH_ASKPASS

do you means just keep these?

+ if (!getenv("GIT_ASKPASS") && getenv("SSH_ASKPASS"))
+ setenv("GIT_ASKPASS", getenv("SSH_ASKPASS"), 1);

best regards
Frank Li

#3 lore raw
In reply to Frank Li
Quoted 4 lines · Frank Li

If GIT_ASKPASS is not set and SSH_ASKPASS set, GIT_ASKPASS will use SSH_ASKPASS. If GIT_ASKPASS set and SSH_ASKPASS is not set, SSH_ASKPASS will use GIT_ASKPASS.

Since there's a maximum total size of the environment on Windows (64kib), perhaps it's better to not increase the environment-size more than necessary and instead check both variables when used? I must admit doing so gives me a kind of yuck-feeling, but at least it should also make non-builtins (like git-svn, which AFAICT is what you're fixing) work consistently even if it's not called through the git-wrapper...

Quoted 29 lines

---
 git.c |    5 +++++

 1 files changed, 5 insertions(+), 0 deletions(-)
git.c +5 -1
index 90c6daf..39e1eba 100644
@@ -54,6 +54,11 @@ static int handle_options(const char ***argv, int *argc, int *envchanged)
  {
        int handled = 0;
 
+       if (getenv("GIT_ASKPASS") && !getenv("SSH_ASKPASS"))
+               setenv("SSH_ASKPASS", getenv("GIT_ASKPASS"), 1);
+       if (!getenv("GIT_ASKPASS") && getenv("SSH_ASKPASS"))
+               setenv("GIT_ASKPASS", getenv("SSH_ASKPASS"), 1);
+
        while (*argc > 0) {
                const char *cmd = (*argv)[0];
                if (cmd[0] != '-')
--

1.7.0.85.g37fda.dirty

--
To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Signature · 1 line
Erik "kusma" Faye-Lund
author
#4 lore raw
Quoted 9 lines

Since there's a maximum total size of the environment on Windows (64kib), perhaps it's better to not increase the environment-size more than necessary and instead check both variables when used? I must admit doing so gives me a kind of yuck-feeling, but at least it should also make non-builtins (like git-svn, which AFAICT is what you're fixing) work consistently even if it's not called through the git-wrapper...

Git-svn use the same way, please read first patch.