From a22936e4b3a7a9bc6eca434f8be3ef6dfd06d35d Mon Sep 17 00:00:00 2001 From: Roy Marples Date: Tue, 30 Aug 2022 15:52:21 +0100 Subject: [PATCH] Fix prior for Linux. --- src/if-linux.c | 10 ++++++++++ src/privsep-linux.c | 4 ++-- src/privsep-root.c | 11 +++-------- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/src/if-linux.c b/src/if-linux.c index 655750a2..e4a16044 100644 --- a/src/if-linux.c +++ b/src/if-linux.c @@ -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; diff --git a/src/privsep-linux.c b/src/privsep-linux.c index 68f78297..d4439634 100644 --- a/src/privsep-linux.c +++ b/src/privsep-linux.c @@ -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); } diff --git a/src/privsep-root.c b/src/privsep-root.c index 7bf2e068..a8290a40 100644 --- a/src/privsep-root.c +++ b/src/privsep-root.c @@ -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; } -- 2.47.2