summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--sbin/dhclient/clparse.c41
-rw-r--r--sbin/dhclient/dhclient.c29
-rw-r--r--sbin/dhclient/dhcpd.h3
3 files changed, 45 insertions, 28 deletions
diff --git a/sbin/dhclient/clparse.c b/sbin/dhclient/clparse.c
index 3ff86a81f09..9490d47e579 100644
--- a/sbin/dhclient/clparse.c
+++ b/sbin/dhclient/clparse.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: clparse.c,v 1.171 2019/01/13 21:55:32 krw Exp $ */
+/* $OpenBSD: clparse.c,v 1.172 2019/01/13 23:15:31 krw Exp $ */
/* Parser for dhclient config and lease files. */
@@ -42,6 +42,7 @@
#include <sys/queue.h>
#include <sys/socket.h>
+#include <sys/stat.h>
#include <sys/types.h>
#include <net/if.h>
@@ -52,6 +53,7 @@
#include <err.h>
#include <errno.h>
+#include <fcntl.h>
#include <limits.h>
#include <signal.h>
#include <stdio.h>
@@ -935,3 +937,40 @@ set_default_hostname(void)
opt->len = strlen(opt->data);
}
}
+
+void
+read_resolv_conf_tail(void)
+{
+ struct stat sb;
+ const char *tail_path = "/etc/resolv.conf.tail";
+ ssize_t tailn;
+ int tailfd;
+
+ if (config->resolv_tail != NULL) {
+ free(config->resolv_tail);
+ config->resolv_tail = NULL;
+ }
+
+ tailfd = open(tail_path, O_RDONLY);
+ if (tailfd == -1) {
+ if (errno != ENOENT)
+ fatal("open(%s)", tail_path);
+ } else if (fstat(tailfd, &sb) == -1) {
+ fatal("fstat(%s)", tail_path);
+ } else {
+ if (sb.st_size > 0 && sb.st_size < LLONG_MAX) {
+ config->resolv_tail = calloc(1, sb.st_size + 1);
+ if (config->resolv_tail == NULL) {
+ fatal("%s contents", tail_path);
+ }
+ tailn = read(tailfd, config->resolv_tail, sb.st_size);
+ if (tailn == -1)
+ fatal("read(%s)", tail_path);
+ else if (tailn == 0)
+ fatalx("got no data from %s", tail_path);
+ else if (tailn != sb.st_size)
+ fatalx("short read of %s", tail_path);
+ }
+ close(tailfd);
+ }
+}
diff --git a/sbin/dhclient/dhclient.c b/sbin/dhclient/dhclient.c
index f65ef6932f8..d1514b66a13 100644
--- a/sbin/dhclient/dhclient.c
+++ b/sbin/dhclient/dhclient.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: dhclient.c,v 1.602 2019/01/13 18:45:21 krw Exp $ */
+/* $OpenBSD: dhclient.c,v 1.603 2019/01/13 23:15:31 krw Exp $ */
/*
* Copyright 2004 Henning Brauer <henning@openbsd.org>
@@ -451,15 +451,13 @@ main(int argc, char *argv[])
struct ieee80211_nwid nwid;
struct ifreq ifr;
struct stat sb;
- const char *tail_path = "/etc/resolv.conf.tail";
struct interface_info *ifi;
struct passwd *pw;
char *ignore_list = NULL;
unsigned char *newp;
- ssize_t tailn;
size_t newsize;
int fd, socket_fd[2];
- int rtfilter, ioctlfd, routefd, tailfd;
+ int rtfilter, ioctlfd, routefd;
int ch;
saved_argv = argv;
@@ -606,28 +604,7 @@ main(int argc, char *argv[])
if (ignore_list != NULL)
apply_ignore_list(ignore_list);
- tailfd = open(tail_path, O_RDONLY);
- if (tailfd == -1) {
- if (errno != ENOENT)
- fatal("open(%s)", tail_path);
- } else if (fstat(tailfd, &sb) == -1) {
- fatal("fstat(%s)", tail_path);
- } else {
- if (sb.st_size > 0 && sb.st_size < LLONG_MAX) {
- config->resolv_tail = calloc(1, sb.st_size + 1);
- if (config->resolv_tail == NULL) {
- fatal("%s contents", tail_path);
- }
- tailn = read(tailfd, config->resolv_tail, sb.st_size);
- if (tailn == -1)
- fatal("read(%s)", tail_path);
- else if (tailn == 0)
- fatalx("got no data from %s", tail_path);
- else if (tailn != sb.st_size)
- fatalx("short read of %s", tail_path);
- }
- close(tailfd);
- }
+ read_resolv_conf_tail();
interface_state(ifi);
if (!LINK_STATE_IS_UP(ifi->link_state))
diff --git a/sbin/dhclient/dhcpd.h b/sbin/dhclient/dhcpd.h
index 1532e68da77..8c07175a3f5 100644
--- a/sbin/dhclient/dhcpd.h
+++ b/sbin/dhclient/dhcpd.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: dhcpd.h,v 1.264 2019/01/13 18:45:21 krw Exp $ */
+/* $OpenBSD: dhcpd.h,v 1.265 2019/01/13 23:15:31 krw Exp $ */
/*
* Copyright (c) 2004 Henning Brauer <henning@openbsd.org>
@@ -238,6 +238,7 @@ void read_lease_db(char *, struct client_lease_tq *);
void apply_ignore_list(char *);
void set_default_client_identifier(struct interface_info *);
void set_default_hostname(void);
+void read_resolv_conf_tail(void);
/* kroute.c */
unsigned int extract_classless_route(uint8_t *, unsigned int,