how can I change the permissions of a linux socket file?

前端 未结 1 1552
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-02-06 02:13

I have a program which creates a socket, and then I want to change the permissions of the socket file:

ret_val = chmod(filename, 0777);

, but i

相关标签:
1条回答
  • 2021-02-06 02:33

    From man 7 unix:

    In the Linux implementation, sockets which are visible in the file system honor the permissions of the directory they are in. Their owner, group and their permissions can be changed. Creation of a new socket will fail if the process does not have write and search (execute) permission on the directory the socket is created in. Connecting to the socket object requires read/write permission. This behavior differs from many BSD-derived systems which ignore permissions for UNIX domain sockets. Portable programs should not rely on this feature for security.

    So if you want to control permissions on a socket, in order to be portable, you should instead control the permissions of the directory containing the socket.

    0 讨论(0)
提交回复
热议问题