A huge application needs, at one specific time, to perform a small number of writes to a file which requires root permissions. It is not really a file but a hardware interface which is exposed to Linux as a file.
To avoid giving root privileges to the whole application, I wrote a bash script which does the critical tasks. For example, the following script will enable port 17 of the hardware interface as output:
echo "17" > /sys/class/gpio/export echo "out" > /sys/class/gpio/gpio17/direction
suid is disabled for bash scripts on my system, I wonder what is the best way to achieve this.
Use some workaround presented here
Call the script with
sudofrom the main application, and edit the sudoers list accordingly, to avoid requiring a password when calling the script. I'm a little bit uncomfortable to give sudo privileges to
Just write a C program, with
fprintf, and set it to suid root. Hardcode the strings and filenames and make sure only root can edit it. Or read the strings from a text file, similarly making sure that no one can edit the file.
Some other solution which didn't occur to me and is safer or simpler then the ones presented above?