aboutsummaryrefslogtreecommitdiff
path: root/seatd/client.c
diff options
context:
space:
mode:
authorKenny Levinsen <kl@kl.wtf>2020-08-01 00:31:16 +0000
committerKenny Levinsen <kl@kl.wtf>2020-08-01 16:53:44 +0200
commit2f54beb5fe95a8919182c407314c8a302a747627 (patch)
tree0f50cc830e8b019df863718f5989b8908d4eadaa /seatd/client.c
parente129536a08a74045719640676b55a03b926117d9 (diff)
client: Implement get_peer for FreeBSD
Diffstat (limited to 'seatd/client.c')
-rw-r--r--seatd/client.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/seatd/client.c b/seatd/client.c
index 72e652c..a8d8452 100644
--- a/seatd/client.c
+++ b/seatd/client.c
@@ -9,6 +9,11 @@
#include <sys/types.h>
#include <unistd.h>
+#if defined(__FreeBSD__)
+#include <sys/ucred.h>
+#include <sys/un.h>
+#endif
+
#include "client.h"
#include "log.h"
#include "poller.h"
@@ -18,6 +23,7 @@
#include "terminal.h"
static int get_peer(int fd, pid_t *pid, uid_t *uid, gid_t *gid) {
+#if defined(__linux__)
struct ucred cred;
socklen_t len = sizeof cred;
if (getsockopt(fd, SOL_SOCKET, SO_PEERCRED, &cred, &len) == -1) {
@@ -27,6 +33,19 @@ static int get_peer(int fd, pid_t *pid, uid_t *uid, gid_t *gid) {
*uid = cred.uid;
*gid = cred.gid;
return 0;
+#elif defined(__FreeBSD__)
+ struct xucred cred;
+ socklen_t len = sizeof cred;
+ if (getsockopt(fd, SOL_SOCKET, LOCAL_PEERCRED, &cred, &len) == -1) {
+ return -1;
+ }
+ *pid = -1;
+ *uid = cred.cr_uid;
+ *gid = cred.cr_ngroups > 0 ? cred.cr_groups[0] : -1;
+ return 0;
+#else
+ return -1;
+#endif
}
struct client *client_create(struct server *server, int client_fd) {