diff options
Diffstat (limited to 'sbin')
-rw-r--r-- | sbin/dhclient/dhclient.c | 52 | ||||
-rw-r--r-- | sbin/dhclient/dhcpd.h | 3 | ||||
-rw-r--r-- | sbin/dhclient/kroute.c | 45 |
3 files changed, 47 insertions, 53 deletions
diff --git a/sbin/dhclient/dhclient.c b/sbin/dhclient/dhclient.c index a2189c2f66d..beda16591f4 100644 --- a/sbin/dhclient/dhclient.c +++ b/sbin/dhclient/dhclient.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dhclient.c,v 1.412 2017/04/10 21:47:44 krw Exp $ */ +/* $OpenBSD: dhclient.c,v 1.413 2017/04/11 10:40:14 krw Exp $ */ /* * Copyright 2004 Henning Brauer <henning@openbsd.org> @@ -2548,34 +2548,6 @@ apply_ignore_list(char *ignore_list) } void -priv_write_file(char *path, int flags, mode_t mode, - u_int8_t *contents, size_t sz) -{ - ssize_t n; - int fd; - - fd = open(path, flags, mode); - if (fd == -1) { - log_warn("Couldn't open '%s'", path); - return; - } - - n = write(fd, contents, sz); - if (n == -1) - log_warn("Couldn't write contents to '%s'", path); - else if ((size_t)n < sz) - log_warnx("Short contents write to '%s' (%zd vs %zu)", path, - n, sz); - - if (fchown(fd, 0, 0) == -1) - log_warn("fchown(fd, %d, %d) of '%s' failed", 0, 0, path); - if (fchmod(fd, mode) == -1) - log_warn("fchmod(fd, 0x%x) of '%s' failed", mode, path); - - close(fd); -} - -void set_lease_times(struct client_lease *lease) { time_t cur_time, time_max; @@ -2742,28 +2714,6 @@ write_resolv_conf(u_int8_t *contents, size_t sz) flush_unpriv_ibuf("write_resolv_conf"); } -void -priv_write_resolv_conf(struct interface_info *ifi, struct imsg *imsg) -{ - u_int8_t *contents; - size_t sz; - - if (imsg->hdr.len < IMSG_HEADER_SIZE) { - log_warnx("short IMSG_WRITE_RESOLV_CONF"); - return; - } - - if (!resolv_conf_priority(ifi)) - return; - - contents = imsg->data; - sz = imsg->hdr.len - IMSG_HEADER_SIZE; - - priv_write_file("/etc/resolv.conf", - O_WRONLY | O_CREAT | O_TRUNC, - S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH, contents, sz); -} - /* * add_direct_route is the equivalent of * diff --git a/sbin/dhclient/dhcpd.h b/sbin/dhclient/dhcpd.h index 9f905209af5..ea88b3dfdc0 100644 --- a/sbin/dhclient/dhcpd.h +++ b/sbin/dhclient/dhcpd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: dhcpd.h,v 1.169 2017/04/08 20:16:04 krw Exp $ */ +/* $OpenBSD: dhcpd.h,v 1.170 2017/04/11 10:40:14 krw Exp $ */ /* * Copyright (c) 2004 Henning Brauer <henning@openbsd.org> @@ -172,6 +172,7 @@ struct dhcp_timeout { void *arg; }; +#define _PATH_RESOLV_CONF "/etc/resolv.conf" #define _PATH_DHCLIENT_CONF "/etc/dhclient.conf" #define _PATH_DHCLIENT_DB "/var/db/dhclient.leases" diff --git a/sbin/dhclient/kroute.c b/sbin/dhclient/kroute.c index 5686aea5a99..543f26b9f2d 100644 --- a/sbin/dhclient/kroute.c +++ b/sbin/dhclient/kroute.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kroute.c,v 1.88 2017/04/09 20:44:13 krw Exp $ */ +/* $OpenBSD: kroute.c,v 1.89 2017/04/11 10:40:14 krw Exp $ */ /* * Copyright 2012 Kenneth R Westerback <krw@openbsd.org> @@ -18,6 +18,7 @@ #include <sys/ioctl.h> #include <sys/socket.h> +#include <sys/stat.h> #include <sys/sysctl.h> #include <arpa/inet.h> @@ -30,6 +31,7 @@ #include <netinet/if_ether.h> #include <errno.h> +#include <fcntl.h> #include <ifaddrs.h> #include <imsg.h> #include <limits.h> @@ -531,6 +533,47 @@ priv_cleanup(struct interface_info *ifi, struct imsg_hup *imsg) priv_delete_address(ifi, &dimsg); } +/* + * priv_write_resolv_conf writes out a new resolv.conf. + */ +void +priv_write_resolv_conf(struct interface_info *ifi, struct imsg *imsg) +{ + u_int8_t *contents; + ssize_t n; + size_t sz; + int fd; + + + if (imsg->hdr.len < IMSG_HEADER_SIZE) { + log_warnx("short IMSG_WRITE_RESOLV_CONF"); + return; + } + + if (!resolv_conf_priority(ifi)) + return; + + contents = imsg->data; + sz = imsg->hdr.len - IMSG_HEADER_SIZE; + + fd = open(_PATH_RESOLV_CONF, O_WRONLY | O_CREAT | O_TRUNC, + S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); + + if (fd == -1) { + log_warn("Couldn't open '%s'", _PATH_RESOLV_CONF); + return; + } + + n = write(fd, contents, sz); + if (n == -1) + log_warn("Couldn't write contents to '%s'", _PATH_RESOLV_CONF); + else if ((size_t)n < sz) + log_warnx("Short contents write to '%s' (%zd vs %zu)", + _PATH_RESOLV_CONF, n, sz); + + close(fd); +} + int resolv_conf_priority(struct interface_info *ifi) { |