1
0
Fork 0
mirror of git://git.code.sf.net/p/cdesktopenv/code synced 2025-03-09 15:50:02 +00:00

Remove 'login' and 'newgrp' builtins: not sane default behaviour

This commit removes the undocumented 'login' and 'newgrp' builtin
commands. They already stopped blocking shell functions by that
name by changing from special to regular builtins in 04b91718 (a
change I forgot to mention in that commit message), but there is
another obnoxious aspect to these: being glorified hooks into
'exec', they replaced your shell session with the external commands
by the same name. This makes argument and error checking
impossible, so if you made so much as a typo, you would be
immediately logged out.

Even if that behaviour is wanted by a few, having it as the default
is user-hostile enough to be called a bug. It also violates the
POSIX definition of the 'newgrp' utility which explicitly says that
it "shall create a new shell execution environment", not replace
the existing one.
https://pubs.opengroup.org/onlinepubs/9699919799/utilities/newgrp.html

Users who do want this behaviour can easily restore it by setting:
	alias login='exec login'
	alias newgrp='exec newgrp'

src/cmd/ksh93/bltins/misc.c:
- As there is no more 'login' builtin, combine b_exec() and
  B_login() functions, which allows eliminating a few variables.
  Note that most of 'exec' was actually implemented in B_login()!

src/cmd/ksh93/data/builtins.c:
- Remove "login" and "newgrp" table entries.

src/cmd/ksh93/include/builtins.h:
- Remove SYSLOGIN parser ID. As this was the first, all the others
  needed renumbering.

src/cmd/ksh93/sh/xec.c:
- Remove SYSLOGIN parser check that made 'login' and 'newgrp' act
  like 'exec' and replace the shell.
This commit is contained in:
Martijn Dekker 2020-06-12 06:57:57 +02:00
parent 7b82c338da
commit d8eba9d112
5 changed files with 56 additions and 63 deletions

View file

@ -32,25 +32,24 @@
* IMPORTANT: The offsets on these macros must be synchronous
* with the order of shtab_builtins[] in data/builtins.c!
*/
#define SYSLOGIN (shgd->bltin_cmds) /* login */
#define SYSEXEC (shgd->bltin_cmds+1) /* exec */
#define SYSREDIR (shgd->bltin_cmds+2) /* redirect */
#define SYSSET (shgd->bltin_cmds+3) /* set */
#define SYSEXEC (shgd->bltin_cmds) /* exec */
#define SYSREDIR (shgd->bltin_cmds+1) /* redirect */
#define SYSSET (shgd->bltin_cmds+2) /* set */
/* : */
#define SYSTRUE (shgd->bltin_cmds+5) /* true */
#define SYSCOMMAND (shgd->bltin_cmds+6) /* command */
#define SYSCD (shgd->bltin_cmds+7) /* cd */
#define SYSBREAK (shgd->bltin_cmds+8) /* break */
#define SYSCONT (shgd->bltin_cmds+9) /* continue */
#define SYSTYPESET (shgd->bltin_cmds+10) /* typeset */
#define SYSTEST (shgd->bltin_cmds+11) /* test */
#define SYSBRACKET (shgd->bltin_cmds+12) /* [ */
#define SYSLET (shgd->bltin_cmds+13) /* let */
#define SYSEXPORT (shgd->bltin_cmds+14) /* export */
#define SYSDOT (shgd->bltin_cmds+15) /* . */
#define SYSRETURN (shgd->bltin_cmds+16) /* return */
#define SYSTRUE (shgd->bltin_cmds+4) /* true */
#define SYSCOMMAND (shgd->bltin_cmds+5) /* command */
#define SYSCD (shgd->bltin_cmds+6) /* cd */
#define SYSBREAK (shgd->bltin_cmds+7) /* break */
#define SYSCONT (shgd->bltin_cmds+8) /* continue */
#define SYSTYPESET (shgd->bltin_cmds+9) /* typeset */
#define SYSTEST (shgd->bltin_cmds+10) /* test */
#define SYSBRACKET (shgd->bltin_cmds+11) /* [ */
#define SYSLET (shgd->bltin_cmds+12) /* let */
#define SYSEXPORT (shgd->bltin_cmds+13) /* export */
#define SYSDOT (shgd->bltin_cmds+14) /* . */
#define SYSRETURN (shgd->bltin_cmds+15) /* return */
#if SHOPT_BASH
# define SYSLOCAL (shgd->bltin_cmds+17) /* local */
# define SYSLOCAL (shgd->bltin_cmds+16) /* local */
#else
# define SYSLOCAL 0
#endif