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