]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
Fix prior for Linux.
authorRoy Marples <roy@marples.name>
Tue, 30 Aug 2022 14:52:21 +0000 (15:52 +0100)
committerRoy Marples <roy@marples.name>
Tue, 30 Aug 2022 14:52:21 +0000 (15:52 +0100)
src/if-linux.c
src/privsep-linux.c
src/privsep-root.c

index 655750a2d216379293e4711216bbdb34a9e2d22a..e4a16044a8dd50d38cafed7e6b7efe155edb4419 100644 (file)
@@ -439,6 +439,13 @@ if_opensockets_os(struct dhcpcd_ctx *ctx)
        int on = 1;
 #endif
 
+#ifdef PRIVSEP
+       if (ctx->options & DHCPCD_PRIVSEPROOT) {
+               ctx->link_fd = -1;
+               goto setup_priv;
+       }
+#endif
+
        /* Open the link socket first so it gets pid() for the socket.
         * Then open our persistent route socket so we get a unique
         * pid that doesn't clash with a process id for after we fork. */
@@ -461,6 +468,9 @@ if_opensockets_os(struct dhcpcd_ctx *ctx)
                logerr("%s: NETLINK_BROADCAST_ERROR", __func__);
 #endif
 
+#ifdef PRIVSEP
+setup_priv:
+#endif
        if ((priv = calloc(1, sizeof(*priv))) == NULL)
                return -1;
 
index 68f782976bab89c67b9b9b3f074faa6ecfaf9146..d4439634131d6032304034e5d2de48f0b7974e70 100644 (file)
@@ -72,7 +72,7 @@ ps_root_dosendnetlink(struct dhcpcd_ctx *ctx, int protocol, struct msghdr *msg)
 
        switch(protocol) {
        case NETLINK_GENERIC:
-               s = priv->netlink_fd;
+               s = priv->generic_fd;
                break;
        case NETLINK_ROUTE:
                s = priv->route_fd;
@@ -83,7 +83,7 @@ ps_root_dosendnetlink(struct dhcpcd_ctx *ctx, int protocol, struct msghdr *msg)
        }
 
        if (sendmsg(s, msg, 0) == -1)
-               return =-1;
+               return -1;
 
        return if_getnetlink(NULL, &riov, s, 0, NULL, NULL);
 }
index 7bf2e06822e7c12a3aa64632a36854d25415b808..a8290a4063befc2d2ad62a670e4dd01bd87806ff 100644 (file)
@@ -669,8 +669,8 @@ ps_root_startcb(struct ps_process *psp)
 
        if (if_opensockets(ctx) == -1)
                logerr("%s: if_opensockets", __func__);
-       else {
 #ifdef BSD
+       else {
                /* We only want to write to this socket, so set
                 * a small as possible buffer size. */
                socklen_t smallbuf = 1;
@@ -678,14 +678,8 @@ ps_root_startcb(struct ps_process *psp)
                if (setsockopt(ctx->link_fd, SOL_SOCKET, SO_RCVBUF,
                    &smallbuf, (socklen_t)sizeof(smallbuf)) == -1)
                        logerr("%s: setsockopt(SO_RCVBUF)", __func__);
-#endif
-#ifdef __linux__
-               /* See if_opensockets_os as to why we close link_fd
-                * rather than not open it. */
-               close(ctx->link_fd);
-               ctx->link_fd = -1;
-#endif
        }
+#endif
 
        /* Open network sockets for sending.
         * This is a small bit wasteful for non sandboxed OS's
@@ -740,6 +734,7 @@ ps_root_startcb(struct ps_process *psp)
            (DHCPCD_MANAGER | DHCPCD_DEV))
                dev_start(ctx, ps_root_handleinterface);
 #endif
+
        return 0;
 }