summaryrefslogtreecommitdiff
path: root/sbin/dhclient
diff options
context:
space:
mode:
authorKenneth R Westerback <krw@cvs.openbsd.org>2012-12-05 03:14:11 +0000
committerKenneth R Westerback <krw@cvs.openbsd.org>2012-12-05 03:14:11 +0000
commit6e57813ee7a1ca1d21886bbb5a62d85f4f74ca32 (patch)
treec11b5f2e88c49f9714c434978ae09282b7944751 /sbin/dhclient
parenta3685c5a2705d2d4b5490b02433fdc2d3a03b1fc (diff)
If there is no domain-name and no domain-name-servers provided in
the lease (or if they are 'ignore'd in dhclient.conf), and there is no resolv,conf.tail then do not remove any existing resolv.conf. Restores the behaviour ajacoutot@ expected and todd@ thinks makes sense.
Diffstat (limited to 'sbin/dhclient')
-rw-r--r--sbin/dhclient/dhclient.c67
1 files changed, 33 insertions, 34 deletions
diff --git a/sbin/dhclient/dhclient.c b/sbin/dhclient/dhclient.c
index 14f46b91d79..87ee4fa9746 100644
--- a/sbin/dhclient/dhclient.c
+++ b/sbin/dhclient/dhclient.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: dhclient.c,v 1.188 2012/12/04 19:24:02 krw Exp $ */
+/* $OpenBSD: dhclient.c,v 1.189 2012/12/05 03:14:10 krw Exp $ */
/*
* Copyright 2004 Henning Brauer <henning@openbsd.org>
@@ -1867,14 +1867,36 @@ priv_resolv_conf(struct imsg_resolv_conf *imsg)
int conffd, tailfd, tailn;
char *buf;
+ tailn = 0;
+ buf = calloc(1, MAXRESOLVCONFSIZE);
+
+ tailfd = open("/etc/resolv.conf.tail", O_RDONLY);
+
+ if (tailfd != -1) {
+ tailn = read(tailfd, buf, MAXRESOLVCONFSIZE - 1);
+ close(tailfd);
+ if (tailn == -1)
+ note("Couldn't read resolv.conf.tail: %s",
+ strerror(errno));
+ else if (tailn == 0)
+ note("Got no data from resolv.conf.tail");
+ }
+
+ if (strlen(imsg->contents) == 0 && tailn < 1) {
+ free(buf);
+ return;
+ }
+
conffd = open("/etc/resolv.conf",
O_WRONLY | O_CREAT | O_TRUNC | O_SYNC | O_EXLOCK,
S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
if (conffd == -1) {
note("Couldn't open resolv.conf: %s", strerror(errno));
+ free(buf);
return;
}
+ n = 0;
if (strlen(imsg->contents)) {
n = write(conffd, imsg->contents, strlen(imsg->contents));
if (n == -1)
@@ -1887,45 +1909,22 @@ priv_resolv_conf(struct imsg_resolv_conf *imsg)
n, strlen(imsg->contents));
}
- tailfd = open("/etc/resolv.conf.tail", O_RDONLY);
-
- n = tailn = 0;
- buf = calloc(1, MAXRESOLVCONFSIZE);
-
- if (tailfd == -1)
- note("Couldn't open resolv.conf.tail: %s", strerror(errno));
- else {
- tailn = read(tailfd, buf, MAXRESOLVCONFSIZE - 1);
- close(tailfd);
- if (tailn == -1)
- note("Couldn't read resolv.conf.tail: %s",
+ if (tailn > 0) {
+ n = write(conffd, buf, strlen(buf));
+ if (n == -1)
+ note("Couldn't write tail to resolv.conf: %s",
strerror(errno));
- else if (tailn == 0)
- note("Got no data from resolv.conf.tail");
- else {
- n = write(conffd, buf, strlen(buf));
- if (n == -1)
- note("Couldn't write tail to resolv.conf: %s",
- strerror(errno));
- else if (n == 0)
- note("Couldn't write tail to resolv.conf");
- else if (n < strlen(buf))
- note("Short tail write to resolv.conf "
- "(%zd vs %zd)", n, strlen(buf));
- }
- free(buf);
- }
-
- if ((strlen(imsg->contents) == 0) && (tailn < 1 || n < 1)) {
- note("No contents for resolv.conf");
- unlink("/etc/resolv.conf");
- close(conffd);
- return;
+ else if (n == 0)
+ note("Couldn't write tail to resolv.conf");
+ else if (n < strlen(buf))
+ note("Short tail write to resolv.conf "
+ "(%zd vs %zd)", n, strlen(buf));
}
fchmod(conffd, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
fchown(conffd, 0, 0); /* root:wheel */
+ free(buf);
close(conffd);
}