system-wide configuration file

Add options SYSCF (to add a system-wide configuration file) and SYSCF_FILE
(for a file-based implementation of SYSCF) - this allows a binary distribution
to be configured at install time.  The only option supported at this time is
WIZARDS - a list of usernames which can use -D; currently only for unix-likes
but should be extendable to anything that has a concept of multiple users.
Add mac tty multiuser config using sgid.
This commit is contained in:
keni
2008-01-09 01:57:41 +00:00
parent 9c3f6f78b9
commit f2d37bac2e
17 changed files with 269 additions and 26 deletions

View File

@@ -70,6 +70,9 @@ const char ynNaqchars[] = "yn#aq";
NEARDATA long yn_number = 0L;
const char disclosure_options[] = "iavgc";
#ifdef SYSCF
char wizards[PL_PSIZ] = DUMMY;
#endif
#if defined(MICRO) || defined(WIN32)
char hackdir[PATHLEN]; /* where rumors, help, record are */

View File

@@ -185,7 +185,7 @@ STATIC_DCL boolean FDECL(make_compressed_name, (const char *, char *));
STATIC_DCL char *FDECL(make_lockname, (const char *,char *));
STATIC_DCL FILE *FDECL(fopen_config_file, (const char *));
STATIC_DCL int FDECL(get_uchars, (FILE *,char *,char *,uchar *,BOOLEAN_P,int,const char *));
int FDECL(parse_config_line, (FILE *,char *,char *,char *));
int FDECL(parse_config_line, (FILE *,char *,char *,char *,int));
#ifdef LOADSYMSETS
STATIC_DCL FILE *NDECL(fopen_sym_file);
STATIC_DCL void FDECL(set_symhandling, (char *,int));
@@ -1947,11 +1947,12 @@ int prefixid;
/*ARGSUSED*/
int
parse_config_line(fp, buf, tmp_ramdisk, tmp_levels)
parse_config_line(fp, buf, tmp_ramdisk, tmp_levels, src)
FILE *fp;
char *buf;
char *tmp_ramdisk;
char *tmp_levels;
int src;
{
#if (defined(macintosh) && (defined(__SC__) || defined(__MRC__))) || defined(__MWERKS__)
# pragma unused(tmp_ramdisk,tmp_levels)
@@ -2064,6 +2065,10 @@ char *tmp_levels;
(void) strncpy(dogname, bufp, PL_PSIZ-1);
} else if (match_varname(buf, "CATNAME", 3)) {
(void) strncpy(catname, bufp, PL_PSIZ-1);
#ifdef SYSCF
} else if ( (src==SET_IN_SYS) && match_varname(buf, "WIZARDS", 6)) {
(void) strncpy(wizards, bufp, PL_PSIZ-1);
#endif
} else if (match_varname(buf, "BOULDER", 3)) {
(void) get_uchars(fp, buf, bufp, &iflags.bouldersym, TRUE,
@@ -2267,8 +2272,9 @@ const char *filename;
#endif /* USER_SOUNDS */
void
read_config_file(filename)
read_config_file(filename, src)
const char *filename;
int src;
{
#define tmp_levels (char *)0
#define tmp_ramdisk (char *)0
@@ -2300,7 +2306,14 @@ const char *filename;
set_duplicate_opt_detection(1);
while (fgets(buf, 4*BUFSZ, fp)) {
if (!parse_config_line(fp, buf, tmp_ramdisk, tmp_levels)) {
#ifdef notyet
/*
XXX Don't call read() in parse_config_line, read as callback or reassemble line
at this level.
OR: Forbid multiline stuff for alternate config sources.
*/
#endif
if (!parse_config_line(fp, buf, tmp_ramdisk, tmp_levels, src)) {
raw_printf("Bad option line: \"%.50s\"", buf);
wait_synch();
}

View File

@@ -386,6 +386,9 @@ static struct Comp_Opt
{ "windowcolors", "the foreground/background colors of windows", /*WC*/
80, DISP_IN_GAME },
{ "windowtype", "windowing system to use", WINTYPELEN, DISP_IN_GAME },
#ifdef SYSCF
{ "wizards", "users with access to wizard mode (etc)", PL_PSIZ, SET_IN_SYS},
#endif
#ifdef BACKWARD_COMPAT
{"DECgraphics", "load DECGraphics display symbols", 70, SET_IN_FILE},
{"IBMgraphics", "load IBMGraphics display symbols", 70, SET_IN_FILE},
@@ -547,8 +550,16 @@ const char *ev;
return (char *)0;
}
/* Split initoptions into 2 parts for SYSCF but don't break anything not
* using SYSCF. */
void
initoptions()
initoptions(){
initoptions_init();
initoptions_finish();
}
void
initoptions_init()
{
#ifndef MAC
char *opts;
@@ -671,17 +682,20 @@ initoptions()
/* since this is done before init_objects(), do partial init here */
objects[SLIME_MOLD].oc_name_idx = SLIME_MOLD;
nmcpy(pl_fruit, OBJ_NAME(objects[SLIME_MOLD]), PL_FSIZ);
}
void
initoptions_finish(){
#ifndef MAC
opts = getenv("NETHACKOPTIONS");
char *opts = getenv("NETHACKOPTIONS");
if (!opts) opts = getenv("HACKOPTIONS");
if (opts) {
if (*opts == '/' || *opts == '\\' || *opts == '@') {
if (*opts == '@') opts++; /* @filename */
/* looks like a filename */
if (strlen(opts) < BUFSZ/2)
read_config_file(opts);
read_config_file(opts, SET_IN_FILE);
} else {
read_config_file((char *)0);
read_config_file((char *)0, SET_IN_FILE);
/* let the total length of options be long;
* parseoptions() will check each individually
*/
@@ -689,7 +703,7 @@ initoptions()
}
} else
#endif
read_config_file((char *)0);
read_config_file((char *)0, SET_IN_FILE);
(void)fruitadd(pl_fruit);
/* Remove "slime mold" from list of object names; this will */
@@ -2249,6 +2263,23 @@ goodfruit:
return;
}
#ifdef SYSCF
fullname = "wizards";
if (wizard && match_optname(opts, fullname, 6, TRUE)) {
if (duplicate) {
complain_about_duplicate(opts,1);
return;
}
if (negated) {
bad_negation(fullname, FALSE);
return;
} else if ((op = string_for_env_opt(fullname, opts, FALSE)) != 0) {
nmcpy(wizards, op, PL_PSIZ);
}
return;
}
#endif
/* menustyle:traditional or combo or full or partial */
if (match_optname(opts, "menustyle", 4, TRUE)) {
int tmp;
@@ -2718,6 +2749,13 @@ doset()
"Compounds (selecting will prompt for new value):",
MENU_UNSELECTED);
#ifdef notyet /* SYSCF */
/* XXX I think this is still fragile. Fixing initial/from_file and/or changing
the SET_* etc to bitmaps will let me make this better. */
if(wizard)
startpass = SET_IN_SYS;
else
#endif
startpass = DISP_IN_GAME;
endpass = SET_IN_GAME;
@@ -3451,6 +3489,14 @@ char *buf;
#endif
else if (!strcmp(optname, "catname"))
Sprintf(buf, "%s", catname[0] ? catname : none );
#ifdef SYSCF
else if (!strcmp(optname, "wizards"))
# ifdef KR1ED
Sprintf(buf, "%s", wizards[0] ? wizards : WIZARD_NAME);
# else
Sprintf(buf, "%s", wizards[0] ? wizards : WIZARD);
# endif
#endif
else if (!strcmp(optname, "disclose")) {
for (i = 0; i < NUM_DISCLOSURE_OPTIONS; i++) {
char topt[2];
@@ -4254,13 +4300,12 @@ struct wc_Opt wc2_options[] = {
{(char *)0, 0L}
};
/*
* If a port wants to change or ensure that the
* If a port wants to change or ensure that the SET_IN_SYS,
* SET_IN_FILE, DISP_IN_GAME, or SET_IN_GAME status of an option is
* correct (for controlling its display in the option menu) call
* set_option_mod_status()
* with the second argument of 0,2, or 3 respectively.
* with the appropriate second argument.
*/
void
set_option_mod_status(optnam, status)
@@ -4268,7 +4313,7 @@ const char *optnam;
int status;
{
int k;
if (status < SET_IN_FILE || status > SET_IN_GAME) {
if ( SET__IS_VALUE_VALID(status) ) {
impossible("set_option_mod_status: status out of range %d.",
status);
return;
@@ -4301,7 +4346,7 @@ unsigned long optmask;
int status;
{
int k = 0;
if (status < SET_IN_FILE || status > SET_IN_GAME) {
if ( SET__IS_VALUE_VALID(status) ) {
impossible("set_wc_option_mod_status: status out of range %d.",
status);
return;
@@ -4357,7 +4402,7 @@ unsigned long optmask;
int status;
{
int k = 0;
if (status < SET_IN_FILE || status > SET_IN_GAME) {
if ( SET__IS_VALUE_VALID(status) ) {
impossible("set_wc2_option_mod_status: status out of range %d.",
status);
return;