diff options
author | 2020-12-10 18:35:31 +0000 | |
---|---|---|
committer | 2020-12-10 18:35:31 +0000 | |
commit | 29762c27b106907caafac7ef0ac264aa03b0b2b6 (patch) | |
tree | fa83db58ae963a7cc9c36189fd67767959015311 /sbin/dhclient | |
parent | Check sample signedness when setting up format conversions. (diff) | |
download | wireguard-openbsd-29762c27b106907caafac7ef0ac264aa03b0b2b6.tar.xz wireguard-openbsd-29762c27b106907caafac7ef0ac264aa03b0b2b6.zip |
Simplify '-i' handling, failing immediately during command line parsing
when an invalid option name is encountered.
Diffstat (limited to 'sbin/dhclient')
-rw-r--r-- | sbin/dhclient/clparse.c | 59 | ||||
-rw-r--r-- | sbin/dhclient/dhclient.8 | 9 | ||||
-rw-r--r-- | sbin/dhclient/dhclient.c | 28 | ||||
-rw-r--r-- | sbin/dhclient/dhcpd.h | 5 |
4 files changed, 42 insertions, 59 deletions
diff --git a/sbin/dhclient/clparse.c b/sbin/dhclient/clparse.c index a430f4ee36f..bb48cbb5850 100644 --- a/sbin/dhclient/clparse.c +++ b/sbin/dhclient/clparse.c @@ -1,4 +1,4 @@ -/* $OpenBSD: clparse.c,v 1.200 2020/12/06 19:51:03 krw Exp $ */ +/* $OpenBSD: clparse.c,v 1.201 2020/12/10 18:35:31 krw Exp $ */ /* Parser for dhclient config and lease files. */ @@ -77,7 +77,7 @@ void parse_lease_decl(FILE *, struct client_lease *); int parse_option(FILE *, int *, struct option_data *); int parse_reject_statement(FILE *); -void apply_ignore_list(char *); +void apply_actions(uint8_t *); void set_default_client_identifier(struct ether_addr *); void set_default_hostname(void); @@ -161,7 +161,7 @@ init_config(void) * | conf-decls conf-decl */ void -read_conf(char *name, char *ignore_list, struct ether_addr *hwaddr) +read_conf(char *name, uint8_t *actions, struct ether_addr *hwaddr) { FILE *cfile; int token; @@ -184,7 +184,7 @@ read_conf(char *name, char *ignore_list, struct ether_addr *hwaddr) set_default_client_identifier(hwaddr); set_default_hostname(); - apply_ignore_list(ignore_list); + apply_actions(actions); } /* @@ -949,49 +949,22 @@ parse_reject_statement(FILE *cfile) return 1; } -/* - * Apply the list of options to be ignored that was provided on the - * command line. This will override any ignore list obtained from - * dhclient.conf. - */ void -apply_ignore_list(char *ignore_list) +apply_actions(uint8_t *actions) { - uint8_t list[DHO_COUNT]; - char *p; - int ix, i, j; - - if (ignore_list == NULL) - return; - - memset(list, 0, sizeof(list)); - ix = 0; - - for (p = strsep(&ignore_list, ", "); p != NULL; - p = strsep(&ignore_list, ", ")) { - if (*p == '\0') - continue; + int i; - i = name_to_code(p); - if (i == DHO_END) { - log_debug("%s: invalid option name: '%s'", log_procname, - p); - return; + for (i = 0; i < DHO_END; i++) { + switch (actions[i]) { + case ACTION_IGNORE: + config->default_actions[i] = ACTION_IGNORE; + free(config->defaults[i].data); + config->defaults[i].data = NULL; + config->defaults[i].len = 0; + break; + default: + break; } - - /* Avoid storing duplicate options in the list. */ - for (j = 0; j < ix && list[j] != i; j++) - ; - if (j == ix) - list[ix++] = i; - } - - for (i = 0; i < ix; i++) { - j = list[i]; - config->default_actions[j] = ACTION_IGNORE; - free(config->defaults[j].data); - config->defaults[j].data = NULL; - config->defaults[j].len = 0; } } diff --git a/sbin/dhclient/dhclient.8 b/sbin/dhclient/dhclient.8 index 17cd6f2bc64..a64a75a4e7d 100644 --- a/sbin/dhclient/dhclient.8 +++ b/sbin/dhclient/dhclient.8 @@ -1,4 +1,4 @@ -.\" $OpenBSD: dhclient.8,v 1.45 2020/12/06 17:40:43 krw Exp $ +.\" $OpenBSD: dhclient.8,v 1.46 2020/12/10 18:35:31 krw Exp $ .\" .\" Copyright (c) 1997 The Internet Software Consortium. .\" All rights reserved. @@ -35,7 +35,7 @@ .\" Enterprises. To learn more about the Internet Software Consortium, .\" see ``http://www.isc.org/isc''. To learn more about Vixie .\" Enterprises, see ``http://www.vix.com''. -.Dd $Mdocdate: December 6 2020 $ +.Dd $Mdocdate: December 10 2020 $ .Dt DHCLIENT 8 .Os .Sh NAME @@ -92,12 +92,11 @@ will run in the foreground and log to .Em stderr . .It Fl i Ar options .Nm -will ignore any values provided by leases for the options specified. -This list will override any ignore statements in +will ignore values provided by leases for the options specified. +This list will supplement ignore statements in .Xr dhclient.conf 5 . .Ar options must be a comma separated list of valid option names. -Invalid option names will cause the entire list to be discarded. .It Fl n Configtest mode. Only check the configuration file for validity. diff --git a/sbin/dhclient/dhclient.c b/sbin/dhclient/dhclient.c index c9c0c2133b8..23fa185ec8c 100644 --- a/sbin/dhclient/dhclient.c +++ b/sbin/dhclient/dhclient.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dhclient.c,v 1.689 2020/12/06 17:40:43 krw Exp $ */ +/* $OpenBSD: dhclient.c,v 1.690 2020/12/10 18:35:31 krw Exp $ */ /* * Copyright 2004 Henning Brauer <henning@openbsd.org> @@ -623,12 +623,13 @@ rtm_dispatch(struct interface_info *ifi, struct rt_msghdr *rtm) int main(int argc, char *argv[]) { + uint8_t actions[DHO_END]; struct stat sb; struct interface_info *ifi; - char *ignore_list = NULL; + char *ignore_list, *p; int fd, socket_fd[2]; int routefd; - int ch; + int ch, i; if (isatty(STDERR_FILENO) != 0) log_init(1, LOG_DEBUG); /* log to stderr until daemonized */ @@ -639,6 +640,7 @@ main(int argc, char *argv[]) if (lstat(_PATH_DHCLIENT_CONF, &sb) == 0) path_dhclient_conf = _PATH_DHCLIENT_CONF; + memset(actions, ACTION_USELEASE, sizeof(actions)); while ((ch = getopt(argc, argv, "c:di:nrv")) != -1) switch (ch) { @@ -654,10 +656,21 @@ main(int argc, char *argv[]) cmd_opts |= OPT_FOREGROUND; break; case 'i': - if (optarg == NULL) - usage(); - cmd_opts |= OPT_IGNORELIST; + if (strlen(optarg) == 0) + break; ignore_list = strdup(optarg); + if (ignore_list == NULL) + fatal("ignore_list"); + for (p = strsep(&ignore_list, ", "); p != NULL; + p = strsep(&ignore_list, ", ")) { + if (*p == '\0') + continue; + i = name_to_code(p); + if (i == DHO_END) + fatalx("invalid option name: '%s'", p); + actions[i] = ACTION_IGNORE; + } + free(ignore_list); break; case 'n': cmd_opts |= OPT_NOACTION; @@ -719,8 +732,7 @@ main(int argc, char *argv[]) fatal("unpriv_ibuf"); imsg_init(unpriv_ibuf, socket_fd[1]); - read_conf(ifi->name, ignore_list, &ifi->hw_address); - free(ignore_list); + read_conf(ifi->name, actions, &ifi->hw_address); if ((cmd_opts & OPT_NOACTION) != 0) return 0; diff --git a/sbin/dhclient/dhcpd.h b/sbin/dhclient/dhcpd.h index 6db785d097d..b96441322c2 100644 --- a/sbin/dhclient/dhcpd.h +++ b/sbin/dhclient/dhcpd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: dhcpd.h,v 1.289 2020/12/06 17:40:43 krw Exp $ */ +/* $OpenBSD: dhcpd.h,v 1.290 2020/12/10 18:35:32 krw Exp $ */ /* * Copyright (c) 2004 Henning Brauer <henning@openbsd.org> @@ -215,7 +215,6 @@ extern int cmd_opts; #define OPT_VERBOSE 0x02 #define OPT_FOREGROUND 0x04 #define OPT_RELEASE 0x08 -#define OPT_IGNORELIST 0x40 void dhcpoffer(struct interface_info *, struct option_data *, const char *); @@ -240,7 +239,7 @@ uint32_t wrapsum(uint32_t); /* clparse.c */ void init_config(void); -void read_conf(char *, char *, struct ether_addr *); +void read_conf(char *, uint8_t *, struct ether_addr *); void read_lease_db(struct client_lease_tq *); /* kroute.c */ |