]> asedeno.scripts.mit.edu Git - PuTTY.git/blobdiff - unix/uxpgnt.c
Note the interaction of jump lists and -cleanup.
[PuTTY.git] / unix / uxpgnt.c
index 2f9826b840c0bb6e7585eba524162dd4e55387f3..41efcbc2d81f405ddebb494c701ca42e34c9a88b 100644 (file)
@@ -103,6 +103,8 @@ FontSpec *platform_default_fontspec(const char *name) { return fontspec_new("");
 Filename *platform_default_filename(const char *name) { return filename_from_str(""); }
 char *x_get_default(const char *key) { return NULL; }
 void log_eventlog(void *handle, const char *event) {}
+int from_backend(void *frontend, int is_stderr, const char *data, int datalen)
+{ assert(!"only here to satisfy notional call from backend_socket_log"); }
 
 /*
  * Short description of parameters.
@@ -134,13 +136,16 @@ static void usage(void)
     printf("  -D           delete all keys from the agent\n");
     printf("Other options:\n");
     printf("  -v           verbose mode (in agent mode)\n");
+    printf("  -s -c        force POSIX or C shell syntax (in agent mode)\n");
     exit(1);
 }
 
 static void version(void)
 {
-    printf("pageant: %s\n", ver);
-    exit(1);
+    char *buildinfo_text = buildinfo("\n");
+    printf("pageant: %s\n%s\n", ver, buildinfo_text);
+    sfree(buildinfo_text);
+    exit(0);
 }
 
 void keylist_update(void)
@@ -191,11 +196,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)
@@ -506,18 +543,19 @@ struct pageant_pubkey *find_key(const char *string, char **retstr)
                     filename_free(fn);
                     return NULL;
                 }
+            } else {
+                /*
+                 * If we've successfully loaded the file, stop here - we
+                 * already have a key blob and need not go to the agent to
+                 * list things.
+                 */
+                key_in.ssh_version = 1;
+                key_in.comment = NULL;
+                key_ret = pageant_pubkey_copy(&key_in);
+                sfree(key_in.blob);
+                filename_free(fn);
+                return key_ret;
             }
-
-            /*
-             * If we've successfully loaded the file, stop here - we
-             * already have a key blob and need not go to the agent to
-             * list things.
-             */
-            key_in.ssh_version = 1;
-            key_ret = pageant_pubkey_copy(&key_in);
-            sfree(key_in.blob);
-            filename_free(fn);
-            return key_ret;
         } else if (keytype == SSH_KEYTYPE_SSH2 ||
                    keytype == SSH_KEYTYPE_SSH2_PUBLIC_RFC4716 ||
                    keytype == SSH_KEYTYPE_SSH2_PUBLIC_OPENSSH) {
@@ -532,18 +570,19 @@ struct pageant_pubkey *find_key(const char *string, char **retstr)
                     filename_free(fn);
                     return NULL;
                 }
+            } else {
+                /*
+                 * If we've successfully loaded the file, stop here - we
+                 * already have a key blob and need not go to the agent to
+                 * list things.
+                 */
+                key_in.ssh_version = 2;
+                key_in.comment = NULL;
+                key_ret = pageant_pubkey_copy(&key_in);
+                sfree(key_in.blob);
+                filename_free(fn);
+                return key_ret;
             }
-
-            /*
-             * If we've successfully loaded the file, stop here - we
-             * already have a key blob and need not go to the agent to
-             * list things.
-             */
-            key_in.ssh_version = 2;
-            key_ret = pageant_pubkey_copy(&key_in);
-            sfree(key_in.blob);
-            filename_free(fn);
-            return key_ret;
         } else {
             if (file_errors) {
                 *retstr = dupprintf("unable to load key file '%s': %s",
@@ -941,6 +980,8 @@ void run_agent(void)
         fprintf(stderr, "pageant: %s: %s\n", socketname, strerror(errno));
         exit(1);
     }
+
+    conf_free(conf);
 }
 
 int main(int argc, char **argv)
@@ -965,6 +1006,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")) {