Subject: groups for anon-users

From: "Denery.FENOUIL" <[email-masked]>
Date: Wed, 03 May 95 11:36:22 +0200

I just subscribed and were not able to retrieve the FAQ so apologize
if this has already been discussed.

I use wu-ftpd 2.4 on ultrix 4.4

Forgive my poor english.

Before you start reading this long post, let me summarize :
- I would appreciate comments on my configuration (especially in the
security domain)
- I propose a little modification of ftpd, for a better consistency
in files/directory creation under anonymous login.

Here we want authorized people to be able to publicly distribute files.
We do not want these "approved" people to have a real account on the
ftp-server since they do not need it but we want their "public" files
to be protected against deletion/modification.
We also want the "safe" approved-anon-upload to NOT require any admin
action.

So, we use the "SITE GROUP" facility to enhance privileges of anonymous
users who have to upload.
Here is a sample of our "ftpaccess" file :

--------------------------------
upload /usr/users/ftp  * no
upload /usr/users/ftp  /pub/incoming yes ftp daemon 644 nodirs
upload /usr/users/ftp  /pub/HOME_GROUP1 yes root FTPGRP1 664 dirs
--------------------------------

and of course, here is the /etc/ftpgroups file :

--------------------------------
GROUP1:dfNZNcD0ggOHg:FTPGRP1
--------------------------------

line #1 : all uploads disabled
line #2 : exception to #1 : /pub/incoming is writable by everyone
line #3 : exception to #1 : /pub/HOME_GROUP1 is writable by members of
ftp-group "GROUP1" (which system-counterpart is "FTPGRP1").

So, an "approved" uploader will connect using anonymous login, use
SITE GROUP GROUP1 and SITE GPASS xxxx to enter system-group FTPGRP1
and will be able to upload files in /pub/GROUP1 (files will be mode
664 and owned root.FTPGRP1)

This is fine BUT here is (was) my problem :

Files uploaded in /pub/GROUP1 have correct mode and owner but
directories created (yes, we want directory creation too) are NOT :
they inherit default mode and ownership (755, guest) !
And now any anon-user can go there and PUT,DELE,etc everything :(

So, I slightly modified src/ftpd.c in order to let directory creation
follow the same rules as file creation (ok this is quick-&-dirty but ...
it works !) :

btw, the first "PATCH" is because fchown() produces a "not owner" error
despite seteuid(0) ; chown() works fine however.

#diff src/ftpd.c src/ftpd.c.org
1537,1540c1537
< /* PATCH start ; Denery FENOUIL 95/04/15 */
< /*       if ((fchown(fdout, uid, gid)) < 0) { */
<         if ((chown(name, uid, gid)) < 0) {
< /* PATCH end */
---
>         if ((fchown(fdout, uid, gid)) < 0) {
1542c1539
<             perror_reply(550, "chown");
---
>             perror_reply(550, "fchown");
2276,2281d2272
< /* PATCH start ; Denery FENOUIL 95/04/15 */
< #if 1
<       {
<         int f_mode;
<         int oldid;
<           struct passwd *pwent;
2283,2305d2273
<         if ( (pwent = getpwnam("ftp")) && (geteuid () == pwent->pw_uid) ) {
<           if (upl_check(name, &uid, &gid, &f_mode, &valid) >= 0) {
<             oldid = geteuid();
<             (void) seteuid((uid_t) 0);
<             if ((chown(name, uid, gid)) < 0) {
<               (void) seteuid(oldid);
<               perror_reply(550, "chown");
<               return;
<             }
<             if (f_mode & 0400) f_mode |= 0100;
<             if (f_mode & 0040) f_mode |= 0010;
<             if (f_mode & 0004) f_mode |= 0001;
<             if (chmod (name, f_mode) < 0) {
<               (void) seteuid(oldid);
<               perror_reply(550, "chmod");
<               return;
<             }
<             (void) seteuid(oldid);
<           }
<         }
<       }
< #endif
< /* PATCH end */

Thanks for your comments and sorry for this long post.

---
Denery Fenouil ([email-masked])