Commit graph

323 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
33ec23c0dc remap: re-enable in autoconf; fix missing pointer assignment
Need to actually output something, too.

The whole section for remap had gotten dropped from autoconf, with the
obvious results...

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2024-06-10 20:56:27 -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
ac7f98e4d8 remap: fix timeouts for "g", add a "gg" flag to match sed s///g
Make sure that when using the global option, we still bump the deadman
timer.

The "g" option really should only have applied to the right-hand
unmatched part of the string, like in sed. Add a "gg" option which
does that.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2024-06-10 20:24:46 -07:00
H. Peter Anvin
74c5d8a020 .editorconfig: tabs are 8
The size of a tab is 8, even if the indentation is 4.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2024-06-10 19:31:17 -07:00
H. Peter Anvin
cb619257ed recvfrom: update config.h define for in_pktinfo.ipi_addr
configure.ac now explicitly checks for struct in_pktinfo.ipi_addr;
update the configure name to match.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2024-06-10 18:38:43 -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
33051a296c signals: require and always use sigaction()
tftpd already requires sigaction() to compile, so there is no reason
to use anything else. It also allows for nicer combination of flags.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2024-06-10 14:36:28 -07:00
Yegor Yefremov
e52af4207a Add EditorConfig support
Provide common indentation configuration for the source files.

For more information, visit https://editorconfig.org/.

Signed-off-by: Yegor Yefremov <yegorslists@googlemail.com>
2024-05-31 11:11:09 -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
15c4f369ee Update version for release 5.3 2024-05-29 15:40:13 -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
1f4b33a1f7 Modernize: use sigaction() whenever possible. Remove uses of common.
bsd_signal() may not be defined, and there is really no reason to even
try to use it if sigaction() is avaiable; using sigaction() guarantees
the semantics we really want.

Replace uses of common variables with explicit instantiation and
extern declarations in a header file.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2024-05-29 15:34:57 -07:00
H. Peter Anvin
9c0908a778 autoconf: remove workarounds for some very old systems
Remove workarounds for some ridiculously old systems; these
workarounds are basically untestable.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2024-05-29 15:15:34 -07:00
H. Peter Anvin
e83d71d394 autoconf: rename configure.in to configure.ac
Rename configure.in to configure.ac in accordance with current
practice.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2024-05-29 15:03:40 -07:00
H. Peter Anvin
b2b34cecc8 tftpd: Canonicalize myaddr before address_is_local()
The comparisons for forbidden addresses in address_is_local() only
work on canonicalized addresses.

Also, work in the case myaddr is NULL (if we ever call it that way...)

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2015-08-07 11:55:08 -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
Ron Lee
ff819b108a Make configure an order-only prerequisite of aconfig.h.in
On filesystems with subsecond resolution, like ext4, we can't trust the
timestamp of aconfig.h.in since autoheader leaves it truncated to second
resolution (apparently touch -r and cp -p can do this at the very least)
while configure has full subsecond resolution, so it can look newer even
when it was cleanly created first, leading to the build system looping
trying to recreate all of that again ...

So in the initial stage of a clean build we can get something like this:

$ make spotless
$ make autoconf
rm -rf MCONFIG configure config.log aconfig.h *.cache
autoconf
rm -f aconfig.h.in aconfig.h
autoheader

$ stat configure aconfig.h.in
  File: ‘configure’
Device: 807h/2055d	Inode: 9443466     Links: 1
Access: 2014-07-31 03:27:27.599293442 +0930
Modify: 2014-07-31 03:27:27.711290270 +0930
Change: 2014-07-31 03:27:27.711290270 +0930

  File: ‘aconfig.h.in’
Device: 807h/2055d	Inode: 9443467     Links: 1
Access: 2014-07-31 03:27:27.000000000 +0930
Modify: 2014-07-31 03:27:27.000000000 +0930
Change: 2014-07-31 03:27:27.903284841 +0930

And with a parallel build, that can then leave 'make all' racing to
remove and recreate aconfig.h (and possibly more things), while it
begins to build the first targets.  Which then fail horribly like
we see here:

https://buildd.debian.org/status/fetch.php?pkg=tftp-hpa&arch=i386&ver=5.2%2B20140608-1&stamp=1406736363

Possibly we also need to move the actual build job into the rule for
the 'all' target, so that the build system update prerequisites are
guaranteed to be completed before it runs (as opposed to running in
parallel with them), but this change might be enough for now.

Signed-off-by: Ron Lee <ron@debian.org>
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2014-07-31 16:25:41 -07:00
Daniel Baumann
3ee2b27809 Update manpage to match source code for --map-file
The manpage had --mapfile but the code had --map-file.

Closes: #606267 in the Debian BTS

Reported-By: Jim Paris <jim@jtan.com>
Signed-off-by: Ron Lee <ron@debian.org>
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2014-07-31 16:25:01 -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
8ddf0d87d7 tftp: drop "inline" from definition of usage()
It is pointless and newer gcc say it is a lose.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2014-06-07 13:00:46 -07:00
H. Peter Anvin
2ac12abbc9 tftpd.8: document IPv6 handling in remapping rules
Document the "4" and "6" conditionals as well as how \i and \x handle
IPv6 addresses.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2014-06-07 12:59:44 -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
c89a63a441 tftp: convert IPv6-mapped IPv4 addresses to IPv4
If we receive IPv4 addresses mapped to IPv6, convert them back to IPv4
so that mapping scripts which use \i behave sanely.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2014-06-07 12:37:33 -07:00
H. Peter Anvin
128e6a3905 Support IPv6 on MacOS X systems
Add feature test macros for MacOS X, and don't require
IPV6_RECVPKTINFO to exist.

Reported-by: YJZ <vollkommen@gmx.net>
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2012-03-01 22:44:32 -08:00
H. Peter Anvin
b9708e2201 Update version for release 5.2 2011-12-11 14:13:52 -08:00
H. Peter Anvin
f08a34ede1 CHANGES: document is address local fix
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2011-12-11 14:13:13 -08:00
H. Peter Anvin
c6d2c36b1a tftpd: the "is this address local" algorithm no longer works on Linux
Linux no longer tries to match the local address with the remote one,
so address_is_local() fails.  Try instead to simply see if we can bind
to the explicit address.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2011-12-08 21:48:06 -08:00
H. Peter Anvin
badf05140d spec: BuildPreReq -> BuildRequires; need -devel package
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2011-06-22 16:32:56 -07:00
H. Peter Anvin
f6a1282fec Update version for release 5.1 2011-06-22 16:29:59 -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
bd250a597f CHANGES: Document bug fix
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2011-06-22 16:27:48 -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
H. Peter Anvin
915f62f5c7 CHANGES: document wraparound fix 2010-09-20 17:49:10 -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
H. Peter Anvin
a63534e6e6 recvfrom: fix the type of the fallthrough case
If we can't figure out the source address, we have the "fall on our
face" version of myrecvfrom(); make sure its prototype matches.  This
handles building on machines where sockaddr_t != int and yet there is
no way to get the source address.  This apparently affects at least
one version of Solaris.

Reported-by: Georg Schwarz <georg.schwarz@freenet.de>
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2009-12-11 16:07:10 -08:00
H. Peter Anvin
e7a7b19483 Update CHANGES for future 5.1 release
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2009-09-14 14:46:34 -07:00
H. Peter Anvin
ab382980ae Fix man page formatting 2009-09-14 14:44:54 -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