diff --git a/ChangeLog b/ChangeLog index 01b30968c..3b92fd015 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,10 @@ 20020723 - (bal) [bsd-cray.c bsd-cray.h] Part 2 of Cray merger. + - (bal) OpenBSD Sync + - markus@cvs.openbsd.org 2002/07/19 15:43:33 + [log.c log.h session.c sshd.c] + remove fatal cleanups after fork; based on discussions with and code + from solar. 20020722 - (bal) AIX tty data limiting patch fix by leigh@solinno.co.uk @@ -1423,4 +1428,4 @@ - (stevesk) entropy.c: typo in debug message - (djm) ssh-keygen -i needs seeded RNG; report from markus@ -$Id: ChangeLog,v 1.2394 2002/07/23 21:00:17 mouring Exp $ +$Id: ChangeLog,v 1.2395 2002/07/23 21:01:56 mouring Exp $ diff --git a/log.c b/log.c index 8c09ec1b2..96626d7d4 100644 --- a/log.c +++ b/log.c @@ -34,7 +34,7 @@ */ #include "includes.h" -RCSID("$OpenBSD: log.c,v 1.23 2002/07/06 01:00:49 deraadt Exp $"); +RCSID("$OpenBSD: log.c,v 1.24 2002/07/19 15:43:33 markus Exp $"); #include "log.h" #include "xmalloc.h" @@ -223,6 +223,18 @@ fatal_remove_cleanup(void (*proc) (void *context), void *context) (u_long) proc, (u_long) context); } +/* Remove all cleanups, to be called after fork() */ +void +fatal_remove_all_cleanups(void) +{ + struct fatal_cleanup *cu, *next_cu; + + for (cu = fatal_cleanups; cu; cu = next_cu) { + next_cu = cu->next; + xfree(cu); + } +} + /* Cleanup and exit */ void fatal_cleanup(void) diff --git a/log.h b/log.h index 3e4c3c3a7..917fafa69 100644 --- a/log.h +++ b/log.h @@ -1,4 +1,4 @@ -/* $OpenBSD: log.h,v 1.7 2002/05/19 20:54:52 deraadt Exp $ */ +/* $OpenBSD: log.h,v 1.8 2002/07/19 15:43:33 markus Exp $ */ /* * Author: Tatu Ylonen @@ -64,6 +64,7 @@ void debug3(const char *, ...) __attribute__((format(printf, 1, 2))); void fatal_cleanup(void); void fatal_add_cleanup(void (*) (void *), void *); void fatal_remove_cleanup(void (*) (void *), void *); +void fatal_remove_all_cleanups(void); void do_log(LogLevel, const char *, va_list); diff --git a/session.c b/session.c index 3c759e472..38388d43a 100644 --- a/session.c +++ b/session.c @@ -33,7 +33,7 @@ */ #include "includes.h" -RCSID("$OpenBSD: session.c,v 1.143 2002/06/30 21:54:16 deraadt Exp $"); +RCSID("$OpenBSD: session.c,v 1.144 2002/07/19 15:43:33 markus Exp $"); #include "ssh.h" #include "ssh1.h" @@ -470,6 +470,8 @@ do_exec_no_pty(Session *s, const char *command) /* Fork the child. */ if ((pid = fork()) == 0) { + fatal_remove_all_cleanups(); + /* Child. Reinitialize the log since the pid has changed. */ log_init(__progname, options.log_level, options.log_facility, log_stderr); @@ -585,6 +587,7 @@ do_exec_pty(Session *s, const char *command) /* Fork the child. */ if ((pid = fork()) == 0) { + fatal_remove_all_cleanups(); /* Child. Reinitialize the log because the pid has changed. */ log_init(__progname, options.log_level, options.log_facility, log_stderr); diff --git a/sshd.c b/sshd.c index 8f9d3c392..427ca3545 100644 --- a/sshd.c +++ b/sshd.c @@ -42,7 +42,7 @@ */ #include "includes.h" -RCSID("$OpenBSD: sshd.c,v 1.255 2002/06/30 21:59:45 deraadt Exp $"); +RCSID("$OpenBSD: sshd.c,v 1.256 2002/07/19 15:43:33 markus Exp $"); #include #include @@ -303,9 +303,6 @@ grace_alarm_handler(int sig) { /* XXX no idea how fix this signal handler */ - /* Close the connection. */ - packet_close(); - /* Log error and exit. */ fatal("Timeout before authentication for %s.", get_remote_ipaddr()); } @@ -589,6 +586,8 @@ privsep_preauth(void) if (pid == -1) { fatal("fork of unprivileged child failed"); } else if (pid != 0) { + fatal_remove_cleanup((void (*) (void *)) packet_close, NULL); + debug2("Network child is on pid %ld", (long)pid); close(pmonitor->m_recvfd); @@ -602,6 +601,10 @@ privsep_preauth(void) while (waitpid(pid, &status, 0) < 0) if (errno != EINTR) break; + + /* Reinstall, since the child has finished */ + fatal_add_cleanup((void (*) (void *)) packet_close, NULL); + return (authctxt); } else { /* child */ @@ -649,6 +652,8 @@ privsep_postauth(Authctxt *authctxt) if (pmonitor->m_pid == -1) fatal("fork of unprivileged child failed"); else if (pmonitor->m_pid != 0) { + fatal_remove_cleanup((void (*) (void *)) packet_close, NULL); + debug2("User child is on pid %ld", (long)pmonitor->m_pid); close(pmonitor->m_recvfd); monitor_child_postauth(pmonitor);