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