Deleted Added
full compact
tftpd.c (122916) tftpd.c (129680)
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 122916 2003-11-20 13:36:31Z sobomax $";
45 "$FreeBSD: head/libexec/tftpd/tftpd.c 129680 2004-05-24 22:56:15Z mdodd $";
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 */

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

104#define MAXDIRS 20
105static struct dirlist {
106 const char *name;
107 int len;
108} dirs[MAXDIRS+1];
109static int suppress_naks;
110static int logging;
111static int ipchroot;
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 */

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

104#define MAXDIRS 20
105static struct dirlist {
106 const char *name;
107 int len;
108} dirs[MAXDIRS+1];
109static int suppress_naks;
110static int logging;
111static int ipchroot;
112static int create_new = 0;
113static mode_t mask = S_IWGRP|S_IWOTH;
112
113static const char *errtomsg(int);
114static void nak(int);
115static void oack(void);
116
117static void timer(int);
118static void justquit(int);
119

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

125 int ch, on;
126 struct sockaddr_storage me;
127 int len;
128 char *chroot_dir = NULL;
129 struct passwd *nobody;
130 const char *chuser = "nobody";
131
132 openlog("tftpd", LOG_PID | LOG_NDELAY, LOG_FTP);
114
115static const char *errtomsg(int);
116static void nak(int);
117static void oack(void);
118
119static void timer(int);
120static void justquit(int);
121

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

127 int ch, on;
128 struct sockaddr_storage me;
129 int len;
130 char *chroot_dir = NULL;
131 struct passwd *nobody;
132 const char *chuser = "nobody";
133
134 openlog("tftpd", LOG_PID | LOG_NDELAY, LOG_FTP);
133 while ((ch = getopt(argc, argv, "cClns:u:")) != -1) {
135 while ((ch = getopt(argc, argv, "cClns:u:Uw")) != -1) {
134 switch (ch) {
135 case 'c':
136 ipchroot = 1;
137 break;
138 case 'C':
139 ipchroot = 2;
140 break;
141 case 'l':
142 logging = 1;
143 break;
144 case 'n':
145 suppress_naks = 1;
146 break;
147 case 's':
148 chroot_dir = optarg;
149 break;
150 case 'u':
151 chuser = optarg;
152 break;
136 switch (ch) {
137 case 'c':
138 ipchroot = 1;
139 break;
140 case 'C':
141 ipchroot = 2;
142 break;
143 case 'l':
144 logging = 1;
145 break;
146 case 'n':
147 suppress_naks = 1;
148 break;
149 case 's':
150 chroot_dir = optarg;
151 break;
152 case 'u':
153 chuser = optarg;
154 break;
155 case 'U':
156 mask = strtol(optarg, NULL, 0);
157 break;
158 case 'w':
159 create_new = 1;
160 break;
153 default:
154 syslog(LOG_WARNING, "ignoring unknown option -%c", ch);
155 }
156 }
157 if (optind < argc) {
158 struct dirlist *dirp;
159
160 /* Get list of directory prefixes. Skip relative pathnames. */

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

171 dirs->name = "/";
172 dirs->len = 1;
173 }
174 if (ipchroot > 0 && chroot_dir == NULL) {
175 syslog(LOG_ERR, "-c requires -s");
176 exit(1);
177 }
178
161 default:
162 syslog(LOG_WARNING, "ignoring unknown option -%c", ch);
163 }
164 }
165 if (optind < argc) {
166 struct dirlist *dirp;
167
168 /* Get list of directory prefixes. Skip relative pathnames. */

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

179 dirs->name = "/";
180 dirs->len = 1;
181 }
182 if (ipchroot > 0 && chroot_dir == NULL) {
183 syslog(LOG_ERR, "-c requires -s");
184 exit(1);
185 }
186
187 umask(mask);
188
179 on = 1;
180 if (ioctl(0, FIONBIO, &on) < 0) {
181 syslog(LOG_ERR, "ioctl(FIONBIO): %m");
182 exit(1);
183 }
184 fromlen = sizeof (from);
185 n = recvfrom(0, buf, sizeof (buf), 0,
186 (struct sockaddr *)&from, &fromlen);

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

548 if (stat(pathname, &stbuf) == 0 &&
549 (stbuf.st_mode & S_IFMT) == S_IFREG) {
550 if ((stbuf.st_mode & S_IROTH) != 0) {
551 break;
552 }
553 err = EACCESS;
554 }
555 }
189 on = 1;
190 if (ioctl(0, FIONBIO, &on) < 0) {
191 syslog(LOG_ERR, "ioctl(FIONBIO): %m");
192 exit(1);
193 }
194 fromlen = sizeof (from);
195 n = recvfrom(0, buf, sizeof (buf), 0,
196 (struct sockaddr *)&from, &fromlen);

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

558 if (stat(pathname, &stbuf) == 0 &&
559 (stbuf.st_mode & S_IFMT) == S_IFREG) {
560 if ((stbuf.st_mode & S_IROTH) != 0) {
561 break;
562 }
563 err = EACCESS;
564 }
565 }
556 if (dirp->name == NULL)
566 if (dirp->name != NULL)
567 *filep = filename = pathname;
568 else if (mode == RRQ)
557 return (err);
569 return (err);
558 *filep = filename = pathname;
559 }
560 if (options[OPT_TSIZE].o_request) {
561 if (mode == RRQ)
562 options[OPT_TSIZE].o_reply = stbuf.st_size;
563 else
564 /* XXX Allows writes of all sizes. */
565 options[OPT_TSIZE].o_reply =
566 atoi(options[OPT_TSIZE].o_request);
567 }
570 }
571 if (options[OPT_TSIZE].o_request) {
572 if (mode == RRQ)
573 options[OPT_TSIZE].o_reply = stbuf.st_size;
574 else
575 /* XXX Allows writes of all sizes. */
576 options[OPT_TSIZE].o_reply =
577 atoi(options[OPT_TSIZE].o_request);
578 }
568 fd = open(filename, mode == RRQ ? O_RDONLY : O_WRONLY|O_TRUNC);
579 if (mode == RRQ)
580 fd = open(filename, O_RDONLY);
581 else {
582 if (create_new)
583 fd = open(filename, O_WRONLY|O_TRUNC|O_CREAT, 0666);
584 else
585 fd = open(filename, O_WRONLY|O_TRUNC);
586 }
569 if (fd < 0)
570 return (errno + 100);
571 file = fdopen(fd, (mode == RRQ)? "r":"w");
572 if (file == NULL) {
573 return errno+100;
574 }
575 return (0);
576}

--- 303 unchanged lines hidden ---
587 if (fd < 0)
588 return (errno + 100);
589 file = fdopen(fd, (mode == RRQ)? "r":"w");
590 if (file == NULL) {
591 return errno+100;
592 }
593 return (0);
594}

--- 303 unchanged lines hidden ---