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