Suppose I want my C program, running on Linux, to execute a certain function which needs to run as the root user (e.g. it reads a root-owned file with permissions -rwx------
). For simplicity, let's assume the function's signature int read_magic_file(int x)
.
If I wanted to do this outside my program, I would need to provide a password and use sudo (or su -c
etc.) - but I want to do this within my program.
So, suppose I have determined a value for x
, and that I've prompted my user for the root password and have gotten that password in a string. Now what do I do?
Notes:
- My executable does not and will not have setuid permissions.
- sudo will not be configured for my program to raise its own privileges, or to be run as root; nor will pam or anything else be configured to allow me to become root without a password etc.