From a273f3ae41624d09d7daae02a927c6efa77ca537 Mon Sep 17 00:00:00 2001 From: Bill Fumerola Date: Sat, 19 Apr 2003 10:14:43 +0000 Subject: [PATCH] properly refuse a connection in the -c case if the client ip's subdirectory does not exist. PR: bin/38303 Submitted by: Woei-Luen, Shyu the committed patch differs from the submitted one, any inaccuracies are mine. --- libexec/tftpd/tftpd.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/libexec/tftpd/tftpd.c b/libexec/tftpd/tftpd.c index 6eb309519a3b..bc247533466c 100644 --- a/libexec/tftpd/tftpd.c +++ b/libexec/tftpd/tftpd.c @@ -171,7 +171,7 @@ main(int argc, char *argv[]) dirs->name = "/"; dirs->len = 1; } - if (ipchroot && chroot_dir == NULL) { + if (ipchroot > 0 && chroot_dir == NULL) { syslog(LOG_ERR, "-c requires -s"); exit(1); } @@ -245,7 +245,7 @@ main(int argc, char *argv[]) * be a problem. See the above comment about system clogging. */ if (chroot_dir) { - if (ipchroot) { + if (ipchroot > 0) { char *tempchroot; struct stat sb; int statret; @@ -258,9 +258,10 @@ main(int argc, char *argv[]) hbuf, sizeof(hbuf), NULL, 0, NI_NUMERICHOST | NI_WITHSCOPEID); asprintf(&tempchroot, "%s/%s", chroot_dir, hbuf); - statret = stat(tempchroot, &sb); - if ((sb.st_mode & S_IFDIR) && - (statret == 0 || (statret == -1 && ipchroot == 1))) + if (ipchroot == 2) + statret = stat(tempchroot, &sb); + if (ipchroot == 1 || + (statret == 0 && (sb.st_mode & S_IFDIR))) chroot_dir = tempchroot; } /* Must get this before chroot because /etc might go away */