summaryrefslogtreecommitdiffstats
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-03-08 11:35:06 +0000
commit04952f15df1bc81d1878833533d344a6b1d1326c (patch)
tree595f503d9c57ebb27774221465924f867bd35229 /compat
parent9ed1226a66ee7e097ef858f7bc4b992fbcda2dc7 (diff)
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);