]> asedeno.scripts.mit.edu Git - PuTTY.git/commitdiff
Support sh/csh syntax switching for Unix Pageant.
authorSimon Tatham <anakin@pobox.com>
Fri, 25 Mar 2016 16:43:59 +0000 (16:43 +0000)
committerSimon Tatham <anakin@pobox.com>
Fri, 25 Mar 2016 16:43:59 +0000 (16:43 +0000)
doc/man-pag.but
unix/uxpgnt.c

index 3ac9e09672881b025024bae38fd4a7f5dc3a9b75..098d33250925ae85823706b0c247a7c695202955 100644 (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.
index 75f719cf38aedae18fae4d72378dad13d56f34cd..4f3dde2d1694cbd33a62636fd7d5b3267cbc3ac0 100644 (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")) {