Take reyk's imsg resolv.conf improvements of a while ago to their
authorkrw <krw@openbsd.org>
Fri, 23 Jun 2017 15:40:56 +0000 (15:40 +0000)
committerkrw <krw@openbsd.org>
Fri, 23 Jun 2017 15:40:56 +0000 (15:40 +0000)
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.

sbin/dhclient/dhcpd.h
sbin/dhclient/kroute.c
sbin/dhclient/privsep.c
sbin/dhclient/privsep.h

index 2e4d70f..a3d279f 100644 (file)
@@ -1,4 +1,4 @@
-/*     $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>
@@ -157,7 +157,6 @@ struct interface_info {
        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"
 
index 5ac34c3..878496f 100644 (file)
@@ -1,4 +1,4 @@
-/*     $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>
@@ -782,39 +782,29 @@ write_resolv_conf(u_int8_t *contents, size_t sz)
 }
 
 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);
 }
index 64898a8..23e4ae9 100644 (file)
@@ -1,4 +1,4 @@
-/*     $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>
@@ -90,7 +90,12 @@ dispatch_imsg(struct interface_info *ifi, struct imsgbuf *ibuf)
                        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:
index ab94db6..3d36763 100644 (file)
@@ -1,4 +1,4 @@
-/*     $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>
@@ -69,7 +69,7 @@ void  priv_flush_routes(struct interface_info *, struct imsg_flush_routes *);
 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 *);