]> andersk Git - gssapi-openssh.git/blobdiff - openssh/openbsd-compat/bsd-getpeereid.c
Import of OpenSSH 4.7p1
[gssapi-openssh.git] / openssh / openbsd-compat / bsd-getpeereid.c
index 8a3779f3aa91f6e8b7abd4bb39f2d91bbf556364..5f7e677e5cdf3e75fc73d3b6c462346aae4ec572 100644 (file)
 
 #include "includes.h"
 
-RCSID("$Id$");
-
 #if !defined(HAVE_GETPEEREID)
 
+#include <sys/types.h>
+#include <sys/socket.h>
+
+#include <unistd.h>
+
 #if defined(SO_PEERCRED)
 int
 getpeereid(int s, uid_t *euid, gid_t *gid)
@@ -34,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)
This page took 0.232643 seconds and 4 git commands to generate.