]> arthur.barton.de Git - netatalk.git/blob - etc/afpd/filedir.c
move of_findname key from filename to dev, inode.
[netatalk.git] / etc / afpd / filedir.c
1 /*
2  * $Id: filedir.c,v 1.29 2002-09-04 17:28:08 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
58 int matchfile2dirperms(upath, vol, did)
59 /* Since it's kinda' big; I decided against an
60 inline function */
61 char    *upath;
62 struct vol  *vol;
63 int             did;
64 /* The below code changes the way file ownership is determined in the name of
65 fixing dropboxes.  It has known security problem.  See the netatalk FAQ for
66 more information */
67 {
68     struct stat st, sb;
69     struct dir  *dir;
70     char        adpath[50];
71     int         uid;
72
73 #ifdef DEBUG
74     LOG(log_info, logtype_afpd, "begin matchfile2dirperms:");
75 #endif /* DEBUG */
76
77     if (stat(upath, &st ) < 0)
78         LOG(log_error, logtype_afpd, "Could not stat %s: %s", upath, strerror(errno));
79     strcpy (adpath, "./.AppleDouble/");
80     strcat (adpath, upath);
81     if (( dir = dirsearch( vol, did )) == NULL ) {
82         LOG(log_error, logtype_afpd, "matchfile2dirperms: Unable to get directory info.");
83         return( AFPERR_NOOBJ );
84     }
85     else if (stat(".", &sb) < 0) {
86         LOG(log_error, logtype_afpd,
87             "matchfile2dirperms: Error checking directory \"%s\": %s",
88             dir->d_name, strerror(errno));
89         return(AFPERR_NOOBJ );
90     }
91     else {
92         uid=geteuid();
93         if ( uid != sb.st_uid )
94         {
95             seteuid(0);
96             if (lchown(upath, sb.st_uid, sb.st_gid) < 0)
97             {
98                 LOG(log_error, logtype_afpd,
99                     "matchfile2dirperms: Error changing owner/gid of %s: %s",
100                     upath, strerror(errno));
101                 return (AFPERR_ACCESS);
102             }
103             if (chmod(upath,(st.st_mode&~default_options.umask)| S_IRGRP| S_IROTH) < 0)
104             {
105                 LOG(log_error, logtype_afpd,
106                     "matchfile2dirperms:  Error adding file read permissions: %s",
107                     strerror(errno));
108                 return (AFPERR_ACCESS);
109             }
110 #ifdef DEBUG
111             else
112                 LOG(log_info, logtype_afpd,
113                     "matchfile2dirperms:  Added S_IRGRP and S_IROTH: %s",
114                     strerror(errno));
115 #endif /* DEBUG */
116             if (lchown(adpath, sb.st_uid, sb.st_gid) < 0)
117             {
118                 LOG(log_error, logtype_afpd,
119                     "matchfile2dirperms: Error changing AppleDouble owner/gid %s: %s",
120                     adpath, strerror(errno));
121                 return (AFPERR_ACCESS);
122             }
123             if (chmod(adpath, (st.st_mode&~default_options.umask)| S_IRGRP| S_IROTH) < 0)
124             {
125                 LOG(log_error, logtype_afpd,
126                     "matchfile2dirperms:  Error adding AD file read permissions: %s",
127                     strerror(errno));
128                 return (AFPERR_ACCESS);
129             }
130 #ifdef DEBUG
131             else
132                 LOG(log_info, logtype_afpd,
133                     "matchfile2dirperms:  Added S_IRGRP and S_IROTH to AD: %s",
134                     strerror(errno));
135 #endif /* DEBUG */
136         }
137 #ifdef DEBUG
138         else
139             LOG(log_info, logtype_afpd,
140                 "matchfile2dirperms: No ownership change necessary.");
141 #endif /* DEBUG */
142     } /* end else if stat success */
143     seteuid(uid); /* Restore process ownership to normal */
144 #ifdef DEBUG
145     LOG(log_info, logtype_afpd, "end matchfile2dirperms:");
146 #endif /* DEBUG */
147
148     return (AFP_OK);
149
150 }
151
152
153 int afp_getfildirparams(obj, ibuf, ibuflen, rbuf, rbuflen )
154 AFPObj      *obj;
155 char    *ibuf, *rbuf;
156 int             ibuflen, *rbuflen;
157 {
158     struct stat         st;
159     struct vol          *vol;
160     struct dir          *dir;
161     u_int32_t           did;
162     int                 buflen, ret;
163     char                *path;
164     u_int16_t           fbitmap, dbitmap, vid;
165
166 #ifdef DEBUG
167     LOG(log_info, logtype_afpd, "begin afp_getfildirparams:");
168 #endif /* DEBUG */
169
170     *rbuflen = 0;
171     ibuf += 2;
172
173     memcpy( &vid, ibuf, sizeof( vid ));
174     ibuf += sizeof( vid );
175     if (( vol = getvolbyvid( vid )) == NULL ) {
176         return( AFPERR_PARAM );
177     }
178
179     memcpy( &did, ibuf, sizeof( did ));
180     ibuf += sizeof( did );
181
182     if (( dir = dirlookup( vol, did )) == NULL ) {
183         return( AFPERR_NOOBJ );
184     }
185
186     memcpy( &fbitmap, ibuf, sizeof( fbitmap ));
187     fbitmap = ntohs( fbitmap );
188     ibuf += sizeof( fbitmap );
189     memcpy( &dbitmap, ibuf, sizeof( dbitmap ));
190     dbitmap = ntohs( dbitmap );
191     ibuf += sizeof( dbitmap );
192
193     if (( path = cname( vol, dir, &ibuf )) == NULL) {
194         return( AFPERR_NOOBJ );
195     }
196
197     if ( stat( mtoupath(vol, path ), &st ) < 0 ) {
198         return( AFPERR_NOOBJ );
199     }
200
201     buflen = 0;
202     if (S_ISDIR(st.st_mode)) {
203         if (dbitmap) {
204             ret = getdirparams(vol, dbitmap, ".", curdir,
205                                &st, 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, path, curdir, &st,
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 /*
236  * We can't use unix file's perm to support Apple's inherited protection modes.
237  * If we aren't the file's owner we can't change its perms when moving it and smb
238  * nfs,... don't even try.
239 */
240 #define AFP_CHECK_ACCESS 
241
242 int check_access(char *path, int mode)
243 {
244 #ifdef AFP_CHECK_ACCESS
245 struct maccess ma;
246 char *p;
247
248     p = ad_dir(path);
249     if (!p)
250        return -1;
251
252     accessmode(p, &ma, curdir, NULL);
253     if ((mode & OPENACC_WR) && !(ma.ma_user & AR_UWRITE))
254         return -1;
255     if ((mode & OPENACC_RD) && !(ma.ma_user & AR_UREAD))
256         return -1;
257 #endif
258     return 0;
259 }
260
261 int afp_setfildirparams(obj, ibuf, ibuflen, rbuf, rbuflen )
262 AFPObj      *obj;
263 char    *ibuf, *rbuf;
264 int             ibuflen, *rbuflen;
265 {
266     struct stat st;
267     struct vol  *vol;
268     struct dir  *dir;
269     char        *path;
270     u_int16_t   vid, bitmap;
271     int         did, rc;
272
273 #ifdef DEBUG
274     LOG(log_info, logtype_afpd, "begin afp_setfildirparams:");
275 #endif /* DEBUG */
276
277     *rbuflen = 0;
278     ibuf += 2;
279     memcpy( &vid, ibuf, sizeof(vid));
280     ibuf += sizeof( vid );
281
282     if (( vol = getvolbyvid( vid )) == NULL ) {
283         return( AFPERR_PARAM );
284     }
285
286     if (vol->v_flags & AFPVOL_RO)
287         return AFPERR_VLOCK;
288
289     memcpy( &did, ibuf, sizeof( did));
290     ibuf += sizeof( did);
291
292     if (( dir = dirsearch( vol, did )) == NULL ) {
293         return( AFPERR_NOOBJ );
294     }
295
296     memcpy( &bitmap, ibuf, sizeof( bitmap ));
297     bitmap = ntohs( bitmap );
298     ibuf += sizeof( bitmap );
299
300     if (( path = cname( vol, dir, &ibuf )) == NULL ) {
301         return( AFPERR_NOOBJ );
302     }
303
304     if ( stat( mtoupath(vol, path ), &st ) < 0 ) {
305         return( AFPERR_NOOBJ );
306     }
307
308     /*
309      * If ibuf is odd, make it even.
310      */
311     if ((u_long)ibuf & 1 ) {
312         ibuf++;
313     }
314
315     if (S_ISDIR(st.st_mode)) {
316         rc = setdirparams(vol, path, bitmap, ibuf );
317     } else {
318         rc = setfilparams(vol, path, bitmap, ibuf );
319     }
320     if ( rc == AFP_OK ) {
321         setvoltime(obj, vol );
322     }
323
324 #ifdef DEBUG
325     LOG(log_info, logtype_afpd, "end afp_setfildirparams:");
326 #endif /* DEBUG */
327
328     return( rc );
329 }
330
331 /* -------------------------------------------- 
332    Factorise some check on a pathname
333 */
334 int check_name(const struct vol *vol, char *name)
335 {
336     /* check for illegal characters in the unix filename */
337     if (!wincheck(vol, name))
338         return AFPERR_PARAM;
339
340     if ((vol->v_flags & AFPVOL_NOHEX) && strchr(name, '/'))
341         return AFPERR_PARAM;
342
343     if (!validupath(vol, name))
344         return AFPERR_EXIST;
345
346     /* check for vetoed filenames */
347     if (veto_file(vol->v_veto, name))
348         return AFPERR_EXIST;
349     return 0;
350 }
351
352 /* ------------------------- 
353     move and rename sdir:oldname to curdir:newname in volume vol
354    
355     special care is needed for lock   
356 */
357 static int moveandrename(vol, sdir, oldname, newname, isdir)
358 const struct vol        *vol;
359 struct dir      *sdir;
360 char        *oldname;
361 char        *newname;
362 int         isdir;
363 {
364     char            *p;
365     char            *upath;
366     int             rc;
367     struct stat     st;
368     int             adflags;
369     struct adouble      ad;
370     struct adouble      *adp;
371     struct ofork        *opened;
372
373 #ifdef CNID_DB
374     cnid_t      id;
375 #endif /* CNID_DB */
376
377     memset(&ad, 0, sizeof(ad));
378     adp = &ad;
379     adflags = 0;
380     
381     if (!isdir) {
382 #ifdef CNID_DB
383         p = mtoupath(vol, oldname);
384         id = cnid_get(vol->v_db, sdir->d_did, p, strlen(p));
385 #endif /* CNID_DB */
386         p = ctoupath( vol, sdir, oldname );
387         if ((opened = of_findname(vol, sdir, p, NULL))) {
388             /* reuse struct adouble so it won't break locks */
389             adp = opened->of_ad;
390         }
391     }
392     else {
393 #ifdef CNID_DB
394         id = sdir->d_did; /* we already have the CNID */
395 #endif /* CNID_DB */
396         p = ctoupath( vol, sdir->d_parent, oldname );
397         adflags = ADFLAGS_DIR;
398     }
399     /*
400      * p now points to the full pathname of the source fs object.
401      * 
402      * we are in the dest folder so we need to use p for ad_open
403     */
404     
405     if (!ad_open(p, ADFLAGS_HF |adflags, O_RDONLY, 0666, adp)) {
406     u_int16_t bshort;
407
408         ad_getattr(adp, &bshort);
409         ad_close( adp, ADFLAGS_HF );
410         if ((bshort & htons(ATTRBIT_NORENAME))) 
411             return(AFPERR_OLOCK);
412     }
413
414     upath = mtoupath(vol, newname);
415     if (0 != (rc = check_name(vol, upath))) {
416             return  rc;
417     }
418
419     /* source == destination. we just silently accept this. */
420     if (curdir == sdir) {
421         if (strcmp(oldname, newname) == 0)
422             return AFP_OK;
423
424         /* deal with case insensitive, case-preserving filesystems. */
425         if ((stat(upath, &st) == 0) && strdiacasecmp(oldname, newname))
426             return AFPERR_EXIST;
427
428     } else if (stat(upath, &st ) == 0)
429         return AFPERR_EXIST;
430
431     if ( !isdir ) {
432         if (of_findname(vol, curdir, upath, &st)) {
433             rc = AFPERR_EXIST; /* was AFPERR_BUSY; */
434         } else {
435             rc = renamefile( p, upath, newname,vol_noadouble(vol), adp );
436             if (rc == AFP_OK)
437                 of_rename(vol, opened, sdir, oldname, curdir, newname);
438         }
439     } else {
440         rc = renamedir(p, upath, sdir, curdir, newname, vol_noadouble(vol));
441     }
442     if ( rc == AFP_OK ) {
443 #ifdef CNID_DB
444         /* renaming may have moved the file/dir across a filesystem */
445         if (stat(upath, &st) < 0)
446             return AFPERR_MISC;
447
448         /* fix up the catalog entry */
449         cnid_update(vol->v_db, id, &st, curdir->d_did, upath, strlen(upath));
450 #endif /* CNID_DB */
451     }
452
453     return rc;
454 }
455
456 /* -------------------------------------------- */
457 int afp_rename(obj, ibuf, ibuflen, rbuf, rbuflen )
458 AFPObj      *obj;
459 char    *ibuf, *rbuf;
460 int             ibuflen, *rbuflen;
461 {
462     struct vol  *vol;
463     struct dir  *sdir;
464     char                *path, *oldname, *newname;
465     u_int32_t   did;
466     int                 plen;
467     u_int16_t   vid;
468     int         isdir = 0;
469     int         rc;
470 #ifdef DEBUG
471     LOG(log_info, logtype_afpd, "begin afp_rename:");
472 #endif /* DEBUG */
473
474     *rbuflen = 0;
475     ibuf += 2;
476
477     memcpy( &vid, ibuf, sizeof( vid ));
478     ibuf += sizeof( vid );
479     if (( vol = getvolbyvid( vid )) == NULL ) {
480         return( AFPERR_PARAM );
481     }
482
483     if (vol->v_flags & AFPVOL_RO)
484         return AFPERR_VLOCK;
485
486     memcpy( &did, ibuf, sizeof( did ));
487     ibuf += sizeof( did );
488     if (( sdir = dirsearch( vol, did )) == NULL ) {
489         return( AFPERR_NOOBJ );
490     }
491
492     /* source pathname */
493     if (( path = cname( vol, sdir, &ibuf )) == NULL ) {
494         return( AFPERR_NOOBJ );
495     }
496
497     sdir = curdir;
498     newname = obj->newtmp;
499     oldname = obj->oldtmp;
500     if ( *path != '\0' ) {
501         strcpy(oldname, path); /* an extra copy for of_rename */
502     }
503     else {
504         if ( sdir->d_parent == NULL ) { /* root directory */
505             return( AFPERR_NORENAME );
506         }
507         /* move to destination dir */
508         if ( movecwd( vol, sdir->d_parent ) < 0 ) {
509             return( AFPERR_NOOBJ );
510         }
511         isdir = 1;
512         strcpy(oldname, sdir->d_name);
513     }
514
515     /* another place where we know about the path type */
516     if ( *ibuf++ != 2 ) {
517         return( AFPERR_PARAM );
518     }
519
520     if (( plen = (unsigned char)*ibuf++ ) != 0 ) {
521         strncpy( newname, ibuf, plen );
522         newname[ plen ] = '\0';
523         if (strlen(newname) != plen) {
524             return( AFPERR_PARAM );
525         }
526     }
527     else {
528         return AFP_OK; /* newname == oldname same dir */
529     }
530     
531     rc = moveandrename(vol, sdir, oldname, newname, isdir);
532
533     if ( rc == AFP_OK ) {
534         setvoltime(obj, vol );
535     }
536
537 #ifdef DEBUG
538     LOG(log_info, logtype_afpd, "end afp_rename:");
539 #endif /* DEBUG */
540
541     return( rc );
542 }
543
544 /* ------------------------------- */
545 int afp_delete(obj, ibuf, ibuflen, rbuf, rbuflen )
546 AFPObj      *obj;
547 char    *ibuf, *rbuf;
548 int             ibuflen, *rbuflen;
549 {
550     struct vol          *vol;
551     struct dir          *dir;
552     char                *path, *upath;
553     int                 did, rc;
554     u_int16_t           vid;
555
556 #ifdef DEBUG
557     LOG(log_info, logtype_afpd, "begin afp_delete:");
558 #endif /* DEBUG */ 
559
560     *rbuflen = 0;
561     ibuf += 2;
562
563     memcpy( &vid, ibuf, sizeof( vid ));
564     ibuf += sizeof( vid );
565     if (( vol = getvolbyvid( vid )) == NULL ) {
566         return( AFPERR_PARAM );
567     }
568
569     if (vol->v_flags & AFPVOL_RO)
570         return AFPERR_VLOCK;
571
572     memcpy( &did, ibuf, sizeof( did ));
573     ibuf += sizeof( int );
574     if (( dir = dirsearch( vol, did )) == NULL ) {
575         return( AFPERR_NOOBJ );
576     }
577
578     if (( path = cname( vol, dir, &ibuf )) == NULL ) {
579         return( AFPERR_NOOBJ );
580     }
581
582     upath = mtoupath(vol, path );
583     if ( *path == '\0' ) {
584         rc = deletecurdir( vol, obj->oldtmp, AFPOBJ_TMPSIZ);
585     } else if (of_findname(vol, curdir, upath, NULL)) {
586         rc = AFPERR_BUSY;
587     } else if ((rc = deletefile( upath, 1)) == AFP_OK) {
588 #ifdef CNID_DB /* get rid of entry */
589         cnid_t id = cnid_get(vol->v_db, curdir->d_did, upath, strlen(upath));
590         cnid_delete(vol->v_db, id);
591 #endif /* CNID_DB */
592     }
593     if ( rc == AFP_OK ) {
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 *ctoupath( vol, dir, name )
605 const struct vol        *vol;
606 struct dir      *dir;
607 char    *name;
608 {
609     struct dir  *d;
610     static char path[ MAXPATHLEN + 1];
611     char        *p, *u;
612     int         len;
613
614     p = path + sizeof( path ) - 1;
615     *p = '\0';
616     u = mtoupath(vol, name );
617     len = strlen( u );
618     p -= len;
619     strncpy( p, u, len );
620     for ( d = dir; d->d_parent; d = d->d_parent ) {
621         *--p = '/';
622         u = mtoupath(vol, d->d_name );
623         len = strlen( u );
624         p -= len;
625         strncpy( p, u, len );
626     }
627     *--p = '/';
628     len = strlen( vol->v_path );
629     p -= len;
630     strncpy( p, vol->v_path, len );
631
632     return( p );
633 }
634
635 /* ------------------------- */
636 int afp_moveandrename(obj, ibuf, ibuflen, rbuf, rbuflen )
637 AFPObj      *obj;
638 char    *ibuf, *rbuf;
639 int             ibuflen, *rbuflen;
640 {
641     struct vol  *vol;
642     struct dir  *sdir, *ddir;
643     int         isdir = 0;
644     char            *oldname, *newname;
645     char        *path;
646     int         did;
647     int         plen;
648     u_int16_t   vid;
649     int         rc;
650 #ifdef DROPKLUDGE
651     int         retvalue;
652 #endif /* DROPKLUDGE */
653
654 #ifdef DEBUG
655     LOG(log_info, logtype_afpd, "begin afp_moveandrename:");
656 #endif /* DEBUG */
657
658     *rbuflen = 0;
659     ibuf += 2;
660
661     memcpy( &vid, ibuf, sizeof( vid ));
662     ibuf += sizeof( vid );
663     if (( vol = getvolbyvid( vid )) == NULL ) {
664         return( AFPERR_PARAM );
665     }
666
667     if (vol->v_flags & AFPVOL_RO)
668         return AFPERR_VLOCK;
669
670     /* source did followed by dest did */
671     memcpy( &did, ibuf, sizeof( did ));
672     ibuf += sizeof( int );
673     if (( sdir = dirsearch( vol, did )) == NULL ) {
674         return( AFPERR_PARAM );
675     }
676
677     memcpy( &did, ibuf, sizeof( did ));
678     ibuf += sizeof( int );
679
680     /* source pathname */
681     if (( path = cname( vol, sdir, &ibuf )) == NULL ) {
682         return( AFPERR_NOOBJ );
683     }
684
685     sdir = curdir;
686     newname = obj->newtmp;
687     oldname = obj->oldtmp;
688     if ( *path != '\0' ) {
689         /* not a directory */
690         strcpy(oldname, path); /* an extra copy for of_rename */
691     } else {
692         isdir = 1;
693         strcpy(oldname, sdir->d_name);
694     }
695
696     /* get the destination directory */
697     if (( ddir = dirsearch( vol, did )) == NULL ) {
698         return( AFPERR_PARAM );
699     }
700     if (( path = cname( vol, ddir, &ibuf )) == NULL ) {
701         return( AFPERR_NOOBJ );
702     }
703     if ( *path != '\0' ) {
704         return( AFPERR_BADTYPE );
705     }
706
707     /* one more place where we know about path type */
708     if ( *ibuf++ != 2 ) {
709         return( AFPERR_PARAM );
710     }
711
712     if (( plen = (unsigned char)*ibuf++ ) != 0 ) {
713         strncpy( newname, ibuf, plen );
714         newname[ plen ] = '\0';
715         if (strlen(newname) != plen) {
716             return( AFPERR_PARAM );
717         }
718     }
719     else {
720         strcpy(newname, oldname);
721     }
722     
723     rc = moveandrename(vol, sdir, oldname, newname, isdir);
724
725     if ( rc == AFP_OK ) {
726 #ifdef DROPKLUDGE
727         if (vol->v_flags & AFPVOL_DROPBOX) {
728             if (retvalue=matchfile2dirperms (newname, vol, did) != AFP_OK) {
729                 return retvalue;
730             }
731         }
732         else
733 #endif /* DROPKLUDGE */
734             if (!isdir) {
735                 char *upath = mtoupath(vol, newname);
736                 int  admode = ad_mode("", 0777);
737
738                 setfilmode(upath, admode, NULL);
739                 setfilmode(ad_path( upath, ADFLAGS_HF ), ad_hf_mode(admode), NULL);
740             }
741         setvoltime(obj, vol );
742     }
743
744 #ifdef DEBUG
745     LOG(log_info, logtype_afpd, "end afp_moveandrename:");
746 #endif /* DEBUG */
747
748     return( rc );
749 }
750
751 int veto_file(const char*veto_str, const char*path)
752 /* given a veto_str like "abc/zxc/" and path "abc", return 1
753  * veto_str should be '/' delimited
754  * if path matches any one of the veto_str elements exactly, then 1 is returned
755  * otherwise, 0 is returned.
756  */
757 {
758     int i;      /* index to veto_str */
759     int j;      /* index to path */
760
761     if ((veto_str == NULL) || (path == NULL))
762         return 0;
763     /*
764     #ifdef DEBUG
765         LOG(log_debug, logtype_afpd, "veto_file \"%s\", \"%s\"", veto_str, path);
766     #endif
767     */
768     for(i=0, j=0; veto_str[i] != '\0'; i++) {
769         if (veto_str[i] == '/') {
770             if ((j>0) && (path[j] == '\0'))
771                 return 1;
772             j = 0;
773         } else {
774             if (veto_str[i] != path[j]) {
775                 while ((veto_str[i] != '/')
776                         && (veto_str[i] != '\0'))
777                     i++;
778                 j = 0;
779                 continue;
780             }
781             j++;
782         }
783     }
784     return 0;
785 }
786