]> granicus.if.org Git - nethack/commitdiff
honor sysconf SHELLERS on VMS
authorPatR <rankin@nethack.org>
Mon, 16 Nov 2020 02:28:20 +0000 (18:28 -0800)
committerPatR <rankin@nethack.org>
Mon, 16 Nov 2020 02:28:20 +0000 (18:28 -0800)
I was looking into adding a confirmation prompt for '!' and it
isn't very promising due to sequencing issues.  (The check for
whether '!' is allowed should happen before the prompt about
running it but the latter should take place in the core rather
than in the port code.)  In the mean time, I noticed that VMS was
ignoring the SHELLERS value from SYSCF.

Untested implementation of a SHELLERS check on VMS.  Even if it
works, it should not be using $USER as the user name to verify.

Tweaks the Unix implementation of check_user_string() but doesn't
switch the testing loop to the simpler version used by VMS which
is derived from the generic users test used by Qt.

include/extern.h
sys/unix/unixmain.c
sys/unix/unixunix.c
sys/vms/vmsunix.c

index d03b6df89da6b8df0f06423eef0cad2836735497..7b4600174cd9c4ad25bab2c338b18dcda89af46d 100644 (file)
@@ -1,4 +1,4 @@
-/* NetHack 3.7 extern.h        $NHDT-Date: 1603507384 2020/10/24 02:43:04 $  $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.873 $ */
+/* NetHack 3.7 extern.h        $NHDT-Date: 1605493683 2020/11/16 02:28:03 $  $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.878 $ */
 /* Copyright (c) Steve Creps, 1988.                              */
 /* NetHack may be freely redistributed.  See license for details. */
 
@@ -2768,7 +2768,7 @@ E void NDECL(port_help);
 E void FDECL(sethanguphandler, (void (*)(int)));
 E boolean NDECL(authorize_wizard_mode);
 E void FDECL(append_slash, (char *));
-E boolean FDECL(check_user_string, (char *));
+E boolean FDECL(check_user_string, (const char *));
 E char *NDECL(get_login_name);
 E unsigned long NDECL(sys_random_seed);
 #endif /* UNIX */
@@ -2952,6 +2952,9 @@ E char *NDECL(verify_termcap);
 E void NDECL(privoff);
 E void NDECL(privon);
 #endif
+#ifdef SYSCF
+E boolean FDECL(check_user_string, (const char *));
+#endif
 #ifdef SHELL
 E int NDECL(dosh);
 #endif
index 87e2550648aed0ce6db8972ce4737f5fe7e2578a..c6fea0d3b2ec128ebb2a146a7a0c685844ddbf79 100644 (file)
@@ -1,4 +1,4 @@
-/* NetHack 3.7 unixmain.c      $NHDT-Date: 1596498297 2020/08/03 23:44:57 $  $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.87 $ */
+/* NetHack 3.7 unixmain.c      $NHDT-Date: 1605493691 2020/11/16 02:28:11 $  $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.90 $ */
 /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
 /*-Copyright (c) Robert Patrick Rankin, 2011. */
 /* NetHack may be freely redistributed.  See license for details. */
@@ -647,11 +647,11 @@ char *name;
 
 boolean
 check_user_string(optstr)
-char *optstr;
+const char *optstr;
 {
     struct passwd *pw;
     int pwlen;
-    char *eop, *w;
+    const char *eop, *w;
     char *pwname = 0;
 
     if (optstr[0] == '*')
@@ -663,7 +663,7 @@ char *optstr;
     if (!pwname || !*pwname)
         return FALSE;
     pwlen = (int) strlen(pwname);
-    eop = eos(optstr);
+    eop = eos((char *) optstr); /* temporarily cast away 'const' */
     w = optstr;
     while (w + pwlen <= eop) {
         if (!*w)
index 9364200f5baa5386e3c3ba6ec4c85d87eee24326..77d3527db0993bcb6b6f5880adcf9fd655aec075 100644 (file)
@@ -1,4 +1,4 @@
-/* NetHack 3.7 unixunix.c      $NHDT-Date: 1596498298 2020/08/03 23:44:58 $  $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.31 $ */
+/* NetHack 3.7 unixunix.c      $NHDT-Date: 1605493693 2020/11/16 02:28:13 $  $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.32 $ */
 /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
 /*-Copyright (c) Kenneth Lorber, Kensington, Maryland, 2015. */
 /* NetHack may be freely redistributed.  See license for details. */
@@ -271,9 +271,8 @@ dosh()
 #ifdef SYSCF
     if (!sysopt.shellers || !sysopt.shellers[0]
         || !check_user_string(sysopt.shellers)) {
-        /* FIXME: should no longer assume a particular command keystroke,
-           and perhaps ought to say "unavailable" rather than "unknown" */
-        Norep("Unknown command '!'.");
+        /* FIXME: should no longer assume a particular command keystroke */
+        Norep("Unavailable command '!'.");
         return 0;
     }
 #endif
index e6f2fca078a0ae198f72216f6178a00e8293228b..66afa88a2bcf4627bac3c5b4bee07ee3a23fe4ca 100644 (file)
@@ -1,4 +1,4 @@
-/* NetHack 3.7 vmsunix.c       $NHDT-Date: 1596498310 2020/08/03 23:45:10 $  $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.23 $ */
+/* NetHack 3.7 vmsunix.c       $NHDT-Date: 1605493693 2020/11/16 02:28:13 $  $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.24 $ */
 /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
 /*-Copyright (c) Robert Patrick Rankin, 2011. */
 /* NetHack may be freely redistributed.  See license for details. */
@@ -54,7 +54,7 @@ int fd;
     if (fstat(fd, &buf))
         return 0; /* cannot get status */
 #ifndef INSURANCE
-    if (buf.st_size != sizeof(int))
+    if (buf.st_size != sizeof (int))
         return 0; /* not an xlock file */
 #endif
     (void) time(&date);
@@ -62,7 +62,7 @@ int fd;
         int lockedpid; /* should be the same size as hackpid */
         unsigned long status, dummy, code = JPI$_PID;
 
-        if (read(fd, (genericptr_t) &lockedpid, sizeof(lockedpid))
+        if (read(fd, (genericptr_t) &lockedpid, sizeof lockedpid)
             != sizeof(lockedpid)) /* strange ... */
             return 0;
         status = lib$getjpi(&code, &lockedpid, 0, &dummy);
@@ -138,7 +138,7 @@ getlock()
     error(g.locknum ? "Too many hacks running now."
                   : "There is a game in progress under your name.");
 
-gotlock:
+ gotlock:
     fd = creat(g.lock, FCMASK);
     unlock_file(HLOCK);
     if (fd == -1) {
@@ -373,6 +373,45 @@ privon()
 }
 #endif /* CHDIR || SHELL || SECURE */
 
+#ifdef SYSCF
+boolean
+check_user_string(userlist)
+const char *userlist;
+{
+    char usrnambuf[BUFSZ];
+    const char *sptr, *p, *q;
+    int ln;
+
+    if (!strcmp(userlist, "*"))
+        return TRUE;
+
+    /* FIXME: ought to use $getjpi or $getuai to retrieve user name here... */
+    Strcpy(usrnambuf, nh_getenv("USER"));
+    ln = (int) strlen(usrnambuf);
+    if (!ln)
+        return FALSE;
+
+    while ((sptr = strstri(userlist, usrnambuf)) != 0) {
+        /* check for full word: start of list or following a space or comma */
+        if ((sptr == userlist || sptr[-1] == ' ' || sptr[-1] == ',')
+            /* and also preceding a space or comma or at end of list */
+            && (sptr[ln] == ' ' || sptr[ln] == ',' || sptr[ln] == '\0'))
+            return TRUE;
+        /* doesn't match full word, but maybe we got a false hit when
+           looking for "jane" in the list "janedoe jane" so keep going */
+        p = index(sptr + 1, ' ');
+        q = index(sptr + 1, ',');
+        if (!p || (q && q < p))
+            p = q;
+        if (!p)
+            break;
+        userlist = p + 1;
+    }
+
+    return FALSE;
+}
+#endif /* SYSCF */
+
 #if defined(SHELL) || defined(SUSPEND)
 static void
 hack_escape(screen_manip, msg_str)
@@ -406,6 +445,14 @@ unsigned long dosh_pid = 0, /* this should cover any interactive escape */
 int
 dosh()
 {
+#ifdef SYSCF
+    if (!sysopt.shellers || !sysopt.shellers[0]
+        || !check_user_string(sysopt.shellers)) {
+        /* FIXME: should no longer assume a particular command keystroke */
+        Norep("Unavailable command '!'.");
+        return 0;
+    }
+#endif
     return vms_doshell("", TRUE); /* call for interactive child process */
 }
 
@@ -617,7 +664,7 @@ int how; /* 1: exit after traceback; 2: stay in debugger */
            in a last-gasp environment so apply the KISS principle...) */
         DBGCMD("set Module/Calls ; show Calls 18"),
         /* epilogue; "exit" ends the sequence it's part of, but it doesn't
-           seem able to cause program termination end when used separately;
+           seem able to cause program termination when used separately;
            instead of relying on it, we'll redirect debugger input to come
            from the null device so that it'll get an end-of-input condition
            when it tries to get a command from the user */
@@ -844,7 +891,7 @@ const unsigned long lib$initialize[] = { (unsigned long) (void *) vmsexeini };
 #endif
 /*      We also need to link against a linker options file containing:
 sys$library:starlet.olb/Include=(lib$initialize)
-psect_attr=lib$initialize, Con,Usr,noPic,Rel,Gbl,noShr,noExe,Rd,noWrt,Long
+psect_attr=lib$initialize, Con,Rel,Gbl,noShr,noExe,Rd,noWrt
  */
 #endif /* C_LIB$INITIALIZE */
 /* End of debugger hackery. */