logical conclusion.
Nuke _PATH_RESOLV_CONF since the value is only meant to be
known inside priv_write_resolv_conf(). Just use a local const char *.
Bring priv_write_resolv_conf() into line with other priv_ functions
invoked from the dispatch loop. i.e. don't pass it the imsg, just pass
a pointer to the data and a size after ensuring there is data to pass.
-/* $OpenBSD: dhcpd.h,v 1.191 2017/06/22 15:08:53 krw Exp $ */
+/* $OpenBSD: dhcpd.h,v 1.192 2017/06/23 15:40:56 krw Exp $ */
/*
* Copyright (c) 2004 Henning Brauer <henning@openbsd.org>
TAILQ_HEAD(_leases, client_lease) leases;
};
-#define _PATH_RESOLV_CONF "/etc/resolv.conf"
#define _PATH_DHCLIENT_CONF "/etc/dhclient.conf"
#define _PATH_DHCLIENT_DB "/var/db/dhclient.leases"
-/* $OpenBSD: kroute.c,v 1.91 2017/04/12 12:22:25 krw Exp $ */
+/* $OpenBSD: kroute.c,v 1.92 2017/06/23 15:40:56 krw Exp $ */
/*
* Copyright 2012 Kenneth R Westerback <krw@openbsd.org>
}
void
-priv_write_resolv_conf(struct interface_info *ifi, struct imsg *imsg)
+priv_write_resolv_conf(struct interface_info *ifi, u_int8_t *contents, size_t sz)
{
- u_int8_t *contents;
+ const char *path = "/etc/resolv.conf";
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,
+ fd = open(path, 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);
+ 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_RESOLV_CONF);
+ 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_RESOLV_CONF, n, sz);
+ path, n, sz);
close(fd);
}
-/* $OpenBSD: privsep.c,v 1.46 2017/04/10 21:47:44 krw Exp $ */
+/* $OpenBSD: privsep.c,v 1.47 2017/06/23 15:40:56 krw Exp $ */
/*
* Copyright (c) 2004 Henning Brauer <henning@openbsd.org>
break;
case IMSG_WRITE_RESOLV_CONF:
- priv_write_resolv_conf(ifi, &imsg);
+ if (imsg.hdr.len <= IMSG_HEADER_SIZE) {
+ log_warnx("short IMSG_WRITE_RESOLV_CONF");
+ return;
+ } else
+ priv_write_resolv_conf(ifi, imsg.data,
+ imsg.hdr.len - IMSG_HEADER_SIZE);
break;
case IMSG_HUP:
-/* $OpenBSD: privsep.h,v 1.35 2017/04/11 13:59:27 krw Exp $ */
+/* $OpenBSD: privsep.h,v 1.36 2017/06/23 15:40:56 krw Exp $ */
/*
* Copyright (c) 2004 Henning Brauer <henning@openbsd.org>
char *resolv_conf_contents(struct interface_info *ifi, struct option_data *,
struct option_data *, struct option_data *);
void write_resolv_conf(u_int8_t *, size_t);
-void priv_write_resolv_conf(struct interface_info *, struct imsg *);
+void priv_write_resolv_conf(struct interface_info *, u_int8_t *, size_t);
void priv_delete_address(struct interface_info *,
struct imsg_delete_address *);