svn commit: r356387 - stable/11/usr.sbin/inetd
Kyle Evans
kevans at FreeBSD.org
Sun Jan 5 21:32:42 UTC 2020
Author: kevans
Date: Sun Jan 5 21:32:41 2020
New Revision: 356387
URL: https://svnweb.freebsd.org/changeset/base/356387
Log:
MFC r310921, r311354, r315644: Light inetd(8) cleanup
r310921:
- Add static for symbols which need not to be exported.
- Clean up warnings to the WARNS=6 level.
r311354:
Fix build when WITHOUT_INET6 is defined.
r315644:
Simplify a pipe for signal handling.
Modified:
stable/11/usr.sbin/inetd/builtins.c
stable/11/usr.sbin/inetd/inetd.c
stable/11/usr.sbin/inetd/inetd.h
Directory Properties:
stable/11/ (props changed)
Modified: stable/11/usr.sbin/inetd/builtins.c
==============================================================================
--- stable/11/usr.sbin/inetd/builtins.c Sun Jan 5 19:14:16 2020 (r356386)
+++ stable/11/usr.sbin/inetd/builtins.c Sun Jan 5 21:32:41 2020 (r356387)
@@ -54,26 +54,25 @@ __FBSDID("$FreeBSD$");
#include "inetd.h"
-void chargen_dg(int, struct servtab *);
-void chargen_stream(int, struct servtab *);
-void daytime_dg(int, struct servtab *);
-void daytime_stream(int, struct servtab *);
-void discard_dg(int, struct servtab *);
-void discard_stream(int, struct servtab *);
-void echo_dg(int, struct servtab *);
-void echo_stream(int, struct servtab *);
+static void chargen_dg(int, struct servtab *);
+static void chargen_stream(int, struct servtab *);
+static void daytime_dg(int, struct servtab *);
+static void daytime_stream(int, struct servtab *);
+static void discard_dg(int, struct servtab *);
+static void discard_stream(int, struct servtab *);
+static void echo_dg(int, struct servtab *);
+static void echo_stream(int, struct servtab *);
static int get_line(int, char *, int);
-void iderror(int, int, int, const char *);
-void ident_stream(int, struct servtab *);
-void initring(void);
-uint32_t machtime(void);
-void machtime_dg(int, struct servtab *);
-void machtime_stream(int, struct servtab *);
+static void iderror(int, int, int, const char *);
+static void ident_stream(int, struct servtab *);
+static void initring(void);
+static uint32_t machtime(void);
+static void machtime_dg(int, struct servtab *);
+static void machtime_stream(int, struct servtab *);
-char ring[128];
-char *endring;
+static char ring[128];
+static char *endring;
-
struct biltin biltins[] = {
/* Echo received data */
{ "echo", SOCK_STREAM, 1, -1, echo_stream },
@@ -107,7 +106,7 @@ struct biltin biltins[] = {
* any regard for input.
*/
-void
+static void
initring(void)
{
int i;
@@ -124,7 +123,7 @@ initring(void)
* characters chosen from the range 0 to 512. We send LINESIZ+2.
*/
/* ARGSUSED */
-void
+static void
chargen_dg(int s, struct servtab *sep)
{
struct sockaddr_storage ss;
@@ -161,7 +160,7 @@ chargen_dg(int s, struct servtab *sep)
/* Character generator */
/* ARGSUSED */
-void
+static void
chargen_stream(int s, struct servtab *sep)
{
int len;
@@ -196,7 +195,7 @@ chargen_stream(int s, struct servtab *sep)
/* Return human-readable time of day */
/* ARGSUSED */
-void
+static void
daytime_dg(int s, struct servtab *sep)
{
char buffer[256];
@@ -221,7 +220,7 @@ daytime_dg(int s, struct servtab *sep)
/* Return human-readable time of day */
/* ARGSUSED */
-void
+static void
daytime_stream(int s, struct servtab *sep __unused)
{
char buffer[256];
@@ -240,7 +239,7 @@ daytime_stream(int s, struct servtab *sep __unused)
/* Discard service -- ignore data */
/* ARGSUSED */
-void
+static void
discard_dg(int s, struct servtab *sep __unused)
{
char buffer[BUFSIZE];
@@ -250,7 +249,7 @@ discard_dg(int s, struct servtab *sep __unused)
/* Discard service -- ignore data */
/* ARGSUSED */
-void
+static void
discard_stream(int s, struct servtab *sep)
{
int ret;
@@ -273,7 +272,7 @@ discard_stream(int s, struct servtab *sep)
/* Echo service -- echo data back */
/* ARGSUSED */
-void
+static void
echo_dg(int s, struct servtab *sep)
{
char buffer[65536]; /* Should be sizeof(max datagram). */
@@ -294,7 +293,7 @@ echo_dg(int s, struct servtab *sep)
/* Echo service -- echo data back */
/* ARGSUSED */
-void
+static void
echo_stream(int s, struct servtab *sep)
{
char buffer[BUFSIZE];
@@ -322,7 +321,7 @@ echo_stream(int s, struct servtab *sep)
/* Generic ident_stream error-sending func */
/* ARGSUSED */
-void
+static void
iderror(int lport, int fport, int s, const char *er)
{
char *p;
@@ -340,7 +339,7 @@ iderror(int lport, int fport, int s, const char *er)
/* Ident service (AKA "auth") */
/* ARGSUSED */
-void
+static void
ident_stream(int s, struct servtab *sep)
{
struct utsname un;
@@ -688,7 +687,7 @@ printit:
* some seventy years Bell Labs was asleep.
*/
-uint32_t
+static uint32_t
machtime(void)
{
@@ -698,7 +697,7 @@ machtime(void)
}
/* ARGSUSED */
-void
+static void
machtime_dg(int s, struct servtab *sep)
{
uint32_t result;
@@ -719,7 +718,7 @@ machtime_dg(int s, struct servtab *sep)
}
/* ARGSUSED */
-void
+static void
machtime_stream(int s, struct servtab *sep __unused)
{
uint32_t result;
Modified: stable/11/usr.sbin/inetd/inetd.c
==============================================================================
--- stable/11/usr.sbin/inetd/inetd.c Sun Jan 5 19:14:16 2020 (r356386)
+++ stable/11/usr.sbin/inetd/inetd.c Sun Jan 5 21:32:41 2020 (r356387)
@@ -206,30 +206,33 @@ __FBSDID("$FreeBSD$");
#define SIGBLOCK (sigmask(SIGCHLD)|sigmask(SIGHUP)|sigmask(SIGALRM))
-void close_sep(struct servtab *);
-void flag_signal(int);
-void flag_config(int);
-void config(void);
-int cpmip(const struct servtab *, int);
-void endconfig(void);
-struct servtab *enter(struct servtab *);
-void freeconfig(struct servtab *);
-struct servtab *getconfigent(void);
-int matchservent(const char *, const char *, const char *);
-char *nextline(FILE *);
-void addchild(struct servtab *, int);
-void flag_reapchild(int);
-void reapchild(void);
-void enable(struct servtab *);
-void disable(struct servtab *);
-void flag_retry(int);
-void retry(void);
-int setconfig(void);
-void setup(struct servtab *);
+#define satosin(sa) ((struct sockaddr_in *)(void *)sa)
+#define csatosin(sa) ((const struct sockaddr_in *)(const void *)sa)
+#ifdef INET6
+#define satosin6(sa) ((struct sockaddr_in6 *)(void *)sa)
+#define csatosin6(sa) ((const struct sockaddr_in6 *)(const void *)sa)
+#endif
+static void close_sep(struct servtab *);
+static void flag_signal(int);
+static void config(void);
+static int cpmip(const struct servtab *, int);
+static void endconfig(void);
+static struct servtab *enter(struct servtab *);
+static void freeconfig(struct servtab *);
+static struct servtab *getconfigent(void);
+static int matchservent(const char *, const char *, const char *);
+static char *nextline(FILE *);
+static void addchild(struct servtab *, int);
+static void reapchild(void);
+static void enable(struct servtab *);
+static void disable(struct servtab *);
+static void retry(void);
+static int setconfig(void);
+static void setup(struct servtab *);
#ifdef IPSEC
-void ipsecsetup(struct servtab *);
+static void ipsecsetup(struct servtab *);
#endif
-void unregisterrpc(register struct servtab *sep);
+static void unregisterrpc(register struct servtab *sep);
static struct conninfo *search_conn(struct servtab *sep, int ctrl);
static int room_conn(struct servtab *sep, struct conninfo *conn);
static void addchild_conn(struct conninfo *conn, pid_t pid);
@@ -240,51 +243,55 @@ static void free_connlist(struct servtab *sep);
static void free_proc(struct procinfo *);
static struct procinfo *search_proc(pid_t pid, int add);
static int hashval(char *p, int len);
+static char *skip(char **);
+static char *sskip(char **);
+static char *newstr(const char *);
+static void print_service(const char *, const struct servtab *);
+/* tcpd.h */
int allow_severity;
int deny_severity;
-int wrap_ex = 0;
-int wrap_bi = 0;
+
+static int wrap_ex = 0;
+static int wrap_bi = 0;
int debug = 0;
-int dolog = 0;
-int maxsock; /* highest-numbered descriptor */
-fd_set allsock;
-int options;
-int timingout;
-int toomany = TOOMANY;
-int maxchild = MAXCHILD;
-int maxcpm = MAXCPM;
-int maxperip = MAXPERIP;
-struct servent *sp;
-struct rpcent *rpc;
-char *hostname = NULL;
-struct sockaddr_in *bind_sa4;
-int v4bind_ok = 0;
+static int dolog = 0;
+static int maxsock; /* highest-numbered descriptor */
+static fd_set allsock;
+static int options;
+static int timingout;
+static int toomany = TOOMANY;
+static int maxchild = MAXCHILD;
+static int maxcpm = MAXCPM;
+static int maxperip = MAXPERIP;
+static struct servent *sp;
+static struct rpcent *rpc;
+static char *hostname = NULL;
+static struct sockaddr_in *bind_sa4;
+static int v4bind_ok = 0;
#ifdef INET6
-struct sockaddr_in6 *bind_sa6;
-int v6bind_ok = 0;
+static struct sockaddr_in6 *bind_sa6;
+static int v6bind_ok = 0;
#endif
-int signalpipe[2];
+static int signalpipe[2];
#ifdef SANITY_CHECK
-int nsock;
+static int nsock;
#endif
-uid_t euid;
-gid_t egid;
-mode_t mask;
+static uid_t euid;
+static gid_t egid;
+static mode_t mask;
-struct servtab *servtab;
+struct servtab *servtab;
-extern struct biltin biltins[];
+static const char *CONFIG = _PATH_INETDCONF;
+static const char *pid_file = _PATH_INETDPID;
+static struct pidfh *pfh = NULL;
-const char *CONFIG = _PATH_INETDCONF;
-const char *pid_file = _PATH_INETDPID;
-struct pidfh *pfh = NULL;
+static struct netconfig *udpconf, *tcpconf, *udp6conf, *tcp6conf;
-struct netconfig *udpconf, *tcpconf, *udp6conf, *tcp6conf;
-
static LIST_HEAD(, procinfo) proctable[PERIPSIZE];
-int
+static int
getvalue(const char *arg, int *value, const char *whine)
{
int tmp;
@@ -308,9 +315,11 @@ whichaf(struct request_info *req)
sa = (struct sockaddr *)req->client->sin;
if (sa == NULL)
return AF_UNSPEC;
+#ifdef INET6
if (sa->sa_family == AF_INET6 &&
- IN6_IS_ADDR_V4MAPPED(&((struct sockaddr_in6 *)sa)->sin6_addr))
+ IN6_IS_ADDR_V4MAPPED(&satosin6(sa)->sin6_addr))
return AF_INET;
+#endif
return sa->sa_family;
}
#endif
@@ -419,7 +428,7 @@ main(int argc, char **argv)
case AF_INET:
if (v4bind_ok)
continue;
- bind_sa4 = (struct sockaddr_in *)res->ai_addr;
+ bind_sa4 = satosin(res->ai_addr);
/* init port num in case servname is dummy */
bind_sa4->sin_port = 0;
v4bind_ok = 1;
@@ -428,7 +437,7 @@ main(int argc, char **argv)
case AF_INET6:
if (v6bind_ok)
continue;
- bind_sa6 = (struct sockaddr_in6 *)res->ai_addr;
+ bind_sa6 = satosin6(res->ai_addr);
/* init port num in case servname is dummy */
bind_sa6->sin6_port = 0;
v6bind_ok = 1;
@@ -520,17 +529,17 @@ main(int argc, char **argv)
}
#endif
- sa.sa_flags = 0;
+ sa = (struct sigaction){
+ .sa_flags = 0,
+ .sa_handler = flag_signal,
+ };
sigemptyset(&sa.sa_mask);
sigaddset(&sa.sa_mask, SIGALRM);
sigaddset(&sa.sa_mask, SIGCHLD);
sigaddset(&sa.sa_mask, SIGHUP);
- sa.sa_handler = flag_retry;
sigaction(SIGALRM, &sa, &saalrm);
config();
- sa.sa_handler = flag_config;
sigaction(SIGHUP, &sa, &sahup);
- sa.sa_handler = flag_reapchild;
sigaction(SIGCHLD, &sa, &sachld);
sa.sa_handler = SIG_IGN;
sigaction(SIGPIPE, &sa, &sapipe);
@@ -579,30 +588,34 @@ main(int argc, char **argv)
}
/* handle any queued signal flags */
if (FD_ISSET(signalpipe[0], &readable)) {
- int nsig;
+ int nsig, signo;
+
if (ioctl(signalpipe[0], FIONREAD, &nsig) != 0) {
- syslog(LOG_ERR, "ioctl: %m");
- exit(EX_OSERR);
+ syslog(LOG_ERR, "ioctl: %m");
+ exit(EX_OSERR);
}
+ nsig /= sizeof(signo);
while (--nsig >= 0) {
- char c;
- if (read(signalpipe[0], &c, 1) != 1) {
- syslog(LOG_ERR, "read: %m");
- exit(EX_OSERR);
- }
- if (debug)
- warnx("handling signal flag %c", c);
- switch(c) {
- case 'A': /* sigalrm */
- retry();
- break;
- case 'C': /* sigchld */
- reapchild();
- break;
- case 'H': /* sighup */
- config();
- break;
- }
+ size_t len;
+
+ len = read(signalpipe[0], &signo, sizeof(signo));
+ if (len != sizeof(signo)) {
+ syslog(LOG_ERR, "read: %m");
+ exit(EX_OSERR);
+ }
+ if (debug)
+ warnx("handling signal flag %d", signo);
+ switch (signo) {
+ case SIGALRM:
+ retry();
+ break;
+ case SIGCHLD:
+ reapchild();
+ break;
+ case SIGHUP:
+ config();
+ break;
+ }
}
}
for (sep = servtab; n && sep; sep = sep->se_next)
@@ -887,12 +900,13 @@ main(int argc, char **argv)
* Add a signal flag to the signal flag queue for later handling
*/
-void
-flag_signal(int c)
+static void
+flag_signal(int signo)
{
- char ch = c;
+ size_t len;
- if (write(signalpipe[1], &ch, 1) != 1) {
+ len = write(signalpipe[1], &signo, sizeof(signo));
+ if (len != sizeof(signo)) {
syslog(LOG_ERR, "write: %m");
_exit(EX_OSERR);
}
@@ -903,7 +917,7 @@ flag_signal(int c)
* limit on children, then stop accepting incoming requests.
*/
-void
+static void
addchild(struct servtab *sep, pid_t pid)
{
if (sep->se_maxchild <= 0)
@@ -920,17 +934,7 @@ addchild(struct servtab *sep, pid_t pid)
disable(sep);
}
-/*
- * Some child process has exited. See if it's on somebody's list.
- */
-
-void
-flag_reapchild(int signo __unused)
-{
- flag_signal('C');
-}
-
-void
+static void
reapchild(void)
{
int k, status;
@@ -968,13 +972,7 @@ reapchild(void)
}
}
-void
-flag_config(int signo __unused)
-{
- flag_signal('H');
-}
-
-void
+static void
config(void)
{
struct servtab *sep, *new, **sepp;
@@ -1182,7 +1180,7 @@ config(void)
(void) sigsetmask(omask);
}
-void
+static void
unregisterrpc(struct servtab *sep)
{
u_int i;
@@ -1237,13 +1235,7 @@ unregisterrpc(struct servtab *sep)
(void) sigsetmask(omask);
}
-void
-flag_retry(int signo __unused)
-{
- flag_signal('A');
-}
-
-void
+static void
retry(void)
{
struct servtab *sep;
@@ -1254,7 +1246,7 @@ retry(void)
setup(sep);
}
-void
+static void
setup(struct servtab *sep)
{
int on = 1;
@@ -1281,6 +1273,7 @@ setsockopt(fd, SOL_SOCKET, opt, (char *)&on, sizeof (o
syslog(LOG_ERR, "setsockopt (SO_PRIVSTATE): %m");
#endif
/* tftpd opens a new connection then needs more infos */
+#ifdef INET6
if ((sep->se_family == AF_INET6) &&
(strcmp(sep->se_proto, "udp") == 0) &&
(sep->se_accept == 0) &&
@@ -1293,6 +1286,7 @@ setsockopt(fd, SOL_SOCKET, opt, (char *)&on, sizeof (o
(char *)&flag, sizeof (flag)) < 0)
syslog(LOG_ERR, "setsockopt (IPV6_V6ONLY): %m");
}
+#endif
#undef turnon
#ifdef IPSEC
ipsecsetup(sep);
@@ -1330,7 +1324,9 @@ setsockopt(fd, SOL_SOCKET, opt, (char *)&on, sizeof (o
u_int i;
socklen_t len = sep->se_ctrladdr_size;
struct netconfig *netid, *netid2 = NULL;
+#ifdef INET6
struct sockaddr_in sock;
+#endif
struct netbuf nbuf, nbuf2;
if (getsockname(sep->se_fd,
@@ -1345,6 +1341,7 @@ setsockopt(fd, SOL_SOCKET, opt, (char *)&on, sizeof (o
nbuf.len = sep->se_ctrladdr.sa_len;
if (sep->se_family == AF_INET)
netid = sep->se_socktype==SOCK_DGRAM? udpconf:tcpconf;
+#ifdef INET6
else {
netid = sep->se_socktype==SOCK_DGRAM? udp6conf:tcp6conf;
if (!sep->se_nomapped) { /* INET and INET6 */
@@ -1356,6 +1353,7 @@ setsockopt(fd, SOL_SOCKET, opt, (char *)&on, sizeof (o
sock.sin_port = sep->se_ctrladdr6.sin6_port;
}
}
+#endif
if (debug)
print_service("REG ", sep);
for (i = sep->se_rpc_lowvers; i <= sep->se_rpc_highvers; i++) {
@@ -1377,7 +1375,7 @@ setsockopt(fd, SOL_SOCKET, opt, (char *)&on, sizeof (o
}
#ifdef IPSEC
-void
+static void
ipsecsetup(struct servtab *sep)
{
char *buf;
@@ -1451,7 +1449,7 @@ ipsecsetup(struct servtab *sep)
/*
* Finish with a service and its socket.
*/
-void
+static void
close_sep(struct servtab *sep)
{
if (sep->se_fd >= 0) {
@@ -1464,7 +1462,7 @@ close_sep(struct servtab *sep)
sep->se_numchild = 0; /* forget about any existing children */
}
-int
+static int
matchservent(const char *name1, const char *name2, const char *proto)
{
char **alias, *p;
@@ -1488,7 +1486,7 @@ matchservent(const char *name1, const char *name2, con
return(0);
}
-struct servtab *
+static struct servtab *
enter(struct servtab *cp)
{
struct servtab *sep;
@@ -1508,7 +1506,7 @@ enter(struct servtab *cp)
return (sep);
}
-void
+static void
enable(struct servtab *sep)
{
if (debug)
@@ -1537,7 +1535,7 @@ enable(struct servtab *sep)
maxsock = sep->se_fd;
}
-void
+static void
disable(struct servtab *sep)
{
if (debug)
@@ -1570,11 +1568,11 @@ disable(struct servtab *sep)
maxsock--;
}
-FILE *fconfig = NULL;
-struct servtab serv;
-char line[LINE_MAX];
+static FILE *fconfig = NULL;
+static struct servtab serv;
+static char line[LINE_MAX];
-int
+static int
setconfig(void)
{
@@ -1586,7 +1584,7 @@ setconfig(void)
return (fconfig != NULL);
}
-void
+static void
endconfig(void)
{
if (fconfig) {
@@ -1595,7 +1593,7 @@ endconfig(void)
}
}
-struct servtab *
+static struct servtab *
getconfigent(void)
{
struct servtab *sep = &serv;
@@ -1973,7 +1971,7 @@ more:
return (sep);
}
-void
+static void
freeconfig(struct servtab *cp)
{
int i;
@@ -2009,7 +2007,7 @@ freeconfig(struct servtab *cp)
* Safe skip - if skip returns null, log a syntax error in the
* configuration file and exit.
*/
-char *
+static char *
sskip(char **cpp)
{
char *cp;
@@ -2022,7 +2020,7 @@ sskip(char **cpp)
return (cp);
}
-char *
+static char *
skip(char **cpp)
{
char *cp = *cpp;
@@ -2058,7 +2056,7 @@ again:
return (start);
}
-char *
+static char *
nextline(FILE *fd)
{
char *cp;
@@ -2071,7 +2069,7 @@ nextline(FILE *fd)
return (line);
}
-char *
+static char *
newstr(const char *cp)
{
char *cr;
@@ -2111,13 +2109,13 @@ check_loop(const struct sockaddr *sa, const struct ser
switch (se2->se_family) {
case AF_INET:
- if (((const struct sockaddr_in *)sa)->sin_port ==
+ if (csatosin(sa)->sin_port ==
se2->se_ctrladdr4.sin_port)
goto isloop;
continue;
#ifdef INET6
case AF_INET6:
- if (((const struct sockaddr_in6 *)sa)->sin6_port ==
+ if (csatosin6(sa)->sin6_port ==
se2->se_ctrladdr6.sin6_port)
goto isloop;
continue;
@@ -2141,7 +2139,7 @@ check_loop(const struct sockaddr *sa, const struct ser
* print_service:
* Dump relevant information to stderr
*/
-void
+static void
print_service(const char *action, const struct servtab *sep)
{
fprintf(stderr,
@@ -2189,9 +2187,9 @@ typedef struct CHash {
CTime ch_Times[CHTSIZE];
} CHash;
-CHash CHashAry[CPMHSIZE];
+static CHash CHashAry[CPMHSIZE];
-int
+static int
cpmip(const struct servtab *sep, int ctrl)
{
struct sockaddr_storage rss;
Modified: stable/11/usr.sbin/inetd/inetd.h
==============================================================================
--- stable/11/usr.sbin/inetd/inetd.h Sun Jan 5 19:14:16 2020 (r356386)
+++ stable/11/usr.sbin/inetd/inetd.h Sun Jan 5 21:32:41 2020 (r356387)
@@ -123,12 +123,7 @@ struct servtab {
#define se_reset se_flags.se_reset
int check_loop(const struct sockaddr *, const struct servtab *sep);
-int getvalue(const char *, int *, const char *);
-char *newstr(const char *);
void inetd_setproctitle(const char *, int);
-void print_service(const char *, const struct servtab *);
-char *sskip(char **);
-char *skip(char **);
struct servtab *tcpmux(int);
extern int debug;
@@ -143,3 +138,4 @@ struct biltin {
int bi_maxchild; /* max number of children, -1=default */
bi_fn_t *bi_fn; /* function which performs it */
};
+extern struct biltin biltins[];
More information about the svn-src-stable-11
mailing list