Config file blues.. add silent option on command line
git-svn-id: svn://katsu.triplehelix.org/dgamelaunch/trunk@198 db0b04b0-f4d1-0310-9a6d-de3e77497b0e
This commit is contained in:
parent
8ef19f7ecc
commit
99e9e4997b
62
config.y
62
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);
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue