0

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:

  1. set the executable owner as root.
  2. set the "setuid" permission bit on the executable
  3. 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

tomix86
  • 1,336
  • 2
  • 18
  • 29
CJCombrink
  • 3,738
  • 1
  • 22
  • 38

2 Answers2

0

You can indeed set the needed capabilities by hand, using setcap() as root.

Therefore, use this command to set the appropriate capabilities, and it will run as a normal user without even needing to be root.

fge
  • 119,121
  • 33
  • 254
  • 329
0

It sounds like the library is doing things that actually do require root privileges.

Perhaps the easiest solution to this is to add the permissions in your build process (e.g. your Makefile).

One way to partially get around this is to split your program into two programs, one that communicates with the camera using the library, and one for the user interface that communicates with the interface program through a socket or pipe. This way, you would only need to change the permissions when you change the interface program. This would also be a generally good idea for setuid programs---you have a small wrapper program with the elevated permissions, and the larger GUI program is running without the extended permissions. It would be easier to audit the setuid program, especially if it can be made very simple.

David Brigada
  • 594
  • 2
  • 10