]> arthur.barton.de Git - netatalk.git/blob - etc/afpd/filedir.c
f9a84039a793e64e2d563d6a1b8e81c85fc5aa90
[netatalk.git] / etc / afpd / filedir.c
1 /*
2  * $Id: filedir.c,v 1.54 2009-09-01 13:15:13 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 <dirent.h>
33 #include <errno.h>
34 #include <sys/param.h>
35 #include <atalk/adouble.h>
36
37 #include <atalk/afp.h>
38 #include <atalk/util.h>
39 #include <atalk/cnid.h>
40 #include <atalk/logger.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(upath, vol, did)
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_info, logtype_afpd, "begin matchfile2dirperms:");
69 #endif /* DEBUG */
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 (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_info, logtype_afpd, "end matchfile2dirperms:");
127 #endif /* DEBUG */
128     return ret;
129 }
130 #endif
131
132 int afp_getfildirparams(obj, ibuf, ibuflen, rbuf, rbuflen )
133 AFPObj  *obj _U_;
134 char    *ibuf, *rbuf;
135 int     ibuflen _U_, *rbuflen;
136 {
137     struct stat         *st;
138     struct vol          *vol;
139     struct dir          *dir;
140     u_int32_t           did;
141     int                 buflen, ret;
142     u_int16_t           fbitmap, dbitmap, vid;
143     struct path         *s_path;
144
145 #ifdef DEBUG
146     LOG(log_info, logtype_afpd, "begin afp_getfildirparams:");
147 #endif /* DEBUG */
148
149     *rbuflen = 0;
150     ibuf += 2;
151
152     memcpy( &vid, ibuf, sizeof( vid ));
153     ibuf += sizeof( vid );
154     if (NULL == ( vol = getvolbyvid( vid )) ) {
155         /* was AFPERR_PARAM but it helps OS 10.3 when a volume has been removed
156          * from the list.
157          */ 
158         return( AFPERR_ACCESS );
159     }
160
161     memcpy( &did, ibuf, sizeof( did ));
162     ibuf += sizeof( did );
163
164     if (NULL == ( dir = dirlookup( vol, did )) ) {
165         return afp_errno;
166     }
167
168     memcpy( &fbitmap, ibuf, sizeof( fbitmap ));
169     fbitmap = ntohs( fbitmap );
170     ibuf += sizeof( fbitmap );
171     memcpy( &dbitmap, ibuf, sizeof( dbitmap ));
172     dbitmap = ntohs( dbitmap );
173     ibuf += sizeof( dbitmap );
174
175     if (NULL == ( s_path = cname( vol, dir, &ibuf )) ) {
176         return get_afp_errno(AFPERR_NOOBJ); 
177     }
178
179     st   = &s_path->st;
180     if (!s_path->st_valid) {
181         /* it's a dir and it should be there
182          * because we chdir in it in cname or
183          * it's curdir (maybe deleted, but then we can't know).
184          * So we need to try harder.
185          */
186         of_statdir(vol, s_path);
187     }
188     if ( s_path->st_errno != 0 ) {
189         return( AFPERR_NOOBJ );
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 #ifdef DEBUG
224     LOG(log_info, logtype_afpd, "end afp_getfildirparams:");
225 #endif /* DEBUG */
226
227     return( AFP_OK );
228 }
229
230 int afp_setfildirparams(obj, ibuf, ibuflen, rbuf, rbuflen )
231 AFPObj  *obj;
232 char    *ibuf, *rbuf _U_;
233 int     ibuflen _U_, *rbuflen;
234 {
235     struct stat *st;
236     struct vol  *vol;
237     struct dir  *dir;
238     struct path *path;
239     u_int16_t   vid, bitmap;
240     int         did, rc;
241
242 #ifdef DEBUG
243     LOG(log_info, logtype_afpd, "begin afp_setfildirparams:");
244 #endif /* DEBUG */
245
246     *rbuflen = 0;
247     ibuf += 2;
248     memcpy( &vid, ibuf, sizeof(vid));
249     ibuf += sizeof( vid );
250
251     if (NULL == ( vol = getvolbyvid( vid )) ) {
252         return( AFPERR_PARAM );
253     }
254
255     if (vol->v_flags & AFPVOL_RO)
256         return AFPERR_VLOCK;
257
258     memcpy( &did, ibuf, sizeof( did));
259     ibuf += sizeof( did);
260
261     if (NULL == ( dir = dirlookup( vol, did )) ) {
262         return afp_errno;    
263     }
264
265     memcpy( &bitmap, ibuf, sizeof( bitmap ));
266     bitmap = ntohs( bitmap );
267     ibuf += sizeof( bitmap );
268
269     if (NULL == ( path = cname( vol, dir, &ibuf ))) {
270         return get_afp_errno(AFPERR_NOOBJ); 
271     }
272
273     st   = &path->st;
274     if (!path->st_valid) {
275         /* it's a dir and it should be there
276          * because we chdir in it in cname
277          */
278         of_statdir(vol, path);
279     }
280
281     if ( path->st_errno != 0 ) {
282         return( AFPERR_NOOBJ );
283     }
284     /*
285      * If ibuf is odd, make it even.
286      */
287     if ((u_long)ibuf & 1 ) {
288         ibuf++;
289     }
290
291     if (S_ISDIR(st->st_mode)) {
292         rc = setdirparams(vol, path, bitmap, ibuf );
293     } else {
294         rc = setfilparams(vol, path, bitmap, ibuf );
295     }
296     if ( rc == AFP_OK ) {
297         setvoltime(obj, vol );
298     }
299
300 #ifdef DEBUG
301     LOG(log_info, logtype_afpd, "end afp_setfildirparams:");
302 #endif /* DEBUG */
303
304     return( rc );
305 }
306
307 /* -------------------------------------------- 
308    Factorise some checks on a pathname
309 */
310 int check_name(const struct vol *vol, char *name)
311 {
312     /* check for illegal characters in the unix filename */
313     if (!wincheck(vol, name))
314         return AFPERR_PARAM;
315
316     if ((vol->v_flags & AFPVOL_NOHEX) && strchr(name, '/'))
317         return AFPERR_PARAM;
318
319     if (!vol->vfs->validupath(vol, name)) {
320         LOG(log_info, logtype_afpd, "check_name: illegal name: '%s'", name);
321         return AFPERR_EXIST;
322     }
323
324     /* check for vetoed filenames */
325     if (veto_file(vol->v_veto, name))
326         return AFPERR_EXIST;
327     return 0;
328 }
329
330 /* ------------------------- 
331     move and rename sdir:oldname to curdir:newname in volume vol
332    
333     special care is needed for lock   
334 */
335 static int moveandrename(vol, sdir, oldname, newname, isdir)
336 const struct vol        *vol;
337 struct dir      *sdir;
338 char        *oldname;
339 char        *newname;
340 int         isdir;
341 {
342     char            *p;
343     char            *upath;
344     int             rc;
345     struct stat     *st, nst;
346     int             adflags;
347     struct adouble      ad;
348     struct adouble      *adp;
349     struct ofork        *opened = NULL;
350     struct path         path;
351     cnid_t      id;
352
353     ad_init(&ad, vol->v_adouble, vol->v_ad_options);
354     adp = &ad;
355     adflags = 0;
356     
357     if (!isdir) {
358         p = mtoupath(vol, oldname, sdir->d_did, utf8_encoding());
359         if (!p) { 
360             return AFPERR_PARAM; /* can't convert */
361         }
362         id = cnid_get(vol->v_cdb, sdir->d_did, p, strlen(p));
363         p = ctoupath( vol, sdir, oldname );
364         if (!p) { 
365             return AFPERR_PARAM; /* pathname too long */
366         }
367         path.st_valid = 0;
368         path.u_name = p;
369         if ((opened = of_findname(&path))) {
370             /* reuse struct adouble so it won't break locks */
371             adp = opened->of_ad;
372         }
373     }
374     else {
375         id = sdir->d_did; /* we already have the CNID */
376         p = ctoupath( vol, sdir->d_parent, oldname );
377         if (!p) {
378             return AFPERR_PARAM;
379         }
380         adflags = ADFLAGS_DIR;
381     }
382     /*
383      * p now points to the full pathname of the source fs object.
384      * 
385      * we are in the dest folder so we need to use p for ad_open
386     */
387     
388     if (!ad_metadata(p, adflags, adp)) {
389         u_int16_t bshort;
390
391         ad_getattr(adp, &bshort);
392         ad_close_metadata( adp);
393         if ((bshort & htons(ATTRBIT_NORENAME))) 
394             return(AFPERR_OLOCK);
395     }
396
397     if (NULL == (upath = mtoupath(vol, newname, curdir->d_did, utf8_encoding()))){ 
398         return AFPERR_PARAM;
399     }
400     path.u_name = upath;
401     st = &path.st;    
402     if (0 != (rc = check_name(vol, upath))) {
403             return  rc;
404     }
405
406     /* source == destination. we just silently accept this. */
407     if ((!isdir && curdir == sdir) || (isdir && curdir == sdir->d_parent)) {
408         if (strcmp(oldname, newname) == 0)
409             return AFP_OK;
410
411         if (stat(upath, st) == 0 || caseenumerate(vol, &path, curdir) == 0) {
412             if (!stat(p, &nst) && !(nst.st_dev == st->st_dev && nst.st_ino == st->st_ino) ) {
413                 /* not the same file */
414                 return AFPERR_EXIST;
415             }
416             errno = 0;
417         }
418     } else if (stat(upath, st ) == 0 || caseenumerate(vol, &path, curdir) == 0)
419         return AFPERR_EXIST;
420
421     if ( !isdir ) {
422         path.st_valid = 1;
423         path.st_errno = errno;
424         if (of_findname(&path)) {
425             rc = AFPERR_EXIST; /* was AFPERR_BUSY; */
426         } else {
427             rc = renamefile(vol, p, upath, newname, adp );
428             if (rc == AFP_OK)
429                 of_rename(vol, opened, sdir, oldname, curdir, newname);
430         }
431     } else {
432         rc = renamedir(vol, p, upath, sdir, curdir, newname);
433     }
434     if ( rc == AFP_OK && id ) {
435         /* renaming may have moved the file/dir across a filesystem */
436         if (stat(upath, st) < 0)
437             return AFPERR_MISC;
438
439         /* fix up the catalog entry */
440         cnid_update(vol->v_cdb, id, st, curdir->d_did, upath, strlen(upath));
441     }
442
443     return rc;
444 }
445
446 /* -------------------------------------------- */
447 int afp_rename(obj, ibuf, ibuflen, rbuf, rbuflen )
448 AFPObj  *obj;
449 char    *ibuf, *rbuf _U_;
450 int     ibuflen _U_, *rbuflen;
451 {
452     struct vol  *vol;
453     struct dir  *sdir;
454     char        *oldname, *newname;
455     struct path *path;
456     u_int32_t   did;
457     int         plen;
458     u_int16_t   vid;
459     int         isdir = 0;
460     int         rc;
461 #ifdef DEBUG
462     LOG(log_info, logtype_afpd, "begin afp_rename:");
463 #endif /* DEBUG */
464
465     *rbuflen = 0;
466     ibuf += 2;
467
468     memcpy( &vid, ibuf, sizeof( vid ));
469     ibuf += sizeof( vid );
470     if (NULL == ( vol = getvolbyvid( vid )) ) {
471         return( AFPERR_PARAM );
472     }
473
474     if (vol->v_flags & AFPVOL_RO)
475         return AFPERR_VLOCK;
476
477     memcpy( &did, ibuf, sizeof( did ));
478     ibuf += sizeof( did );
479     if (NULL == ( sdir = dirlookup( vol, did )) ) {
480         return afp_errno;    
481     }
482
483     /* source pathname */
484     if (NULL == ( path = cname( vol, sdir, &ibuf )) ) {
485         return get_afp_errno(AFPERR_NOOBJ); 
486     }
487
488     sdir = curdir;
489     newname = obj->newtmp;
490     oldname = obj->oldtmp;
491     isdir = path_isadir(path);
492     if ( *path->m_name != '\0' ) {
493         strcpy(oldname, path->m_name); /* an extra copy for of_rename */
494         if (isdir) {
495             /* curdir parent dir, need to move sdir back */
496             sdir = path->d_dir;
497         }
498     }
499     else {
500         if ( sdir->d_parent == NULL ) { /* root directory */
501             return( AFPERR_NORENAME );
502         }
503         /* move to destination dir */
504         if ( movecwd( vol, sdir->d_parent ) < 0 ) {
505             return afp_errno;
506         }
507         strcpy(oldname, sdir->d_m_name);
508     }
509
510     /* another place where we know about the path type */
511     if ((plen = copy_path_name(vol, newname, ibuf)) < 0) {
512         return( AFPERR_PARAM );
513     }
514
515     if (!plen) {
516         return AFP_OK; /* newname == oldname same dir */
517     }
518     
519     rc = moveandrename(vol, sdir, oldname, newname, isdir);
520
521     if ( rc == AFP_OK ) {
522         setvoltime(obj, vol );
523     }
524
525 #ifdef DEBUG
526     LOG(log_info, logtype_afpd, "end afp_rename:");
527 #endif /* DEBUG */
528
529     return( rc );
530 }
531
532 /* ------------------------------- */
533 int afp_delete(obj, ibuf, ibuflen, rbuf, rbuflen )
534 AFPObj  *obj;
535 char    *ibuf, *rbuf _U_;
536 int     ibuflen _U_, *rbuflen;
537 {
538     struct vol          *vol;
539     struct dir          *dir;
540     struct path         *s_path;
541     char                *upath;
542     int                 did, rc;
543     u_int16_t           vid;
544
545 #ifdef DEBUG
546     LOG(log_info, logtype_afpd, "begin afp_delete:");
547 #endif /* DEBUG */ 
548
549     *rbuflen = 0;
550     ibuf += 2;
551
552     memcpy( &vid, ibuf, sizeof( vid ));
553     ibuf += sizeof( vid );
554     if (NULL == ( vol = getvolbyvid( vid )) ) {
555         return( AFPERR_PARAM );
556     }
557
558     if (vol->v_flags & AFPVOL_RO)
559         return AFPERR_VLOCK;
560
561     memcpy( &did, ibuf, sizeof( did ));
562     ibuf += sizeof( int );
563     if (NULL == ( dir = dirlookup( vol, did )) ) {
564         return afp_errno;    
565     }
566
567     if (NULL == ( s_path = cname( vol, dir, &ibuf )) ) {
568         return get_afp_errno(AFPERR_NOOBJ); 
569     }
570
571     upath = s_path->u_name;
572     if ( path_isadir( s_path) ) {
573         if (*s_path->m_name != '\0') {
574             rc = AFPERR_ACCESS;
575         }
576         else {
577             rc = deletecurdir( vol);
578         }
579     } else if (of_findname(s_path)) {
580         rc = AFPERR_BUSY;
581     } else {
582         rc = deletefile(vol, upath, 1);
583     }
584     if ( rc == AFP_OK ) {
585         curdir->offcnt--;
586         setvoltime(obj, vol );
587     }
588
589 #ifdef DEBUG
590     LOG(log_info, logtype_afpd, "end afp_delete:");
591 #endif /* DEBUG */
592
593     return( rc );
594 }
595 /* ------------------------ */
596 char *absupath( vol, dir, u )
597 const struct vol        *vol;
598 struct dir      *dir;
599 char    *u;
600 {
601     struct dir  *d;
602     static char path[ MAXPATHLEN + 1];
603     char        *p;
604     int         len;
605
606     if (u == NULL)
607         return NULL;
608         
609     p = path + sizeof( path ) - 1;
610     *p = '\0';
611     len = strlen( u );
612     p -= len;
613     memcpy( p, u, len );
614     if (dir) for ( d = dir; d->d_parent; d = d->d_parent ) {
615         u = d->d_u_name;
616         len = strlen( u );
617         if (p -len -1 < path) {
618             /* FIXME 
619                rather rare so LOG error and/or client message ?
620             */
621             return NULL;
622         }
623         *--p = '/';
624         p -= len;
625         memcpy( p, u, len );
626     }
627     len = strlen( vol->v_path );
628     if (p -len -1 < path) {
629         return NULL;
630     }
631     *--p = '/';
632     p -= len;
633     memcpy( p, vol->v_path, len );
634
635     return( p );
636 }
637
638 /* ------------------------
639  * FIXME dir could be NULL
640 */
641 char *ctoupath( vol, dir, name )
642 const struct vol        *vol;
643 struct dir      *dir;
644 char    *name;
645 {
646     return absupath(vol, dir, mtoupath(vol, name, dir->d_did, utf8_encoding()));
647 }
648
649 /* ------------------------- */
650 int afp_moveandrename(obj, ibuf, ibuflen, rbuf, rbuflen )
651 AFPObj  *obj;
652 char    *ibuf, *rbuf _U_;
653 int     ibuflen  _U_, *rbuflen;
654 {
655     struct vol  *vol;
656     struct dir  *sdir, *ddir;
657     int         isdir;
658     char        *oldname, *newname;
659     struct path *path;
660     int         did;
661     int         pdid;
662     int         plen;
663     u_int16_t   vid;
664     int         rc;
665 #ifdef DROPKLUDGE
666     int         retvalue;
667 #endif /* DROPKLUDGE */
668
669 #ifdef DEBUG
670     LOG(log_info, logtype_afpd, "begin afp_moveandrename:");
671 #endif /* DEBUG */
672
673     *rbuflen = 0;
674     ibuf += 2;
675
676     memcpy( &vid, ibuf, sizeof( vid ));
677     ibuf += sizeof( vid );
678     if (NULL == ( vol = getvolbyvid( vid )) ) {
679         return( AFPERR_PARAM );
680     }
681
682     if (vol->v_flags & AFPVOL_RO)
683         return AFPERR_VLOCK;
684
685     /* source did followed by dest did */
686     memcpy( &did, ibuf, sizeof( did ));
687     ibuf += sizeof( int );
688     if (NULL == ( sdir = dirlookup( vol, did )) ) {
689         return afp_errno; /* was AFPERR_PARAM */
690     }
691
692     memcpy( &did, ibuf, sizeof( did ));
693     ibuf += sizeof( int );
694
695     /* source pathname */
696     if (NULL == ( path = cname( vol, sdir, &ibuf )) ) {
697         return get_afp_errno(AFPERR_NOOBJ); 
698     }
699
700     sdir = curdir;
701     newname = obj->newtmp;
702     oldname = obj->oldtmp;
703     
704     isdir = path_isadir(path);
705     if ( *path->m_name != '\0' ) {
706         if (isdir) {
707             sdir = path->d_dir;
708         }
709         strcpy(oldname, path->m_name); /* an extra copy for of_rename */
710     } else {
711         strcpy(oldname, sdir->d_m_name);
712     }
713
714     /* get the destination directory */
715     if (NULL == ( ddir = dirlookup( vol, did )) ) {
716         return afp_errno; /*  was AFPERR_PARAM */
717     }
718     if (NULL == ( path = cname( vol, ddir, &ibuf ))) {
719         return( AFPERR_NOOBJ );
720     }
721     pdid = curdir->d_did;
722     if ( *path->m_name != '\0' ) {
723         return path_error(path, AFPERR_NOOBJ);
724     }
725
726     /* one more place where we know about path type */
727     if ((plen = copy_path_name(vol, newname, ibuf)) < 0) {
728         return( AFPERR_PARAM );
729     }
730
731     if (!plen) {
732         strcpy(newname, oldname);
733     }
734
735     rc = moveandrename(vol, sdir, oldname, newname, isdir);
736
737     if ( rc == AFP_OK ) {
738         char *upath = mtoupath(vol, newname, pdid, utf8_encoding());
739         
740         if (NULL == upath) {
741             return AFPERR_PARAM;
742         }
743         curdir->offcnt++;
744         sdir->offcnt--;
745 #ifdef DROPKLUDGE
746         if (vol->v_flags & AFPVOL_DROPBOX) {
747             /* FIXME did is not always the source id */
748             if ((retvalue=matchfile2dirperms (upath, vol, did)) != AFP_OK) {
749                 return retvalue;
750             }
751         }
752         else
753 #endif /* DROPKLUDGE */
754             /* if unix priv don't try to match perm with dest folder */
755             if (!isdir && !vol_unix_priv(vol)) {
756                 int  admode = ad_mode("", 0777) | vol->v_fperm;
757
758                 setfilmode(upath, admode, NULL);
759                 vol->vfs->rf_setfilmode(vol, upath, admode, NULL);
760             }
761         setvoltime(obj, vol );
762     }
763
764 #ifdef DEBUG
765     LOG(log_info, logtype_afpd, "end afp_moveandrename:");
766 #endif /* DEBUG */
767
768     return( rc );
769 }
770
771 int veto_file(const char*veto_str, const char*path)
772 /* given a veto_str like "abc/zxc/" and path "abc", return 1
773  * veto_str should be '/' delimited
774  * if path matches any one of the veto_str elements exactly, then 1 is returned
775  * otherwise, 0 is returned.
776  */
777 {
778     int i;      /* index to veto_str */
779     int j;      /* index to path */
780
781     if ((veto_str == NULL) || (path == NULL))
782         return 0;
783
784     for(i=0, j=0; veto_str[i] != '\0'; i++) {
785         if (veto_str[i] == '/') {
786             if ((j>0) && (path[j] == '\0')) {
787                 LOG(log_info, logtype_afpd, "vetoed file:'%s'", path);
788                 return 1;
789             }
790             j = 0;
791         } else {
792             if (veto_str[i] != path[j]) {
793                 while ((veto_str[i] != '/')
794                         && (veto_str[i] != '\0'))
795                     i++;
796                 j = 0;
797                 continue;
798             }
799             j++;
800         }
801     }
802     return 0;
803 }
804