Skip to contentSkip to conversation

getpeereid() for Linux

DISCUSSION Florian Weimer 2 participants 3 messages Sep 5, 2001

lore
Share & tools
lore
#0 lore raw

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?

Thanks to /proc, it is possible to implement the user ID part of the syscall in userland, at least for TCP sockets, but this isn't enough. (I've got a such an implementation which seems to work quite well, just in case you are interested.)

Signature · 3 lines
Florian Weimer 	                  [email protected]
University of Stuttgart           http://cert.uni-stuttgart.de/
RUS-CERT                          +49-711-685-5973/fax +49-711-685-5898
#1 lore raw
Quoted 11 lines

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.

Signature · 3 lines
Michael Bacarella <[email protected]>
Technical Staff / System Development,
New York Connect.Net, Ltd.
#2 lore raw
In reply to Florian Weimer
Quoted 2 lines · Michael Bacarella

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

Well, it doesn't work with TCP. Uh-oh, I see I forgot to mention the
following: I need this functionality for local TCP connections, not just UNIX domain sockets.

Signature · 3 lines
Florian Weimer 	                  [email protected]
University of Stuttgart           http://cert.uni-stuttgart.de/
RUS-CERT                          +49-711-685-5973/fax +49-711-685-5898