On Mon, Nov 2, 2020 at 3:13 PM Björn Bidar <[email protected]> wrote:
> >Would you mind to drop a few words what bash does in such cases ?
> It does exactly what ash does with but it load bashrc instead of $ENV like in
> the patch.
> See man bash: "Bash attempts to determine when it is being run with its
> standard input connected to a network connection, as when executed by the
> remote shell daemon, usually rshd, or the secure shell daemon sshd. If bash
> determines it is being run in this fashion, it reads and executes commands
> from ~/.bashrc, if that file exists and is readable."
>
> So this just extends existing functionality.
Keeping in mind that this patch adds a functionality which is distinctly
NOT described by standards, I would like an extended explanation.
Let me guess the purpose why bash does this. ssh probably uses
"sh -c COMMAND" to run user's command when executed in the
"ssh USER@HOST COMMAND" form, and the problem was, this command
was not run with .bashrc pre-executed, unlike the case where user
types it by hand after ssh-ing into the HOST.
So the fix in bash was:
static void run_startup_files () {
...
/* get the rshd/sshd case out of the way first. */
if (interactive_shell == 0 && no_rc == 0 && login_shell == 0 &&
act_like_sh == 0 && command_execution_string)
{
run_by_ssh = (find_variable ("SSH_CLIENT") != (SHELL_VAR *)0) ||
(find_variable ("SSH2_CLIENT") != (SHELL_VAR *)0);
/* If we were run by sshd or we think we were run by rshd, execute
~/.bashrc if we are a top-level shell. */
if ((run_by_ssh || isnetconn (fileno (stdin))) && shell_level < 2)
{
#ifdef SYS_BASHRC
maybe_execute_file (SYS_BASHRC, 1);
#endif
maybe_execute_file (bashrc_file, 1);
return;
}
}
...
main(){
...
/* The startup files are run with `set -e' temporarily disabled. */
if (locally_skip_execution == 0 && running_setuid == 0)
{
old_errexit_flag = exit_immediately_on_error;
exit_immediately_on_error = 0;
run_startup_files ();
exit_immediately_on_error += old_errexit_flag;
}
I can see that ash users also might need their init scripts to be run
for "ssh USER@HOST COMMAND", but ash has no .bashrc analogue as of now.
Your code does not reproduce bash behavior - bash does NOT run $ENV
script, it runs .bashrc script for ssh (see above).
IOW - the patch adds a special-case for ssh which is *different*
from bash.
Please explain your real-world scenario which prompted you
to create the patch.
_______________________________________________
busybox mailing list
[email protected]
http://lists.busybox.net/mailman/listinfo/busybox