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