« New SIte! | Main | Displaying script(1) Logs »

June 05, 2004

User Environment

The idea and fix I got the other day was from Rich Amik. He got the following error when trying to start ss with the -u switch:

ss ľu <user>
Script started, file is <FIFO>
bash: /home/<calling user>/.bashrc: Permission denied

This was because the -u user had no exec (or perhaps, read) permissions on the calling user's .bashrc. This can happen with root, too, if the calling user's home directory is on an NFS file system exported with root mapped to nobody. Rich's suggested solution was to set the HOME environment variable to the -u user's home after ss had become that user, but before the script command was run. This worked.

Rich also asked a question that had come up before. How come the resulting shell had the environment of the calling user? My answer to this had always been that the script command ran the shell, not ss, and that I therefore had no control over the resulting environment. I was about to give Rich this answer, but then I looked again at his reported error message. The shell was attempting to run ${HOME}/.bashrc! Blinding Flash of the Obvious. Setting HOME to the target user's home before running script would cause the shell to run that user's shell startup script(s), at least for bash, so that the resulting shell would have the target user's environment.

I quickly hacked together code to make ss set $ENV{HOME} in perl at the correct place. I added a new switch to ss, '-', as in 'su -'. It does the trick, and will become part of the upcoming release. If you can't wait, a patch to sudoshell to enable this feature is here.

Posted by hbo at June 5, 2004 10:27 AM