Hello all, I am suggesting three fairly small changes to src/inetd.c:
0001-inetd-Improve-printout-of-service-changes.patch
Makes the reporting of services, in particular for TCPMUX services.
0002-inetd-Adapt-service-nodes-to-IPv6.patch
In order to allow node lists containing nimerical IPv6 addresses,
'strchr' must be replaced by 'strrchr'. In addition, a simple
pre-determination of numerical addresses will remove a timeout
that would occur when no resolver is present.
0003-inetd-Replaceable-path-for-PID-file.patch
A possibility to replace the hard coded path of the PID file.
Observe that it is implemented as the type with optional argument.
This allows the usage `inetd -p"" /etc/inetd.conf'.
Regards,
Mats
From ca5fb2430ec4c36e4765ea0e9cb00a5a1e087eda Mon Sep 17 00:00:00 2001 From: Mats Erik Andersson <[email protected]> Date: Sat, 27 Nov 2010 00:04:42 +0100 Subject: [PATCH 1/3] inetd: Improve printout of service changes. --- ChangeLog | 8 ++++++++ src/inetd.c | 14 +++++++++----- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index 08c3b23..232c611 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2010-11-26 Mats Erik Andersson <[email protected]> + + * src/inetd.c (print_service): If `ISMUX(SEP)' then present the + node name as `tcpmux' or as `tcpmuxplus'. Make 'builtin=' show + actual service name, or `no' for non-builtins. + (fix_tcpmux): Let SERV.se_file report `fix_tcpmux' as origin. + Correct some spelling mistakes in error message. + 2010-11-24 Mats Erik Andersson <[email protected]> * tests/addrpeek.c: New file. diff --git a/src/inetd.c b/src/inetd.c index 625ebff..7f7adbb 100644 --- a/src/inetd.c +++ b/src/inetd.c @@ -523,12 +523,15 @@ void print_service (const char *action, struct servtab *sep) { fprintf (stderr, - "%s:%d: %s: %s:%s proto=%s, wait=%d, max=%u, user=%s builtin=%lx server=%s\n", + "%s:%d: %s: %s:%s proto=%s, wait=%d, max=%u, user=%s builtin=%s server=%s\n", sep->se_file, sep->se_line, action, - sep->se_node ? sep->se_node : "*", sep->se_service, sep->se_proto, + ISMUX (sep) ? (ISMUXPLUS (sep) ? "tcpmuxplus" : "tcpmux") + : (sep->se_node ? sep->se_node : "*"), + sep->se_service, sep->se_proto, sep->se_wait, sep->se_max, sep->se_user, - (long) sep->se_bi, sep->se_server); + sep->se_bi ? sep->se_bi->bi_service : "no", + sep->se_server); } @@ -1227,6 +1230,7 @@ fix_tcpmux (void) struct servtab serv; memset (&serv, 0, sizeof (serv)); + serv.se_file = "fix_tcpmux"; serv.se_service = newstr ("tcpmux"); serv.se_socktype = SOCK_STREAM; serv.se_checked = 1; @@ -1237,8 +1241,8 @@ fix_tcpmux (void) /* Should not happen */ freeconfig (&serv); if (debug) - fprintf (stderr, "INETERNAL ERROR: could not found tcpmux built-in"); - syslog (LOG_ERR, "INETERNAL ERROR: could not found tcpmux built-in"); + fprintf (stderr, "INTERNAL ERROR: could not find tcpmux built-in"); + syslog (LOG_ERR, "INTERNAL ERROR: could not find tcpmux built-in"); return; } serv.se_wait = serv.se_bi->bi_wait; -- 1.7.2.3
From 89ea3fd62d0c8b924198d991c8ee2dcb39f16035 Mon Sep 17 00:00:00 2001 From: Mats Erik Andersson <[email protected]> Date: Sat, 27 Nov 2010 01:04:07 +0100 Subject: [PATCH 2/3] inetd: Adapt service nodes to IPv6. --- ChangeLog | 7 +++++++ src/inetd.c | 29 ++++++++++++++++++++++++++++- 2 files changed, 35 insertions(+), 1 deletions(-) diff --git a/ChangeLog b/ChangeLog index 232c611..358fece 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2010-11-27 Mats Erik Andersson <[email protected]> + + * src/inetd.c (inetd_getaddrinfo): If IPV6, then add a flag + AI_NUMERICHOST if the node is a numeric address string. + New variable NUMERIC_ADDRESS. Debug symbolic addresses. + (getconfigent): Replace `strchr' with `strrchr'. + 2010-11-26 Mats Erik Andersson <[email protected]> * src/inetd.c (print_service): If `ISMUX(SEP)' then present the diff --git a/src/inetd.c b/src/inetd.c index 7f7adbb..3d87867 100644 --- a/src/inetd.c +++ b/src/inetd.c @@ -737,10 +737,33 @@ enter (struct servtab *cp) return sep; } +#define IPV4_NUMCHARS ".0123456789" +#define IPV6_NUMCHARS ".:0123456789abcdefABCDEF" + int inetd_getaddrinfo (struct servtab *sep, int proto, struct addrinfo **result) { struct addrinfo hints; +#ifdef IPV6 + bool numeric_address = false; + + /* In case a numerical address is supplied, which does not + apply to the indicated domain, a non-local resolver + will wait in vain until time out occurs, thus blocking. + Avoid this by falling back to numerical host resolving + when address string seems to be numerical. */ + + /* Purely numeric address? Separate criteria for IPv4 and IPv6, + since IPv6 allows hexadecimal coding and IPv4 mapping! */ + if (sep->se_node + && (strspn (sep->se_node, IPV4_NUMCHARS) == strlen (sep->se_node) + || (strchr (sep->se_node, ':') + && strspn (sep->se_node, IPV6_NUMCHARS)) ) ) + numeric_address = true; + else + if (debug && sep->se_node) + fprintf (stderr, "Resolving address: %s\n", sep->se_node); +#endif /* IPV6 */ memset (&hints, 0, sizeof (hints)); @@ -749,6 +772,10 @@ inetd_getaddrinfo (struct servtab *sep, int proto, struct addrinfo **result) if (sep->se_v4mapped && (sep->se_family != AF_INET)) hints.ai_flags |= AI_V4MAPPED; #endif +#ifdef IPV6 + if (numeric_address) + hints.ai_flags |= AI_NUMERICHOST; +#endif hints.ai_family = sep->se_family; hints.ai_socktype = sep->se_socktype; hints.ai_protocol = proto; @@ -944,7 +971,7 @@ getconfigent (FILE *fconfig, const char *file, size_t *line) sep->se_line = *line; node = argv[INETD_SERVICE]; - service = strchr (node, ':'); + service = strrchr (node, ':'); if (!service) { if (global_serv_node) -- 1.7.2.3
From 10ce9394cd95d7f332cd4c86fc62c6ca7d517563 Mon Sep 17 00:00:00 2001 From: Mats Erik Andersson <[email protected]> Date: Sat, 27 Nov 2010 02:07:12 +0100 Subject: [PATCH 3/3] inetd: Replaceable path for PID file. --- ChangeLog | 9 +++++++++ src/inetd.c | 19 +++++++++++++++++-- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 358fece..9623bc7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,14 @@ 2010-11-27 Mats Erik Andersson <[email protected]> + * src/inetd.c (pidfile_option): New variable. + (pid_file): New variable. + (argp_options): Add an option for replacing path of PID file. + (parse_opt): Handle option `p'. + (main): Condition PID file use on PIDFILE_OPTION. Replace the + macro PATH_INETDPID by variable PID_FILE. + +2010-11-27 Mats Erik Andersson <[email protected]> + * src/inetd.c (inetd_getaddrinfo): If IPV6, then add a flag AI_NUMERICHOST if the node is a numeric address string. New variable NUMERIC_ADDRESS. Debug symbolic addresses. diff --git a/src/inetd.c b/src/inetd.c index 3d87867..8d2a915 100644 --- a/src/inetd.c +++ b/src/inetd.c @@ -163,6 +163,8 @@ char **config_files; static bool env_option = false; /* Set environment variables */ static bool resolve_option = false; /* Resolve IP addresses */ +static bool pidfile_option = true; /* Record the PID in a file */ +static const char *pid_file = PATH_INETDPID; const char args_doc[] = "[CONF-FILE [CONF-DIR]]..."; const char doc[] = "Internet super-server."; @@ -185,6 +187,9 @@ static struct argp_option argp_options[] = { "turn on debugging, run in foreground mode", GRP+1}, {"environment", OPT_ENVIRON, NULL, 0, "pass local and remote socket information in environment variables", GRP+1}, + { "pidfile", 'p', "PIDFILE", OPTION_ARG_OPTIONAL, + "replace the default path \"" PATH_INETDPID "\"", + GRP+1 }, {"rate", 'R', "NUMBER", 0, "maximum invocation rate (per minute)", GRP+1}, {"resolve", OPT_RESOLVE, NULL, 0, @@ -211,6 +216,13 @@ parse_opt (int key, char *arg, struct argp_state *state) env_option = true; break; + case 'p': + if (arg && strlen (arg)) + pid_file = arg; + else + pidfile_option = false; + break; + case 'R': number = strtol (arg, &p, 0); if (number < 1 || *p) @@ -1859,15 +1871,18 @@ main (int argc, char *argv[], char *envp[]) openlog ("inetd", LOG_PID | LOG_NOWAIT, LOG_DAEMON); + if (pidfile_option) { - FILE *fp = fopen (PATH_INETDPID, "w"); + FILE *fp = fopen (pid_file, "w"); if (fp != NULL) { + if (debug) + fprintf(stderr, "Using pid-file at \"%s\".\n", pid_file); fprintf (fp, "%d\n", getpid ()); fclose (fp); } else - syslog (LOG_CRIT, "can't open %s: %s\n", PATH_INETDPID, + syslog (LOG_CRIT, "can't open %s: %s\n", pid_file, strerror (errno)); } -- 1.7.2.3
signature.asc
Description: Digital signature
