Deleted Added
full compact
tftpd.c (331722) tftpd.c (332609)
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 331722 2018-03-29 02:50:57Z eadler $");
42__FBSDID("$FreeBSD: stable/11/libexec/tftpd/tftpd.c 332609 2018-04-16 16:33:35Z 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

--- 363 unchanged lines hidden (view full) ---

414 if (tp->th_opcode == RRQ) {
415 if (allow_ro)
416 tftp_rrq(peer, tp->th_stuff, n - 1);
417 else {
418 tftp_log(LOG_WARNING,
419 "%s read access denied", peername);
420 exit(1);
421 }
43
44/*
45 * Trivial file transfer protocol server.
46 *
47 * This version includes many modifications by Jim Guyton
48 * <guyton@rand-unix>.
49 */
50

--- 363 unchanged lines hidden (view full) ---

414 if (tp->th_opcode == RRQ) {
415 if (allow_ro)
416 tftp_rrq(peer, tp->th_stuff, n - 1);
417 else {
418 tftp_log(LOG_WARNING,
419 "%s read access denied", peername);
420 exit(1);
421 }
422 }
423 if (tp->th_opcode == WRQ) {
422 } else if (tp->th_opcode == WRQ) {
424 if (allow_wo)
425 tftp_wrq(peer, tp->th_stuff, n - 1);
426 else {
427 tftp_log(LOG_WARNING,
428 "%s write access denied", peername);
429 exit(1);
430 }
423 if (allow_wo)
424 tftp_wrq(peer, tp->th_stuff, n - 1);
425 else {
426 tftp_log(LOG_WARNING,
427 "%s write access denied", peername);
428 exit(1);
429 }
431 }
430 } else
431 send_error(peer, EBADOP);
432 exit(1);
433}
434
435static void
436reduce_path(char *fn)
437{
438 char *slash, *ptr;
439

--- 98 unchanged lines hidden (view full) ---

538 else
539 send_ack(peer, 0);
540 }
541 if (logging) {
542 tftp_log(LOG_INFO, "%s: write request for %s: %s", peername,
543 filename, errtomsg(ecode));
544 }
545
432 exit(1);
433}
434
435static void
436reduce_path(char *fn)
437{
438 char *slash, *ptr;
439

--- 98 unchanged lines hidden (view full) ---

538 else
539 send_ack(peer, 0);
540 }
541 if (logging) {
542 tftp_log(LOG_INFO, "%s: write request for %s: %s", peername,
543 filename, errtomsg(ecode));
544 }
545
546 if (ecode) {
547 send_error(peer, ecode);
548 exit(1);
549 }
546 tftp_recvfile(peer, mode);
547 exit(0);
548}
549
550/*
551 * RRQ - send a file to the client
552 */
553void

--- 182 unchanged lines hidden (view full) ---

736 * to give an indication that the file exists.
737 */
738 err = ENOTFOUND;
739 for (dirp = dirs; dirp->name != NULL; dirp++) {
740 snprintf(pathname, sizeof(pathname), "%s/%s",
741 dirp->name, filename);
742 if (stat(pathname, &stbuf) == 0 &&
743 (stbuf.st_mode & S_IFMT) == S_IFREG) {
550 tftp_recvfile(peer, mode);
551 exit(0);
552}
553
554/*
555 * RRQ - send a file to the client
556 */
557void

--- 182 unchanged lines hidden (view full) ---

740 * to give an indication that the file exists.
741 */
742 err = ENOTFOUND;
743 for (dirp = dirs; dirp->name != NULL; dirp++) {
744 snprintf(pathname, sizeof(pathname), "%s/%s",
745 dirp->name, filename);
746 if (stat(pathname, &stbuf) == 0 &&
747 (stbuf.st_mode & S_IFMT) == S_IFREG) {
744 if ((stbuf.st_mode & S_IROTH) != 0) {
745 break;
748 if (mode == RRQ) {
749 if ((stbuf.st_mode & S_IROTH) != 0)
750 break;
751 } else {
752 if ((stbuf.st_mode & S_IWOTH) != 0)
753 break;
746 }
747 err = EACCESS;
748 }
749 }
750 if (dirp->name != NULL)
751 *filep = filename = pathname;
752 else if (mode == RRQ)
753 return (err);
754 }
755 err = EACCESS;
756 }
757 }
758 if (dirp->name != NULL)
759 *filep = filename = pathname;
760 else if (mode == RRQ)
761 return (err);
762 else if (err != ENOTFOUND || !create_new)
763 return (err);
754 }
755
756 /*
757 * This option is handled here because it (might) require(s) the
758 * size of the file.
759 */
760 option_tsize(peer, NULL, mode, &stbuf);
761

--- 54 unchanged lines hidden (view full) ---

816 if (debug&DEBUG_SIMPLE)
817 tftp_log(LOG_DEBUG, "Receiving file");
818
819 write_init(0, file, mode);
820
821 block = 0;
822 tftp_receive(peer, &block, &ts, NULL, 0);
823
764 }
765
766 /*
767 * This option is handled here because it (might) require(s) the
768 * size of the file.
769 */
770 option_tsize(peer, NULL, mode, &stbuf);
771

--- 54 unchanged lines hidden (view full) ---

826 if (debug&DEBUG_SIMPLE)
827 tftp_log(LOG_DEBUG, "Receiving file");
828
829 write_init(0, file, mode);
830
831 block = 0;
832 tftp_receive(peer, &block, &ts, NULL, 0);
833
824 write_close();
825 gettimeofday(&now2, NULL);
826
827 if (debug&DEBUG_SIMPLE) {
828 double f;
829 if (now1.tv_usec > now2.tv_usec) {
830 now2.tv_usec += 1000000;
831 now2.tv_sec--;
832 }
833
834 f = now2.tv_sec - now1.tv_sec +
835 (now2.tv_usec - now1.tv_usec) / 100000.0;
836 tftp_log(LOG_INFO,
837 "Download of %jd bytes in %d blocks completed after %0.1f seconds\n",
838 (intmax_t)ts.amount, block, f);
839 }
840
841 return;
842}
834 gettimeofday(&now2, NULL);
835
836 if (debug&DEBUG_SIMPLE) {
837 double f;
838 if (now1.tv_usec > now2.tv_usec) {
839 now2.tv_usec += 1000000;
840 now2.tv_sec--;
841 }
842
843 f = now2.tv_sec - now1.tv_sec +
844 (now2.tv_usec - now1.tv_usec) / 100000.0;
845 tftp_log(LOG_INFO,
846 "Download of %jd bytes in %d blocks completed after %0.1f seconds\n",
847 (intmax_t)ts.amount, block, f);
848 }
849
850 return;
851}