]> arthur.barton.de Git - netatalk.git/blobdiff - etc/afpd/enumerate.c
Configurable symlink behaviour
[netatalk.git] / etc / afpd / enumerate.c
index a0453d94809f9209928661ca9c0589437db5af76..2a3893354838f51cded7ff6e7628ef058cd74784 100644 (file)
@@ -1,6 +1,4 @@
 /*
- * $Id: enumerate.c,v 1.46 2009-10-14 15:04:00 franklahm Exp $
- *
  * Copyright (c) 1990,1993 Regents of The University of Michigan.
  * All Rights Reserved.  See COPYRIGHT.
  */
 #include <atalk/adouble.h>
 #include <atalk/vfs.h>
 #include <atalk/cnid.h>
+#include <atalk/util.h>
+#include <atalk/bstrlib.h>
+#include <atalk/bstradd.h>
+#include <atalk/globals.h>
+
 #include "desktop.h"
 #include "directory.h"
+#include "dircache.h"
 #include "volume.h"
-#include "globals.h"
 #include "file.h"
 #include "fork.h"
 #include "filedir.h"
@@ -152,18 +155,19 @@ for_each_dirent(const struct vol *vol, char *name, dir_loop fn, void *data)
    macnamelength(1) + macname(31) + utf8(4) + utf8namelen(2) + utf8name(255) +
    oddpadding(1) */
 
-#define REPLY_PARAM_MAXLEN (4 + 104 + 1 + MACFILELEN + 4 + 2 + 255 + 1)
+#define REPLY_PARAM_MAXLEN (4 + 104 + 1 + MACFILELEN + 4 + 2 + UTF8FILELEN_EARLY + 1)
 
 /* ----------------------------- */
-static int enumerate(AFPObj *obj _U_, char *ibuf, unsigned int ibuflen _U_, 
+static int enumerate(AFPObj *obj _U_, char *ibuf, size_t ibuflen _U_, 
     char *rbuf, 
-    unsigned int *rbuflen, 
+    size_t *rbuflen, 
     int ext)
 {
     static struct savedir      sd = { 0, 0, 0, NULL, NULL, 0 };
     struct vol                 *vol;
     struct dir                 *dir;
-    int                                did, ret, esz, len, first = 1;
+    int                                did, ret, len, first = 1;
+    size_t                     esz;
     char                        *data, *start;
     u_int16_t                  vid, fbitmap, dbitmap, reqcnt, actcnt = 0;
     u_int16_t                  temp16;
@@ -265,6 +269,9 @@ static int enumerate(AFPObj *obj _U_, char *ibuf, unsigned int ibuflen _U_,
         return path_error(o_path, AFPERR_NODIR );
     }
 
+    LOG(log_debug, logtype_afpd, "enumerate(\"%s/%s\", f/d:%04x/%04x, rc:%u, i:%u, max:%u)",
+        getcwdpath(), o_path->u_name, fbitmap, dbitmap, reqcnt, sindex, maxsz);
+
     data = rbuf + 3 * sizeof( u_int16_t );
     sz = 3 * sizeof( u_int16_t );      /* fbitmap, dbitmap, reqcount */
 
@@ -276,12 +283,13 @@ static int enumerate(AFPObj *obj _U_, char *ibuf, unsigned int ibuflen _U_,
     if ( sindex == 1 || curdir->d_did != sd.sd_did || vid != sd.sd_vid ) {
         sd.sd_last = sd.sd_buf;
         /* if dir was in the cache we don't have the inode */
-        if (( !o_path->st_valid && stat( ".", &o_path->st ) < 0 ) ||
-              (ret = for_each_dirent(vol, ".", enumerate_loop, (void *)&sd)) < 0) 
+        if (( !o_path->st_valid && ostat(".", &o_path->st, vol_syml_opt(vol)) < 0 ) ||
+            (ret = for_each_dirent(vol, ".", enumerate_loop, (void *)&sd)) < 0) 
         {
+            LOG(log_error, logtype_afpd, "enumerate: loop error: %s (%d)", strerror(errno), errno);
             switch (errno) {
             case EACCES:
-               return AFPERR_ACCESS;
+                return AFPERR_ACCESS;
             case ENOTDIR:
                 return AFPERR_BADTYPE;
             case ENOMEM:
@@ -339,7 +347,7 @@ static int enumerate(AFPObj *obj _U_, char *ibuf, unsigned int ibuflen _U_,
         }
         memset(&s_path, 0, sizeof(s_path));
         s_path.u_name = sd.sd_last;
-        if (of_stat( &s_path) < 0 ) {
+        if (of_stat(vol, &s_path) < 0 ) {
             /*
              * Somebody else plays with the dir, well it can be us with 
             * "Empty Trash..."
@@ -351,7 +359,7 @@ static int enumerate(AFPObj *obj _U_, char *ibuf, unsigned int ibuflen _U_,
              */
             *sd.sd_last = 0;
             sd.sd_last += len + 1;
-            curdir->offcnt--;          /* a little lie */
+            curdir->d_offcnt--;                /* a little lie */
             continue;
         }
 
@@ -366,19 +374,22 @@ static int enumerate(AFPObj *obj _U_, char *ibuf, unsigned int ibuflen _U_,
             if ( dbitmap == 0 ) {
                 continue;
             }
-            dir = dirsearch_byname(vol, curdir, s_path.u_name);
-            if (!dir && NULL == (dir = adddir( vol, curdir, &s_path) ) ) {
+            int len = strlen(s_path.u_name);
+            if ((dir = dircache_search_by_name(vol, curdir, s_path.u_name, len)) == NULL) {
+                if ((dir = dir_add(vol, curdir, &s_path, len)) == NULL) {
+                    LOG(log_error, logtype_afpd, "enumerate(vid:%u, did:%u, name:'%s'): error adding dir: '%s'",
+                        ntohs(vid), ntohl(did), o_path->u_name, s_path.u_name);
                     return AFPERR_MISC;
                 }
-            if (AFP_OK != ( ret = getdirparams(vol, dbitmap, &s_path, dir,
-                                     data + header , &esz ))) {
-                return( ret );
             }
+            if ((ret = getdirparams(vol, dbitmap, &s_path, dir, data + header , &esz)) != AFP_OK)
+                return( ret );
 
         } else {
             if ( fbitmap == 0 ) {
                 continue;
             }
+            /* files are added to the dircache in getfilparams() -> getmetadata() */
             if (AFP_OK != ( ret = getfilparams(vol, fbitmap, &s_path, curdir, 
                                      data + header , &esz )) ) {
                 return( ret );
@@ -450,25 +461,25 @@ static int enumerate(AFPObj *obj _U_, char *ibuf, unsigned int ibuflen _U_,
 }
 
 /* ----------------------------- */
-int afp_enumerate(AFPObj *obj, char *ibuf, unsigned int ibuflen, 
+int afp_enumerate(AFPObj *obj, char *ibuf, size_t ibuflen, 
     char *rbuf, 
-    unsigned int *rbuflen)
+    size_t *rbuflen)
 {
     return enumerate(obj, ibuf,ibuflen ,rbuf,rbuflen , 0);
 }
 
 /* ----------------------------- */
-int afp_enumerate_ext(AFPObj *obj, char *ibuf, unsigned int ibuflen, 
+int afp_enumerate_ext(AFPObj *obj, char *ibuf, size_t ibuflen, 
     char *rbuf, 
-    unsigned int *rbuflen)
+    size_t *rbuflen)
 {
     return enumerate(obj, ibuf,ibuflen ,rbuf,rbuflen , 1);
 }
 
 /* ----------------------------- */
-int afp_enumerate_ext2(AFPObj *obj, char *ibuf, unsigned int ibuflen, 
+int afp_enumerate_ext2(AFPObj *obj, char *ibuf, size_t ibuflen, 
     char *rbuf, 
-    unsigned int *rbuflen)
+    size_t *rbuflen)
 {
     return enumerate(obj, ibuf,ibuflen ,rbuf,rbuflen , 2);
 }