aboutsummaryrefslogtreecommitdiff
path: root/compat
diff options
context:
space:
mode:
authorNicholas Marriott <nicholas.marriott@gmail.com>2022-03-08 11:35:06 +0000
committerNicholas Marriott <nicholas.marriott@gmail.com>2022-04-06 14:19:50 +0100
commitf97d784f172a10e0444ad93bb536ee0428613aa7 (patch)
tree085a0a2d5a5a84af4724d462014349d8c1f3473c /compat
parent759f94965454a043285813cf4fd8b83944587973 (diff)
downloadrtmux-f97d784f172a10e0444ad93bb536ee0428613aa7.tar.gz
rtmux-f97d784f172a10e0444ad93bb536ee0428613aa7.tar.bz2
rtmux-f97d784f172a10e0444ad93bb536ee0428613aa7.zip
Use getpeerucred if available (not tested).
Diffstat (limited to 'compat')
-rw-r--r--compat/getpeereid.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/compat/getpeereid.c b/compat/getpeereid.c
index 722f14a2..5a593c07 100644
--- a/compat/getpeereid.c
+++ b/compat/getpeereid.c
@@ -19,6 +19,10 @@
#include <stdio.h>
+#ifdef HAVE_UCRED_H
+#include <ucred.h>
+#endif
+
#include "compat.h"
int
@@ -33,6 +37,21 @@ getpeereid(int s, uid_t *uid, gid_t *gid)
*uid = uc.uid;
*gid = uc.gid;
return (0);
+#elif defined(HAVE_GETPEERUCRED)
+int
+getpeereid(int s, uid_t *uid, gid_t *gid)
+{
+ ucred_t *ucred = NULL;
+
+ if (getpeerucred(s, &ucred) == -1)
+ return (-1);
+ if ((*uid = ucred_geteuid(ucred)) == -1)
+ return (-1);
+ if ((*gid = ucred_getrgid(ucred)) == -1)
+ return (-1);
+ ucred_free(ucred);
+ return (0);
+}
#else
errno = EOPNOTSUPP;
return (-1);