加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Linux > 正文

如何更改linux套接字文件的权限?

发布时间:2020-12-13 18:30:29 所属栏目:Linux 来源:网络整理
导读:我有一个程序,它创建一个套接字,然后我想更改套接字文件的权限: ret_val = chmod(filename,0777); ,但它不会改变,即使ret_val为0.如果我在常规文件上尝试相同的操作,它也可以. 有任何想法吗? P.S:我以root身份运行程序,因此它拥有所需的所有权限. 解决方
我有一个程序,它创建一个套接字,然后我想更改套接字文件的权限:
ret_val = chmod(filename,0777);

,但它不会改变,即使ret_val为0.如果我在常规文件上尝试相同的操作,它也可以.

有任何想法吗?

P.S:我以root身份运行程序,因此它拥有所需的所有权限.

解决方法

来自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.

因此,如果要控制套接字上的权限,为了便于移植,您应该控制包含套接字的目录的权限.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读