Bug 22174

Summary: bash reads rcfile when it shouldn't
Product: [Retired] Red Hat Linux Reporter: Tim Waugh <twaugh>
Component: bashAssignee: Bernhard Rosenkraenzer <bero>
Status: CLOSED NOTABUG QA Contact: David Lawrence <dkl>
Severity: medium Docs Contact:
Priority: medium    
Version: 7.0CC: alburrow, dr
Target Milestone: ---   
Target Release: ---   
Hardware: i386   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2000-12-13 10:37:07 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Tim Waugh 2000-12-12 18:25:50 UTC
[root@turmoil /root]# id; id user
uid=0(root) gid=0(root)
groups=0(root),1(bin),2(daemon),3(sys),4(adm),6(disk),10(wheel)
uid=500(user) gid=500(user) groups=500(user)
[root@turmoil /root]# grep ^user /etc/passwd
user:x:500:500::/home/user:/bin/bash
[root@turmoil /root]# su user -c ':'
bash: /root/.bashrc: Permission denied
[root@turmoil /root]# strace -feexecve su user -c ':' 2>&1 | grep bash
[pid  1399] execve("/bin/bash", ["bash", "-c", ":"], [/* 25 vars */]) = 0
bash: /root/.bashrc: Permission denied

The man page says that 'bash -c :' should not be considered interactive,
and only interactive shells should read .bashrc.

Comment 1 Tim Waugh 2001-02-01 23:39:23 UTC
Thi only happens with BASH_ENV set, just like the documentation says.  Thanks to
Chet Ramey for diagnosing.

Comment 2 Need Real Name 2002-02-03 22:15:37 UTC
This bug should be reopened for RedHat 7.2 and openssh-2.9p2-12.
OpenSSH is causing the "~/.bashrc" file to be read for 
non-interactive shells.

To see this do the following.

  + For each F in "/etc/ssh/sshrc", "~/.ssh/rc", "/etc/profile",
                  "~/.bash_profile", "/etc/bashrc", and "~/.bashrc"
    on the host and target account do the following.

      - Prepend the lines (replacing %F with the filename)

echo "In %F for USER=\"${USER}\"," >> /tmp/ssh-errors.txt
echo "with PS1=\"${PS1}\"," >> /tmp/ssh-errors.txt
echo "with ENV=\"${ENV}\", and" >> /tmp/ssh-errors.txt
echo "with BASH_ENV=\"${BASH_ENV}\"." >> /tmp/ssh-errors.txt

      - Comment out the usual references to other rc files.


Now for a warm up see what happens when you execute

    /bin/bash -c "/usr/bin/env"

from within the target account.  According to 

    http://www.snailbook.com/faq/sftp-corruption.auto.html

this is the intended effect of running ssh, scp, etc.  So have
a look at "/tmp/ssh-errors.txt".  On my RedHat 7.2 box it remains
empty because this is neither a login nor an interactive shell.


However, when we do the same from another RedHat 7.2 host via
the OpenSSH command

    ssh andrew@hostname "/usr/bin/env"

"/tmp/ssh-errors.txt" now contains the lines

In .ssh/rc for USER="andrew",
with PS1="",
with ENV="", and
with BASH_ENV="".
In .bashrc for USER="andrew",
with PS1="",
with ENV="", and
with BASH_ENV="".

The first reference is expected.  The sshd(8) manpage explains
that "~/.ssh/rc" wil be sourced, but there is no explanation
for "~/.bashrc" being sourced.  Not even the one caused by
the earlier RedHat practice of setting ENV to this file.
Furthermore, the shell is clearly non-interactive because PS1
is _not_ set.

This is _very_ annoying because it means there is nowhere
to put stty commands or send messages at login, because
OpenSSH wil stupidly invoke these interactive shell resources.


Thanks

Andrew


Comment 3 Need Real Name 2002-02-03 22:20:49 UTC
My mistake --- wrong bug report number, I'll go and affix this
to an OpenSSH bug where I thought I was typing it.