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