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