libpcap 函数需要 root 权限
当以非 root 用户身份运行时,pcap_lookupdev()
会填充 errbuf 变量,而当以 root 用户身份运行时,相同的函数会返回第一个可用网络接口的值。
此访问是否被操作系统或库禁用。我认为这是操作系统。正确答案是什么?
这不是一个家庭作业问题
The pcap_lookupdev()
fills in the errbuf variable when run as non-root user, while the same functions returns the value of the first available network interface when run as root.
Is this access disabled by the OS or the library. I think it is the OS. What is the right answer?
This is not a homework question
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
一般来说,当涉及到访问操作系统提供的文件、设备和其他服务时,Unix(以及 Linux)中的访问模型是在操作系统中实现的。
用户空间程序应该尝试他们想做的任何事情,并通过例如向用户通知消息来优雅地处理任何错误情况。
这有几个优点:
可维护性:访问策略的实施仍然由操作系统负责,并且可以统一配置。想要限制对资源的访问的管理员会这样做一次,而不是必须在此处配置该库,而不是在此处配置该库,然后...
可配置性:管理员可以像简单一样配置
安全性:通常不应信任用户空间程序执行访问策略。这就像让狼看守羊一样。
编辑:
在您的情况下,
pcap
需要低级访问权限到网络接口。由于安全隐患(捕获网络流量、生成任意网络数据包等),此类访问仅限于特权用户。例如,在 Linux 上,pcap
需要CAP_NET_RAW
用户可用的能力。In general, when it comes to accessing files, devices and other services provided by the OS, access models in Unix (and, thus, Linux) are implemented in the OS.
Userspace programs are expected to just try whatever they want to do and gracefully handle any error condition by e.g. informing the user with a message.
This has several advantages:
Maintainability: Access policy enforcement remains with the OS and can be configured uniformly. The administrator that wants to restrict access to a resource does so once, rather than having to configure this library here, than that library there, then...
Configurability: The administrator can configure as simple or complex an access policy they need without being limited by each userspace implementation.
Security: Userspace programs should not in general be trusted with enforcing access policy. It would be like having a wolf guard the sheep.
EDIT:
In your case,
pcap
needs low-level access to the network interface. Due to the security implications (capturing network traffic, generating arbitrary network packets etc), such access is limited to privileged users only. On Linux, for example,pcap
needs theCAP_NET_RAW
capability to be available to the user.许多 pcap 功能需要 root 权限才能正常工作。这可能是问题所在吗?
Many of the pcap functions require root privileges in order to work correctly. Might this be the problem?
这主要取决于操作系统。并非所有
pcap
功能都需要所有操作系统上的 root 权限。参考参考手册页,分别列出了所有特殊权限要求。
It mostly depends on OS. Not all
pcap
functions require root privilege on all OS.Ref to Reference Manual Pages, all special privilege requirements are listed respectively.