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