Is there a way for a UNIX domain socket listener to only accept connection from certain user (chmod
/chown
does not work for abstract socket afaik), or in another word, get the uid of the incoming connection (on Linux)?
Dbus, which uses abstract unix socket on Linux, has a function GetConnectionUnixUser
which is used by polkit to determine the caller. So I suppose the dbus-daemon
must have a way to do that. Does anyone know how that works?
The easiest way to check peer credentials is with
SO_PEERCRED
. To do this for socketsock
:From a tlpi example. PostgreSQL has a few variants for other unices.
Yes -- this operation, along with FD passing, is supported via an ancilliary message with the
SCM_CREDENTIALS
type. The calls involved are documented inman 7 unix
.