Run as different user
I am setting up my own daemon and are now working with the config-file. I wonder if I should enable running as a different user. How can I do this then?
The language is C++. My daemon starts, forks and dies, letting the fork be the running daemon. |
You say it is a daemon, so I suppose it is started as root, and you want to change to a different user ("drop root privileges" as they say) to increase security of your program.
You can do that like below. Though this is in C, it largely (if not entirely) applies to C++. Code:
#include <stdio.h> |
Ok.. Thanks a lot.
But now I am working on a config-file and I thought that maby it would be better if the user of the program just had to type in the name of the user/group instead of their IDs and then the program could get the uid/gid out of that. Is that possible? |
sure, see getpwnam(3)
|
All times are GMT -5. The time now is 09:47 AM. |