fix github pull request #26 - validating #explore

Fixes #26

Report stated that the attempt to look up the player's username
(on Unix) failed (reason unknown) and nethack refused to allow the
player to execute the #explore command even though sysconf was set
to use character names (CHECK_PLNAME=1) instead of user names.
Setting EXPLORERS to "*" overcomes this glitch, but the fix moves
a bit of code around to honor CHECK_PLNAME before fetching username
so that that isn't necessary.

I ended up doing some formattng clean up (replace tabs with spaces,
whitespace cleanup in 'port_insert_pastebuf()').  The actual change
to fix #26 is only a few lines.
This commit is contained in:
PatR
2019-10-06 17:30:18 -07:00
parent 193f8c39bd
commit 80d3abcf00
2 changed files with 28 additions and 25 deletions

View File

@@ -1,4 +1,4 @@
$NHDT-Branch: NetHack-3.6 $:$NHDT-Revision: 1.125 $ $NHDT-Date: 1570318925 2019/10/05 23:42:05 $ $NHDT-Branch: NetHack-3.6 $:$NHDT-Revision: 1.126 $ $NHDT-Date: 1570408209 2019/10/07 00:30:09 $
This fixes36.3 file is here to capture information about updates in the 3.6.x This fixes36.3 file is here to capture information about updates in the 3.6.x
lineage following the release of 3.6.2 in May 2019. Please note, however, lineage following the release of 3.6.2 in May 2019. Please note, however,
@@ -209,6 +209,8 @@ tty: revert the attempt to fix "message line anomaly: if autodecribe feedback
wrapped to second line, the wrapped portion wasn't erased when a wrapped to second line, the wrapped portion wasn't erased when a
shorter line was shown or getpos was dismissed" because it disrupted shorter line was shown or getpos was dismissed" because it disrupted
prompts that spanned more than one line, a more significant issue prompts that spanned more than one line, a more significant issue
unix: sysconf CHECK_PLNAME=1 wouldn't work if attempt to obtain unix username
failed even though it didn't need that username
Platform- and/or Interface-Specific Fixes or Features Platform- and/or Interface-Specific Fixes or Features

View File

@@ -1,4 +1,4 @@
/* NetHack 3.6 unixmain.c $NHDT-Date: 1432512788 2015/05/25 00:13:08 $ $NHDT-Branch: master $:$NHDT-Revision: 1.52 $ */ /* NetHack 3.6 unixmain.c $NHDT-Date: 1570408210 2019/10/07 00:30:10 $ $NHDT-Branch: NetHack-3.6 $:$NHDT-Revision: 1.70 $ */
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
/*-Copyright (c) Robert Patrick Rankin, 2011. */ /*-Copyright (c) Robert Patrick Rankin, 2011. */
/* NetHack may be freely redistributed. See license for details. */ /* NetHack may be freely redistributed. See license for details. */
@@ -117,7 +117,7 @@ char *argv[];
if (argcheck(argc, argv, ARG_DEBUG) == 1) { if (argcheck(argc, argv, ARG_DEBUG) == 1) {
argc--; argc--;
argv++; argv++;
} }
if (argc > 1 && !strncmp(argv[1], "-d", 2) && argv[1][2] != 'e') { if (argc > 1 && !strncmp(argv[1], "-d", 2) && argv[1][2] != 'e') {
/* avoid matching "-dec" for DECgraphics; since the man page /* avoid matching "-dec" for DECgraphics; since the man page
@@ -262,7 +262,7 @@ char *argv[];
* First, try to find and restore a save file for specified character. * First, try to find and restore a save file for specified character.
* We'll return here if new game player_selection() renames the hero. * We'll return here if new game player_selection() renames the hero.
*/ */
attempt_restore: attempt_restore:
/* /*
* getlock() complains and quits if there is already a game * getlock() complains and quits if there is already a game
@@ -531,8 +531,8 @@ whoami()
{ {
/* /*
* Who am i? Algorithm: 1. Use name as specified in NETHACKOPTIONS * Who am i? Algorithm: 1. Use name as specified in NETHACKOPTIONS
* 2. Use $USER or $LOGNAME (if 1. fails) * 2. Use $USER or $LOGNAME (if 1. fails)
* 3. Use getlogin() (if 2. fails) * 3. Use getlogin() (if 2. fails)
* The resulting name is overridden by command line options. * The resulting name is overridden by command line options.
* If everything fails, or if the resulting name is some generic * If everything fails, or if the resulting name is some generic
* account like "games", "play", "player", "hack" then eventually * account like "games", "play", "player", "hack" then eventually
@@ -654,17 +654,17 @@ char *optstr;
struct passwd *pw = get_unix_pw(); struct passwd *pw = get_unix_pw();
int pwlen; int pwlen;
char *eop, *w; char *eop, *w;
char *pwname; char *pwname = 0;
if (optstr[0] == '*') if (optstr[0] == '*')
return TRUE; /* allow any user */ return TRUE; /* allow any user */
if (!pw)
return FALSE;
if (sysopt.check_plname) if (sysopt.check_plname)
pwname = plname; pwname = plname;
else else if ((pw = get_unix_pw()) != 0)
pwname = pw->pw_name; pwname = pw->pw_name;
pwlen = strlen(pwname); if (!pwname || !*pwname)
return FALSE;
pwlen = (int) strlen(pwname);
eop = eos(optstr); eop = eos(optstr);
w = optstr; w = optstr;
while (w + pwlen <= eop) { while (w + pwlen <= eop) {
@@ -722,7 +722,6 @@ get_login_name()
struct passwd *pw = get_unix_pw(); struct passwd *pw = get_unix_pw();
buf[0] = '\0'; buf[0] = '\0';
if (pw) if (pw)
(void)strcpy(buf, pw->pw_name); (void)strcpy(buf, pw->pw_name);
@@ -739,31 +738,33 @@ char *buf;
/* This should be replaced when there is a Cocoa port. */ /* This should be replaced when there is a Cocoa port. */
const char *errfmt; const char *errfmt;
size_t len; size_t len;
FILE *PB = popen("/usr/bin/pbcopy","w"); FILE *PB = popen("/usr/bin/pbcopy", "w");
if(!PB){
errfmt = "Unable to start pbcopy (%d)\n"; if (!PB) {
goto error; errfmt = "Unable to start pbcopy (%d)\n";
goto error;
} }
len = strlen(buf); len = strlen(buf);
/* Remove the trailing \n, carefully. */ /* Remove the trailing \n, carefully. */
if(buf[len-1] == '\n') len--; if (buf[len - 1] == '\n')
len--;
/* XXX Sorry, I'm too lazy to write a loop for output this short. */ /* XXX Sorry, I'm too lazy to write a loop for output this short. */
if(len!=fwrite(buf,1,len,PB)){ if (len != fwrite(buf, 1, len, PB)) {
errfmt = "Error sending data to pbcopy (%d)\n"; errfmt = "Error sending data to pbcopy (%d)\n";
goto error; goto error;
} }
if(pclose(PB)!=-1){ if (pclose(PB) != -1) {
return; return;
} }
errfmt = "Error finishing pbcopy (%d)\n"; errfmt = "Error finishing pbcopy (%d)\n";
error: error:
raw_printf(errfmt,strerror(errno)); raw_printf(errfmt, strerror(errno));
} }
#endif #endif /* __APPLE__ */
unsigned long unsigned long
sys_random_seed() sys_random_seed()