patch-freebsd 11.8 KB
Newer Older
Mike Hibler's avatar
Mike Hibler committed
1
2
diff -rcN tftp-hpa-0.33.orig/MCONFIG.in tftp-hpa-0.33/MCONFIG.in
*** tftp-hpa-0.33.orig/MCONFIG.in	Tue Nov 27 03:18:11 2001
Mike Hibler's avatar
Mike Hibler committed
3
--- tftp-hpa-0.33/MCONFIG.in	Thu Feb  6 13:07:09 2003
Mike Hibler's avatar
Mike Hibler committed
4
5
6
7
8
9
10
11
12
13
14
15
16
***************
*** 27,32 ****
--- 27,36 ----
  
  # System binaries
  SBINDIR = @sbindir@
+ LIBEXECDIR = @libexecdir@
+ 
+ # Config info
+ ETCDIR = @sysconfdir@
  
  # Binary suffixes
  O = @OBJEXT@
Mike Hibler's avatar
Mike Hibler committed
17
18
19
20
21
22
23
24
25
26
***************
*** 42,47 ****
--- 46,52 ----
  INSTALL         = @INSTALL@
  INSTALL_PROGRAM = @INSTALL_PROGRAM@
  INSTALL_DATA    = @INSTALL_DATA@
+ INSTALL_SCRIPT  = @INSTALL_SCRIPT@
  
  # Compiler and compiler flags
  CC      = @CC@
Mike Hibler's avatar
Mike Hibler committed
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
diff -rcN tftp-hpa-0.33.orig/configure tftp-hpa-0.33/configure
*** tftp-hpa-0.33.orig/configure	Sun Feb  2 18:33:26 2003
--- tftp-hpa-0.33/configure	Wed Feb  5 14:03:10 2003
***************
*** 9652,9658 ****
  fi
  
  if $LIBXTRA; then
! 	LIBS="../lib/libxtra.a $LIBS"
  fi
  
  
--- 9652,9658 ----
  fi
  
  if $LIBXTRA; then
! 	LIBSXTRA=../lib/libxtra.a
  fi
  
  
***************
*** 10647,10653 ****
  fi
  fi;
  
! TFTPD_LIBS="$LIBS"
  LIBS="$common_libs"
  
  
--- 10647,10653 ----
  fi
  fi;
  
! TFTPD_LIBS="$LIBSXTRA $LIBS"
  LIBS="$common_libs"
  
  
***************
*** 11559,11565 ****
  fi
  fi;
  
! TFTP_LIBS="$LIBS"
  LIBS="$common_libs"
  
  
--- 11559,11565 ----
  fi
  fi;
  
! TFTP_LIBS="$LIBSXTRA $LIBS"
  LIBS="$common_libs"
  
  
diff -rcN tftp-hpa-0.33.orig/configure.in tftp-hpa-0.33/configure.in
*** tftp-hpa-0.33.orig/configure.in	Thu Jan 30 19:17:01 2003
--- tftp-hpa-0.33/configure.in	Wed Feb  5 14:03:10 2003
***************
*** 124,130 ****
  AC_SEARCH_LIBS(xstrdup, iberty, , LIBXTRA=true AC_LIBOBJ(xstrdup))
  AC_SEARCH_LIBS(bsd_signal, bsd, , LIBXTRA=true AC_LIBOBJ(bsdsignal))
  if $LIBXTRA; then
! 	LIBS="../lib/libxtra.a $LIBS"
  fi
  
  dnl
--- 124,130 ----
  AC_SEARCH_LIBS(xstrdup, iberty, , LIBXTRA=true AC_LIBOBJ(xstrdup))
  AC_SEARCH_LIBS(bsd_signal, bsd, , LIBXTRA=true AC_LIBOBJ(bsdsignal))
  if $LIBXTRA; then
! 	LIBSXTRA=../lib/libxtra.a
  fi
  
  dnl
***************
*** 159,165 ****
  	])
  ],:)
  
! TFTPD_LIBS="$LIBS"
  LIBS="$common_libs"
  
  dnl
--- 159,165 ----
  	])
  ],:)
  
! TFTPD_LIBS="$LIBSXTRA $LIBS"
  LIBS="$common_libs"
  
  dnl
***************
*** 187,193 ****
  	])
  ],:)
  
! TFTP_LIBS="$LIBS"
  LIBS="$common_libs"
  
  AC_SUBST(TFTP_LIBS)
--- 187,193 ----
  	])
  ],:)
  
! TFTP_LIBS="$LIBSXTRA $LIBS"
  LIBS="$common_libs"
  
  AC_SUBST(TFTP_LIBS)
diff -rcN tftp-hpa-0.33.orig/tftpd/Makefile tftp-hpa-0.33/tftpd/Makefile
*** tftp-hpa-0.33.orig/tftpd/Makefile	Tue Nov 27 03:18:11 2001
Mike Hibler's avatar
Mike Hibler committed
137
--- tftp-hpa-0.33/tftpd/Makefile	Thu Feb  6 13:08:32 2003
Mike Hibler's avatar
Mike Hibler committed
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
***************
*** 23,32 ****
  	sed -e 's/@@VERSION@@/$(VERSION)/g' < $< > $@
  
  install: all
! 	mkdir -p $(INSTALLROOT)$(SBINDIR) $(INSTALLROOT)$(MANDIR)/man8
! 	$(INSTALL_PROGRAM) tftpd$(X) $(INSTALLROOT)$(SBINDIR)/in.tftpd
! 	$(INSTALL_DATA)    tftpd.8 $(INSTALLROOT)$(MANDIR)/man8/in.tftpd.8
! 	cd $(INSTALLROOT)$(MANDIR)/man8 && $(LN_S) -f in.tftpd.8 tftpd.8
  
  clean:
  	rm -f *.o *.obj *.exe tftpd tftpsubs.c tftpsubs.h tftpd.8
--- 23,33 ----
  	sed -e 's/@@VERSION@@/$(VERSION)/g' < $< > $@
  
  install: all
! 	mkdir -p $(INSTALLROOT)$(LIBEXECDIR) $(INSTALLROOT)$(MANDIR)/man8
! 	$(INSTALL_PROGRAM) tftpd$(X) $(INSTALLROOT)$(LIBEXECDIR)/tftpd
! 	$(INSTALL_DATA)    tftpd.8 $(INSTALLROOT)$(MANDIR)/man8/tftpd.8
Mike Hibler's avatar
Mike Hibler committed
157
! 	$(INSTALL_SCRIPT) -m 555 tftpd-hpa.sh $(INSTALLROOT)$(ETCDIR)/rc.d/
Mike Hibler's avatar
Mike Hibler committed
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
! 	$(INSTALL_DATA)    tftpd.rules $(INSTALLROOT)$(ETCDIR)/
  
  clean:
  	rm -f *.o *.obj *.exe tftpd tftpsubs.c tftpsubs.h tftpd.8
diff -rcN tftp-hpa-0.33.orig/tftpd/tftpd-hpa.sh tftp-hpa-0.33/tftpd/tftpd-hpa.sh
*** tftp-hpa-0.33.orig/tftpd/tftpd-hpa.sh	Wed Dec 31 17:00:00 1969
--- tftp-hpa-0.33/tftpd/tftpd-hpa.sh	Wed Feb  5 14:28:33 2003
***************
*** 0 ****
--- 1,43 ----
+ #!/bin/sh
+ #
+ 
+ if ! PREFIX=$(expr $0 : "\(/.*\)/etc/rc\.d/$(basename $0)\$"); then
+     echo "$0: Cannot determine the PREFIX" >&2
+     exit 1
+ fi
+ 
+ tftpd_flags="-l"
+ 
+ if [ -z "${source_rc_confs_defined}" ]; then
+ 	if [ -r /etc/defaults/rc.conf ]; then
+ 		. /etc/defaults/rc.conf
+ 		source_rc_confs
+ 	elif [ -r /etc/rc.conf ]; then
+ 		. /etc/rc.conf
+ 	fi
+ fi
+ 
+ if [ -r ${PREFIX}/etc/tftpd.rules ]; then
+ 	tftpd_flags="-m ${PREFIX}/etc/tftpd.rules $tftpd_flags"
+ fi
+ 
+ case "$1" in
+ start)
+ 	if [ -x ${PREFIX}/libexec/tftpd ]; then
+ 		echo -n ' tftpd'
+ 		if [ `grep -c -E '^tftp' /etc/inetd.conf` -ne 0 ]; then
+ 			echo ": enabled in inetd.conf, not starting daemon"
+ 		else
+ 			${PREFIX}/libexec/tftpd $tftpd_flags
+ 		fi
+ 	fi
+ 	;;
+ stop)
+ 	killall tftpd && echo -n ' tftpd'
+ 	;;
+ *)
+ 	echo "Usage: `basename $0` {start|stop}" >&2
+ 	;;
+ esac
+ 
+ exit 0
diff -rcN tftp-hpa-0.33.orig/tftpd/tftpd.c tftp-hpa-0.33/tftpd/tftpd.c
*** tftp-hpa-0.33.orig/tftpd/tftpd.c	Thu Jan 30 19:22:33 2003
--- tftp-hpa-0.33/tftpd/tftpd.c	Wed Feb  5 14:03:10 2003
***************
*** 61,66 ****
--- 61,67 ----
  #include <pwd.h>
  #include <limits.h>
  #include <syslog.h>
+ #include <sys/wait.h>
  
  #include "tftpsubs.h"
  #include "recvfrom.h"
***************
*** 107,112 ****
--- 108,115 ----
  int	unixperms = 0;
  
  int verbosity = 0;
+ int maxchildren = 0;
+ int numchildren;
  
  struct formats;
  #ifdef WITH_REGEX
***************
*** 152,159 ****
  {
    (void)sig;			/* Suppress unused warning */
    timeout <<= 1;
!   if (timeout >= maxtimeout || timeout_quit)
      exit(0);
    siglongjmp(timeoutbuf, 1);
  }
  
--- 155,165 ----
  {
    (void)sig;			/* Suppress unused warning */
    timeout <<= 1;
!   if (timeout >= maxtimeout || timeout_quit) {
!     if ( verbosity >= 3 && !timeout_quit )
!       syslog(LOG_WARNING, "no response from %s\n", inet_ntoa(from.sin_addr));
      exit(0);
+   }
    siglongjmp(timeoutbuf, 1);
  }
  
***************
*** 247,252 ****
--- 253,277 ----
    }
  }
  
+ static void
+ reapchild(int sig)
+ {
+   pid_t pid;
+   int status;
+  
+   sig = SIGCHLD;
+ 
+   while ( 1 ) {
+     pid = waitpid(-1, &status, WNOHANG);
+     if ( pid <= 0 )
+       break;
+     numchildren--;
+     if ( verbosity >= 3 )
+       syslog(LOG_INFO, "pid %d exits, numchildren=%d",
+ 	     pid, numchildren);
+   }
+ }
+ 
  int
  main(int argc, char **argv)
  {
***************
*** 270,275 ****
--- 295,301 ----
  #ifdef WITH_REGEX
    char *rewrite_file = NULL;
  #endif
+   sigset_t childmask;
  
    /* basename() is way too much of a pain from a portability standpoint */
  
***************
*** 278,284 ****
    
    openlog(__progname, LOG_PID|LOG_NDELAY, LOG_DAEMON);
    
!   while ((c = getopt(argc, argv, "cspvVla:u:U:r:t:T:m:")) != -1)
      switch (c) {
      case 'c':
        cancreate = 1;
--- 304,310 ----
    
    openlog(__progname, LOG_PID|LOG_NDELAY, LOG_DAEMON);
    
!   while ((c = getopt(argc, argv, "cC:spvVla:u:U:r:t:T:m:")) != -1)
      switch (c) {
      case 'c':
        cancreate = 1;
***************
*** 350,355 ****
--- 376,386 ----
        printf("%s\n", TFTPD_CONFIG_STR);
        exit(0);
        break;
+     case 'C':
+       maxchildren = atoi(optarg);
+       if (maxchildren < 0)
+ 	maxchildren = 0;
+       break;
      default:
        usage();
        break;
***************
*** 481,494 ****
    } else {
      /* 0 is our socket descriptor */
      close(1); close(2);
    }
  
!   /* This means we don't want to wait() for children */
  #ifdef SA_NOCLDWAIT
!   set_signal(SIGCHLD, SIG_IGN, SA_NOCLDSTOP|SA_NOCLDWAIT);
  #else
!   set_signal(SIGCHLD, SIG_IGN, SA_NOCLDSTOP);
  #endif
  
    /* Take SIGHUP and use it to set a variable.  This
       is polled synchronously to make sure we don't
--- 512,535 ----
    } else {
      /* 0 is our socket descriptor */
      close(1); close(2);
+ 
+     /* child max only applies to standalone server */
+     maxchildren = 0;
    }
  
!   if ( maxchildren == 0 ) {
!     /* This means we don't want to wait() for children */
  #ifdef SA_NOCLDWAIT
!     set_signal(SIGCHLD, SIG_IGN, SA_NOCLDSTOP|SA_NOCLDWAIT);
  #else
!     set_signal(SIGCHLD, SIG_IGN, SA_NOCLDSTOP);
  #endif
+   } else {
+     set_signal(SIGCHLD, reapchild, SA_NOCLDSTOP);
+     sigemptyset(&childmask);
+     sigaddset(&childmask, SIGCHLD);
+   }
+   numchildren = 0;
  
    /* Take SIGHUP and use it to set a variable.  This
       is polled synchronously to make sure we don't
***************
*** 526,535 ****
      set_socket_nonblock(fd, 0);
  #endif    
  
      /* Never time out if we're in standalone mode */
      rv = select(fd+1, &readset, NULL, NULL, standalone ? NULL : &tv_waittime);
!     if ( rv == -1 && errno == EINTR )
        continue;		/* Signal caught, reloop */
      if ( rv == -1 ) {
        syslog(LOG_ERR, "select loop: %m");
        exit(EX_IOERR);
--- 567,582 ----
      set_socket_nonblock(fd, 0);
  #endif    
  
+     if ( maxchildren )
+       sigprocmask(SIG_UNBLOCK, &childmask, 0);
+ 
      /* Never time out if we're in standalone mode */
      rv = select(fd+1, &readset, NULL, NULL, standalone ? NULL : &tv_waittime);
!     if ( rv == -1 && errno == EINTR ) {
!       if ( maxchildren )
! 	sigprocmask(SIG_BLOCK, &childmask, 0);
        continue;		/* Signal caught, reloop */
+     }
      if ( rv == -1 ) {
        syslog(LOG_ERR, "select loop: %m");
        exit(EX_IOERR);
***************
*** 537,542 ****
--- 584,601 ----
        exit(0);		/* Timeout, return to inetd */
      }
  
+     if ( maxchildren ) {
+       sigset_t oldmask;
+       sigprocmask(SIG_BLOCK, &childmask, &oldmask);
+       if ( numchildren == maxchildren ) {
+ 	if ( verbosity >= 4 )
+ 	  syslog(LOG_INFO, "request delayed");
+ 	while ( numchildren == maxchildren )
+ 	  sigsuspend(&oldmask);
+ 	continue;
+       }
+     }
+ 
  #ifdef __CYGWIN__
      set_socket_nonblock(fd, 1);
  #endif    
***************
*** 576,581 ****
--- 635,642 ----
        exit(EX_OSERR);	/* Return to inetd, just in case */
      } else if ( pid == 0 )
        break;			/* Child exit, parent loop */
+ 
+     numchildren++;
    }
    
    /* Child process: handle the actual request here */
***************
*** 606,612 ****
  
    /* Close file descriptors we don't need */
    close(fd);
!   
    /* Get a socket.  This has to be done before the chroot(), since
       some systems require access to /dev to create a socket. */
    
--- 667,673 ----
  
    /* Close file descriptors we don't need */
    close(fd);
! 
    /* Get a socket.  This has to be done before the chroot(), since
       some systems require access to /dev to create a socket. */
    
***************
*** 793,798 ****
--- 854,866 ----
      else
        (*pf->f_send)(pf, NULL, 0);
    }
+ 
+   if ( verbosity >= 3 ) {
+     syslog(LOG_NOTICE, "%s from %s done (segsize==%d)\n",
+ 	   tp->th_opcode == WRQ ? "WRQ" : "RRQ",
+ 	   inet_ntoa(from.sin_addr), segsize);
+   }
+ 
    exit(0);			/* Request completed */
  }
  
diff -rcN tftp-hpa-0.33.orig/tftpd/tftpd.rules tftp-hpa-0.33/tftpd/tftpd.rules
*** tftp-hpa-0.33.orig/tftpd/tftpd.rules	Wed Dec 31 17:00:00 1969
--- tftp-hpa-0.33/tftpd/tftpd.rules	Wed Feb  5 14:03:10 2003
***************
*** 0 ****
--- 1,27 ----
+ #
+ # Rules for chroot /tftpboot setup.  Just strip off the /tftpboot.
+ #
+ # This file has three fields: operation, regex, remapping
+ #
+ # The operation is a combination of the following letters:
+ #
+ # r - rewrite the matched string with the remapping pattern
+ # i - case-insensitive matching
+ # g - repeat until no match (used with "r")
+ # e - exit (with success) if we match this pattern, do not process
+ #     subsequent rules
+ # s - start over from the first rule if we match this pattern
+ # a - abort (refuse the request) if we match this rule
+ # G - this rule applies to TFTP GET requests only
+ # P - this rule applies to TFTP PUT requests only
+ #
+ # The regex is a regular expression in the style of egrep(1).
+ #
+ # The remapping is a pattern, all characters are verbatim except \
+ # \0 copies the full string that matched the regex
+ # \1..\9 copies the 9 first (..) expressions in the regex
+ # \\ is an escaped \
+ #
+ # "#" begins a comment, unless \-escaped
+ #
+ r	^/tftpboot			# Remove prefix since we chroot