Module Name: src Committed By: rillig Date: Mon Aug 30 17:32:23 UTC 2021
Modified Files: src/usr.sbin/inetd: inetd.c inetd.h ipsec.c ipsec.h parse_v2.c Log Message: inetd: remove trailing whitespace To generate a diff of this commit: cvs rdiff -u -r1.129 -r1.130 src/usr.sbin/inetd/inetd.c cvs rdiff -u -r1.1 -r1.2 src/usr.sbin/inetd/inetd.h cvs rdiff -u -r1.5 -r1.6 src/usr.sbin/inetd/ipsec.c cvs rdiff -u -r1.2 -r1.3 src/usr.sbin/inetd/ipsec.h \ src/usr.sbin/inetd/parse_v2.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/usr.sbin/inetd/inetd.c diff -u src/usr.sbin/inetd/inetd.c:1.129 src/usr.sbin/inetd/inetd.c:1.130 --- src/usr.sbin/inetd/inetd.c:1.129 Mon Aug 30 08:21:12 2021 +++ src/usr.sbin/inetd/inetd.c Mon Aug 30 17:32:23 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: inetd.c,v 1.129 2021/08/30 08:21:12 mlelstv Exp $ */ +/* $NetBSD: inetd.c,v 1.130 2021/08/30 17:32:23 rillig Exp $ */ /*- * Copyright (c) 1998, 2003 The NetBSD Foundation, Inc. @@ -66,7 +66,7 @@ __COPYRIGHT("@(#) Copyright (c) 1983, 19 #if 0 static char sccsid[] = "@(#)inetd.c 8.4 (Berkeley) 4/13/94"; #else -__RCSID("$NetBSD: inetd.c,v 1.129 2021/08/30 08:21:12 mlelstv Exp $"); +__RCSID("$NetBSD: inetd.c,v 1.130 2021/08/30 17:32:23 rillig Exp $"); #endif #endif /* not lint */ @@ -484,7 +484,7 @@ main(int argc, char *argv[]) if (!sep->se_wait && sep->se_socktype == SOCK_STREAM) { /* XXX here do the libwrap check-before-accept*/ ctrl = accept(sep->se_fd, NULL, NULL); - DPRINTF(SERV_FMT ": accept, ctrl fd %d", + DPRINTF(SERV_FMT ": accept, ctrl fd %d", SERV_PARAMS(sep), ctrl); if (ctrl < 0) { if (errno != EINTR) @@ -644,7 +644,7 @@ run_service(int ctrl, struct servtab *se } else if (sep->se_group) { (void) setgid((gid_t)grp->gr_gid); } - DPRINTF("%d execl %s", + DPRINTF("%d execl %s", getpid(), sep->se_server); /* Set our control descriptor to not close-on-exec... */ if (fcntl(ctrl, F_SETFD, 0) < 0) @@ -705,21 +705,21 @@ reapchild(void) size_t line_number; -/* +/* * Recursively merge loaded service definitions with any defined - * in the current or included config files. + * in the current or included config files. */ static void config(void) { struct servtab *sep, *cp; /* - * Current position in line, used with key-values notation, - * saves cp across getconfigent calls. + * Current position in line, used with key-values notation, + * saves cp across getconfigent calls. */ char *current_pos; size_t n; - + /* open config file from beginning */ fconfig = fopen(CONFIG, "r"); if(fconfig == NULL) { @@ -729,7 +729,7 @@ config(void) /* First call to nextline will advance line_number to 1 */ line_number = 0; - + /* Start parsing at the beginning of the first line */ current_pos = nextline(fconfig); @@ -782,9 +782,9 @@ config(void) } sep->se_checked = 1; - /* + /* * Remainder of config(void) checks validity of servtab options - * and sets up the service by setting up sockets (in setup(servtab)). + * and sets up the service by setting up sockets (in setup(servtab)). */ switch (sep->se_family) { case AF_LOCAL: @@ -842,7 +842,7 @@ config(void) if (isrpcservice(sep) || ISMUX(sep)) port = "0"; else - port = sep->se_service; + port = sep->se_service; error = getaddrinfo(host, port, &hints, &res); if (error) { if (error == EAI_SERVICE) { @@ -886,7 +886,7 @@ config(void) rp = getrpcbyname(sep->se_service); if (rp == 0) { syslog(LOG_ERR, - SERV_FMT + SERV_FMT ": unknown service", SERV_PARAMS(sep)); sep->se_checked = 0; @@ -943,7 +943,7 @@ goaway(void) for (sep = servtab; sep != NULL; sep = sep->se_next) { if (sep->se_fd == -1) continue; - + switch (sep->se_family) { case AF_LOCAL: (void)unlink(sep->se_service); @@ -972,7 +972,7 @@ setup(struct servtab *sep) struct kevent *ev; if ((sep->se_fd = socket(sep->se_family, sep->se_socktype, 0)) < 0) { - DPRINTF("socket failed on " SERV_FMT ": %s", + DPRINTF("socket failed on " SERV_FMT ": %s", SERV_PARAMS(sep), strerror(errno)); syslog(LOG_ERR, "%s/%s: socket: %m", sep->se_service, sep->se_proto); @@ -1067,7 +1067,7 @@ setsockopt(fd, SOL_SOCKET, opt, &on, (so */ static void close_sep(struct servtab *sep) -{ +{ if (sep->se_fd >= 0) { (void) close(sep->se_fd); @@ -1201,25 +1201,25 @@ static struct servtab * getconfigent(char **current_pos) { struct servtab *sep = &serv; - int argc, val; + int argc, val; char *cp, *cp0, *arg, *buf0, *buf1, *sz0, *sz1; static char TCPMUX_TOKEN[] = "tcpmux/"; #define MUX_LEN (sizeof(TCPMUX_TOKEN)-1) char *hostdelim; - /* - * Pre-condition: current_pos points into line, + /* + * Pre-condition: current_pos points into line, * line contains config line. Continue where the last getconfigent left off. - * Allows for multiple service definitions per line. + * Allows for multiple service definitions per line. */ cp = *current_pos; if (false) { - /* - * Go to the next line, but only after attemting to read the current - * one! Keep reading until we find a valid definition or EOF. + /* + * Go to the next line, but only after attemting to read the current + * one! Keep reading until we find a valid definition or EOF. */ -more: +more: cp = nextline(fconfig); } @@ -1244,8 +1244,8 @@ more: if (ipsecsetup_test(p) < 0) { ERR("Invalid IPsec policy \"%s\"", p); LOG_EARLY_ENDCONF(); - /* - * Stop reading the current config to prevent services + /* + * Stop reading the current config to prevent services * from being run without IPsec. */ return NULL; @@ -1283,7 +1283,7 @@ more: goto more; } } - + /* After this point, we might need to store data in a servtab */ *sep = init_servtab(); @@ -1353,16 +1353,16 @@ more: freeconfig(sep); goto more; case V2_ERROR: - /* + /* * Unrecoverable error, stop reading. freeconfig is called - * in parse_v2.c + * in parse_v2.c */ LOG_EARLY_ENDCONF(); freeconfig(sep); return NULL; } } else if (strcmp(arg, "off") == 0 || strncmp(arg, "off#", 4) == 0) { - + if (arg[3] == '#') { cp = nextline(fconfig); } @@ -1523,7 +1523,7 @@ do { \ if (cp1 != NULL) { int rstatus; *cp1++ = '\0'; - sep->se_service_max = (size_t)strtou(cp1, NULL, 10, 0, + sep->se_service_max = (size_t)strtou(cp1, NULL, 10, 0, SERVTAB_COUNT_MAX, &rstatus); if (rstatus != 0) { @@ -1533,7 +1533,7 @@ do { \ } WRN("Improper \"max\" value '%s', " - "using '%zu' instead: %s", + "using '%zu' instead: %s", cp1, sep->se_service_max, strerror(rstatus)); @@ -1581,7 +1581,7 @@ do { \ freeconfig(sep); goto more; } - + argc = 0; for (arg = skip(&cp); cp; arg = skip(&cp)) { if (argc < MAXARGV) @@ -1647,7 +1647,7 @@ again: c = getc(fconfig); (void) ungetc(c, fconfig); - if (c == ' ' || c == '\t') + if (c == ' ' || c == '\t') if ((cp = nextline(fconfig)) != NULL) goto again; *cpp = NULL; @@ -1805,7 +1805,7 @@ discard_stream(int s, struct servtab *se /* ARGSUSED */ static void discard_dg(int s, struct servtab *sep) /* Discard service -- ignore data */ - + { char buffer[BUFSIZE]; @@ -2256,8 +2256,8 @@ config_root() purge_unchecked(); } -static void -purge_unchecked(void) +static void +purge_unchecked(void) { struct servtab *sep, **sepp = &servtab; int servtab_count = 0; @@ -2285,9 +2285,9 @@ purge_unchecked(void) } static bool -is_same_service(const struct servtab *sep, const struct servtab *cp) +is_same_service(const struct servtab *sep, const struct servtab *cp) { - return + return strcmp(sep->se_service, cp->se_service) == 0 && strcmp(sep->se_hostaddr, cp->se_hostaddr) == 0 && strcmp(sep->se_proto, cp->se_proto) == 0 && @@ -2295,9 +2295,9 @@ is_same_service(const struct servtab *se ISMUX(sep) == ISMUX(cp); } -int +int parse_protocol(struct servtab *sep) -{ +{ int val; if (strcmp(sep->se_proto, "unix") == 0) { @@ -2409,11 +2409,11 @@ parse_server(struct servtab *sep, const } /* TODO test to make sure accept filter still works */ -void +void parse_accept_filter(char *arg, struct servtab *sep) { char *accf, *accf_arg; /* one and only one accept filter */ - accf = strchr(arg, ':'); + accf = strchr(arg, ':'); if (!accf) return; if (accf != strrchr(arg, ':') || *(accf + 1) == '\0') { @@ -2437,7 +2437,7 @@ parse_accept_filter(char *arg, struct se } } -void +void parse_socktype(char* arg, struct servtab* sep) { /* stream socket may have an accept filter, only check first chars */ if (strncmp(arg, "stream", sizeof("stream") - 1) == 0) @@ -2454,13 +2454,13 @@ parse_socktype(char* arg, struct servtab sep->se_socktype = -1; } -static struct servtab +static struct servtab init_servtab() { /* This does not set every field to default. See enter() as well */ return (struct servtab) { - /* + /* * Set se_max to non-zero so uninitialized value is not - * a valid value. Useful in v2 syntax parsing. + * a valid value. Useful in v2 syntax parsing. */ .se_service_max = SERVTAB_UNSPEC_SIZE_T, .se_ip_max = SERVTAB_UNSPEC_SIZE_T, @@ -2519,7 +2519,7 @@ include_configs(char *pattern) #endif } -static void +static void prepare_next_config(const char *file_name) { /* Setup new state that is normally only done in main */ @@ -2640,7 +2640,7 @@ check_no_reinclude(const char *glob_path } /* Resolve the pattern relative to the config file the pattern is from */ -static char * +static char * gen_file_pattern(const char *cur_config, const char *pattern) { if(pattern[0] == '/') { @@ -2660,7 +2660,7 @@ gen_file_pattern(const char *cur_config, if (last == 0) { /* cur_config is just a filename, pattern already correct */ return newstr(pattern); - } + } /* Relativize pattern to cur_config file's directory */ char *full_pattern = malloc(last + 1 + strlen(pattern) + 1); @@ -2675,7 +2675,7 @@ gen_file_pattern(const char *cur_config, } static int -glob_error(const char *path, int error) +glob_error(const char *path, int error) { WRN("Error while resolving path '%s': %s", path, strerror(error)); return 0; @@ -2702,13 +2702,13 @@ rl_process(struct servtab *sep, int ctrl sep->se_time = now; istimevalid = true; } - + if (sep->se_count >= sep->se_service_max) { if(!istimevalid) { now = rl_time(); istimevalid = true; } - + if (now - sep->se_time > CNT_INTVL) { rl_reset(sep, now); } else { @@ -2747,17 +2747,17 @@ rl_process(struct servtab *sep, int ctrl DPRINTF( SERV_FMT ": se_ip_max %zu and ip_count %zu", SERV_PARAMS(sep), sep->se_ip_max, node->count); - + if (node->count >= sep->se_ip_max) { if (!istimevalid) { - /* + /* * Only get the clock time if we didn't - * already + * already */ now = rl_time(); istimevalid = true; } - + if (now - sep->se_time > CNT_INTVL) { rl_reset(sep, now); node = rl_add(sep, hbuf); @@ -2769,7 +2769,7 @@ rl_process(struct servtab *sep, int ctrl * log */ syslog(LOG_ERR, SERV_FMT - ": max ip spawn rate (%zu in " + ": max ip spawn rate (%zu in " "%ji seconds) for " "%." TOSTRING(NI_MAXHOST) "s " "already met; service not started", @@ -2779,13 +2779,13 @@ rl_process(struct servtab *sep, int ctrl node->address); } - DPRINTF(SERV_FMT ": service not started", + DPRINTF(SERV_FMT ": service not started", SERV_PARAMS(sep)); rl_drop_connection(sep, ctrl); /* * Increment so debug-syslog message will - * trigger only once + * trigger only once */ node->count++; return -1; @@ -2808,7 +2808,7 @@ rl_get_name(struct servtab *sep, int ctr socklen_t len = sizeof(struct sockaddr_storage); switch (sep->se_socktype) { case SOCK_STREAM: - if (getpeername(ctrl, (struct sockaddr *)&addr, &len)) { + if (getpeername(ctrl, (struct sockaddr *)&addr, &len)) { /* error, log it and skip ip rate limiting */ syslog(LOG_ERR, SERV_FMT " failed to get peer name of the " @@ -2823,7 +2823,7 @@ rl_get_name(struct servtab *sep, int ctr /* scatter/gather and control info is null */ }; int count; - + /* Peek so service can still get the packet */ count = recvmsg(ctrl, &header, MSG_PEEK); if (count == -1) { @@ -2843,7 +2843,7 @@ rl_get_name(struct servtab *sep, int ctr exit(EXIT_FAILURE); } - if (getnameinfo((struct sockaddr *)&addr, + if (getnameinfo((struct sockaddr *)&addr, addr.ss_len, hbuf, NI_MAXHOST, NULL, 0, NI_NUMERICHOST)) { /* error, log it and skip ip rate limiting */ @@ -2860,9 +2860,9 @@ rl_drop_connection(struct servtab *sep, { if (!sep->se_wait && sep->se_socktype == SOCK_STREAM) { - /* - * If the fd isn't a listen socket, - * close the individual connection too. + /* + * If the fd isn't a listen socket, + * close the individual connection too. */ close(ctrl); return; @@ -2870,7 +2870,7 @@ rl_drop_connection(struct servtab *sep, if (sep->se_socktype != SOCK_DGRAM) { return; } - /* + /* * Drop the single datagram the service would have * consumed if nowait. If this is a wait service, this * will consume 1 datagram, and further received packets @@ -2880,7 +2880,7 @@ rl_drop_connection(struct servtab *sep, /* All fields null, just consume one message */ }; int count; - + count = recvmsg(ctrl, &header, 0); if (count == -1) { syslog(LOG_ERR, @@ -2888,11 +2888,11 @@ rl_drop_connection(struct servtab *sep, SERV_PARAMS(sep), strerror(errno)); exit(EXIT_FAILURE); } - DPRINTF(SERV_FMT ": dropped dgram message", + DPRINTF(SERV_FMT ": dropped dgram message", SERV_PARAMS(sep)); } -static time_t +static time_t rl_time() { struct timespec time; @@ -2912,7 +2912,7 @@ rl_add(struct servtab *sep, char* ip) SERV_FMT ": add ip %s to rate limiting tracking", SERV_PARAMS(sep), ip); - /* + /* * TODO memory could be saved by using a variable length malloc * with only the length of ip instead of the existing address field * NI_MAXHOST in length. @@ -2941,7 +2941,7 @@ rl_add(struct servtab *sep, char* ip) static void rl_reset(struct servtab *sep, time_t now) { - DPRINTF(SERV_FMT ": %ji seconds passed; resetting rate limiting ", + DPRINTF(SERV_FMT ": %ji seconds passed; resetting rate limiting ", SERV_PARAMS(sep), (intmax_t)(now - sep->se_time)); sep->se_count = 0; @@ -2967,7 +2967,7 @@ clear_ip_list(struct servtab *sep) { static struct se_ip_list_node * rl_try_get_ip(struct servtab *sep, char *ip) { - struct se_ip_list_node *curr; + struct se_ip_list_node *curr; DPRINTF( SERV_FMT ": look up ip %s for ip_max rate limiting", Index: src/usr.sbin/inetd/inetd.h diff -u src/usr.sbin/inetd/inetd.h:1.1 src/usr.sbin/inetd/inetd.h:1.2 --- src/usr.sbin/inetd/inetd.h:1.1 Sun Aug 29 09:54:18 2021 +++ src/usr.sbin/inetd/inetd.h Mon Aug 30 17:32:23 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: inetd.h,v 1.1 2021/08/29 09:54:18 christos Exp $ */ +/* $NetBSD: inetd.h,v 1.2 2021/08/30 17:32:23 rillig Exp $ */ /*- * Copyright (c) 1998, 2003 The NetBSD Foundation, Inc. @@ -82,9 +82,9 @@ #endif typedef enum service_type { - NORM_TYPE = 0, - MUX_TYPE = 1, - MUXPLUS_TYPE = 2, + NORM_TYPE = 0, + MUX_TYPE = 1, + MUXPLUS_TYPE = 2, FAITH_TYPE = 3 } service_type; @@ -159,9 +159,9 @@ struct servtab { size_t se_ip_max; /* max # of instances of this service per ip per minute */ struct se_ip_list_node { struct se_ip_list_node *next; - size_t count; /* + size_t count; /* * number of instances of this service started from - * this ip address since se_time (includes + * this ip address since se_time (includes * attempted starts if greater than se_ip_max) */ char address[NI_MAXHOST]; @@ -202,7 +202,7 @@ extern char *policy; typedef enum parse_v2_result {V2_SUCCESS, V2_SKIP, V2_ERROR} parse_v2_result; -/* +/* * Parse a key-values service definition, starting at the token after * on/off (i.e. parse a series of key-values pairs terminated by a semicolon). * Fills the provided servtab structure. Does not call freeconfig on error. Index: src/usr.sbin/inetd/ipsec.c diff -u src/usr.sbin/inetd/ipsec.c:1.5 src/usr.sbin/inetd/ipsec.c:1.6 --- src/usr.sbin/inetd/ipsec.c:1.5 Sun Feb 3 12:02:22 2019 +++ src/usr.sbin/inetd/ipsec.c Mon Aug 30 17:32:23 2021 @@ -1,9 +1,9 @@ -/* $NetBSD: ipsec.c,v 1.5 2019/02/03 12:02:22 mrg Exp $ */ +/* $NetBSD: ipsec.c,v 1.6 2021/08/30 17:32:23 rillig Exp $ */ /* * Copyright (C) 1999 WIDE Project. * All rights reserved. - * + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: @@ -15,7 +15,7 @@ * 3. Neither the name of the project nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. - * + * * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE Index: src/usr.sbin/inetd/ipsec.h diff -u src/usr.sbin/inetd/ipsec.h:1.2 src/usr.sbin/inetd/ipsec.h:1.3 --- src/usr.sbin/inetd/ipsec.h:1.2 Tue Jan 23 21:06:24 2018 +++ src/usr.sbin/inetd/ipsec.h Mon Aug 30 17:32:23 2021 @@ -1,9 +1,9 @@ -/* $NetBSD: ipsec.h,v 1.2 2018/01/23 21:06:24 sevan Exp $ */ +/* $NetBSD: ipsec.h,v 1.3 2021/08/30 17:32:23 rillig Exp $ */ /* * Copyright (C) 1999 WIDE Project. * All rights reserved. - * + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: @@ -15,7 +15,7 @@ * 3. Neither the name of the project nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. - * + * * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE Index: src/usr.sbin/inetd/parse_v2.c diff -u src/usr.sbin/inetd/parse_v2.c:1.2 src/usr.sbin/inetd/parse_v2.c:1.3 --- src/usr.sbin/inetd/parse_v2.c:1.2 Mon Aug 30 06:27:49 2021 +++ src/usr.sbin/inetd/parse_v2.c Mon Aug 30 17:32:23 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: parse_v2.c,v 1.2 2021/08/30 06:27:49 tih Exp $ */ +/* $NetBSD: parse_v2.c,v 1.3 2021/08/30 17:32:23 rillig Exp $ */ /*- * Copyright (c) 2021 The NetBSD Foundation, Inc. @@ -30,7 +30,7 @@ */ #include <sys/cdefs.h> -__RCSID("$NetBSD: parse_v2.c,v 1.2 2021/08/30 06:27:49 tih Exp $"); +__RCSID("$NetBSD: parse_v2.c,v 1.3 2021/08/30 17:32:23 rillig Exp $"); #include <ctype.h> #include <errno.h> @@ -156,7 +156,7 @@ parse_syntax_v2(struct servtab *sep, cha invoke_result result; for (;;) { - switch(result = + switch(result = parse_invoke_handler(&is_valid_definition, cpp, sep)) { case INVOKE_SUCCESS: /* Keep reading more options in. */ @@ -194,14 +194,14 @@ parse_syntax_v2(struct servtab *sep, cha } } -/* +/* * Fill in any remaining values that should be inferred - * Log an error if a required parameter that isn't + * Log an error if a required parameter that isn't * provided by user can't be inferred from other servtab data. - * Return true on success, false on failure. + * Return true on success, false on failure. */ -static bool -fill_default_values(struct servtab *sep) +static bool +fill_default_values(struct servtab *sep) { bool is_valid = true; @@ -209,7 +209,7 @@ fill_default_values(struct servtab *sep) /* Set default to same as in v1 syntax. */ sep->se_service_max = TOOMANY; } - + if (sep->se_hostaddr == NULL) { /* Set hostaddr to default */ sep->se_hostaddr = newstr(defhost); @@ -292,7 +292,7 @@ setup_internal(struct servtab *sep) ENI("exec"); return false; } - + if (wait_prev != SERVTAB_UNSPEC_VAL && wait_prev != sep->se_wait) { /* If wait was already specified throw an error. */ WRN(WAIT_WRN, sep->se_service); @@ -311,7 +311,7 @@ infer_protocol_ip_version(struct servtab && strcmp("rpc/udp", sep->se_proto) != 0) { return true; } - + if (inet_pton(AF_INET, sep->se_hostaddr, &tmp)) { sep->se_family = AF_INET; return true; @@ -327,29 +327,29 @@ infer_protocol_ip_version(struct servtab return false; } -/* - * Skips whitespaces, newline characters, and comments, - * and returns the next token. Returns false and logs error if an EOF is - * encountered. +/* + * Skips whitespaces, newline characters, and comments, + * and returns the next token. Returns false and logs error if an EOF is + * encountered. */ -static bool +static bool skip_whitespace(char **cpp) { char *cp = *cpp; int line_start = line_number; - + for (;;) { while (isblank((unsigned char)*cp)) cp++; - if (*cp == '\0' || *cp == '#') { + if (*cp == '\0' || *cp == '#') { cp = nextline(fconfig); /* Should never expect EOF when skipping whitespace */ if (cp == NULL) { ERR("Early end of file after line %d", - line_start); + line_start); return false; } continue; @@ -362,7 +362,7 @@ skip_whitespace(char **cpp) } /* Get the key handler function pointer for the given name */ -static key_handler_func +static key_handler_func get_handler(char *name) { /* Call function to handle option parsing. */ @@ -374,18 +374,18 @@ get_handler(char *name) return NULL; } -static inline void +static inline void strmove(char *buf, size_t off) -{ +{ memmove(buf, buf + off, strlen(buf + off) + 1); } -/* - * Perform an in-place parse of a single-line quoted string +/* + * Perform an in-place parse of a single-line quoted string * with escape sequences. Sets *cpp to the position after the quoted characters. * Uses shell-style quote parsing. */ -static bool +static bool parse_quotes(char **cpp) { char *cp = *cpp; @@ -398,7 +398,7 @@ parse_quotes(char **cpp) strmove(cp, 1); continue; } - + if (*cp == '\\') { /* start is location of backslash */ char *start = cp; @@ -406,9 +406,9 @@ parse_quotes(char **cpp) switch (*cp) { case 'x': { int temp, bits; - if (((bits = hex_to_bits(*(cp + 1))) == -1) + if (((bits = hex_to_bits(*(cp + 1))) == -1) || ((temp = hex_to_bits(*(cp + 2))) == -1)) { - ERR("Invalid hexcode sequence '%.4s'", + ERR("Invalid hexcode sequence '%.4s'", start); return false; } @@ -474,16 +474,16 @@ hex_to_bits(char in) } } -/* +/* * Parse the next value for a key handler and advance list->cp past the found - * value. Return NULL if there are no more values or there was an error + * value. Return NULL if there are no more values or there was an error * during parsing, and set the list->state to the appropriate value. */ -static char * +static char * next_value(vlist list) { char *cp = list->cp; - + if (list->state != VALS_PARSING) { /* Already at the end of a values list, or there was an error.*/ return NULL; @@ -500,19 +500,19 @@ next_value(vlist list) list->cp = cp + 1; return NULL; } - + /* Check for end of line */ if (!skip_whitespace(&cp)) { list->state = VALS_ERROR; return NULL; } - /* + /* * Found the start of a potential value. Advance one character - * past the end of the value. + * past the end of the value. */ char * start = cp; - while (!isblank((unsigned char)*cp) && *cp != '#' && + while (!isblank((unsigned char)*cp) && *cp != '#' && *cp != ',' && *cp != ';' && *cp != '\0' ) { if (*cp == '"' || *cp == '\'') { /* Found a quoted segment */ @@ -525,7 +525,7 @@ next_value(vlist list) cp++; } } - + /* Handle comments next to unquoted values */ if (*cp == '#') { *cp = '\0'; @@ -534,7 +534,7 @@ next_value(vlist list) } if (*cp == '\0') { - /* + /* * Value ends with end of line, so it is already NUL-terminated */ list->cp = cp; @@ -570,20 +570,20 @@ parse_invoke_handler(bool *is_valid_defi /* Starting character of key */ key_name = cp; - + /* alphabetical or underscore allowed in name */ while (isalpha((unsigned char)*cp) || *cp == '_') { cp++; } - + is_blank = isblank((unsigned char)*cp); /* Get key handler and move to start of values */ if (*cp != '=' && !is_blank && *cp != '#') { ERR("Expected '=' but found '%c'", *cp); return INVOKE_ERROR; - } - + } + save = *cp; *cp = '\0'; cp++; @@ -616,9 +616,9 @@ parse_invoke_handler(bool *is_valid_defi info = (val_parse_info) {cp, VALS_PARSING}; - /* + /* * Read values for key and write into sep. - * If parsing is successful, all values for key must be read. + * If parsing is successful, all values for key must be read. */ if (handler(sep, &info) == KEY_HANDLER_FAILURE) { /* @@ -631,14 +631,14 @@ parse_invoke_handler(bool *is_valid_defi } if (info.state == VALS_END_DEF) { - /* + /* * Exit definition handling for(;;). - * Set the position to the end of the definition, + * Set the position to the end of the definition, * for multi-definition lines. */ *cpp = info.cp; return INVOKE_FINISH; - } + } if (info.state == VALS_ERROR) { /* Parse error, stop reading config */ return INVOKE_ERROR; @@ -655,8 +655,8 @@ is_internal(struct servtab *sep) return sep->se_bi != NULL; } -/* - * Key-values handlers +/* + * Key-values handlers */ static hresult @@ -667,8 +667,8 @@ unknown_handler(struct servtab *sep, vli } /* Set listen address for this service */ -static hresult -bind_handler(struct servtab *sep, vlist values) +static hresult +bind_handler(struct servtab *sep, vlist values) { if (sep->se_hostaddr != NULL) { TMD("bind"); @@ -684,7 +684,7 @@ bind_handler(struct servtab *sep, vlist return KEY_HANDLER_SUCCESS; } -static hresult +static hresult socket_type_handler(struct servtab *sep, vlist values) { char *type = next_value(values); @@ -710,14 +710,14 @@ socket_type_handler(struct servtab *sep, } /* Set accept filter SO_ACCEPTFILTER */ -static hresult +static hresult filter_handler(struct servtab *sep, vlist values) { - /* + /* * See: SO_ACCEPTFILTER https://man.netbsd.org/setsockopt.2 * An accept filter can have one other argument. * This code currently only supports one accept filter - * Also see parse_accept_filter(char* arg, struct servtab*sep) + * Also see parse_accept_filter(char* arg, struct servtab*sep) */ char *af_name, *af_arg; @@ -750,7 +750,7 @@ filter_handler(struct servtab *sep, vlis } /* Set protocol (udp, tcp, unix, etc.) */ -static hresult +static hresult protocol_handler(struct servtab *sep, vlist values) { char *val; @@ -759,7 +759,7 @@ protocol_handler(struct servtab *sep, vl TFA("protocol"); return KEY_HANDLER_FAILURE; } - + if (sep->se_type == NORM_TYPE && strncmp(val, "faith/", strlen("faith/")) == 0) { val += strlen("faith/"); @@ -777,7 +777,7 @@ protocol_handler(struct servtab *sep, vl return KEY_HANDLER_SUCCESS; } -/* +/* * Convert a string number possible ending with k or m to an integer. * Based on MALFORMED, GETVAL, and ASSIGN in getconfigent(void). */ @@ -816,18 +816,18 @@ size_to_bytes(char *arg) } /* sndbuf size */ -static hresult +static hresult send_buf_handler(struct servtab *sep, vlist values) { char *arg; int buffer_size; if (ISMUX(sep)) { - ERR("%s: can't specify buffer sizes for tcpmux services", + ERR("%s: can't specify buffer sizes for tcpmux services", sep->se_service); return KEY_HANDLER_FAILURE; } - + if ((arg = next_value(values)) == NULL) { TFA("sndbuf"); @@ -851,14 +851,14 @@ send_buf_handler(struct servtab *sep, vl } /* recvbuf size */ -static hresult +static hresult recv_buf_handler(struct servtab *sep, vlist values) { char *arg; int buffer_size; if (ISMUX(sep)) { - ERR("%s: Cannot specify buffer sizes for tcpmux services", + ERR("%s: Cannot specify buffer sizes for tcpmux services", sep->se_service); return KEY_HANDLER_FAILURE; } @@ -866,8 +866,8 @@ recv_buf_handler(struct servtab *sep, vl if ((arg = next_value(values)) == NULL){ TFA("recvbuf"); return KEY_HANDLER_FAILURE; - } - + } + buffer_size = size_to_bytes(arg); if (buffer_size == -1) { @@ -886,7 +886,7 @@ recv_buf_handler(struct servtab *sep, vl } /* Same as wait in positional */ -static hresult +static hresult wait_handler(struct servtab *sep, vlist values) { char *val; @@ -922,7 +922,7 @@ wait_handler(struct servtab *sep, vlist } else if (parse_wait(sep, wait)) { return KEY_HANDLER_FAILURE; } - + if ((val = next_value(values)) != NULL) { TMA("wait"); return KEY_HANDLER_FAILURE; @@ -932,7 +932,7 @@ wait_handler(struct servtab *sep, vlist } /* Set max connections in interval rate-limit, same as max in positional */ -static hresult +static hresult service_max_handler(struct servtab *sep, vlist values) { char *count_str; @@ -942,7 +942,7 @@ service_max_handler(struct servtab *sep, TMD("service_max"); return KEY_HANDLER_FAILURE; } - + count_str = next_value(values); if (count_str == NULL) { @@ -950,7 +950,7 @@ service_max_handler(struct servtab *sep, return KEY_HANDLER_FAILURE; } - size_t count = (size_t)strtou(count_str, NULL, 10, 0, + size_t count = (size_t)strtou(count_str, NULL, 10, 0, SERVTAB_COUNT_MAX, &rstatus); if (rstatus) { @@ -974,12 +974,12 @@ ip_max_handler(struct servtab *sep, vlis { char *count_str; int rstatus; - + if (sep->se_ip_max != SERVTAB_UNSPEC_SIZE_T) { TMD("ip_max"); return KEY_HANDLER_FAILURE; } - + count_str = next_value(values); if (count_str == NULL) { @@ -987,7 +987,7 @@ ip_max_handler(struct servtab *sep, vlis return KEY_HANDLER_FAILURE; } - size_t count = (size_t)strtou(count_str, NULL, 10, 0, + size_t count = (size_t)strtou(count_str, NULL, 10, 0, SERVTAB_COUNT_MAX, &rstatus); if (rstatus) { @@ -1006,12 +1006,12 @@ ip_max_handler(struct servtab *sep, vlis } /* Set user to execute as */ -static hresult +static hresult user_handler(struct servtab *sep, vlist values) { if (sep->se_user != NULL) { TMD("user"); - return KEY_HANDLER_FAILURE; + return KEY_HANDLER_FAILURE; } char *name = next_value(values); @@ -1030,9 +1030,9 @@ user_handler(struct servtab *sep, vlist return KEY_HANDLER_SUCCESS; } - + /* Set group to execute as */ -static hresult +static hresult group_handler(struct servtab *sep, vlist values) { char *name = next_value(values); @@ -1053,7 +1053,7 @@ group_handler(struct servtab *sep, vlist } /* Handle program path or "internal" */ -static hresult +static hresult exec_handler(struct servtab *sep, vlist values) { char *val; @@ -1075,7 +1075,7 @@ exec_handler(struct servtab *sep, vlist WRN(WAIT_WRN, sep->se_service); } } - + if ((val = next_value(values)) != NULL) { TMA("exec"); return KEY_HANDLER_FAILURE; @@ -1085,7 +1085,7 @@ exec_handler(struct servtab *sep, vlist } /* Handle program arguments */ -static hresult +static hresult args_handler(struct servtab *sep, vlist values) { char *val; @@ -1107,13 +1107,13 @@ args_handler(struct servtab *sep, vlist } while (argc <= MAXARGV) sep->se_argv[argc++] = NULL; - + return KEY_HANDLER_SUCCESS; } #ifdef IPSEC -/* +/* * ipsec_handler currently uses the ipsec.h utilities for parsing, requiring * all policies as a single value. This handler could potentially allow multiple * policies as separate values in the future, but strings would need to be @@ -1135,7 +1135,7 @@ ipsec_handler(struct servtab *sep, vlist return KEY_HANDLER_FAILURE; } - /* + /* * Use 'ipsec=' with no argument to disable ipsec for this service * An empty string indicates that IPsec was disabled, handled in * fill_default_values.