]> arthur.barton.de Git - netatalk.git/blob - etc/afpd/filedir.c
fa3e5f617d1df400769cd5822334afee46fae40b
[netatalk.git] / etc / afpd / filedir.c
1 /*
2  * $Id: filedir.c,v 1.69.2.2 2010-02-01 16:13:52 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 (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         LOG(log_debug, logtype_afpd, "getfildirparams: !s_path->st_valid");
183         /* it's a dir and it should be there
184          * because we chdir in it in cname or
185          * it's curdir (maybe deleted, but then we can't know).
186          * So we need to try harder.
187          */
188         of_statdir(vol, s_path);
189     }
190     if ( s_path->st_errno != 0 ) {
191         if (afp_errno != AFPERR_ACCESS) {
192             LOG(log_debug, logtype_afpd, "getfildirparams: s_path->st_errno != 0");
193             return( AFPERR_NOOBJ );
194         }
195     }
196
197
198     buflen = 0;
199     if (S_ISDIR(st->st_mode)) {
200         if (dbitmap) {
201             dir = s_path->d_dir;
202             if (!dir)
203                 return AFPERR_NOOBJ;
204
205             ret = getdirparams(vol, dbitmap, s_path, dir,
206                                rbuf + 3 * sizeof( u_int16_t ), &buflen );
207             if (ret != AFP_OK )
208                 return( ret );
209         }
210         /* this is a directory */
211         *(rbuf + 2 * sizeof( u_int16_t )) = (char) FILDIRBIT_ISDIR;
212     } else {
213         if (fbitmap && AFP_OK != (ret = getfilparams(vol, fbitmap, s_path, curdir,
214                                                      rbuf + 3 * sizeof( u_int16_t ), &buflen )) ) {
215             return( ret );
216         }
217         /* this is a file */
218         *(rbuf + 2 * sizeof( u_int16_t )) = FILDIRBIT_ISFILE;
219     }
220     *rbuflen = buflen + 3 * sizeof( u_int16_t );
221     fbitmap = htons( fbitmap );
222     memcpy( rbuf, &fbitmap, sizeof( fbitmap ));
223     rbuf += sizeof( fbitmap );
224     dbitmap = htons( dbitmap );
225     memcpy( rbuf, &dbitmap, sizeof( dbitmap ));
226     rbuf += sizeof( dbitmap ) + sizeof( u_char );
227     *rbuf = 0;
228
229     return( AFP_OK );
230 }
231
232 int afp_setfildirparams(AFPObj *obj, char *ibuf, size_t ibuflen _U_, char *rbuf _U_, size_t *rbuflen)
233 {
234     struct stat *st;
235     struct vol  *vol;
236     struct dir  *dir;
237     struct path *path;
238     u_int16_t   vid, bitmap;
239     int     did, rc;
240
241     *rbuflen = 0;
242     ibuf += 2;
243     memcpy( &vid, ibuf, sizeof(vid));
244     ibuf += sizeof( vid );
245
246     if (NULL == ( vol = getvolbyvid( vid )) ) {
247         return( AFPERR_PARAM );
248     }
249
250     if (vol->v_flags & AFPVOL_RO)
251         return AFPERR_VLOCK;
252
253     memcpy( &did, ibuf, sizeof( did));
254     ibuf += sizeof( did);
255
256     if (NULL == ( dir = dirlookup( vol, did )) ) {
257         return afp_errno;
258     }
259
260     memcpy( &bitmap, ibuf, sizeof( bitmap ));
261     bitmap = ntohs( bitmap );
262     ibuf += sizeof( bitmap );
263
264     if (NULL == ( path = cname( vol, dir, &ibuf ))) {
265         return get_afp_errno(AFPERR_NOOBJ);
266     }
267
268     st   = &path->st;
269     if (!path->st_valid) {
270         /* it's a dir and it should be there
271          * because we chdir in it in cname
272          */
273         of_statdir(vol, path);
274     }
275
276     if ( path->st_errno != 0 ) {
277         if (afp_errno != AFPERR_ACCESS)
278             return( AFPERR_NOOBJ );
279     }
280     /*
281      * If ibuf is odd, make it even.
282      */
283     if ((u_long)ibuf & 1 ) {
284         ibuf++;
285     }
286
287     if (S_ISDIR(st->st_mode)) {
288         rc = setdirparams(vol, path, bitmap, ibuf );
289     } else {
290         rc = setfilparams(vol, path, bitmap, ibuf );
291     }
292     if ( rc == AFP_OK ) {
293         setvoltime(obj, vol );
294     }
295
296     return( rc );
297 }
298
299 /* --------------------------------------------
300    Factorise some checks on a pathname
301 */
302 int check_name(const struct vol *vol, char *name)
303 {
304     /* check for illegal characters in the unix filename */
305     if (!wincheck(vol, name))
306         return AFPERR_PARAM;
307
308     if ((vol->v_flags & AFPVOL_NOHEX) && strchr(name, '/'))
309         return AFPERR_PARAM;
310
311     if (!vol->vfs->vfs_validupath(vol, name)) {
312         LOG(log_error, logtype_afpd, "check_name: illegal name: '%s'", name);
313         return AFPERR_EXIST;
314     }
315
316     /* check for vetoed filenames */
317     if (veto_file(vol->v_veto, name))
318         return AFPERR_EXIST;
319     return 0;
320 }
321
322 /* -------------------------
323    move and rename sdir:oldname to curdir:newname in volume vol
324
325    special care is needed for lock
326 */
327 static int moveandrename(const struct vol *vol, struct dir *sdir, char *oldname, char *newname, int isdir)
328 {
329     char            *p;
330     char            *upath;
331     int             rc;
332     struct stat     *st, nst;
333     int             adflags;
334     struct adouble  ad;
335     struct adouble  *adp;
336     struct ofork    *opened = NULL;
337     struct path         path;
338     cnid_t      id;
339
340     ad_init(&ad, vol->v_adouble, vol->v_ad_options);
341     adp = &ad;
342     adflags = 0;
343
344     if (!isdir) {
345         p = mtoupath(vol, oldname, sdir->d_did, utf8_encoding());
346         if (!p) {
347             return AFPERR_PARAM; /* can't convert */
348         }
349         id = cnid_get(vol->v_cdb, sdir->d_did, p, strlen(p));
350         p = ctoupath( vol, sdir, oldname );
351         if (!p) {
352             return AFPERR_PARAM; /* pathname too long */
353         }
354         path.st_valid = 0;
355         path.u_name = p;
356         if ((opened = of_findname(&path))) {
357             /* reuse struct adouble so it won't break locks */
358             adp = opened->of_ad;
359         }
360     }
361     else {
362         id = sdir->d_did; /* we already have the CNID */
363         p = ctoupath( vol, dirlookup(vol, sdir->d_pdid), oldname );
364         if (!p) {
365             return AFPERR_PARAM;
366         }
367         adflags = ADFLAGS_DIR;
368     }
369     /*
370      * p now points to the full pathname of the source fs object.
371      *
372      * we are in the dest folder so we need to use p for ad_open
373      */
374
375     if (!ad_metadata(p, adflags, adp)) {
376         u_int16_t bshort;
377
378         ad_getattr(adp, &bshort);
379         ad_close_metadata( adp);
380         if ((bshort & htons(ATTRBIT_NORENAME)))
381             return(AFPERR_OLOCK);
382     }
383
384     if (NULL == (upath = mtoupath(vol, newname, curdir->d_did, utf8_encoding()))){
385         return AFPERR_PARAM;
386     }
387     path.u_name = upath;
388     st = &path.st;
389     if (0 != (rc = check_name(vol, upath))) {
390         return  rc;
391     }
392
393     /* source == destination. we just silently accept this. */
394     if ((!isdir && curdir == sdir) || (isdir && curdir->d_did == sdir->d_pdid)) {
395         if (strcmp(oldname, newname) == 0)
396             return AFP_OK;
397
398         if (stat(upath, st) == 0 || caseenumerate(vol, &path, curdir) == 0) {
399             if (!stat(p, &nst) && !(nst.st_dev == st->st_dev && nst.st_ino == st->st_ino) ) {
400                 /* not the same file */
401                 return AFPERR_EXIST;
402             }
403             errno = 0;
404         }
405     } else if (stat(upath, st ) == 0 || caseenumerate(vol, &path, curdir) == 0)
406         return AFPERR_EXIST;
407
408     if ( !isdir ) {
409         path.st_valid = 1;
410         path.st_errno = errno;
411         if (of_findname(&path)) {
412             rc = AFPERR_EXIST; /* was AFPERR_BUSY; */
413         } else {
414             rc = renamefile(vol, p, upath, newname, adp );
415             if (rc == AFP_OK)
416                 of_rename(vol, opened, sdir, oldname, curdir, newname);
417         }
418     } else {
419         rc = renamedir(vol, p, upath, sdir, curdir, newname);
420     }
421     if ( rc == AFP_OK && id ) {
422         /* renaming may have moved the file/dir across a filesystem */
423         if (stat(upath, st) < 0)
424             return AFPERR_MISC;
425
426         /* fix up the catalog entry */
427         cnid_update(vol->v_cdb, id, st, curdir->d_did, upath, strlen(upath));
428     }
429
430     return rc;
431 }
432
433 /* -------------------------------------------- */
434 int afp_rename(AFPObj *obj, char *ibuf, size_t ibuflen _U_, char *rbuf _U_, size_t *rbuflen)
435 {
436     struct vol  *vol;
437     struct dir  *sdir;
438     char        *oldname, *newname;
439     struct path *path;
440     u_int32_t   did;
441     int         plen;
442     u_int16_t   vid;
443     int         isdir = 0;
444     int         rc;
445
446     *rbuflen = 0;
447     ibuf += 2;
448
449     memcpy( &vid, ibuf, sizeof( vid ));
450     ibuf += sizeof( vid );
451     if (NULL == ( vol = getvolbyvid( vid )) ) {
452         return( AFPERR_PARAM );
453     }
454
455     if (vol->v_flags & AFPVOL_RO)
456         return AFPERR_VLOCK;
457
458     memcpy( &did, ibuf, sizeof( did ));
459     ibuf += sizeof( did );
460     if (NULL == ( sdir = dirlookup( vol, did )) ) {
461         return afp_errno;
462     }
463
464     /* source pathname */
465     if (NULL == ( path = cname( vol, sdir, &ibuf )) ) {
466         return get_afp_errno(AFPERR_NOOBJ);
467     }
468
469     sdir = curdir;
470     newname = obj->newtmp;
471     oldname = obj->oldtmp;
472     isdir = path_isadir(path);
473     if ( *path->m_name != '\0' ) {
474         strcpy(oldname, path->m_name); /* an extra copy for of_rename */
475         if (isdir) {
476             /* curdir parent dir, need to move sdir back */
477             sdir = path->d_dir;
478         }
479     }
480     else {
481         if ( sdir->d_did == DIRDID_ROOT ) { /* root directory */
482             return( AFPERR_NORENAME );
483         }
484         /* move to destination dir */
485         if ( movecwd( vol, dirlookup(vol, sdir->d_pdid) ) < 0 ) {
486             return afp_errno;
487         }
488         memcpy(oldname, cfrombstring(sdir->d_m_name), blength(sdir->d_m_name) +1);
489     }
490
491     /* another place where we know about the path type */
492     if ((plen = copy_path_name(vol, newname, ibuf)) < 0) {
493         return( AFPERR_PARAM );
494     }
495
496     if (!plen) {
497         return AFP_OK; /* newname == oldname same dir */
498     }
499
500     rc = moveandrename(vol, sdir, oldname, newname, isdir);
501
502     if ( rc == AFP_OK ) {
503         setvoltime(obj, vol );
504     }
505
506     return( rc );
507 }
508
509 /* ------------------------------- */
510 int afp_delete(AFPObj *obj, char *ibuf, size_t ibuflen _U_, char *rbuf _U_, size_t *rbuflen)
511 {
512     struct vol      *vol;
513     struct dir      *dir;
514     struct path         *s_path;
515     char        *upath;
516     int         did, rc;
517     u_int16_t       vid;
518
519     *rbuflen = 0;
520     ibuf += 2;
521
522     memcpy( &vid, ibuf, sizeof( vid ));
523     ibuf += sizeof( vid );
524     if (NULL == ( vol = getvolbyvid( vid )) ) {
525         return( AFPERR_PARAM );
526     }
527
528     if (vol->v_flags & AFPVOL_RO)
529         return AFPERR_VLOCK;
530
531     memcpy( &did, ibuf, sizeof( did ));
532     ibuf += sizeof( int );
533
534     if (NULL == ( dir = dirlookup( vol, did )) ) {
535         return afp_errno;
536     }
537
538     if (NULL == ( s_path = cname( vol, dir, &ibuf )) ) {
539         return get_afp_errno(AFPERR_NOOBJ);
540     }
541
542     upath = s_path->u_name;
543     if ( path_isadir( s_path) ) {
544         if (*s_path->m_name != '\0' || curdir->d_did == DIRDID_ROOT)
545             rc = AFPERR_ACCESS;
546         else
547             rc = deletecurdir( vol);
548     } else if (of_findname(s_path)) {
549         rc = AFPERR_BUSY;
550     } else {
551         /* it's a file st_valid should always be true
552          * only test for ENOENT because EACCES needs
553          * to read meta data in deletefile
554          */
555         if (s_path->st_valid && s_path->st_errno == ENOENT) {
556             rc = AFPERR_NOOBJ;
557         }
558         else {
559             rc = deletefile(vol, upath, 1);
560         }
561     }
562     if ( rc == AFP_OK ) {
563         curdir->offcnt--;
564         setvoltime(obj, vol );
565     }
566
567     return( rc );
568 }
569 /* ------------------------ */
570 char *absupath(const struct vol *vol, struct dir *dir, char *u)
571 {
572     static char pathbuf[MAXPATHLEN + 1];
573     bstring path;
574
575     if (u == NULL || dir == NULL || vol == NULL)
576         return NULL;
577
578     if ((path = bstrcpy(dir->d_fullpath)) == NULL)
579         return NULL;
580     if (bcatcstr(path, "/") != BSTR_OK)
581         return NULL;
582     if (bcatcstr(path, u) != BSTR_OK)
583         return NULL;
584     if (path->slen > MAXPATHLEN)
585         return NULL;
586
587     LOG(log_debug, logtype_afpd, "absupath: %s", cfrombstring(path));
588
589     strncpy(pathbuf, cfrombstring(path), blength(path) + 1);
590     bdestroy(path);
591
592     return(pathbuf);
593 }
594
595 char *ctoupath(const struct vol *vol, struct dir *dir, char *name)
596 {
597     if (vol == NULL || dir == NULL || name == NULL)
598         return NULL;
599     return absupath(vol, dir, mtoupath(vol, name, dir->d_did, utf8_encoding()));
600 }
601
602 /* ------------------------- */
603 int afp_moveandrename(AFPObj *obj, char *ibuf, size_t ibuflen _U_, char *rbuf _U_, size_t *rbuflen)
604 {
605     struct vol  *vol;
606     struct dir  *sdir, *ddir;
607     int         isdir;
608     char    *oldname, *newname;
609     struct path *path;
610     int     did;
611     int     pdid;
612     int         plen;
613     u_int16_t   vid;
614     int         rc;
615 #ifdef DROPKLUDGE
616     int     retvalue;
617 #endif /* DROPKLUDGE */
618
619     *rbuflen = 0;
620     ibuf += 2;
621
622     memcpy( &vid, ibuf, sizeof( vid ));
623     ibuf += sizeof( vid );
624     if (NULL == ( vol = getvolbyvid( vid )) ) {
625         return( AFPERR_PARAM );
626     }
627
628     if (vol->v_flags & AFPVOL_RO)
629         return AFPERR_VLOCK;
630
631     /* source did followed by dest did */
632     memcpy( &did, ibuf, sizeof( did ));
633     ibuf += sizeof( int );
634     if (NULL == ( sdir = dirlookup( vol, did )) ) {
635         return afp_errno; /* was AFPERR_PARAM */
636     }
637
638     memcpy( &did, ibuf, sizeof( did ));
639     ibuf += sizeof( int );
640
641     /* source pathname */
642     if (NULL == ( path = cname( vol, sdir, &ibuf )) ) {
643         return get_afp_errno(AFPERR_NOOBJ);
644     }
645
646     sdir = curdir;
647     newname = obj->newtmp;
648     oldname = obj->oldtmp;
649
650     isdir = path_isadir(path);
651     if ( *path->m_name != '\0' ) {
652         if (isdir) {
653             sdir = path->d_dir;
654         }
655         strcpy(oldname, path->m_name); /* an extra copy for of_rename */
656     } else {
657         memcpy(oldname, cfrombstring(sdir->d_m_name), blength(sdir->d_m_name) + 1);
658     }
659
660     /* get the destination directory */
661     if (NULL == ( ddir = dirlookup( vol, did )) ) {
662         return afp_errno; /*  was AFPERR_PARAM */
663     }
664     if (NULL == ( path = cname( vol, ddir, &ibuf ))) {
665         return( AFPERR_NOOBJ );
666     }
667     pdid = curdir->d_did;
668     if ( *path->m_name != '\0' ) {
669         return path_error(path, AFPERR_NOOBJ);
670     }
671
672     /* one more place where we know about path type */
673     if ((plen = copy_path_name(vol, newname, ibuf)) < 0) {
674         return( AFPERR_PARAM );
675     }
676
677     if (!plen) {
678         strcpy(newname, oldname);
679     }
680
681     LOG(log_debug, logtype_afpd, "afp_move: {oldname:'%s', newname:'%s', isdir:%u}",
682         oldname, newname, isdir);
683     rc = moveandrename(vol, sdir, oldname, newname, isdir);
684
685     if ( rc == AFP_OK ) {
686         char *upath = mtoupath(vol, newname, pdid, utf8_encoding());
687
688         if (NULL == upath) {
689             return AFPERR_PARAM;
690         }
691         curdir->offcnt++;
692         sdir->offcnt--;
693 #ifdef DROPKLUDGE
694         if (vol->v_flags & AFPVOL_DROPBOX) {
695             /* FIXME did is not always the source id */
696             if ((retvalue=matchfile2dirperms (upath, vol, did)) != AFP_OK) {
697                 return retvalue;
698             }
699         }
700         else
701 #endif /* DROPKLUDGE */
702             /* if unix priv don't try to match perm with dest folder */
703             if (!isdir && !vol_unix_priv(vol)) {
704                 int  admode = ad_mode("", 0777) | vol->v_fperm;
705
706                 setfilmode(upath, admode, NULL, vol->v_umask);
707                 vol->vfs->vfs_setfilmode(vol, upath, admode, NULL);
708             }
709         setvoltime(obj, vol );
710     }
711
712     return( rc );
713 }
714
715 int veto_file(const char*veto_str, const char*path)
716 /* given a veto_str like "abc/zxc/" and path "abc", return 1
717  * veto_str should be '/' delimited
718  * if path matches any one of the veto_str elements exactly, then 1 is returned
719  * otherwise, 0 is returned.
720  */
721 {
722     int i;  /* index to veto_str */
723     int j;  /* index to path */
724
725     if ((veto_str == NULL) || (path == NULL))
726         return 0;
727
728     for(i=0, j=0; veto_str[i] != '\0'; i++) {
729         if (veto_str[i] == '/') {
730             if ((j>0) && (path[j] == '\0')) {
731                 LOG(log_debug, logtype_afpd, "vetoed file:'%s'", path);
732                 return 1;
733             }
734             j = 0;
735         } else {
736             if (veto_str[i] != path[j]) {
737                 while ((veto_str[i] != '/')
738                        && (veto_str[i] != '\0'))
739                     i++;
740                 j = 0;
741                 continue;
742             }
743             j++;
744         }
745     }
746     return 0;
747 }
748