Skip to content

Commit a3e9c91

Browse files
authored
Merge pull request #2967 from DeusData/distill/2492-freebsd-peer-pid
fix(daemon): read the peer pid on FreeBSD via LOCAL_PEERCRED
2 parents a0c7f28 + c8de7dc commit a3e9c91

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

‎src/daemon/ipc.c‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,9 @@ int cbm_daemon_ipc_wait_pending(const cbm_ipc_pending_ops_t *ops, uint32_t timeo
484484
#include <sys/stat.h>
485485
#include <sys/types.h>
486486
#include <sys/un.h>
487+
#ifdef __FreeBSD__
488+
#include <sys/ucred.h>
489+
#endif
487490
#include <time.h>
488491
#include <unistd.h>
489492
#if defined(__linux__)
@@ -3843,6 +3846,15 @@ uint64_t cbm_daemon_ipc_connection_peer_pid(const cbm_daemon_ipc_connection_t *c
38433846
return 0;
38443847
}
38453848
return (uint64_t)credentials.pid;
3849+
#elif defined(__FreeBSD__)
3850+
struct xucred credentials;
3851+
socklen_t length = sizeof(credentials);
3852+
if (getsockopt(connection->fd, SOL_LOCAL, LOCAL_PEERCRED, &credentials, &length) != 0 ||
3853+
length != sizeof(credentials) || credentials.cr_version != XUCRED_VERSION ||
3854+
credentials.cr_uid != geteuid() || credentials.cr_pid <= 0) {
3855+
return 0;
3856+
}
3857+
return (uint64_t)credentials.cr_pid;
38463858
#elif defined(SOL_LOCAL) && defined(LOCAL_PEERPID)
38473859
pid_t peer_pid = 0;
38483860
socklen_t length = sizeof(peer_pid);

0 commit comments

Comments
 (0)