PATCH: auth EXTERNAL on platforms other then Linux
Michael Krivoruchko
misha at sun.com
Thu Oct 6 12:04:03 PDT 2005
Hi,
Attached patch provides support of auth EXTERNAL on Solaris 10+
(getpeerucred), FreeBSD 4.6+, OpenBSD 3.0+ and FreeBSD 5.0+ as
well as MacOSX 10.2+ (getpeereid).
I tested this patch only on Solaris 10 x86 so it might be issues
with other platforms (i.e. BSDs and MacOSX).
Misha
--
-------------- next part --------------
diff -ruN dbus/configure.in dbus-auth-extern/configure.in
--- dbus/configure.in 2005-09-06 23:38:54.000000000 +0100
+++ dbus-auth-extern/configure.in 2005-10-06 18:26:28.000000000 +0100
@@ -652,6 +652,7 @@
AC_DEFINE(HAVE_CMSGCRED,1,[Have cmsgcred structure])
fi
+AC_CHECK_FUNCS(getpeerucred getpeereid)
#### Abstract sockets
diff -ruN dbus/dbus/dbus-sysdeps.c dbus-auth-extern/dbus/dbus-sysdeps.c
--- dbus/dbus/dbus-sysdeps.c 2005-08-03 18:42:56.000000000 +0100
+++ dbus-auth-extern/dbus/dbus-sysdeps.c 2005-10-06 18:07:23.000000000 +0100
@@ -57,7 +57,9 @@
#ifdef HAVE_BACKTRACE
#include <execinfo.h>
#endif
-
+#ifdef HAVE_GETPEERUCRED
+#include <ucred.h>
+#endif
#ifndef O_BINARY
#define O_BINARY 0
@@ -923,7 +925,33 @@
credentials->pid = cmsg.cred.cmcred_pid;
credentials->uid = cmsg.cred.cmcred_euid;
credentials->gid = cmsg.cred.cmcred_groups[0];
-#else /* !SO_PEERCRED && !HAVE_CMSGCRED */
+#elif defined(HAVE_GETPEEREID)
+ uid_t euid;
+ gid_t egid;
+ if (getpeereid (client_fd, &euid, &egid) == 0)
+ {
+ credentials->uid = euid;
+ credentials->gid = egid;
+ }
+ else
+ {
+ _dbus_verbose ("Failed to getpeereid() credentials: %s\n", _dbus_strerror (errno));
+ }
+#elif defined(HAVE_GETPEERUCRED)
+ ucred_t * ucred = NULL;
+ if (getpeerucred (client_fd, &ucred) == 0)
+ {
+ credentials->pid = ucred_getpid (ucred);
+ credentials->uid = ucred_geteuid (ucred);
+ credentials->gid = ucred_getegid (ucred);
+ }
+ else
+ {
+ _dbus_verbose ("Failed to getpeerucred() credentials: %s\n", _dbus_strerror (errno));
+ }
+ if (ucred != NULL)
+ ucred_free (ucred);
+#else /* !SO_PEERCRED && !HAVE_CMSGCRED && !HAVE_GETPEEREID && !HAVE_GETPEERUCRED */
_dbus_verbose ("Socket credentials not supported on this OS\n");
#endif
}
More information about the dbus
mailing list