Add ability to change location of passwd and lockfile.

git-svn-id: svn://katsu.triplehelix.org/dgamelaunch/trunk@137 db0b04b0-f4d1-0310-9a6d-de3e77497b0e
This commit is contained in:
Joshua Kwan 2004-01-21 01:57:44 +00:00
parent 7c8eebf836
commit 8b9c796b10
5 changed files with 34 additions and 10 deletions

View File

@ -59,6 +59,8 @@ LONGCOMMENT "/*"
"spooldir" { return TYPE_PATH_SPOOL; }
"banner" { return TYPE_PATH_BANNER; }
"rc_template" { return TYPE_PATH_CANNED; }
"passwd" { return TYPE_PATH_PASSWD; }
"lockfile" { return TYPE_PATH_LOCKFILE; }
\n { line++; col = 0; }

View File

@ -26,6 +26,7 @@ static const char* lookup_token (int t);
%token TYPE_SUSER TYPE_SGROUP TYPE_SGID TYPE_SUID TYPE_MAX
%token TYPE_PATH_NETHACK TYPE_PATH_DGLDIR TYPE_PATH_SPOOL
%token TYPE_PATH_BANNER TYPE_PATH_CANNED TYPE_PATH_CHROOT
%token TYPE_PATH_PASSWD TYPE_PATH_LOCKFILE
%token <s> TYPE_VALUE
%token <i> TYPE_NUMBER
%type <kt> KeyType
@ -84,32 +85,42 @@ KeyPair: KeyType '=' TYPE_VALUE {
case TYPE_PATH_CHROOT:
if (myconfig->chroot) free(myconfig->chroot);
myconfig->chroot = strdup ($3);
myconfig->chroot = strdup ($3);
break;
case TYPE_PATH_NETHACK:
if (myconfig->nethack) free(myconfig->nethack);
myconfig->nethack = strdup ($3);
myconfig->nethack = strdup ($3);
break;
case TYPE_PATH_DGLDIR:
if (myconfig->dglroot) free(myconfig->dglroot);
myconfig->dglroot = strdup ($3);
myconfig->dglroot = strdup ($3);
break;
case TYPE_PATH_BANNER:
if (myconfig->banner) free(myconfig->banner);
myconfig->banner = strdup($3);
myconfig->banner = strdup($3);
break;
case TYPE_PATH_CANNED:
if (myconfig->rcfile) free(myconfig->rcfile);
myconfig->rcfile = strdup($3);
myconfig->rcfile = strdup($3);
break;
case TYPE_PATH_SPOOL:
if (myconfig->spool) free (myconfig->spool);
myconfig->spool = strdup($3);
myconfig->spool = strdup($3);
break;
case TYPE_PATH_LOCKFILE:
if (myconfig->lockfile) free (myconfig->lockfile);
myconfig->lockfile = strdup($3);
break;
case TYPE_PATH_PASSWD:
if (myconfig->passwd) free(myconfig->passwd);
myconfig->passwd = strdup($3);
break;
default:
@ -171,6 +182,8 @@ KeyType : TYPE_SUSER { $$ = TYPE_SUSER; }
| TYPE_PATH_SPOOL { $$ = TYPE_PATH_SPOOL; }
| TYPE_PATH_BANNER { $$ = TYPE_PATH_BANNER; }
| TYPE_PATH_CANNED { $$ = TYPE_PATH_CANNED; }
| TYPE_PATH_PASSWD { $$ = TYPE_PATH_PASSWD; }
| TYPE_PATH_LOCKFILE { $$ = TYPE_PATH_LOCKFILE; }
;
%%

View File

@ -109,6 +109,8 @@ struct dg_config defconfig = {
"/var/lib/dgamelaunch/",
"/bin/nethack",
"/dgldir/",
"/dgl-lock",
"/dgl-login",
"/dgl-banner",
"/dgl-default-rcfile",
"/var/mail/",
@ -1000,14 +1002,14 @@ readfile (int nolock)
if (!nolock)
{
fpl = fopen ("/dgl-lock", "r");
fpl = fopen (myconfig->lockfile, "r");
if (!fpl)
graceful_exit (106);
if (fcntl (fileno (fpl), F_SETLKW, &fl) == -1)
graceful_exit (114);
}
fp = fopen ("/dgl-login", "r");
fp = fopen (myconfig->passwd, "r");
if (!fp)
graceful_exit (106);
@ -1191,7 +1193,7 @@ writefile (int requirenew)
fl.l_start = 0;
fl.l_len = 0;
fpl = fopen ("/dgl-lock", "r+");
fpl = fopen (myconfig->lockfile, "r+");
if (!fpl)
graceful_exit (115);
if (fcntl (fileno (fpl), F_SETLK, &fl))
@ -1202,7 +1204,7 @@ writefile (int requirenew)
freefile ();
readfile (1);
fp = fopen ("/dgl-login", "w");
fp = fopen (myconfig->passwd, "w");
if (!fp)
graceful_exit (104);

View File

@ -38,4 +38,9 @@ banner = "/dgl-banner"
# From inside the jail, the default .nethackrc that is copied for new users.
rc_template = "/dgl-default-rcfile"
# The defaults are usually just fine for this. passwd refers to the file
# that stores the user database, and lockfile is only used internally by
# dgamelaunch.
passwd = "/dgl-login"
lockfile = "/dgl-lock"

View File

@ -42,6 +42,8 @@ struct dg_config
char* chroot;
char* nethack;
char* dglroot;
char* lockfile;
char* passwd;
char* banner;
char* rcfile;
char* spool;