From 33bb6bec1605b35f8903eaa0bf90a80ab665abd1 Mon Sep 17 00:00:00 2001 From: Marco Peereboom Date: Wed, 29 Dec 2010 16:24:59 +0000 Subject: consolidate getpeerid code with linux. fix enable_socket default fix man page from Stevan Andjelkovic --- linux/linux.c | 36 ++++++++++++++++++++++++++++++++++++ linux/util.h | 3 +++ 2 files changed, 39 insertions(+) (limited to 'linux') 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 #include +#include #include #include @@ -681,6 +682,41 @@ fmt_scaled(long long number, char *result) return 0; } +/* --------------------------------------------------------------------------- */ + +/* + * Copyright (c) 2002,2004 Damien Miller + * + * 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); + -- cgit 1.4.1-2-gfad0