Apply sysconf EXPLORERS restriction on startup

The sysconf EXPLORERS list restricting access to explore mode was being
evaluated and used when a player used the #exploremode command in-game,
or when specifying -X or OPTIONS=playmode:explore on the command line
when resuming a normal game, but not when starting an entirely new game.
When SYSCF is avilable, check for authorization early, similar to debug
mode authorization, to restrict access to explore mode to EXPLORERS
under (hopefully) all circumstances.
This commit is contained in:
Michael Meyer
2023-11-07 15:38:08 -08:00
committed by PatR
parent 4f405b77ce
commit 85b727c92c
9 changed files with 86 additions and 16 deletions
+3
View File
@@ -2123,6 +2123,7 @@ extern int dohistory(void);
extern void chdirx(char *, boolean); extern void chdirx(char *, boolean);
#endif /* CHDIR */ #endif /* CHDIR */
extern boolean authorize_wizard_mode(void); extern boolean authorize_wizard_mode(void);
extern boolean authorize_explore_mode(void);
#endif #endif
#if defined(WIN32) #if defined(WIN32)
extern int getlock(void); extern int getlock(void);
@@ -3100,6 +3101,7 @@ extern void port_help(void);
#endif #endif
extern void sethanguphandler(void(*)(int)); extern void sethanguphandler(void(*)(int));
extern boolean authorize_wizard_mode(void); extern boolean authorize_wizard_mode(void);
extern boolean authorize_explore_mode(void);
extern void append_slash(char *); extern void append_slash(char *);
extern boolean check_user_string(const char *); extern boolean check_user_string(const char *);
extern char *get_login_name(void); extern char *get_login_name(void);
@@ -3264,6 +3266,7 @@ extern void chdirx(const char *, boolean);
#endif /* CHDIR */ #endif /* CHDIR */
extern void sethanguphandler(void(*)(int)); extern void sethanguphandler(void(*)(int));
extern boolean authorize_wizard_mode(void); extern boolean authorize_wizard_mode(void);
extern boolean authorize_explore_mode(void);
/* ### vmsmisc.c ### */ /* ### vmsmisc.c ### */
+1 -6
View File
@@ -965,10 +965,7 @@ enter_explore_mode(void)
} else { } else {
const char *oldmode = !wizard ? "normal game" : "debug mode"; const char *oldmode = !wizard ? "normal game" : "debug mode";
#ifdef SYSCF if (!authorize_explore_mode()) {
#if defined(UNIX)
if (!sysopt.explorers || !sysopt.explorers[0]
|| !check_user_string(sysopt.explorers)) {
if (!wizard) { if (!wizard) {
You("cannot access explore mode."); You("cannot access explore mode.");
return ECMD_OK; return ECMD_OK;
@@ -978,8 +975,6 @@ enter_explore_mode(void)
/* keep going */ /* keep going */
} }
} }
#endif
#endif
pline("Beware! From explore mode there will be no return to %s,", pline("Beware! From explore mode there will be no return to %s,",
oldmode); oldmode);
if (paranoid_query(ParanoidQuit, if (paranoid_query(ParanoidQuit,
+5 -2
View File
@@ -10257,11 +10257,14 @@ set_playmode(void)
gp.plnamelen = (int) strlen(strcpy(gp.plname, "wizard")); gp.plnamelen = (int) strlen(strcpy(gp.plname, "wizard"));
else else
wizard = FALSE; /* not allowed or not available */ wizard = FALSE; /* not allowed or not available */
/* force explore mode if we didn't make it into wizard mode */ /* try explore mode if we didn't make it into wizard mode */
discover = !wizard; discover = !wizard;
iflags.deferred_X = FALSE; iflags.deferred_X = FALSE;
} }
/* don't need to do anything special for explore mode or normal play */ if (discover && !authorize_explore_mode()) {
discover = iflags.deferred_X = FALSE;
}
/* don't need to do anything special for normal play */
} }
static void static void
+2 -2
View File
@@ -560,8 +560,8 @@ restgamestate(NHFILE *nhfp)
if (newgameflags.debug) { if (newgameflags.debug) {
/* authorized by startup code; wizard mode exists and is allowed */ /* authorized by startup code; wizard mode exists and is allowed */
wizard = TRUE, discover = iflags.deferred_X = FALSE; wizard = TRUE, discover = iflags.deferred_X = FALSE;
} else if (wizard) { } else if (wizard || discover) {
/* specified by save file; check authorization now */ /* specified by save file; check authorization now. */
set_playmode(); set_playmode();
} }
role_init(); /* Reset the initial role, race, gender, and alignment */ role_init(); /* Reset the initial role, race, gender, and alignment */
+27 -3
View File
@@ -50,7 +50,7 @@ extern void init_linux_cons(void);
#endif #endif
static void wd_message(void); static void wd_message(void);
static boolean wiz_error_flag = FALSE; static boolean wiz_error_flag = FALSE, explore_error_flag = FALSE;
static struct passwd *get_unix_pw(void); static struct passwd *get_unix_pw(void);
#ifdef __EMSCRIPTEN__ #ifdef __EMSCRIPTEN__
@@ -605,6 +605,22 @@ authorize_wizard_mode(void)
return FALSE; return FALSE;
} }
/* similar to above, validate explore mode access */
boolean
authorize_explore_mode(void)
{
#ifdef SYSCF
if (sysopt.explorers && sysopt.explorers[0]) {
if (check_user_string(sysopt.explorers))
return TRUE;
}
explore_error_flag = TRUE; /* not being allowed into explore mode */
return FALSE;
#else
return TRUE; /* if sysconf disabled, no restrictions on explore mode */
#endif
}
static void static void
wd_message(void) wd_message(void)
{ {
@@ -614,9 +630,17 @@ wd_message(void)
pline("Only user%s %s may access debug (wizard) mode.", pline("Only user%s %s may access debug (wizard) mode.",
strchr(sysopt.wizards, ' ') ? "s" : "", tmp); strchr(sysopt.wizards, ' ') ? "s" : "", tmp);
free(tmp); free(tmp);
} else } else {
You("cannot access debug (wizard) mode.");
}
wizard = 0; /* (paranoia) */
if (!explore_error_flag) {
pline("Entering explore/discovery mode instead."); pline("Entering explore/discovery mode instead.");
wizard = 0, discover = 1; /* (paranoia) */ discover = 1;
}
} else if (explore_error_flag) {
You("cannot access explore mode."); /* same as enter_explore_mode */
discover = 0; /* (more paranoia) */
} else if (discover) } else if (discover)
You("are in non-scoring explore/discovery mode."); You("are in non-scoring explore/discovery mode.");
} }
+7
View File
@@ -720,6 +720,13 @@ authorize_wizard_mode(void)
return FALSE; return FALSE;
} }
/* similar to above, validate explore mode access */
boolean
authorize_explore_mode(void)
{
return TRUE; /* no restrictions on explore mode */
}
#ifdef EXEPATH #ifdef EXEPATH
#ifdef __DJGPP__ #ifdef __DJGPP__
#define PATH_SEPARATOR '/' #define PATH_SEPARATOR '/'
+27 -3
View File
@@ -53,7 +53,7 @@ extern void init_linux_cons(void);
#endif #endif
static void wd_message(void); static void wd_message(void);
static boolean wiz_error_flag = FALSE; static boolean wiz_error_flag = FALSE, explore_error_flag = FALSE;
static struct passwd *get_unix_pw(void); static struct passwd *get_unix_pw(void);
int int
@@ -964,6 +964,22 @@ authorize_wizard_mode(void)
return FALSE; return FALSE;
} }
/* similar to above, validate explore mode access */
boolean
authorize_explore_mode(void)
{
#ifdef SYSCF
if (sysopt.explorers && sysopt.explorers[0]) {
if (check_user_string(sysopt.explorers))
return TRUE;
}
explore_error_flag = TRUE; /* not being allowed into explore mode */
return FALSE;
#else
return TRUE; /* if sysconf disabled, no restrictions on explore mode */
#endif
}
static void static void
wd_message(void) wd_message(void)
{ {
@@ -973,9 +989,17 @@ wd_message(void)
pline("Only user%s %s may access debug (wizard) mode.", pline("Only user%s %s may access debug (wizard) mode.",
strchr(sysopt.wizards, ' ') ? "s" : "", tmp); strchr(sysopt.wizards, ' ') ? "s" : "", tmp);
free(tmp); free(tmp);
} else } else {
You("cannot access debug (wizard) mode.");
}
wizard = 0; /* (paranoia) */
if (!explore_error_flag) {
pline("Entering explore/discovery mode instead."); pline("Entering explore/discovery mode instead.");
wizard = 0, discover = 1; /* (paranoia) */ discover = 1;
}
} else if (explore_error_flag) {
You("cannot access explore mode."); /* same as enter_explore_mode */
discover = 0; /* (more paranoia) */
} else if (discover) } else if (discover)
You("are in non-scoring explore/discovery mode."); You("are in non-scoring explore/discovery mode.");
} }
+7
View File
@@ -484,6 +484,13 @@ authorize_wizard_mode(void)
return FALSE; return FALSE;
} }
/* similar to above, validate explore mode access */
boolean
authorize_explore_mode(void)
{
return TRUE; /* no restrictions on explore mode */
}
static void static void
wd_message(void) wd_message(void)
{ {
+7
View File
@@ -1021,6 +1021,13 @@ authorize_wizard_mode(void)
return FALSE; return FALSE;
} }
/* similar to above, validate explore mode access */
boolean
authorize_explore_mode(void)
{
return TRUE; /* no restrictions on explore mode */
}
#define PATH_SEPARATOR '\\' #define PATH_SEPARATOR '\\'
#if defined(WIN32) && !defined(WIN32CON) #if defined(WIN32) && !defined(WIN32CON)