Deleted Added
full compact
tftpd.c (95496) tftpd.c (112452)
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 95496 2002-04-26 12:27:55Z ume $";
45 "$FreeBSD: head/libexec/tftpd/tftpd.c 112452 2003-03-20 22:42:22Z dwmalone $";
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 */

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

98 * Null-terminated directory prefix list for absolute pathname requests and
99 * search list for relative pathname requests.
100 *
101 * MAXDIRS should be at least as large as the number of arguments that
102 * inetd allows (currently 20).
103 */
104#define MAXDIRS 20
105static struct dirlist {
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 */

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

98 * Null-terminated directory prefix list for absolute pathname requests and
99 * search list for relative pathname requests.
100 *
101 * MAXDIRS should be at least as large as the number of arguments that
102 * inetd allows (currently 20).
103 */
104#define MAXDIRS 20
105static struct dirlist {
106 char *name;
106 const char *name;
107 int len;
108} dirs[MAXDIRS+1];
109static int suppress_naks;
110static int logging;
111static int ipchroot;
112
107 int len;
108} dirs[MAXDIRS+1];
109static int suppress_naks;
110static int logging;
111static int ipchroot;
112
113static char *errtomsg(int);
113static const char *errtomsg(int);
114static void nak(int);
114static void nak(int);
115static void oack();
115static void oack(void);
116
116
117static void timer(int);
118static void justquit(int);
119
117int
118main(int argc, char *argv[])
119{
120 struct tftphdr *tp;
121 int n;
122 int ch, on;
123 struct sockaddr_storage me;
124 int len;
125 char *chroot_dir = NULL;
126 struct passwd *nobody;
120int
121main(int argc, char *argv[])
122{
123 struct tftphdr *tp;
124 int n;
125 int ch, on;
126 struct sockaddr_storage me;
127 int len;
128 char *chroot_dir = NULL;
129 struct passwd *nobody;
127 char *chuser = "nobody";
130 const char *chuser = "nobody";
128
129 openlog("tftpd", LOG_PID | LOG_NDELAY, LOG_FTP);
130 while ((ch = getopt(argc, argv, "cClns:u:")) != -1) {
131 switch (ch) {
132 case 'c':
133 ipchroot = 1;
134 break;
135 case 'C':

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

316}
317
318struct formats;
319int validate_access(char **, int);
320void xmitfile(struct formats *);
321void recvfile(struct formats *);
322
323struct formats {
131
132 openlog("tftpd", LOG_PID | LOG_NDELAY, LOG_FTP);
133 while ((ch = getopt(argc, argv, "cClns:u:")) != -1) {
134 switch (ch) {
135 case 'c':
136 ipchroot = 1;
137 break;
138 case 'C':

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

319}
320
321struct formats;
322int validate_access(char **, int);
323void xmitfile(struct formats *);
324void recvfile(struct formats *);
325
326struct formats {
324 char *f_mode;
327 const char *f_mode;
325 int (*f_validate)(char **, int);
326 void (*f_send)(struct formats *);
327 void (*f_recv)(struct formats *);
328 int f_convert;
329} formats[] = {
330 { "netascii", validate_access, xmitfile, recvfile, 1 },
331 { "octet", validate_access, xmitfile, recvfile, 0 },
332#ifdef notdef
333 { "mail", validate_user, sendmail, recvmail, 1 },
334#endif
328 int (*f_validate)(char **, int);
329 void (*f_send)(struct formats *);
330 void (*f_recv)(struct formats *);
331 int f_convert;
332} formats[] = {
333 { "netascii", validate_access, xmitfile, recvfile, 1 },
334 { "octet", validate_access, xmitfile, recvfile, 0 },
335#ifdef notdef
336 { "mail", validate_user, sendmail, recvmail, 1 },
337#endif
335 { 0 }
338 { 0, NULL, NULL, NULL, 0 }
336};
337
338struct options {
339};
340
341struct options {
339 char *o_type;
342 const char *o_type;
340 char *o_request;
341 int o_reply; /* turn into union if need be */
342} options[] = {
343 char *o_request;
344 int o_reply; /* turn into union if need be */
345} options[] = {
343 { "tsize" }, /* OPT_TSIZE */
344 { "timeout" }, /* OPT_TIMEOUT */
345 { NULL }
346 { "tsize", NULL, 0 }, /* OPT_TSIZE */
347 { "timeout", NULL, 0 }, /* OPT_TIMEOUT */
348 { NULL, NULL, 0 }
346};
347
348enum opt_enum {
349 OPT_TSIZE = 0,
350 OPT_TIMEOUT,
351};
352
353/*

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

574}
575
576/*
577 * Send the requested file.
578 */
579void
580xmitfile(struct formats *pf)
581{
349};
350
351enum opt_enum {
352 OPT_TSIZE = 0,
353 OPT_TIMEOUT,
354};
355
356/*

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

577}
578
579/*
580 * Send the requested file.
581 */
582void
583xmitfile(struct formats *pf)
584{
582 struct tftphdr *dp, *r_init();
585 struct tftphdr *dp;
583 struct tftphdr *ap; /* ack packet */
584 int size, n;
585 volatile unsigned short block;
586
587 signal(SIGALRM, timer);
588 dp = r_init();
589 ap = (struct tftphdr *)ackbuf;
590 block = 1;

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

653
654
655/*
656 * Receive a file.
657 */
658void
659recvfile(struct formats *pf)
660{
586 struct tftphdr *ap; /* ack packet */
587 int size, n;
588 volatile unsigned short block;
589
590 signal(SIGALRM, timer);
591 dp = r_init();
592 ap = (struct tftphdr *)ackbuf;
593 block = 1;

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

656
657
658/*
659 * Receive a file.
660 */
661void
662recvfile(struct formats *pf)
663{
661 struct tftphdr *dp, *w_init();
664 struct tftphdr *dp;
662 struct tftphdr *ap; /* ack buffer */
663 int n, size;
664 volatile unsigned short block;
665
666 signal(SIGALRM, timer);
667 dp = w_init();
668 ap = (struct tftphdr *)ackbuf;
669 block = 0;

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

726 (void) send(peer, ackbuf, 4, 0); /* resend final ack */
727 }
728abort:
729 return;
730}
731
732struct errmsg {
733 int e_code;
665 struct tftphdr *ap; /* ack buffer */
666 int n, size;
667 volatile unsigned short block;
668
669 signal(SIGALRM, timer);
670 dp = w_init();
671 ap = (struct tftphdr *)ackbuf;
672 block = 0;

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

729 (void) send(peer, ackbuf, 4, 0); /* resend final ack */
730 }
731abort:
732 return;
733}
734
735struct errmsg {
736 int e_code;
734 char *e_msg;
737 const char *e_msg;
735} errmsgs[] = {
736 { EUNDEF, "Undefined error code" },
737 { ENOTFOUND, "File not found" },
738 { EACCESS, "Access violation" },
739 { ENOSPACE, "Disk full or allocation exceeded" },
740 { EBADOP, "Illegal TFTP operation" },
741 { EBADID, "Unknown transfer ID" },
742 { EEXISTS, "File already exists" },
743 { ENOUSER, "No such user" },
744 { EOPTNEG, "Option negotiation" },
745 { -1, 0 }
746};
747
738} errmsgs[] = {
739 { EUNDEF, "Undefined error code" },
740 { ENOTFOUND, "File not found" },
741 { EACCESS, "Access violation" },
742 { ENOSPACE, "Disk full or allocation exceeded" },
743 { EBADOP, "Illegal TFTP operation" },
744 { EBADID, "Unknown transfer ID" },
745 { EEXISTS, "File already exists" },
746 { ENOUSER, "No such user" },
747 { EOPTNEG, "Option negotiation" },
748 { -1, 0 }
749};
750
748static char *
751static const char *
749errtomsg(int error)
750{
752errtomsg(int error)
753{
751 static char buf[20];
754 static char ebuf[20];
752 struct errmsg *pe;
753 if (error == 0)
754 return "success";
755 for (pe = errmsgs; pe->e_code >= 0; pe++)
756 if (pe->e_code == error)
757 return pe->e_msg;
755 struct errmsg *pe;
756 if (error == 0)
757 return "success";
758 for (pe = errmsgs; pe->e_code >= 0; pe++)
759 if (pe->e_code == error)
760 return pe->e_msg;
758 snprintf(buf, sizeof(buf), "error %d", error);
759 return buf;
761 snprintf(ebuf, sizeof(buf), "error %d", error);
762 return ebuf;
760}
761
762/*
763 * Send a nak packet (error message).
764 * Error code passed in is one of the
765 * standard TFTP codes, or a UNIX errno
766 * offset by 100.
767 */

--- 99 unchanged lines hidden ---
763}
764
765/*
766 * Send a nak packet (error message).
767 * Error code passed in is one of the
768 * standard TFTP codes, or a UNIX errno
769 * offset by 100.
770 */

--- 99 unchanged lines hidden ---