]> arthur.barton.de Git - netatalk.git/blob - etc/afpd/filedir.c
2e26e51951897dc85fae6e84ce48770960d1e379
[netatalk.git] / etc / afpd / filedir.c
1 /*
2  * $Id: filedir.c,v 1.57 2009-10-14 15:04:01 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 <dirent.h>
33 #include <errno.h>
34 #include <sys/param.h>
35
36 #include <atalk/adouble.h>
37 #include <atalk/vfs.h>
38 #include <atalk/afp.h>
39 #include <atalk/util.h>
40 #include <atalk/cnid.h>
41 #include <atalk/logger.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_info, logtype_afpd, "begin matchfile2dirperms:");
70 #endif /* DEBUG */
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 (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_info, logtype_afpd, "end matchfile2dirperms:");
128 #endif /* DEBUG */
129     return ret;
130 }
131 #endif
132
133 int afp_getfildirparams(AFPObj *obj _U_, char *ibuf, int ibuflen _U_, char *rbuf, int *rbuflen)
134 {
135     struct stat         *st;
136     struct vol          *vol;
137     struct dir          *dir;
138     u_int32_t           did;
139     int                 buflen, ret;
140     u_int16_t           fbitmap, dbitmap, vid;
141     struct path         *s_path;
142
143 #ifdef DEBUG
144     LOG(log_info, logtype_afpd, "begin afp_getfildirparams:");
145 #endif /* DEBUG */
146
147     *rbuflen = 0;
148     ibuf += 2;
149
150     memcpy( &vid, ibuf, sizeof( vid ));
151     ibuf += sizeof( vid );
152     if (NULL == ( vol = getvolbyvid( vid )) ) {
153         /* was AFPERR_PARAM but it helps OS 10.3 when a volume has been removed
154          * from the list.
155          */ 
156         return( AFPERR_ACCESS );
157     }
158
159     memcpy( &did, ibuf, sizeof( did ));
160     ibuf += sizeof( did );
161
162     if (NULL == ( dir = dirlookup( vol, did )) ) {
163         return afp_errno;
164     }
165
166     memcpy( &fbitmap, ibuf, sizeof( fbitmap ));
167     fbitmap = ntohs( fbitmap );
168     ibuf += sizeof( fbitmap );
169     memcpy( &dbitmap, ibuf, sizeof( dbitmap ));
170     dbitmap = ntohs( dbitmap );
171     ibuf += sizeof( dbitmap );
172
173     if (NULL == ( s_path = cname( vol, dir, &ibuf )) ) {
174         return get_afp_errno(AFPERR_NOOBJ); 
175     }
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     buflen = 0;
191     if (S_ISDIR(st->st_mode)) {
192         if (dbitmap) {
193             dir = s_path->d_dir;
194             if (!dir) 
195                 return AFPERR_NOOBJ;
196
197             ret = getdirparams(vol, dbitmap, s_path, dir,
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 && AFP_OK != (ret = getfilparams(vol, fbitmap, s_path, curdir, 
206                                             rbuf + 3 * sizeof( u_int16_t ), &buflen )) ) {
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(AFPObj *obj, char *ibuf, int ibuflen _U_, char *rbuf _U_, int *rbuflen)
229 {
230     struct stat *st;
231     struct vol  *vol;
232     struct dir  *dir;
233     struct path *path;
234     u_int16_t   vid, bitmap;
235     int         did, rc;
236
237 #ifdef DEBUG
238     LOG(log_info, logtype_afpd, "begin afp_setfildirparams:");
239 #endif /* DEBUG */
240
241     *rbuflen = 0;
242     ibuf += 2;
243     memcpy( &vid, ibuf, sizeof(vid));
244     ibuf += sizeof( vid );
245
246     if (NULL == ( vol = getvolbyvid( vid )) ) {
247         return( AFPERR_PARAM );
248     }
249
250     if (vol->v_flags & AFPVOL_RO)
251         return AFPERR_VLOCK;
252
253     memcpy( &did, ibuf, sizeof( did));
254     ibuf += sizeof( did);
255
256     if (NULL == ( dir = dirlookup( vol, did )) ) {
257         return afp_errno;    
258     }
259
260     memcpy( &bitmap, ibuf, sizeof( bitmap ));
261     bitmap = ntohs( bitmap );
262     ibuf += sizeof( bitmap );
263
264     if (NULL == ( path = cname( vol, dir, &ibuf ))) {
265         return get_afp_errno(AFPERR_NOOBJ); 
266     }
267
268     st   = &path->st;
269     if (!path->st_valid) {
270         /* it's a dir and it should be there
271          * because we chdir in it in cname
272          */
273         of_statdir(vol, path);
274     }
275
276     if ( path->st_errno != 0 ) {
277         return( AFPERR_NOOBJ );
278     }
279     /*
280      * If ibuf is odd, make it even.
281      */
282     if ((u_long)ibuf & 1 ) {
283         ibuf++;
284     }
285
286     if (S_ISDIR(st->st_mode)) {
287         rc = setdirparams(vol, path, bitmap, ibuf );
288     } else {
289         rc = setfilparams(vol, path, bitmap, ibuf );
290     }
291     if ( rc == AFP_OK ) {
292         setvoltime(obj, vol );
293     }
294
295 #ifdef DEBUG
296     LOG(log_info, logtype_afpd, "end afp_setfildirparams:");
297 #endif /* DEBUG */
298
299     return( rc );
300 }
301
302 /* -------------------------------------------- 
303    Factorise some checks on a pathname
304 */
305 int check_name(const struct vol *vol, char *name)
306 {
307     /* check for illegal characters in the unix filename */
308     if (!wincheck(vol, name))
309         return AFPERR_PARAM;
310
311     if ((vol->v_flags & AFPVOL_NOHEX) && strchr(name, '/'))
312         return AFPERR_PARAM;
313
314     if (!vol->vfs->vfs_validupath(vol, name)) {
315         LOG(log_info, logtype_afpd, "check_name: illegal name: '%s'", name);
316         return AFPERR_EXIST;
317     }
318
319     /* check for vetoed filenames */
320     if (veto_file(vol->v_veto, name))
321         return AFPERR_EXIST;
322     return 0;
323 }
324
325 /* ------------------------- 
326     move and rename sdir:oldname to curdir:newname in volume vol
327    
328     special care is needed for lock   
329 */
330 static int moveandrename(const struct vol *vol, struct dir *sdir, char *oldname, char *newname, int isdir)
331 {
332     char            *p;
333     char            *upath;
334     int             rc;
335     struct stat     *st, nst;
336     int             adflags;
337     struct adouble      ad;
338     struct adouble      *adp;
339     struct ofork        *opened = NULL;
340     struct path         path;
341     cnid_t      id;
342
343     ad_init(&ad, vol->v_adouble, vol->v_ad_options);
344     adp = &ad;
345     adflags = 0;
346     
347     if (!isdir) {
348         p = mtoupath(vol, oldname, sdir->d_did, utf8_encoding());
349         if (!p) { 
350             return AFPERR_PARAM; /* can't convert */
351         }
352         id = cnid_get(vol->v_cdb, sdir->d_did, p, strlen(p));
353         p = ctoupath( vol, sdir, oldname );
354         if (!p) { 
355             return AFPERR_PARAM; /* pathname too long */
356         }
357         path.st_valid = 0;
358         path.u_name = p;
359         if ((opened = of_findname(&path))) {
360             /* reuse struct adouble so it won't break locks */
361             adp = opened->of_ad;
362         }
363     }
364     else {
365         id = sdir->d_did; /* we already have the CNID */
366         p = ctoupath( vol, sdir->d_parent, oldname );
367         if (!p) {
368             return AFPERR_PARAM;
369         }
370         adflags = ADFLAGS_DIR;
371     }
372     /*
373      * p now points to the full pathname of the source fs object.
374      * 
375      * we are in the dest folder so we need to use p for ad_open
376     */
377     
378     if (!ad_metadata(p, adflags, adp)) {
379         u_int16_t bshort;
380
381         ad_getattr(adp, &bshort);
382         ad_close_metadata( adp);
383         if ((bshort & htons(ATTRBIT_NORENAME))) 
384             return(AFPERR_OLOCK);
385     }
386
387     if (NULL == (upath = mtoupath(vol, newname, curdir->d_did, utf8_encoding()))){ 
388         return AFPERR_PARAM;
389     }
390     path.u_name = upath;
391     st = &path.st;    
392     if (0 != (rc = check_name(vol, upath))) {
393             return  rc;
394     }
395
396     /* source == destination. we just silently accept this. */
397     if ((!isdir && curdir == sdir) || (isdir && curdir == sdir->d_parent)) {
398         if (strcmp(oldname, newname) == 0)
399             return AFP_OK;
400
401         if (stat(upath, st) == 0 || caseenumerate(vol, &path, curdir) == 0) {
402             if (!stat(p, &nst) && !(nst.st_dev == st->st_dev && nst.st_ino == st->st_ino) ) {
403                 /* not the same file */
404                 return AFPERR_EXIST;
405             }
406             errno = 0;
407         }
408     } else if (stat(upath, st ) == 0 || caseenumerate(vol, &path, curdir) == 0)
409         return AFPERR_EXIST;
410
411     if ( !isdir ) {
412         path.st_valid = 1;
413         path.st_errno = errno;
414         if (of_findname(&path)) {
415             rc = AFPERR_EXIST; /* was AFPERR_BUSY; */
416         } else {
417             rc = renamefile(vol, p, upath, newname, adp );
418             if (rc == AFP_OK)
419                 of_rename(vol, opened, sdir, oldname, curdir, newname);
420         }
421     } else {
422         rc = renamedir(vol, p, upath, sdir, curdir, newname);
423     }
424     if ( rc == AFP_OK && id ) {
425         /* renaming may have moved the file/dir across a filesystem */
426         if (stat(upath, st) < 0)
427             return AFPERR_MISC;
428
429         /* fix up the catalog entry */
430         cnid_update(vol->v_cdb, id, st, curdir->d_did, upath, strlen(upath));
431     }
432
433     return rc;
434 }
435
436 /* -------------------------------------------- */
437 int afp_rename(AFPObj *obj, char *ibuf, int ibuflen _U_, char *rbuf _U_, int *rbuflen)
438 {
439     struct vol  *vol;
440     struct dir  *sdir;
441     char        *oldname, *newname;
442     struct path *path;
443     u_int32_t   did;
444     int         plen;
445     u_int16_t   vid;
446     int         isdir = 0;
447     int         rc;
448 #ifdef DEBUG
449     LOG(log_info, logtype_afpd, "begin afp_rename:");
450 #endif /* DEBUG */
451
452     *rbuflen = 0;
453     ibuf += 2;
454
455     memcpy( &vid, ibuf, sizeof( vid ));
456     ibuf += sizeof( vid );
457     if (NULL == ( vol = getvolbyvid( vid )) ) {
458         return( AFPERR_PARAM );
459     }
460
461     if (vol->v_flags & AFPVOL_RO)
462         return AFPERR_VLOCK;
463
464     memcpy( &did, ibuf, sizeof( did ));
465     ibuf += sizeof( did );
466     if (NULL == ( sdir = dirlookup( vol, did )) ) {
467         return afp_errno;    
468     }
469
470     /* source pathname */
471     if (NULL == ( path = cname( vol, sdir, &ibuf )) ) {
472         return get_afp_errno(AFPERR_NOOBJ); 
473     }
474
475     sdir = curdir;
476     newname = obj->newtmp;
477     oldname = obj->oldtmp;
478     isdir = path_isadir(path);
479     if ( *path->m_name != '\0' ) {
480         strcpy(oldname, path->m_name); /* an extra copy for of_rename */
481         if (isdir) {
482             /* curdir parent dir, need to move sdir back */
483             sdir = path->d_dir;
484         }
485     }
486     else {
487         if ( sdir->d_parent == NULL ) { /* root directory */
488             return( AFPERR_NORENAME );
489         }
490         /* move to destination dir */
491         if ( movecwd( vol, sdir->d_parent ) < 0 ) {
492             return afp_errno;
493         }
494         strcpy(oldname, sdir->d_m_name);
495     }
496
497     /* another place where we know about the path type */
498     if ((plen = copy_path_name(vol, newname, ibuf)) < 0) {
499         return( AFPERR_PARAM );
500     }
501
502     if (!plen) {
503         return AFP_OK; /* newname == oldname same dir */
504     }
505     
506     rc = moveandrename(vol, sdir, oldname, newname, isdir);
507
508     if ( rc == AFP_OK ) {
509         setvoltime(obj, vol );
510     }
511
512 #ifdef DEBUG
513     LOG(log_info, logtype_afpd, "end afp_rename:");
514 #endif /* DEBUG */
515
516     return( rc );
517 }
518
519 /* ------------------------------- */
520 int afp_delete(AFPObj *obj, char *ibuf, int ibuflen _U_, char *rbuf _U_, int *rbuflen)
521 {
522     struct vol          *vol;
523     struct dir          *dir;
524     struct path         *s_path;
525     char                *upath;
526     int                 did, rc;
527     u_int16_t           vid;
528
529 #ifdef DEBUG
530     LOG(log_info, logtype_afpd, "begin afp_delete:");
531 #endif /* DEBUG */ 
532
533     *rbuflen = 0;
534     ibuf += 2;
535
536     memcpy( &vid, ibuf, sizeof( vid ));
537     ibuf += sizeof( vid );
538     if (NULL == ( vol = getvolbyvid( vid )) ) {
539         return( AFPERR_PARAM );
540     }
541
542     if (vol->v_flags & AFPVOL_RO)
543         return AFPERR_VLOCK;
544
545     memcpy( &did, ibuf, sizeof( did ));
546     ibuf += sizeof( int );
547     if (NULL == ( dir = dirlookup( vol, did )) ) {
548         return afp_errno;    
549     }
550
551     if (NULL == ( s_path = cname( vol, dir, &ibuf )) ) {
552         return get_afp_errno(AFPERR_NOOBJ); 
553     }
554
555     upath = s_path->u_name;
556     if ( path_isadir( s_path) ) {
557         if (*s_path->m_name != '\0') {
558             rc = AFPERR_ACCESS;
559         }
560         else {
561             rc = deletecurdir( vol);
562         }
563     } else if (of_findname(s_path)) {
564         rc = AFPERR_BUSY;
565     } else {
566         rc = deletefile(vol, upath, 1);
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 /* ------------------------ */
580 char *absupath(const struct vol *vol, struct dir *dir, char *u)
581 {
582     struct dir  *d;
583     static char path[ MAXPATHLEN + 1];
584     char        *p;
585     int         len;
586
587     if (u == NULL)
588         return NULL;
589         
590     p = path + sizeof( path ) - 1;
591     *p = '\0';
592     len = strlen( u );
593     p -= len;
594     memcpy( p, u, len );
595     if (dir) for ( d = dir; d->d_parent; d = d->d_parent ) {
596         u = d->d_u_name;
597         len = strlen( u );
598         if (p -len -1 < path) {
599             /* FIXME 
600                rather rare so LOG error and/or client message ?
601             */
602             return NULL;
603         }
604         *--p = '/';
605         p -= len;
606         memcpy( p, u, len );
607     }
608     len = strlen( vol->v_path );
609     if (p -len -1 < path) {
610         return NULL;
611     }
612     *--p = '/';
613     p -= len;
614     memcpy( p, vol->v_path, len );
615
616     return( p );
617 }
618
619 /* ------------------------
620  * FIXME dir could be NULL
621 */
622 char *ctoupath(const struct vol *vol, struct dir *dir, char *name)
623 {
624     return absupath(vol, dir, mtoupath(vol, name, dir->d_did, utf8_encoding()));
625 }
626
627 /* ------------------------- */
628 int afp_moveandrename(AFPObj *obj, char *ibuf, int ibuflen  _U_, char *rbuf _U_, int *rbuflen)
629 {
630     struct vol  *vol;
631     struct dir  *sdir, *ddir;
632     int         isdir;
633     char        *oldname, *newname;
634     struct path *path;
635     int         did;
636     int         pdid;
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 afp_errno; /* was AFPERR_PARAM */
665     }
666
667     memcpy( &did, ibuf, sizeof( did ));
668     ibuf += sizeof( int );
669
670     /* source pathname */
671     if (NULL == ( path = cname( vol, sdir, &ibuf )) ) {
672         return get_afp_errno(AFPERR_NOOBJ); 
673     }
674
675     sdir = curdir;
676     newname = obj->newtmp;
677     oldname = obj->oldtmp;
678     
679     isdir = path_isadir(path);
680     if ( *path->m_name != '\0' ) {
681         if (isdir) {
682             sdir = path->d_dir;
683         }
684         strcpy(oldname, path->m_name); /* an extra copy for of_rename */
685     } else {
686         strcpy(oldname, sdir->d_m_name);
687     }
688
689     /* get the destination directory */
690     if (NULL == ( ddir = dirlookup( vol, did )) ) {
691         return afp_errno; /*  was AFPERR_PARAM */
692     }
693     if (NULL == ( path = cname( vol, ddir, &ibuf ))) {
694         return( AFPERR_NOOBJ );
695     }
696     pdid = curdir->d_did;
697     if ( *path->m_name != '\0' ) {
698         return path_error(path, AFPERR_NOOBJ);
699     }
700
701     /* one more place where we know about path type */
702     if ((plen = copy_path_name(vol, newname, ibuf)) < 0) {
703         return( AFPERR_PARAM );
704     }
705
706     if (!plen) {
707         strcpy(newname, oldname);
708     }
709
710     rc = moveandrename(vol, sdir, oldname, newname, isdir);
711
712     if ( rc == AFP_OK ) {
713         char *upath = mtoupath(vol, newname, pdid, utf8_encoding());
714         
715         if (NULL == upath) {
716             return AFPERR_PARAM;
717         }
718         curdir->offcnt++;
719         sdir->offcnt--;
720 #ifdef DROPKLUDGE
721         if (vol->v_flags & AFPVOL_DROPBOX) {
722             /* FIXME did is not always the source id */
723             if ((retvalue=matchfile2dirperms (upath, vol, did)) != AFP_OK) {
724                 return retvalue;
725             }
726         }
727         else
728 #endif /* DROPKLUDGE */
729             /* if unix priv don't try to match perm with dest folder */
730             if (!isdir && !vol_unix_priv(vol)) {
731                 int  admode = ad_mode("", 0777) | vol->v_fperm;
732
733                 setfilmode(upath, admode, NULL, vol->v_umask);
734                 vol->vfs->vfs_setfilmode(vol, upath, admode, NULL);
735             }
736         setvoltime(obj, vol );
737     }
738
739 #ifdef DEBUG
740     LOG(log_info, logtype_afpd, "end afp_moveandrename:");
741 #endif /* DEBUG */
742
743     return( rc );
744 }
745
746 int veto_file(const char*veto_str, const char*path)
747 /* given a veto_str like "abc/zxc/" and path "abc", return 1
748  * veto_str should be '/' delimited
749  * if path matches any one of the veto_str elements exactly, then 1 is returned
750  * otherwise, 0 is returned.
751  */
752 {
753     int i;      /* index to veto_str */
754     int j;      /* index to path */
755
756     if ((veto_str == NULL) || (path == NULL))
757         return 0;
758
759     for(i=0, j=0; veto_str[i] != '\0'; i++) {
760         if (veto_str[i] == '/') {
761             if ((j>0) && (path[j] == '\0')) {
762                 LOG(log_info, logtype_afpd, "vetoed file:'%s'", path);
763                 return 1;
764             }
765             j = 0;
766         } else {
767             if (veto_str[i] != path[j]) {
768                 while ((veto_str[i] != '/')
769                         && (veto_str[i] != '\0'))
770                     i++;
771                 j = 0;
772                 continue;
773             }
774             j++;
775         }
776     }
777     return 0;
778 }
779