]> arthur.barton.de Git - netatalk.git/blob - etc/afpd/filedir.c
long name an utf8 name in the same query (copy the same name for now). More
[netatalk.git] / etc / afpd / filedir.c
1 /*
2  * $Id: filedir.c,v 1.35 2002-10-25 11:10:48 didg Exp $
3  *
4  * Copyright (c) 1990,1993 Regents of The University of Michigan.
5  * All Rights Reserved.  See COPYRIGHT.
6  */
7
8 #ifdef HAVE_CONFIG_H
9 #include "config.h"
10 #endif /* HAVE_CONFIG_H */
11
12 #include <errno.h>
13 #include <atalk/logger.h>
14 #include <sys/types.h>
15 #include <sys/stat.h>
16 #include <sys/param.h>
17 #include <netatalk/endian.h>
18 #include <atalk/adouble.h>
19 #include <atalk/afp.h>
20 #include <atalk/util.h>
21 #ifdef CNID_DB
22 #include <atalk/cnid.h>
23 #endif /* CNID_DB */
24 #include <stdio.h>
25 #include <stdlib.h>
26 #ifdef HAVE_FCNTL_H
27 #include <fcntl.h>
28 #endif /* HAVE_FCNTL_H */
29 #include <dirent.h>
30
31 /* STDC check */
32 #if STDC_HEADERS
33 #include <string.h>
34 #else /* STDC_HEADERS */
35 #ifndef HAVE_STRCHR
36 #define strchr index
37 #define strrchr index
38 #endif /* HAVE_STRCHR */
39 char *strchr (), *strrchr ();
40 #ifndef HAVE_MEMCPY
41 #define memcpy(d,s,n) bcopy ((s), (d), (n))
42 #define memmove(d,s,n) bcopy ((s), (d), (n))
43 #endif /* ! HAVE_MEMCPY */
44 #endif /* STDC_HEADERS */
45
46 #ifdef HAVE_UNISTD_H
47 #include <unistd.h>
48 #endif /* HAVE_UNISTD_H */
49
50 #include "directory.h"
51 #include "desktop.h"
52 #include "volume.h"
53 #include "fork.h"
54 #include "file.h"
55 #include "globals.h"
56 #include "filedir.h"
57 #include "unix.h"
58
59 int matchfile2dirperms(upath, vol, did)
60 /* Since it's kinda' big; I decided against an
61 inline function */
62 char    *upath;
63 struct vol  *vol;
64 int             did;
65 /* The below code changes the way file ownership is determined in the name of
66 fixing dropboxes.  It has known security problem.  See the netatalk FAQ for
67 more information */
68 {
69     struct stat st, sb;
70     struct dir  *dir;
71     char        *adpath;
72     uid_t       uid;
73     int         ret = AFP_OK;
74 #ifdef DEBUG
75     LOG(log_info, logtype_afpd, "begin matchfile2dirperms:");
76 #endif /* DEBUG */
77
78     if (stat(upath, &st ) < 0) {
79         LOG(log_error, logtype_afpd, "Could not stat %s: %s", upath, strerror(errno));
80         return AFPERR_NOOBJ ;
81     }
82
83     adpath = ad_path( upath, ADFLAGS_HF );
84     /* FIXME dirsearch doesn't move cwd to did ! */
85     if (( dir = dirlookup( vol, did )) == NULL ) {
86         LOG(log_error, logtype_afpd, "matchfile2dirperms: Unable to get directory info.");
87         ret = AFPERR_NOOBJ;
88     }
89     else if (stat(".", &sb) < 0) {
90         LOG(log_error, logtype_afpd,
91             "matchfile2dirperms: Error checking directory \"%s\": %s",
92             dir->d_m_name, strerror(errno));
93         ret = AFPERR_NOOBJ;
94     }
95     else {
96         uid=geteuid();
97         if ( uid != sb.st_uid )
98         {
99             seteuid(0);
100             if (lchown(upath, sb.st_uid, sb.st_gid) < 0)
101             {
102                 LOG(log_error, logtype_afpd,
103                     "matchfile2dirperms: Error changing owner/gid of %s: %s",
104                     upath, strerror(errno));
105                 ret = AFPERR_ACCESS;
106             }
107             else if (chmod(upath,(st.st_mode&~default_options.umask)| S_IRGRP| S_IROTH) < 0)
108             {
109                 LOG(log_error, logtype_afpd,
110                     "matchfile2dirperms:  Error adding file read permissions: %s",
111                     strerror(errno));
112                 ret = AFPERR_ACCESS;
113             }
114             else if (lchown(adpath, sb.st_uid, sb.st_gid) < 0)
115             {
116                 LOG(log_error, logtype_afpd,
117                     "matchfile2dirperms: Error changing AppleDouble owner/gid %s: %s",
118                     adpath, strerror(errno));
119                 ret = AFPERR_ACCESS;
120             }
121             else if (chmod(adpath, (st.st_mode&~default_options.umask)| S_IRGRP| S_IROTH) < 0)
122             {
123                 LOG(log_error, logtype_afpd,
124                     "matchfile2dirperms:  Error adding AD file read permissions: %s",
125                     strerror(errno));
126                 ret = AFPERR_ACCESS;
127             }
128             seteuid(uid); 
129         }
130     } /* end else if stat success */
131
132 #ifdef DEBUG
133     LOG(log_info, logtype_afpd, "end matchfile2dirperms:");
134 #endif /* DEBUG */
135     return ret;
136 }
137
138
139 int afp_getfildirparams(obj, ibuf, ibuflen, rbuf, rbuflen )
140 AFPObj      *obj;
141 char    *ibuf, *rbuf;
142 int             ibuflen, *rbuflen;
143 {
144     struct stat         *st;
145     struct vol          *vol;
146     struct dir          *dir;
147     u_int32_t           did;
148     int                 buflen, ret;
149     u_int16_t           fbitmap, dbitmap, vid;
150     struct path         *s_path;
151
152 #ifdef DEBUG
153     LOG(log_info, logtype_afpd, "begin afp_getfildirparams:");
154 #endif /* DEBUG */
155
156     *rbuflen = 0;
157     ibuf += 2;
158
159     memcpy( &vid, ibuf, sizeof( vid ));
160     ibuf += sizeof( vid );
161     if (( vol = getvolbyvid( vid )) == NULL ) {
162         return( AFPERR_PARAM );
163     }
164
165     memcpy( &did, ibuf, sizeof( did ));
166     ibuf += sizeof( did );
167
168     if (( dir = dirlookup( vol, did )) == NULL ) {
169         return( AFPERR_NOOBJ );
170     }
171
172     memcpy( &fbitmap, ibuf, sizeof( fbitmap ));
173     fbitmap = ntohs( fbitmap );
174     ibuf += sizeof( fbitmap );
175     memcpy( &dbitmap, ibuf, sizeof( dbitmap ));
176     dbitmap = ntohs( dbitmap );
177     ibuf += sizeof( dbitmap );
178
179     if (( s_path = cname( vol, dir, &ibuf )) == NULL) {
180         return( AFPERR_NOOBJ );
181     }
182
183     st   = &s_path->st;
184     if (!s_path->st_valid) {
185         /* it's a dir and it should be there
186          * because we chdir in it in cname
187          */
188         of_stat(s_path);
189     }
190     if ( s_path->st_errno != 0 ) {
191         return( AFPERR_NOOBJ );
192     }
193
194     buflen = 0;
195     if (S_ISDIR(st->st_mode)) {
196         if (dbitmap) {
197             ret = getdirparams(vol, dbitmap, s_path, curdir,
198                                  rbuf + 3 * sizeof( u_int16_t ), &buflen );
199             if (ret != AFP_OK )
200                 return( ret );
201         }
202         /* this is a directory */
203         *(rbuf + 2 * sizeof( u_int16_t )) = (char) FILDIRBIT_ISDIR;
204     } else {
205         if (fbitmap && ( ret = getfilparams(vol, fbitmap, s_path, curdir, 
206                                             rbuf + 3 * sizeof( u_int16_t ), &buflen )) != AFP_OK ) {
207             return( ret );
208         }
209         /* this is a file */
210         *(rbuf + 2 * sizeof( u_int16_t )) = FILDIRBIT_ISFILE;
211     }
212     *rbuflen = buflen + 3 * sizeof( u_int16_t );
213     fbitmap = htons( fbitmap );
214     memcpy( rbuf, &fbitmap, sizeof( fbitmap ));
215     rbuf += sizeof( fbitmap );
216     dbitmap = htons( dbitmap );
217     memcpy( rbuf, &dbitmap, sizeof( dbitmap ));
218     rbuf += sizeof( dbitmap ) + sizeof( u_char );
219     *rbuf = 0;
220
221 #ifdef DEBUG
222     LOG(log_info, logtype_afpd, "end afp_getfildirparams:");
223 #endif /* DEBUG */
224
225     return( AFP_OK );
226 }
227
228 int afp_setfildirparams(obj, ibuf, ibuflen, rbuf, rbuflen )
229 AFPObj      *obj;
230 char    *ibuf, *rbuf;
231 int             ibuflen, *rbuflen;
232 {
233     struct stat *st;
234     struct vol  *vol;
235     struct dir  *dir;
236     struct path *path;
237     u_int16_t   vid, bitmap;
238     int         did, rc;
239
240 #ifdef DEBUG
241     LOG(log_info, logtype_afpd, "begin afp_setfildirparams:");
242 #endif /* DEBUG */
243
244     *rbuflen = 0;
245     ibuf += 2;
246     memcpy( &vid, ibuf, sizeof(vid));
247     ibuf += sizeof( vid );
248
249     if (( vol = getvolbyvid( vid )) == NULL ) {
250         return( AFPERR_PARAM );
251     }
252
253     if (vol->v_flags & AFPVOL_RO)
254         return AFPERR_VLOCK;
255
256     memcpy( &did, ibuf, sizeof( did));
257     ibuf += sizeof( did);
258
259     if (( dir = dirlookup( vol, did )) == NULL ) {
260         return( AFPERR_NOOBJ );
261     }
262
263     memcpy( &bitmap, ibuf, sizeof( bitmap ));
264     bitmap = ntohs( bitmap );
265     ibuf += sizeof( bitmap );
266
267     if (( path = cname( vol, dir, &ibuf )) == NULL ) {
268         return( AFPERR_NOOBJ );
269     }
270
271     st   = &path->st;
272     if (!path->st_valid) {
273         /* it's a dir and it should be there
274          * because we chdir in it in cname
275          */
276         of_stat(path);
277     }
278
279     if ( path->st_errno != 0 ) {
280         return( AFPERR_NOOBJ );
281     }
282     /*
283      * If ibuf is odd, make it even.
284      */
285     if ((u_long)ibuf & 1 ) {
286         ibuf++;
287     }
288
289     if (S_ISDIR(st->st_mode)) {
290         rc = setdirparams(vol, path, bitmap, ibuf );
291     } else {
292         rc = setfilparams(vol, path, bitmap, ibuf );
293     }
294     if ( rc == AFP_OK ) {
295         setvoltime(obj, vol );
296     }
297
298 #ifdef DEBUG
299     LOG(log_info, logtype_afpd, "end afp_setfildirparams:");
300 #endif /* DEBUG */
301
302     return( rc );
303 }
304
305 /* -------------------------------------------- 
306    Factorise some check on a pathname
307 */
308 int check_name(const struct vol *vol, char *name)
309 {
310     /* check for illegal characters in the unix filename */
311     if (!wincheck(vol, name))
312         return AFPERR_PARAM;
313
314     if ((vol->v_flags & AFPVOL_NOHEX) && strchr(name, '/'))
315         return AFPERR_PARAM;
316
317     if (!validupath(vol, name))
318         return AFPERR_EXIST;
319
320     /* check for vetoed filenames */
321     if (veto_file(vol->v_veto, name))
322         return AFPERR_EXIST;
323     return 0;
324 }
325
326 /* ------------------------- 
327     move and rename sdir:oldname to curdir:newname in volume vol
328    
329     special care is needed for lock   
330 */
331 static int moveandrename(vol, sdir, oldname, newname, isdir)
332 const struct vol        *vol;
333 struct dir      *sdir;
334 char        *oldname;
335 char        *newname;
336 int         isdir;
337 {
338     char            *p;
339     char            *upath;
340     int             rc;
341     struct stat     *st;
342     int             adflags;
343     struct adouble      ad;
344     struct adouble      *adp;
345     struct ofork        *opened = NULL;
346     struct path         path;
347 #ifdef CNID_DB
348     cnid_t      id;
349 #endif /* CNID_DB */
350
351     memset(&ad, 0, sizeof(ad));
352     adp = &ad;
353     adflags = 0;
354     
355     if (!isdir) {
356 #ifdef CNID_DB
357         p = mtoupath(vol, oldname);
358         id = cnid_get(vol->v_db, sdir->d_did, p, strlen(p));
359 #endif /* CNID_DB */
360         p = ctoupath( vol, sdir, oldname );
361         path.st_valid = 0;
362         path.u_name = p;
363         if ((opened = of_findname(&path))) {
364             /* reuse struct adouble so it won't break locks */
365             adp = opened->of_ad;
366         }
367     }
368     else {
369 #ifdef CNID_DB
370         id = sdir->d_did; /* we already have the CNID */
371 #endif /* CNID_DB */
372         p = ctoupath( vol, sdir->d_parent, oldname );
373         adflags = ADFLAGS_DIR;
374     }
375     /*
376      * p now points to the full pathname of the source fs object.
377      * 
378      * we are in the dest folder so we need to use p for ad_open
379     */
380     
381     if (!ad_open(p, ADFLAGS_HF |adflags, O_RDONLY, 0666, adp)) {
382     u_int16_t bshort;
383
384         ad_getattr(adp, &bshort);
385         ad_close( adp, ADFLAGS_HF );
386         if ((bshort & htons(ATTRBIT_NORENAME))) 
387             return(AFPERR_OLOCK);
388     }
389
390     upath = mtoupath(vol, newname);
391     path.u_name = upath;
392     st = &path.st;    
393     if (0 != (rc = check_name(vol, upath))) {
394             return  rc;
395     }
396
397     /* source == destination. we just silently accept this. */
398     if (curdir == sdir) {
399         if (strcmp(oldname, newname) == 0)
400             return AFP_OK;
401
402         /* deal with case insensitive, case-preserving filesystems. */
403         if ((stat(upath, st) == 0) && strdiacasecmp(oldname, newname))
404             return AFPERR_EXIST;
405
406     } else if (stat(upath, st ) == 0)
407         return AFPERR_EXIST;
408
409     if ( !isdir ) {
410         path.st_valid = 1;
411         path.st_errno = errno;
412         if (of_findname(&path)) {
413             rc = AFPERR_EXIST; /* was AFPERR_BUSY; */
414         } else {
415             rc = renamefile( p, upath, newname,vol_noadouble(vol), adp );
416             if (rc == AFP_OK)
417                 of_rename(vol, opened, sdir, oldname, curdir, newname);
418         }
419     } else {
420         rc = renamedir(p, upath, sdir, curdir, newname, vol_noadouble(vol));
421     }
422     if ( rc == AFP_OK ) {
423 #ifdef CNID_DB
424         /* renaming may have moved the file/dir across a filesystem */
425         if (stat(upath, st) < 0)
426             return AFPERR_MISC;
427
428         /* fix up the catalog entry */
429         cnid_update(vol->v_db, id, st, curdir->d_did, upath, strlen(upath));
430 #endif /* CNID_DB */
431     }
432
433     return rc;
434 }
435
436 /* -------------------------------------------- */
437 int afp_rename(obj, ibuf, ibuflen, rbuf, rbuflen )
438 AFPObj      *obj;
439 char    *ibuf, *rbuf;
440 int             ibuflen, *rbuflen;
441 {
442     struct vol  *vol;
443     struct dir  *sdir;
444     char        *oldname, *newname;
445     struct path *path;
446     u_int32_t   did;
447     int         plen;
448     u_int16_t   vid;
449     int         isdir = 0;
450     int         rc;
451 #ifdef DEBUG
452     LOG(log_info, logtype_afpd, "begin afp_rename:");
453 #endif /* DEBUG */
454
455     *rbuflen = 0;
456     ibuf += 2;
457
458     memcpy( &vid, ibuf, sizeof( vid ));
459     ibuf += sizeof( vid );
460     if (( vol = getvolbyvid( vid )) == NULL ) {
461         return( AFPERR_PARAM );
462     }
463
464     if (vol->v_flags & AFPVOL_RO)
465         return AFPERR_VLOCK;
466
467     memcpy( &did, ibuf, sizeof( did ));
468     ibuf += sizeof( did );
469     if (( sdir = dirlookup( vol, did )) == NULL ) {
470         return( AFPERR_NOOBJ );
471     }
472
473     /* source pathname */
474     if (( path = cname( vol, sdir, &ibuf )) == NULL ) {
475         return( AFPERR_NOOBJ );
476     }
477
478     sdir = curdir;
479     newname = obj->newtmp;
480     oldname = obj->oldtmp;
481     if ( *path->m_name != '\0' ) {
482         strcpy(oldname, path->m_name); /* an extra copy for of_rename */
483     }
484     else {
485         if ( sdir->d_parent == NULL ) { /* root directory */
486             return( AFPERR_NORENAME );
487         }
488         /* move to destination dir */
489         if ( movecwd( vol, sdir->d_parent ) < 0 ) {
490             return( AFPERR_NOOBJ );
491         }
492         isdir = 1;
493         strcpy(oldname, sdir->d_m_name);
494     }
495
496     /* another place where we know about the path type */
497     if ((plen = copy_path_name(newname, ibuf)) < 0) {
498         return( AFPERR_PARAM );
499     }
500
501     if (!plen) {
502         return AFP_OK; /* newname == oldname same dir */
503     }
504     
505     rc = moveandrename(vol, sdir, oldname, newname, isdir);
506
507     if ( rc == AFP_OK ) {
508         setvoltime(obj, vol );
509     }
510
511 #ifdef DEBUG
512     LOG(log_info, logtype_afpd, "end afp_rename:");
513 #endif /* DEBUG */
514
515     return( rc );
516 }
517
518 /* ------------------------------- */
519 int afp_delete(obj, ibuf, ibuflen, rbuf, rbuflen )
520 AFPObj      *obj;
521 char    *ibuf, *rbuf;
522 int             ibuflen, *rbuflen;
523 {
524     struct vol          *vol;
525     struct dir          *dir;
526     struct path         *s_path;
527     char                *upath;
528     int                 did, rc;
529     u_int16_t           vid;
530
531 #ifdef DEBUG
532     LOG(log_info, logtype_afpd, "begin afp_delete:");
533 #endif /* DEBUG */ 
534
535     *rbuflen = 0;
536     ibuf += 2;
537
538     memcpy( &vid, ibuf, sizeof( vid ));
539     ibuf += sizeof( vid );
540     if (( vol = getvolbyvid( vid )) == NULL ) {
541         return( AFPERR_PARAM );
542     }
543
544     if (vol->v_flags & AFPVOL_RO)
545         return AFPERR_VLOCK;
546
547     memcpy( &did, ibuf, sizeof( did ));
548     ibuf += sizeof( int );
549     if (( dir = dirlookup( vol, did )) == NULL ) {
550         return( AFPERR_NOOBJ );
551     }
552
553     if (( s_path = cname( vol, dir, &ibuf )) == NULL ) {
554         return( AFPERR_NOOBJ );
555     }
556
557     upath = s_path->u_name;
558     if ( *s_path->m_name == '\0' ) {
559         rc = deletecurdir( vol, obj->oldtmp, AFPOBJ_TMPSIZ);
560     } else if (of_findname(s_path)) {
561         rc = AFPERR_BUSY;
562     } else if ((rc = deletefile( upath, 1)) == AFP_OK) {
563 #ifdef CNID_DB /* get rid of entry */
564         cnid_t id = cnid_get(vol->v_db, curdir->d_did, upath, strlen(upath));
565         cnid_delete(vol->v_db, id);
566 #endif /* CNID_DB */
567     }
568     if ( rc == AFP_OK ) {
569         curdir->offcnt--;
570         setvoltime(obj, vol );
571     }
572
573 #ifdef DEBUG
574     LOG(log_info, logtype_afpd, "end afp_delete:");
575 #endif /* DEBUG */
576
577     return( rc );
578 }
579 char *absupath( vol, dir, u )
580 const struct vol        *vol;
581 struct dir      *dir;
582 char    *u;
583 {
584     struct dir  *d;
585     static char path[ MAXPATHLEN + 1];
586     char        *p;
587     int         len;
588
589     p = path + sizeof( path ) - 1;
590     *p = '\0';
591     len = strlen( u );
592     p -= len;
593     strncpy( p, u, len );
594     for ( d = dir; d->d_parent; d = d->d_parent ) {
595         *--p = '/';
596         u = d->d_u_name;
597         len = strlen( u );
598         p -= len;
599         strncpy( p, u, len );
600     }
601     *--p = '/';
602     len = strlen( vol->v_path );
603     p -= len;
604     strncpy( p, vol->v_path, len );
605
606     return( p );
607 }
608
609 char *ctoupath( vol, dir, name )
610 const struct vol        *vol;
611 struct dir      *dir;
612 char    *name;
613 {
614     return absupath(vol, dir, mtoupath(vol, name));
615 }
616
617 /* ------------------------- */
618 int afp_moveandrename(obj, ibuf, ibuflen, rbuf, rbuflen )
619 AFPObj      *obj;
620 char    *ibuf, *rbuf;
621 int             ibuflen, *rbuflen;
622 {
623     struct vol  *vol;
624     struct dir  *sdir, *ddir;
625     int         isdir = 0;
626     char        *oldname, *newname;
627     struct path *path;
628     int         did;
629     int         plen;
630     u_int16_t   vid;
631     int         rc;
632 #ifdef DROPKLUDGE
633     int         retvalue;
634 #endif /* DROPKLUDGE */
635
636 #ifdef DEBUG
637     LOG(log_info, logtype_afpd, "begin afp_moveandrename:");
638 #endif /* DEBUG */
639
640     *rbuflen = 0;
641     ibuf += 2;
642
643     memcpy( &vid, ibuf, sizeof( vid ));
644     ibuf += sizeof( vid );
645     if (( vol = getvolbyvid( vid )) == NULL ) {
646         return( AFPERR_PARAM );
647     }
648
649     if (vol->v_flags & AFPVOL_RO)
650         return AFPERR_VLOCK;
651
652     /* source did followed by dest did */
653     memcpy( &did, ibuf, sizeof( did ));
654     ibuf += sizeof( int );
655     if (( sdir = dirlookup( vol, did )) == NULL ) {
656         return( AFPERR_PARAM );
657     }
658
659     memcpy( &did, ibuf, sizeof( did ));
660     ibuf += sizeof( int );
661
662     /* source pathname */
663     if (( path = cname( vol, sdir, &ibuf )) == NULL ) {
664         return( AFPERR_NOOBJ );
665     }
666
667     sdir = curdir;
668     newname = obj->newtmp;
669     oldname = obj->oldtmp;
670     if ( *path->m_name != '\0' ) {
671         /* not a directory */
672         strcpy(oldname, path->m_name); /* an extra copy for of_rename */
673     } else {
674         isdir = 1;
675         strcpy(oldname, sdir->d_m_name);
676     }
677
678     /* get the destination directory */
679     if (( ddir = dirlookup( vol, did )) == NULL ) {
680         return( AFPERR_PARAM );
681     }
682     if (( path = cname( vol, ddir, &ibuf )) == NULL ) {
683         return( AFPERR_NOOBJ );
684     }
685     if ( *path->m_name != '\0' ) {
686         return( AFPERR_BADTYPE );
687     }
688
689     /* one more place where we know about path type */
690     if ((plen = copy_path_name(newname, ibuf)) < 0) {
691         return( AFPERR_PARAM );
692     }
693
694     if (!plen) {
695         strcpy(newname, oldname);
696     }
697
698     rc = moveandrename(vol, sdir, oldname, newname, isdir);
699
700     if ( rc == AFP_OK ) {
701         curdir->offcnt++;
702         sdir->offcnt--;
703
704         char *upath = mtoupath(vol, newname);
705 #ifdef DROPKLUDGE
706         if (vol->v_flags & AFPVOL_DROPBOX) {
707             if ((retvalue=matchfile2dirperms (upath, vol, did)) != AFP_OK) {
708                 return retvalue;
709             }
710         }
711         else
712 #endif /* DROPKLUDGE */
713             if (!isdir) {
714                 int  admode = ad_mode("", 0777);
715
716                 setfilmode(upath, admode, NULL);
717                 setfilmode(ad_path( upath, ADFLAGS_HF ), ad_hf_mode(admode), NULL);
718             }
719         setvoltime(obj, vol );
720     }
721
722 #ifdef DEBUG
723     LOG(log_info, logtype_afpd, "end afp_moveandrename:");
724 #endif /* DEBUG */
725
726     return( rc );
727 }
728
729 int veto_file(const char*veto_str, const char*path)
730 /* given a veto_str like "abc/zxc/" and path "abc", return 1
731  * veto_str should be '/' delimited
732  * if path matches any one of the veto_str elements exactly, then 1 is returned
733  * otherwise, 0 is returned.
734  */
735 {
736     int i;      /* index to veto_str */
737     int j;      /* index to path */
738
739     if ((veto_str == NULL) || (path == NULL))
740         return 0;
741     /*
742     #ifdef DEBUG
743         LOG(log_debug, logtype_afpd, "veto_file \"%s\", \"%s\"", veto_str, path);
744     #endif
745     */
746     for(i=0, j=0; veto_str[i] != '\0'; i++) {
747         if (veto_str[i] == '/') {
748             if ((j>0) && (path[j] == '\0'))
749                 return 1;
750             j = 0;
751         } else {
752             if (veto_str[i] != path[j]) {
753                 while ((veto_str[i] != '/')
754                         && (veto_str[i] != '\0'))
755                     i++;
756                 j = 0;
757                 continue;
758             }
759             j++;
760         }
761     }
762     return 0;
763 }
764