Commit graph

110 commits

Author SHA1 Message Date
H. Peter Anvin
2c86ff58dc remap: *actually* build, and fix masked logic errors
Well, now it is actually being compiled, and should hopefully work
again...

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2024-06-10 21:09:46 -07:00
H. Peter Anvin
9a92dec1dc tftpd: make it possible to adjust the remap deadman
Allow the user to tweak the remap deadman counter if it is necessary
for whatever reason.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2024-06-10 20:36:22 -07:00
H. Peter Anvin
fefaa2cc5c autoconf: modernize and modularize
Use my modular m4 library used for other things as well; update
autoconf macros to 2.71 standard.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2024-06-10 18:24:53 -07:00
H. Peter Anvin
5e8d5c24b2 tftpd: Use setres*id() if available
POSIX apparently doesn't clearly specify the behavior of the saved ID
when calling setre*id(). If the system has setres*id() then use it to
make absolutely sure that the ID changes cannot be undone.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2024-05-29 18:10:41 -07:00
H. Peter Anvin
99112f0206 tftpd: allow initgroups() to rescue setgroups() failure
If setgroups() fails, but initgroups() succeeds (somehow) then allow
the process to continue, as initgroups() ought to have set the group
list properly.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2024-05-29 17:52:42 -07:00
H. Peter Anvin
416046e2ad tftpd: call setgroups() before initgroups()
Unconditionally call setgroups() before calling
initgroups(). That way if initgroups() fails for some reason (e.g. it
is unable to access /etc/groups or the equivalent) then at least the
group list will be empty.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2024-05-29 17:49:21 -07:00
H. Peter Anvin
b9f2335e88 tftpd: shut up one more setjmp complaint
One more place where the compiler complains about setjmp. Work around
it by creating yet another static variable. Ugly, but it works.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2024-05-29 17:35:14 -07:00
H. Peter Anvin
351907e3f0 tftpd: handle rule filter flags more cleanly
Instead of a bunch of ad hoc tests, keep a bitmask of flags that would
keep this rule from being executed. This also removes the ugly hack of
converting the request mode between opcode and character encodings for
really no good reason.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2024-05-29 17:28:53 -07:00
H. Peter Anvin
6f96fcd1b6 tftpd: allow a rewrite rule to probe for the existence of a file
This adds an "E" flag to the rewrite rules, which exits rule
processing if and only if the result is a valid, accessible
filename. If combined with "r", the rewrite is cancelled if the rule
is not applied.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2024-05-29 17:16:06 -07:00
H. Peter Anvin
1dc6d55811 tftpd: handle restricted user namespaces on Linux
If the tftpd process lacks the privilege to set its uid, gid, or
groups, then assume it is already restricted in the way the
administrator requested, if and only if EPERM is returned.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2024-05-29 16:01:54 -07:00
H. Peter Anvin
aaaa76e8e7 tftpd: explicitly declare timer() static
Declare the function timer() as static, which is what it ought to be.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2024-05-29 15:37:44 -07:00
H. Peter Anvin
7678ae7f14 tftpd: Canonicalize all the addresses
We cannot canonicalize myaddr and not the from address.  We need to
canonicalize both of them, or else we'll try to create an IPv4 socket
and bind an IPv6-mapped IPv4 address to it, which is going to fail.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2015-08-07 11:49:13 -07:00
Thorsten Glaser
18ac1e26f7 __progname[] is provided by libc
Rename local variable to tftpd_progname to avoid a clash with glibc
global symbols and work around Debian bug #519006 (Closes: #564052).

[ hpa: specifically, double-underscore symbols in C are reserved for
  the implementation, i.e. compiler/libc. ]

Signed-off-by: Ron Lee <ron@debian.org>
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2014-07-31 16:24:37 -07:00
H. Peter Anvin
18ee96a03f tftpd: allow IPv4/6-specific remapping rules
Allow remapping rules to be conditional on IPv4 vs IPv6.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2014-06-07 12:59:33 -07:00
H. Peter Anvin
464be3090b tftpd: add Intel copyright header
Part of my Intel job now...

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2011-06-22 16:28:38 -07:00
H. Peter Anvin
f3035c45bc tftpd: simplify option parsing
Simplify the option parsing to make use of the fact that all the
options we support are integer options.  This fixes a buffer overflow
in the utimeout option.

Reported-by: Timo Warns <warns@pre-sense.de>
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2011-06-10 11:49:00 -07:00
H. Peter Anvin
2864d83fea tftpd: try to handle duplicate WRQ packets
Duplicate WRQ packets can really hurt, since they end up accessing the
same file.  This attempts to lock the file, which should work for the
case where a correctly implemented TFTP stack uses the same session ID
(port number) for each retry; in any other case they look like
multiple sessions to the same file and it is a crapshoot if we end up
with the correct one.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2011-05-12 19:16:17 -07:00
H. Peter Anvin
05ffcecaa8 Merge remote-tracking branch 'origin/master' 2011-05-09 21:09:18 -07:00
H. Peter Anvin
ad5aab9281 tftpd: constipate struct formats
struct formats should be static const; make it so and mark all users
const.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2011-05-05 10:11:59 -07:00
H. Peter Anvin
0b5732e263 remap: change the mode argument from a boolean to a character
Instead of taking a boolean value for get/put, pass a character; this
allows us to extend the number of possibilities in the future.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2011-05-05 10:08:53 -07:00
Tim Newsome
aeb1c31bae tftpd: Don't resend the OACK packet on block number wrap
When uploading a file that is larger than 32MB (with standard block
size), the block number will roll over. If it rolls over to 0, the code
mistakenly resends the option ack frame instead of acknowledging the 0
data block. This change fixes that behavior.
2010-09-20 17:48:33 -07:00
Ferenc Wagner
c86f82532e Implement the --pidfile option
Setting the umask moved later, right before entering the select loop,
so that it does not affect the permissions of the pid file.

Signed-off-by: Ferenc Wagner <wferi@niif.hu>
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2009-09-14 14:41:13 -07:00
Ferenc Wagner
5a27e30ec2 Untabify tftpd.c
Signed-off-by: Ferenc Wagner <wferi@niif.hu>
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2009-09-14 14:41:10 -07:00
Ferenc Wagner
85029077c8 Fix comment typo
Signed-off-by: Ferenc Wagner <wferi@niif.hu>
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2009-09-14 14:41:07 -07:00
Ferenc Wagner
3f2bc9833d Ensure that the log socket is available for the child
Just in case syslog has been restarted, bounce the log socket before
the chroot.

Signed-off-by: Ferenc Wagner <wferi@niif.hu>
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2009-09-14 14:41:02 -07:00
H. Peter Anvin
9ba4e118d2 tftpd.c: update copyright notice 2009-02-24 16:26:16 -08:00
Florian Lohoff
acf818880c tftpd: correctly disable PMTU discovery in standalone mode
Use the correct file descriptors so we correctly turn off PMTU.
2009-02-16 14:40:01 -08:00
H. Peter Anvin
932277c9a5 tftpd: implement the "rollover" option
Implement the "rollover" option, to set the rollover block number to
anything other than zero.  Apparently some idiots have gotten the idea
that block numbers should roll over to one, rather than zero.
2009-02-02 15:14:27 -08:00
Georg Schwarz
b0a2a17864 Cast IPv6 address from SOCKADDR_P() to struct in6_addr *
We need to cast IPv6 addresses from SOCKADDR_P() to struct in6_addr *
on some platforms, including at least MacOS X.
2008-11-14 08:37:49 -08:00
Karsten Keil
544abd789e Add error messages if address types mismatch
If a user does supply a IPv4 or IPv6 address
but force the other type with -4 or -6, give an error.
The patch also fix the special [::ffff:127.0.1]
address handling, it work now if you bind to this
address but only if you not force IPv6 only, it seems
that the kernel does not signal connections to a
IPv6 socket listen on [::ffff:127.0.0.1], if it was bound
IPv6 only.
I think we can live with it and do not need a special test
for this address.

Signed-off-by: Karsten Keil <kkeil@suse.de>
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2008-08-01 08:24:16 -07:00
Karsten Keil
18fd18bd5c Improve address type error handling
This patch detects numeric address types to avoid unnecessary
warnings/errors.  It also cleans up error printing to not print error
messages on stderr in the deamon case.

Signed-off-by: Karsten Keil <kkeil@suse.de>
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2008-07-31 11:48:18 -07:00
H. Peter Anvin
e4d3083006 tftpd: switch to getopt_long()
Switch to using getopt_long(); include a version in case the platform
lacks it.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2008-07-30 17:16:00 -07:00
H. Peter Anvin
0c6f7f86d3 tftpd: mark symbols static
Mark symbols not accessed from other files static.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2008-07-30 16:17:02 -07:00
Karsten Keil
cfb85d4dec Fix numeric IPv6 address handling
This patch fix a issue with numeric IPv6 addresses in the
tftpd -a address[:port] option.

Since IPv6 addresses use colon ':' in differnt counts itself, we cannot detect,
if the last colon is a seperator, so it is needed to put the IPv6 address into
square brackets, e.g. [2001:db8::1], so a optional port assignment is
unambiguous.
The patch also allows to specify numeric IPv6 addresses in other places enclosed
in [], but in these cases it accept these also without [].

Signed-off-by: Karsten Keil <kkeil@suse.de>
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2008-07-30 15:20:31 -07:00
H. Peter Anvin
c3a5c712e2 Allow the -4 option even in an IPv4-only configuration
Allow the -4 option even if IPv6 isn't compiled in.
2008-07-23 14:36:18 -04:00
Karsten Keil
28f22b6591 Add support for IPv6 in the server and client.
Add support for IPv6 in the server and client.
You can force the use of IPv4 or IPv6 only with new
-4 and -6 commandline options, if IPv6 support was compiled in.

Signed-off-by: Karsten Keil <kkeil@suse.de>
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2008-07-23 14:29:41 -04:00
H. Peter Anvin
9f83475779 Formatting cleanup 2008-07-08 17:26:18 -04:00
H. Peter Anvin
cd22c6ea31 Formatting cleanup
Clean up line break
2008-07-08 17:24:11 -04:00
H. Peter Anvin
22accddda0 Reformat the source code
The source code was a mix of different styles; normalize on NASM
style; basically K&R style with 4 space indentation.
2008-07-08 17:14:44 -04:00
H. Peter Anvin
c7ecc59f86 When running in secure mode (-s), we must not chdir while daemonizing
When running in secure mode (-s), we must not chdir while daemonizing.
Thanks to Adrian Urquhart for spotting this bug.
2007-01-30 15:38:04 -08:00
H. Peter Anvin
d9938a7d83 Add -L option to not daemonize process 2007-01-15 01:12:52 -08:00
H. Peter Anvin
059de7ce20 Use replacement library functions to daemonize, rather than #ifdef hell 2007-01-15 01:11:26 -08:00
H. Peter Anvin
982c1f2697 printf() and htonl() type matching issue
On older systems, htonl() returns unsigned long, on newer systems it
returns uint32_t.  Cast to unsigned long and use %08lX for the format,
that seems to be the easiest solution.
2007-01-08 16:30:10 -08:00
Dyks, Axel (XL)
1cb44ce918 tftp-hpa does not reload the remap file when receiving SIGHUP
... because the signal handling code is enclosed in "#ifdef HAVE_REGEX"
instead of "#ifdef WITH_REGEX"

The following patch against head of "network/tftp/tftp-hap.git" on "kernel.org"
fixes this issues (you are using blanks for indention and not tabs. right?).

Cheers
Axel
2006-12-05 14:36:32 -08:00
Zack Bartel
ec5973ac5f Moved pick_port_bind() to the libcommon common code so both client and server can use it. Client can now specify a range of ephemeral ports (transaction id) 2006-11-13 17:33:29 -08:00
H. Peter Anvin
14993bc916 Introduce socklen_t; detect non-local (e.g. broadcast) receive addresses 2006-10-04 21:54:04 -07:00
H. Peter Anvin
40133b212b Move common code to a common/ subdirectory 2006-10-04 10:19:06 -07:00
H. Peter Anvin
b3892e801f Correct the logic when to loop for the port range 2006-02-16 09:29:35 -08:00
Peter Anvin
ccb6289984 Actually do loop... 2005-10-13 15:20:41 -07:00
Peter Anvin
4187af0e6f Cleaner version implementing port range 2005-10-13 11:41:37 -07:00