]> arthur.barton.de Git - netatalk.git/blobdiff - etc/afpd/dircache.c
Fix data corruption bug
[netatalk.git] / etc / afpd / dircache.c
index 6a077148710eae391fd3bf3d899ded1e2cc797dd..7cd08f6f4ec5182a356447306d5ddfa8baa4f173 100644 (file)
 #include <atalk/queue.h>
 #include <atalk/bstrlib.h>
 #include <atalk/bstradd.h>
+#include <atalk/globals.h>
 
 #include "dircache.h"
 #include "directory.h"
 #include "hash.h"
-#include "globals.h"
+
 
 /*
  * Directory Cache
@@ -330,7 +331,7 @@ struct dir *dircache_search_by_did(const struct vol *vol, cnid_t cnid)
             dircache_stat.expunged++;
             return NULL;
         }
-        if (cdir->dcache_ctime != st.st_ctime) {
+        if ((cdir->dcache_ctime != st.st_ctime) || (cdir->dcache_ino != st.st_ino)) {
             LOG(log_debug, logtype_afpd, "dircache(cnid:%u): {modified:\"%s\"}",
                 ntohl(cnid), cfrombstr(cdir->d_u_name));
             (void)dir_remove(vol, cdir);
@@ -401,12 +402,8 @@ struct dir *dircache_search_by_name(const struct vol *vol,
             return NULL;
         }
 
-        /* Remove modified directories (precaution, probably not necessary) and file */
-        if (
-            (!(cdir->d_flags & DIRF_ISFILE) && (cdir->dcache_ctime != st.st_ctime))
-            ||
-            ((cdir->d_flags & DIRF_ISFILE) && (cdir->dcache_ino != st.st_ino))
-           ) {
+        /* Remove modified directories and files */
+        if ((cdir->dcache_ctime != st.st_ctime) || (cdir->dcache_ino != st.st_ino)) {
             LOG(log_debug, logtype_afpd, "dircache(did:%u,\"%s\"): {modified}",
                 ntohl(dir->d_did), name);
             (void)dir_remove(vol, cdir);
@@ -465,7 +462,7 @@ int dircache_add(const struct vol *vol,
         dircache_stat.expunged++;
     }
     key.d_vid = vol->v_vid;
-    key.d_pdid = dir->d_did;
+    key.d_pdid = dir->d_pdid;
     key.d_u_name = dir->d_u_name;
     if ((hn = hash_lookup(index_didname, &key))) {
         /* Found an entry with the same DID/name, delete it */
@@ -560,7 +557,7 @@ void dircache_remove(const struct vol *vol _U_, struct dir *dir, int flags)
  * - a DID/name index on the main dircache
  * - a queue index on the dircache
  *
- * @param size   (r) requested maximum size from afpd.conf
+ * @param size   (r) requested maximum size from afp.conf
  *
  * @return 0 on success, -1 on error
  */
@@ -597,6 +594,7 @@ int dircache_init(int reqsize)
     rootParent.d_fullpath = bfromcstr("ROOT_PARENT");
     rootParent.d_m_name = bfromcstr("ROOT_PARENT");
     rootParent.d_u_name = rootParent.d_m_name;
+    rootParent.d_rights_cache = 0xffffffff;
 
     return 0;
 }
@@ -695,5 +693,6 @@ void dircache_dump(void)
 
     fprintf(dump, "\n");
     fflush(dump);
+    fclose(dump);
     return;
 }