Re: [PATCH] Added support for dropping privileges to git-daemon.
- From
- Mitchell Blank Jr <mitch@sfgoth.com>
- Date
- Aug 19, 2006, 17:25 UTC
- Message-ID
- <20060819172533.GB64962@gaz.sfgoth.com>
- In-Reply-To
- <1155990772.6591@hammerfest>
Tilman Sauerbeck wrote:
> + if (user && group) > + drop_privileges();
It seems "if (user)" would be sufficient here.
> + if (!user ^ !group)
> + die("either set both user and group or none of them");For simplicities sake I'd actually suggest allowing group==NULL. So change this test to be
if (group && !user)
die("--group supplied without --user");Then in drop_privileges() do something like:
struct passwd *p; gid_t gid;
p = getpwnam(user);
if (!p)
die("user not found - %s", user);
if (group == NULL)
gid = p->pw_gid;
else {
struct group *g = getgrnam(group);
if (!g)
die("group not found - %s", group);
gid = g->gr_gid;
}Since usually you want to use the same gid that is normally associated with that pid, this just makes things a little easier on the user
-Mitch