diff options
-rw-r--r-- | common/terminal.c | 4 | ||||
-rw-r--r-- | seatd/client.c | 19 |
2 files changed, 21 insertions, 2 deletions
diff --git a/common/terminal.c b/common/terminal.c index 469d78f..a46ff14 100644 --- a/common/terminal.c +++ b/common/terminal.c @@ -17,8 +17,8 @@ #elif defined(__FreeBSD__) #include <sys/consio.h> #include <sys/kbio.h> -#define TTY0 "/dev/ttyv0" -#define TTYF "/dev/ttyv%d" +#define TTY0 "/dev/ttyv0" +#define TTYF "/dev/ttyv%d" #define K_ON K_XLATE #define K_OFF K_CODE #define FRSIG SIGIO 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) { |