summaryrefslogtreecommitdiff
path: root/sbin/dhclient/dhclient.c
diff options
context:
space:
mode:
authorKenneth R Westerback <krw@cvs.openbsd.org>2012-11-03 16:54:35 +0000
committerKenneth R Westerback <krw@cvs.openbsd.org>2012-11-03 16:54:35 +0000
commit8be1b4dc0f7cc07181a7f15d8063b4e4da0e2140 (patch)
tree819369e068897e4d1e4167e570cdfa14380533be /sbin/dhclient/dhclient.c
parentd1f0e7f499f9bb09f80d592f5db982c9d01baa55 (diff)
Various fixes/tweaks for resolv.conf handling:
1) Don't leak a file descriptor if there are no contents for resolv.conf. 2) Allow for only resolv.conf.tail to go into resolv.conf. 3) Don't need to pass around interface name when creating resolv.conf. 4) Don't leave 0 length resolv.conf lying around if there are no contents.
Diffstat (limited to 'sbin/dhclient/dhclient.c')
-rw-r--r--sbin/dhclient/dhclient.c33
1 files changed, 16 insertions, 17 deletions
diff --git a/sbin/dhclient/dhclient.c b/sbin/dhclient/dhclient.c
index 6a0e2d349ba..d9678b79579 100644
--- a/sbin/dhclient/dhclient.c
+++ b/sbin/dhclient/dhclient.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: dhclient.c,v 1.163 2012/11/02 17:29:37 krw Exp $ */
+/* $OpenBSD: dhclient.c,v 1.164 2012/11/03 16:54:34 krw Exp $ */
/*
* Copyright 2004 Henning Brauer <henning@openbsd.org>
@@ -1813,16 +1813,11 @@ new_resolv_conf(char *ifname, char *domainname, char *nameservers)
hdr.code = IMSG_NEW_RESOLV_CONF;
hdr.len = sizeof(hdr) +
- sizeof(len) + strlen(ifname) +
sizeof(len) + strlen(contents);
buf = buf_open(hdr.len);
buf_add(buf, &hdr, sizeof(hdr));
- len = strlen(ifname);
- buf_add(buf, &len, sizeof(len));
- buf_add(buf, ifname, len);
-
len = strlen(contents);
buf_add(buf, &len, sizeof(len));
buf_add(buf, contents, len);
@@ -1833,7 +1828,7 @@ new_resolv_conf(char *ifname, char *domainname, char *nameservers)
}
void
-priv_new_resolv_conf(char *ifname, char *contents)
+priv_new_resolv_conf(char *contents)
{
ssize_t n;
int conffd, tailfd, tailn;
@@ -1847,18 +1842,20 @@ priv_new_resolv_conf(char *ifname, char *contents)
return;
}
- n = write(conffd, contents, strlen(contents));
- if (n == -1)
- note("Couldn't write contents to resolv.conf: %m");
- else if (n == 0)
- note("Couldn't write contents to resolv.conf");
- else if (n < strlen(contents))
- note("Short contents write to resolv.conf (%zd vs %zd)", n,
- strlen(contents));
+ if (contents) {
+ n = write(conffd, contents, strlen(contents));
+ if (n == -1)
+ note("Couldn't write contents to resolv.conf: %m");
+ else if (n == 0)
+ note("Couldn't write contents to resolv.conf");
+ else if (n < strlen(contents))
+ note("Short contents write to resolv.conf (%zd vs %zd)",
+ n, strlen(contents));
+ }
tailfd = open("/etc/resolv.conf.tail", O_RDONLY);
- tailn = 0;
+ n = tailn = 0;
buf = calloc(1, MAXRESOLVCONFSIZE);
if (tailfd == -1)
@@ -1883,8 +1880,10 @@ priv_new_resolv_conf(char *ifname, char *contents)
free(buf);
}
- if (strlen(contents) == 0 && tailn == 0) {
+ if ((!contents || strlen(contents) == 0) && (tailn < 1 || n < 1)) {
note("No contents for resolv.conf");
+ unlink("/etc/resolv.conf");
+ close(conffd);
return;
}