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

标签 c sockets permissions

我有一个创建套接字的程序,然后我想更改套接字文件的权限:

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.

所以如果你想控制一个套接字的权限,为了便携,你应该控制包含套接字的目录的权限。

关于c - 如何更改 linux 套接字文件的权限?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5977556/

相关文章:

c - 区分字符串中的数字和字母

java - 在Android Studio中发送开放声音控制(OSC),套接字错误

java - Android 5 至 6 问题 : External Storage Path File. Exists() 已损坏/正在寻找替代方案

c++ - Clion 无法打开输出文件,权限被拒绝

javascript - Chrome 扩展程序 - 请求新权限

c - Lex/Flex 扫描仪不扫描,我不知道为什么

c# - 如何在.net中使用c库

c - 为什么在这个特定程序中 case 标签没有减少为整数常量?

c - inet_pton() 对应的链路层地址

php - 在 PHP 中创建简单的客户端/服务器 UDP 示例