Re: getpeereid() for Linux

Michael Bacarella (mbac@nyct.net)
Wed, 5 Sep 2001 09:38:51 -0400


> 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/