]> arthur.barton.de Git - netatalk.git/blob - etc/afpd/filedir.c
dirlookup by recursion, not through db lookups
[netatalk.git] / etc / afpd / filedir.c
1 /*
2  * $Id: filedir.c,v 1.69.2.3 2010-02-04 14:34:31 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         /* 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
323    special care is needed for lock
324 */
325 static int moveandrename(const struct vol *vol, struct dir *sdir, char *oldname, char *newname, int isdir)
326 {
327     char            *p;
328     char            *upath;
329     int             rc;
330     struct stat     *st, nst;
331     int             adflags;
332     struct adouble  ad;
333     struct adouble  *adp;
334     struct ofork    *opened = NULL;
335     struct path         path;
336     cnid_t      id;
337
338     ad_init(&ad, vol->v_adouble, vol->v_ad_options);
339     adp = &ad;
340     adflags = 0;
341
342     if (!isdir) {
343         p = mtoupath(vol, oldname, sdir->d_did, utf8_encoding());
344         if (!p) {
345             return AFPERR_PARAM; /* can't convert */
346         }
347         id = cnid_get(vol->v_cdb, sdir->d_did, p, strlen(p));
348         p = ctoupath( vol, sdir, oldname );
349         if (!p) {
350             return AFPERR_PARAM; /* pathname too long */
351         }
352         path.st_valid = 0;
353         path.u_name = p;
354         if ((opened = of_findname(&path))) {
355             /* reuse struct adouble so it won't break locks */
356             adp = opened->of_ad;
357         }
358     }
359     else {
360         id = sdir->d_did; /* we already have the CNID */
361         p = ctoupath( vol, dirlookup(vol, sdir->d_pdid), oldname );
362         if (!p) {
363             return AFPERR_PARAM;
364         }
365         adflags = ADFLAGS_DIR;
366     }
367     /*
368      * p now points to the full pathname of the source fs object.
369      *
370      * we are in the dest folder so we need to use p for ad_open
371      */
372
373     if (!ad_metadata(p, adflags, adp)) {
374         u_int16_t bshort;
375
376         ad_getattr(adp, &bshort);
377         ad_close_metadata( adp);
378         if ((bshort & htons(ATTRBIT_NORENAME)))
379             return(AFPERR_OLOCK);
380     }
381
382     if (NULL == (upath = mtoupath(vol, newname, curdir->d_did, utf8_encoding()))){
383         return AFPERR_PARAM;
384     }
385     path.u_name = upath;
386     st = &path.st;
387     if (0 != (rc = check_name(vol, upath))) {
388         return  rc;
389     }
390
391     /* source == destination. we just silently accept this. */
392     if ((!isdir && curdir == sdir) || (isdir && curdir->d_did == sdir->d_pdid)) {
393         if (strcmp(oldname, newname) == 0)
394             return AFP_OK;
395
396         if (stat(upath, st) == 0 || caseenumerate(vol, &path, curdir) == 0) {
397             if (!stat(p, &nst) && !(nst.st_dev == st->st_dev && nst.st_ino == st->st_ino) ) {
398                 /* not the same file */
399                 return AFPERR_EXIST;
400             }
401             errno = 0;
402         }
403     } else if (stat(upath, st ) == 0 || caseenumerate(vol, &path, curdir) == 0)
404         return AFPERR_EXIST;
405
406     if ( !isdir ) {
407         path.st_valid = 1;
408         path.st_errno = errno;
409         if (of_findname(&path)) {
410             rc = AFPERR_EXIST; /* was AFPERR_BUSY; */
411         } else {
412             rc = renamefile(vol, p, upath, newname, adp );
413             if (rc == AFP_OK)
414                 of_rename(vol, opened, sdir, oldname, curdir, newname);
415         }
416     } else {
417         rc = renamedir(vol, p, upath, sdir, curdir, newname);
418     }
419     if ( rc == AFP_OK && id ) {
420         /* renaming may have moved the file/dir across a filesystem */
421         if (stat(upath, st) < 0)
422             return AFPERR_MISC;
423
424         /* fix up the catalog entry */
425         cnid_update(vol->v_cdb, id, st, curdir->d_did, upath, strlen(upath));
426     }
427
428     return rc;
429 }
430
431 /* -------------------------------------------- */
432 int afp_rename(AFPObj *obj, char *ibuf, size_t ibuflen _U_, char *rbuf _U_, size_t *rbuflen)
433 {
434     struct vol  *vol;
435     struct dir  *sdir;
436     char        *oldname, *newname;
437     struct path *path;
438     u_int32_t   did;
439     int         plen;
440     u_int16_t   vid;
441     int         isdir = 0;
442     int         rc;
443
444     *rbuflen = 0;
445     ibuf += 2;
446
447     memcpy( &vid, ibuf, sizeof( vid ));
448     ibuf += sizeof( vid );
449     if (NULL == ( vol = getvolbyvid( vid )) ) {
450         return( AFPERR_PARAM );
451     }
452
453     if (vol->v_flags & AFPVOL_RO)
454         return AFPERR_VLOCK;
455
456     memcpy( &did, ibuf, sizeof( did ));
457     ibuf += sizeof( did );
458     if (NULL == ( sdir = dirlookup( vol, did )) ) {
459         return afp_errno;
460     }
461
462     /* source pathname */
463     if (NULL == ( path = cname( vol, sdir, &ibuf )) ) {
464         return get_afp_errno(AFPERR_NOOBJ);
465     }
466
467     sdir = curdir;
468     newname = obj->newtmp;
469     oldname = obj->oldtmp;
470     isdir = path_isadir(path);
471     if ( *path->m_name != '\0' ) {
472         strcpy(oldname, path->m_name); /* an extra copy for of_rename */
473         if (isdir) {
474             /* curdir parent dir, need to move sdir back */
475             sdir = path->d_dir;
476         }
477     }
478     else {
479         if ( sdir->d_did == DIRDID_ROOT ) { /* root directory */
480             return( AFPERR_NORENAME );
481         }
482         /* move to destination dir */
483         if ( movecwd( vol, dirlookup(vol, sdir->d_pdid) ) < 0 ) {
484             return afp_errno;
485         }
486         memcpy(oldname, cfrombstring(sdir->d_m_name), blength(sdir->d_m_name) +1);
487     }
488
489     /* another place where we know about the path type */
490     if ((plen = copy_path_name(vol, newname, ibuf)) < 0) {
491         return( AFPERR_PARAM );
492     }
493
494     if (!plen) {
495         return AFP_OK; /* newname == oldname same dir */
496     }
497
498     rc = moveandrename(vol, sdir, oldname, newname, isdir);
499
500     if ( rc == AFP_OK ) {
501         setvoltime(obj, vol );
502     }
503
504     return( rc );
505 }
506
507 /* ------------------------------- */
508 int afp_delete(AFPObj *obj, char *ibuf, size_t ibuflen _U_, char *rbuf _U_, size_t *rbuflen)
509 {
510     struct vol      *vol;
511     struct dir      *dir;
512     struct path         *s_path;
513     char        *upath;
514     int         did, rc;
515     u_int16_t       vid;
516
517     *rbuflen = 0;
518     ibuf += 2;
519
520     memcpy( &vid, ibuf, sizeof( vid ));
521     ibuf += sizeof( vid );
522     if (NULL == ( vol = getvolbyvid( vid )) ) {
523         return( AFPERR_PARAM );
524     }
525
526     if (vol->v_flags & AFPVOL_RO)
527         return AFPERR_VLOCK;
528
529     memcpy( &did, ibuf, sizeof( did ));
530     ibuf += sizeof( int );
531
532     if (NULL == ( dir = dirlookup( vol, did )) ) {
533         return afp_errno;
534     }
535
536     if (NULL == ( s_path = cname( vol, dir, &ibuf )) ) {
537         return get_afp_errno(AFPERR_NOOBJ);
538     }
539
540     upath = s_path->u_name;
541     if ( path_isadir( s_path) ) {
542         if (*s_path->m_name != '\0' || curdir->d_did == DIRDID_ROOT)
543             rc = AFPERR_ACCESS;
544         else
545             rc = deletecurdir( vol);
546     } else if (of_findname(s_path)) {
547         rc = AFPERR_BUSY;
548     } else {
549         /* it's a file st_valid should always be true
550          * only test for ENOENT because EACCES needs
551          * to read meta data in deletefile
552          */
553         if (s_path->st_valid && s_path->st_errno == ENOENT) {
554             rc = AFPERR_NOOBJ;
555         }
556         else {
557             rc = deletefile(vol, upath, 1);
558         }
559     }
560     if ( rc == AFP_OK ) {
561         curdir->offcnt--;
562         setvoltime(obj, vol );
563     }
564
565     return( rc );
566 }
567 /* ------------------------ */
568 char *absupath(const struct vol *vol, struct dir *dir, char *u)
569 {
570     static char pathbuf[MAXPATHLEN + 1];
571     bstring path;
572
573     if (u == NULL || dir == NULL || vol == NULL)
574         return NULL;
575
576     if ((path = bstrcpy(dir->d_fullpath)) == NULL)
577         return NULL;
578     if (bcatcstr(path, "/") != BSTR_OK)
579         return NULL;
580     if (bcatcstr(path, u) != BSTR_OK)
581         return NULL;
582     if (path->slen > MAXPATHLEN)
583         return NULL;
584
585     LOG(log_debug, logtype_afpd, "absupath: %s", cfrombstring(path));
586
587     strncpy(pathbuf, cfrombstring(path), blength(path) + 1);
588     bdestroy(path);
589
590     return(pathbuf);
591 }
592
593 char *ctoupath(const struct vol *vol, struct dir *dir, char *name)
594 {
595     if (vol == NULL || dir == NULL || name == NULL)
596         return NULL;
597     return absupath(vol, dir, mtoupath(vol, name, dir->d_did, utf8_encoding()));
598 }
599
600 /* ------------------------- */
601 int afp_moveandrename(AFPObj *obj, char *ibuf, size_t ibuflen _U_, char *rbuf _U_, size_t *rbuflen)
602 {
603     struct vol  *vol;
604     struct dir  *sdir, *ddir;
605     int         isdir;
606     char    *oldname, *newname;
607     struct path *path;
608     int     did;
609     int     pdid;
610     int         plen;
611     u_int16_t   vid;
612     int         rc;
613 #ifdef DROPKLUDGE
614     int     retvalue;
615 #endif /* DROPKLUDGE */
616
617     *rbuflen = 0;
618     ibuf += 2;
619
620     memcpy( &vid, ibuf, sizeof( vid ));
621     ibuf += sizeof( vid );
622     if (NULL == ( vol = getvolbyvid( vid )) ) {
623         return( AFPERR_PARAM );
624     }
625
626     if (vol->v_flags & AFPVOL_RO)
627         return AFPERR_VLOCK;
628
629     /* source did followed by dest did */
630     memcpy( &did, ibuf, sizeof( did ));
631     ibuf += sizeof( int );
632     if (NULL == ( sdir = dirlookup( vol, did )) ) {
633         return afp_errno; /* was AFPERR_PARAM */
634     }
635
636     memcpy( &did, ibuf, sizeof( did ));
637     ibuf += sizeof( int );
638
639     /* source pathname */
640     if (NULL == ( path = cname( vol, sdir, &ibuf )) ) {
641         return get_afp_errno(AFPERR_NOOBJ);
642     }
643
644     sdir = curdir;
645     newname = obj->newtmp;
646     oldname = obj->oldtmp;
647
648     isdir = path_isadir(path);
649     if ( *path->m_name != '\0' ) {
650         if (isdir) {
651             sdir = path->d_dir;
652         }
653         strcpy(oldname, path->m_name); /* an extra copy for of_rename */
654     } else {
655         memcpy(oldname, cfrombstring(sdir->d_m_name), blength(sdir->d_m_name) + 1);
656     }
657
658     /* get the destination directory */
659     if (NULL == ( ddir = dirlookup( vol, did )) ) {
660         return afp_errno; /*  was AFPERR_PARAM */
661     }
662     if (NULL == ( path = cname( vol, ddir, &ibuf ))) {
663         return( AFPERR_NOOBJ );
664     }
665     pdid = curdir->d_did;
666     if ( *path->m_name != '\0' ) {
667         return path_error(path, AFPERR_NOOBJ);
668     }
669
670     /* one more place where we know about path type */
671     if ((plen = copy_path_name(vol, newname, ibuf)) < 0) {
672         return( AFPERR_PARAM );
673     }
674
675     if (!plen) {
676         strcpy(newname, oldname);
677     }
678
679     LOG(log_debug, logtype_afpd, "afp_move: {oldname:'%s', newname:'%s', isdir:%u}",
680         oldname, newname, isdir);
681     rc = moveandrename(vol, sdir, oldname, newname, isdir);
682
683     if ( rc == AFP_OK ) {
684         char *upath = mtoupath(vol, newname, pdid, utf8_encoding());
685
686         if (NULL == upath) {
687             return AFPERR_PARAM;
688         }
689         curdir->offcnt++;
690         sdir->offcnt--;
691 #ifdef DROPKLUDGE
692         if (vol->v_flags & AFPVOL_DROPBOX) {
693             /* FIXME did is not always the source id */
694             if ((retvalue=matchfile2dirperms (upath, vol, did)) != AFP_OK) {
695                 return retvalue;
696             }
697         }
698         else
699 #endif /* DROPKLUDGE */
700             /* if unix priv don't try to match perm with dest folder */
701             if (!isdir && !vol_unix_priv(vol)) {
702                 int  admode = ad_mode("", 0777) | vol->v_fperm;
703
704                 setfilmode(upath, admode, NULL, vol->v_umask);
705                 vol->vfs->vfs_setfilmode(vol, upath, admode, NULL);
706             }
707         setvoltime(obj, vol );
708     }
709
710     return( rc );
711 }
712
713 int veto_file(const char*veto_str, const char*path)
714 /* given a veto_str like "abc/zxc/" and path "abc", return 1
715  * veto_str should be '/' delimited
716  * if path matches any one of the veto_str elements exactly, then 1 is returned
717  * otherwise, 0 is returned.
718  */
719 {
720     int i;  /* index to veto_str */
721     int j;  /* index to path */
722
723     if ((veto_str == NULL) || (path == NULL))
724         return 0;
725
726     for(i=0, j=0; veto_str[i] != '\0'; i++) {
727         if (veto_str[i] == '/') {
728             if ((j>0) && (path[j] == '\0')) {
729                 LOG(log_debug, logtype_afpd, "vetoed file:'%s'", path);
730                 return 1;
731             }
732             j = 0;
733         } else {
734             if (veto_str[i] != path[j]) {
735                 while ((veto_str[i] != '/')
736                        && (veto_str[i] != '\0'))
737                     i++;
738                 j = 0;
739                 continue;
740             }
741             j++;
742         }
743     }
744     return 0;
745 }
746