I am busy developing an application in C++ on a Linux computer. The application uses a 3rd party library that uses the Ethernet adapter and the network. The library is the library of a GigE Vision camera. On startup my application tries to connect to the camera and then it returns information about the camera, thereafter it starts streaming video to the application.
After a while the application could not connect or get the camera information from the camera, but running the application as root (sudo) solves the problem.
I have contacted the supplier of the library and they have indicated that I should do the following:
Users who feel running as root compromises their system security may find the following implementation satisfactory:
- set the executable owner as root.
- set the "setuid" permission bit on the executable
- in code, when application starts use capset() to release all but these privileges: CAP_SYS_NICE, CAP_NET_ADMIN, CAP_NET_BROADCAST, CAP_NET_RAW The application will start with all root privileges, but it will drop them immediately after startup.
This does work but isn't there an alternative way for me to do this without changing the executable? I am thinking of adding my user to some group that allows me to access those privileges, any help will be appreciated.
The above mentioned solution is not optimal in the sense that after each compilation I need to change the owner and set the permissions. The application is used to record video and capture images. For the mentioned solution these recordings and captures are then also owned by the root user and the user needs to be changed back when distributing the files.
OS: Ubuntu Linux 11.10 Environment: C++ with Qt