From fe006b9c0a96398b23d5471705a8e718e2654745 Mon Sep 17 00:00:00 2001 From: Pasi Kallinen Date: Fri, 5 Feb 2016 20:39:13 +0200 Subject: [PATCH] Add CHECK_PLNAME to sysconf Setting CHECK_PLNAME to 1 makes WIZARDS, EXPLORERS, and SHELLERS check the player name instead of the user's login name. This is mostly useful for public servers which have external login system and don't create user accounts for players. --- doc/Guidebook.mn | 4 ++++ doc/Guidebook.tex | 4 ++++ doc/fixes36.1 | 2 ++ include/sys.h | 1 + src/files.c | 4 ++++ src/sys.c | 1 + sys/unix/sysconf | 4 ++++ sys/unix/unixmain.c | 9 +++++++-- 8 files changed, 27 insertions(+), 2 deletions(-) diff --git a/doc/Guidebook.mn b/doc/Guidebook.mn index f03853b6c..a6a39f441 100644 --- a/doc/Guidebook.mn +++ b/doc/Guidebook.mn @@ -3276,6 +3276,10 @@ SEDUCE 0 or 1 to disable or enable, respectively, the SEDUCE option (see the source for details on this function). .lp +CHECK_PLNAME +Setting this to 1 will make the EXPLORERS, WIZARDS, and SHELLERS check +for the player name instead of the user's login name. +.lp CHECK_SAVE_UID 0 or 1 to disable or enable, respectively, the UID checking for savefiles. .pg diff --git a/doc/Guidebook.tex b/doc/Guidebook.tex index 110f4248c..5f13e784f 100644 --- a/doc/Guidebook.tex +++ b/doc/Guidebook.tex @@ -3905,6 +3905,10 @@ A string explaining how to recover a game on this system (no default value). 0 or 1 to disable or enable, respectively, the SEDUCE option (see the source) for details on this function. %.lp +\item[\ib{CHECK\verb+_+PLNAME}] +Setting this to 1 will make the EXPLORERS, WIZARDS, and SHELLERS check +for the player name instead of the user's login name. +%.lp \item[\ib{CHECK\verb+_+SAVE\verb+_+UID}] 0 or 1 to disable or enable, respectively, the UID checking for savefiles. \elist diff --git a/doc/fixes36.1 b/doc/fixes36.1 index f8bb03ff7..47120a06d 100644 --- a/doc/fixes36.1 +++ b/doc/fixes36.1 @@ -179,6 +179,8 @@ X11: enable a scroll bar in menu windows X11: support pre-selected entries in menu windows X11: make the extended command menu be easier to use and look a little nicer X11: make the getline text entry widget display a bigger text entry area +unix: add CHECK_PLNAME-option to sysconf to make WIZARDS, EXPLORERS, and + SHELLERS check player name instead of user's login name General New Features diff --git a/include/sys.h b/include/sys.h index 10b7c3c5f..d2989a842 100644 --- a/include/sys.h +++ b/include/sys.h @@ -22,6 +22,7 @@ struct sysopt { int maxplayers; int seduce; int check_save_uid; /* restoring savefile checks UID? */ + int check_plname; /* use plname for checking wizards/explorers/shellers */ /* record file */ int persmax; diff --git a/src/files.c b/src/files.c index f8a767257..8553bc309 100644 --- a/src/files.c +++ b/src/files.c @@ -2264,6 +2264,10 @@ int src; && match_varname(buf, "CHECK_SAVE_UID", 14)) { n = atoi(bufp); sysopt.check_save_uid = n; + } else if (src == SET_IN_SYS + && match_varname(buf, "CHECK_PLNAME", 12)) { + n = atoi(bufp); + sysopt.check_plname = n; } else if (match_varname(buf, "SEDUCE", 6)) { n = !!atoi(bufp); /* XXX this could be tighter */ /* allow anyone to turn it off, but only sysconf to turn it on*/ diff --git a/src/sys.c b/src/sys.c index 96c080ea4..c56e75fec 100644 --- a/src/sys.c +++ b/src/sys.c @@ -72,6 +72,7 @@ sys_early_init() #endif sysopt.check_save_uid = 1; + sysopt.check_plname = 0; sysopt.seduce = 1; /* if it's compiled in, default to on */ sysopt_seduce_set(sysopt.seduce); return; diff --git a/sys/unix/sysconf b/sys/unix/sysconf index 1347a7a9e..85ab25bf7 100644 --- a/sys/unix/sysconf +++ b/sys/unix/sysconf @@ -30,6 +30,10 @@ EXPLORERS=* # Uses the same syntax as the WIZARDS and EXPLORERS options above. #SHELLERS= +# Use the player name for matching WIZARDS, EXPLORERS and SHELLERS, +# instead of the user's login name. +#CHECK_PLNAME=1 + # Limit the number of simultaneous games (see also nethack.sh). # Valid values are 0-25. # Commenting this out or setting the value to 0 constructs lock files diff --git a/sys/unix/unixmain.c b/sys/unix/unixmain.c index 506618f14..2d6452ce8 100644 --- a/sys/unix/unixmain.c +++ b/sys/unix/unixmain.c @@ -621,11 +621,16 @@ char *optstr; struct passwd *pw = get_unix_pw(); int pwlen; char *eop, *w; + char *pwname; if (optstr[0] == '*') return TRUE; /* allow any user */ if (!pw) return FALSE; - pwlen = strlen(pw->pw_name); + if (sysopt.check_plname) + pwname = plname; + else + pwname = pw->pw_name; + pwlen = strlen(pwname); eop = eos(optstr); w = optstr; while (w + pwlen <= eop) { @@ -635,7 +640,7 @@ char *optstr; w++; continue; } - if (!strncmp(w, pw->pw_name, pwlen)) { + if (!strncmp(w, pwname, pwlen)) { if (!w[pwlen] || isspace(w[pwlen])) return TRUE; } -- 2.40.0