Commit Graph

141 Commits

Author SHA1 Message Date
christos 71fa92b75e PR/56963: Mark Davies: inetd not configured for rpc
Move RPC includes to inetd.h
2022-08-10 08:37:53 +00:00
dholland 9178dcce36 PR bin/56963 Mark Davies: inetd not configured for rpc
Instead of using negative flags to turn on positive flags, set -DRPC
in the makefile. Corrects a problem where the SunRPC code in parse.c
was accidentally left disabled.

This is a prime example of why we don't like negative flags...
2022-08-10 03:35:38 +00:00
ryo 223f9ca45a To an alias address, or in a multihoming environment, the internal dgram
server may respond from a different address than the destination address
sent by the client.
To solve this problem, I introduce sendfromto() and recvfromto() so that
the server can reply from the correct address, i.e., the destination address
used in the request.

This change also has the aspect of a reference implementation using the
RECVDSTADDR and PKTINFO socket options.
2021-10-17 04:14:49 +00:00
rillig 8b3967e586 inetd: remove trailing whitespace, add space after 'if' and 'for'
No functional change.
2021-10-12 22:51:28 +00:00
christos b19025f3ec PR/56448: Solomon Ritzow: Various improvements.
Rate limiting code has been moved to ratelimit.c. I renamed
clear_ip_list to rl_clear_ip_list and broke the code up into more
functions. I have also made the per-IP rate limiting allocation more
efficient. IP addresses are now stored in their network format instead
of a string from getnameinfo (see inetd.h struct rl_ip_node). malloc
calls use only the space needed by the structure by using offsetof on
union members (I suppose this can be a bit dangerous if not done
correctly...). Per-IP rate limiting still supports textual comparison
using getnameinfo for address families other than AF_INET and AF_INET6, but I
don't think there are any that are actually compatible or used by inetd (I
haven't tested UNIX sockets with a remote bound to another file, but I did test
using IPv6 with the textual format by commenting out the IPv6 specific
code, and it works properly). Still potentially handy for the future.
The IP node list (se_rl_ip_list) now uses the <sys/queue.h> SLIST macros
instead of a custom list. I've broken rl_process up into helper functions
for each type of rate limiting and created a separate function for
address stringification, for use with printouts from the -d flag. I
tried to reduce stack memory use by moving printing code involving
string buffers into separate functions. I haven't tested rl_ipv6_eq on
a 32-bit system.

The code for the positional syntax has also been moved to parse.c.
Function try_biltin has been added to remove parse.c:parse_server's
dependency on the biltin structure definition.

File inetd.h has been updated with the proper function prototypes, and
the servtab structure has been update with the new IP node SLIST. I also
moved things around a bit. The way we (a peer and myself)
formatted inetd.h previously was somewhat confusing. Function and global
variable prototypes are now organized by the source file they are
defined in.

I also added a -f flag that I saw in another problem report
(https://gnats.netbsd.org/12823) that I thought could be useful. It
runs inetd in the foreground but without debug printouts or SO_DEBUG.
I'm not completely sure about the line "if (foreground) setsid()" that
I changed from "if (debug) setsid()".
2021-10-12 19:08:04 +00:00
rillig 11067b051b inetd: remove redundant tests before calling isspace 2021-09-03 21:02:04 +00:00
rillig 18ec0f1992 inetd: remove redundant null check before free
No functional change.
2021-09-03 20:41:19 +00:00
rillig adeed07f1b inetd: prepare for lint's strict bool mode
Lint's strict bool mode considers bool incompatible with the other
scalar types.  This makes the type of expressions more visible in the
code.  In particular, conditions of the form '!strcmp(...)' are no
longer allowed, they have to be written as 'strcmp(...) == 0'.

The operator '!' cannot be used with sep->se_wait since that has type
pid_t, not bool.

No change to the resulting binary.
2021-09-03 20:24:28 +00:00
rillig 9948f2b7a0 inetd: normalize indentation and alignment in comments 2021-09-03 19:33:51 +00:00
rillig 3ac7b8f346 inetd: fix Clang build
error: implicit conversion changes signedness: 'service_type' to 'int'
2021-08-31 19:34:42 +00:00
rillig 5d133dbc57 inetd: raise WARNS from 5 to 6
The necessary fixes include:
* explicit integer conversions, to get rid of mixed signedness
* function prototypes for parameterless functions

While here:
* add space after comma
* add space after 'if'
* place the '{' of a function definition on a separate line
* rename variables 'bits' and 'temp' to 'hi' and 'lo'
* in parse_quote, prefer expressions over assignments
* make hex_to_bits static

No functional change.
2021-08-30 18:21:11 +00:00
rillig 9805323331 inetd: remove trailing whitespace 2021-08-30 17:32:23 +00:00
mlelstv 1223be2cd5 Fix reverted logic when parsing server program.
Compare pointer with NULL not 0.
2021-08-30 08:21:12 +00:00
christos b74091d873 fix printf formats (intmax -> j) 2021-08-29 11:43:25 +00:00
christos 2557380693 Inetd enhancements by James Browning, Gabe Coffland, Alex Gavin, Solomon Ritzow
Described in:
    https://www.mail-archive.com/tech-userlevel@netbsd.org/msg03114.html
And developed in:
    https://github.com/ritzow/src/pull/1

From their notes:

All new functionality should be explained by the updated manpage.

The manpage has been refactored a bit: A new section "Directives"
has been added and the information about default hostnames and
IPsec directives has been moved there, and the new file include
directive information is also there.

getconfigent has the most major changes. A newline is no longer
read immediately, but is called only by a "goto more" (inside an
if(false) block). This allows multiple definitions or directives
to exist on a single line for anything that doesn't terminate using
a newline. This means a key-values service definition can be followed
by another key-values service definition, a positional definition,
or an ipsec, hostname, or .include directive on the same line.

memset is no longer used explicitly to clear the servtab structure,
a function init_servtab() is used instead, which uses a C struct
initializer.

The servtab se_group field is its own allocation now, and not just
a pointer into the user:group string.

Refactored some stuff out of getconfigent to separate functions
for use by parse_v2.c. These functions in inetd.c are named with
the form parse_*()

parse_v2.c only has code for parsing a key-values service definition
into a provided servtab. It should not have anything that affects
global state other than line and line_number.

Some function prototypes, structures, and #defines have been moved
from inetd.c to inetd.h.

The function config_root replaces config as the function called on
a config file load/reload. The code removed from the end of
config(void) is now called in config_root, so it is not run on each
recursive config call.

setconfig(void) was removed and its code added into config_root
because that is the only place it is called, and redundant checks
for non-null globals were removed because they are always freed by
endconfig. The fseek code was also removed because the config files
are always closed by endconfig.

Rate limiting code was updated to add a per-service per-IP rate
limiting form. Some of that code was refactored out of other places
into functions with names in the form rl_*()

We have not added any of the license or version information to the
new files parse_v2.c, parse_v2.h, and inetd.h and we have not
updated the license or version info for inetd.c.

Security related:

The behavior when reading invalid IPsec strings has changed. Inetd
no longer exits, it quits reading the current config file instead.
Could this impact program security?

We have not checked for memory leaks. Solomon tried to use dmalloc
without success. getconfigent seemed to have a memory leak at each
"goto more". It seems like inetd has never free'd allocated strings
when throwing away erroneous service definitions during parsing
(i.e. when "goto more" is called when parsing fields). OpenBSD's
version calls freeconfig on "goto more"
(c5eae130d6/usr.sbin/inetd/inetd.c (L1049))
but NetBSD only calls it when service definitions are no longer
needed. This has been fixed. freeconfig is called immediately before
any "goto more". There shouldn't be any time when a servtab is in
an invalid state where freeconfig would break.
2021-08-29 09:54:18 +00:00
msaitoh e992133145 s/suport/support/ 2019-12-27 09:22:19 +00:00
martin ee3280f977 Bump MAXARGV from 20 to 64 - with bozohttpd and all config on the command
line it is easy to hit the (silent) limit.
2017-11-28 11:51:11 +00:00
ozaki-r 37c5cac096 Don't setup SPs if no policy sepecifier is specified
We expect that SPs are set up iff some policy sepecifier(s) are specified.

Found on investigating an issue reported by Robert Swindells
2017-10-17 07:13:19 +00:00
elric e8ad4c8a7e Increase buffer size reported to strlcpy() to be one larger than the
length of the string we copy in so that there is space for the '\0'.
2017-02-15 02:48:31 +00:00
khorben fa8ee723bd Use base 10 when logging the exit status or exit signal for sub-processes,
instead of hexadecimal.
2014-04-05 23:36:10 +00:00
christos a16db3405d PR/47318: Henning Petersen: Replace (r)index with str(r)chr in inetd.c
And while here strncpy with strlcpy
2012-12-13 19:38:40 +00:00
drochner 8fd6dadaf8 include <netipsec/ipsec.h> rather than <netinet6/ipsec.h> from userland
where possible, for consistency and compatibility to FreeBSD
(exception: KAME specific statistics gathering in netstat(1) and systat(1))
2012-01-04 16:09:40 +00:00
joerg bec77c5f43 Use __dead 2011-08-31 13:32:36 +00:00
pooka a7c3e616ee RLIMIT_NOFILE stabilized in NetBSD 17 years ago, so it's safe now
to remove the #ifdef's from around code which uses it.
2010-12-15 15:36:15 +00:00
pooka 7d769f0a0f Nuke conditionally compiled MULOG stuff. Itojun wanted to do it
already 8 years ago when he fixed the compilation last time, and
again it hasn't been buildable in years.
2010-12-15 13:13:28 +00:00
dholland d4ca0466e8 Avoid SIGSEGV in forked child process for (some?) instant-disconnect clients. 2010-03-25 16:36:00 +00:00
tsarna 4a827eaa92 Back out mDNS changes which were not discussed.
There is design work that needs to be done first.
2009-10-22 22:50:35 +00:00
jkunz bd5b8260f5 Add mDNS Service Directory support to inetd(8).
inetd(8) can now advertize services in the mDNS-SD.
(Per service configuration option in inetd.conf(5).)
2009-10-22 16:34:27 +00:00
roy 7027866a09 Rename internal getline() function to get_line() so it does
conflict with the soon to be added getline(3) libc function.
2009-07-13 19:05:39 +00:00
christos 6a9b5acd29 print the proper client address (ryo shimizu) 2009-05-23 03:24:51 +00:00
lukem 8d37bc2951 Fix -Wsign-compare issue 2009-04-15 08:38:37 +00:00
christos 8b39f71df8 - when we close an se_fd, set it to -1
- fix int/ssize_t/size_t/socklen_t issues
- fix casts
- remove unused variables
- fix prototypes
- fix const
- remove unneeded casts
2009-01-08 21:37:20 +00:00
christos 5fe5dff0de PR/40340: Ed Ravin: Print the numeric address in addition to the hostname. 2009-01-08 18:29:43 +00:00
christos ef3c9e6675 Print the numeric address of the host. 2009-01-08 18:08:10 +00:00
tls 717f903a98 Add accept filters, ported from FreeBSD by Coyote Point Systems. Add inetd
support for specifying an accept filter for a service (mostly as a usage
example, but it can be handy for other things).  Manual pages to follow
in a day or so.

OK core@.
2008-08-04 03:55:47 +00:00
lukem 9c1945664c Remove the \n and tabs from the __COPYRIGHT() strings.
Tweak to use a consistent format.
2008-07-21 13:36:57 +00:00
dholland e62b84ba61 When running a builtin service (a what? yeah, a piece of useless
legacy code), if the builtin service forks (not all do), avoid leaking
listening sockets into the child process.

If the child process were to keep copies of the listening sockets
around and then hang about for a long time, it would prevent inetd
from being able to re-bind them upon restart.

The listening sockets are tagged close-on-exec, but that doesn't help
when one doesn't exec.

Patch from my own very old PR 8253.
2008-05-26 03:41:25 +00:00
martin ce099b4099 Remove clause 3 and 4 from TNF licenses 2008-04-28 20:22:51 +00:00
hubertf 889da1779b * Don't include headers twice
* Remove a few trailing whitespaces
 * Rearrange and join to one #if for some headers

Patch contributed by Slava Semushin <slava.semushin@gmail.com>
in private mail.
2007-01-16 17:32:04 +00:00
rillig 7eb2c18b51 Fixed gcc warnings about comparison between signed and unsigned, as well
as one case where a variable had been used for two different purposes
(which also required different types).
2007-01-02 16:00:46 +00:00
mrg 1fa98f5b05 - use socklen_t where appropriate
- avoid lvalue casts
2006-05-11 06:59:40 +00:00
christos 2f3bdfce80 Don't ignore SIGCHLD, because we are not going to get kqueue notifications
about it if we do.
2005-04-09 20:14:55 +00:00
christos a0d7588f62 Simplify code a bit, and whitespace. 2004-11-28 05:40:47 +00:00
dsl cfe7f80ff0 Add (unsigned char) cast to ctype functions 2004-10-29 20:51:11 +00:00
pk 6b2734d11c Add two missing `#ifdef INET6's. 2004-10-20 11:37:42 +00:00
rumble 7caa241563 Change the log that is produced when the maximum spawn count per
last 60 second interval is reached to more accurately reflect
what has happened.

Also, break up a few long strings, obey 80 columns, and remove a
superfluous newline passed to syslog(3).
2004-09-14 17:42:31 +00:00
cube 6894b27b47 Allow quoting using single or double quotes inside inetd.conf. Closes
PR 24192 by Tyler Retzlaff.
2004-01-25 10:00:17 +00:00
fvdl 7de4819e2c Don't assign NULL to an integer. 2003-10-21 02:43:37 +00:00
agc 326b2259b7 Move UCB-licensed code from 4-clause to 3-clause licence.
Patches provided by Joel Baker in PR 22366, verified by myself.
2003-08-07 11:25:11 +00:00
itojun 1d06004879 use strlcpy 2003-07-13 13:54:02 +00:00