Subject: Re: nodirs argument on upload command doesn't work

From: David Carmean <[email-masked]>
Date: Mon, 1 Jun 1998 10:29:10 -0700

On Fri, May 29, 1998 at 11:14:08PM -0500, Kent Landfield wrote:

> # On Fri, May 29, 1998 at 02:45:31PM -0400, Gregory A Lundberg wrote:
> # 
> # > Yes.  A patch is available in the mailing list archives.

Well, I've spent at least 45 minutes searching through the 
archives on lanfield.com, but haven't found this patch.  Do 
you remember the subject line of the message(s) containing 
the patch?

Shouldn't a patch such as this at least be in a contrib 
directory somewhere, if not incorporated?

-- 
David Carmean                                           <[email-masked]>
Avtel Communications, Santa Barbara, CA			+1-805-730-7740
  PGP fingerprint =  B1 57 EB A8 1D B9 87 86  5F 5C 51 A4 F2 5E ED FD

---

From: Gregory A Lundberg <[email-masked]>
Date: Mon, 1 Jun 1998 14:07:06 -0400 (EDT)

>From [email-masked]  Wed Apr 29 22:25:31 1998
(CDT)
Received: (from achurch@localhost) by Bahamut.dragonfire.net (8.8.5/8.8.8)
id WAA28784; Wed, 29 Apr 1998 22:21:41 -0400
Message-Id: <[email-masked]>
Date: Wed, 29 Apr 1998 22:21:37 EDT
Reply-To: [email-masked]
Sender: [email-masked]
From: [email-masked] (Andy Church)
To: Sean H Davies <[email-masked]>
Cc: [email-masked]
Subject: Re: import directories
X-Mailer: MMail v4.62
X-Listprocessor-Version: 8.0 -- ListProcessor(tm) by CREN
Status: RO
X-Status: 

----

Gregory A Lundberg		Senior Partner, VRnet Company
1441 Elmdale Drive              [email-masked]
Kettering, OH 45409-1615 USA    1-800-809-2195

From [email-masked] Mon Jun  1 14:06:50 1998
Date: Wed, 29 Apr 1998 22:21:37 EDT
From: Andy Church <[email-masked]>
To: Sean H Davies <[email-masked]>
Cc: [email-masked]
Subject: Re: import directories

>I have been able to setup an import directory where anonymous users are
>able to drop off files. The directory is unlistable but writable by
>anonymous.
>Files are written ( due to the upload directive in ftpaccess ) with an
>owner of unknown but group of ftp.
>However, if anonymous users create directories in the import hierarchy,
>then the owner and group is ftp:staff.

     This is a bug in wu-ftpd.  Try the following patch (also available as
ftp://achurch.dragonfire.net/wu-ftpd/mkdir.patch).  Note that this patch is
untested, but looks like it should work.

*** src/extensions.c.old	Tue Apr 28 01:09:03 1998
--- src/extensions.c	Wed Apr 29 22:17:34 1998
***************
*** 949,960 ****
  
  int
  #ifdef __STDC__
! dir_check(char *name, uid_t *uid, gid_t *gid, int *valid)
  #else
! dir_check(name,uid,gid,valid)
  char *name;
  uid_t *uid;
  gid_t *gid;
  int *valid;
  #endif
  {
--- 949,961 ----
  
  int
  #ifdef __STDC__
! dir_check(char *name, uid_t *uid, gid_t *gid, int *d_mode, int *valid)
  #else
! dir_check(name,uid,gid,d_mode,valid)
  char *name;
  uid_t *uid;
  gid_t *gid;
+ int *d_mode;
  int *valid;
  #endif
  {
***************
*** 965,971 ****
    char *ap2 = NULL,
         *ap3 = NULL,
         *ap4 = NULL,
!        *ap6 = NULL;
    char cwdir[BUFSIZ];
    char path[BUFSIZ];
    char *sp;
--- 966,974 ----
    char *ap2 = NULL,
         *ap3 = NULL,
         *ap4 = NULL,
!        *ap5 = NULL,
!        *ap6 = NULL,
!        *ap7 = NULL;
    char cwdir[BUFSIZ];
    char path[BUFSIZ];
    char *sp;
***************
*** 983,989 ****
      return(-1);
    }
    while (getaclentry("upload", &entry) && ARG0 && ARG1 && ARG2 != NULL) {
!       if ( (!strcmp(ARG0, pw->pw_dir)) &&
             ((i = path_compare(ARG1, cwdir)) >= match_value) ) {
            match_value = i;
            ap2 = ARG2;
--- 986,992 ----
      return(-1);
    }
    while (getaclentry("upload", &entry) && ARG0 && ARG1 && ARG2 != NULL) {
!       if ( (!strcmp(ARG0, "*") || !strcmp(ARG0, pw->pw_dir)) &&
             ((i = path_compare(ARG1, cwdir)) >= match_value) ) {
            match_value = i;
            ap2 = ARG2;
***************
*** 991,998 ****
--- 994,1005 ----
            else       ap3 = NULL;
            if (ARG4)  ap4 = ARG4;
            else       ap4 = NULL;
+           if (ARG5)  ap5 = ARG5;
+           else       ap5 = NULL;
            if (ARG6)  ap6 = ARG6;
            else       ap6 = NULL;
+           if (ARG7)  ap7 = ARG7;
+           else       ap7 = NULL;
        }
    }
    if ( (ap3 && !strcasecmp(ap3, "nodirs")) ||
***************
*** 1004,1011 ****
       *uid = atoi(ap3);    /* the uid  */
    if (ap4) {
       *gid = atoi(ap4);    /* the gid */
-      *valid = 1;
     }
    return(1);
  }
  
--- 1011,1030 ----
       *uid = atoi(ap3);    /* the uid  */
    if (ap4) {
       *gid = atoi(ap4);    /* the gid */
     }
+   if (ap7) {
+      sscanf(ap7, "%o", d_mode); /* the mode */
+      *valid = 1;
+   } else if (ap5) {
+      sscanf(ap7, "%o", d_mode); /* take file mode, and add search permission */
+      if (*d_mode & 0600)
+         *d_mode |= 0100;
+      if (*d_mode & 0060)
+         *d_mode |= 0010;
+      if (*d_mode & 0006)
+         *d_mode |= 0001;
+      *valid = 1;
+   }
    return(1);
  }
  
*** src/ftpd.c.old	Tue Apr 28 01:09:04 1998
--- src/ftpd.c	Wed Apr 29 21:53:43 1998
***************
*** 3107,3118 ****
  {
  	uid_t uid;
  	gid_t gid;
  	int   valid;
  
      /*
       * check the directory, can we mkdir here?
       */
!     if ( (dir_check(name, &uid, &gid, &valid)) <= 0 )
          return;
  
      /*
--- 3107,3119 ----
  {
  	uid_t uid;
  	gid_t gid;
+ 	int   mode;
  	int   valid;
  
      /*
       * check the directory, can we mkdir here?
       */
!     if ( (dir_check(name, &uid, &gid, &mode, &valid)) <= 0 )
          return;
  
      /*
***************
*** 3121,3133 ****
      if ( (fn_check(name)) <= 0 )
          return;
  
!     if (mkdir(name, 0777) < 0) {
          if (errno == EEXIST)
              perror_reply(553, name);
          else
              perror_reply(550, name);
  	return;
      }
      reply(257, "MKD command successful.");
  }
  
--- 3122,3160 ----
      if ( (fn_check(name)) <= 0 )
          return;
  
!     if (valid <= 0)
!         mode = 0777;
! 
!     if (mkdir(name, mode) < 0) {
          if (errno == EEXIST)
              perror_reply(553, name);
          else
              perror_reply(550, name);
  	return;
      }
+ 
+     if (valid > 0) {
+         uid_t oldid = geteuid();
+         delay_signaling();
+         (void) seteuid((uid_t) 0);
+         /*
+          * There's a small file race here: if someone deletes the directory
+          * we just created and creates another file or directory in its
+          * place before we get a chance to chown() it, that new file or
+          * directory gets the appropriate modes.  I don't think you could
+          * actually do anything useful with this, though (remember, set-id
+          * bits are cleared on chown())...
+          */
+         if ((chown(name, uid, gid)) < 0) {
+             (void) seteuid(oldid);
+             enable_signaling();
+             perror_reply(550, "fchown");
+             return;
+         }
+         (void) seteuid(oldid);
+         enable_signaling();
+     }
+ 
      reply(257, "MKD command successful.");
  }

  --Andy Church                  | If Bell Atlantic really is the heart
    [email-masked]       | of communication, then it desperately
    www.dragonfire.net/~achurch/ | needs a quadruple bypass.

---

From: [email-masked] (Stan Barber)
Date: 3 Jun 1998 22:13:06 GMT

>directory somewhere, if not incorporated?

If I add a contrib directory that contains patches, I would probably be
expected to regression test those patches with each release of the software.
If I don't put the regression tests in there, then folks will just log
bug reports telling me about problems with the patches (even through they
are just contrib stuff). This is a no-win senario for me. So, I encourage
folks to contribute stuff like that to the list and in some cases, the 
wu-ftpd resource site will put them up as items that folks can download.
Kent will have to comment on how such things might be put up on his website.

-- 
Stan   | Director of Technology, VERIO     | Work Email: [email-masked]
Olan   | Phone: +1-713-793-0222            | Personal Email: [email-masked]
Barber | Fax:   +1-713-793-0221            | Opinions expressed are only mine.