Skip to Main Content

Infrastructure Software

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

Multiple defects in default /etc/profile

viloxSep 16 2016 — edited Sep 16 2016

For a long time Solaris is supplied with the same default /etc/profile, with small variations (I attached the current one at the end of the message for reference). Recently, I investigated an issue related to setting up an user environment, had a close look at the /etc/profile, and found mistakes. Here they are.

/etc/profile:

  1. Incorrectly assumes that login shell is always interactive. But login shell may also non-interactively execute some script.

    On script execution, displaying quota, motd and new mail notifications is inappropriate. Non-interactive login shell shall be as much verbose as `hushlogin' shell.

  2. Irrelevantly guesses TERM.

    When gdm starts X-session
    /usr/sbin/gdm-binary
    `- /usr/lib/gdm-simple-slave
       `- /usr/lib/gdm-session-worker
          `- ...
    gdm-session-worker takes care to remove TERM (=sun-color) from session environment. But later, X startup scripts certainly source /etc/profile and resurrect console's TERM=sun-color into X environment. Then TERM=sun-color persists in the environment of each X session process. There is no much hurt from this, but this is ... ugly.

    IMO, guessing TERM is out of /etc/profile business. Why it's here?
  3. Incorrectly assumes that login shell always has `-' in front of it's name. But this is not true, e.g.
    $ bash --login
    In this case the part of /etc/profile, enclosed in [case "$0" in -bash) ... esac] brackets, can not be reached, because `$0' is `bash'.

  4. Incorrectly assumes that only login shell may source /etc/profile. But there is nothing wrong if anybody, due some reasons, reconstructs `login environment' in a separate, non-login shell, e.g.:
    $ env -i TERM=$TERM PATH=$PATH bash --norc
    bash-4.1$ . /etc/profile
    The part of /etc/profile, enclosed in [case "$0" in -bash) ... esac] brackets, shall be executed as for `normal' login, but it shall not, because `$0' is `bash'

    Here is a real life example. Look how X-session is been set up:
    /usr/sbin/gdm-binary
    `- /usr/lib/gdm-simple-slave
       `- /usr/lib/gdm-session-worker
          `- /bin/ksh /etc/gdm/Xsession gnome-session
    Then, in /etc/gdm/Xsession:

    32: # First read /etc/profile and .profile
    33: test -f /etc/profile && . /etc/profile
    34: test -f "$HOME/.profile" && . "$HOME/.profile"

    Again, the part of /etc/profile, enclosed in [case "$0" in -bash) ... esac] brackets, can not be reached, because `$0' is not even `bash', but `/etc/gdm/Xsession'.

The whole point of the items (3,4) is that :

detecting the exact kind of script interpreter by enumerating it's names [case "$0" in -sh | -ksh | -ksh93 | -jsh | -bash | -zsh)] does not work.

Why it's here?

Current (Solaris 11.3) /etc/profile, for reference:

# The profile that all logins get before using their own .profile.

trap ""  2 3

export LOGNAME PATH

if [ "$TERM" = "" ]

then

    if /bin/i386

    then

        TERM=sun-color

    else

        TERM=sun

    fi

    export TERM

fi

#    Login and -su shells get /etc/profile services.

#    -rsh is given its environment in its .profile.

case "$0" in

-sh | -ksh | -ksh93 | -jsh | -bash | -zsh)

    if [ ! -f .hushlogin ]

    then

        /usr/sbin/quota

        #    Allow the user to break the Message-Of-The-Day only.

        trap "trap '' 2"  2

        /bin/cat -s /etc/motd

        trap "" 2

        /bin/mail -E

        case $? in

        0)

            echo "You have new mail."

              ;;

        2)

            echo "You have mail."

               ;;

        esac

    fi

esac

umask 022

trap  2 3

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 14 2016
Added on Sep 16 2016
0 comments
536 views