summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArthur de Jong <arthur@arthurdejong.org>2008-01-26 14:31:47 +0000
committerArthur de Jong <arthur@arthurdejong.org>2008-01-26 14:31:47 +0000
commit42d2f9a937ec24702da2de6b4052acbfd68e5949 (patch)
treeff1b0d34d0abcb76eca5d36b53c30811c274d003
parentda63099262e71310b7c8b6af3ba85214b430ef72 (diff)
add (untested) support for the Solaris getpeerucred() function
git-svn-id: http://arthurdejong.org/svn/nss-pam-ldapd/nss-ldapd@566 ef36b2f9-881f-0410-afb5-c4e39611909c
-rw-r--r--compat/getpeercred.c17
-rw-r--r--compat/getpeercred.h4
-rw-r--r--configure.ac2
3 files changed, 21 insertions, 2 deletions
diff --git a/compat/getpeercred.c b/compat/getpeercred.c
index 101a492..e36c907 100644
--- a/compat/getpeercred.c
+++ b/compat/getpeercred.c
@@ -31,9 +31,15 @@
#include <sys/ucred.h>
#endif /* HAVE SYS_UCRED_H */
#include <errno.h>
+#ifdef HAVE_UCRED_H
+#include <ucred.h>
+#endif /* HAVE_UCRED_H */
#include "getpeercred.h"
+/* Note: most of this code is untested, except for the first
+ implementation (it may even fail to compile) */
+
int getpeercred(int sock,uid_t *uid,gid_t *gid,pid_t *pid)
{
#if defined(SO_PEERCRED)
@@ -73,6 +79,17 @@ int getpeercred(int sock,uid_t *uid,gid_t *gid,pid_t *pid)
if (gid!=NULL) *gid=cred.gid;
if (pid!=NULL) *pid=cred.pid;
return 0;
+#elif defined(HAVE_GETPEERUCRED)
+ ucred_t *cred=NULL;
+ if (getpeerucred(client,&cred))
+ return -1;
+ /* save the data */
+ if (uid!=NULL) *uid=ucred_geteuid(&cred);
+ if (gid!=NULL) *gid=ucred_getegid(&cred);
+ if (pid!=NULL) *pid=ucred_getpid(&cred);
+ /* free cred and return */
+ ucred_free(&ucred);
+ return 0;
#elif defined(HAVE_GETPEEREID)
uid_t tuid;
gid_t tgid;
diff --git a/compat/getpeercred.h b/compat/getpeercred.h
index 8a103e1..2db6b5d 100644
--- a/compat/getpeercred.h
+++ b/compat/getpeercred.h
@@ -24,8 +24,8 @@
#ifndef _COMPAT_GETPEERCRED_H
#define _COMPAT_GETPEERCRED_H 1
-/* This function tries to determine the user id, group id and process
- id of the other end of the specified socket.
+/* This function tries to determine the (effective) user id, group id
+ and process id of the other end of the specified socket.
Any of the uid, gid and pid paramaters may be NULL to not update
that information.
On success, zero is returned. On error, -1 is returned, and errno
diff --git a/configure.ac b/configure.ac
index 9826569..d83a8b6 100644
--- a/configure.ac
+++ b/configure.ac
@@ -137,6 +137,7 @@ AC_CHECK_HEADERS(gssapi/gssapi_krb5.h gssapi.h)
AC_CHECK_HEADERS(grp.h)
AC_CHECK_HEADERS(sys/socket.h)
AC_CHECK_HEADERS(sys/ucred.h)
+AC_CHECK_HEADERS(ucred.h)
# set up directory with compatibility replacement files
AC_CONFIG_LIBOBJ_DIR([compat])
@@ -169,6 +170,7 @@ AC_CHECK_FUNCS(ether_aton_r)
AC_CHECK_FUNCS(ether_ntoa_r)
AC_CHECK_FUNCS(setgroups)
AC_CHECK_FUNCS(getpeereid)
+AC_CHECK_FUNCS(getpeerucred)
# checks for types
AC_C_CONST