diff --git a/doc/man-pag.but b/doc/man-pag.but index 3ac9e096..098d3325 100644 --- a/doc/man-pag.but +++ b/doc/man-pag.but @@ -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. diff --git a/unix/uxpgnt.c b/unix/uxpgnt.c index 75f719cf..4f3dde2d 100644 --- a/unix/uxpgnt.c +++ b/unix/uxpgnt.c @@ -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")) {