tftpd.c revision 1.2 1 1.1 cgd /*
2 1.1 cgd * Copyright (c) 1983 Regents of the University of California.
3 1.1 cgd * All rights reserved.
4 1.1 cgd *
5 1.1 cgd * Redistribution and use in source and binary forms, with or without
6 1.1 cgd * modification, are permitted provided that the following conditions
7 1.1 cgd * are met:
8 1.1 cgd * 1. Redistributions of source code must retain the above copyright
9 1.1 cgd * notice, this list of conditions and the following disclaimer.
10 1.1 cgd * 2. Redistributions in binary form must reproduce the above copyright
11 1.1 cgd * notice, this list of conditions and the following disclaimer in the
12 1.1 cgd * documentation and/or other materials provided with the distribution.
13 1.1 cgd * 3. All advertising materials mentioning features or use of this software
14 1.1 cgd * must display the following acknowledgement:
15 1.1 cgd * This product includes software developed by the University of
16 1.1 cgd * California, Berkeley and its contributors.
17 1.1 cgd * 4. Neither the name of the University nor the names of its contributors
18 1.1 cgd * may be used to endorse or promote products derived from this software
19 1.1 cgd * without specific prior written permission.
20 1.1 cgd *
21 1.1 cgd * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 1.1 cgd * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 1.1 cgd * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 1.1 cgd * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 1.1 cgd * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 1.1 cgd * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 1.1 cgd * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 1.1 cgd * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 1.1 cgd * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 1.1 cgd * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 1.1 cgd * SUCH DAMAGE.
32 1.1 cgd */
33 1.1 cgd
34 1.1 cgd #ifndef lint
35 1.1 cgd char copyright[] =
36 1.1 cgd "@(#) Copyright (c) 1983 Regents of the University of California.\n\
37 1.1 cgd All rights reserved.\n";
38 1.1 cgd #endif /* not lint */
39 1.1 cgd
40 1.1 cgd #ifndef lint
41 1.1 cgd static char sccsid[] = "@(#)tftpd.c 5.13 (Berkeley) 2/26/91";
42 1.1 cgd #endif /* not lint */
43 1.1 cgd
44 1.1 cgd /*
45 1.1 cgd * Trivial file transfer protocol server.
46 1.1 cgd *
47 1.1 cgd * This version includes many modifications by Jim Guyton <guyton@rand-unix>
48 1.1 cgd */
49 1.1 cgd
50 1.1 cgd #include <sys/types.h>
51 1.1 cgd #include <sys/ioctl.h>
52 1.1 cgd #include <sys/stat.h>
53 1.1 cgd #include <signal.h>
54 1.1 cgd #include <fcntl.h>
55 1.1 cgd
56 1.1 cgd #include <sys/socket.h>
57 1.1 cgd #include <netinet/in.h>
58 1.1 cgd #include <arpa/tftp.h>
59 1.1 cgd #include <netdb.h>
60 1.1 cgd
61 1.1 cgd #include <setjmp.h>
62 1.1 cgd #include <syslog.h>
63 1.1 cgd #include <stdio.h>
64 1.1 cgd #include <errno.h>
65 1.1 cgd #include <ctype.h>
66 1.1 cgd #include <string.h>
67 1.1 cgd #include <stdlib.h>
68 1.1 cgd
69 1.1 cgd #define TIMEOUT 5
70 1.1 cgd
71 1.1 cgd extern int errno;
72 1.2 mycroft struct sockaddr_in s_in = { AF_INET };
73 1.1 cgd int peer;
74 1.1 cgd int rexmtval = TIMEOUT;
75 1.1 cgd int maxtimeout = 5*TIMEOUT;
76 1.1 cgd
77 1.1 cgd #define PKTSIZE SEGSIZE+4
78 1.1 cgd char buf[PKTSIZE];
79 1.1 cgd char ackbuf[PKTSIZE];
80 1.1 cgd struct sockaddr_in from;
81 1.1 cgd int fromlen;
82 1.1 cgd
83 1.1 cgd #define MAXARG 4
84 1.1 cgd char *dirs[MAXARG+1];
85 1.1 cgd
86 1.1 cgd main(ac, av)
87 1.1 cgd char **av;
88 1.1 cgd {
89 1.1 cgd register struct tftphdr *tp;
90 1.1 cgd register int n = 0;
91 1.1 cgd int on = 1;
92 1.1 cgd
93 1.1 cgd ac--; av++;
94 1.1 cgd while (ac-- > 0 && n < MAXARG)
95 1.1 cgd dirs[n++] = *av++;
96 1.1 cgd openlog("tftpd", LOG_PID, LOG_DAEMON);
97 1.1 cgd if (ioctl(0, FIONBIO, &on) < 0) {
98 1.1 cgd syslog(LOG_ERR, "ioctl(FIONBIO): %m\n");
99 1.1 cgd exit(1);
100 1.1 cgd }
101 1.1 cgd fromlen = sizeof (from);
102 1.1 cgd n = recvfrom(0, buf, sizeof (buf), 0,
103 1.1 cgd (struct sockaddr *)&from, &fromlen);
104 1.1 cgd if (n < 0) {
105 1.1 cgd syslog(LOG_ERR, "recvfrom: %m\n");
106 1.1 cgd exit(1);
107 1.1 cgd }
108 1.1 cgd /*
109 1.1 cgd * Now that we have read the message out of the UDP
110 1.1 cgd * socket, we fork and exit. Thus, inetd will go back
111 1.1 cgd * to listening to the tftp port, and the next request
112 1.1 cgd * to come in will start up a new instance of tftpd.
113 1.1 cgd *
114 1.1 cgd * We do this so that inetd can run tftpd in "wait" mode.
115 1.1 cgd * The problem with tftpd running in "nowait" mode is that
116 1.1 cgd * inetd may get one or more successful "selects" on the
117 1.1 cgd * tftp port before we do our receive, so more than one
118 1.1 cgd * instance of tftpd may be started up. Worse, if tftpd
119 1.1 cgd * break before doing the above "recvfrom", inetd would
120 1.1 cgd * spawn endless instances, clogging the system.
121 1.1 cgd */
122 1.1 cgd {
123 1.1 cgd int pid;
124 1.1 cgd int i, j;
125 1.1 cgd
126 1.1 cgd for (i = 1; i < 20; i++) {
127 1.1 cgd pid = fork();
128 1.1 cgd if (pid < 0) {
129 1.1 cgd sleep(i);
130 1.1 cgd /*
131 1.1 cgd * flush out to most recently sent request.
132 1.1 cgd *
133 1.1 cgd * This may drop some request, but those
134 1.1 cgd * will be resent by the clients when
135 1.1 cgd * they timeout. The positive effect of
136 1.1 cgd * this flush is to (try to) prevent more
137 1.1 cgd * than one tftpd being started up to service
138 1.1 cgd * a single request from a single client.
139 1.1 cgd */
140 1.1 cgd j = sizeof from;
141 1.1 cgd i = recvfrom(0, buf, sizeof (buf), 0,
142 1.1 cgd (struct sockaddr *)&from, &j);
143 1.1 cgd if (i > 0) {
144 1.1 cgd n = i;
145 1.1 cgd fromlen = j;
146 1.1 cgd }
147 1.1 cgd } else {
148 1.1 cgd break;
149 1.1 cgd }
150 1.1 cgd }
151 1.1 cgd if (pid < 0) {
152 1.1 cgd syslog(LOG_ERR, "fork: %m\n");
153 1.1 cgd exit(1);
154 1.1 cgd } else if (pid != 0) {
155 1.1 cgd exit(0);
156 1.1 cgd }
157 1.1 cgd }
158 1.1 cgd from.sin_family = AF_INET;
159 1.1 cgd alarm(0);
160 1.1 cgd close(0);
161 1.1 cgd close(1);
162 1.1 cgd peer = socket(AF_INET, SOCK_DGRAM, 0);
163 1.1 cgd if (peer < 0) {
164 1.1 cgd syslog(LOG_ERR, "socket: %m\n");
165 1.1 cgd exit(1);
166 1.1 cgd }
167 1.2 mycroft if (bind(peer, (struct sockaddr *)&s_in, sizeof (s_in)) < 0) {
168 1.1 cgd syslog(LOG_ERR, "bind: %m\n");
169 1.1 cgd exit(1);
170 1.1 cgd }
171 1.1 cgd if (connect(peer, (struct sockaddr *)&from, sizeof(from)) < 0) {
172 1.1 cgd syslog(LOG_ERR, "connect: %m\n");
173 1.1 cgd exit(1);
174 1.1 cgd }
175 1.1 cgd tp = (struct tftphdr *)buf;
176 1.1 cgd tp->th_opcode = ntohs(tp->th_opcode);
177 1.1 cgd if (tp->th_opcode == RRQ || tp->th_opcode == WRQ)
178 1.1 cgd tftp(tp, n);
179 1.1 cgd exit(1);
180 1.1 cgd }
181 1.1 cgd
182 1.1 cgd int validate_access();
183 1.1 cgd int sendfile(), recvfile();
184 1.1 cgd
185 1.1 cgd struct formats {
186 1.1 cgd char *f_mode;
187 1.1 cgd int (*f_validate)();
188 1.1 cgd int (*f_send)();
189 1.1 cgd int (*f_recv)();
190 1.1 cgd int f_convert;
191 1.1 cgd } formats[] = {
192 1.1 cgd { "netascii", validate_access, sendfile, recvfile, 1 },
193 1.1 cgd { "octet", validate_access, sendfile, recvfile, 0 },
194 1.1 cgd #ifdef notdef
195 1.1 cgd { "mail", validate_user, sendmail, recvmail, 1 },
196 1.1 cgd #endif
197 1.1 cgd { 0 }
198 1.1 cgd };
199 1.1 cgd
200 1.1 cgd /*
201 1.1 cgd * Handle initial connection protocol.
202 1.1 cgd */
203 1.1 cgd tftp(tp, size)
204 1.1 cgd struct tftphdr *tp;
205 1.1 cgd int size;
206 1.1 cgd {
207 1.1 cgd register char *cp;
208 1.1 cgd int first = 1, ecode;
209 1.1 cgd register struct formats *pf;
210 1.1 cgd char *filename, *mode;
211 1.1 cgd
212 1.1 cgd filename = cp = tp->th_stuff;
213 1.1 cgd again:
214 1.1 cgd while (cp < buf + size) {
215 1.1 cgd if (*cp == '\0')
216 1.1 cgd break;
217 1.1 cgd cp++;
218 1.1 cgd }
219 1.1 cgd if (*cp != '\0') {
220 1.1 cgd nak(EBADOP);
221 1.1 cgd exit(1);
222 1.1 cgd }
223 1.1 cgd if (first) {
224 1.1 cgd mode = ++cp;
225 1.1 cgd first = 0;
226 1.1 cgd goto again;
227 1.1 cgd }
228 1.1 cgd for (cp = mode; *cp; cp++)
229 1.1 cgd if (isupper(*cp))
230 1.1 cgd *cp = tolower(*cp);
231 1.1 cgd for (pf = formats; pf->f_mode; pf++)
232 1.1 cgd if (strcmp(pf->f_mode, mode) == 0)
233 1.1 cgd break;
234 1.1 cgd if (pf->f_mode == 0) {
235 1.1 cgd nak(EBADOP);
236 1.1 cgd exit(1);
237 1.1 cgd }
238 1.1 cgd ecode = (*pf->f_validate)(filename, tp->th_opcode);
239 1.1 cgd if (ecode) {
240 1.1 cgd nak(ecode);
241 1.1 cgd exit(1);
242 1.1 cgd }
243 1.1 cgd if (tp->th_opcode == WRQ)
244 1.1 cgd (*pf->f_recv)(pf);
245 1.1 cgd else
246 1.1 cgd (*pf->f_send)(pf);
247 1.1 cgd exit(0);
248 1.1 cgd }
249 1.1 cgd
250 1.1 cgd
251 1.1 cgd FILE *file;
252 1.1 cgd
253 1.1 cgd /*
254 1.1 cgd * Validate file access. Since we
255 1.1 cgd * have no uid or gid, for now require
256 1.1 cgd * file to exist and be publicly
257 1.1 cgd * readable/writable.
258 1.1 cgd * If we were invoked with arguments
259 1.1 cgd * from inetd then the file must also be
260 1.1 cgd * in one of the given directory prefixes.
261 1.1 cgd * Note also, full path name must be
262 1.1 cgd * given as we have no login directory.
263 1.1 cgd */
264 1.1 cgd validate_access(filename, mode)
265 1.1 cgd char *filename;
266 1.1 cgd int mode;
267 1.1 cgd {
268 1.1 cgd struct stat stbuf;
269 1.1 cgd int fd;
270 1.1 cgd char *cp, **dirp;
271 1.1 cgd
272 1.1 cgd if (*filename != '/')
273 1.1 cgd return (EACCESS);
274 1.1 cgd /*
275 1.1 cgd * prevent tricksters from getting around the directory restrictions
276 1.1 cgd */
277 1.1 cgd for (cp = filename + 1; *cp; cp++)
278 1.1 cgd if(*cp == '.' && strncmp(cp-1, "/../", 4) == 0)
279 1.1 cgd return(EACCESS);
280 1.1 cgd for (dirp = dirs; *dirp; dirp++)
281 1.1 cgd if (strncmp(filename, *dirp, strlen(*dirp)) == 0)
282 1.1 cgd break;
283 1.1 cgd if (*dirp==0 && dirp!=dirs)
284 1.1 cgd return (EACCESS);
285 1.1 cgd if (stat(filename, &stbuf) < 0)
286 1.1 cgd return (errno == ENOENT ? ENOTFOUND : EACCESS);
287 1.1 cgd if (mode == RRQ) {
288 1.1 cgd if ((stbuf.st_mode&(S_IREAD >> 6)) == 0)
289 1.1 cgd return (EACCESS);
290 1.1 cgd } else {
291 1.1 cgd if ((stbuf.st_mode&(S_IWRITE >> 6)) == 0)
292 1.1 cgd return (EACCESS);
293 1.1 cgd }
294 1.1 cgd fd = open(filename, mode == RRQ ? 0 : 1);
295 1.1 cgd if (fd < 0)
296 1.1 cgd return (errno + 100);
297 1.1 cgd file = fdopen(fd, (mode == RRQ)? "r":"w");
298 1.1 cgd if (file == NULL) {
299 1.1 cgd return errno+100;
300 1.1 cgd }
301 1.1 cgd return (0);
302 1.1 cgd }
303 1.1 cgd
304 1.1 cgd int timeout;
305 1.1 cgd jmp_buf timeoutbuf;
306 1.1 cgd
307 1.1 cgd void
308 1.1 cgd timer()
309 1.1 cgd {
310 1.1 cgd
311 1.1 cgd timeout += rexmtval;
312 1.1 cgd if (timeout >= maxtimeout)
313 1.1 cgd exit(1);
314 1.1 cgd longjmp(timeoutbuf, 1);
315 1.1 cgd }
316 1.1 cgd
317 1.1 cgd /*
318 1.1 cgd * Send the requested file.
319 1.1 cgd */
320 1.1 cgd sendfile(pf)
321 1.1 cgd struct formats *pf;
322 1.1 cgd {
323 1.1 cgd struct tftphdr *dp, *r_init();
324 1.1 cgd register struct tftphdr *ap; /* ack packet */
325 1.1 cgd register int block = 1, size, n;
326 1.1 cgd
327 1.1 cgd signal(SIGALRM, timer);
328 1.1 cgd dp = r_init();
329 1.1 cgd ap = (struct tftphdr *)ackbuf;
330 1.1 cgd do {
331 1.1 cgd size = readit(file, &dp, pf->f_convert);
332 1.1 cgd if (size < 0) {
333 1.1 cgd nak(errno + 100);
334 1.1 cgd goto abort;
335 1.1 cgd }
336 1.1 cgd dp->th_opcode = htons((u_short)DATA);
337 1.1 cgd dp->th_block = htons((u_short)block);
338 1.1 cgd timeout = 0;
339 1.1 cgd (void) setjmp(timeoutbuf);
340 1.1 cgd
341 1.1 cgd send_data:
342 1.1 cgd if (send(peer, dp, size + 4, 0) != size + 4) {
343 1.1 cgd syslog(LOG_ERR, "tftpd: write: %m\n");
344 1.1 cgd goto abort;
345 1.1 cgd }
346 1.1 cgd read_ahead(file, pf->f_convert);
347 1.1 cgd for ( ; ; ) {
348 1.1 cgd alarm(rexmtval); /* read the ack */
349 1.1 cgd n = recv(peer, ackbuf, sizeof (ackbuf), 0);
350 1.1 cgd alarm(0);
351 1.1 cgd if (n < 0) {
352 1.1 cgd syslog(LOG_ERR, "tftpd: read: %m\n");
353 1.1 cgd goto abort;
354 1.1 cgd }
355 1.1 cgd ap->th_opcode = ntohs((u_short)ap->th_opcode);
356 1.1 cgd ap->th_block = ntohs((u_short)ap->th_block);
357 1.1 cgd
358 1.1 cgd if (ap->th_opcode == ERROR)
359 1.1 cgd goto abort;
360 1.1 cgd
361 1.1 cgd if (ap->th_opcode == ACK) {
362 1.1 cgd if (ap->th_block == block) {
363 1.1 cgd break;
364 1.1 cgd }
365 1.1 cgd /* Re-synchronize with the other side */
366 1.1 cgd (void) synchnet(peer);
367 1.1 cgd if (ap->th_block == (block -1)) {
368 1.1 cgd goto send_data;
369 1.1 cgd }
370 1.1 cgd }
371 1.1 cgd
372 1.1 cgd }
373 1.1 cgd block++;
374 1.1 cgd } while (size == SEGSIZE);
375 1.1 cgd abort:
376 1.1 cgd (void) fclose(file);
377 1.1 cgd }
378 1.1 cgd
379 1.1 cgd void
380 1.1 cgd justquit()
381 1.1 cgd {
382 1.1 cgd exit(0);
383 1.1 cgd }
384 1.1 cgd
385 1.1 cgd
386 1.1 cgd /*
387 1.1 cgd * Receive a file.
388 1.1 cgd */
389 1.1 cgd recvfile(pf)
390 1.1 cgd struct formats *pf;
391 1.1 cgd {
392 1.1 cgd struct tftphdr *dp, *w_init();
393 1.1 cgd register struct tftphdr *ap; /* ack buffer */
394 1.1 cgd register int block = 0, n, size;
395 1.1 cgd
396 1.1 cgd signal(SIGALRM, timer);
397 1.1 cgd dp = w_init();
398 1.1 cgd ap = (struct tftphdr *)ackbuf;
399 1.1 cgd do {
400 1.1 cgd timeout = 0;
401 1.1 cgd ap->th_opcode = htons((u_short)ACK);
402 1.1 cgd ap->th_block = htons((u_short)block);
403 1.1 cgd block++;
404 1.1 cgd (void) setjmp(timeoutbuf);
405 1.1 cgd send_ack:
406 1.1 cgd if (send(peer, ackbuf, 4, 0) != 4) {
407 1.1 cgd syslog(LOG_ERR, "tftpd: write: %m\n");
408 1.1 cgd goto abort;
409 1.1 cgd }
410 1.1 cgd write_behind(file, pf->f_convert);
411 1.1 cgd for ( ; ; ) {
412 1.1 cgd alarm(rexmtval);
413 1.1 cgd n = recv(peer, dp, PKTSIZE, 0);
414 1.1 cgd alarm(0);
415 1.1 cgd if (n < 0) { /* really? */
416 1.1 cgd syslog(LOG_ERR, "tftpd: read: %m\n");
417 1.1 cgd goto abort;
418 1.1 cgd }
419 1.1 cgd dp->th_opcode = ntohs((u_short)dp->th_opcode);
420 1.1 cgd dp->th_block = ntohs((u_short)dp->th_block);
421 1.1 cgd if (dp->th_opcode == ERROR)
422 1.1 cgd goto abort;
423 1.1 cgd if (dp->th_opcode == DATA) {
424 1.1 cgd if (dp->th_block == block) {
425 1.1 cgd break; /* normal */
426 1.1 cgd }
427 1.1 cgd /* Re-synchronize with the other side */
428 1.1 cgd (void) synchnet(peer);
429 1.1 cgd if (dp->th_block == (block-1))
430 1.1 cgd goto send_ack; /* rexmit */
431 1.1 cgd }
432 1.1 cgd }
433 1.1 cgd /* size = write(file, dp->th_data, n - 4); */
434 1.1 cgd size = writeit(file, &dp, n - 4, pf->f_convert);
435 1.1 cgd if (size != (n-4)) { /* ahem */
436 1.1 cgd if (size < 0) nak(errno + 100);
437 1.1 cgd else nak(ENOSPACE);
438 1.1 cgd goto abort;
439 1.1 cgd }
440 1.1 cgd } while (size == SEGSIZE);
441 1.1 cgd write_behind(file, pf->f_convert);
442 1.1 cgd (void) fclose(file); /* close data file */
443 1.1 cgd
444 1.1 cgd ap->th_opcode = htons((u_short)ACK); /* send the "final" ack */
445 1.1 cgd ap->th_block = htons((u_short)(block));
446 1.1 cgd (void) send(peer, ackbuf, 4, 0);
447 1.1 cgd
448 1.1 cgd signal(SIGALRM, justquit); /* just quit on timeout */
449 1.1 cgd alarm(rexmtval);
450 1.1 cgd n = recv(peer, buf, sizeof (buf), 0); /* normally times out and quits */
451 1.1 cgd alarm(0);
452 1.1 cgd if (n >= 4 && /* if read some data */
453 1.1 cgd dp->th_opcode == DATA && /* and got a data block */
454 1.1 cgd block == dp->th_block) { /* then my last ack was lost */
455 1.1 cgd (void) send(peer, ackbuf, 4, 0); /* resend final ack */
456 1.1 cgd }
457 1.1 cgd abort:
458 1.1 cgd return;
459 1.1 cgd }
460 1.1 cgd
461 1.1 cgd struct errmsg {
462 1.1 cgd int e_code;
463 1.1 cgd char *e_msg;
464 1.1 cgd } errmsgs[] = {
465 1.1 cgd { EUNDEF, "Undefined error code" },
466 1.1 cgd { ENOTFOUND, "File not found" },
467 1.1 cgd { EACCESS, "Access violation" },
468 1.1 cgd { ENOSPACE, "Disk full or allocation exceeded" },
469 1.1 cgd { EBADOP, "Illegal TFTP operation" },
470 1.1 cgd { EBADID, "Unknown transfer ID" },
471 1.1 cgd { EEXISTS, "File already exists" },
472 1.1 cgd { ENOUSER, "No such user" },
473 1.1 cgd { -1, 0 }
474 1.1 cgd };
475 1.1 cgd
476 1.1 cgd /*
477 1.1 cgd * Send a nak packet (error message).
478 1.1 cgd * Error code passed in is one of the
479 1.1 cgd * standard TFTP codes, or a UNIX errno
480 1.1 cgd * offset by 100.
481 1.1 cgd */
482 1.1 cgd nak(error)
483 1.1 cgd int error;
484 1.1 cgd {
485 1.1 cgd register struct tftphdr *tp;
486 1.1 cgd int length;
487 1.1 cgd register struct errmsg *pe;
488 1.1 cgd
489 1.1 cgd tp = (struct tftphdr *)buf;
490 1.1 cgd tp->th_opcode = htons((u_short)ERROR);
491 1.1 cgd tp->th_code = htons((u_short)error);
492 1.1 cgd for (pe = errmsgs; pe->e_code >= 0; pe++)
493 1.1 cgd if (pe->e_code == error)
494 1.1 cgd break;
495 1.1 cgd if (pe->e_code < 0) {
496 1.1 cgd pe->e_msg = strerror(error - 100);
497 1.1 cgd tp->th_code = EUNDEF; /* set 'undef' errorcode */
498 1.1 cgd }
499 1.1 cgd strcpy(tp->th_msg, pe->e_msg);
500 1.1 cgd length = strlen(pe->e_msg);
501 1.1 cgd tp->th_msg[length] = '\0';
502 1.1 cgd length += 5;
503 1.1 cgd if (send(peer, buf, length, 0) != length)
504 1.1 cgd syslog(LOG_ERR, "nak: %m\n");
505 1.1 cgd }
506