From: Roy Marples Date: Sun, 5 Jul 2026 15:01:13 +0000 (+0100) Subject: Fix compile on Linux X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=3554f56523dff642a90bb4cda21c18cbee7a519e;p=thirdparty%2Fdhcpcd.git Fix compile on Linux --- diff --git a/src/control.c b/src/control.c index 09aebc04..960ac4c3 100644 --- a/src/control.c +++ b/src/control.c @@ -33,6 +33,7 @@ #include #include +#include #include #include #include @@ -54,6 +55,10 @@ (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) diff --git a/src/privsep-control.c b/src/privsep-control.c index 8c2fa514..3ace3ad3 100644 --- a/src/privsep-control.c +++ b/src/privsep-control.c @@ -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 */ diff --git a/src/privsep-root.c b/src/privsep-root.c index 755b3b43..dec46b0d 100644 --- a/src/privsep-root.c +++ b/src/privsep-root.c @@ -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;