]> arthur.barton.de Git - netatalk.git/blob - etc/afpd/filedir.c
A big patch to correct many afpd problems. For one, the trash will
[netatalk.git] / etc / afpd / filedir.c
1 /*
2  * $Id: filedir.c,v 1.27 2002-05-13 04:59:36 jmarcus 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
58 int matchfile2dirperms(upath, vol, did)
59 /* Since it's kinda' big; I decided against an
60 inline function */
61 char    *upath;
62 struct vol  *vol;
63 int             did;
64 /* The below code changes the way file ownership is determined in the name of
65 fixing dropboxes.  It has known security problem.  See the netatalk FAQ for
66 more information */
67 {
68     struct stat st, sb;
69     struct dir  *dir;
70     char        adpath[50];
71     int         uid;
72
73 #ifdef DEBUG
74     LOG(log_info, logtype_afpd, "begin matchfile2dirperms:");
75 #endif /* DEBUG */
76
77     if (stat(upath, &st ) < 0)
78         LOG(log_error, logtype_afpd, "Could not stat %s: %s", upath, strerror(errno));
79     strcpy (adpath, "./.AppleDouble/");
80     strcat (adpath, upath);
81     if (( dir = dirsearch( vol, did )) == NULL ) {
82         LOG(log_error, logtype_afpd, "matchfile2dirperms: Unable to get directory info.");
83         return( AFPERR_NOOBJ );
84     }
85     else if (stat(".", &sb) < 0) {
86         LOG(log_error, logtype_afpd,
87             "matchfile2dirperms: Error checking directory \"%s\": %s",
88             dir->d_name, strerror(errno));
89         return(AFPERR_NOOBJ );
90     }
91     else {
92         uid=geteuid();
93         if ( uid != sb.st_uid )
94         {
95             seteuid(0);
96             if (lchown(upath, sb.st_uid, sb.st_gid) < 0)
97             {
98                 LOG(log_error, logtype_afpd,
99                     "matchfile2dirperms: Error changing owner/gid of %s: %s",
100                     upath, strerror(errno));
101                 return (AFPERR_ACCESS);
102             }
103             if (chmod(upath,(st.st_mode&~default_options.umask)| S_IRGRP| S_IROTH) < 0)
104             {
105                 LOG(log_error, logtype_afpd,
106                     "matchfile2dirperms:  Error adding file read permissions: %s",
107                     strerror(errno));
108                 return (AFPERR_ACCESS);
109             }
110 #ifdef DEBUG
111             else
112                 LOG(log_info, logtype_afpd,
113                     "matchfile2dirperms:  Added S_IRGRP and S_IROTH: %s",
114                     strerror(errno));
115 #endif /* DEBUG */
116             if (lchown(adpath, sb.st_uid, sb.st_gid) < 0)
117             {
118                 LOG(log_error, logtype_afpd,
119                     "matchfile2dirperms: Error changing AppleDouble owner/gid %s: %s",
120                     adpath, strerror(errno));
121                 return (AFPERR_ACCESS);
122             }
123             if (chmod(adpath, (st.st_mode&~default_options.umask)| S_IRGRP| S_IROTH) < 0)
124             {
125                 LOG(log_error, logtype_afpd,
126                     "matchfile2dirperms:  Error adding AD file read permissions: %s",
127                     strerror(errno));
128                 return (AFPERR_ACCESS);
129             }
130 #ifdef DEBUG
131             else
132                 LOG(log_info, logtype_afpd,
133                     "matchfile2dirperms:  Added S_IRGRP and S_IROTH to AD: %s",
134                     strerror(errno));
135 #endif /* DEBUG */
136         }
137 #ifdef DEBUG
138         else
139             LOG(log_info, logtype_afpd,
140                 "matchfile2dirperms: No ownership change necessary.");
141 #endif /* DEBUG */
142     } /* end else if stat success */
143     seteuid(uid); /* Restore process ownership to normal */
144 #ifdef DEBUG
145     LOG(log_info, logtype_afpd, "end matchfile2dirperms:");
146 #endif /* DEBUG */
147
148     return (AFP_OK);
149
150 }
151
152
153 int afp_getfildirparams(obj, ibuf, ibuflen, rbuf, rbuflen )
154 AFPObj      *obj;
155 char    *ibuf, *rbuf;
156 int             ibuflen, *rbuflen;
157 {
158     struct stat         st;
159     struct vol          *vol;
160     struct dir          *dir;
161     u_int32_t           did;
162     int                 buflen, ret;
163     char                *path;
164     u_int16_t           fbitmap, dbitmap, vid;
165
166 #ifdef DEBUG
167     LOG(log_info, logtype_afpd, "begin afp_getfildirparams:");
168 #endif /* DEBUG */
169
170     *rbuflen = 0;
171     ibuf += 2;
172
173     memcpy( &vid, ibuf, sizeof( vid ));
174     ibuf += sizeof( vid );
175     if (( vol = getvolbyvid( vid )) == NULL ) {
176         return( AFPERR_PARAM );
177     }
178
179     memcpy( &did, ibuf, sizeof( did ));
180     ibuf += sizeof( did );
181
182     if (( dir = dirlookup( vol, did )) == NULL ) {
183         return( AFPERR_NOOBJ );
184     }
185
186     memcpy( &fbitmap, ibuf, sizeof( fbitmap ));
187     fbitmap = ntohs( fbitmap );
188     ibuf += sizeof( fbitmap );
189     memcpy( &dbitmap, ibuf, sizeof( dbitmap ));
190     dbitmap = ntohs( dbitmap );
191     ibuf += sizeof( dbitmap );
192
193     if (( path = cname( vol, dir, &ibuf )) == NULL) {
194         return( AFPERR_NOOBJ );
195     }
196
197     if ( stat( mtoupath(vol, path ), &st ) < 0 ) {
198         return( AFPERR_NOOBJ );
199     }
200
201     buflen = 0;
202     if (S_ISDIR(st.st_mode)) {
203         if (dbitmap) {
204             ret = getdirparams(vol, dbitmap, ".", curdir,
205                                &st, rbuf + 3 * sizeof( u_int16_t ), &buflen );
206             if (ret != AFP_OK )
207                 return( ret );
208         }
209         /* this is a directory */
210         *(rbuf + 2 * sizeof( u_int16_t )) = (char) FILDIRBIT_ISDIR;
211     } else {
212         if (fbitmap && ( ret = getfilparams(vol, fbitmap, path, curdir, &st,
213                                             rbuf + 3 * sizeof( u_int16_t ), &buflen )) != AFP_OK ) {
214             return( ret );
215         }
216         /* this is a file */
217         *(rbuf + 2 * sizeof( u_int16_t )) = FILDIRBIT_ISFILE;
218     }
219     *rbuflen = buflen + 3 * sizeof( u_int16_t );
220     fbitmap = htons( fbitmap );
221     memcpy( rbuf, &fbitmap, sizeof( fbitmap ));
222     rbuf += sizeof( fbitmap );
223     dbitmap = htons( dbitmap );
224     memcpy( rbuf, &dbitmap, sizeof( dbitmap ));
225     rbuf += sizeof( dbitmap ) + sizeof( u_char );
226     *rbuf = 0;
227
228 #ifdef DEBUG
229     LOG(log_info, logtype_afpd, "end afp_getfildirparams:");
230 #endif /* DEBUG */
231
232     return( AFP_OK );
233 }
234
235 int afp_setfildirparams(obj, ibuf, ibuflen, rbuf, rbuflen )
236 AFPObj      *obj;
237 char    *ibuf, *rbuf;
238 int             ibuflen, *rbuflen;
239 {
240     struct stat st;
241     struct vol  *vol;
242     struct dir  *dir;
243     char        *path;
244     u_int16_t   vid, bitmap;
245     int         did, rc;
246
247 #ifdef DEBUG
248     LOG(log_info, logtype_afpd, "begin afp_setfildirparams:");
249 #endif /* DEBUG */
250
251     *rbuflen = 0;
252     ibuf += 2;
253     memcpy( &vid, ibuf, sizeof(vid));
254     ibuf += sizeof( vid );
255
256     if (( vol = getvolbyvid( vid )) == NULL ) {
257         return( AFPERR_PARAM );
258     }
259
260     if (vol->v_flags & AFPVOL_RO)
261         return AFPERR_VLOCK;
262
263     memcpy( &did, ibuf, sizeof( did));
264     ibuf += sizeof( did);
265
266     if (( dir = dirsearch( vol, did )) == NULL ) {
267         return( AFPERR_NOOBJ );
268     }
269
270     memcpy( &bitmap, ibuf, sizeof( bitmap ));
271     bitmap = ntohs( bitmap );
272     ibuf += sizeof( bitmap );
273
274     if (( path = cname( vol, dir, &ibuf )) == NULL ) {
275         return( AFPERR_NOOBJ );
276     }
277
278     if ( stat( mtoupath(vol, path ), &st ) < 0 ) {
279         return( AFPERR_NOOBJ );
280     }
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;
346
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         if ((opened = of_findname(vol, sdir, oldname))) {
362             /* reuse struct adouble so it won't break locks */
363             adp = opened->of_ad;
364         }
365     }
366     else {
367 #ifdef CNID_DB
368         id = sdir->d_did; /* we already have the CNID */
369 #endif /* CNID_DB */
370         p = ctoupath( vol, sdir->d_parent, oldname );
371         adflags = ADFLAGS_DIR;
372     }
373     /*
374      * p now points to the full pathname of the source fs object.
375      * 
376      * we are in the dest folder so we need to use p for ad_open
377     */
378     
379     if (!ad_open(p, ADFLAGS_HF |adflags, O_RDONLY, 0666, adp)) {
380     u_int16_t bshort;
381
382         ad_getattr(adp, &bshort);
383         ad_close( adp, ADFLAGS_HF );
384         if ((bshort & htons(ATTRBIT_NORENAME))) 
385             return(AFPERR_OLOCK);
386     }
387
388     upath = mtoupath(vol, newname);
389     if (0 != (rc = check_name(vol, upath))) {
390             return  rc;
391     }
392
393     /* source == destination. we just silently accept this. */
394     if (curdir == sdir) {
395         if (strcmp(oldname, newname) == 0)
396             return AFP_OK;
397
398         /* deal with case insensitive, case-preserving filesystems. */
399         if ((stat(upath, &st) == 0) && strdiacasecmp(oldname, newname))
400             return AFPERR_EXIST;
401
402     } else if (stat(upath, &st ) == 0)
403         return AFPERR_EXIST;
404
405     if ( !isdir ) {
406         if (of_findname(vol, curdir, newname)) {
407             rc = AFPERR_EXIST; /* was AFPERR_BUSY; */
408         } else if ((rc = renamefile( p, upath, newname,
409                                      vol_noadouble(vol), adp )) == AFP_OK) {
410             /* if it's still open, rename the ofork as well. */
411             rc = of_rename(vol, sdir, oldname, curdir, newname);
412         }
413     } else {
414         rc = renamedir(p, upath, sdir, curdir, newname, vol_noadouble(vol));
415     }
416     if ( rc == AFP_OK ) {
417 #ifdef CNID_DB
418         /* renaming may have moved the file/dir across a filesystem */
419         if (stat(upath, &st) < 0)
420             return AFPERR_MISC;
421
422         /* fix up the catalog entry */
423         cnid_update(vol->v_db, id, &st, curdir->d_did, upath, strlen(upath));
424 #endif /* CNID_DB */
425     }
426
427     return rc;
428 }
429
430 /* -------------------------------------------- */
431 int afp_rename(obj, ibuf, ibuflen, rbuf, rbuflen )
432 AFPObj      *obj;
433 char    *ibuf, *rbuf;
434 int             ibuflen, *rbuflen;
435 {
436     struct vol  *vol;
437     struct dir  *sdir;
438     char                *path, *oldname, *newname;
439     u_int32_t   did;
440     int                 plen;
441     u_int16_t   vid;
442     int         isdir = 0;
443     int         rc;
444 #ifdef DEBUG
445     LOG(log_info, logtype_afpd, "begin afp_rename:");
446 #endif /* DEBUG */
447
448     *rbuflen = 0;
449     ibuf += 2;
450
451     memcpy( &vid, ibuf, sizeof( vid ));
452     ibuf += sizeof( vid );
453     if (( vol = getvolbyvid( vid )) == NULL ) {
454         return( AFPERR_PARAM );
455     }
456
457     if (vol->v_flags & AFPVOL_RO)
458         return AFPERR_VLOCK;
459
460     memcpy( &did, ibuf, sizeof( did ));
461     ibuf += sizeof( did );
462     if (( sdir = dirsearch( vol, did )) == NULL ) {
463         return( AFPERR_NOOBJ );
464     }
465
466     /* source pathname */
467     if (( path = cname( vol, sdir, &ibuf )) == NULL ) {
468         return( AFPERR_NOOBJ );
469     }
470
471     sdir = curdir;
472     newname = obj->newtmp;
473     oldname = obj->oldtmp;
474     if ( *path != '\0' ) {
475         strcpy(oldname, path); /* an extra copy for of_rename */
476     }
477     else {
478         if ( sdir->d_parent == NULL ) { /* root directory */
479             return( AFPERR_NORENAME );
480         }
481         /* move to destination dir */
482         if ( movecwd( vol, sdir->d_parent ) < 0 ) {
483             return( AFPERR_NOOBJ );
484         }
485         isdir = 1;
486         strcpy(oldname, sdir->d_name);
487     }
488
489     /* another place where we know about the path type */
490     if ( *ibuf++ != 2 ) {
491         return( AFPERR_PARAM );
492     }
493
494     if (( plen = (unsigned char)*ibuf++ ) != 0 ) {
495         strncpy( newname, ibuf, plen );
496         newname[ plen ] = '\0';
497     }
498     else {
499         return AFP_OK; /* newname == oldname same dir */
500     }
501     
502     rc = moveandrename(vol, sdir, oldname, newname, isdir);
503
504     if ( rc == AFP_OK ) {
505         setvoltime(obj, vol );
506     }
507
508 #ifdef DEBUG
509     LOG(log_info, logtype_afpd, "end afp_rename:");
510 #endif /* DEBUG */
511
512     return( rc );
513 }
514
515 /* ------------------------------- */
516 int afp_delete(obj, ibuf, ibuflen, rbuf, rbuflen )
517 AFPObj      *obj;
518 char    *ibuf, *rbuf;
519 int             ibuflen, *rbuflen;
520 {
521     struct vol          *vol;
522     struct dir          *dir;
523     char                *path, *upath;
524     int                 did, rc;
525     u_int16_t           vid;
526
527 #ifdef DEBUG
528     LOG(log_info, logtype_afpd, "begin afp_delete:");
529 #endif /* DEBUG */ 
530
531     *rbuflen = 0;
532     ibuf += 2;
533
534     memcpy( &vid, ibuf, sizeof( vid ));
535     ibuf += sizeof( vid );
536     if (( vol = getvolbyvid( vid )) == NULL ) {
537         return( AFPERR_PARAM );
538     }
539
540     if (vol->v_flags & AFPVOL_RO)
541         return AFPERR_VLOCK;
542
543     memcpy( &did, ibuf, sizeof( did ));
544     ibuf += sizeof( int );
545     if (( dir = dirsearch( vol, did )) == NULL ) {
546         return( AFPERR_NOOBJ );
547     }
548
549     if (( path = cname( vol, dir, &ibuf )) == NULL ) {
550         return( AFPERR_NOOBJ );
551     }
552
553     if ( *path == '\0' ) {
554         rc = deletecurdir( vol, obj->oldtmp, AFPOBJ_TMPSIZ);
555     } else if (of_findname(vol, curdir, path)) {
556         rc = AFPERR_BUSY;
557     } else if ((rc = deletefile( upath = mtoupath(vol, path ), 1)) == AFP_OK) {
558 #ifdef CNID_DB /* get rid of entry */
559         cnid_t id = cnid_get(vol->v_db, curdir->d_did, upath, strlen(upath));
560         cnid_delete(vol->v_db, id);
561 #endif /* CNID_DB */
562     }
563     if ( rc == AFP_OK ) {
564         setvoltime(obj, vol );
565     }
566
567 #ifdef DEBUG
568     LOG(log_info, logtype_afpd, "end afp_delete:");
569 #endif /* DEBUG */
570
571     return( rc );
572 }
573
574 char *ctoupath( vol, dir, name )
575 const struct vol        *vol;
576 struct dir      *dir;
577 char    *name;
578 {
579     struct dir  *d;
580     static char path[ MAXPATHLEN + 1];
581     char        *p, *u;
582     int         len;
583
584     p = path + sizeof( path ) - 1;
585     *p = '\0';
586     u = mtoupath(vol, name );
587     len = strlen( u );
588     p -= len;
589     strncpy( p, u, len );
590     for ( d = dir; d->d_parent; d = d->d_parent ) {
591         *--p = '/';
592         u = mtoupath(vol, d->d_name );
593         len = strlen( u );
594         p -= len;
595         strncpy( p, u, len );
596     }
597     *--p = '/';
598     len = strlen( vol->v_path );
599     p -= len;
600     strncpy( p, vol->v_path, len );
601
602     return( p );
603 }
604
605 /* ------------------------- */
606 int afp_moveandrename(obj, ibuf, ibuflen, rbuf, rbuflen )
607 AFPObj      *obj;
608 char    *ibuf, *rbuf;
609 int             ibuflen, *rbuflen;
610 {
611     struct vol  *vol;
612     struct dir  *sdir, *ddir;
613     int         isdir = 0;
614     char            *oldname, *newname;
615     char        *path;
616     int         did;
617     int         plen;
618     u_int16_t   vid;
619     int         rc;
620 #ifdef DROPKLUDGE
621     int         retvalue;
622 #endif /* DROPKLUDGE */
623
624 #ifdef DEBUG
625     LOG(log_info, logtype_afpd, "begin afp_moveandrename:");
626 #endif /* DEBUG */
627
628     *rbuflen = 0;
629     ibuf += 2;
630
631     memcpy( &vid, ibuf, sizeof( vid ));
632     ibuf += sizeof( vid );
633     if (( vol = getvolbyvid( vid )) == NULL ) {
634         return( AFPERR_PARAM );
635     }
636
637     if (vol->v_flags & AFPVOL_RO)
638         return AFPERR_VLOCK;
639
640     /* source did followed by dest did */
641     memcpy( &did, ibuf, sizeof( did ));
642     ibuf += sizeof( int );
643     if (( sdir = dirsearch( vol, did )) == NULL ) {
644         return( AFPERR_PARAM );
645     }
646
647     memcpy( &did, ibuf, sizeof( did ));
648     ibuf += sizeof( int );
649
650     /* source pathname */
651     if (( path = cname( vol, sdir, &ibuf )) == NULL ) {
652         return( AFPERR_NOOBJ );
653     }
654
655     sdir = curdir;
656     newname = obj->newtmp;
657     oldname = obj->oldtmp;
658     if ( *path != '\0' ) {
659         /* not a directory */
660         strcpy(oldname, path); /* an extra copy for of_rename */
661     } else {
662         isdir = 1;
663         strcpy(oldname, sdir->d_name);
664     }
665
666     /* get the destination directory */
667     if (( ddir = dirsearch( vol, did )) == NULL ) {
668         return( AFPERR_PARAM );
669     }
670     if (( path = cname( vol, ddir, &ibuf )) == NULL ) {
671         return( AFPERR_NOOBJ );
672     }
673     if ( *path != '\0' ) {
674         return( AFPERR_BADTYPE );
675     }
676
677     /* one more place where we know about path type */
678     if ( *ibuf++ != 2 ) {
679         return( AFPERR_PARAM );
680     }
681
682     if (( plen = (unsigned char)*ibuf++ ) != 0 ) {
683         strncpy( newname, ibuf, plen );
684         newname[ plen ] = '\0';
685     }
686     else {
687         strcpy(newname, oldname);
688     }
689     
690     rc = moveandrename(vol, sdir, oldname, newname, isdir);
691
692     if ( rc == AFP_OK ) {
693 #ifdef DROPKLUDGE
694         if (vol->v_flags & AFPVOL_DROPBOX) {
695             if (retvalue=matchfile2dirperms (newname, vol, did) != AFP_OK) {
696                 return retvalue;
697             }
698         }
699 #endif /* DROPKLUDGE */
700         setvoltime(obj, vol );
701     }
702
703 #ifdef DEBUG
704     LOG(log_info, logtype_afpd, "end afp_moveandrename:");
705 #endif /* DEBUG */
706
707     return( rc );
708 }
709
710 int veto_file(const char*veto_str, const char*path)
711 /* given a veto_str like "abc/zxc/" and path "abc", return 1
712  * veto_str should be '/' delimited
713  * if path matches any one of the veto_str elements exactly, then 1 is returned
714  * otherwise, 0 is returned.
715  */
716 {
717     int i;      /* index to veto_str */
718     int j;      /* index to path */
719
720     if ((veto_str == NULL) || (path == NULL))
721         return 0;
722     /*
723     #ifdef DEBUG
724         LOG(log_debug, logtype_afpd, "veto_file \"%s\", \"%s\"", veto_str, path);
725     #endif
726     */
727     for(i=0, j=0; veto_str[i] != '\0'; i++) {
728         if (veto_str[i] == '/') {
729             if ((j>0) && (path[j] == '\0'))
730                 return 1;
731             j = 0;
732         } else {
733             if (veto_str[i] != path[j]) {
734                 while ((veto_str[i] != '/')
735                         && (veto_str[i] != '\0'))
736                     i++;
737                 j = 0;
738                 continue;
739             }
740             j++;
741         }
742     }
743     return 0;
744 }
745