]> skyeroc.xyz Git - dgamelaunch/commitdiff
Config file blues.. add silent option on command line
authorJoshua Kwan <joshk@triplehelix.org>
Sat, 31 Jan 2004 06:23:02 +0000 (06:23 +0000)
committerJoshua Kwan <joshk@triplehelix.org>
Sat, 31 Jan 2004 06:23:02 +0000 (06:23 +0000)
git-svn-id: svn://katsu.triplehelix.org/dgamelaunch/trunk@198 db0b04b0-f4d1-0310-9a6d-de3e77497b0e

config.y
dgamelaunch.c
dgamelaunch.conf
dgamelaunch.h

index 53824440551aaf21a6493e41d64abbee95cd8531..d21b8826dabe26c7cd05235553e5663cd027818d 100644 (file)
--- a/config.y
+++ b/config.y
@@ -34,7 +34,7 @@ static const char* lookup_token (int t);
 %%
 
 Configuration: KeyPairs
-       | { fprintf(stderr, "%s: no settings, proceeding with defaults\n", config); }
+       | { if (!silent) fprintf(stderr, "%s: no settings, proceeding with defaults\n", config); }
        ;
 
 KeyPairs: KeyPairs KeyPair
@@ -55,14 +55,28 @@ KeyPair: KeyType '=' TYPE_VALUE {
   switch ($1)
   {
     case TYPE_SGROUP:
+      if (myconfig->shed_gid != (gid_t)-1)
+        break;
+       
       myconfig->shed_group = strdup($3);
       if ((gr = getgrnam($3)) != NULL)
-        myconfig->shed_gid = gr->gr_gid;
+      {
+       myconfig->shed_gid = gr->gr_gid;
+       if (!silent)
+         fprintf(stderr, "%s:%d: suggest replacing 'shed_group = \"%s\"' line with 'shed_gid = %d'\n",
+         config, line, $3, gr->gr_gid);
+      }
       else
-        fprintf(stderr, "%s: no such group '%s'\n", config, $3);
+      {
+        if (!silent)
+          fprintf(stderr, "%s: no such group '%s'\n", config, $3);
+      }
       
       break;
     case TYPE_SUSER:
+      if (myconfig->shed_uid != (uid_t)-1)
+        break;
+       
       if (!strcmp($3, "root"))
       {
         fprintf(stderr, "%s: I refuse to run as root! Aborting.\n", config);
@@ -72,7 +86,12 @@ KeyPair: KeyType '=' TYPE_VALUE {
       if ((usr = getpwnam($3)) != NULL)
       {
         if (usr->pw_uid != 0)
+       {
           myconfig->shed_uid = usr->pw_uid;
+         if (!silent)
+           fprintf(stderr, "%s:%d: suggest replacing 'shed_user = \"%s\"' line with 'shed_uid = %d'\n",
+             config, line, $3, usr->pw_uid);
+       }
        else
        {
          fprintf(stderr, "%s: I refuse to run as %s (uid 0!) Aborting.\n", config, $3);
@@ -80,7 +99,10 @@ KeyPair: KeyType '=' TYPE_VALUE {
        }
       }
       else
-        fprintf(stderr, "%s: no such user '%s'\n", config, $3);
+      {
+        if (!silent)
+          fprintf(stderr, "%s: no such user '%s'\n", config, $3);
+      }
       break;
 
     case TYPE_PATH_CHROOT:
@@ -139,25 +161,26 @@ KeyPair: KeyType '=' TYPE_VALUE {
   switch ($1)
   {
     case TYPE_SUID:
-      if (!myconfig->shed_user)
+      if (!silent && myconfig->shed_uid != (uid_t)-1 && myconfig->shed_uid != $3)
+        fprintf(stderr, "%s:%d: 'shed_uid = %lu' entry overrides old setting %d\n",
+         config, line, $3, myconfig->shed_uid);
+
+      /* Naive user protection - do not allow running as user root */
+      if ($3 == 0)
       {
-        /* Naive user protection - do not allow running as user root */
-       if ($3 == 0)
-       {
-         fprintf(stderr, "%s: I refuse to run as uid 0 (root)! Aborting.\n", config);
-         graceful_exit(1);
-       }
-        myconfig->shed_uid = $3;
+        fprintf(stderr, "%s: I refuse to run as uid 0 (root)! Aborting.\n", config);
+        graceful_exit(1);
       }
-       
+     
+      myconfig->shed_uid = $3;
       break;
 
     case TYPE_SGID:
-      if (!myconfig->shed_group)
-      {
-        myconfig->shed_gid = $3;
-      }
-
+      if (!silent && myconfig->shed_gid != (gid_t)-1 && myconfig->shed_gid != $3)
+        fprintf(stderr, "%s:%d: 'shed_gid = %lu' entry overrides old setting %d\n",
+         config, line, $3, myconfig->shed_gid);
+      
+      myconfig->shed_gid = $3;
       break;
 
     case TYPE_MAX:
@@ -209,5 +232,6 @@ const char* lookup_token (int t)
 
 void yyerror(char const* s)
 {
-  fprintf(stderr, "%s: couldn't parse \"%s\" at line %d, column %d: %s\n", config, yytext, line, col, s);
+  if (!silent)
+    fprintf(stderr, "%s: couldn't parse \"%s\" at line %d, column %d: %s\n", config, yytext, line, col, s);
 }
index 7a2944c0039a6441e218b49ccddcbc5d46ff7e66..4d5f24cfefe86fdd6064f570cbb4ef9c39ad99e9 100644 (file)
@@ -91,6 +91,7 @@ extern int editor_main (int argc, char **argv);
 
 struct dg_config *myconfig = NULL;
 char* config = NULL;
+int silent = 0;
 
 struct dg_config defconfig = {
   /* chroot = */ "/var/lib/dgamelaunch/",
@@ -1467,9 +1468,22 @@ main (int argc, char** argv)
   /* for chroot and program execution */
   char atrcfilename[81], *spool;
   unsigned int len;
+  int i;
 
-  if (argc == 2)
-    config = strdup(argv[1]);
+  for (i = 1; i < argc; i++)
+  {
+    if (!strcmp(argv[i], "-q")) silent = 1;
+    else 
+    {
+      if (config)
+      {
+       if (!silent)
+         fprintf(stderr, "warning: using %s\n", argv[i]);
+       free(config);
+      }
+      config = strdup(argv[i]);
+    }
+  }
   
   create_config();
 
index 9fdd20464d049cbe6a6bb8b3e5eb90543f40f7a8..09df739ee23a5a84b3d9ce6d030cae57cbbbc16f 100644 (file)
@@ -1,20 +1,25 @@
-/* This is a sample dgamelaunch configuration file. Comments like this as
-   well as bash-style comments are allowed in this configuration file. Each
-   configuration option will be explained along with its default value. */
+# This is a sample dgamelaunch configuration file. Only bash-style comments
+# are allowed, such as this. Each configuration option will be explained
+# along with its default value. 
+
+# The following two options are fairly insecure. They will force us to 
+# load the password/group database into memory while still having root
+# privileges. Replace them with shed_uid/shed_gid entries as soon as
+# possible if you decide to use them. dgamelaunch will inform you of
+# the uids/gids corresponding to your choices when it loads.
+#
+# Note that shed_uid and shed_gid will always take precedence over
+# shed_user and shed_group if they are specified.
 
 # shed_user: username to shed privileges to
 shed_user = "games"
-
 # shed_group: group name to shed privileges to
 shed_group = "games"
 
-# Alternatively, you may use the respective gids/uids. This is for Debian:
+# Preferably, you may use the respective gids/uids. This is for Debian:
 shed_uid = 5
 shed_gid = 60
 
-# Note that shed_user and shed_group will always take precedence over
-# shed_uid and shed_gid.
-
 # Max amount of registered users to allow.
 maxusers = 64000
 
index 1261c64ee0c3c736481c761e13b0e4082f8efa57..57a143dc8826f31b74045b30747ed6fa27673753 100644 (file)
@@ -59,6 +59,7 @@ extern char* config; /* file path */
 extern struct dg_config *myconfig;
 extern char *chosen_name;
 extern int loggedin;
+extern int silent;
 
 /* dgamelaunch.c */
 extern void create_config(void);