: nply/fiche2

commit 053bd8d5d6eeb68c73cb94f60254a8a91562a84b
parent 36f8df2011d360be7cd0b0bd8df717502afc53d6
Author: Björn Ketelaars <bjorn.ketelaars@hydroxide.nl>
Date: Fri, 4 Sep 2015 16:16:31 +0200

drop privileges when running as root
1 file changed, 11 insertions(+), 0 deletions(-)
M
fiche.c
|
11
+++++++++++
diff --git a/fiche.c b/fiche.c
@@ -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();