]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
Fix compile on Linux
authorRoy Marples <roy@marples.name>
Sun, 5 Jul 2026 15:01:13 +0000 (16:01 +0100)
committerRoy Marples <roy@marples.name>
Sun, 5 Jul 2026 15:20:51 +0000 (16:20 +0100)
src/control.c
src/privsep-control.c
src/privsep-root.c

index 09aebc0436dc0187edae0d0419ff5e90eeedcd88..960ac4c3528239bcfd56e6f3753ab84e6dcfbccd 100644 (file)
@@ -33,6 +33,7 @@
 
 #include <errno.h>
 #include <fcntl.h>
+#include <grp.h>
 #include <pwd.h>
 #include <stdio.h>
 #include <stdlib.h>
        (sizeof(*(su)) - sizeof((su)->sun_path) + strlen((su)->sun_path))
 #endif
 
+#define SUN_MODE (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH)
+
+#define LISTEN_BACKLOG 5
+
 static void control_handle_data(void *, unsigned short);
 
 static void
@@ -94,6 +99,22 @@ control_hangup(struct fd_list *fd)
        control_free(fd);
 }
 
+#ifdef SO_PEERCRED
+static int
+getpeereid(int fd, uid_t *uid, gid_t *gid)
+{
+       struct ucred creds;
+       socklen_t creds_len = sizeof(creds);
+
+       if (getsockopt(fd, SOL_SOCKET, SO_PEERCRED, &creds, &creds_len) == -1)
+               return -1;
+
+       *uid = creds.uid;
+       *gid = creds.gid;
+       return 0;
+}
+#endif
+
 static int
 control_handle_read(struct fd_list *fd)
 {
@@ -431,8 +452,6 @@ make_sock(struct sockaddr_un *sa, const char *ifname, sa_family_t family)
        return fd;
 }
 
-#define SOCK_MODE (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH)
-
 static int
 control_start1(struct dhcpcd_ctx *ctx, const char *ifname, sa_family_t family)
 {
@@ -447,10 +466,8 @@ control_start1(struct dhcpcd_ctx *ctx, const char *ifname, sa_family_t family)
        len = (socklen_t)SUN_LEN(&sa);
        unlink(sa.sun_path);
        if (bind(fd, (struct sockaddr *)&sa, len) == -1 ||
-           chmod(sa.sun_path, 0666) == -1 ||
-           (ctx->control_group &&
-               chown(sa.sun_path, geteuid(), ctx->control_group) == -1) ||
-           listen(fd, sizeof(ctx->control_fds)) == -1)
+           chmod(sa.sun_path, SUN_MODE) == -1 ||
+           listen(fd, LISTEN_BACKLOG) == -1)
                goto err;
 
 #ifdef PRIVSEP_RIGHTS
@@ -647,7 +664,7 @@ control_user_ispriv(struct dhcpcd_ctx *ctx, uid_t uid, gid_t gid)
 
        pw = getpwuid(uid);
        if (pw == NULL)
-               return -1;
+               return 0; /* unknown user is not privileged */
 
        groups = reallocarray(groups, (size_t)ngroups, sizeof(*groups));
        if (groups == NULL)
index 8c2fa514b91a9117363af12e40c1da07876d91de..3ace3ad3027bf11247206809c3529a16d3469183 100644 (file)
@@ -38,7 +38,6 @@
 #include "privsep.h"
 
 #define PS_CTL_FD(ctx)   (ctx)->ps_ctl->psp_fd
-#define PS_CTL_FLAGS_PRIV ~(~0UL >> 1)
 
 /* We expect to have open 2 privsep STREAM, 2 STREAM and 2 file STREAM fds */
 
index 755b3b437f7a87038f609e00bdaca27e14705620..dec46b0d9b618a8d7b18202e630fe7aaf40c16f2 100644 (file)
@@ -325,7 +325,7 @@ ps_root_douser_ispriv(struct dhcpcd_ctx *ctx, void *data, size_t len)
 {
        uid_t uid;
        gid_t gid;
-       uint8_t *p = data;
+       uint8_t *p;
 
        if (len != sizeof(uid) + sizeof(gid)) {
                errno = EINVAL;