dragorn wrote:
On Mon, Nov 12, 2012 at 12:06:58AM -0500, Adam wrote:
I ran across a strange inconsistency today.  What should

     su -l -c 'echo $PATH'

return when run by an ordinary user (who happens to know the root
password) at the bash prompt?  Under Mandriva and CentOS it returns
the user's path, but under Debian it returns root's path.  I don't
understand the inconsistency or which response is correct, but that
would seem to make some shell scripts non-portable.
Sudo can be configured to pass or filter environment variables.  This
may be an artifact of that.

Thanks for your very informative reply! It just seems strange to me that the same command (even if unlikely and unsafe) should produce different yet successful results under different distros.

You should NEVER trust path, especially not path supplied by a user,
in a root script, so this shouldn't affect anything.

Yes, full paths for everything in a script. This also avoids any aliases for the programs it uses. BTW 'sudo' seems to have trouble finding executables, even if the full path is specified. Also, one piece of Java in a script called by my script fails (the Java code can't find something) on some distros (Java and sudo versions) but works in others when my script is invoked with sudo. With 'su' and 'su -' it always succeeds. I don't quite understand why, but as a workaround I'll just specify that my script must be invoked with 'su' or 'su -'.

this goes back to one of the original unix hacks of "get root to put
'.' in his path" and "i can't see a file in my home dir, could you
look?" ... and now he's running your copy of 'ls' granting you
superuser rights.

Unfortunately my script is a wrapper for elderly software written for Lindows/Linspire (no other version was ever available), and apparently in that distro the user normally runs as root. Ugh.

Adam

_______________________________________________
Mid-Hudson Valley Linux Users Group                  http://mhvlug.org
http://mhvlug.org/cgi-bin/mailman/listinfo/mhvlug

Upcoming Meetings (6pm - 8pm)                         Vassar College
 Dec 5 - SysAdmin Panel
 Jan 9 - High Performance Computing
 Feb 6 - February Meeting

Reply via email to