]> arthur.barton.de Git - netatalk.git/blob - etc/afpd/filedir.c
put volume case insensitive option back
[netatalk.git] / etc / afpd / filedir.c
1 /*
2  * $Id: filedir.c,v 1.53 2009-04-17 04:24:20 didg 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         return AFPERR_EXIST;
321
322     /* check for vetoed filenames */
323     if (veto_file(vol->v_veto, name))
324         return AFPERR_EXIST;
325     return 0;
326 }
327
328 /* ------------------------- 
329     move and rename sdir:oldname to curdir:newname in volume vol
330    
331     special care is needed for lock   
332 */
333 static int moveandrename(vol, sdir, oldname, newname, isdir)
334 const struct vol        *vol;
335 struct dir      *sdir;
336 char        *oldname;
337 char        *newname;
338 int         isdir;
339 {
340     char            *p;
341     char            *upath;
342     int             rc;
343     struct stat     *st, nst;
344     int             adflags;
345     struct adouble      ad;
346     struct adouble      *adp;
347     struct ofork        *opened = NULL;
348     struct path         path;
349     cnid_t      id;
350
351     ad_init(&ad, vol->v_adouble, vol->v_ad_options);
352     adp = &ad;
353     adflags = 0;
354     
355     if (!isdir) {
356         p = mtoupath(vol, oldname, sdir->d_did, utf8_encoding());
357         if (!p) { 
358             return AFPERR_PARAM; /* can't convert */
359         }
360         id = cnid_get(vol->v_cdb, sdir->d_did, p, strlen(p));
361         p = ctoupath( vol, sdir, oldname );
362         if (!p) { 
363             return AFPERR_PARAM; /* pathname too long */
364         }
365         path.st_valid = 0;
366         path.u_name = p;
367         if ((opened = of_findname(&path))) {
368             /* reuse struct adouble so it won't break locks */
369             adp = opened->of_ad;
370         }
371     }
372     else {
373         id = sdir->d_did; /* we already have the CNID */
374         p = ctoupath( vol, sdir->d_parent, oldname );
375         if (!p) {
376             return AFPERR_PARAM;
377         }
378         adflags = ADFLAGS_DIR;
379     }
380     /*
381      * p now points to the full pathname of the source fs object.
382      * 
383      * we are in the dest folder so we need to use p for ad_open
384     */
385     
386     if (!ad_metadata(p, adflags, adp)) {
387         u_int16_t bshort;
388
389         ad_getattr(adp, &bshort);
390         ad_close_metadata( adp);
391         if ((bshort & htons(ATTRBIT_NORENAME))) 
392             return(AFPERR_OLOCK);
393     }
394
395     if (NULL == (upath = mtoupath(vol, newname, curdir->d_did, utf8_encoding()))){ 
396         return AFPERR_PARAM;
397     }
398     path.u_name = upath;
399     st = &path.st;    
400     if (0 != (rc = check_name(vol, upath))) {
401             return  rc;
402     }
403
404     /* source == destination. we just silently accept this. */
405     if ((!isdir && curdir == sdir) || (isdir && curdir == sdir->d_parent)) {
406         if (strcmp(oldname, newname) == 0)
407             return AFP_OK;
408
409         if (stat(upath, st) == 0 || caseenumerate(vol, &path, curdir) == 0) {
410             if (!stat(p, &nst) && !(nst.st_dev == st->st_dev && nst.st_ino == st->st_ino) ) {
411                 /* not the same file */
412                 return AFPERR_EXIST;
413             }
414             errno = 0;
415         }
416     } else if (stat(upath, st ) == 0 || caseenumerate(vol, &path, curdir) == 0)
417         return AFPERR_EXIST;
418
419     if ( !isdir ) {
420         path.st_valid = 1;
421         path.st_errno = errno;
422         if (of_findname(&path)) {
423             rc = AFPERR_EXIST; /* was AFPERR_BUSY; */
424         } else {
425             rc = renamefile(vol, p, upath, newname, adp );
426             if (rc == AFP_OK)
427                 of_rename(vol, opened, sdir, oldname, curdir, newname);
428         }
429     } else {
430         rc = renamedir(vol, p, upath, sdir, curdir, newname);
431     }
432     if ( rc == AFP_OK && id ) {
433         /* renaming may have moved the file/dir across a filesystem */
434         if (stat(upath, st) < 0)
435             return AFPERR_MISC;
436
437         /* fix up the catalog entry */
438         cnid_update(vol->v_cdb, id, st, curdir->d_did, upath, strlen(upath));
439     }
440
441     return rc;
442 }
443
444 /* -------------------------------------------- */
445 int afp_rename(obj, ibuf, ibuflen, rbuf, rbuflen )
446 AFPObj  *obj;
447 char    *ibuf, *rbuf _U_;
448 int     ibuflen _U_, *rbuflen;
449 {
450     struct vol  *vol;
451     struct dir  *sdir;
452     char        *oldname, *newname;
453     struct path *path;
454     u_int32_t   did;
455     int         plen;
456     u_int16_t   vid;
457     int         isdir = 0;
458     int         rc;
459 #ifdef DEBUG
460     LOG(log_info, logtype_afpd, "begin afp_rename:");
461 #endif /* DEBUG */
462
463     *rbuflen = 0;
464     ibuf += 2;
465
466     memcpy( &vid, ibuf, sizeof( vid ));
467     ibuf += sizeof( vid );
468     if (NULL == ( vol = getvolbyvid( vid )) ) {
469         return( AFPERR_PARAM );
470     }
471
472     if (vol->v_flags & AFPVOL_RO)
473         return AFPERR_VLOCK;
474
475     memcpy( &did, ibuf, sizeof( did ));
476     ibuf += sizeof( did );
477     if (NULL == ( sdir = dirlookup( vol, did )) ) {
478         return afp_errno;    
479     }
480
481     /* source pathname */
482     if (NULL == ( path = cname( vol, sdir, &ibuf )) ) {
483         return get_afp_errno(AFPERR_NOOBJ); 
484     }
485
486     sdir = curdir;
487     newname = obj->newtmp;
488     oldname = obj->oldtmp;
489     isdir = path_isadir(path);
490     if ( *path->m_name != '\0' ) {
491         strcpy(oldname, path->m_name); /* an extra copy for of_rename */
492         if (isdir) {
493             /* curdir parent dir, need to move sdir back */
494             sdir = path->d_dir;
495         }
496     }
497     else {
498         if ( sdir->d_parent == NULL ) { /* root directory */
499             return( AFPERR_NORENAME );
500         }
501         /* move to destination dir */
502         if ( movecwd( vol, sdir->d_parent ) < 0 ) {
503             return afp_errno;
504         }
505         strcpy(oldname, sdir->d_m_name);
506     }
507
508     /* another place where we know about the path type */
509     if ((plen = copy_path_name(vol, newname, ibuf)) < 0) {
510         return( AFPERR_PARAM );
511     }
512
513     if (!plen) {
514         return AFP_OK; /* newname == oldname same dir */
515     }
516     
517     rc = moveandrename(vol, sdir, oldname, newname, isdir);
518
519     if ( rc == AFP_OK ) {
520         setvoltime(obj, vol );
521     }
522
523 #ifdef DEBUG
524     LOG(log_info, logtype_afpd, "end afp_rename:");
525 #endif /* DEBUG */
526
527     return( rc );
528 }
529
530 /* ------------------------------- */
531 int afp_delete(obj, ibuf, ibuflen, rbuf, rbuflen )
532 AFPObj  *obj;
533 char    *ibuf, *rbuf _U_;
534 int     ibuflen _U_, *rbuflen;
535 {
536     struct vol          *vol;
537     struct dir          *dir;
538     struct path         *s_path;
539     char                *upath;
540     int                 did, rc;
541     u_int16_t           vid;
542
543 #ifdef DEBUG
544     LOG(log_info, logtype_afpd, "begin afp_delete:");
545 #endif /* DEBUG */ 
546
547     *rbuflen = 0;
548     ibuf += 2;
549
550     memcpy( &vid, ibuf, sizeof( vid ));
551     ibuf += sizeof( vid );
552     if (NULL == ( vol = getvolbyvid( vid )) ) {
553         return( AFPERR_PARAM );
554     }
555
556     if (vol->v_flags & AFPVOL_RO)
557         return AFPERR_VLOCK;
558
559     memcpy( &did, ibuf, sizeof( did ));
560     ibuf += sizeof( int );
561     if (NULL == ( dir = dirlookup( vol, did )) ) {
562         return afp_errno;    
563     }
564
565     if (NULL == ( s_path = cname( vol, dir, &ibuf )) ) {
566         return get_afp_errno(AFPERR_NOOBJ); 
567     }
568
569     upath = s_path->u_name;
570     if ( path_isadir( s_path) ) {
571         if (*s_path->m_name != '\0') {
572             rc = AFPERR_ACCESS;
573         }
574         else {
575             rc = deletecurdir( vol);
576         }
577     } else if (of_findname(s_path)) {
578         rc = AFPERR_BUSY;
579     } else {
580         rc = deletefile(vol, upath, 1);
581     }
582     if ( rc == AFP_OK ) {
583         curdir->offcnt--;
584         setvoltime(obj, vol );
585     }
586
587 #ifdef DEBUG
588     LOG(log_info, logtype_afpd, "end afp_delete:");
589 #endif /* DEBUG */
590
591     return( rc );
592 }
593 /* ------------------------ */
594 char *absupath( vol, dir, u )
595 const struct vol        *vol;
596 struct dir      *dir;
597 char    *u;
598 {
599     struct dir  *d;
600     static char path[ MAXPATHLEN + 1];
601     char        *p;
602     int         len;
603
604     if (u == NULL)
605         return NULL;
606         
607     p = path + sizeof( path ) - 1;
608     *p = '\0';
609     len = strlen( u );
610     p -= len;
611     memcpy( p, u, len );
612     if (dir) for ( d = dir; d->d_parent; d = d->d_parent ) {
613         u = d->d_u_name;
614         len = strlen( u );
615         if (p -len -1 < path) {
616             /* FIXME 
617                rather rare so LOG error and/or client message ?
618             */
619             return NULL;
620         }
621         *--p = '/';
622         p -= len;
623         memcpy( p, u, len );
624     }
625     len = strlen( vol->v_path );
626     if (p -len -1 < path) {
627         return NULL;
628     }
629     *--p = '/';
630     p -= len;
631     memcpy( p, vol->v_path, len );
632
633     return( p );
634 }
635
636 /* ------------------------
637  * FIXME dir could be NULL
638 */
639 char *ctoupath( vol, dir, name )
640 const struct vol        *vol;
641 struct dir      *dir;
642 char    *name;
643 {
644     return absupath(vol, dir, mtoupath(vol, name, dir->d_did, utf8_encoding()));
645 }
646
647 /* ------------------------- */
648 int afp_moveandrename(obj, ibuf, ibuflen, rbuf, rbuflen )
649 AFPObj  *obj;
650 char    *ibuf, *rbuf _U_;
651 int     ibuflen  _U_, *rbuflen;
652 {
653     struct vol  *vol;
654     struct dir  *sdir, *ddir;
655     int         isdir;
656     char        *oldname, *newname;
657     struct path *path;
658     int         did;
659     int         pdid;
660     int         plen;
661     u_int16_t   vid;
662     int         rc;
663 #ifdef DROPKLUDGE
664     int         retvalue;
665 #endif /* DROPKLUDGE */
666
667 #ifdef DEBUG
668     LOG(log_info, logtype_afpd, "begin afp_moveandrename:");
669 #endif /* DEBUG */
670
671     *rbuflen = 0;
672     ibuf += 2;
673
674     memcpy( &vid, ibuf, sizeof( vid ));
675     ibuf += sizeof( vid );
676     if (NULL == ( vol = getvolbyvid( vid )) ) {
677         return( AFPERR_PARAM );
678     }
679
680     if (vol->v_flags & AFPVOL_RO)
681         return AFPERR_VLOCK;
682
683     /* source did followed by dest did */
684     memcpy( &did, ibuf, sizeof( did ));
685     ibuf += sizeof( int );
686     if (NULL == ( sdir = dirlookup( vol, did )) ) {
687         return afp_errno; /* was AFPERR_PARAM */
688     }
689
690     memcpy( &did, ibuf, sizeof( did ));
691     ibuf += sizeof( int );
692
693     /* source pathname */
694     if (NULL == ( path = cname( vol, sdir, &ibuf )) ) {
695         return get_afp_errno(AFPERR_NOOBJ); 
696     }
697
698     sdir = curdir;
699     newname = obj->newtmp;
700     oldname = obj->oldtmp;
701     
702     isdir = path_isadir(path);
703     if ( *path->m_name != '\0' ) {
704         if (isdir) {
705             sdir = path->d_dir;
706         }
707         strcpy(oldname, path->m_name); /* an extra copy for of_rename */
708     } else {
709         strcpy(oldname, sdir->d_m_name);
710     }
711
712     /* get the destination directory */
713     if (NULL == ( ddir = dirlookup( vol, did )) ) {
714         return afp_errno; /*  was AFPERR_PARAM */
715     }
716     if (NULL == ( path = cname( vol, ddir, &ibuf ))) {
717         return( AFPERR_NOOBJ );
718     }
719     pdid = curdir->d_did;
720     if ( *path->m_name != '\0' ) {
721         return path_error(path, AFPERR_NOOBJ);
722     }
723
724     /* one more place where we know about path type */
725     if ((plen = copy_path_name(vol, newname, ibuf)) < 0) {
726         return( AFPERR_PARAM );
727     }
728
729     if (!plen) {
730         strcpy(newname, oldname);
731     }
732
733     rc = moveandrename(vol, sdir, oldname, newname, isdir);
734
735     if ( rc == AFP_OK ) {
736         char *upath = mtoupath(vol, newname, pdid, utf8_encoding());
737         
738         if (NULL == upath) {
739             return AFPERR_PARAM;
740         }
741         curdir->offcnt++;
742         sdir->offcnt--;
743 #ifdef DROPKLUDGE
744         if (vol->v_flags & AFPVOL_DROPBOX) {
745             /* FIXME did is not always the source id */
746             if ((retvalue=matchfile2dirperms (upath, vol, did)) != AFP_OK) {
747                 return retvalue;
748             }
749         }
750         else
751 #endif /* DROPKLUDGE */
752             /* if unix priv don't try to match perm with dest folder */
753             if (!isdir && !vol_unix_priv(vol)) {
754                 int  admode = ad_mode("", 0777) | vol->v_fperm;
755
756                 setfilmode(upath, admode, NULL);
757                 vol->vfs->rf_setfilmode(vol, upath, admode, NULL);
758             }
759         setvoltime(obj, vol );
760     }
761
762 #ifdef DEBUG
763     LOG(log_info, logtype_afpd, "end afp_moveandrename:");
764 #endif /* DEBUG */
765
766     return( rc );
767 }
768
769 int veto_file(const char*veto_str, const char*path)
770 /* given a veto_str like "abc/zxc/" and path "abc", return 1
771  * veto_str should be '/' delimited
772  * if path matches any one of the veto_str elements exactly, then 1 is returned
773  * otherwise, 0 is returned.
774  */
775 {
776     int i;      /* index to veto_str */
777     int j;      /* index to path */
778
779     if ((veto_str == NULL) || (path == NULL))
780         return 0;
781     /*
782     #ifdef DEBUG
783         LOG(log_debug, logtype_afpd, "veto_file \"%s\", \"%s\"", veto_str, path);
784     #endif
785     */
786     for(i=0, j=0; veto_str[i] != '\0'; i++) {
787         if (veto_str[i] == '/') {
788             if ((j>0) && (path[j] == '\0'))
789                 return 1;
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