requirement of root privileges for libpcap functions

社会主义新天地 提交于 2019-12-19 10:28:45

问题


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


回答1:


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 the CAP_NET_RAW capability to be available to the user.




回答2:


Many of the pcap functions require root privileges in order to work correctly. Might this be the problem?



来源:https://stackoverflow.com/questions/4885841/requirement-of-root-privileges-for-libpcap-functions

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!