Dave's Brain

Browse - programming tips - linux become user nobody

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
Copyright © 2008-2010, dave - Code samples on Dave's Brain is licensed under the Creative Commons Attribution 2.5 License. However other material, including English text has all rights reserved.