-/* $OpenBSD: dhclient.c,v 1.412 2017/04/10 21:47:44 krw Exp $ */
+/* $OpenBSD: dhclient.c,v 1.413 2017/04/11 10:40:14 krw Exp $ */
/*
* Copyright 2004 Henning Brauer <henning@openbsd.org>
memcpy(config->ignored_options, list, sizeof(config->ignored_options));
}
-void
-priv_write_file(char *path, int flags, mode_t mode,
- u_int8_t *contents, size_t sz)
-{
- ssize_t n;
- int fd;
-
- fd = open(path, flags, mode);
- if (fd == -1) {
- 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);
- else if ((size_t)n < sz)
- log_warnx("Short contents write to '%s' (%zd vs %zu)", path,
- n, sz);
-
- if (fchown(fd, 0, 0) == -1)
- log_warn("fchown(fd, %d, %d) of '%s' failed", 0, 0, path);
- if (fchmod(fd, mode) == -1)
- log_warn("fchmod(fd, 0x%x) of '%s' failed", mode, path);
-
- close(fd);
-}
-
void
set_lease_times(struct client_lease *lease)
{
flush_unpriv_ibuf("write_resolv_conf");
}
-void
-priv_write_resolv_conf(struct interface_info *ifi, struct imsg *imsg)
-{
- u_int8_t *contents;
- size_t sz;
-
- 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;
-
- priv_write_file("/etc/resolv.conf",
- O_WRONLY | O_CREAT | O_TRUNC,
- S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH, contents, sz);
-}
-
/*
* add_direct_route is the equivalent of
*
-/* $OpenBSD: kroute.c,v 1.88 2017/04/09 20:44:13 krw Exp $ */
+/* $OpenBSD: kroute.c,v 1.89 2017/04/11 10:40:14 krw Exp $ */
/*
* Copyright 2012 Kenneth R Westerback <krw@openbsd.org>
#include <sys/ioctl.h>
#include <sys/socket.h>
+#include <sys/stat.h>
#include <sys/sysctl.h>
#include <arpa/inet.h>
#include <netinet/if_ether.h>
#include <errno.h>
+#include <fcntl.h>
#include <ifaddrs.h>
#include <imsg.h>
#include <limits.h>
priv_delete_address(ifi, &dimsg);
}
+/*
+ * priv_write_resolv_conf writes out a new resolv.conf.
+ */
+void
+priv_write_resolv_conf(struct interface_info *ifi, struct imsg *imsg)
+{
+ u_int8_t *contents;
+ 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,
+ S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
+
+ if (fd == -1) {
+ log_warn("Couldn't open '%s'", _PATH_RESOLV_CONF);
+ return;
+ }
+
+ n = write(fd, contents, sz);
+ if (n == -1)
+ log_warn("Couldn't write contents to '%s'", _PATH_RESOLV_CONF);
+ else if ((size_t)n < sz)
+ log_warnx("Short contents write to '%s' (%zd vs %zu)",
+ _PATH_RESOLV_CONF, n, sz);
+
+ close(fd);
+}
+
int
resolv_conf_priority(struct interface_info *ifi)
{