Linux – UNIX domain sockets not accessable across users

linuxsockets

I'm running a client/server application on Red Hat Enterprise using ZMQ for message passing. The IPC socket used to associate a client with the server is implemented using a Unix domain socket.

If user A starts the server process, it seems like only clients started by user A can connect to and communicate over that socket. Our project requires that the clients be able to be run by different users, so this is a major sticking point.

The socket is located at /tmp/ipc_assoc with default 755 permissions. chmod 777 does not fix the problem. chown userB allows user B to access the socket, but user A then loses access. Not even root can access the socket. There is no ACL or SeLinux in use on the machine.

Is this typical behavior for Unix domain sockets? Has anyone figured out how to work around it?

Best Answer

chmod(s.sun_path, 0777); after listening to the socket.

domain = AF_UNIX;
name = servname;
port = -1;

n = MakeLocalSocket(s);
if (n == 0) {
    fatal("can't create socket");
}

unlink(s.sun_path);

if (bind(fd, & s, n) < 0) {
    fatal("can't bind socket");
}

if (listen(fd, 5) != 0) {
    fatal("can't listen to socket");
}

/* UNIX domain sockets need to be mode 777 on 4.3 */
chmod(s.sun_path, 0777);
Related Topic