]> skyeroc.xyz Git - dgamelaunch/commitdiff
Additional anti-root uid security fixes
authorJoshua Kwan <joshk@triplehelix.org>
Wed, 21 Jan 2004 01:37:16 +0000 (01:37 +0000)
committerJoshua Kwan <joshk@triplehelix.org>
Wed, 21 Jan 2004 01:37:16 +0000 (01:37 +0000)
git-svn-id: svn://katsu.triplehelix.org/dgamelaunch/trunk@134 db0b04b0-f4d1-0310-9a6d-de3e77497b0e

config.y
dgamelaunch.c

index 336f144b0ec93ec39563e9f5aded8e47cec29f8d..485cd118c03f126e81449147ddb1db1470a664b6 100644 (file)
--- a/config.y
+++ b/config.y
@@ -45,7 +45,11 @@ KeyPair: KeyType '=' TYPE_VALUE {
   struct passwd* usr;
   
   if (!myconfig)
+  {
     myconfig = calloc(1, sizeof(struct dg_config));
+    myconfig->shed_uid = (uid_t)-1;
+    myconfig->shed_gid = (gid_t)-1;
+  }
 
   switch ($1)
   {
@@ -58,12 +62,25 @@ KeyPair: KeyType '=' TYPE_VALUE {
       
       break;
     case TYPE_SUSER:
+      if (!strcmp($3, "root"))
+      {
+        fprintf(stderr, "%s: I refuse to run as root! Aborting.\n", config);
+       graceful_exit(1);
+      }
       myconfig->shed_user = strdup($3);
       if ((usr = getpwnam($3)) != NULL)
-        myconfig->shed_uid = usr->pw_uid;
+      {
+        if (usr->pw_uid != 0)
+          myconfig->shed_uid = usr->pw_uid;
+       else
+       {
+         fprintf(stderr, "%s: I refuse to run as %s (uid 0!) Aborting.\n", config, $3);
+         graceful_exit(1);
+       }
+      }
       else
-        fprintf(stderr, "%s: no such group '%s'\n", config, $3);
-     break;
+        fprintf(stderr, "%s: no such user '%s'\n", config, $3);
+      break;
 
     case TYPE_PATH_CHROOT:
       if (myconfig->chroot) free(myconfig->chroot);
@@ -113,6 +130,12 @@ KeyPair: KeyType '=' TYPE_VALUE {
     case TYPE_SUID:
       if (!myconfig->shed_user)
       {
+        /* Naive user protection - do not allow running as user root */
+       if ($3 == 0)
+       {
+         fprintf(stderr, "%s: I refuse to run as root! Aborting.\n", config);
+         graceful_exit(1);
+       }
         myconfig->shed_uid = $3;
       }
        
index 958a3722e561587dabf94d9f5d35ad141ab54945..f056607282ee8d426add4232e0fcfe54fceb1ba2 100644 (file)
@@ -170,7 +170,7 @@ create_config ()
     }
 
     /* Fill the rest with defaults */
-    if (!myconfig->shed_user && myconfig->shed_uid == 0)
+    if (!myconfig->shed_user && myconfig->shed_uid == -1)
     {
       struct passwd *pw;
       if ((pw = getpwnam(defconfig.shed_user)))
@@ -179,7 +179,7 @@ create_config ()
        myconfig->shed_uid = defconfig.shed_uid;
     }
 
-    if (!myconfig->shed_group && myconfig->shed_gid == 0)
+    if (!myconfig->shed_group && myconfig->shed_gid == -1)
     {
       struct group *gr;
       if ((gr = getgrnam(defconfig.shed_group)))