support 'nethack --nethackrc=~/File'
Substitute $HOME/File if command line specifies --nethackrc=~/File to avoid "Access to ~/File denied (2)". Only implemented for opening run-time config file on Unix. Works for NETHACKOPTIONS=@~/File too; the normally optional at-sign is required since the tilde won't match a slash to distinguish file versus options. Only supports "~/" file path prefix, not "~user/".
This commit is contained in:
@@ -2479,6 +2479,8 @@ Unix: add ../include/nhlua.h to the alloc.o dependencies in Makefile.utl to
|
|||||||
Unix: implement SELF_RECOVER compile-time option, on by default on linux
|
Unix: implement SELF_RECOVER compile-time option, on by default on linux
|
||||||
Unix: allow build to succeed with musl (instead of glibc), by specifying
|
Unix: allow build to succeed with musl (instead of glibc), by specifying
|
||||||
musl=1 on the make command line
|
musl=1 on the make command line
|
||||||
|
Unix: support tilde expansion for home directory path, "~/relative-path", in
|
||||||
|
command line --nethackrc=path and environment NETHACKOPTIONS=@path
|
||||||
user_sounds: move the message hook from inside individual window display ports
|
user_sounds: move the message hook from inside individual window display ports
|
||||||
to the core where it allows MSGTYP_NOSHOW msgtyp's to still trigger
|
to the core where it allows MSGTYP_NOSHOW msgtyp's to still trigger
|
||||||
sounds to correct a reported github issue; also fixes a past reported
|
sounds to correct a reported github issue; also fixes a past reported
|
||||||
|
|||||||
@@ -242,6 +242,13 @@ fopen_config_file(const char *filename, int src)
|
|||||||
if (filename && *filename) {
|
if (filename && *filename) {
|
||||||
set_configfile_name(filename);
|
set_configfile_name(filename);
|
||||||
#ifdef UNIX
|
#ifdef UNIX
|
||||||
|
if (!strncmp(configfile, "~/", 2) && (envp = nh_getenv("HOME")) != 0) {
|
||||||
|
/* support for command line '--nethackrc=~/path' (or for
|
||||||
|
NETHACKOPTIONS='@~/path'; we don't support ~user/path) */
|
||||||
|
Snprintf(tmp_config, sizeof tmp_config, "%s/%s",
|
||||||
|
envp, configfile + 2); /* insert $HOME/ and remove ~/ */
|
||||||
|
set_configfile_name(tmp_config);
|
||||||
|
}
|
||||||
if (access(configfile, 4) == -1) { /* 4 is R_OK on newer systems */
|
if (access(configfile, 4) == -1) { /* 4 is R_OK on newer systems */
|
||||||
/* nasty sneaky attempt to read file through
|
/* nasty sneaky attempt to read file through
|
||||||
* NetHack's setuid permissions -- this is the only
|
* NetHack's setuid permissions -- this is the only
|
||||||
|
|||||||
Reference in New Issue
Block a user