diff --git a/usr.sbin/syslogd/syslogd.c b/usr.sbin/syslogd/syslogd.c --- a/usr.sbin/syslogd/syslogd.c +++ b/usr.sbin/syslogd/syslogd.c @@ -177,6 +177,7 @@ (((d)->s6_addr32[2] ^ (a)->s6_addr32[2]) & (m)->s6_addr32[2]) == 0 && \ (((d)->s6_addr32[3] ^ (a)->s6_addr32[3]) & (m)->s6_addr32[3]) == 0 ) #endif + /* * Sockets used for logging; monitored by kevent(). */ @@ -327,11 +328,10 @@ #define DQ_TIMO_INIT 2 /* - * Struct to hold records of network addresses that are allowed to log - * to us. + * Network addresses that are allowed to log to us. */ struct allowedpeer { - int isnumeric; + bool isnumeric; u_short port; union { struct { @@ -347,7 +347,6 @@ }; static STAILQ_HEAD(, allowedpeer) aphead = STAILQ_HEAD_INITIALIZER(aphead); - /* * Intervals at which we flush out "message repeated" messages, * in seconds after previous message is logged. After each flush, @@ -444,7 +443,7 @@ static int p_open(const char *, pid_t *); static const char *ttymsg_check(struct iovec *, int, char *, int); static void usage(void); -static int validate(struct sockaddr *, const char *); +static bool validate(struct sockaddr *, const char *); static void unmapped(struct sockaddr *); static void wallmsg(struct filed *, struct iovec *, const int iovlen); static int waitdaemon(int); @@ -3332,7 +3331,7 @@ .ai_flags = AI_PASSIVE | AI_NUMERICHOST }; if (getaddrinfo(s, NULL, &hints, &res) == 0) { - ap->isnumeric = 1; + ap->isnumeric = true; memcpy(&ap->a_addr, res->ai_addr, res->ai_addrlen); ap->a_mask = (struct sockaddr_storage){ .ss_family = res->ai_family, @@ -3393,7 +3392,7 @@ freeaddrinfo(res); } else { /* arg `s' is domain name */ - ap->isnumeric = 0; + ap->isnumeric = false; ap->a_name = s; if (cp1) *cp1 = '/'; @@ -3436,7 +3435,7 @@ /* * Validate that the remote peer has permission to log to us. */ -static int +static bool validate(struct sockaddr *sa, const char *hname) { int i; @@ -3450,15 +3449,10 @@ #endif struct addrinfo hints, *res; u_short sport; - int num = 0; - STAILQ_FOREACH(ap, &aphead, next) { - num++; - } - dprintf("# of validation rule: %d\n", num); - if (num == 0) - /* traditional behaviour, allow everything */ - return (1); + /* traditional behaviour, allow everything */ + if (STAILQ_EMPTY(&aphead)) + return (true); (void)strlcpy(name, hname, sizeof(name)); hints = (struct addrinfo){ @@ -3474,7 +3468,7 @@ } if (getnameinfo(sa, sa->sa_len, ip, sizeof(ip), port, sizeof(port), NI_NUMERICHOST | NI_NUMERICSERV) != 0) - return (0); /* for safety, should not occur */ + return (false); /* for safety, should not occur */ dprintf("validate: dgram from IP %s, port %s, name %s;\n", ip, port, name); sport = atoi(port); @@ -3534,9 +3528,9 @@ } } dprintf("accepted in rule %d.\n", i); - return (1); /* hooray! */ + return (true); /* hooray! */ } - return (0); + return (false); } /*