Date: 2010jan2
OS: Linux
Language: C/C++
Q. For security, I want the daemon (server) I am writing to become
user "nobody". How do I do that?
Q. Here's a function that does that:
bool become_nobody()
{
struct passwd *pw;
if ((pw = getpwnam("nobody")) == NULL) return false;
seteuid(pw->pw_uid);
setegid(pw->pw_gid);
return true;
}
// Example use:
main()
{
become_nobody(); // Do very first
// Do everything else
}
| What this info useful to you? You can donate to say thanks |
Add a comment
Sign in to add a comment