about summary refs log tree commit diff stats
path: root/linux
diff options
context:
space:
mode:
authorMarco Peereboom <marco@conformal.com>2010-12-29 16:24:59 +0000
committerMarco Peereboom <marco@conformal.com>2010-12-29 16:24:59 +0000
commit33bb6bec1605b35f8903eaa0bf90a80ab665abd1 (patch)
treef8fb720f2c85962351d20fde70caaa6b06c1e143 /linux
parentbfe757b6f525bfda747a30bd0f7c2af14bc76a1e (diff)
downloadxombrero-33bb6bec1605b35f8903eaa0bf90a80ab665abd1.tar.gz
consolidate getpeerid code with linux.
fix enable_socket default
fix man page

from Stevan Andjelkovic <stevan@student.chalmers.se>
Diffstat (limited to 'linux')
-rw-r--r--linux/linux.c36
-rw-r--r--linux/util.h3
2 files changed, 39 insertions, 0 deletions
diff --git a/linux/linux.c b/linux/linux.c
index 97544c5..2e0eb9b 100644
--- a/linux/linux.c
+++ b/linux/linux.c
@@ -2,6 +2,7 @@
 
 #include <sys/types.h>
 #include <sys/cdefs.h>
+#include <sys/socket.h>
 
 #include <errno.h>
 #include <errno.h>
@@ -681,6 +682,41 @@ fmt_scaled(long long number, char *result)
 	return 0;
 }
 
+/* --------------------------------------------------------------------------- */
+
+/*
+ * Copyright (c) 2002,2004 Damien Miller <djm@mindrot.org>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+/* Get effective user and group identification of locally-connected
+ * peer.
+ */
+int
+getpeereid(int s, uid_t *euid, gid_t *gid)
+{
+	struct ucred cred;
+	socklen_t len = sizeof(cred);
+
+	if (getsockopt(s, SOL_SOCKET, SO_PEERCRED, &cred, &len) < 0)
+		return (-1);
+	*euid = cred.uid;
+	*gid = cred.gid;
+
+	return (0);
+}
+
 #ifdef	MAIN
 /*
  * This is the original version of the program in the man page.
diff --git a/linux/util.h b/linux/util.h
index d0ad170..46c75ad 100644
--- a/linux/util.h
+++ b/linux/util.h
@@ -29,3 +29,6 @@ int	fmt_scaled(long long number, char *result);
  * fmt_scaled(3) specific flags. (from OpenBSD util.h)
  */
 #define FMT_SCALED_STRSIZE	7	/* minus sign, 4 digits, suffix, null byte */
+
+int getpeereid(int s, uid_t *euid, gid_t *gid);
+