Hello, I use openssh-2.3.0p1 under linux-2.2.16 with standard settings and experience the following annoying problem: After I login the current directory is not set to the $HOME directory as expected, but to the _resolved_ path-name of the $HOME directory, where links and automounter dirs are expanded. To be specific, my $HOME is "/home/amann" but since /home is a link to the automounter directory /net/hservnlds/home/, my current working directory after login is "/tmp_mnt/hservnlds/home/amann". The reason for this is that sshd does not set the $PWD variable correctly. In order to fix this bug, I propose the following patch: diff -u ../../sb/openssh-2.3.0p1/session.c ./session.c --- ../../sb/openssh-2.3.0p1/session.c Sat Oct 28 05:19:58 2000 +++ ./session.c Tue Nov 14 16:07:54 2000 @@ -1293,6 +1293,8 @@ if (login_getcapbool(lc, "requirehome", 0)) exit(1); #endif + } else { + child_set_env(&env, &envsize, "PWD", pw->pw_dir); } /* Disclaimer: This patch fixes the problem for me. Since I am not at all familiar with security-critical programming, please check twice before you apply this patch. It might also be considered to set $PWD already before $HOME/.ssh/environment is read. (BTW, why is there no global /etc/environment file, I really miss it). CU, Andreas
IMHO, setting $PWD is the job of the shell. there are even some shells that do not need $PWD nor care about symlinks. On Tue, Nov 14, 2000 at 08:32:13PM +0100, Andreas Amann wrote:> Hello, > > I use openssh-2.3.0p1 under linux-2.2.16 with standard settings and > experience the following annoying problem: After I login the current > directory is not set to the $HOME directory as expected, but to the > _resolved_ path-name of the $HOME directory, where links and > automounter dirs are expanded. To be specific, my $HOME is > "/home/amann" but since /home is a link to the automounter directory > /net/hservnlds/home/, my current working directory after login is > "/tmp_mnt/hservnlds/home/amann". The reason for this is that sshd does > not set the $PWD variable correctly. > > In order to fix this bug, I propose the following patch: > > diff -u ../../sb/openssh-2.3.0p1/session.c ./session.c > --- ../../sb/openssh-2.3.0p1/session.c Sat Oct 28 05:19:58 2000 > +++ ./session.c Tue Nov 14 16:07:54 2000 > @@ -1293,6 +1293,8 @@ > if (login_getcapbool(lc, "requirehome", 0)) > exit(1); > #endif > + } else { > + child_set_env(&env, &envsize, "PWD", pw->pw_dir); > } > > /* > > > > Disclaimer: This patch fixes the problem for me. Since I am not at all > familiar with security-critical programming, please check twice > before you apply this patch. It might also be considered to set $PWD > already before $HOME/.ssh/environment is read. > (BTW, why is there no global /etc/environment file, I really miss it). > > > > CU, > > Andreas >
Markus Friedl writes: > IMHO, setting $PWD is the job of the shell. > > there are even some shells that do not need $PWD nor > care about symlinks. >>From "man 3 getcwd" (man-pages-1.31.):If the environment variable PWD is set, and its value is correct, then that value will be returned. IMHO, that means that any program, that changes the current working directory should also update $PWD, so that it?s child processes can make a proper getcwd() call. Otherwise the child will not be able to recover the logical path of the current working directory, but only the resolved path, which is usually not what they want, especially when using automounting fs. Note that $PWD is not a shell-specific, but a glibc specific variable. Since the shell does usually not change the working directory at startup, it is not its task to set or change $PWD (how should it know the correct value anyway, if not via $PWD from its parent?) -- Andreas Amann Institut fuer theoretische Physik, TU Berlin