From: Michael Jeanson Date: Mon, 19 Jul 2021 17:42:55 +0000 (-0400) Subject: Add 'pid' to socket peercred on FreeBSD X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=2956f16b84f00d4f91b124d296462baca6aa04cc;p=lttng-ust.git Add 'pid' to socket peercred on FreeBSD The 'pid' of the socket peer was added to xucred in FreeBSD 12. Lttng-tools doesn't yet have full support for FreeBSD but once it's merged the baseline should be either FreeBSD 12 or 13 so we can get away with no compat code. Change-Id: I238baef7eedb3a909fb3804e6fd2cca4db84b21a Signed-off-by: Michael Jeanson Signed-off-by: Mathieu Desnoyers --- diff --git a/src/lib/lttng-ust-ctl/ustctl.c b/src/lib/lttng-ust-ctl/ustctl.c index 784cb75d..8c60bdb2 100644 --- a/src/lib/lttng-ust-ctl/ustctl.c +++ b/src/lib/lttng-ust-ctl/ustctl.c @@ -2408,7 +2408,6 @@ int get_cred(int sock, /* * Override application uid/gid with unix socket credentials. Use the * first group of the cr_groups. - * Use the pid and ppid provided by the application on registration. */ static int get_cred(int sock, @@ -2422,21 +2421,25 @@ int get_cred(int sock, socklen_t xucred_len = sizeof(struct xucred); int ret; - ret = getsockopt(sock, SOL_SOCKET, LOCAL_PEERCRED, &xucred, &xucred_len); + ret = getsockopt(sock, SOL_LOCAL, LOCAL_PEERCRED, &xucred, &xucred_len); if (ret) { return -LTTNG_UST_ERR_PEERCRED; } if (xucred.cr_version != XUCRED_VERSION || xucred.cr_ngroups < 1) { return -LTTNG_UST_ERR_PEERCRED; } - DBG("Unix socket peercred [ uid: %u, gid: %u ], " - "application registered claiming [ pid: %d, ppid: %d, uid: %u, gid: %u ]", - xucred.cr_uid, xucred.cr_groups[0], + DBG("Unix socket peercred [ pid: %u, uid: %u, gid: %u ], " + "application registered claiming [ pid: %u, ppid: %u, uid: %u, gid: %u ]", + xucred.cr_pid, xucred.cr_uid, xucred.cr_groups[0], reg_msg->pid, reg_msg->ppid, reg_msg->uid, reg_msg->gid); - *pid = reg_msg->pid; - *ppid = reg_msg->ppid; + *pid = xucred.cr_pid; *uid = xucred.cr_uid; *gid = xucred.cr_groups[0]; + if (xucred.cr_pid == reg_msg->pid) { + *ppid = reg_msg->ppid; + } else { + *ppid = 0; + } return 0; } #else