summaryrefslogtreecommitdiff
path: root/openbsd-compat/bsd-getpeereid.c
diff options
context:
space:
mode:
authorDarren Tucker <dtucker@zip.com.au>2007-03-21 21:39:57 +1100
committerDarren Tucker <dtucker@zip.com.au>2007-03-21 21:39:57 +1100
commit164aa30e4604672f688b5c51b90e42dfa129821b (patch)
tree4ce05465abbf23eb557d9f9ef4841a6be23c2365 /openbsd-compat/bsd-getpeereid.c
parent04354b97dc1cc87d01a33db508a9ea0f0148fb83 (diff)
- (dtucker) [configure.ac openbsd-compat/bsd-getpeereid.c] Bug #1287: Use
getpeerucred to implement getpeereid (currently only Solaris 10 and up). Patch by Jan.Pechanec at Sun.
Diffstat (limited to 'openbsd-compat/bsd-getpeereid.c')
-rw-r--r--openbsd-compat/bsd-getpeereid.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/openbsd-compat/bsd-getpeereid.c b/openbsd-compat/bsd-getpeereid.c
index bdae8b63..5f7e677e 100644
--- a/openbsd-compat/bsd-getpeereid.c
+++ b/openbsd-compat/bsd-getpeereid.c
@@ -37,6 +37,28 @@ getpeereid(int s, uid_t *euid, gid_t *gid)
return (0);
}
+#elif defined(HAVE_GETPEERUCRED)
+
+#ifdef HAVE_UCRED_H
+# include <ucred.h>
+#endif
+
+int
+getpeereid(int s, uid_t *euid, gid_t *gid)
+{
+ ucred_t *ucred = NULL;
+
+ if (getpeerucred(s, &ucred) == -1)
+ return (-1);
+ if ((*euid = ucred_geteuid(ucred)) == -1)
+ return (-1);
+ if ((*gid = ucred_getrgid(ucred)) == -1)
+ return (-1);
+
+ ucred_free(ucred);
+
+ return (0);
+}
#else
int
getpeereid(int s, uid_t *euid, gid_t *gid)