]> arthur.barton.de Git - netatalk.git/commitdiff
bugfix: --enable-dropkludge INSECURE is an understatement
authordidg <didg>
Sat, 7 Sep 2002 19:18:59 +0000 (19:18 +0000)
committerdidg <didg>
Sat, 7 Sep 2002 19:18:59 +0000 (19:18 +0000)
etc/afpd/file.c
etc/afpd/filedir.c
etc/afpd/unix.c
include/atalk/adouble.h

index 310fcdd7a2105b58d9912b0b39338298328ab2e5..fc441ad209ae00da0574dd8cc9e22c1b177f5365 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: file.c,v 1.57 2002-09-06 04:23:45 didg Exp $
+ * $Id: file.c,v 1.58 2002-09-07 19:18:59 didg Exp $
  *
  * Copyright (c) 1990,1993 Regents of The University of Michigan.
  * All Rights Reserved.  See COPYRIGHT.
@@ -933,13 +933,13 @@ int               ibuflen, *rbuflen;
      *      and locks need to stay coherent. as a result,
      *      we just balk if the file is opened already. */
 
+    newname = obj->newtmp;
+    strcpy( newname, path );
+
     upath = mtoupath(vol, newname );
     if (of_findname(upath, NULL))
         return AFPERR_DENYCONF;
 
-    newname = obj->newtmp;
-    strcpy( newname, path );
-
     p = ctoupath( vol, curdir, newname );
 #ifdef FORCE_UIDGID
     /* FIXME svid != dvid && dvid's user can't read svid */
@@ -976,15 +976,14 @@ int               ibuflen, *rbuflen;
             return( AFPERR_PARAM );
         }
     }
-
-    if ( (err = copyfile(p, mtoupath(vol, newname), 
-                            newname, vol_noadouble(vol))) < 0 ) {
+    upath = mtoupath(vol, newname);
+    if ( (err = copyfile(p, upath , newname, vol_noadouble(vol))) < 0 ) {
         return err;
     }
 
 #ifdef DROPKLUDGE
     if (vol->v_flags & AFPVOL_DROPBOX) {
-        retvalue=matchfile2dirperms(newname, vol, sdid);
+        retvalue=matchfile2dirperms(upath, vol, ddid); /* FIXME sdir or ddid */
     }
 #endif /* DROPKLUDGE */
 
index 155c7e6d96c210f8e89819676c6e257ee03896a9..1ffda27a3988e264c4e5947bddbf3e9f9388b1ac 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: filedir.c,v 1.30 2002-09-05 14:52:06 didg Exp $
+ * $Id: filedir.c,v 1.31 2002-09-07 19:18:59 didg Exp $
  *
  * Copyright (c) 1990,1993 Regents of The University of Michigan.
  * All Rights Reserved.  See COPYRIGHT.
@@ -67,26 +67,29 @@ more information */
 {
     struct stat        st, sb;
     struct dir *dir;
-    char       adpath[50];
+    char       *adpath;
     int                uid;
-
+    int         ret = AFP_OK;
 #ifdef DEBUG
     LOG(log_info, logtype_afpd, "begin matchfile2dirperms:");
 #endif /* DEBUG */
 
-    if (stat(upath, &st ) < 0)
+    if (stat(upath, &st ) < 0) {
         LOG(log_error, logtype_afpd, "Could not stat %s: %s", upath, strerror(errno));
-    strcpy (adpath, "./.AppleDouble/");
-    strcat (adpath, upath);
+        return AFPERR_NOOBJ ;
+    }
+
+    adpath = ad_path( upath, ADFLAGS_HF );
+    /* FIXME dirsearch doesn't move cwd to did ! */
     if (( dir = dirsearch( vol, did )) == NULL ) {
         LOG(log_error, logtype_afpd, "matchfile2dirperms: Unable to get directory info.");
-        return( AFPERR_NOOBJ );
+        ret = AFPERR_NOOBJ;
     }
     else if (stat(".", &sb) < 0) {
         LOG(log_error, logtype_afpd,
             "matchfile2dirperms: Error checking directory \"%s\": %s",
             dir->d_name, strerror(errno));
-        return(AFPERR_NOOBJ );
+        ret AFPERR_NOOBJ;
     }
     else {
         uid=geteuid();
@@ -98,55 +101,37 @@ more information */
                 LOG(log_error, logtype_afpd,
                     "matchfile2dirperms: Error changing owner/gid of %s: %s",
                     upath, strerror(errno));
-                return (AFPERR_ACCESS);
+                ret = AFPERR_ACCESS;
             }
-            if (chmod(upath,(st.st_mode&~default_options.umask)| S_IRGRP| S_IROTH) < 0)
+            else if (chmod(upath,(st.st_mode&~default_options.umask)| S_IRGRP| S_IROTH) < 0)
             {
                 LOG(log_error, logtype_afpd,
                     "matchfile2dirperms:  Error adding file read permissions: %s",
                     strerror(errno));
-                return (AFPERR_ACCESS);
+                ret = AFPERR_ACCESS;
             }
-#ifdef DEBUG
-            else
-                LOG(log_info, logtype_afpd,
-                    "matchfile2dirperms:  Added S_IRGRP and S_IROTH: %s",
-                    strerror(errno));
-#endif /* DEBUG */
-            if (lchown(adpath, sb.st_uid, sb.st_gid) < 0)
+            else if (lchown(adpath, sb.st_uid, sb.st_gid) < 0)
             {
                 LOG(log_error, logtype_afpd,
                     "matchfile2dirperms: Error changing AppleDouble owner/gid %s: %s",
                     adpath, strerror(errno));
-                return (AFPERR_ACCESS);
+                ret = AFPERR_ACCESS;
             }
-            if (chmod(adpath, (st.st_mode&~default_options.umask)| S_IRGRP| S_IROTH) < 0)
+            else if (chmod(adpath, (st.st_mode&~default_options.umask)| S_IRGRP| S_IROTH) < 0)
             {
                 LOG(log_error, logtype_afpd,
                     "matchfile2dirperms:  Error adding AD file read permissions: %s",
                     strerror(errno));
-                return (AFPERR_ACCESS);
+                ret = AFPERR_ACCESS;
             }
-#ifdef DEBUG
-            else
-                LOG(log_info, logtype_afpd,
-                    "matchfile2dirperms:  Added S_IRGRP and S_IROTH to AD: %s",
-                    strerror(errno));
-#endif /* DEBUG */
+            seteuid(uid); 
         }
-#ifdef DEBUG
-        else
-            LOG(log_info, logtype_afpd,
-                "matchfile2dirperms: No ownership change necessary.");
-#endif /* DEBUG */
     } /* end else if stat success */
-    seteuid(uid); /* Restore process ownership to normal */
+
 #ifdef DEBUG
     LOG(log_info, logtype_afpd, "end matchfile2dirperms:");
 #endif /* DEBUG */
-
-    return (AFP_OK);
-
+    return ret;
 }
 
 
@@ -723,16 +708,16 @@ int               ibuflen, *rbuflen;
     rc = moveandrename(vol, sdir, oldname, newname, isdir);
 
     if ( rc == AFP_OK ) {
+        char *upath = mtoupath(vol, newname);
 #ifdef DROPKLUDGE
         if (vol->v_flags & AFPVOL_DROPBOX) {
-            if (retvalue=matchfile2dirperms (newname, vol, did) != AFP_OK) {
+            if (retvalue=matchfile2dirperms (upath, vol, did) != AFP_OK) {
                 return retvalue;
             }
         }
         else
 #endif /* DROPKLUDGE */
             if (!isdir) {
-                char *upath = mtoupath(vol, newname);
                 int  admode = ad_mode("", 0777);
 
                 setfilmode(upath, admode, NULL);
index 7f948bc907a8492f53fc956fca1e2fd1dd999e9a..7f2a3fc5fa87b2ebd7b21c3451c7590c59b86773 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: unix.c,v 1.36 2002-08-29 18:57:26 didg Exp $
+ * $Id: unix.c,v 1.37 2002-09-07 19:18:59 didg Exp $
  *
  * Copyright (c) 1990,1993 Regents of The University of Michigan.
  * All Rights Reserved.  See COPYRIGHT.
@@ -234,53 +234,52 @@ struct maccess    *ma;
     return( mode );
 }
 
-int stickydirmode(name, mode, dropbox)
+/*
+   a dropbox is a folder where w is set but not r eg:
+   rwx-wx-wx or rwx-wx-- 
+   rwx----wx (is not asked by a Mac with OS >= 8.0 ?)
+*/
+static int stickydirmode(name, mode, dropbox)
 char * name;
 const mode_t mode;
 const int dropbox;
 {
-    int retval;
-#ifdef DROPKLUDGE
-    int uid;
-#endif /* DROPKLUDGE */
+    int retval = 0;
 
-    /* Turn on the sticky bit if this is a drop box, also turn off the setgid bit */
-    retval=0;
 #ifdef DROPKLUDGE
+    /* Turn on the sticky bit if this is a drop box, also turn off the setgid bit */
     if (dropbox) {
-        if (mode & S_IWOTH) {
-            if (mode & S_IROTH);
-            else { /* if S_IWOTH and not S_IROTH */
-                uid=geteuid();
-                if ( seteuid(0) < 0) {
-                    LOG(log_error, logtype_afpd, "stickydirmode: unable to seteuid root: %s", strerror(errno));
-                }
-                if ( retval=chmod( name, ( (DIRBITS | mode | S_ISVTX) & ~default_options.umask) ) < 0) {
-                    LOG(log_error, logtype_afpd, "stickydirmode: chmod \"%s\": %s", name, strerror(errno) );
-                    return(AFPERR_ACCESS);
-                } else {
+        int uid;
+
+        if ( ( (mode & S_IWOTH) && !(mode & S_IROTH)) ||
+             ( (mode & S_IWGRP) && !(mode & S_IRGRP)) )
+        {
+            uid=geteuid();
+            if ( seteuid(0) < 0) {
+                LOG(log_error, logtype_afpd, "stickydirmode: unable to seteuid root: %s", strerror(errno));
+            }
+            if ( retval=chmod( name, ( (DIRBITS | mode | S_ISVTX) & ~default_options.umask) ) < 0) {
+                LOG(log_error, logtype_afpd, "stickydirmode: chmod \"%s\": %s", name, strerror(errno) );
+            } else {
 #ifdef DEBUG
-                    LOG(log_info, logtype_afpd, "stickydirmode: (debug) chmod \"%s\": %s", name, strerror(retval) );
+                LOG(log_info, logtype_afpd, "stickydirmode: (debug) chmod \"%s\": %s", name, strerror(retval) );
 #endif /* DEBUG */
-                    seteuid(uid);
-                } /* end getting retval */
-            } /* end if not & S_IROTH */
-        } else { /* end if S_IWOTH and not S_IROTH */
-#endif /* DROPKLUDGE */
-
-            /*
-            *  Ignore EPERM errors:  We may be dealing with a directory that is
-            *  group writable, in which case chmod will fail.
-            */
-            if ( (chmod( name, (DIRBITS | mode) & ~default_options.umask ) < 0) && errno != EPERM)  {
-                LOG(log_error, logtype_afpd, "stickydirmode: chmod \"%s\": %s",
-                    name, strerror(errno) );
-                retval = -1;
             }
-#ifdef DROPKLUDGE
-        } /* end if not mode */
-    } /* end checking for "dropbox" */
+            seteuid(uid);
+            return retval;
+        }
+    }
 #endif /* DROPKLUDGE */
+
+    /*
+     *  Ignore EPERM errors:  We may be dealing with a directory that is
+     *  group writable, in which case chmod will fail.
+     */
+    if ( (chmod( name, (DIRBITS | mode) & ~default_options.umask ) < 0) && errno != EPERM)  {
+        LOG(log_error, logtype_afpd, "stickydirmode: chmod \"%s\": %s",name, strerror(errno) );
+        retval = -1;
+    }
+
     return retval;
 }
 
@@ -450,7 +449,7 @@ const int dropbox;
             continue;
         }
         if (S_ISREG(st.st_mode)) {
-           if (setfilmode(dirp->d_name, ad_hf_mode(mode), &st) < 0) {
+           if (setfilmode(buf, ad_hf_mode(mode), &st) < 0) {
                /* FIXME what do we do then? */
            }
         }
index 93acdcb1924596a55d3cbf55356ab8604548402f..d9b4f18dc5fafcb2b22ed46860727f8da114648e 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: adouble.h,v 1.9 2002-08-29 18:57:36 didg Exp $
+ * $Id: adouble.h,v 1.10 2002-09-07 19:19:00 didg Exp $
  * Copyright (c) 1990,1991 Regents of The University of Michigan.
  * All Rights Reserved.
  *
@@ -295,7 +295,8 @@ extern int ad_mkdir   __P((char *, int));
 extern int ad_open    __P((char *, int, int, int, struct adouble *)); 
 extern int ad_refresh __P((struct adouble *));
 
-/* extend to RW if R for locking */ 
+/* extend header to RW if R or W (W if R for locking),
+ */ 
 static inline mode_t ad_hf_mode (mode_t mode)
 {
 #ifndef USE_FLOCK_LOCKS
@@ -307,6 +308,14 @@ static inline mode_t ad_hf_mode (mode_t mode)
     if ((mode & S_IROTH))
         mode |= S_IWOTH;
 #endif
+    /* if write mode set add read mode */
+    if ((mode & S_IWUSR))
+        mode |= S_IRUSR;
+    if ((mode & S_IWGRP))
+        mode |= S_IRGRP;
+    if ((mode & S_IWOTH))
+        mode |= S_IROTH;
+
     return mode;
 }