Subject: Solaris 2 getcwd() bug

From: Mark Costlow <[email-masked]>
Date: Wed, 18 Sep 1996 13:32:55 -0600

Strictly speaking, this isn't a wu-ftpd problem, but it bit me on our FTP
server so I thought I'd mention it here.

In Solaris 2.5.1 (probably older versions too, but I'm not sure), the getcwd()
library call is broken.  getcwd() is supposed to stat each directory from "."
up to "/", determining the directory name at each level, building up the full
pathname for your current directory.  It's supposed to just stat each
directory in the path, *not* any other directories.  If you do a getcwd() on
an NFS-mounted partition however, it lstat()'s every file in your parent
directory!

We use the same machine for both anonymous and regular FTP services.  The anon
FTP files are on a local disk, but user's home directories are served over NFS
from a SunOS 4 host.  We recently upgraded our FTP server machine from SunOS 4
to Solaris 2.5.1.  When we did this, we discovered that some users were
getting a 2-3 minute delay when they logged in.  Anonymous FTP worked fine,
and some users got logged in with no delay, but for other users the delay was
so long that their FTP clients timed out before they got logged in.

Turns out that ftpd does a getcwd() after it logs the user in (which is
sensible).  For a user with an NFS-mounted home directory, this caused the
program to lstat() about 2,000 NFS-mounted directories, which was the source
of the delay.  It only lstat()ed directories until it found the one it was
looking for, so if your directory came up quickly in the list you wouldn't
even notice the problem, but for others there was a long wait.

The fix was to grab the getcwd() code from GNU LibC, rip out some of the
glibc-specific stuff, and link it with ftpd via the support library.  Doing a
"pwd" in someone's home directory from that machine still takes 2 minutes
(haven't had the guts to replace /bin/pwd yet), but in our case there aren't
any shell logins allowed on that machine so it's not important.

I hope this helps someone somewhere.  Maybe wu-ftpd should throw a getcwd()
into the distribution for use on Solaris machines.

Oh, by the way, Sun has this bug listed in SunSolve, and they've acknowledged
it, but they don't have a patch.  They say it only affects you if you're
talking to an NFS V2 server (i.e. SunOS 4).  But the problem is in the
getcwd() code, not NFS.  Perhaps NFS V3 does something to lessen the impact of
getcwd()'s bogus behavior, but it's still bogus.

Mark
-- 
Mark Costlow            | Personal Contact:      | SWCP Information:
Southwest Cyberport     | Mail:  [email-masked] | Mail: [email-masked]
Public Access Internet  | Voice: +1-505-293-5967 | FTP:  ftp.swcp.com:/pub/swcp
Albuquerque, NM         | Fax:   +1-505-271-5477 | WWW:  http://www.swcp.com/

               "Education is never a waste" - Viscount du Valmont

---

From: "Andrew P. Schwalb" <[email-masked]>
Date: Thu, 19 Sep 1996 08:36:33 -0400

> getcwd()'s bogus behavior, but it's still bogus.
I have a Solaris 2.5 machine running wu-ftp 2.4 beta 11.  My machine
exhibits the same behaviour (taking forever to log someone in, so long
that sometimes their client times out).  This seems to happen to most
people, but doesn't happen to everyone.  This is on a Sparc 20 with
nothing else to do and only 1 or 2 people logging in at a time.  I am on
a 56k frame relay link.
-- 

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|~~
0-                                                         /| 
Andrew P. Schwalb                              ___________/_|__
Advanced Technology Group   L O C K H E E D  M A R T I N /  | /
Ocala Operations                                        /   |/    
[email-masked]                                      /
                                                           /|
                                                          / |