1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-01-10 01:48:00 +00:00

Support sh/csh syntax switching for Unix Pageant.

This commit is contained in:
Simon Tatham 2016-03-25 16:43:59 +00:00
parent 52746ae793
commit fc77fa0b8b
2 changed files with 47 additions and 3 deletions

View File

@ -260,6 +260,14 @@ output.
}
\dt \cw{-s}, \cw{-c}
\dd Force Pageant to output its environment setup commands in the
style of POSIX / Bourne shells (\cw{-s}) or C shells (\cw{-c})
respectively. If neither option is given, Pageant will guess based on
whether the environment variable \cw{SHELL} has a value ending in
\cq{csh}.
\dt \cw{--help}
\dd Print a brief summary of command-line options and terminate.

View File

@ -193,11 +193,43 @@ struct X11Connection {
};
char *socketname;
static enum { SHELL_AUTO, SHELL_SH, SHELL_CSH } shell_type = SHELL_AUTO;
void pageant_print_env(int pid)
{
printf("SSH_AUTH_SOCK=%s; export SSH_AUTH_SOCK;\n"
"SSH_AGENT_PID=%d; export SSH_AGENT_PID;\n",
socketname, (int)pid);
if (shell_type == SHELL_AUTO) {
/* Same policy as OpenSSH: if $SHELL ends in "csh" then assume
* it's csh-shaped. */
const char *shell = getenv("SHELL");
if (shell && strlen(shell) >= 3 &&
!strcmp(shell + strlen(shell) - 3, "csh"))
shell_type = SHELL_CSH;
else
shell_type = SHELL_SH;
}
/*
* These shell snippets could usefully pay some attention to
* escaping of interesting characters. I don't think it causes a
* problem at the moment, because the pathnames we use are so
* utterly boring, but it's a lurking bug waiting to happen once
* a bit more flexibility turns up.
*/
switch (shell_type) {
case SHELL_SH:
printf("SSH_AUTH_SOCK=%s; export SSH_AUTH_SOCK;\n"
"SSH_AGENT_PID=%d; export SSH_AGENT_PID;\n",
socketname, pid);
break;
case SHELL_CSH:
printf("setenv SSH_AUTH_SOCK %s;\n"
"setenv SSH_AGENT_PID %d;\n",
socketname, pid);
break;
case SHELL_AUTO:
assert(0 && "Can't get here");
break;
}
}
void pageant_fork_and_print_env(int retain_tty)
@ -967,6 +999,10 @@ int main(int argc, char **argv)
curr_keyact = KEYACT_CLIENT_ADD;
} else if (!strcmp(p, "-d")) {
curr_keyact = KEYACT_CLIENT_DEL;
} else if (!strcmp(p, "-s")) {
shell_type = SHELL_SH;
} else if (!strcmp(p, "-c")) {
shell_type = SHELL_CSH;
} else if (!strcmp(p, "-D")) {
add_keyact(KEYACT_CLIENT_DEL_ALL, NULL);
} else if (!strcmp(p, "-l")) {