]> arthur.barton.de Git - netatalk.git/blob - libatalk/vfs/vfs.c
Merge master
[netatalk.git] / libatalk / vfs / vfs.c
1 /*
2     Copyright (c) 2004 Didier Gautheron
3     Copyright (c) 2009 Frank Lahm
4  
5    This program is free software; you can redistribute it and/or modify
6    it under the terms of the GNU General Public License as published by
7    the Free Software Foundation; either version 2 of the License, or
8    (at your option) any later version.
9  
10    This program is distributed in the hope that it will be useful,
11    but WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13    GNU General Public License for more details.
14  
15    You should have received a copy of the GNU General Public License
16    along with this program; if not, write to the Free Software
17    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  
19 */
20 #ifdef HAVE_CONFIG_H
21 #include "config.h"
22 #endif /* HAVE_CONFIG_H */
23
24 #include <sys/types.h>
25 #include <sys/stat.h>
26 #include <unistd.h>
27 #include <string.h>
28 #include <stdio.h>
29 #include <stdlib.h>
30 #include <libgen.h>
31
32 #include <atalk/afp.h>    
33 #include <atalk/adouble.h>
34 #include <atalk/ea.h>
35 #include <atalk/acl.h>
36 #include <atalk/logger.h>
37 #include <atalk/util.h>
38 #include <atalk/volume.h>
39 #include <atalk/vfs.h>
40 #include <atalk/directory.h>
41 #include <atalk/unix.h>
42 #include <atalk/errchk.h>
43 #include <atalk/bstrlib.h>
44 #include <atalk/bstradd.h>
45 #include <atalk/compat.h>
46
47 struct perm {
48     uid_t uid;
49     gid_t gid;
50 };
51
52 typedef int (*rf_loop)(struct dirent *, char *, void *, int , mode_t );
53
54 /* ----------------------------- */
55 static int 
56 for_each_adouble(const char *from, const char *name, rf_loop fn, void *data, int flag, mode_t v_umask)
57 {
58     char            buf[ MAXPATHLEN + 1];
59     char            *m;
60     DIR             *dp;
61     struct dirent   *de;
62     int             ret;
63     
64
65     if (NULL == ( dp = opendir( name)) ) {
66         if (!flag) {
67             LOG(log_error, logtype_afpd, "%s: opendir %s: %s", from, fullpathname(name),strerror(errno) );
68             return -1;
69         }
70         return 0;
71     }
72     strlcpy( buf, name, sizeof(buf));
73     strlcat( buf, "/", sizeof(buf) );
74     m = strchr( buf, '\0' );
75     ret = 0;
76     while ((de = readdir(dp))) {
77         if (!strcmp(de->d_name, ".") || !strcmp(de->d_name, "..")) {
78                 continue;
79         }
80         
81         strlcat(buf, de->d_name, sizeof(buf));
82         if (fn && (ret = fn(de, buf, data, flag, v_umask))) {
83            closedir(dp);
84            return ret;
85         }
86         *m = 0;
87     }
88     closedir(dp);
89     return ret;
90 }
91
92 /*******************************************************************************
93  * classic adouble format 
94  *******************************************************************************/
95
96 static int netatalk_name(const char *name)
97 {
98     return strcasecmp(name,".AppleDouble") &&
99         strcasecmp(name,".AppleDB") &&
100         strcasecmp(name,".AppleDesktop");
101 }
102
103 static int validupath_adouble(VFS_FUNC_ARGS_VALIDUPATH)
104 {
105     if (name[0] != '.')
106         return 1;
107     
108     if (!(vol->v_flags & AFPVOL_USEDOTS))
109         return 0;
110         
111     return netatalk_name(name) && strcasecmp(name,".Parent");
112 }                                           
113
114 /* ----------------- */
115 static int RF_chown_adouble(VFS_FUNC_ARGS_CHOWN)
116 {
117     struct stat st;
118     const char *ad_p;
119
120     ad_p = vol->ad_path(path, ADFLAGS_HF );
121
122     if ( stat( ad_p, &st ) < 0 )
123         return 0; /* ignore */
124
125     return chown( ad_p, uid, gid );
126 }
127
128 /* ----------------- */
129 static int RF_renamedir_adouble(VFS_FUNC_ARGS_RENAMEDIR)
130 {
131     return 0;
132 }
133
134 /* ----------------- */
135 static int deletecurdir_adouble_loop(struct dirent *de, char *name, void *data _U_, int flag _U_, mode_t v_umask)
136 {
137     struct stat st;
138     int         err;
139     
140     /* bail if the file exists in the current directory.
141      * note: this will not fail with dangling symlinks */
142     
143     if (stat(de->d_name, &st) == 0)
144         return AFPERR_DIRNEMPT;
145
146     if ((err = netatalk_unlink(name)))
147         return err;
148
149     return 0;
150 }
151
152 static int RF_deletecurdir_adouble(VFS_FUNC_ARGS_DELETECURDIR)
153 {
154     int err;
155
156     /* delete stray .AppleDouble files. this happens to get .Parent files
157        as well. */
158     if ((err = for_each_adouble("deletecurdir", ".AppleDouble", deletecurdir_adouble_loop, NULL, 1, vol->v_umask))) 
159         return err;
160     return netatalk_rmdir(-1, ".AppleDouble" );
161 }
162
163 /* ----------------- */
164 static int adouble_setfilmode(const char * name, mode_t mode, struct stat *st, mode_t v_umask)
165 {
166     return setfilmode(name, ad_hf_mode(mode), st, v_umask);
167 }
168
169 static int RF_setfilmode_adouble(VFS_FUNC_ARGS_SETFILEMODE)
170 {
171     return adouble_setfilmode(vol->ad_path(name, ADFLAGS_HF ), mode, st, vol->v_umask);
172 }
173
174 /* ----------------- */
175 static int RF_setdirunixmode_adouble(VFS_FUNC_ARGS_SETDIRUNIXMODE)
176 {
177     const char *adouble = vol->ad_path(name, ADFLAGS_DIR );
178     int  dropbox = vol->v_flags;
179
180     if (dir_rx_set(mode)) {
181         if (stickydirmode(ad_dir(adouble), DIRBITS | mode, dropbox, vol->v_umask) < 0 ) 
182             return -1;
183     }
184
185     if (adouble_setfilmode(vol->ad_path(name, ADFLAGS_DIR ), mode, st, vol->v_umask) < 0) 
186         return -1;
187
188     if (!dir_rx_set(mode)) {
189         if (stickydirmode(ad_dir(adouble), DIRBITS | mode, dropbox, vol->v_umask) < 0 ) 
190             return  -1 ;
191     }
192     return 0;
193 }
194
195 /* ----------------- */
196 static int setdirmode_adouble_loop(struct dirent *de _U_, char *name, void *data, int flag, mode_t v_umask)
197 {
198     mode_t hf_mode = *(mode_t *)data;
199     struct stat st;
200
201     if ( stat( name, &st ) < 0 ) {
202         if (flag)
203             return 0;
204         LOG(log_error, logtype_afpd, "setdirmode: stat %s: %s", name, strerror(errno) );
205     }
206     else if (!S_ISDIR(st.st_mode)) {
207         if (setfilmode(name, hf_mode , &st, v_umask) < 0) {
208                /* FIXME what do we do then? */
209         }
210     }
211     return 0;
212 }
213
214 static int RF_setdirmode_adouble(VFS_FUNC_ARGS_SETDIRMODE)
215 {
216     int   dropbox = vol->v_flags;
217     mode_t hf_mode = ad_hf_mode(mode);
218     const char  *adouble = vol->ad_path(name, ADFLAGS_DIR );
219     const char  *adouble_p = ad_dir(adouble);
220
221     if (dir_rx_set(mode)) {
222         if (stickydirmode(ad_dir(adouble), DIRBITS | mode, dropbox, vol->v_umask) < 0) 
223             return -1;
224     }
225
226     if (for_each_adouble("setdirmode", adouble_p, setdirmode_adouble_loop, &hf_mode, vol_noadouble(vol), vol->v_umask))
227         return -1;
228
229     if (!dir_rx_set(mode)) {
230         if (stickydirmode(ad_dir(adouble), DIRBITS | mode, dropbox, vol->v_umask) < 0) 
231             return  -1 ;
232     }
233     return 0;
234 }
235
236 /* ----------------- */
237 static int setdirowner_adouble_loop(struct dirent *de _U_, char *name, void *data, int flag _U_, mode_t v_umask _U_)
238 {
239     struct perm   *owner  = data;
240
241     if ( chown( name, owner->uid, owner->gid ) < 0 && errno != EPERM ) {
242          LOG(log_debug, logtype_afpd, "setdirowner: chown %d/%d %s: %s",
243                 owner->uid, owner->gid, fullpathname(name), strerror(errno) );
244          /* return ( -1 ); Sometimes this is okay */
245     }
246     return 0;
247 }
248
249 static int RF_setdirowner_adouble(VFS_FUNC_ARGS_SETDIROWNER)
250 {
251     int           noadouble = vol_noadouble(vol);
252     char          *adouble_p;
253     struct stat   st;
254     struct perm   owner;
255     
256     owner.uid = uid;
257     owner.gid = gid;
258
259     adouble_p = ad_dir(vol->ad_path(name, ADFLAGS_DIR ));
260
261     if (for_each_adouble("setdirowner", adouble_p, setdirowner_adouble_loop, &owner, noadouble, vol->v_umask)) 
262         return -1;
263
264     /*
265      * We cheat: we know that chown doesn't do anything.
266      */
267     if ( stat( ".AppleDouble", &st ) < 0) {
268         if (errno == ENOENT && noadouble)
269             return 0;
270         LOG(log_error, logtype_afpd, "setdirowner: stat %s: %s", fullpathname(".AppleDouble"), strerror(errno) );
271         return -1;
272     }
273     if ( gid && gid != st.st_gid && chown( ".AppleDouble", uid, gid ) < 0 && errno != EPERM ) {
274         LOG(log_debug, logtype_afpd, "setdirowner: chown %d/%d %s: %s",
275             uid, gid,fullpathname(".AppleDouble"), strerror(errno) );
276         /* return ( -1 ); Sometimes this is okay */
277     }
278     return 0;
279 }
280
281 /* ----------------- */
282 static int RF_deletefile_adouble(VFS_FUNC_ARGS_DELETEFILE)
283 {
284         return netatalk_unlinkat(dirfd, vol->ad_path(file, ADFLAGS_HF));
285 }
286
287 /* ----------------- */
288 static int RF_renamefile_adouble(VFS_FUNC_ARGS_RENAMEFILE)
289 {
290     char  adsrc[ MAXPATHLEN + 1];
291     int   err = 0;
292
293     strcpy( adsrc, vol->ad_path(src, 0 ));
294     if (unix_rename(dirfd, adsrc, -1, vol->ad_path(dst, 0 )) < 0) {
295         struct stat st;
296
297         err = errno;
298         if (errno == ENOENT) {
299                 struct adouble    ad;
300
301             if (lstatat(dirfd, adsrc, &st)) /* source has no ressource fork, */
302                 return 0;
303
304             /* We are here  because :
305              * -there's no dest folder. 
306              * -there's no .AppleDouble in the dest folder.
307              * if we use the struct adouble passed in parameter it will not
308              * create .AppleDouble if the file is already opened, so we
309              * use a diff one, it's not a pb,ie it's not the same file, yet.
310              */
311             ad_init(&ad, vol->v_adouble, vol->v_ad_options); 
312             if (ad_open(&ad, dst, ADFLAGS_HF, O_RDWR | O_CREAT, 0666) == 0) {
313                 ad_close(&ad, ADFLAGS_HF);
314                 if (!unix_rename(dirfd, adsrc, -1, vol->ad_path(dst, 0 )) ) 
315                    err = 0;
316                 else 
317                    err = errno;
318             }
319             else { /* it's something else, bail out */
320                     err = errno;
321                 }
322             }
323         }
324         if (err) {
325                 errno = err;
326                 return -1;
327         }
328         return 0;
329 }
330
331 static int RF_copyfile_adouble(VFS_FUNC_ARGS_COPYFILE)
332 /* const struct vol *vol, int sfd, const char *src, const char *dst */
333 {
334     EC_INIT;
335     bstring s = NULL, d = NULL;
336     char *dup1 = NULL;
337     char *dup2 = NULL;
338     char *dup3 = NULL;
339     char *dup4 = NULL;
340     const char *name = NULL;
341     const char *dir = NULL;
342
343     struct stat st;
344     EC_ZERO(stat(dst, &st));
345
346     if (S_ISDIR(st.st_mode)) {
347         /* build src path to AppleDouble file*/
348         EC_NULL(s = bfromcstr(src));
349         EC_ZERO(bcatcstr(s, "/.AppleDouble/.Parent"));
350
351         /* build dst path to AppleDouble file*/
352         EC_NULL(d = bfromcstr(dst));
353         EC_ZERO(bcatcstr(d, "/.AppleDouble/.Parent"));
354     } else {
355         /* get basename */
356
357         /* build src path to AppleDouble file*/
358         EC_NULL(dup1 = strdup(src));
359         EC_NULL(name = basename(strdup(dup1)));
360
361         EC_NULL(dup2 = strdup(src));
362         EC_NULL(dir = dirname(dup2));
363         EC_NULL(s = bfromcstr(dir));
364         EC_ZERO(bcatcstr(s, "/.AppleDouble/"));
365         EC_ZERO(bcatcstr(s, name));
366
367         /* build dst path to AppleDouble file*/
368         EC_NULL(dup4 = strdup(dst));
369         EC_NULL(name = basename(strdup(dup4)));
370
371         EC_NULL(dup3 = strdup(dst));
372         EC_NULL(dir = dirname(dup3));
373         EC_NULL(d = bfromcstr(dir));
374         EC_ZERO(bcatcstr(d, "/.AppleDouble/"));
375         EC_ZERO(bcatcstr(d, name));
376     }
377
378     EC_ZERO(copy_file(sfd, cfrombstr(s), cfrombstr(d), 0666));
379
380 EC_CLEANUP:
381     bdestroy(s);
382     bdestroy(d);
383     if (dup1) free(dup1);
384     if (dup2) free(dup2);
385     if (dup3) free(dup3);
386     if (dup4) free(dup4);
387
388     EC_EXIT;
389 }
390
391 #ifdef HAVE_SOLARIS_ACLS
392 static int RF_solaris_acl(VFS_FUNC_ARGS_ACL)
393 {
394     static char buf[ MAXPATHLEN + 1];
395     struct stat st;
396     int len;
397
398     if ((stat(path, &st)) != 0)
399         return -1;
400     if (S_ISDIR(st.st_mode)) {
401         len = snprintf(buf, MAXPATHLEN, "%s/.AppleDouble",path);
402         if (len < 0 || len >=  MAXPATHLEN)
403             return -1;
404         /* set acl on .AppleDouble dir first */
405         if ((acl(buf, cmd, count, aces)) != 0)
406             return -1;
407         /* now set ACL on ressource fork */
408         if ((acl(vol->ad_path(path, ADFLAGS_DIR), cmd, count, aces)) != 0)
409             return -1;
410     } else
411         /* set ACL on ressource fork */
412         if ((acl(vol->ad_path(path, ADFLAGS_HF), cmd, count, aces)) != 0)
413             return -1;
414
415     return 0;
416 }
417
418 static int RF_solaris_remove_acl(VFS_FUNC_ARGS_REMOVE_ACL)
419 {
420     int ret;
421     static char buf[ MAXPATHLEN + 1];
422     int len;
423
424     if (dir) {
425         len = snprintf(buf, MAXPATHLEN, "%s/.AppleDouble",path);
426         if (len < 0 || len >=  MAXPATHLEN)
427             return AFPERR_MISC;
428         /* remove ACL from .AppleDouble/.Parent first */
429         if ((ret = remove_acl_vfs(vol->ad_path(path, ADFLAGS_DIR))) != AFP_OK)
430             return ret;
431         /* now remove from .AppleDouble dir */
432         if ((ret = remove_acl_vfs(buf)) != AFP_OK)
433             return ret;
434     } else
435         /* remove ACL from ressource fork */
436         if ((ret = remove_acl_vfs(vol->ad_path(path, ADFLAGS_HF))) != AFP_OK)
437             return ret;
438
439     return AFP_OK;
440 }
441 #endif
442
443 #ifdef HAVE_POSIX_ACLS
444 static int RF_posix_acl(VFS_FUNC_ARGS_ACL)
445 {
446     EC_INIT;
447     static char buf[ MAXPATHLEN + 1];
448     struct stat st;
449     int len;
450
451     if (S_ISDIR(st.st_mode)) {
452         len = snprintf(buf, MAXPATHLEN, "%s/.AppleDouble",path);
453         if (len < 0 || len >=  MAXPATHLEN)
454             EC_FAIL;
455         /* set acl on .AppleDouble dir first */
456         EC_ZERO_LOG(acl_set_file(buf, type, acl));
457
458         if (type == ACL_TYPE_ACCESS)
459             /* set ACL on ressource fork (".Parent") too */
460             EC_ZERO_LOG(acl_set_file(vol->ad_path(path, ADFLAGS_DIR), type, acl));
461     } else {
462         /* set ACL on ressource fork */
463         EC_ZERO_LOG(acl_set_file(vol->ad_path(path, ADFLAGS_HF), type, acl));
464     }
465     
466 EC_CLEANUP:
467     if (ret != 0)
468         return AFPERR_MISC;
469     return AFP_OK;
470 }
471
472 static int RF_posix_remove_acl(VFS_FUNC_ARGS_REMOVE_ACL)
473 {
474     EC_INIT;
475     static char buf[ MAXPATHLEN + 1];
476     int len;
477
478     if (dir) {
479         len = snprintf(buf, MAXPATHLEN, "%s/.AppleDouble",path);
480         if (len < 0 || len >=  MAXPATHLEN)
481             return AFPERR_MISC;
482         /* remove ACL from .AppleDouble/.Parent first */
483         EC_ZERO_LOG_ERR(remove_acl_vfs(vol->ad_path(path, ADFLAGS_DIR)), AFPERR_MISC);
484
485         /* now remove from .AppleDouble dir */
486         EC_ZERO_LOG_ERR(remove_acl_vfs(buf), AFPERR_MISC);
487     } else {
488         /* remove ACL from ressource fork */
489         EC_ZERO_LOG_ERR(remove_acl_vfs(vol->ad_path(path, ADFLAGS_HF)), AFPERR_MISC);
490     }
491
492 EC_CLEANUP:
493     EC_EXIT;
494 }
495 #endif
496
497 /*************************************************************************
498  * EA adouble format 
499  ************************************************************************/
500 static int validupath_ea(VFS_FUNC_ARGS_VALIDUPATH)
501 {
502     return 1;
503 }             
504
505 /* ----------------- */
506 static int RF_chown_ea(VFS_FUNC_ARGS_CHOWN)
507 {
508     mode_t file_mode = ad_hf_mode(mode);
509     mode_t dir_mode = file_mode;
510     struct set_mode param;
511
512     if ((dir_mode & (S_IRUSR | S_IWUSR )))
513         dir_mode |= S_IXUSR;
514     if ((dir_mode & (S_IRGRP | S_IWGRP )))
515         dir_mode |= S_IXGRP;
516     if ((dir_mode & (S_IROTH | S_IWOTH )))
517         dir_mode |= S_IXOTH;
518
519         /* change folder */
520         dir_mode |= DIRBITS;
521     if (dir_rx_set(dir_mode)) {
522         if (chmod_acl( name,  dir_mode ) < 0)
523             return -1;
524     }
525     param.st = st;
526     param.mode = file_mode;
527     if (for_each_adouble("setfilmode_ads", name, ads_setfilmode_loop, &param, 0, v_umask) < 0)
528         return -1;
529
530     if (!dir_rx_set(dir_mode)) {
531         if (chmod_acl( name,  dir_mode ) < 0)
532             return -1;
533     }
534
535     return 0;
536 }
537
538 /* ---------------- */
539 static int RF_renamedir_ea(VFS_FUNC_ARGS_RENAMEDIR)
540 {
541     return 0;
542 }
543
544 /* ---------------- */
545 static int RF_deletecurdir_ea(VFS_FUNC_ARGS_DELETECURDIR)
546 {
547     return 0;
548 }
549
550 /* ---------------- */
551 static int RF_setdirunixmode_ea(VFS_FUNC_ARGS_SETDIRUNIXMODE)
552 {
553     return 0;
554 }
555
556 static int RF_setfilmode_ea(VFS_FUNC_ARGS_SETFILEMODE)
557 {
558     return 0;
559 }
560
561 /* ---------------- */
562 static int RF_setdirmode_ea(VFS_FUNC_ARGS_SETDIRMODE)
563 {
564     return 0;
565 }
566
567 /* ---------------- */
568 static int RF_setdirowner_ea(VFS_FUNC_ARGS_SETDIROWNER)
569 {
570         return 0;
571 }
572
573 static int RF_deletefile_ea(VFS_FUNC_ARGS_DELETEFILE)
574 {
575     return 0;
576 }
577 static int RF_copyfile_ea(VFS_FUNC_ARGS_COPYFILE)
578 {
579     return 0;
580 }
581
582 /* ---------------- */
583 static int RF_renamefile_ea(VFS_FUNC_ARGS_RENAMEFILE)
584 {
585     return 0;
586 }
587
588 #if 0
589 /*************************************************************************
590  * osx adouble format 
591  ************************************************************************/
592 static int validupath_osx(VFS_FUNC_ARGS_VALIDUPATH)
593 {
594     return strncmp(name,"._", 2) && (
595       (vol->v_flags & AFPVOL_USEDOTS) ? netatalk_name(name): name[0] != '.');
596 }             
597
598 /* ---------------- */
599 static int RF_renamedir_osx(VFS_FUNC_ARGS_RENAMEDIR)
600 {
601     /* We simply move the corresponding ad file as well */
602     char   tempbuf[258]="._";
603     return unix_rename(dirfd, vol->ad_path(oldpath,0), -1, strcat(tempbuf,newpath));
604 }
605
606 /* ---------------- */
607 static int RF_deletecurdir_osx(VFS_FUNC_ARGS_DELETECURDIR)
608 {
609     return netatalk_unlink( vol->ad_path(".",0) );
610 }
611
612 /* ---------------- */
613 static int RF_setdirunixmode_osx(VFS_FUNC_ARGS_SETDIRUNIXMODE)
614 {
615     return adouble_setfilmode(vol->ad_path(name, ADFLAGS_DIR ), mode, st, vol->v_umask);
616 }
617
618 /* ---------------- */
619 static int RF_setdirmode_osx(VFS_FUNC_ARGS_SETDIRMODE)
620 {
621     return 0;
622 }
623
624 /* ---------------- */
625 static int RF_setdirowner_osx(VFS_FUNC_ARGS_SETDIROWNER)
626 {
627         return 0;
628 }
629
630 /* ---------------- */
631 static int RF_renamefile_osx(VFS_FUNC_ARGS_RENAMEFILE)
632 {
633     char  adsrc[ MAXPATHLEN + 1];
634     int   err = 0;
635
636     strcpy( adsrc, vol->ad_path(src, 0 ));
637
638     if (unix_rename(dirfd, adsrc, -1, vol->ad_path(dst, 0 )) < 0) {
639         struct stat st;
640
641         err = errno;
642         if (errno == ENOENT && lstatat(dirfd, adsrc, &st)) /* source has no ressource fork, */
643             return 0;
644         errno = err;
645         return -1;
646     }
647     return 0;
648 }
649 #endif
650
651 /********************************************************************************************
652  * VFS chaining
653  ********************************************************************************************/
654
655 /* 
656  * Up until we really start stacking many VFS modules on top of one another or use
657  * dynamic module loading like we do for UAMs, up until then we just stack VFS modules
658  * via an fixed size array.
659  * All VFS funcs must return AFP_ERR codes. When a func in the chain returns an error
660  * this error code will be returned to the caller, BUT the chain in followed and all
661  * following funcs are called in order to give them a chance.
662  */
663
664 /* 
665  * Define most VFS funcs with macros as they all do the same.
666  * Only "ad_path" and "validupath" will NOT do stacking and only
667  * call the func from the first module.
668  */
669
670 #define VFS_MFUNC(name, args, vars) \
671     static int vfs_ ## name(args) \
672     { \
673         int i = 0, ret = AFP_OK, err; \
674         while (vol->vfs_modules[i]) { \
675             if (vol->vfs_modules[i]->vfs_ ## name) { \
676                 err = vol->vfs_modules[i]->vfs_ ## name (vars); \
677                 if ((ret == AFP_OK) && (err != AFP_OK)) \
678                     ret = err; \
679             } \
680             i ++; \
681         } \
682         return ret; \
683     }
684
685 VFS_MFUNC(chown, VFS_FUNC_ARGS_CHOWN, VFS_FUNC_VARS_CHOWN)
686 VFS_MFUNC(renamedir, VFS_FUNC_ARGS_RENAMEDIR, VFS_FUNC_VARS_RENAMEDIR) 
687 VFS_MFUNC(deletecurdir, VFS_FUNC_ARGS_DELETECURDIR, VFS_FUNC_VARS_DELETECURDIR)
688 VFS_MFUNC(setfilmode, VFS_FUNC_ARGS_SETFILEMODE, VFS_FUNC_VARS_SETFILEMODE)
689 VFS_MFUNC(setdirmode, VFS_FUNC_ARGS_SETDIRMODE, VFS_FUNC_VARS_SETDIRMODE)
690 VFS_MFUNC(setdirunixmode, VFS_FUNC_ARGS_SETDIRUNIXMODE, VFS_FUNC_VARS_SETDIRUNIXMODE)
691 VFS_MFUNC(setdirowner, VFS_FUNC_ARGS_SETDIROWNER, VFS_FUNC_VARS_SETDIROWNER)
692 VFS_MFUNC(deletefile, VFS_FUNC_ARGS_DELETEFILE, VFS_FUNC_VARS_DELETEFILE)
693 VFS_MFUNC(renamefile, VFS_FUNC_ARGS_RENAMEFILE, VFS_FUNC_VARS_RENAMEFILE)
694 VFS_MFUNC(copyfile, VFS_FUNC_ARGS_COPYFILE, VFS_FUNC_VARS_COPYFILE)
695 #ifdef HAVE_ACLS
696 VFS_MFUNC(acl, VFS_FUNC_ARGS_ACL, VFS_FUNC_VARS_ACL)
697 VFS_MFUNC(remove_acl, VFS_FUNC_ARGS_REMOVE_ACL, VFS_FUNC_VARS_REMOVE_ACL)
698 #endif
699 VFS_MFUNC(ea_getsize, VFS_FUNC_ARGS_EA_GETSIZE, VFS_FUNC_VARS_EA_GETSIZE)
700 VFS_MFUNC(ea_getcontent, VFS_FUNC_ARGS_EA_GETCONTENT, VFS_FUNC_VARS_EA_GETCONTENT)
701 VFS_MFUNC(ea_list, VFS_FUNC_ARGS_EA_LIST, VFS_FUNC_VARS_EA_LIST)
702 VFS_MFUNC(ea_set, VFS_FUNC_ARGS_EA_SET, VFS_FUNC_VARS_EA_SET)
703 VFS_MFUNC(ea_remove, VFS_FUNC_ARGS_EA_REMOVE, VFS_FUNC_VARS_EA_REMOVE)
704
705 static int vfs_validupath(VFS_FUNC_ARGS_VALIDUPATH)
706 {
707     return vol->vfs_modules[0]->vfs_validupath(VFS_FUNC_VARS_VALIDUPATH);
708 }
709
710 /*
711  * These function pointers get called from the lib users via vol->vfs->func.
712  * These funcs are defined via the macros above.
713  */
714 static struct vfs_ops vfs_master_funcs = {
715     vfs_validupath,
716     vfs_chown,
717     vfs_renamedir,
718     vfs_deletecurdir,
719     vfs_setfilmode,
720     vfs_setdirmode,
721     vfs_setdirunixmode,
722     vfs_setdirowner,
723     vfs_deletefile,
724     vfs_renamefile,
725     vfs_copyfile,
726 #ifdef HAVE_ACLS
727     vfs_acl,
728     vfs_remove_acl,
729 #endif
730     vfs_ea_getsize,
731     vfs_ea_getcontent,
732     vfs_ea_list,
733     vfs_ea_set,
734     vfs_ea_remove
735 };
736
737 /* 
738  * Primary adouble modules: v2, ea
739  */
740
741 static struct vfs_ops netatalk_adouble_v2 = {
742     /* vfs_validupath:    */ validupath_adouble,
743     /* vfs_chown:         */ RF_chown_adouble,
744     /* vfs_renamedir:     */ RF_renamedir_adouble,
745     /* vfs_deletecurdir:  */ RF_deletecurdir_adouble,
746     /* vfs_setfilmode:    */ RF_setfilmode_adouble,
747     /* vfs_setdirmode:    */ RF_setdirmode_adouble,
748     /* vfs_setdirunixmode:*/ RF_setdirunixmode_adouble,
749     /* vfs_setdirowner:   */ RF_setdirowner_adouble,
750     /* vfs_deletefile:    */ RF_deletefile_adouble,
751     /* vfs_renamefile:    */ RF_renamefile_adouble,
752     /* vfs_copyfile:      */ RF_copyfile_adouble,
753     NULL
754 };
755
756 static struct vfs_ops netatalk_adouble_ea = {
757     /* vfs_validupath:    */ validupath_ea,
758     /* vfs_chown:         */ RF_chown_ea,
759     /* vfs_renamedir:     */ RF_renamedir_ea,
760     /* vfs_deletecurdir:  */ RF_deletecurdir_ea,
761     /* vfs_setfilmode:    */ RF_setfilmode_ea,
762     /* vfs_setdirmode:    */ RF_setdirmode_ea,
763     /* vfs_setdirunixmode:*/ RF_setdirunixmode_ea,
764     /* vfs_setdirowner:   */ RF_setdirowner_ea,
765     /* vfs_deletefile:    */ RF_deletefile_ea,
766     /* vfs_renamefile:    */ RF_renamefile_ea,
767     /* vfs_copyfile:      */ RF_copyfile_ea,
768     NULL
769 };
770
771 /* 
772  * Secondary vfs modules for Extended Attributes
773  */
774
775 static struct vfs_ops netatalk_ea_adouble = {
776     /* vfs_validupath:    */ NULL,
777     /* vfs_chown:         */ ea_chown,
778     /* vfs_renamedir:     */ NULL, /* ok */
779     /* vfs_deletecurdir:  */ NULL, /* ok */
780     /* vfs_setfilmode:    */ ea_chmod_file,
781     /* vfs_setdirmode:    */ NULL, /* ok */
782     /* vfs_setdirunixmode:*/ ea_chmod_dir,
783     /* vfs_setdirowner:   */ NULL, /* ok */
784     /* vfs_deletefile:    */ ea_deletefile,
785     /* vfs_renamefile:    */ ea_renamefile,
786     /* vfs_copyfile       */ ea_copyfile,
787 #ifdef HAVE_ACLS
788     /* vfs_acl:           */ NULL,
789     /* vfs_remove_acl     */ NULL,
790 #endif
791     /* vfs_getsize        */ get_easize,
792     /* vfs_getcontent     */ get_eacontent,
793     /* vfs_list           */ list_eas,
794     /* vfs_set            */ set_ea,
795     /* vfs_remove         */ remove_ea
796 };
797
798 static struct vfs_ops netatalk_ea_sys = {
799     /* validupath:        */ NULL,
800     /* rf_chown:          */ NULL,
801     /* rf_renamedir:      */ NULL,
802     /* rf_deletecurdir:   */ NULL,
803     /* rf_setfilmode:     */ NULL,
804     /* rf_setdirmode:     */ NULL,
805     /* rf_setdirunixmode: */ NULL,
806     /* rf_setdirowner:    */ NULL,
807     /* rf_deletefile:     */ NULL,
808     /* rf_renamefile:     */ NULL,
809     /* vfs_copyfile:      */ sys_ea_copyfile,
810 #ifdef HAVE_ACLS
811     /* rf_acl:            */ NULL,
812     /* rf_remove_acl      */ NULL,
813 #endif
814     /* ea_getsize         */ sys_get_easize,
815     /* ea_getcontent      */ sys_get_eacontent,
816     /* ea_list            */ sys_list_eas,
817     /* ea_set             */ sys_set_ea,
818     /* ea_remove          */ sys_remove_ea
819 };
820
821 /* 
822  * Tertiary VFS modules for ACLs
823  */
824
825 #ifdef HAVE_SOLARIS_ACLS
826 static struct vfs_ops netatalk_solaris_acl_adouble = {
827     /* validupath:        */ NULL,
828     /* rf_chown:          */ NULL,
829     /* rf_renamedir:      */ NULL,
830     /* rf_deletecurdir:   */ NULL,
831     /* rf_setfilmode:     */ NULL,
832     /* rf_setdirmode:     */ NULL,
833     /* rf_setdirunixmode: */ NULL,
834     /* rf_setdirowner:    */ NULL,
835     /* rf_deletefile:     */ NULL,
836     /* rf_renamefile:     */ NULL,
837     /* vfs_copyfile       */ NULL,
838     /* rf_acl:            */ RF_solaris_acl,
839     /* rf_remove_acl      */ RF_solaris_remove_acl,
840     NULL
841 };
842 #endif
843
844 #ifdef HAVE_POSIX_ACLS
845 static struct vfs_ops netatalk_posix_acl_adouble = {
846     /* validupath:        */ NULL,
847     /* rf_chown:          */ NULL,
848     /* rf_renamedir:      */ NULL,
849     /* rf_deletecurdir:   */ NULL,
850     /* rf_setfilmode:     */ NULL,
851     /* rf_setdirmode:     */ NULL,
852     /* rf_setdirunixmode: */ NULL,
853     /* rf_setdirowner:    */ NULL,
854     /* rf_deletefile:     */ NULL,
855     /* rf_renamefile:     */ NULL,
856     /* vfs_copyfile       */ NULL,
857     /* rf_acl:            */ RF_posix_acl,
858     /* rf_remove_acl      */ RF_posix_remove_acl,
859     NULL
860 };
861 #endif
862
863 /* ---------------- */
864 void initvol_vfs(struct vol *vol)
865 {
866     vol->vfs = &vfs_master_funcs;
867
868     /* Default adouble stuff */
869     if (vol->v_adouble == AD_VERSION2) {
870         vol->vfs_modules[0] = &netatalk_adouble_v2;
871         vol->ad_path = ad_path;
872     } else {
873         vol->vfs_modules[0] = &netatalk_adouble_ea;
874         vol->ad_path = ad_path_ea;
875     }
876
877     /* Extended Attributes */
878     if (vol->v_vfs_ea == AFPVOL_EA_SYS) {
879         LOG(log_debug, logtype_afpd, "initvol_vfs: enabling EA support with native EAs");
880         vol->vfs_modules[1] = &netatalk_ea_sys;
881     } else if (vol->v_vfs_ea == AFPVOL_EA_AD) {
882         LOG(log_debug, logtype_afpd, "initvol_vfs: enabling EA support with adouble files");
883         vol->vfs_modules[1] = &netatalk_ea_adouble;
884     } else {
885         LOG(log_debug, logtype_afpd, "initvol_vfs: volume without EA support");
886     }
887
888     /* ACLs */
889 #ifdef HAVE_SOLARIS_ACLS
890     vol->vfs_modules[2] = &netatalk_solaris_acl_adouble;
891 #endif
892 #ifdef HAVE_POSIX_ACLS
893     vol->vfs_modules[2] = &netatalk_posix_acl_adouble;
894 #endif
895
896 }