diff options
author | Theo de Raadt <deraadt@cvs.openbsd.org> | 2004-12-06 23:04:15 +0000 |
---|---|---|
committer | Theo de Raadt <deraadt@cvs.openbsd.org> | 2004-12-06 23:04:15 +0000 |
commit | f41c154ac05ca2876af616579040e3046d65ed70 (patch) | |
tree | 444670cb824b0a29e0e95bc17195a899769dd266 | |
parent | 6362781442cf20ec59e6550787b8b741d379fca9 (diff) |
seperate reply_r, like earlier change but safer; moritz ok
-rw-r--r-- | libexec/ftpd/ftpcmd.y | 7 | ||||
-rw-r--r-- | libexec/ftpd/ftpd.c | 31 |
2 files changed, 32 insertions, 6 deletions
diff --git a/libexec/ftpd/ftpcmd.y b/libexec/ftpd/ftpcmd.y index 2f774c30882..fc8bfae9d06 100644 --- a/libexec/ftpd/ftpcmd.y +++ b/libexec/ftpd/ftpcmd.y @@ -1,4 +1,4 @@ -/* $OpenBSD: ftpcmd.y,v 1.46 2004/12/04 18:00:43 deraadt Exp $ */ +/* $OpenBSD: ftpcmd.y,v 1.47 2004/12/06 23:04:14 deraadt Exp $ */ /* $NetBSD: ftpcmd.y,v 1.7 1996/04/08 19:03:11 jtc Exp $ */ /* @@ -44,7 +44,7 @@ static const char sccsid[] = "@(#)ftpcmd.y 8.3 (Berkeley) 4/6/94"; #else static const char rcsid[] = - "$OpenBSD: ftpcmd.y,v 1.46 2004/12/04 18:00:43 deraadt Exp $"; + "$OpenBSD: ftpcmd.y,v 1.47 2004/12/06 23:04:14 deraadt Exp $"; #endif #endif /* not lint */ @@ -1170,8 +1170,7 @@ toolong(signo) { struct syslog_data sdata = SYSLOG_DATA_INIT; - /* XXX signal races */ - reply(421, + reply_r(421, "Timeout (%d seconds): closing control connection.", timeout); if (logging) syslog_r(LOG_INFO, &sdata, "User %s timed out after %d seconds", diff --git a/libexec/ftpd/ftpd.c b/libexec/ftpd/ftpd.c index a27bba5693b..980abca47d3 100644 --- a/libexec/ftpd/ftpd.c +++ b/libexec/ftpd/ftpd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ftpd.c,v 1.161 2004/12/04 18:00:43 deraadt Exp $ */ +/* $OpenBSD: ftpd.c,v 1.162 2004/12/06 23:04:14 deraadt Exp $ */ /* $NetBSD: ftpd.c,v 1.15 1995/06/03 22:46:47 mycroft Exp $ */ /* @@ -70,7 +70,7 @@ static const char copyright[] = static const char sccsid[] = "@(#)ftpd.c 8.4 (Berkeley) 4/16/94"; #else static const char rcsid[] = - "$OpenBSD: ftpd.c,v 1.161 2004/12/04 18:00:43 deraadt Exp $"; + "$OpenBSD: ftpd.c,v 1.162 2004/12/06 23:04:14 deraadt Exp $"; #endif #endif /* not lint */ @@ -1930,6 +1930,33 @@ reply(int n, const char *fmt, ...) free(buf); } + +void +reply_r(int n, const char *fmt, ...) +{ + char *p, *next; + char msg[BUFSIZ]; + char buf[BUFSIZ]; + va_list ap; + struct syslog_data sdata = SYSLOG_DATA_INIT; + + va_start(ap, fmt); + vsnprintf(msg, sizeof(msg), fmt, ap); + va_end(ap); + + next = msg; + + while ((p = strsep(&next, "\n\r"))) { + snprintf(buf, sizeof(buf), "%d%s %s\r\n", n, + (next != '\0') ? "-" : "", p); + write(STDOUT_FILENO, buf, strlen(buf)); + if (debug) { + buf[strlen(buf) - 2] = '\0'; + syslog_r(LOG_DEBUG, &sdata, "<--- %s", buf); + } + } +} + void lreply(int n, const char *fmt, ...) { |