]> arthur.barton.de Git - netatalk.git/commitdiff
Several fixes in ad_conv_dehex()
authorRalph Boehme <sloowfranklin@gmail.com>
Tue, 19 Feb 2013 16:35:04 +0000 (17:35 +0100)
committerRalph Boehme <sloowfranklin@gmail.com>
Tue, 19 Feb 2013 16:35:04 +0000 (17:35 +0100)
Testing whether we need to perform dehexing was done by a simple
strchr(':'), thus names only containing a single ':' would trigger
dehexing even though they might not contain the relevant strings
":2e" or :2f".

Also fix a ressource leak in bfindreplace() and simplify the
check whether a rename took place in enumerate.c.

etc/afpd/enumerate.c
libatalk/adouble/ad_conv.c

index 0c3c0576e5249f3b679bc4714f65c710847581a6..5f0e1644a849e52efdfd059bb2467087dbd1dfb9 100644 (file)
@@ -362,16 +362,14 @@ static int enumerate(AFPObj *obj _U_, char *ibuf, size_t ibuflen _U_,
 
         /* conversions on the fly */
         const char *convname;
-        if (ad_convert(sd.sd_last, &s_path.st, vol, &convname) == 0 && convname) {
-            s_path.u_name = (char *)convname;
-        }
-
-        /* Fixup CNID db if ad_convert resulted in a rename (then convname != NULL) */
-        if (convname) {
-            s_path.id = cnid_lookup(vol->v_cdb, &s_path.st, curdir->d_did, sd.sd_last, strlen(sd.sd_last));
-            if (s_path.id != CNID_INVALID) {
-                if (cnid_update(vol->v_cdb, s_path.id, &s_path.st, curdir->d_did, (char *)convname, strlen(convname)) != 0)
-                    LOG(log_error, logtype_afpd, "enumerate: error updating CNID of \"%s\"", fullpathname(convname));
+        if (ad_convert(sd.sd_last, &s_path.st, vol, &convname) == 0) {
+            if (convname) {
+                s_path.u_name = (char *)convname;
+                s_path.id = cnid_lookup(vol->v_cdb, &s_path.st, curdir->d_did, sd.sd_last, strlen(sd.sd_last));
+                if (s_path.id != CNID_INVALID) {
+                    if (cnid_update(vol->v_cdb, s_path.id, &s_path.st, curdir->d_did, (char *)convname, strlen(convname)) != 0)
+                        LOG(log_error, logtype_afpd, "enumerate: error updating CNID of \"%s\"", fullpathname(convname));
+                }
             }
         }
 
index a9fae763affc2874f5e52d11e956f665cd6b13d6..151ab9fd12412313732fce2756aaae050d7524b9 100644 (file)
@@ -201,21 +201,31 @@ static int ad_conv_dehex(const char *path, const struct stat *sp, const struct v
 {
     EC_INIT;
     static char buf[MAXPATHLEN];
-    const char *p;
     int adflags = S_ISDIR(sp->st_mode) ? ADFLAGS_DIR : 0;
     bstring newpath = NULL;
+    static bstring str2e = NULL;
+    static bstring str2f = NULL;
+    static bstring strdot = NULL;
+    static bstring strcolon = NULL;
+
+    if (str2e == NULL) {
+        str2e = bfromcstr(":2e");
+        str2f = bfromcstr(":2f");
+        strdot = bfromcstr(".");
+        strcolon = bfromcstr(":");
+    }
 
     LOG(log_debug, logtype_ad,"ad_conv_dehex(\"%s\"): BEGIN", fullpathname(path));
 
     *newpathp = NULL;
 
-    if ((p = strchr(path, ':')) == NULL)
+    if (((strstr(path, ":2e")) == NULL) && ((strstr(path, ":2f")) == NULL) )
         goto EC_CLEANUP;
 
     EC_NULL( newpath = bfromcstr(path) );
 
-    EC_ZERO( bfindreplace(newpath, bfromcstr(":2e"), bfromcstr("."), 0) );
-    EC_ZERO( bfindreplace(newpath, bfromcstr(":2f"), bfromcstr(":"), 0) );
+    EC_ZERO( bfindreplace(newpath, str2e, strdot, 0) );
+    EC_ZERO( bfindreplace(newpath, str2f, strcolon, 0) );
     
     become_root();
     if (adflags != ADFLAGS_DIR)