diff options
author | Mike Pechkin <mpech@cvs.openbsd.org> | 2002-05-13 07:44:49 +0000 |
---|---|---|
committer | Mike Pechkin <mpech@cvs.openbsd.org> | 2002-05-13 07:44:49 +0000 |
commit | 92c301519055ff7e620ade9e5bce4ec65d796923 (patch) | |
tree | 00683d9941a74558e9214fa4a8ca778d7c5f0c22 | |
parent | 1251f88a7ca26bd952efdfbf558e3d2de1237304 (diff) |
o) fix order and usage of chroot&chdir;
o) move code up from chroot&chdir block (tftpd);
millert@ ok
-rw-r--r-- | libexec/smtpd/src/smtpd.c | 13 | ||||
-rw-r--r-- | libexec/tftpd/tftpd.c | 29 | ||||
-rw-r--r-- | usr.sbin/chroot/chroot.c | 6 |
3 files changed, 23 insertions, 25 deletions
diff --git a/libexec/smtpd/src/smtpd.c b/libexec/smtpd/src/smtpd.c index 71cfddfd5e3..aaa876a29db 100644 --- a/libexec/smtpd/src/smtpd.c +++ b/libexec/smtpd/src/smtpd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: smtpd.c,v 1.11 2001/01/28 19:34:34 niklas Exp $*/ +/* $OpenBSD: smtpd.c,v 1.12 2002/05/13 07:44:48 mpech Exp $*/ /* * smtpd, Obtuse SMTP daemon, storing agent. does simple collection of @@ -41,7 +41,7 @@ char *obtuse_copyright = "Copyright 1996 - Obtuse Systems Corporation - All rights reserved."; -char *obtuse_rcsid = "$OpenBSD: smtpd.c,v 1.11 2001/01/28 19:34:34 niklas Exp $"; +char *obtuse_rcsid = "$OpenBSD: smtpd.c,v 1.12 2002/05/13 07:44:48 mpech Exp $"; #include <stdarg.h> #include <stdlib.h> @@ -2368,16 +2368,15 @@ main(int argc, char **argv) } if (chrootdir != NULL) { - if (chdir(chrootdir) != 0) { - syslog(LOG_CRIT, "Couldn't chdir to directory %s! (%m)", - chrootdir); - exit(EX_CONFIG); - } if (chroot(chrootdir) != 0) { syslog(LOG_CRIT, "Couldn't chroot to directory %s! (%m)", chrootdir); exit(EX_CONFIG); } + if (chdir("/") != 0) { + syslog(LOG_CRIT, "Couldn't chdir! (%m)"); + exit(EX_CONFIG); + } } else { syslog(LOG_CRIT, "No chroot directory specified! Aborting."); abort(); diff --git a/libexec/tftpd/tftpd.c b/libexec/tftpd/tftpd.c index 509678fb243..459c72aff98 100644 --- a/libexec/tftpd/tftpd.c +++ b/libexec/tftpd/tftpd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tftpd.c,v 1.21 2002/02/01 06:05:22 itojun Exp $ */ +/* $OpenBSD: tftpd.c,v 1.22 2002/05/13 07:44:48 mpech Exp $ */ /* * Copyright (c) 1983 Regents of the University of California. @@ -41,7 +41,7 @@ char copyright[] = #ifndef lint /*static char sccsid[] = "from: @(#)tftpd.c 5.13 (Berkeley) 2/26/91";*/ -static char rcsid[] = "$OpenBSD: tftpd.c,v 1.21 2002/02/01 06:05:22 itojun Exp $: tftpd.c,v 1.6 1997/02/16 23:49:21 deraadt Exp $"; +static char rcsid[] = "$OpenBSD: tftpd.c,v 1.22 2002/05/13 07:44:48 mpech Exp $: tftpd.c,v 1.6 1997/02/16 23:49:21 deraadt Exp $"; #endif /* not lint */ /* @@ -170,6 +170,12 @@ main(argc, argv) ndirs++; } + pw = getpwnam("nobody"); + if (!pw) { + syslog(LOG_ERR, "no nobody: %m"); + exit(1); + } + if (secure) { if (ndirs == 0) { syslog(LOG_ERR, "no -s directory"); @@ -179,21 +185,14 @@ main(argc, argv) syslog(LOG_ERR, "too many -s directories"); exit(1); } - if (chdir(dirs[0])) { - syslog(LOG_ERR, "%s: %m", dirs[0]); + if (chroot(dirs[0])) { + syslog(LOG_ERR, "chroot %s: %m", dirs[0]); + exit(1); + } + if (chdir("/")) { + syslog(LOG_ERR, "chdir: %m"); exit(1); } - } - - pw = getpwnam("nobody"); - if (!pw) { - syslog(LOG_ERR, "no nobody: %m"); - exit(1); - } - - if (secure && chroot(".")) { - syslog(LOG_ERR, "chroot: %m"); - exit(1); } (void) setegid(pw->pw_gid); diff --git a/usr.sbin/chroot/chroot.c b/usr.sbin/chroot/chroot.c index 3c82b505411..42aa469899f 100644 --- a/usr.sbin/chroot/chroot.c +++ b/usr.sbin/chroot/chroot.c @@ -1,4 +1,4 @@ -/* $OpenBSD: chroot.c,v 1.3 2000/08/17 15:28:36 mickey Exp $ */ +/* $OpenBSD: chroot.c,v 1.4 2002/05/13 07:44:48 mpech Exp $ */ /* * Copyright (c) 1988 The Regents of the University of California. @@ -41,7 +41,7 @@ char copyright[] = #ifndef lint /*static char sccsid[] = "from: @(#)chroot.c 5.8 (Berkeley) 6/1/90";*/ -static char rcsid[] = "$OpenBSD: chroot.c,v 1.3 2000/08/17 15:28:36 mickey Exp $"; +static char rcsid[] = "$OpenBSD: chroot.c,v 1.4 2002/05/13 07:44:48 mpech Exp $"; #endif /* not lint */ #include <stdio.h> @@ -62,7 +62,7 @@ main(argc, argv) (void)fprintf(stderr, "usage: chroot newroot [command]\n"); exit(1); } - if (chdir(argv[1]) || chroot(".")) + if (chroot(argv[1]) || chdir("/")) err(1, "%s", argv[1]); if (argv[2]) { execvp(argv[2], &argv[2]); |