tftpd.c (332609) | tftpd.c (339051) |
---|---|
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 --- 25 unchanged lines hidden (view full) --- 34#endif /* not lint */ 35 36#ifndef lint 37#if 0 38static char sccsid[] = "@(#)tftpd.c 8.1 (Berkeley) 6/4/93"; 39#endif 40#endif /* not lint */ 41#include <sys/cdefs.h> | 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 --- 25 unchanged lines hidden (view full) --- 34#endif /* not lint */ 35 36#ifndef lint 37#if 0 38static char sccsid[] = "@(#)tftpd.c 8.1 (Berkeley) 6/4/93"; 39#endif 40#endif /* not lint */ 41#include <sys/cdefs.h> |
42__FBSDID("$FreeBSD: stable/11/libexec/tftpd/tftpd.c 332609 2018-04-16 16:33:35Z asomers $"); | 42__FBSDID("$FreeBSD: stable/11/libexec/tftpd/tftpd.c 339051 2018-10-01 15:47:34Z asomers $"); |
43 44/* 45 * Trivial file transfer protocol server. 46 * 47 * This version includes many modifications by Jim Guyton 48 * <guyton@rand-unix>. 49 */ 50 --- 316 unchanged lines hidden (view full) --- 367 exit(1); 368 } 369 if (chroot(chroot_dir)) { 370 tftp_log(LOG_ERR, "chroot: %s: %s", 371 chroot_dir, strerror(errno)); 372 exit(1); 373 } 374 chdir("/"); | 43 44/* 45 * Trivial file transfer protocol server. 46 * 47 * This version includes many modifications by Jim Guyton 48 * <guyton@rand-unix>. 49 */ 50 --- 316 unchanged lines hidden (view full) --- 367 exit(1); 368 } 369 if (chroot(chroot_dir)) { 370 tftp_log(LOG_ERR, "chroot: %s: %s", 371 chroot_dir, strerror(errno)); 372 exit(1); 373 } 374 chdir("/"); |
375 setgroups(1, &nobody->pw_gid); | 375 if (setgroups(1, &nobody->pw_gid) != 0) { 376 tftp_log(LOG_ERR, "setgroups failed"); 377 exit(1); 378 } |
376 if (setuid(nobody->pw_uid) != 0) { 377 tftp_log(LOG_ERR, "setuid failed"); 378 exit(1); 379 } 380 } 381 382 len = sizeof(me_sock); 383 if (getsockname(0, (struct sockaddr *)&me_sock, &len) == 0) { --- 131 unchanged lines hidden (view full) --- 515 char *cp; 516 int has_options = 0, ecode; 517 char *filename, *mode; 518 char fnbuf[PATH_MAX]; 519 520 cp = parse_header(peer, recvbuffer, size, &filename, &mode); 521 size -= (cp - recvbuffer) + 1; 522 | 379 if (setuid(nobody->pw_uid) != 0) { 380 tftp_log(LOG_ERR, "setuid failed"); 381 exit(1); 382 } 383 } 384 385 len = sizeof(me_sock); 386 if (getsockname(0, (struct sockaddr *)&me_sock, &len) == 0) { --- 131 unchanged lines hidden (view full) --- 518 char *cp; 519 int has_options = 0, ecode; 520 char *filename, *mode; 521 char fnbuf[PATH_MAX]; 522 523 cp = parse_header(peer, recvbuffer, size, &filename, &mode); 524 size -= (cp - recvbuffer) + 1; 525 |
523 strcpy(fnbuf, filename); | 526 strlcpy(fnbuf, filename, sizeof(fnbuf)); |
524 reduce_path(fnbuf); 525 filename = fnbuf; 526 527 if (size > 0) { 528 if (options_rfc_enabled) 529 has_options = !parse_options(peer, cp, size); 530 else 531 tftp_log(LOG_INFO, "Options found but not enabled"); --- 28 unchanged lines hidden (view full) --- 560 char *cp; 561 int has_options = 0, ecode; 562 char *filename, *mode; 563 char fnbuf[PATH_MAX]; 564 565 cp = parse_header(peer, recvbuffer, size, &filename, &mode); 566 size -= (cp - recvbuffer) + 1; 567 | 527 reduce_path(fnbuf); 528 filename = fnbuf; 529 530 if (size > 0) { 531 if (options_rfc_enabled) 532 has_options = !parse_options(peer, cp, size); 533 else 534 tftp_log(LOG_INFO, "Options found but not enabled"); --- 28 unchanged lines hidden (view full) --- 563 char *cp; 564 int has_options = 0, ecode; 565 char *filename, *mode; 566 char fnbuf[PATH_MAX]; 567 568 cp = parse_header(peer, recvbuffer, size, &filename, &mode); 569 size -= (cp - recvbuffer) + 1; 570 |
568 strcpy(fnbuf, filename); | 571 strlcpy(fnbuf, filename, sizeof(fnbuf)); |
569 reduce_path(fnbuf); 570 filename = fnbuf; 571 572 if (size > 0) { 573 if (options_rfc_enabled) 574 has_options = !parse_options(peer, cp, size); 575 else 576 tftp_log(LOG_INFO, "Options found but not enabled"); --- 220 unchanged lines hidden (view full) --- 797 798static void 799tftp_xmitfile(int peer, const char *mode) 800{ 801 uint16_t block; 802 time_t now; 803 struct tftp_stats ts; 804 | 572 reduce_path(fnbuf); 573 filename = fnbuf; 574 575 if (size > 0) { 576 if (options_rfc_enabled) 577 has_options = !parse_options(peer, cp, size); 578 else 579 tftp_log(LOG_INFO, "Options found but not enabled"); --- 220 unchanged lines hidden (view full) --- 800 801static void 802tftp_xmitfile(int peer, const char *mode) 803{ 804 uint16_t block; 805 time_t now; 806 struct tftp_stats ts; 807 |
808 memset(&ts, 0, sizeof(ts)); |
|
805 now = time(NULL); 806 if (debug&DEBUG_SIMPLE) 807 tftp_log(LOG_DEBUG, "Transmitting file"); 808 809 read_init(0, file, mode); 810 block = 1; 811 tftp_send(peer, &block, &ts); 812 read_close(); --- 39 unchanged lines hidden --- | 809 now = time(NULL); 810 if (debug&DEBUG_SIMPLE) 811 tftp_log(LOG_DEBUG, "Transmitting file"); 812 813 read_init(0, file, mode); 814 block = 1; 815 tftp_send(peer, &block, &ts); 816 read_close(); --- 39 unchanged lines hidden --- |