]> arthur.barton.de Git - netatalk.git/blobdiff - bin/ad/ad_find.c
Mere sf master
[netatalk.git] / bin / ad / ad_find.c
index a233b9adf51385a05ed532f60c7780bffb30cb70..8501500c7c7ff9acb229a3a005a0279db55442d3 100644 (file)
@@ -33,6 +33,7 @@
 #include <atalk/bstradd.h>
 #include <atalk/directory.h>
 #include <atalk/util.h>
+#include <atalk/unicode.h>
 #include "ad.h"
 
 static volatile sig_atomic_t alarmed;
@@ -114,9 +115,26 @@ int ad_find(int argc, char **argv)
     if (openvol(srchvol, &vol) != 0)
         ERROR("Cant open volume \"%s\"", srchvol);
 
+    uint16_t flags = CONV_TOLOWER;
+    char namebuf[MAXPATHLEN + 1];
+    if (convert_charset(vol.volinfo.v_volcharset,
+                        vol.volinfo.v_volcharset,
+                        vol.volinfo.v_maccharset,
+                        argv[optind],
+                        strlen(argv[optind]),
+                        namebuf,
+                        MAXPATHLEN,
+                        &flags) == (size_t)-1) {
+        ERROR("conversion error");
+    }
+
     int count;
     char resbuf[DBD_MAX_SRCH_RSLTS * sizeof(cnid_t)];
-    if ((count = cnid_find(vol.volume.v_cdb, argv[optind], strlen(argv[optind]), resbuf, sizeof(resbuf))) < 1) {
+    if ((count = cnid_find(vol.volume.v_cdb,
+                           namebuf,
+                           strlen(namebuf),
+                           resbuf,
+                           sizeof(resbuf))) < 1) {
         ret = 1;
     } else {
         ret = 0;
@@ -138,14 +156,16 @@ int ad_find(int argc, char **argv)
 
             while (did != DIRDID_ROOT) {
                 if ((name = cnid_resolve(vol.volume.v_cdb, &did, buffer, buflen)) == NULL)
-                    ERROR("Can't resolve CNID: %u", ntohl(did));
+                    goto next;
                 bstrListPush(pathlist, bfromcstr(name));
             }
             bstrListPush(pathlist, volpath);
             path = bjoinInv(pathlist, sep);
-            bstrListDestroy(pathlist);
             
             printf("%s\n", cfrombstr(path));
+
+        next:
+            bstrListDestroy(pathlist);
             bdestroy(path);
         }
         bdestroy(sep);