X-Git-Url: https://asedeno.scripts.mit.edu/gitweb/?a=blobdiff_plain;f=unix%2Fuxpgnt.c;h=2f9826b840c0bb6e7585eba524162dd4e55387f3;hb=af1460d6e5044a3344aaacd15c91cfdcb58578e7;hp=0329f6b9359dd54f2e553267cf96df087db9953a;hpb=a1816395211c7acfa24b0eabfcb5f05ca5fcc074;p=PuTTY.git diff --git a/unix/uxpgnt.c b/unix/uxpgnt.c index 0329f6b9..2f9826b8 100644 --- a/unix/uxpgnt.c +++ b/unix/uxpgnt.c @@ -23,7 +23,7 @@ SockAddr unix_sock_addr(const char *path); Socket new_unix_listener(SockAddr listenaddr, Plug plug); -void fatalbox(char *p, ...) +void fatalbox(const char *p, ...) { va_list ap; fprintf(stderr, "FATAL ERROR: "); @@ -33,7 +33,7 @@ void fatalbox(char *p, ...) fputc('\n', stderr); exit(1); } -void modalfatalbox(char *p, ...) +void modalfatalbox(const char *p, ...) { va_list ap; fprintf(stderr, "FATAL ERROR: "); @@ -43,7 +43,7 @@ void modalfatalbox(char *p, ...) fputc('\n', stderr); exit(1); } -void nonfatal(char *p, ...) +void nonfatal(const char *p, ...) { va_list ap; fprintf(stderr, "ERROR: "); @@ -52,7 +52,7 @@ void nonfatal(char *p, ...) va_end(ap); fputc('\n', stderr); } -void connection_fatal(void *frontend, char *p, ...) +void connection_fatal(void *frontend, const char *p, ...) { va_list ap; fprintf(stderr, "FATAL ERROR: "); @@ -62,7 +62,7 @@ void connection_fatal(void *frontend, char *p, ...) fputc('\n', stderr); exit(1); } -void cmdline_error(char *p, ...) +void cmdline_error(const char *p, ...) { va_list ap; fprintf(stderr, "pageant: "); @@ -88,8 +88,8 @@ void pageant_log(void *ctx, const char *fmt, va_list ap) * In Pageant our selects are synchronous, so these functions are * empty stubs. */ -int uxsel_input_add(int fd, int rwx) { return 0; } -void uxsel_input_remove(int id) { } +uxsel_id *uxsel_input_add(int fd, int rwx) { return NULL; } +void uxsel_input_remove(uxsel_id *id) { } /* * More stubs. @@ -111,7 +111,29 @@ static void usage(void) { printf("Pageant: SSH agent\n"); printf("%s\n", ver); - printf("FIXME\n"); + printf("Usage: pageant [key files]\n"); + printf(" pageant [key files] --exec [args]\n"); + printf(" pageant -a [key files]\n"); + printf(" pageant -d [key identifiers]\n"); + printf(" pageant --public [key identifiers]\n"); + printf(" pageant --public-openssh [key identifiers]\n"); + printf(" pageant -l\n"); + printf(" pageant -D\n"); + printf("Lifetime options, for running Pageant as an agent:\n"); + printf(" -X run with the lifetime of the X server\n"); + printf(" -T run with the lifetime of the controlling tty\n"); + printf(" --permanent run permanently\n"); + printf(" --debug run in debugging mode, without forking\n"); + printf(" --exec run with the lifetime of that command\n"); + printf("Client options, for talking to an existing agent:\n"); + printf(" -a add key(s) to the existing agent\n"); + printf(" -l list currently loaded key fingerprints and comments\n"); + printf(" --public print public keys in RFC 4716 format\n"); + printf(" --public-openssh print public keys in OpenSSH format\n"); + printf(" -d delete key(s) from the agent\n"); + printf(" -D delete all keys from the agent\n"); + printf("Other options:\n"); + printf(" -v verbose mode (in agent mode)\n"); exit(1); } @@ -269,6 +291,21 @@ void add_keyact(keyact action, const char *filename) keyact_tail = a; } +int have_controlling_tty(void) +{ + int fd = open("/dev/tty", O_RDONLY); + if (fd < 0) { + if (errno != ENXIO) { + perror("/dev/tty: open"); + exit(1); + } + return FALSE; + } else { + close(fd); + return TRUE; + } +} + char **exec_args = NULL; enum { LIFE_UNSPEC, LIFE_X11, LIFE_TTY, LIFE_DEBUG, LIFE_PERM, LIFE_EXEC @@ -277,30 +314,50 @@ const char *display = NULL; static char *askpass(const char *comment) { - prompts_t *p = new_prompts(NULL); - int ret; - - /* - * FIXME: if we don't have a terminal, and have to do this by X11, - * there's a big missing piece. - */ - - p->to_server = FALSE; - p->name = dupstr("Pageant passphrase prompt"); - add_prompt(p, - dupprintf("Enter passphrase to load key '%s': ", comment), - FALSE); - ret = console_get_userpass_input(p, NULL, 0); - assert(ret >= 0); - - if (!ret) { - perror("pageant: unable to read passphrase"); - free_prompts(p); - return NULL; - } else { - char *passphrase = dupstr(p->prompts[0]->result); - free_prompts(p); + if (have_controlling_tty()) { + int ret; + prompts_t *p = new_prompts(NULL); + p->to_server = FALSE; + p->name = dupstr("Pageant passphrase prompt"); + add_prompt(p, + dupprintf("Enter passphrase to load key '%s': ", comment), + FALSE); + ret = console_get_userpass_input(p, NULL, 0); + assert(ret >= 0); + + if (!ret) { + perror("pageant: unable to read passphrase"); + free_prompts(p); + return NULL; + } else { + char *passphrase = dupstr(p->prompts[0]->result); + free_prompts(p); + return passphrase; + } + } else if (display) { + char *prompt, *passphrase; + int success; + + /* in gtkask.c */ + char *gtk_askpass_main(const char *display, const char *wintitle, + const char *prompt, int *success); + + prompt = dupprintf("Enter passphrase to load key '%s': ", comment); + passphrase = gtk_askpass_main(display, + "Pageant passphrase prompt", + prompt, &success); + sfree(prompt); + if (!success) { + /* return value is error message */ + fprintf(stderr, "%s\n", passphrase); + sfree(passphrase); + passphrase = NULL; + } return passphrase; + } else { + fprintf(stderr, "no way to read a passphrase without tty or " + "X display\n"); + return NULL; } } @@ -320,7 +377,6 @@ static int unix_add_keyfile(const char *filename_str) goto cleanup; } else if (status == PAGEANT_ACTION_FAILURE) { fprintf(stderr, "pageant: %s: %s\n", filename_str, err); - sfree(err); ret = FALSE; goto cleanup; } @@ -345,7 +401,6 @@ static int unix_add_keyfile(const char *filename_str) goto cleanup; } else if (status == PAGEANT_ACTION_FAILURE) { fprintf(stderr, "pageant: %s: %s\n", filename_str, err); - sfree(err); ret = FALSE; goto cleanup; } @@ -682,8 +737,6 @@ void run_agent(void) NULL }; - if (!display) - display = getenv("DISPLAY"); if (!display) { fprintf(stderr, "pageant: no DISPLAY for -X mode\n"); exit(1); @@ -840,16 +893,9 @@ void run_agent(void) * our containing tty session has ended, so it's time to * clean up and leave. */ - int fd = open("/dev/tty", O_RDONLY); - if (fd < 0) { - if (errno != ENXIO) { - perror("/dev/tty: open"); - exit(1); - } + if (!have_controlling_tty()) { time_to_die = TRUE; break; - } else { - close(fd); } } @@ -974,6 +1020,12 @@ int main(int argc, char **argv) sk_init(); uxsel_init(); + if (!display) { + display = getenv("DISPLAY"); + if (display && !*display) + display = NULL; + } + /* * Now distinguish our two main running modes. Either we're * actually starting up an agent, in which case we should have a