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