]> arthur.barton.de Git - netatalk.git/blob - etc/afpd/filedir.c
add osx like resource fork.
[netatalk.git] / etc / afpd / filedir.c
1 /*
2  * $Id: filedir.c,v 1.45.2.2.2.9 2004-03-11 02:02:01 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->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: Error changing owner/gid of %s: %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:  Error adding file read permissions: %s",
104                     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: Error changing AppleDouble owner/gid %s: %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:  Error adding AD file read permissions: %s",
118                     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;
134 char    *ibuf, *rbuf;
135 int             ibuflen, *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         return( AFPERR_PARAM );
156     }
157
158     memcpy( &did, ibuf, sizeof( did ));
159     ibuf += sizeof( did );
160
161     if (NULL == ( dir = dirlookup( vol, did )) ) {
162         return afp_errno;
163     }
164
165     memcpy( &fbitmap, ibuf, sizeof( fbitmap ));
166     fbitmap = ntohs( fbitmap );
167     ibuf += sizeof( fbitmap );
168     memcpy( &dbitmap, ibuf, sizeof( dbitmap ));
169     dbitmap = ntohs( dbitmap );
170     ibuf += sizeof( dbitmap );
171
172     if (NULL == ( s_path = cname( vol, dir, &ibuf )) ) {
173         return get_afp_errno(AFPERR_NOOBJ); 
174     }
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(s_path);
184     }
185     if ( s_path->st_errno != 0 ) {
186         return( AFPERR_NOOBJ );
187     }
188
189     buflen = 0;
190     if (S_ISDIR(st->st_mode)) {
191         if (dbitmap) {
192             dir = s_path->dir;
193             if (!dir) 
194                 return AFPERR_NOOBJ;
195
196             ret = getdirparams(vol, dbitmap, s_path, dir,
197                                  rbuf + 3 * sizeof( u_int16_t ), &buflen );
198             if (ret != AFP_OK )
199                 return( ret );
200         }
201         /* this is a directory */
202         *(rbuf + 2 * sizeof( u_int16_t )) = (char) FILDIRBIT_ISDIR;
203     } else {
204         if (fbitmap && AFP_OK != (ret = getfilparams(vol, fbitmap, s_path, curdir, 
205                                             rbuf + 3 * sizeof( u_int16_t ), &buflen )) ) {
206             return( ret );
207         }
208         /* this is a file */
209         *(rbuf + 2 * sizeof( u_int16_t )) = FILDIRBIT_ISFILE;
210     }
211     *rbuflen = buflen + 3 * sizeof( u_int16_t );
212     fbitmap = htons( fbitmap );
213     memcpy( rbuf, &fbitmap, sizeof( fbitmap ));
214     rbuf += sizeof( fbitmap );
215     dbitmap = htons( dbitmap );
216     memcpy( rbuf, &dbitmap, sizeof( dbitmap ));
217     rbuf += sizeof( dbitmap ) + sizeof( u_char );
218     *rbuf = 0;
219
220 #ifdef DEBUG
221     LOG(log_info, logtype_afpd, "end afp_getfildirparams:");
222 #endif /* DEBUG */
223
224     return( AFP_OK );
225 }
226
227 int afp_setfildirparams(obj, ibuf, ibuflen, rbuf, rbuflen )
228 AFPObj      *obj;
229 char    *ibuf, *rbuf;
230 int             ibuflen, *rbuflen;
231 {
232     struct stat *st;
233     struct vol  *vol;
234     struct dir  *dir;
235     struct path *path;
236     u_int16_t   vid, bitmap;
237     int         did, rc;
238
239 #ifdef DEBUG
240     LOG(log_info, logtype_afpd, "begin afp_setfildirparams:");
241 #endif /* DEBUG */
242
243     *rbuflen = 0;
244     ibuf += 2;
245     memcpy( &vid, ibuf, sizeof(vid));
246     ibuf += sizeof( vid );
247
248     if (NULL == ( vol = getvolbyvid( vid )) ) {
249         return( AFPERR_PARAM );
250     }
251
252     if (vol->v_flags & AFPVOL_RO)
253         return AFPERR_VLOCK;
254
255     memcpy( &did, ibuf, sizeof( did));
256     ibuf += sizeof( did);
257
258     if (NULL == ( dir = dirlookup( vol, did )) ) {
259         return afp_errno;    
260     }
261
262     memcpy( &bitmap, ibuf, sizeof( bitmap ));
263     bitmap = ntohs( bitmap );
264     ibuf += sizeof( bitmap );
265
266     if (NULL == ( path = cname( vol, dir, &ibuf ))) {
267         return get_afp_errno(AFPERR_NOOBJ); 
268     }
269
270     st   = &path->st;
271     if (!path->st_valid) {
272         /* it's a dir and it should be there
273          * because we chdir in it in cname
274          */
275         of_stat(path);
276     }
277
278     if ( path->st_errno != 0 ) {
279         return( AFPERR_NOOBJ );
280     }
281     /*
282      * If ibuf is odd, make it even.
283      */
284     if ((u_long)ibuf & 1 ) {
285         ibuf++;
286     }
287
288     if (S_ISDIR(st->st_mode)) {
289         rc = setdirparams(vol, path, bitmap, ibuf );
290     } else {
291         rc = setfilparams(vol, path, bitmap, ibuf );
292     }
293     if ( rc == AFP_OK ) {
294         setvoltime(obj, vol );
295     }
296
297 #ifdef DEBUG
298     LOG(log_info, logtype_afpd, "end afp_setfildirparams:");
299 #endif /* DEBUG */
300
301     return( rc );
302 }
303
304 /* -------------------------------------------- 
305    Factorise some checks on a pathname
306 */
307 int check_name(const struct vol *vol, char *name)
308 {
309     /* check for illegal characters in the unix filename */
310     if (!wincheck(vol, name))
311         return AFPERR_PARAM;
312
313     if ((vol->v_flags & AFPVOL_NOHEX) && strchr(name, '/'))
314         return AFPERR_PARAM;
315
316     if (!vol->validupath(vol, name))
317         return AFPERR_EXIST;
318
319     /* check for vetoed filenames */
320     if (veto_file(vol->v_veto, name))
321         return AFPERR_EXIST;
322     return 0;
323 }
324
325 /* ------------------------- 
326     move and rename sdir:oldname to curdir:newname in volume vol
327    
328     special care is needed for lock   
329 */
330 static int moveandrename(vol, sdir, oldname, newname, isdir)
331 const struct vol        *vol;
332 struct dir      *sdir;
333 char        *oldname;
334 char        *newname;
335 int         isdir;
336 {
337     char            *p;
338     char            *upath;
339     int             rc;
340     struct stat     *st;
341     int             adflags;
342     struct adouble      ad;
343     struct adouble      *adp;
344     struct ofork        *opened = NULL;
345     struct path         path;
346     cnid_t      id;
347     ucs2_t *oldname_w, *newname_w;
348
349     ad_init(&ad, vol->v_adouble);
350     adp = &ad;
351     adflags = 0;
352     
353     if (!isdir) {
354         p = mtoupath(vol, oldname, sdir->d_did, utf8_encoding());
355         if (!p) { 
356             return AFPERR_PARAM; /* can't convert */
357         }
358         id = cnid_get(vol->v_cdb, sdir->d_did, p, strlen(p));
359         p = ctoupath( vol, sdir, oldname );
360         if (!p) { 
361             return AFPERR_PARAM; /* pathname too long */
362         }
363         path.st_valid = 0;
364         path.u_name = p;
365         if ((opened = of_findname(&path))) {
366             /* reuse struct adouble so it won't break locks */
367             adp = opened->of_ad;
368         }
369     }
370     else {
371         id = sdir->d_did; /* we already have the CNID */
372         p = ctoupath( vol, sdir->d_parent, oldname );
373         if (!p) {
374             return AFPERR_PARAM;
375         }
376         adflags = ADFLAGS_DIR;
377     }
378     /*
379      * p now points to the full pathname of the source fs object.
380      * 
381      * we are in the dest folder so we need to use p for ad_open
382     */
383     
384     if (!ad_open(p, ADFLAGS_HF |adflags, O_RDONLY, 0666, adp)) {
385     u_int16_t bshort;
386
387         ad_getattr(adp, &bshort);
388         ad_close( adp, ADFLAGS_HF );
389         if ((bshort & htons(ATTRBIT_NORENAME))) 
390             return(AFPERR_OLOCK);
391     }
392
393     if (NULL == (upath = mtoupath(vol, newname, curdir->d_did, utf8_encoding()))){ 
394         return AFPERR_PARAM;
395     }
396     path.u_name = upath;
397     st = &path.st;    
398     if (0 != (rc = check_name(vol, upath))) {
399             return  rc;
400     }
401
402     /* source == destination. we just silently accept this. */
403     if (curdir == sdir) {
404         if (strcmp(oldname, newname) == 0)
405             return AFP_OK;
406
407         /* deal with case insensitive, case-preserving filesystems. */
408         if ((stat(upath, st) == 0)) {
409             if ((size_t)-1 == (convert_string_allocate(vol->v_volcharset, CH_UCS2, oldname,
410                                 strlen(oldname), (char**) &oldname_w)) ) {
411                 return AFPERR_MISC; /* conversion error has already been logged */
412             }
413             if ((size_t)-1 == (convert_string_allocate(vol->v_volcharset, CH_UCS2, newname, 
414                                 strlen(newname), (char**) &newname_w)) ) {
415                 free(oldname_w);
416                 return AFPERR_MISC; /* conversion error has already been logged */
417             }
418             if (!strcasecmp_w(oldname_w, newname_w)) {
419                 free(oldname_w);
420                 free(newname_w);
421                 return AFPERR_EXIST;
422             }
423             free (oldname_w);   
424             free (newname_w);   
425         }
426     } else if (stat(upath, st ) == 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, 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, 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(obj, ibuf, ibuflen, rbuf, rbuflen )
456 AFPObj      *obj;
457 char    *ibuf, *rbuf;
458 int             ibuflen, *rbuflen;
459 {
460     struct vol  *vol;
461     struct dir  *sdir;
462     char        *oldname, *newname;
463     struct path *path;
464     u_int32_t   did;
465     int         plen;
466     u_int16_t   vid;
467     int         isdir = 0;
468     int         rc;
469 #ifdef DEBUG
470     LOG(log_info, logtype_afpd, "begin afp_rename:");
471 #endif /* DEBUG */
472
473     *rbuflen = 0;
474     ibuf += 2;
475
476     memcpy( &vid, ibuf, sizeof( vid ));
477     ibuf += sizeof( vid );
478     if (NULL == ( vol = getvolbyvid( vid )) ) {
479         return( AFPERR_PARAM );
480     }
481
482     if (vol->v_flags & AFPVOL_RO)
483         return AFPERR_VLOCK;
484
485     memcpy( &did, ibuf, sizeof( did ));
486     ibuf += sizeof( did );
487     if (NULL == ( sdir = dirlookup( vol, did )) ) {
488         return afp_errno;    
489     }
490
491     /* source pathname */
492     if (NULL == ( path = cname( vol, sdir, &ibuf )) ) {
493         return get_afp_errno(AFPERR_NOOBJ); 
494     }
495
496     sdir = curdir;
497     newname = obj->newtmp;
498     oldname = obj->oldtmp;
499     isdir = path_isadir(path);
500     if ( *path->m_name != '\0' ) {
501         strcpy(oldname, path->m_name); /* an extra copy for of_rename */
502         if (isdir) {
503             /* curdir parent dir, need to move sdir back */
504             sdir = path->dir;
505         }
506     }
507     else {
508         if ( sdir->d_parent == NULL ) { /* root directory */
509             return( AFPERR_NORENAME );
510         }
511         /* move to destination dir */
512         if ( movecwd( vol, sdir->d_parent ) < 0 ) {
513             return afp_errno;
514         }
515         strcpy(oldname, sdir->d_m_name);
516     }
517
518     /* another place where we know about the path type */
519     if ((plen = copy_path_name(newname, ibuf)) < 0) {
520         return( AFPERR_PARAM );
521     }
522
523     if (!plen) {
524         return AFP_OK; /* newname == oldname same dir */
525     }
526     
527     rc = moveandrename(vol, sdir, oldname, newname, isdir);
528
529     if ( rc == AFP_OK ) {
530         setvoltime(obj, vol );
531     }
532
533 #ifdef DEBUG
534     LOG(log_info, logtype_afpd, "end afp_rename:");
535 #endif /* DEBUG */
536
537     return( rc );
538 }
539
540 /* ------------------------------- */
541 int afp_delete(obj, ibuf, ibuflen, rbuf, rbuflen )
542 AFPObj      *obj;
543 char    *ibuf, *rbuf;
544 int             ibuflen, *rbuflen;
545 {
546     struct vol          *vol;
547     struct dir          *dir;
548     struct path         *s_path;
549     char                *upath;
550     int                 did, rc;
551     u_int16_t           vid;
552
553 #ifdef DEBUG
554     LOG(log_info, logtype_afpd, "begin afp_delete:");
555 #endif /* DEBUG */ 
556
557     *rbuflen = 0;
558     ibuf += 2;
559
560     memcpy( &vid, ibuf, sizeof( vid ));
561     ibuf += sizeof( vid );
562     if (NULL == ( vol = getvolbyvid( vid )) ) {
563         return( AFPERR_PARAM );
564     }
565
566     if (vol->v_flags & AFPVOL_RO)
567         return AFPERR_VLOCK;
568
569     memcpy( &did, ibuf, sizeof( did ));
570     ibuf += sizeof( int );
571     if (NULL == ( dir = dirlookup( vol, did )) ) {
572         return afp_errno;    
573     }
574
575     if (NULL == ( s_path = cname( vol, dir, &ibuf )) ) {
576         return get_afp_errno(AFPERR_NOOBJ); 
577     }
578
579     upath = s_path->u_name;
580     if ( path_isadir( s_path) ) {
581         if (*s_path->m_name != '\0') {
582             rc = AFPERR_ACCESS;
583         }
584         else {
585             rc = deletecurdir( vol, obj->oldtmp, AFPOBJ_TMPSIZ);
586         }
587     } else if (of_findname(s_path)) {
588         rc = AFPERR_BUSY;
589     } else {
590         rc = deletefile(vol, upath, 1);
591     }
592     if ( rc == AFP_OK ) {
593         curdir->offcnt--;
594         setvoltime(obj, vol );
595     }
596
597 #ifdef DEBUG
598     LOG(log_info, logtype_afpd, "end afp_delete:");
599 #endif /* DEBUG */
600
601     return( rc );
602 }
603 /* ------------------------ */
604 char *absupath( vol, dir, u )
605 const struct vol        *vol;
606 struct dir      *dir;
607 char    *u;
608 {
609     struct dir  *d;
610     static char path[ MAXPATHLEN + 1];
611     char        *p;
612     int         len;
613
614     if (u == NULL)
615         return NULL;
616         
617     p = path + sizeof( path ) - 1;
618     *p = '\0';
619     len = strlen( u );
620     p -= len;
621     memcpy( p, u, len );
622     if (dir) for ( d = dir; d->d_parent; d = d->d_parent ) {
623         u = d->d_u_name;
624         len = strlen( u );
625         if (p -len -1 < path) {
626             /* FIXME 
627                rather rare so LOG error and/or client message ?
628             */
629             return NULL;
630         }
631         *--p = '/';
632         p -= len;
633         memcpy( p, u, len );
634     }
635     len = strlen( vol->v_path );
636     if (p -len -1 < path) {
637         return NULL;
638     }
639     *--p = '/';
640     p -= len;
641     memcpy( p, vol->v_path, len );
642
643     return( p );
644 }
645
646 /* ------------------------
647  * FIXME dir could be NULL
648 */
649 char *ctoupath( vol, dir, name )
650 const struct vol        *vol;
651 struct dir      *dir;
652 char    *name;
653 {
654     return absupath(vol, dir, mtoupath(vol, name, dir->d_did, utf8_encoding()));
655 }
656
657 /* ------------------------- */
658 int afp_moveandrename(obj, ibuf, ibuflen, rbuf, rbuflen )
659 AFPObj      *obj;
660 char    *ibuf, *rbuf;
661 int             ibuflen, *rbuflen;
662 {
663     struct vol  *vol;
664     struct dir  *sdir, *ddir;
665     int         isdir;
666     char        *oldname, *newname;
667     struct path *path;
668     int         did;
669     int         pdid;
670     int         plen;
671     u_int16_t   vid;
672     int         rc;
673 #ifdef DROPKLUDGE
674     int         retvalue;
675 #endif /* DROPKLUDGE */
676
677 #ifdef DEBUG
678     LOG(log_info, logtype_afpd, "begin afp_moveandrename:");
679 #endif /* DEBUG */
680
681     *rbuflen = 0;
682     ibuf += 2;
683
684     memcpy( &vid, ibuf, sizeof( vid ));
685     ibuf += sizeof( vid );
686     if (NULL == ( vol = getvolbyvid( vid )) ) {
687         return( AFPERR_PARAM );
688     }
689
690     if (vol->v_flags & AFPVOL_RO)
691         return AFPERR_VLOCK;
692
693     /* source did followed by dest did */
694     memcpy( &did, ibuf, sizeof( did ));
695     ibuf += sizeof( int );
696     if (NULL == ( sdir = dirlookup( vol, did )) ) {
697         return afp_errno; /* was AFPERR_PARAM */
698     }
699
700     memcpy( &did, ibuf, sizeof( did ));
701     ibuf += sizeof( int );
702
703     /* source pathname */
704     if (NULL == ( path = cname( vol, sdir, &ibuf )) ) {
705         return get_afp_errno(AFPERR_NOOBJ); 
706     }
707
708     sdir = curdir;
709     newname = obj->newtmp;
710     oldname = obj->oldtmp;
711     
712     isdir = path_isadir(path);
713     if ( *path->m_name != '\0' ) {
714         if (isdir) {
715             sdir = path->dir;
716         }
717         strcpy(oldname, path->m_name); /* an extra copy for of_rename */
718     } else {
719         strcpy(oldname, sdir->d_m_name);
720     }
721
722     /* get the destination directory */
723     if (NULL == ( ddir = dirlookup( vol, did )) ) {
724         return afp_errno; /*  was AFPERR_PARAM */
725     }
726     if (NULL == ( path = cname( vol, ddir, &ibuf ))) {
727         return( AFPERR_NOOBJ );
728     }
729     pdid = curdir->d_did;
730     if ( *path->m_name != '\0' ) {
731         return path_error(path, AFPERR_NOOBJ);
732     }
733
734     /* one more place where we know about path type */
735     if ((plen = copy_path_name(newname, ibuf)) < 0) {
736         return( AFPERR_PARAM );
737     }
738
739     if (!plen) {
740         strcpy(newname, oldname);
741     }
742
743     rc = moveandrename(vol, sdir, oldname, newname, isdir);
744
745     if ( rc == AFP_OK ) {
746         char *upath = mtoupath(vol, newname, pdid, utf8_encoding());
747         
748         if (NULL == upath) {
749             return AFPERR_PARAM;
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                 return retvalue;
758             }
759         }
760         else
761 #endif /* DROPKLUDGE */
762             /* if unix priv don't try to match perm with dest folder */
763             if (!isdir && !vol_unix_priv(vol)) {
764                 int  admode = ad_mode("", 0777);
765
766                 setfilmode(upath, admode, NULL);
767                 setfilmode(vol->ad_path( upath, ADFLAGS_HF ), ad_hf_mode(admode), NULL);
768             }
769         setvoltime(obj, vol );
770     }
771
772 #ifdef DEBUG
773     LOG(log_info, logtype_afpd, "end afp_moveandrename:");
774 #endif /* DEBUG */
775
776     return( rc );
777 }
778
779 int veto_file(const char*veto_str, const char*path)
780 /* given a veto_str like "abc/zxc/" and path "abc", return 1
781  * veto_str should be '/' delimited
782  * if path matches any one of the veto_str elements exactly, then 1 is returned
783  * otherwise, 0 is returned.
784  */
785 {
786     int i;      /* index to veto_str */
787     int j;      /* index to path */
788
789     if ((veto_str == NULL) || (path == NULL))
790         return 0;
791     /*
792     #ifdef DEBUG
793         LOG(log_debug, logtype_afpd, "veto_file \"%s\", \"%s\"", veto_str, path);
794     #endif
795     */
796     for(i=0, j=0; veto_str[i] != '\0'; i++) {
797         if (veto_str[i] == '/') {
798             if ((j>0) && (path[j] == '\0'))
799                 return 1;
800             j = 0;
801         } else {
802             if (veto_str[i] != path[j]) {
803                 while ((veto_str[i] != '/')
804                         && (veto_str[i] != '\0'))
805                     i++;
806                 j = 0;
807                 continue;
808             }
809             j++;
810         }
811     }
812     return 0;
813 }
814