lkml.org 
[lkml]   [2001]   [Sep]   [5]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: getpeereid() for Linux
> Would anyone like to give me a helping hand in implementing the
> getpeereid() syscall for Linux? See the following page for the
> documentation of the OpenBSD implementation:
>
> http://www.openbsd.org/cgi-bin/man.cgi?query=getpeereid&sektion=2&apropos=0&manpath=OpenBSD+Current
>
> I think I could work out the kernel data structures to gather the
> relevant data from, however, I won't get all the locking stuff right.
>
> OTOH, is there any chance that the addition of such a syscall would be
> accepted?

There's no need. The equivalent functionality can already be
implemented in userspace.

------

#include <sys/socket.h>

uid_t getpeereuid(int sd)
{
struct ucred cred;
int len = sizeof (cred);

if (getsockopt(sd,SOL_SOCKET,SO_PEERCRED,&cred,&len))
return -1;

return cred.uid;
}

------

The same can be done for gid, and even pid.

Yes, Linux rules.

--
Michael Bacarella <mbac@nyct.net>
Technical Staff / System Development,
New York Connect.Net, Ltd.
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

\
 
 \ /
  Last update: 2005-03-22 13:02    [W:0.031 / U:5.048 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site