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

@ -1332,10 +1332,8 @@ int sh_exec(register const Shnode_t *t, int flags)
if(io)
{
struct openlist *item;
if(np==SYSLOGIN)
type=1;
else if(np==SYSEXEC || np==SYSREDIR) /* 'exec' or 'redirect' */
type=1+!com[1]; /* redirections persist if no args */
if(np==SYSEXEC || np==SYSREDIR) /* 'exec' or 'redirect' */
type=1+!com[1]; /* redirections persist if no args */
else
type = (execflg && !shp->subshell && !shp->st.trapcom[0]);
shp->redir0 = 1;