]> arthur.barton.de Git - netatalk.git/blobdiff - etc/afpd/catsearch.c
Removed C++ comment.
[netatalk.git] / etc / afpd / catsearch.c
index d8cf010fb11096bee6721221cb8548d723d8aec4..bab3591e9bcd0ce65f1dfe06384b9c34ff35c84e 100644 (file)
@@ -30,6 +30,7 @@
 #include <errno.h>
 #include <syslog.h>
 #include <unistd.h>
+#include <ctype.h>
 
 #if STDC_HEADERS
 #include <string.h>
@@ -50,7 +51,7 @@
 #include <atalk/adouble.h>
 #ifdef CNID_DB
 #include <atalk/cnid.h>
-#endif /* DID_MTAB */
+#endif /* CNID_DB */
 #include "desktop.h"
 #include "directory.h"
 #include "file.h"
 #include "filedir.h"
 #include "fork.h"
 
-#ifdef DID_MTAB
-#include "parse-mtab.h"
-#endif /* DID_MTAB */
-
-#ifdef WITH_CATSEARCH
-
 struct finderinfo {
        u_int32_t f_type;
        u_int32_t creator;
@@ -179,7 +174,7 @@ static int reducestack()
                        /* Check if we need to free (or release) dir structures */
                } else
                        return dsidx - 1;
-       } // while
+       }
        return -1;
 } /* reducestack() */
 
@@ -200,6 +195,7 @@ static int resolve_dir(struct vol *vol, int cidx)
 {
        struct dir *dir, *curdir;
        struct stat statbuf;
+       char* mname = NULL;
 
        if (dstack[cidx].dir != NULL)
                return 1;
@@ -224,7 +220,8 @@ static int resolve_dir(struct vol *vol, int cidx)
                        return 0;
                }
 
-       if (!dir && ((dir = adddir(vol, curdir, dstack[cidx].lname, strlen(dstack[cidx].lname),
+       mname = utompath(vol, dstack[cidx].lname);
+       if (!dir && ((dir = adddir(vol, curdir, mname, strlen(mname),
                                                dstack[cidx].path, strlen(dstack[cidx].path), &statbuf)) == NULL))
                        return 0;
        dstack[cidx].dir = dir;
@@ -233,24 +230,19 @@ static int resolve_dir(struct vol *vol, int cidx)
 } /* resolve_dir */
 
 /* Looks up for an opened adouble structure, opens resource fork of selected file. */
-static struct adouble *adl_lkup(struct vol *vol, char *upath, int cidx, int isdir)
+static struct adouble *adl_lkup(char *upath, struct stat *sb)
 {
        static struct adouble ad;
        struct adouble *adp;
-       char *mpath = utompath(vol, upath);
        struct ofork *of;
+       int isdir = S_ISDIR(sb->st_mode);
 
-/*
-       //if (dstack[cidx].dir == NULL && !resolve_dir(vol, cidx))
-       //      return NULL;
-
-       //if ((of = of_findname(vol, dstack[cidx].dir, mpath))) {
-       //      adp = of->of_ad;
-       //} else {
-       */
+       if (!isdir && (of = of_findname(upath, sb ))) {
+               adp = of->of_ad;
+       } else {
                memset(&ad, 0, sizeof(ad));
                adp = &ad;
-       /* } */
+       } 
 
        if ( ad_open( upath, ADFLAGS_HF | (isdir)?ADFLAGS_DIR:0, O_RDONLY, 0, adp) < 0 ) {
                return NULL;
@@ -316,7 +308,7 @@ static int crit_check(struct vol *vol, char *uname, char *fname, int cidx) {
 
        /* Check for creation date... */
        if (c1.rbitmap & (1<<DIRPBIT_CDATE)) {
-               if (adp || (adp = adl_lkup(vol, uname, cidx, r))) {
+               if (adp || (adp = adl_lkup(uname, &sbuf))) {
                        if (ad_getdate(adp, AD_DATE_CREATE, (u_int32_t*)&c_date) >= 0)
                                c_date = AD_DATE_TO_UNIX(c_date);
                        else c_date = sbuf.st_mtime;
@@ -327,7 +319,7 @@ static int crit_check(struct vol *vol, char *uname, char *fname, int cidx) {
 
        /* Check for backup date... */
        if (c1.rbitmap & (1<<DIRPBIT_BDATE)) {
-               if (adp || (adp == adl_lkup(vol, uname, cidx, r))) {
+               if (adp || (adp == adl_lkup(uname, &sbuf))) {
                        if (ad_getdate(adp, AD_DATE_BACKUP, (u_int32_t*)&b_date) >= 0)
                                b_date = AD_DATE_TO_UNIX(b_date);
                        else b_date = sbuf.st_mtime;
@@ -337,45 +329,50 @@ static int crit_check(struct vol *vol, char *uname, char *fname, int cidx) {
        }
                                
        /* Check attributes */
-       if ((c1.rbitmap & (1<<DIRPBIT_ATTR)) && c2.attr != 0)
-               if (adp || (adp = adl_lkup(vol, uname, cidx, r))) {
+       if ((c1.rbitmap & (1<<DIRPBIT_ATTR)) && c2.attr != 0) {
+               if (adp || (adp = adl_lkup(uname, &sbuf))) {
                        ad_getattr(adp, &attr);
                        if ((attr & c2.attr) != c1.attr)
                                goto crit_check_ret;
                } else goto crit_check_ret;
+       }
                
 
         /* Check file type ID */
-       if ((c1.rbitmap & (1<<DIRPBIT_FINFO)) && c2.finfo.f_type != 0)
-               if (adp || (adp = adl_lkup(vol, uname, cidx, r))) {
+       if ((c1.rbitmap & (1<<DIRPBIT_FINFO)) && c2.finfo.f_type != 0) {
+               if (adp || (adp = adl_lkup(uname, &sbuf))) {
                        finfo = (struct finderinfo*)ad_entry(adp, ADEID_FINDERI);
                        if (finfo->f_type != c1.finfo.f_type)
                                goto crit_check_ret;
                } else goto crit_check_ret;
+       }
 
        /* Check creator ID */
-       if ((c1.rbitmap & (1<<DIRPBIT_FINFO)) && c2.finfo.creator != 0)
-               if (adp || (adp = adl_lkup(vol, uname, cidx, r))) {
+       if ((c1.rbitmap & (1<<DIRPBIT_FINFO)) && c2.finfo.creator != 0) {
+               if (adp || (adp = adl_lkup(uname, &sbuf))) {
                        finfo = (struct finderinfo*)ad_entry(adp, ADEID_FINDERI);
                        if (finfo->creator != c1.finfo.creator)
                                goto crit_check_ret;
                } else goto crit_check_ret;
+       }
        
        /* Check finder info attributes */
-       if ((c1.rbitmap & (1<<DIRPBIT_FINFO)) && c2.finfo.attrs != 0)
-               if (adp || (adp = adl_lkup(vol, uname, cidx, r))) {
+       if ((c1.rbitmap & (1<<DIRPBIT_FINFO)) && c2.finfo.attrs != 0) {
+               if (adp || (adp = adl_lkup(uname, &sbuf))) {
                        finfo = (struct finderinfo*)ad_entry(adp, ADEID_FINDERI);
                        if ((finfo->attrs & c2.finfo.attrs) != c1.finfo.attrs)
                                goto crit_check_ret;
                } else goto crit_check_ret;
+       }
 
        /* Check label */
-       if ((c1.rbitmap & (1<<DIRPBIT_FINFO)) && c2.finfo.label != 0)
-               if (adp || (adp = adl_lkup(vol, uname, cidx, r))) {
+       if ((c1.rbitmap & (1<<DIRPBIT_FINFO)) && c2.finfo.label != 0) {
+               if (adp || (adp = adl_lkup(uname, &sbuf))) {
                        finfo = (struct finderinfo*)ad_entry(adp, ADEID_FINDERI);
                        if ((finfo->label & c2.finfo.label) != c1.finfo.label)
                                goto crit_check_ret;
                } else goto crit_check_ret;
+       }
        
        /* FIXME: Attributes check ! */
        
@@ -392,7 +389,8 @@ crit_check_ret:
 static int rslt_add(struct vol *vol, struct stat *statbuf, char *fname, short cidx, int isdir, char **rbuf)
 {
        char *p = *rbuf;
-       int l = fname != NULL ? strlen(fname) : 0;
+       char *savefname = (fname != NULL) ? strdup (fname) : NULL;
+       int l = savefname != NULL ? strlen(savefname) : 0;
        u_int32_t did;
        char p0;
 
@@ -409,11 +407,13 @@ static int rslt_add(struct vol *vol, struct stat *statbuf, char *fname, short ci
        }
 
        /* Fill offset of returned file name */
-       if (fname != NULL) {
-               *p++ = 0;
-               *p++ = (int)(p - *rbuf) - 1;
+       if (savefname != NULL) {
+               *p = 0;
+               p += 1;
+               *p = (int)(p - *rbuf) - 1;
+               p += 1;
                p[0] = l;
-               strcpy(p+1, fname);
+               strcpy(p+1, savefname);
                p += l + 1;
        }
 
@@ -422,6 +422,8 @@ static int rslt_add(struct vol *vol, struct stat *statbuf, char *fname, short ci
 
        *rbuf = p;
        /* *rbuf[0] = (int)(p-*rbuf); */
+       if (savefname != NULL)
+               free (savefname);
        return 1;
 } /* rslt_add */
 
@@ -590,11 +592,8 @@ int afp_catsearch(AFPObj *obj, char *ibuf, int ibuflen,
     u_int32_t   rmatches, reserved;
     u_int32_t  catpos[4];
     u_int32_t   pdid = 0;
-    char        *lname = NULL;
-    struct dir *dir;
     int ret, rsize, i = 0;
     u_int32_t nrecs = 0;
-    static int nrr = 1;
     char *spec1, *spec2, *bspec1, *bspec2;
 
     memset(&c1, 0, sizeof(c1));
@@ -644,10 +643,10 @@ int afp_catsearch(AFPObj *obj, char *ibuf, int ibuflen,
 
     /* File attribute bits... */
     if (c1.rbitmap & (1 << FILPBIT_ATTR)) {
-           memcpy(&c1.attr, ibuf, sizeof(c1.attr));
+           memcpy(&c1.attr, spec1, sizeof(c1.attr));
            spec1 += sizeof(c1.attr);
            c1.attr = ntohs(c1.attr);
-           memcpy(&c2.attr, ibuf, sizeof(c2.attr));
+           memcpy(&c2.attr, spec2, sizeof(c2.attr));
            spec2 += sizeof(c1.attr);
            c2.attr = ntohs(c2.attr);
     }
@@ -692,7 +691,7 @@ int afp_catsearch(AFPObj *obj, char *ibuf, int ibuflen,
     }
 
     /* Finder info */
-    if (c1.rbitmap * (1 << FILPBIT_FINFO)) {
+    if (c1.rbitmap & (1 << FILPBIT_FINFO)) {
            memcpy(&c1.finfo, spec1, sizeof(c1.finfo));
            spec1 += sizeof(c1.finfo);
            memcpy(&c2.finfo, spec2, sizeof(c2.finfo));
@@ -721,12 +720,12 @@ int afp_catsearch(AFPObj *obj, char *ibuf, int ibuflen,
     if (c1.rbitmap & (1 << FILPBIT_LNAME)) {
         /* Get the long filename */    
        memcpy(c1.lname, bspec1 + spec1[1] + 1, (bspec1 + spec1[1])[0]);
-       c1.lname[(bspec1 + spec1[1])[0]]= 0;
+       c1.lname[(int) (bspec1 + spec1[1])[0]]= 0;
        for (i = 0; c1.lname[i] != 0; i++)
                c1.lname[i] = tolower(c1.lname[i]);
        /* FIXME: do we need it ? It's always null ! */
        memcpy(c2.lname, bspec2 + spec2[1] + 1, (bspec2 + spec2[1])[0]);
-       c2.lname[(bspec2 + spec2[1])[0]]= 0;
+       c2.lname[(int) (bspec2 + spec2[1])[0]]= 0;
        for (i = 0; c2.lname[i] != 0; i++)
                c2.lname[i] = tolower(c2.lname[i]);
     }
@@ -754,6 +753,3 @@ int afp_catsearch(AFPObj *obj, char *ibuf, int ibuflen,
 /* FIXME: we need a clean separation between afp stubs and 'real' implementation */
 /* (so, all buffer packing/unpacking should be done in stub, everything else 
    should be done in other functions) */
-
-#endif
-/* WITH_CATSEARCH */