tftpd.c (112452) | tftpd.c (113714) |
---|---|
1/* 2 * Copyright (c) 1983, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 28 unchanged lines hidden (view full) --- 37 The Regents of the University of California. All rights reserved.\n"; 38#endif /* not lint */ 39 40#ifndef lint 41#if 0 42static char sccsid[] = "@(#)tftpd.c 8.1 (Berkeley) 6/4/93"; 43#endif 44static const char rcsid[] = | 1/* 2 * Copyright (c) 1983, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 28 unchanged lines hidden (view full) --- 37 The Regents of the University of California. All rights reserved.\n"; 38#endif /* not lint */ 39 40#ifndef lint 41#if 0 42static char sccsid[] = "@(#)tftpd.c 8.1 (Berkeley) 6/4/93"; 43#endif 44static const char rcsid[] = |
45 "$FreeBSD: head/libexec/tftpd/tftpd.c 112452 2003-03-20 22:42:22Z dwmalone $"; | 45 "$FreeBSD: head/libexec/tftpd/tftpd.c 113714 2003-04-19 10:14:43Z billf $"; |
46#endif /* not lint */ 47 48/* 49 * Trivial file transfer protocol server. 50 * 51 * This version includes many modifications by Jim Guyton 52 * <guyton@rand-unix>. 53 */ --- 112 unchanged lines hidden (view full) --- 166 dirp++; 167 } 168 } 169 } 170 else if (chroot_dir) { 171 dirs->name = "/"; 172 dirs->len = 1; 173 } | 46#endif /* not lint */ 47 48/* 49 * Trivial file transfer protocol server. 50 * 51 * This version includes many modifications by Jim Guyton 52 * <guyton@rand-unix>. 53 */ --- 112 unchanged lines hidden (view full) --- 166 dirp++; 167 } 168 } 169 } 170 else if (chroot_dir) { 171 dirs->name = "/"; 172 dirs->len = 1; 173 } |
174 if (ipchroot && chroot_dir == NULL) { | 174 if (ipchroot > 0 && chroot_dir == NULL) { |
175 syslog(LOG_ERR, "-c requires -s"); 176 exit(1); 177 } 178 179 on = 1; 180 if (ioctl(0, FIONBIO, &on) < 0) { 181 syslog(LOG_ERR, "ioctl(FIONBIO): %m"); 182 exit(1); --- 57 unchanged lines hidden (view full) --- 240 } 241 242 /* 243 * Since we exit here, we should do that only after the above 244 * recvfrom to keep inetd from constantly forking should there 245 * be a problem. See the above comment about system clogging. 246 */ 247 if (chroot_dir) { | 175 syslog(LOG_ERR, "-c requires -s"); 176 exit(1); 177 } 178 179 on = 1; 180 if (ioctl(0, FIONBIO, &on) < 0) { 181 syslog(LOG_ERR, "ioctl(FIONBIO): %m"); 182 exit(1); --- 57 unchanged lines hidden (view full) --- 240 } 241 242 /* 243 * Since we exit here, we should do that only after the above 244 * recvfrom to keep inetd from constantly forking should there 245 * be a problem. See the above comment about system clogging. 246 */ 247 if (chroot_dir) { |
248 if (ipchroot) { | 248 if (ipchroot > 0) { |
249 char *tempchroot; 250 struct stat sb; 251 int statret; 252 struct sockaddr_storage ss; 253 char hbuf[NI_MAXHOST]; 254 255 memcpy(&ss, &from, from.ss_len); 256 unmappedaddr((struct sockaddr_in6 *)&ss); 257 getnameinfo((struct sockaddr *)&ss, ss.ss_len, 258 hbuf, sizeof(hbuf), NULL, 0, 259 NI_NUMERICHOST | NI_WITHSCOPEID); 260 asprintf(&tempchroot, "%s/%s", chroot_dir, hbuf); | 249 char *tempchroot; 250 struct stat sb; 251 int statret; 252 struct sockaddr_storage ss; 253 char hbuf[NI_MAXHOST]; 254 255 memcpy(&ss, &from, from.ss_len); 256 unmappedaddr((struct sockaddr_in6 *)&ss); 257 getnameinfo((struct sockaddr *)&ss, ss.ss_len, 258 hbuf, sizeof(hbuf), NULL, 0, 259 NI_NUMERICHOST | NI_WITHSCOPEID); 260 asprintf(&tempchroot, "%s/%s", chroot_dir, hbuf); |
261 statret = stat(tempchroot, &sb); 262 if ((sb.st_mode & S_IFDIR) && 263 (statret == 0 || (statret == -1 && ipchroot == 1))) | 261 if (ipchroot == 2) 262 statret = stat(tempchroot, &sb); 263 if (ipchroot == 1 || 264 (statret == 0 && (sb.st_mode & S_IFDIR))) |
264 chroot_dir = tempchroot; 265 } 266 /* Must get this before chroot because /etc might go away */ 267 if ((nobody = getpwnam(chuser)) == NULL) { 268 syslog(LOG_ERR, "%s: no such user", chuser); 269 exit(1); 270 } 271 if (chroot(chroot_dir)) { --- 598 unchanged lines hidden --- | 265 chroot_dir = tempchroot; 266 } 267 /* Must get this before chroot because /etc might go away */ 268 if ((nobody = getpwnam(chuser)) == NULL) { 269 syslog(LOG_ERR, "%s: no such user", chuser); 270 exit(1); 271 } 272 if (chroot(chroot_dir)) { --- 598 unchanged lines hidden --- |