]> arthur.barton.de Git - netatalk.git/commitdiff
Check for DENY READ in FPCopyFile.
authordidg <didg>
Tue, 7 Dec 2004 03:23:48 +0000 (03:23 +0000)
committerdidg <didg>
Tue, 7 Dec 2004 03:23:48 +0000 (03:23 +0000)
etc/afpd/directory.c
etc/afpd/file.c
etc/afpd/file.h
etc/afpd/fork.c
etc/afpd/fork.h
etc/afpd/ofork.c
libatalk/adouble/ad_lock.c

index e22c7c949a52480d32efbcb8a1a93b9295d96cc1..80050643077a7d26ec7b1242e78fb6915e71a9cc 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: directory.c,v 1.71.2.4.2.15.2.2 2004-12-07 02:58:10 didg Exp $
+ * $Id: directory.c,v 1.71.2.4.2.15.2.3 2004-12-07 03:23:48 didg Exp $
  *
  * Copyright (c) 1990,1993 Regents of The University of Michigan.
  * All Rights Reserved.  See COPYRIGHT.
@@ -786,7 +786,7 @@ static int copydir(const struct vol *vol, char *src, char *dst)
             if (S_ISDIR(st.st_mode)) {
                 if (AFP_OK != (err = copydir(vol, spath, dpath)))
                     goto copydir_done;
-            } else if (AFP_OK != (err = copyfile(vol, vol, spath, dpath, NULL))) {
+            } else if (AFP_OK != (err = copyfile(vol, vol, spath, dpath, NULL, NULL))) {
                 goto copydir_done;
 
             } else {
index 09502efa000223ef6353a8a5bb293503b5d2b28e..bf7f6efa0fe763b14a587ff13c3f355e06b44625 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: file.c,v 1.92.2.2.2.31.2.4 2004-12-07 02:58:09 didg Exp $
+ * $Id: file.c,v 1.92.2.2.2.31.2.5 2004-12-07 03:23:49 didg Exp $
  *
  * Copyright (c) 1990,1993 Regents of The University of Michigan.
  * All Rights Reserved.  See COPYRIGHT.
@@ -805,12 +805,8 @@ int setfilparams(struct vol *vol,
 #endif /* DEBUG */
 
     upath = path->u_name;
-    if ((of = of_findname(path))) {
-        adp = of->of_ad;
-    } else {
-        ad_init(&ad, vol->v_adouble);
-        adp = &ad;
-    }
+    adp = of_ad(vol, path, &ad);
+    
 
     if (!vol_unix_priv(vol) && check_access(upath, OPENACC_WR ) < 0) {
         return AFPERR_ACCESS;
@@ -1051,7 +1047,7 @@ struct adouble    *adp;
                /* FIXME  warning in syslog so admin'd know there's a conflict ?*/
                return AFPERR_OLOCK; /* little lie */
            }
-            if (AFP_OK != ( rc = copyfile(vol, vol, src, dst, newname )) ) {
+            if (AFP_OK != ( rc = copyfile(vol, vol, src, dst, newname, NULL )) ) {
                 /* on error copyfile delete dest */
                 return( rc );
             }
@@ -1211,6 +1207,9 @@ int               ibuflen, *rbuflen;
     int         err, retvalue = AFP_OK;
     u_int16_t  svid, dvid;
 
+    struct adouble ad, *adp;
+    int denyreadset;
+    
 #ifdef DEBUG
     LOG(log_info, logtype_afpd, "begin afp_copyfile:");
 #endif /* DEBUG */
@@ -1248,11 +1247,20 @@ 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, s_path->m_name );
+    adp = of_ad(s_vol, s_path, &ad);
 
-    if (of_findname(s_path))
+    if (ad_open(s_path->u_name , ADFLAGS_DF |ADFLAGS_HF | ADFLAGS_NOHF, O_RDONLY, 0, adp) < 0) {
         return AFPERR_DENYCONF;
+    }
+    denyreadset = (getforkmode(adp, ADEID_DFORK, AD_FILELOCK_DENY_RD) != 0 || 
+                  getforkmode(adp, ADEID_RFORK, AD_FILELOCK_DENY_RD) != 0 );
+    ad_close( adp, ADFLAGS_DF |ADFLAGS_HF );
+    if (denyreadset) {
+        return AFPERR_DENYCONF;
+    }
+
+    newname = obj->newtmp;
+    strcpy( newname, s_path->m_name );
 
     p = ctoupath( s_vol, curdir, newname );
     if (!p) {
@@ -1290,7 +1298,7 @@ int               ibuflen, *rbuflen;
     if (NULL == (upath = mtoupath(d_vol, newname, curdir->d_did, utf8_encoding()))) {
         return( AFPERR_PARAM );
     }
-    if ( (err = copyfile(s_vol, d_vol, p, upath , newname)) < 0 ) {
+    if ( (err = copyfile(s_vol, d_vol, p, upath , newname, adp)) < 0 ) {
         return err;
     }
     curdir->offcnt++;
@@ -1394,9 +1402,10 @@ static int copy_fd(int dfd, int sfd)
  * if newname is NULL (from directory.c) we don't want to copy ressource fork.
  * because we are doing it elsewhere.
  */
-int copyfile(s_vol, d_vol, src, dst, newname )
+int copyfile(s_vol, d_vol, src, dst, newname, adp )
 const struct vol *s_vol, *d_vol;
 char   *src, *dst, *newname;
+struct adouble *adp;
 {
     struct adouble     ads, add;
     int                        err = 0;
@@ -1409,42 +1418,45 @@ char    *src, *dst, *newname;
     LOG(log_info, logtype_afpd, "begin copyfile:");
 #endif /* DEBUG */
 
-    ad_init(&ads, s_vol->v_adouble); 
+    if (adp == NULL) {
+        ad_init(&ads, s_vol->v_adouble); 
+        adp = &ads;
+    }
     ad_init(&add, d_vol->v_adouble);
     adflags = ADFLAGS_DF;
     if (newname) {
         adflags |= ADFLAGS_HF;
     }
 
-    if (ad_open(src , adflags | ADFLAGS_NOHF, O_RDONLY, 0, &ads) < 0) {
+    if (ad_open(src , adflags | ADFLAGS_NOHF, O_RDONLY, 0, adp) < 0) {
         ret_err = errno;
         goto done;
     }
 
-    if (ad_hfileno(&ads) == -1) {
+    if (ad_hfileno(adp) == -1) {
         /* no resource fork, don't create one for dst file */
         adflags &= ~ADFLAGS_HF;
     }
 
     if (ad_open(dst , adflags | noadouble, O_RDWR|O_CREAT|O_EXCL, 0666, &add) < 0) {
         ret_err = errno;
-        ad_close( &ads, adflags );
+        ad_close( adp, adflags );
         if (EEXIST != ret_err) {
             deletefile(d_vol, dst, 0);
             goto done;
         }
         return AFPERR_EXIST;
     }
-    if (ad_hfileno(&ads) == -1 || 0 == (err = copy_fd(ad_hfileno(&add), ad_hfileno(&ads)))){
+    if (ad_hfileno(adp) == -1 || 0 == (err = copy_fd(ad_hfileno(&add), ad_hfileno(adp)))){
         /* copy the data fork */
-       err = copy_fd(ad_dfileno(&add), ad_dfileno(&ads));
+       err = copy_fd(ad_dfileno(&add), ad_dfileno(adp));
     }
 
     /* Now, reopen destination file */
     if (err < 0) {
        ret_err = errno;
     }
-    ad_close( &ads, adflags );
+    ad_close( adp, adflags );
 
     if (ad_close( &add, adflags ) <0) {
         deletefile(d_vol, dst, 0);
@@ -1729,18 +1741,14 @@ reenumerate_id(const struct vol *vol, char *name, cnid_t did)
 
 #if AD_VERSION > AD_VERSION1
         if (aint != CNID_INVALID && !S_ISDIR(path.st.st_mode)) {
-            struct ofork    *of;
+//            struct ofork    *of;
             struct adouble  ad, *adp;
 
             path.st_errno = 0;
             path.st_valid = 1;
             path.u_name = de->d_name;
             
-            if (!(of = of_findname(&path))) {
-                ad_init(&ad, vol->v_adouble);
-                adp = &ad;
-            } else
-                adp = of->of_ad;
+            adp = of_ad(vol, &path, &ad);
             
             if ( ad_open( de->d_name, ADFLAGS_HF, O_RDWR, 0, adp ) < 0 ) {
                 continue;
index dc0ddb83ac9b53b61f81f6cdcd6da52a9176c693..157e71630d7b1323d74a92622d9583be32f72296 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: file.h,v 1.16.2.2.2.3.2.1 2004-12-07 02:58:09 didg Exp $
+ * $Id: file.h,v 1.16.2.2.2.3.2.2 2004-12-07 03:23:49 didg Exp $
  *
  * Copyright (c) 1990,1991 Regents of The University of Michigan.
  * All Rights Reserved.
@@ -130,7 +130,7 @@ extern int getfilparams __P((struct vol *, u_int16_t, struct path *,
 
 extern int setfilparams __P((struct vol *, struct path *, u_int16_t, char *));
 extern int renamefile   __P((const struct vol *, char *, char *, char *, struct adouble *));
-extern int copyfile     __P((const struct vol *, const struct vol *, char *, char *, char *));
+extern int copyfile     __P((const struct vol *, const struct vol *, char *, char *, char *, struct adouble *));
 extern int deletefile   __P((const struct vol *, char *, int));
 
 extern void *get_finderinfo __P((const char *, struct adouble *, void *));
index ab7ba4e8b3713f67a30a76a0fbda7bbf284fa9e2..1255496a9e965037be89ba0f5d1265d970ca7c39 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: fork.c,v 1.51.2.2.2.10.2.1 2004-10-30 22:42:06 didg Exp $
+ * $Id: fork.c,v 1.51.2.2.2.10.2.2 2004-12-07 03:23:49 didg Exp $
  *
  * Copyright (c) 1990,1993 Regents of The University of Michigan.
  * All Rights Reserved.  See COPYRIGHT.
@@ -178,11 +178,13 @@ static int setforkmode(struct adouble *adp, int eid, int ofrefnum, int what)
 
 /* -------------------------
 */
-static int getforkmode(struct adouble *adp, int eid, int what)
+int getforkmode(struct adouble *adp, int eid, int what)
 {
     return ad_testlock(adp, eid,  what);
 }
 
+/* -------------------------
+*/
 static int fork_setmode(struct adouble *adp, int eid, int access, int ofrefnum)
 {
     int ret;
index 2611a1ba5507f193636bac973ef5353564cbe48b..4c711b5c38805af36a359e87b1b4d2fddfd1bc0a 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: fork.h,v 1.8.6.2 2004-05-10 18:40:32 didg Exp $
+ * $Id: fork.h,v 1.8.6.2.2.1 2004-12-07 03:23:51 didg Exp $
  *
  * Copyright (c) 1990,1993 Regents of The University of Michigan.
  * All Rights Reserved.  See COPYRIGHT.
@@ -69,8 +69,10 @@ extern int          of_flush     __P((const struct vol *));
 extern void         of_pforkdesc __P((FILE *));
 extern int          of_stat      __P((struct path *));
 extern int          of_statdir   __P((const struct vol *vol, struct path *));
+extern struct adouble *of_ad     __P((const struct vol *, struct path *, struct adouble *));
 /* in fork.c */
 extern int          flushfork    __P((struct ofork *));
+extern int          getforkmode  __P((struct adouble *, int , int ));
 
 /* FP functions */
 extern int     afp_openfork __P((AFPObj *, char *, int, char *, int *));
index 1d39b26681693b2592f7f5ffd30e9c658d255940..17b5ae59a914a1b5d963b24d4db6877fb59e5294 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: ofork.c,v 1.20.6.6 2004-05-10 18:40:32 didg Exp $
+ * $Id: ofork.c,v 1.20.6.6.2.1 2004-12-07 03:23:51 didg Exp $
  *
  * Copyright (c) 1996 Regents of The University of Michigan.
  * All Rights Reserved.  See COPYRIGHT.
@@ -372,3 +372,21 @@ struct ofork       *of;
 
     free( of );
 }
+
+/* ----------------------
+
+*/
+struct adouble *of_ad(const struct vol *vol, struct path *path, struct adouble *ad)
+{
+    struct ofork        *of;
+    struct adouble      *adp;
+
+    if ((of = of_findname(path))) {
+        adp = of->of_ad;
+    } else {
+        ad_init(ad, vol->v_adouble);
+        adp = ad;
+    }
+    return adp;
+}
+
index 0cb1968ddd4628f89c23b4925dce14ddf02826bf..a5d00e9cbabea271f5fbf8ad1a58cde5045f3ddb 100644 (file)
@@ -1,5 +1,5 @@
 /* 
- * $Id: ad_lock.c,v 1.11.6.4 2004-05-08 22:37:46 didg Exp $
+ * $Id: ad_lock.c,v 1.11.6.4.2.1 2004-12-07 03:24:38 didg Exp $
  *
  * Copyright (c) 1998,1999 Adrian Sun (asun@zoology.washington.edu)
  * All Rights Reserved. See COPYRIGHT for more information.
@@ -403,9 +403,14 @@ int ad_testlock(struct adouble *ad, int eid, const off_t off)
     if ((ad_hfileno(ad) != -1)) {
        adf = &ad->ad_hf;
        lock.l_start = df2off(off);
-       }
-  } else { /* rfork */
-       adf = &ad->ad_hf;
+    }
+  } 
+  else { /* rfork */
+    if ((ad_hfileno(ad) == -1)) {
+        /* there's no resource fork. return no lock */
+        return 0;
+    }
+    adf = &ad->ad_hf;
     lock.l_start = hf2off(off);
   }