diff options
-rw-r--r-- | sbin/dhclient/dhclient.c | 43 | ||||
-rw-r--r-- | sbin/dhclient/dhcpd.h | 13 |
2 files changed, 43 insertions, 13 deletions
diff --git a/sbin/dhclient/dhclient.c b/sbin/dhclient/dhclient.c index aa7ad892ed7..51ad92f7c1b 100644 --- a/sbin/dhclient/dhclient.c +++ b/sbin/dhclient/dhclient.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dhclient.c,v 1.656 2020/01/20 21:21:20 krw Exp $ */ +/* $OpenBSD: dhclient.c,v 1.657 2020/01/23 22:39:35 krw Exp $ */ /* * Copyright 2004 Henning Brauer <henning@openbsd.org> @@ -474,23 +474,25 @@ main(int argc, char *argv[]) while ((ch = getopt(argc, argv, "c:di:L:nrv")) != -1) switch (ch) { case 'c': + if (optarg == NULL) + usage(); + cmd_opts |= OPT_CONFPATH; path_dhclient_conf = optarg; break; case 'd': cmd_opts |= OPT_FOREGROUND; break; case 'i': + if (optarg == NULL) + usage(); + cmd_opts |= OPT_IGNORELIST; ignore_list = strdup(optarg); - if (ignore_list == NULL) - fatal("ignore_list"); break; case 'L': + if (optarg == NULL) + usage(); + cmd_opts |= OPT_DBPATH; path_option_db = optarg; - if (lstat(path_option_db, &sb) != -1) { - if (S_ISREG(sb.st_mode) == 0) - fatalx("'%s' is not a regular file", - path_option_db); - } break; case 'n': cmd_opts |= OPT_NOACTION; @@ -511,6 +513,31 @@ main(int argc, char *argv[]) if (argc != 1) usage(); + if ((cmd_opts & OPT_DBPATH) != 0) { + if (lstat(path_option_db, &sb) == -1) { + /* + * Non-existant file is OK. An attempt will be + * made to create it. + */ + if (errno != ENOENT) + fatal("lstat(%s)", path_option_db); + } else if (S_ISREG(sb.st_mode) == 0) + fatalx("'%s' is not a regular file", + path_option_db); + } + if ((cmd_opts & OPT_CONFPATH) != 0) { + if (lstat(path_dhclient_conf, &sb) == -1) { + /* + * Non-existant file is OK. It lets you ignore + * /etc/dhclient.conf for testing. + */ + if (errno != ENOENT) + fatal("lstat(%s)", path_dhclient_conf); + } else if (S_ISREG(sb.st_mode) == 0) + fatalx("'%s' is not a regular file", + path_dhclient_conf); + } + if ((cmd_opts & (OPT_FOREGROUND | OPT_NOACTION)) != 0) cmd_opts |= OPT_VERBOSE; diff --git a/sbin/dhclient/dhcpd.h b/sbin/dhclient/dhcpd.h index b8d6c852bce..d98b12de0c3 100644 --- a/sbin/dhclient/dhcpd.h +++ b/sbin/dhclient/dhcpd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: dhcpd.h,v 1.284 2019/11/22 22:45:52 krw Exp $ */ +/* $OpenBSD: dhcpd.h,v 1.285 2020/01/23 22:39:35 krw Exp $ */ /* * Copyright (c) 2004 Henning Brauer <henning@openbsd.org> @@ -211,10 +211,13 @@ extern struct client_config *config; extern struct imsgbuf *unpriv_ibuf; extern int quit; extern int cmd_opts; -#define OPT_NOACTION 1 -#define OPT_VERBOSE 2 -#define OPT_FOREGROUND 4 -#define OPT_RELEASE 8 +#define OPT_NOACTION 0x01 +#define OPT_VERBOSE 0x02 +#define OPT_FOREGROUND 0x04 +#define OPT_RELEASE 0x08 +#define OPT_CONFPATH 0x10 +#define OPT_DBPATH 0x20 +#define OPT_IGNORELIST 0x40 void dhcpoffer(struct interface_info *, struct option_data *, const char *); |