]> arthur.barton.de Git - netatalk.git/commitdiff
Fix deletefile by protecting agains double ad_close
authorFrank Lahm <franklahm@googlemail.com>
Mon, 10 Jan 2011 16:15:29 +0000 (17:15 +0100)
committerFrank Lahm <franklahm@googlemail.com>
Mon, 10 Jan 2011 16:15:29 +0000 (17:15 +0100)
etc/afpd/file.c
include/atalk/adouble.h
libatalk/adouble/ad_flush.c

index 6cb4e9a8b25bfd44c58e352fa42f81b09d546e05..ba930108f89ebde3a7ae079b6ee6b5815fb6cb62 100644 (file)
@@ -1481,7 +1481,7 @@ int copyfile(const struct vol *s_vol,
         adflags |= ADFLAGS_HF;
     }
 
-    if (ad_openat(adp, sfd, src, adflags | ADFLAGS_NOHF, O_RDONLY) < 0) {
+    if (ad_openat(adp, sfd, src, adflags | ADFLAGS_NOHF, O_RDONLY, O_RDONLY) < 0) {
         ret_err = errno;
         goto done;
     }
@@ -1625,7 +1625,7 @@ int deletefile(const struct vol *vol, int dirfd, char *file, int checkAttrib)
  
     /* try to open both forks at once */
     adflags = ADFLAGS_DF;
-    if ( ad_openat(&ad, dirfd, file, adflags |ADFLAGS_HF|ADFLAGS_NOHF, O_RDONLY) < 0 ) {
+    if ( ad_openat(&ad, dirfd, file, adflags |ADFLAGS_HF|ADFLAGS_NOHF, O_RDONLY, O_RDONLY) < 0 ) {
         switch (errno) {
         case ENOENT:
             err = AFPERR_NOOBJ;
index 10414f3ea17d1e87156fb75e6e269998cefda9e4..176f934ce6766250ef62ddf100d905dbaa80f4bf 100644 (file)
@@ -171,6 +171,7 @@ struct ad_fd {
 
 /* some header protection */
 #define AD_INITED  0xad494e54  /* ad"INT" */
+#define AD_CLOSED  0xadc10ced
 
 struct adouble;
 
index da6bcc29ab292566581f6a34a69427854142d447..5853c48caa0ef2e3a87c70d20c7bb1d32a57ce64 100644 (file)
@@ -189,6 +189,11 @@ int ad_close( struct adouble *ad, int adflags)
 {
     int err = 0;
 
+    if (ad->ad_inited == AD_CLOSED) {
+        LOG(log_warning, logtype_default, "ad_close: double close");
+        return 0;
+    }
+
     LOG(log_debug, logtype_default, "ad_close(\"%s\", %s)",
         cfrombstr(ad->ad_fullpath),
         adflags2logstr(adflags));
@@ -225,5 +230,7 @@ int ad_close( struct adouble *ad, int adflags)
         ad->ad_fullpath = NULL;
     }
 
+    ad->ad_inited = AD_CLOSED;
+
     return err;
 }