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