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 }
Programming Tips - For security, I want the daemon (server) I am writing to become user "nobody". How do I do that?
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?
A. Here's a function that does that: