]> arthur.barton.de Git - netatalk.git/blob - etc/afpd/filedir.c
Style police.
[netatalk.git] / etc / afpd / filedir.c
1 /*
2  * $Id: filedir.c,v 1.21 2002-01-19 21:29:55 jmarcus 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_default, "begin matchfile2dirperms:");
75 #endif /* DEBUG */
76
77     if (stat(upath, &st ) < 0)
78         LOG(log_error, logtype_default, "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_default, "matchfile2dirperms: Unable to get directory info.");
83         return( AFPERR_NOOBJ );
84     }
85     else if (stat(".", &sb) < 0) {
86         LOG(log_error, logtype_default,
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_default,
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&0777&~default_options.umask)| S_IRGRP| S_IROTH) < 0)
104             {
105                 LOG(log_error, logtype_default,
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_default,
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_default,
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&0777&~default_options.umask)| S_IRGRP| S_IROTH) < 0)
124             {
125                 LOG(log_error, logtype_default,
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_default,
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_default,
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_default, "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_default, "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 = dirsearch( 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_default, "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     char        *path;
244     u_int16_t   vid, bitmap;
245     int         did, rc;
246
247 #ifdef DEBUG
248     LOG(log_info, logtype_default, "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 (( vol = getvolbyvid( vid )) == NULL ) {
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 = dirsearch( vol, did )) == NULL ) {
267         return( AFPERR_NOOBJ );
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( AFPERR_NOOBJ );
276     }
277
278     if ( stat( mtoupath(vol, path ), &st ) < 0 ) {
279         return( AFPERR_NOOBJ );
280     }
281
282     /*
283      * If ibuf is odd, make it even.
284      */
285     if ((u_long)ibuf & 1 ) {
286         ibuf++;
287     }
288
289     if (S_ISDIR(st.st_mode)) {
290         rc = setdirparams(vol, path, bitmap, ibuf );
291     } else {
292         rc = setfilparams(vol, path, bitmap, ibuf );
293     }
294     if ( rc == AFP_OK ) {
295         setvoltime(obj, vol );
296     }
297
298 #ifdef DEBUG
299     LOG(log_info, logtype_default, "end afp_setfildirparams:");
300 #endif /* DEBUG */
301
302     return( rc );
303 }
304
305 int afp_rename(obj, ibuf, ibuflen, rbuf, rbuflen )
306 AFPObj      *obj;
307 char    *ibuf, *rbuf;
308 int             ibuflen, *rbuflen;
309 {
310     struct adouble      ad;
311     struct stat         st;
312     struct vol          *vol;
313     struct dir          *dir, *odir = NULL;
314     char                *path, *buf, *upath, *newpath;
315     char                *newadpath;
316     u_int32_t           did;
317     int                 plen;
318     u_int16_t           vid;
319 #ifdef CNID_DB
320     cnid_t              id;
321 #endif /* CNID_DB */
322
323 #ifdef DEBUG
324     LOG(log_info, logtype_default, "begin afp_rename:");
325 #endif /* DEBUG */
326
327     *rbuflen = 0;
328     ibuf += 2;
329
330     memcpy( &vid, ibuf, sizeof( vid ));
331     ibuf += sizeof( vid );
332     if (( vol = getvolbyvid( vid )) == NULL ) {
333         return( AFPERR_PARAM );
334     }
335
336     if (vol->v_flags & AFPVOL_RO)
337         return AFPERR_VLOCK;
338
339     memcpy( &did, ibuf, sizeof( did ));
340     ibuf += sizeof( did );
341     if (( dir = dirsearch( vol, did )) == NULL ) {
342         return( AFPERR_NOOBJ );
343     }
344
345     if (( path = cname( vol, dir, &ibuf )) == NULL ) {
346         return( AFPERR_NOOBJ );
347     }
348
349     /* another place where we know about the path type */
350     if ( *ibuf++ != 2 ) {
351         return( AFPERR_PARAM );
352     }
353     plen = (unsigned char) *ibuf++;
354     *( ibuf + plen ) = '\0';
355
356     if ( *path == '\0' ) {
357         if ( curdir->d_parent == NULL ) { /* root directory */
358             return( AFPERR_NORENAME );
359         }
360         odir = curdir;
361         path = curdir->d_name;
362         if ( movecwd( vol, curdir->d_parent ) < 0 ) {
363             return( AFPERR_NOOBJ );
364         }
365     }
366
367 #ifdef notdef
368     if ( strcasecmp( path, ibuf ) == 0 ) {
369         return( AFP_OK );
370     }
371 #endif /* notdef */
372
373     /* if a curdir/newname ofork exists, return busy */
374     if (of_findname(vol, curdir, ibuf))
375         return AFPERR_BUSY;
376
377     /* source == destination. just say okay. */
378     if (strcmp(path, ibuf) == 0)
379         return AFP_OK;
380
381     /* check for illegal characters */
382     if (!wincheck(vol, ibuf))
383         return AFPERR_PARAM;
384
385     newpath = obj->oldtmp;
386     strcpy( newpath, mtoupath(vol, ibuf ));
387
388     if ((vol->v_flags & AFPVOL_NOHEX) && strchr(newpath, '/'))
389         return AFPERR_PARAM;
390
391     if (!validupath(vol, newpath))
392         return AFPERR_EXIST;
393
394     /* check for vetoed filenames */
395     if (veto_file(vol->v_veto, newpath))
396         return AFPERR_EXIST;
397
398     /* the strdiacasecmp deals with case-insensitive, case preserving
399        filesystems */
400     if (stat( newpath, &st ) == 0 && strdiacasecmp(path, ibuf))
401         return( AFPERR_EXIST );
402
403     upath = mtoupath(vol, path);
404
405 #ifdef CNID_DB
406     id = cnid_get(vol->v_db, curdir->d_did, upath, strlen(upath));
407 #endif /* CNID_DB */
408
409     if ( rename( upath, newpath ) < 0 ) {
410         switch ( errno ) {
411         case ENOENT :
412             return( AFPERR_NOOBJ );
413         case EACCES :
414             return( AFPERR_ACCESS );
415         default :
416             return( AFPERR_PARAM );
417         }
418     }
419
420 #ifdef CNID_DB
421     if (stat(newpath, &st) < 0) /* this shouldn't fail */
422         return AFPERR_MISC;
423     cnid_update(vol->v_db, id, &st, curdir->d_did, newpath, strlen(newpath));
424 #endif /* CNID_DB */
425
426     if ( !odir ) {
427         newadpath = obj->newtmp;
428         strcpy( newadpath, ad_path( newpath, 0 ));
429         if ( rename( ad_path( upath, 0 ), newadpath ) < 0 ) {
430             if ( errno == ENOENT ) {    /* no adouble header file */
431                 if (( unlink( newadpath ) < 0 ) && ( errno != ENOENT )) {
432                     return( AFPERR_PARAM );
433                 }
434                 goto out;
435             }
436             return( AFPERR_PARAM );
437         }
438
439         memset(&ad, 0, sizeof(ad));
440         if ( ad_open( newpath, ADFLAGS_HF, O_RDWR|O_CREAT, 0666,
441                       &ad) < 0 ) {
442             return( AFPERR_PARAM );
443         }
444     } else {
445         int isad = 1;
446
447         memset(&ad, 0, sizeof(ad));
448         if ( ad_open( newpath, vol_noadouble(vol)|ADFLAGS_HF|ADFLAGS_DIR,
449                       O_RDWR|O_CREAT, 0666, &ad) < 0 ) {
450             if (!((errno == ENOENT) && vol_noadouble(vol)))
451                 return( AFPERR_PARAM );
452             isad = 0;
453         }
454         if ((buf = realloc( odir->d_name, plen + 1 )) == NULL ) {
455             LOG(log_error, logtype_default, "afp_rename: realloc: %s", strerror(errno) );
456             if (isad) {
457                 ad_flush(&ad, ADFLAGS_HF); /* in case of create */
458                 ad_close(&ad, ADFLAGS_HF);
459             }
460             return AFPERR_MISC;
461         }
462         odir->d_name = buf;
463         strcpy( odir->d_name, ibuf );
464         if (!isad)
465             goto out;
466     }
467
468     ad_setentrylen( &ad, ADEID_NAME, plen );
469     memcpy( ad_entry( &ad, ADEID_NAME ), ibuf, plen );
470     ad_flush( &ad, ADFLAGS_HF );
471     ad_close( &ad, ADFLAGS_HF );
472
473 out:
474     setvoltime(obj, vol );
475
476     /* if it's still open, rename the ofork as well. */
477     if (of_rename(vol, curdir, path, curdir, ibuf) < 0)
478         return AFPERR_MISC;
479
480 #ifdef DEBUG
481     LOG(log_info, logtype_default, "end afp_rename:");
482 #endif /* DEBUG */
483
484     return( AFP_OK );
485 }
486
487
488 int afp_delete(obj, ibuf, ibuflen, rbuf, rbuflen )
489 AFPObj      *obj;
490 char    *ibuf, *rbuf;
491 int             ibuflen, *rbuflen;
492 {
493     struct vol          *vol;
494     struct dir          *dir;
495     char                *path, *upath;
496     int                 did, rc;
497     u_int16_t           vid;
498
499 #ifdef DEBUG
500     LOG(log_info, logtype_default, "begin afp_delete:");
501 #endif /* DEBUG */ 
502
503     *rbuflen = 0;
504     ibuf += 2;
505
506     memcpy( &vid, ibuf, sizeof( vid ));
507     ibuf += sizeof( vid );
508     if (( vol = getvolbyvid( vid )) == NULL ) {
509         return( AFPERR_PARAM );
510     }
511
512     if (vol->v_flags & AFPVOL_RO)
513         return AFPERR_VLOCK;
514
515     memcpy( &did, ibuf, sizeof( did ));
516     ibuf += sizeof( int );
517     if (( dir = dirsearch( vol, did )) == NULL ) {
518         return( AFPERR_NOOBJ );
519     }
520
521     if (( path = cname( vol, dir, &ibuf )) == NULL ) {
522         return( AFPERR_NOOBJ );
523     }
524
525     if ( *path == '\0' ) {
526         rc = deletecurdir( vol, obj->oldtmp, AFPOBJ_TMPSIZ);
527     } else if (of_findname(vol, curdir, path)) {
528         rc = AFPERR_BUSY;
529     } else if ((rc = deletefile( upath = mtoupath(vol, path ))) == AFP_OK) {
530 #ifdef CNID_DB /* get rid of entry */
531         cnid_t id = cnid_get(vol->v_db, curdir->d_did, upath, strlen(upath));
532         cnid_delete(vol->v_db, id);
533 #endif /* CNID_DB */
534     }
535     if ( rc == AFP_OK ) {
536         setvoltime(obj, vol );
537     }
538
539 #ifdef DEBUG
540     LOG(log_info, logtype_default, "end afp_delete:");
541 #endif /* DEBUG */
542
543     return( rc );
544 }
545
546 char *ctoupath( vol, dir, name )
547 const struct vol        *vol;
548 struct dir      *dir;
549 char    *name;
550 {
551     struct dir  *d;
552     static char path[ MAXPATHLEN + 1];
553     char        *p, *u;
554     int         len;
555
556     p = path + sizeof( path ) - 1;
557     *p = '\0';
558     u = mtoupath(vol, name );
559     len = strlen( u );
560     p -= len;
561     strncpy( p, u, len );
562     for ( d = dir; d->d_parent; d = d->d_parent ) {
563         *--p = '/';
564         u = mtoupath(vol, d->d_name );
565         len = strlen( u );
566         p -= len;
567         strncpy( p, u, len );
568     }
569     *--p = '/';
570     len = strlen( vol->v_path );
571     p -= len;
572     strncpy( p, vol->v_path, len );
573
574     return( p );
575 }
576
577
578 int afp_moveandrename(obj, ibuf, ibuflen, rbuf, rbuflen )
579 AFPObj      *obj;
580 char    *ibuf, *rbuf;
581 int             ibuflen, *rbuflen;
582 {
583     struct vol  *vol;
584     struct dir  *sdir, *ddir, *odir = NULL;
585     struct stat st;
586     char        *oldname, *newname;
587     char        *path, *p, *upath;
588     int         did, rc;
589     int         plen;
590     u_int16_t   vid;
591 #ifdef CNID_DB
592     cnid_t      id;
593 #endif /* CNID_DB */
594 #ifdef DROPKLUDGE
595     int         retvalue;
596 #endif /* DROPKLUDGE */
597
598 #ifdef DEBUG
599     LOG(log_info, logtype_default, "begin afp_moveandrename:");
600 #endif /* DEBUG */
601
602     *rbuflen = 0;
603     ibuf += 2;
604
605     memcpy( &vid, ibuf, sizeof( vid ));
606     ibuf += sizeof( vid );
607     if (( vol = getvolbyvid( vid )) == NULL ) {
608         return( AFPERR_PARAM );
609     }
610
611     if (vol->v_flags & AFPVOL_RO)
612         return AFPERR_VLOCK;
613
614     /* source did followed by dest did */
615     memcpy( &did, ibuf, sizeof( did ));
616     ibuf += sizeof( int );
617     if (( sdir = dirsearch( vol, did )) == NULL ) {
618         return( AFPERR_PARAM );
619     }
620
621     memcpy( &did, ibuf, sizeof( did ));
622     ibuf += sizeof( int );
623
624     /* source pathname */
625     if (( path = cname( vol, sdir, &ibuf )) == NULL ) {
626         return( AFPERR_NOOBJ );
627     }
628
629     sdir = curdir;
630     newname = obj->newtmp;
631     oldname = obj->oldtmp;
632     if ( *path != '\0' ) {
633         /* not a directory */
634         strcpy(newname, path);
635         strcpy(oldname, path); /* an extra copy for of_rename */
636 #ifdef CNID_DB
637         p = mtoupath(vol, path);
638         id = cnid_get(vol->v_db, sdir->d_did, p, strlen(p));
639 #endif /* CNID_DB */
640         p = ctoupath( vol, sdir, newname );
641     } else {
642         odir = curdir;
643         strcpy( newname, odir->d_name );
644         strcpy(oldname, odir->d_name);
645         p = ctoupath( vol, odir->d_parent, newname );
646 #ifdef CNID_DB
647         id = curdir->d_did; /* we already have the CNID */
648 #endif /* CNID_DB */
649     }
650     /*
651      * p now points to the full pathname of the source fs object.
652      */
653
654     /* get the destination directory */
655     if (( ddir = dirsearch( vol, did )) == NULL ) {
656         return( AFPERR_PARAM );
657     }
658     if (( path = cname( vol, ddir, &ibuf )) == NULL ) {
659         return( AFPERR_NOOBJ );
660     }
661     if ( *path != '\0' ) {
662         return( AFPERR_BADTYPE );
663     }
664
665     /* one more place where we know about path type */
666     if ( *ibuf++ != 2 ) {
667         return( AFPERR_PARAM );
668     }
669
670     if (( plen = (unsigned char)*ibuf++ ) != 0 ) {
671         strncpy( newname, ibuf, plen );
672         newname[ plen ] = '\0';
673     }
674
675     /* check for illegal characters */
676     if (!wincheck(vol, newname))
677         return AFPERR_PARAM;
678
679     upath = mtoupath(vol, newname);
680
681     if ((vol->v_flags & AFPVOL_NOHEX) && strchr(upath, '/'))
682         return AFPERR_PARAM;
683
684     if (!validupath(vol, upath))
685         return AFPERR_EXIST;
686
687     /* check for vetoed filenames */
688     if (veto_file(vol->v_veto, upath))
689         return AFPERR_EXIST;
690
691     /* source == destination. we just silently accept this. */
692     if (curdir == sdir) {
693         if (strcmp(oldname, newname) == 0)
694             return AFP_OK;
695
696         /* deal with case insensitive, case-preserving filesystems. */
697         if ((stat(upath, &st) == 0) && strdiacasecmp(oldname, newname))
698             return AFPERR_EXIST;
699
700     } else if (stat(upath, &st ) == 0)
701         return( AFPERR_EXIST );
702
703     if ( !odir ) {
704         if (of_findname(vol, curdir, newname)) {
705             rc = AFPERR_BUSY;
706         } else if ((rc = renamefile( p, upath, newname,
707                                      vol_noadouble(vol) )) == AFP_OK) {
708             /* if it's still open, rename the ofork as well. */
709             rc = of_rename(vol, sdir, oldname, curdir, newname);
710         }
711     } else {
712         rc = renamedir(p, upath, odir, curdir, newname, vol_noadouble(vol));
713     }
714
715 #ifdef DROPKLUDGE
716     if (vol->v_flags & AFPVOL_DROPBOX) {
717         if (retvalue=matchfile2dirperms (newname, vol, did) != AFP_OK) {
718             return retvalue;
719         }
720     }
721 #endif /* DROPKLUDGE */
722
723     if ( rc == AFP_OK ) {
724 #ifdef CNID_DB
725         /* renaming may have moved the file/dir across a filesystem */
726         if (stat(upath, &st) < 0)
727             return AFPERR_MISC;
728
729         /* fix up the catalog entry */
730         cnid_update(vol->v_db, id, &st, curdir->d_did, upath, strlen(upath));
731 #endif /* CNID_DB */
732         setvoltime(obj, vol );
733     }
734
735 #ifdef DEBUG
736     LOG(log_info, logtype_default, "end afp_moveandrename:");
737 #endif /* DEBUG */
738
739     return( rc );
740 }
741
742 int veto_file(const char*veto_str, const char*path)
743 /* given a veto_str like "abc/zxc/" and path "abc", return 1
744  * veto_str should be '/' delimited
745  * if path matches any one of the veto_str elements exactly, then 1 is returned
746  * otherwise, 0 is returned.
747  */
748 {
749     int i;      /* index to veto_str */
750     int j;      /* index to path */
751
752     if ((veto_str == NULL) || (path == NULL))
753         return 0;
754     /*
755     #ifdef DEBUG
756         LOG(log_debug, logtype_default, "veto_file \"%s\", \"%s\"", veto_str, path);
757     #endif
758     */
759     for(i=0, j=0; veto_str[i] != '\0'; i++) {
760         if (veto_str[i] == '/') {
761             if ((j>0) && (path[j] == '\0'))
762                 return 1;
763             j = 0;
764         } else {
765             if (veto_str[i] != path[j]) {
766                 while ((veto_str[i] != '/')
767                         && (veto_str[i] != '\0'))
768                     i++;
769                 j = 0;
770                 continue;
771             }
772             j++;
773         }
774     }
775     return 0;
776 }
777