summaryrefslogtreecommitdiff
path: root/sbin/dhclient/clparse.c
diff options
context:
space:
mode:
authorKenneth R Westerback <krw@cvs.openbsd.org>2020-12-10 18:35:33 +0000
committerKenneth R Westerback <krw@cvs.openbsd.org>2020-12-10 18:35:33 +0000
commit645a38c4ecf4232d68ff57422ab95cc0a9303091 (patch)
tree534aab9a8b4bf1df626109a1af40f2adddd64cc7 /sbin/dhclient/clparse.c
parent58548b5f3cc2920b93bc4718a839a6b7003b3a80 (diff)
Simplify '-i' handling, failing immediately during command line parsing
when an invalid option name is encountered.
Diffstat (limited to 'sbin/dhclient/clparse.c')
-rw-r--r--sbin/dhclient/clparse.c59
1 files changed, 16 insertions, 43 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;
}
}