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