=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/ssh/readpass.c,v retrieving revision 1.65 retrieving revision 1.66 diff -u -r1.65 -r1.66 --- src/usr.bin/ssh/readpass.c 2020/10/18 11:32:01 1.65 +++ src/usr.bin/ssh/readpass.c 2020/11/08 22:37:24 1.66 @@ -1,4 +1,4 @@ -/* $OpenBSD: readpass.c,v 1.65 2020/10/18 11:32:01 djm Exp $ */ +/* $OpenBSD: readpass.c,v 1.66 2020/11/08 22:37:24 djm Exp $ */ /* * Copyright (c) 2001 Markus Friedl. All rights reserved. * @@ -219,6 +219,14 @@ return (allowed); } +static void +writemsg(const char *msg) +{ + (void)write(STDERR_FILENO, "\r", 1); + (void)write(STDERR_FILENO, msg, strlen(msg)); + (void)write(STDERR_FILENO, "\r\n", 2); +} + struct notifier_ctx { pid_t pid; void (*osigchld)(int); @@ -229,8 +237,8 @@ { va_list args; char *prompt = NULL; - pid_t pid; - void (*osigchld)(int); + pid_t pid = -1; + void (*osigchld)(int) = NULL; const char *askpass, *s; struct notifier_ctx *ret = NULL; @@ -241,10 +249,8 @@ if (fflush(NULL) != 0) error_f("fflush: %s", strerror(errno)); if (!force_askpass && isatty(STDERR_FILENO)) { - (void)write(STDERR_FILENO, "\r", 1); - (void)write(STDERR_FILENO, prompt, strlen(prompt)); - (void)write(STDERR_FILENO, "\r\n", 2); - goto out; + writemsg(prompt); + goto out_ctx; } if ((askpass = getenv("SSH_ASKPASS")) == NULL) askpass = _PATH_SSH_ASKPASS_DEFAULT; @@ -275,6 +281,7 @@ _exit(1); /* NOTREACHED */ } + out_ctx: if ((ret = calloc(1, sizeof(*ret))) == NULL) { kill(pid, SIGTERM); fatal_f("calloc failed"); @@ -287,9 +294,22 @@ } void -notify_complete(struct notifier_ctx *ctx) +notify_complete(struct notifier_ctx *ctx, const char *fmt, ...) { int ret; + char *msg = NULL; + va_list args; + + if (fmt != NULL && ctx->pid == -1) { + /* + * notify_start wrote to stderr, so send conclusion message + * there too + */ + va_start(args, fmt); + xvasprintf(&msg, fmt, args); + va_end(args); + writemsg(msg); + } if (ctx == NULL || ctx->pid <= 0) { free(ctx);