From b179d7e13dbf37510aaac7c33b6fa9cc4ac756aa Mon Sep 17 00:00:00 2001 From: deraadt <> Date: Thu, 1 Jul 2010 19:15:30 +0000 Subject: getpeereid() can now be a library routine using getsockopt() with SOL_SOCKET and SO_PEERCRED, only issue being that it cannot return EFAULT for a page fault. The kernel code will soon be put into compat, and then in 10 years or so tedu will delete it. ok guenther millert --- src/lib/libc/net/getpeereid.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 src/lib/libc/net/getpeereid.c (limited to 'src/lib/libc/net/getpeereid.c') diff --git a/src/lib/libc/net/getpeereid.c b/src/lib/libc/net/getpeereid.c new file mode 100644 index 0000000000..208e541f17 --- /dev/null +++ b/src/lib/libc/net/getpeereid.c @@ -0,0 +1,36 @@ +/* $OpenBSD: getpeereid.c,v 1.1 2010/07/01 19:15:30 deraadt Exp $ */ + +/* + * Copyright (c) 2010 Theo de Raadt + * + * 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. + */ + +#include +#include + +int +getpeereid(int s, uid_t *euid, gid_t *egid) +{ + struct sockpeercred creds; + socklen_t credslen = sizeof(creds); + int error; + + error = getsockopt(s, SOL_SOCKET, SO_PEERCRED, + &creds, &credslen); + if (error) + return (error); + *euid = creds.uid; + *egid = creds.gid; + return (0); +} -- cgit v1.2.3-55-g6feb