drop privileges when running as root

This commit is contained in:
Björn Ketelaars
2015-09-04 16:16:31 +02:00
parent 36f8df2011
commit 053bd8d5d6

11
fiche.c
View File

@@ -36,6 +36,17 @@ int main(int argc, char **argv)
time_seed = time(0);
parse_parameters(argc, argv);
if (getuid() == 0)
{
if (UID == -1)
error("ERROR: user not set");
if (setgid(GID) != 0)
error("ERROR: Unable to drop group privileges");
if (setuid(UID) != 0)
error("ERROR: Unable to drop user privileges");
}
if (BASEDIR == NULL)
set_basedir();