summaryrefslogtreecommitdiff
path: root/sbin/dhclient
diff options
context:
space:
mode:
authorKenneth R Westerback <krw@cvs.openbsd.org>2017-08-18 15:06:12 +0000
committerKenneth R Westerback <krw@cvs.openbsd.org>2017-08-18 15:06:12 +0000
commit93eb9b99060f7b29e84faaf51177e3ac690052aa (patch)
treee4670d3de073747e384fa47102c984b9f3e5d56f /sbin/dhclient
parent96e01a0efb268766622560f66597f30ce09e9801 (diff)
Truncating a file and then deciding not to change its
contents doesn't do what you think it does. Restore "no dns servers, no search, means don't touch resolv.conf" behaviour unintentionally changed at t2k17. Noticed by ajacoutot@ during an upgrade using a non-OpenBSD dhcpd server that only provides the options it is asked for.
Diffstat (limited to 'sbin/dhclient')
-rw-r--r--sbin/dhclient/kroute.c25
1 files changed, 14 insertions, 11 deletions
diff --git a/sbin/dhclient/kroute.c b/sbin/dhclient/kroute.c
index 6db356bf9ef..d9d6b16b871 100644
--- a/sbin/dhclient/kroute.c
+++ b/sbin/dhclient/kroute.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kroute.c,v 1.138 2017/08/14 22:12:59 krw Exp $ */
+/* $OpenBSD: kroute.c,v 1.139 2017/08/18 15:06:11 krw Exp $ */
/*
* Copyright 2012 Kenneth R Westerback <krw@openbsd.org>
@@ -553,6 +553,9 @@ priv_write_resolv_conf(char *contents)
size_t sz;
int fd;
+ if (contents == NULL)
+ return;
+
fd = open(path, O_WRONLY | O_CREAT | O_TRUNC,
S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
@@ -561,15 +564,13 @@ priv_write_resolv_conf(char *contents)
return;
}
- if (contents != NULL) {
- sz = strlen(contents);
- 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);
- }
+ sz = strlen(contents);
+ 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);
close(fd);
}
@@ -704,7 +705,8 @@ set_resolv_conf(char *name, uint8_t *rtsearch, unsigned int rtsearch_len,
if (len == 0) {
free(dn);
- return;
+ contents = NULL;
+ goto done;
}
rslt = asprintf(&courtesy, "# Generated by %s dhclient\n", name);
@@ -733,6 +735,7 @@ set_resolv_conf(char *name, uint8_t *rtsearch, unsigned int rtsearch_len,
if (config->resolv_tail != NULL)
strlcat(contents, config->resolv_tail, len);
+done:
rslt = imsg_compose(unpriv_ibuf, IMSG_SET_RESOLV_CONF,
0, 0, -1, contents, len);
if (rslt == -1)