]> arthur.barton.de Git - netatalk.git/blob - etc/afpd/filedir.c
Fix for not shown ACLs for when filesyem uid or gid couldn't be resolved because...
[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 = -1;
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             rc = AFPERR_MISC;
387             goto exit;
388         }
389     }
390     if (!ad_metadata(p, adflags, adp)) {
391         u_int16_t bshort;
392
393         ad_getattr(adp, &bshort);
394         ad_close_metadata( adp);
395         if ((bshort & htons(ATTRBIT_NORENAME))) {
396             rc = AFPERR_OLOCK;
397             goto exit;
398         }
399     }
400     if (sdir_fd != -1) {
401         if (fchdir(cwd_fd) != 0) {
402             LOG(log_error, logtype_afpd, "moveandrename: %s", strerror(errno) );
403             rc = AFPERR_MISC;
404             goto exit;
405         }
406     }
407
408     if (NULL == (upath = mtoupath(vol, newname, curdir->d_did, utf8_encoding()))){ 
409         rc = AFPERR_PARAM;
410         goto exit;
411     }
412     path.u_name = upath;
413     st = &path.st;    
414     if (0 != (rc = check_name(vol, upath))) {
415         goto exit;
416     }
417
418     /* source == destination. we just silently accept this. */
419     if ((!isdir && curdir == sdir) || (isdir && curdir == sdir->d_parent)) {
420         if (strcmp(oldname, newname) == 0) {
421             rc = AFP_OK;
422             goto exit;
423         }
424
425         if (stat(upath, st) == 0 || caseenumerate(vol, &path, curdir) == 0) {
426             if (!stat(p, &nst) && !(nst.st_dev == st->st_dev && nst.st_ino == st->st_ino) ) {
427                 /* not the same file */
428                 rc = AFPERR_EXIST;
429                 goto exit;
430             }
431             errno = 0;
432         }
433     } else if (stat(upath, st ) == 0 || caseenumerate(vol, &path, curdir) == 0) {
434         rc = AFPERR_EXIST;
435         goto exit;
436     }
437
438     if ( !isdir ) {
439         path.st_valid = 1;
440         path.st_errno = errno;
441         if (of_findname(&path)) {
442             rc = AFPERR_EXIST; /* was AFPERR_BUSY; */
443         } else {
444             rc = renamefile(vol, sdir_fd, p, upath, newname, adp );
445             if (rc == AFP_OK)
446                 of_rename(vol, opened, sdir, oldname, curdir, newname);
447         }
448     } else {
449         rc = renamedir(vol, sdir_fd, p, upath, sdir, curdir, newname);
450     }
451     if ( rc == AFP_OK && id ) {
452         /* renaming may have moved the file/dir across a filesystem */
453         if (stat(upath, st) < 0) {
454             rc = AFPERR_MISC;
455             goto exit;
456         }
457         /* fix up the catalog entry */
458         cnid_update(vol->v_cdb, id, st, curdir->d_did, upath, strlen(upath));
459     }
460
461 exit:
462     if (cwd_fd != -1)
463         close(cwd_fd);
464     return rc;
465 }
466
467 /* -------------------------------------------- */
468 int afp_rename(AFPObj *obj, char *ibuf, size_t ibuflen _U_, char *rbuf _U_, size_t *rbuflen)
469 {
470     struct vol  *vol;
471     struct dir  *sdir;
472     char        *oldname, *newname;
473     struct path *path;
474     u_int32_t   did;
475     int         plen;
476     u_int16_t   vid;
477     int         isdir = 0;
478     int         rc;
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( did );
494     if (NULL == ( sdir = dirlookup( vol, did )) ) {
495         return afp_errno;    
496     }
497
498     /* source pathname */
499     if (NULL == ( path = cname( vol, sdir, &ibuf )) ) {
500         return get_afp_errno(AFPERR_NOOBJ); 
501     }
502
503     sdir = curdir;
504     newname = obj->newtmp;
505     oldname = obj->oldtmp;
506     isdir = path_isadir(path);
507     if ( *path->m_name != '\0' ) {
508         strcpy(oldname, path->m_name); /* an extra copy for of_rename */
509         if (isdir) {
510             /* curdir parent dir, need to move sdir back */
511             sdir = path->d_dir;
512         }
513     }
514     else {
515         if ( sdir->d_parent == NULL ) { /* root directory */
516             return( AFPERR_NORENAME );
517         }
518         /* move to destination dir */
519         if ( movecwd( vol, sdir->d_parent ) < 0 ) {
520             return afp_errno;
521         }
522         strcpy(oldname, sdir->d_m_name);
523     }
524
525     /* another place where we know about the path type */
526     if ((plen = copy_path_name(vol, newname, ibuf)) < 0) {
527         return( AFPERR_PARAM );
528     }
529
530     if (!plen) {
531         return AFP_OK; /* newname == oldname same dir */
532     }
533     
534     rc = moveandrename(vol, sdir, -1, oldname, newname, isdir);
535     if ( rc == AFP_OK ) {
536         setvoltime(obj, vol );
537     }
538
539     return( rc );
540 }
541
542 /* ------------------------------- */
543 int afp_delete(AFPObj *obj, char *ibuf, size_t ibuflen _U_, char *rbuf _U_, size_t *rbuflen)
544 {
545     struct vol          *vol;
546     struct dir          *dir;
547     struct path         *s_path;
548     char                *upath;
549     int                 did, rc;
550     u_int16_t           vid;
551
552     *rbuflen = 0;
553     ibuf += 2;
554
555     memcpy( &vid, ibuf, sizeof( vid ));
556     ibuf += sizeof( vid );
557     if (NULL == ( vol = getvolbyvid( vid )) ) {
558         return( AFPERR_PARAM );
559     }
560
561     if (vol->v_flags & AFPVOL_RO)
562         return AFPERR_VLOCK;
563
564     memcpy( &did, ibuf, sizeof( did ));
565     ibuf += sizeof( int );
566     if (NULL == ( dir = dirlookup( vol, did )) ) {
567         return afp_errno;    
568     }
569
570     if (NULL == ( s_path = cname( vol, dir, &ibuf )) ) {
571         return get_afp_errno(AFPERR_NOOBJ); 
572     }
573
574     upath = s_path->u_name;
575     if ( path_isadir( s_path) ) {
576         if (*s_path->m_name != '\0') {
577             rc = AFPERR_ACCESS;
578         }
579         else {
580             rc = deletecurdir( vol);
581         }
582     } else if (of_findname(s_path)) {
583         rc = AFPERR_BUSY;
584     } else {
585         /* it's a file st_valid should always be true
586          * only test for ENOENT because EACCES needs
587          * to read meta data in deletefile
588          */
589         if (s_path->st_valid && s_path->st_errno == ENOENT) {
590             rc = AFPERR_NOOBJ;
591         }
592         else {
593             rc = deletefile(vol, -1, upath, 1);
594         }
595     }
596     if ( rc == AFP_OK ) {
597         curdir->offcnt--;
598         setvoltime(obj, vol );
599     }
600
601     return( rc );
602 }
603 /* ------------------------ */
604 char *absupath(const struct vol *vol, struct dir *dir, char *u)
605 {
606     struct dir  *d;
607     static char path[ MAXPATHLEN + 1];
608     char        *p;
609     int         len;
610
611     if (u == NULL)
612         return NULL;
613         
614     p = path + sizeof( path ) - 1;
615     *p = '\0';
616     len = strlen( u );
617     p -= len;
618     memcpy( p, u, len );
619     if (dir) for ( d = dir; d->d_parent; d = d->d_parent ) {
620         u = d->d_u_name;
621         len = strlen( u );
622         if (p -len -1 < path) {
623             /* FIXME 
624                rather rare so LOG error and/or client message ?
625             */
626             return NULL;
627         }
628         *--p = '/';
629         p -= len;
630         memcpy( p, u, len );
631     }
632     len = strlen( vol->v_path );
633     if (p -len -1 < path) {
634         return NULL;
635     }
636     *--p = '/';
637     p -= len;
638     memcpy( p, vol->v_path, len );
639
640     return( p );
641 }
642
643 /* ------------------------
644  * FIXME dir could be NULL
645 */
646 char *ctoupath(const struct vol *vol, struct dir *dir, char *name)
647 {
648     return absupath(vol, dir, mtoupath(vol, name, dir->d_did, utf8_encoding()));
649 }
650
651 /* ------------------------- */
652 int afp_moveandrename(AFPObj *obj, char *ibuf, size_t ibuflen _U_, char *rbuf _U_, size_t *rbuflen)
653 {
654     struct vol  *vol;
655     struct dir  *sdir, *ddir;
656     int         isdir;
657     char        *oldname, *newname;
658     struct path *path;
659     int         did;
660     int         pdid;
661     int         plen;
662     u_int16_t   vid;
663     int         rc;
664 #ifdef DROPKLUDGE
665     int         retvalue;
666 #endif /* DROPKLUDGE */
667     int     sdir_fd = -1;
668
669
670     *rbuflen = 0;
671     ibuf += 2;
672
673     memcpy( &vid, ibuf, sizeof( vid ));
674     ibuf += sizeof( vid );
675     if (NULL == ( vol = getvolbyvid( vid )) ) {
676         return( AFPERR_PARAM );
677     }
678
679     if (vol->v_flags & AFPVOL_RO)
680         return AFPERR_VLOCK;
681
682     /* source did followed by dest did */
683     memcpy( &did, ibuf, sizeof( did ));
684     ibuf += sizeof( int );
685     if (NULL == ( sdir = dirlookup( vol, did )) ) {
686         return afp_errno; /* was AFPERR_PARAM */
687     }
688
689     memcpy( &did, ibuf, sizeof( did ));
690     ibuf += sizeof( int );
691
692     /* source pathname */
693     if (NULL == ( path = cname( vol, sdir, &ibuf )) ) {
694         return get_afp_errno(AFPERR_NOOBJ); 
695     }
696
697     sdir = curdir;
698     newname = obj->newtmp;
699     oldname = obj->oldtmp;
700     
701     isdir = path_isadir(path);
702     if ( *path->m_name != '\0' ) {
703         if (isdir) {
704             sdir = path->d_dir;
705         }
706         strcpy(oldname, path->m_name); /* an extra copy for of_rename */
707     } else {
708         strcpy(oldname, sdir->d_m_name);
709     }
710
711 #ifdef HAVE_RENAMEAT
712     if ((sdir_fd = open(".", O_RDONLY)) == -1)
713         return AFPERR_MISC;
714 #endif
715
716     /* get the destination directory */
717     if (NULL == ( ddir = dirlookup( vol, did )) ) {
718         rc = afp_errno; /*  was AFPERR_PARAM */
719         goto exit;
720     }
721     if (NULL == ( path = cname( vol, ddir, &ibuf ))) {
722         rc = AFPERR_NOOBJ;
723         goto exit;
724     }
725     pdid = curdir->d_did;
726     if ( *path->m_name != '\0' ) {
727         rc = path_error(path, AFPERR_NOOBJ);
728         goto exit;
729     }
730
731     /* one more place where we know about path type */
732     if ((plen = copy_path_name(vol, newname, ibuf)) < 0) {
733         rc = AFPERR_PARAM;
734         goto exit;
735     }
736
737     if (!plen) {
738         strcpy(newname, oldname);
739     }
740
741     /* This does the work */
742     rc = moveandrename(vol, sdir, sdir_fd, oldname, newname, isdir);
743
744     if ( rc == AFP_OK ) {
745         char *upath = mtoupath(vol, newname, pdid, utf8_encoding());
746         
747         if (NULL == upath) {
748             rc = AFPERR_PARAM;
749             goto exit;
750         }
751         curdir->offcnt++;
752         sdir->offcnt--;
753 #ifdef DROPKLUDGE
754         if (vol->v_flags & AFPVOL_DROPBOX) {
755             /* FIXME did is not always the source id */
756             if ((retvalue=matchfile2dirperms (upath, vol, did)) != AFP_OK) {
757                 rc = retvalue;
758                 goto exit;
759             }
760         }
761         else
762 #endif /* DROPKLUDGE */
763             /* if unix priv don't try to match perm with dest folder */
764             if (!isdir && !vol_unix_priv(vol)) {
765                 int  admode = ad_mode("", 0777) | vol->v_fperm;
766
767                 setfilmode(upath, admode, NULL, vol->v_umask);
768                 vol->vfs->vfs_setfilmode(vol, upath, admode, NULL);
769             }
770         setvoltime(obj, vol );
771     }
772
773 exit:
774 #ifdef HAVE_RENAMEAT
775     if (sdir_fd != -1)
776         close(sdir_fd);
777 #endif
778
779     return( rc );
780 }
781
782 int veto_file(const char*veto_str, const char*path)
783 /* given a veto_str like "abc/zxc/" and path "abc", return 1
784  * veto_str should be '/' delimited
785  * if path matches any one of the veto_str elements exactly, then 1 is returned
786  * otherwise, 0 is returned.
787  */
788 {
789     int i;      /* index to veto_str */
790     int j;      /* index to path */
791
792     if ((veto_str == NULL) || (path == NULL))
793         return 0;
794
795     for(i=0, j=0; veto_str[i] != '\0'; i++) {
796         if (veto_str[i] == '/') {
797             if ((j>0) && (path[j] == '\0')) {
798                 LOG(log_debug, logtype_afpd, "vetoed file:'%s'", path);
799                 return 1;
800             }
801             j = 0;
802         } else {
803             if (veto_str[i] != path[j]) {
804                 while ((veto_str[i] != '/')
805                         && (veto_str[i] != '\0'))
806                     i++;
807                 j = 0;
808                 continue;
809             }
810             j++;
811         }
812     }
813     return 0;
814 }
815