summaryrefslogtreecommitdiff
path: root/sbin/dhclient/kroute.c
diff options
context:
space:
mode:
Diffstat (limited to 'sbin/dhclient/kroute.c')
-rw-r--r--sbin/dhclient/kroute.c38
1 files changed, 22 insertions, 16 deletions
diff --git a/sbin/dhclient/kroute.c b/sbin/dhclient/kroute.c
index 6b737ef5b28..ef32b7a41e4 100644
--- a/sbin/dhclient/kroute.c
+++ b/sbin/dhclient/kroute.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kroute.c,v 1.135 2017/08/09 19:57:54 krw Exp $ */
+/* $OpenBSD: kroute.c,v 1.136 2017/08/10 17:15:05 krw Exp $ */
/*
* Copyright 2012 Kenneth R Westerback <krw@openbsd.org>
@@ -648,21 +648,22 @@ priv_set_address(char *name, int ioctlfd, struct imsg_set_address *imsg)
* [priv_]write_resolv_conf write out a new resolv.conf.
*/
void
-write_resolv_conf(uint8_t *contents, size_t sz)
+write_resolv_conf(void)
{
int rslt;
rslt = imsg_compose(unpriv_ibuf, IMSG_WRITE_RESOLV_CONF,
- 0, 0, -1, contents, sz);
+ 0, 0, -1, NULL, 0);
if (rslt == -1)
log_warn("write_resolv_conf: imsg_compose");
}
void
-priv_write_resolv_conf(uint8_t *contents, size_t sz)
+priv_write_resolv_conf(char *contents)
{
const char *path = "/etc/resolv.conf";
ssize_t n;
+ size_t sz;
int fd;
fd = open(path, O_WRONLY | O_CREAT | O_TRUNC,
@@ -673,12 +674,15 @@ priv_write_resolv_conf(uint8_t *contents, size_t sz)
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 (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);
+ }
close(fd);
}
@@ -760,13 +764,12 @@ done:
}
/*
- * resolv_conf_contents creates a string that are the resolv.conf contents
+ * set_resolv_conf creates a string that are the resolv.conf contents
* that should be used when the interface is determined to be the one to
* create /etc/resolv.conf
*/
-char *
-resolv_conf_contents(char *name,
- uint8_t *rtsearch, unsigned int rtsearch_len,
+void
+set_resolv_conf(char *name, uint8_t *rtsearch, unsigned int rtsearch_len,
uint8_t *rtdns, unsigned int rtdns_len)
{
char *dn, *nss[MAXNS], *contents, *courtesy;
@@ -814,7 +817,7 @@ resolv_conf_contents(char *name,
if (len == 0) {
free(dn);
- return NULL;
+ return;
}
rslt = asprintf(&courtesy, "# Generated by %s dhclient\n", name);
@@ -843,7 +846,10 @@ resolv_conf_contents(char *name,
if (config->resolv_tail != NULL)
strlcat(contents, config->resolv_tail, len);
- return contents;
+ rslt = imsg_compose(unpriv_ibuf, IMSG_SET_RESOLV_CONF,
+ 0, 0, -1, contents, len);
+ if (rslt == -1)
+ log_warn("set_resolv_conf: imsg_compose");
}
/*