Subject: busy day--cd ~ solution for guest accounts

From: Michael Douglass <[email-masked]>
Date: Sun, 16 Nov 1997 22:36:10 -0600

WARNING: IGNORANT, UNKNOWNING IDIOTS RESPONDING TO THIS WILL NOT GET MY
         EAR THIS TIME....  (Nor will I rush out to buy some stupid book.)

Regardless of what solution you take, this is the one that I declare the
best, most straight-forward solution for 'cd ~'.  It should be 100% correct
to assume that the home directory listed in the real /etc/passwd is the
actual home directory.  Of course, with the /./, and the guestgroup set
in the ftpaccess file, we chroot to the LHS of the /./.  Immediately
upon the chroot, wu-ftpd does a chdir() to the RHS of the /./.  It is
at this point that I thought of the best solution to the 'cd ~' problem...
'cd ~' does a chdir(pw->pw_dir) where the 'pw' here is a global structure
that remains throughout the user's logged-in-time.  Therefore, at
the point of the chroot() and chdir() call we can store the RHS of the
/./ as pw->pw_dir since once we chroot, we remained chroot()ed right?

Here is a patch:

diff -c -r1.2 ftpd.c
*** /tmp/T0arY3T_       Sun Nov 16 22:31:52 1997
--- ftpd.c      Sun Nov 16 22:29:42 1997
***************
*** 1571,1577 ****
      expand_id();

      if (anonymous || guest) {
!         char *sp;
          /* We MUST do a chdir() after the chroot. Otherwise the old current
           * directory will be accessible as "." outside the new root! */
  #ifdef VIRTUAL
--- 1571,1577 ----
      expand_id();

      if (anonymous || guest) {
!         char *sp,*t;
          /* We MUST do a chdir() after the chroot. Otherwise the old current
           * directory will be accessible as "." outside the new root! */
  #ifdef VIRTUAL
***************
*** 1594,1599 ****
--- 1594,1603 ----
            reply(550, "Can't set guest privileges.");
            goto bad;
          }
+           t = strdup( sp );
+           if (pw->pw_dir)
+               free(pw->pw_dir);
+           pw->pw_dir = t;
          }
      }
  #ifdef AIX

-- 
Michael Douglass
Texas Networking, Inc.

 "The past is a foreign country; they do things differently there."
      L. P. Hartley, British author. The Go-Between, Prologue (1953).

---

From: Gregory A Lundberg <[email-masked]>
Date: Mon, 17 Nov 1997 10:15:55 -0500 (EST)

Looks like we both got up today and decided to fix this.  I noticed I'd
missed a case, which you also appear to have missed.  My patch is below,
and I'll add somethinsg similar to yours .. it looks to me like it's
choose-your-coding-style with these patches ...

--- ftpd.c.orig	Fri Sep 12 11:42:46 1997
+++ ftpd.c	Mon Nov 17 10:07:28 1997
@@ -1587,12 +1587,31 @@
             if (chroot(pw->pw_dir) < 0 || chdir("/") < 0) {
                 reply(530, "Can't set guest privileges.");
                 goto bad;
+            } else {
+               if ((pw->pw_dir [0] == '\0')
+               ||  ((pw->pw_dir [0] == '/') && (pw->pw_dir[1] == '\0'))) {
+                 /*
+                  * This may be unnecessary, but why set guest privileges
+                  * if we're chroot'd to the root?  Besides, I needed an
+                  * else for the test to be sure ps->pw_dir was long enough
+                  * to set it to "/".  GAL 17NOV97
+                  */
+                 reply(530, "Can't set guest privileges.");
+                 goto bad;
+               } else {
+                 pw->pw_dir [0] = '/';
+                 pw->pw_dir [1] = '\0';
+               }
             }
         } else{
 	  *sp++ = '\0';
 	  if (chroot(pw->pw_dir) < 0 || chdir(++sp) < 0) {
 	    reply(550, "Can't set guest privileges.");
 	    goto bad;
+          } else {
+            char *pp;
+            pp = pw->pw_dir;
+            do *pp++ = *sp; while (*sp++ != '\0');
 	  }
         }
     }

On Sun, 16 Nov 1997, Michael Douglass wrote:

> Date: Sun, 16 Nov 1997 22:36:10 -0600
> From: Michael Douglass <[email-masked]>
> To: [email-masked]
> Subject: busy day--cd ~ solution for guest accounts
> 
> 

Near line 1588 .. 

    reply (530, "Can't set guest privileges.");
    goto bad;
    }
+ t = strdup( "/" );
+ if (ps->pw_dir)
+   free(pw->pw_dir);
+ pw->pw_dir = t;
  } else{
    *sp++ = '\0';

----

Gregory A Lundberg		Senior Partner, VRnet Company
1441 Elmdale Drive              email: [email-masked] [205.133.13.8]
Kettering, OH 45409-1615 USA    voice: +1 (937) 299-7653