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