]> arthur.barton.de Git - netatalk.git/blob - etc/afpd/volume.c
6c286851d959aadcccf64206858acfb7a4634e46
[netatalk.git] / etc / afpd / volume.c
1 /*
2  * Copyright (c) 1990,1993 Regents of The University of Michigan.
3  * All Rights Reserved.  See COPYRIGHT.
4  */
5
6 #ifdef HAVE_CONFIG_H
7 #include "config.h"
8 #endif
9
10 #include <sys/time.h>
11 #include <sys/syslog.h>
12 #include <sys/types.h>
13 #include <sys/stat.h>
14 #include <sys/param.h>
15 #include <netatalk/endian.h>
16 #include <atalk/asp.h>
17 #include <atalk/dsi.h>
18 #include <atalk/adouble.h>
19 #include <atalk/afp.h>
20 #include <atalk/util.h>
21 #include <atalk/cnid.h>
22 #include <dirent.h>
23 #include <fcntl.h>
24 #include <stdio.h>
25 #include <stdlib.h>
26 #include <ctype.h>
27 #include <string.h>
28 #include <pwd.h>
29 #include <grp.h>
30 #include <utime.h>
31 #include <errno.h>
32
33 #include "directory.h"
34 #include "file.h"
35 #include "volume.h"
36 #include "globals.h"
37 #include "unix.h"
38
39 #ifndef MIN
40 #define MIN(a, b) ((a) < (b) ? (a) : (b))
41 #endif
42
43 #ifndef NO_LARGE_VOL_SUPPORT
44 #if BYTE_ORDER == BIG_ENDIAN
45 #define hton64(x)       (x)
46 #define ntoh64(x)       (x)
47 #else
48 #define hton64(x)       ((u_int64_t) (htonl(((x) >> 32) & 0xffffffffLL)) | \
49                          (u_int64_t) ((htonl(x) & 0xffffffffLL) << 32))
50 #define ntoh64(x)       (hton64(x))
51 #endif
52 #endif
53
54 static struct vol *volumes = NULL;
55 static int              lastvid = 0;
56 #if AD_VERSION == AD_VERSION1
57 static char             *Trash = "\02\024Network Trash Folder";
58 #endif
59 static struct extmap    *extmap = NULL, *defextmap = NULL;
60
61 #define VOLOPT_ALLOW      0  /* user allow list */
62 #define VOLOPT_DENY       1  /* user deny list */
63 #define VOLOPT_RWLIST     2  /* user rw list */
64 #define VOLOPT_ROLIST     3  /* user ro list */
65 #define VOLOPT_CODEPAGE   4  /* codepage */
66 #define VOLOPT_PASSWORD   5  /* volume password */
67 #define VOLOPT_CASEFOLD   6  /* character case mangling */
68 #define VOLOPT_FLAGS      7  /* various flags */
69 #define VOLOPT_DBPATH     8  /* path to database */
70 #define VOLOPT_MAPCHARS   9  /* does mtou and utom mappings. syntax:
71                                 m and u can be double-byte hex
72                                 strings if necessary.
73                                 m=u -> map both ways
74                                 m>u -> map m to u
75                                 m<u -> map u to m
76                                 !u  -> make u illegal always
77                                 ~u  -> make u illegal only as the first
78                                        part of a double-byte character.
79                              */
80
81 #ifdef FORCE_UIDGID
82 #define VOLOPT_FORCEUID  10  /* force uid for username x */
83 #define VOLOPT_FORCEGID  11  /* force gid for group x */
84 #endif FORCE_UIDGID
85
86 #define VOLOPT_MAX        11
87 #define VOLOPT_NUM        (VOLOPT_MAX + 1)
88
89 #define VOLPASSLEN  8
90 #define VOLOPT_DEFAULT     ":DEFAULT:"
91 #define VOLOPT_DEFAULT_LEN 9
92 struct vol_option {
93   char *c_value;
94   int i_value; 
95 };
96
97 static __inline__ void volfree(struct vol_option *options,
98                                const struct vol_option *save)
99 {
100   int i;
101
102   if (save) {
103     for (i = 0; i < VOLOPT_MAX; i++) {
104       if (options[i].c_value && (options[i].c_value != save[i].c_value))
105         free(options[i].c_value);
106     }
107   } else {
108     for (i = 0; i < VOLOPT_MAX; i++) {
109       if (options[i].c_value)
110         free(options[i].c_value);
111     }
112   }
113 }
114
115
116 /* handle variable substitutions. here's what we understand:
117  * $c   -> client ip/appletalk address
118  * $f   -> full name (whatever's in the gecos field)
119  * $g   -> group
120  * $h   -> hostname 
121  * $s   -> server name (hostname if it doesn't exist)
122  * $u   -> username (guest is usually nobody)
123  * $v   -> volume name (ADEID_NAME or basename)
124  * $z   -> zone (may not exist)
125  * $$   -> $
126  */
127 #define is_var(a, b) (strncmp((a), (b), 2) == 0)
128 static void volxlate(AFPObj *obj, char *dest, int destlen, 
129                      char *src, struct passwd *pwd, char *path)
130 {
131   char *p, *q;
132   int len;
133
134   strncpy(dest, src, destlen);
135   if ((p = strchr(src, '$')) == NULL) /* nothing to do */
136     return; 
137
138   /* first part of the path. just forward to the next variable. */
139   len = MIN(p - src, destlen);
140   if (len > 0) {
141     destlen -= len;
142     dest += len;
143   }
144
145   while (p && destlen > 0) {
146     /* now figure out what the variable is */
147     q = NULL;
148     if (is_var(p, "$c")) {
149       if (obj->proto == AFPPROTO_ASP) {
150         ASP asp = obj->handle;
151
152         len = sprintf(dest, "%u.%u", ntohs(asp->asp_sat.sat_addr.s_net),
153                       asp->asp_sat.sat_addr.s_node);
154         dest += len;
155         destlen -= len;
156
157       } else if (obj->proto == AFPPROTO_DSI) {
158         DSI *dsi = obj->handle;
159
160         len = sprintf(dest, "%s:%u", inet_ntoa(dsi->client.sin_addr),
161                       ntohs(dsi->client.sin_port));
162         dest += len;
163         destlen -= len;
164       }
165     } else if (is_var(p, "$f")) {
166       if (q = strchr(pwd->pw_gecos, ','))
167         *q = '\0';
168       q = pwd->pw_gecos;
169     } else if (is_var(p, "$g")) {
170       struct group *grp = getgrgid(pwd->pw_gid);
171       if (grp)
172         q = grp->gr_name;
173     } else if (is_var(p, "$h")) {
174       q = obj->options.hostname;
175     } else if (is_var(p, "$s")) {
176       if (obj->Obj)
177         q = obj->Obj;
178       else if (obj->options.server) {
179         q = obj->options.server;
180       } else
181         q = obj->options.hostname;
182     } else if (is_var(p, "$u")) {
183       q = obj->username;
184     } else if (is_var(p, "$v")) {
185       if (path) {
186         struct adouble ad;
187
188         memset(&ad, 0, sizeof(ad));
189         if (ad_open(path, ADFLAGS_HF, O_RDONLY, 0, &ad) < 0)
190           goto no_volname;
191
192         if ((len = MIN(ad_getentrylen(&ad, ADEID_NAME), destlen)) > 0) {
193           memcpy(dest, ad_entry(&ad, ADEID_NAME), len);
194           ad_close(&ad, ADFLAGS_HF);
195           dest += len;
196           destlen -= len;
197         } else {
198           ad_close(&ad, ADFLAGS_HF);
199 no_volname: /* simple basename */
200           if ((q = strrchr(path, '/')) == NULL)
201             q = path;
202           else if (*(q + 1) != '\0')
203             q++;
204         }
205       }
206     } else if (is_var(p, "$z")) {
207       q = obj->Zone;
208     } else if (is_var(p, "$$")) {
209       q = "$";
210     } else
211       q = p;
212     
213     /* copy the stuff over. if we don't understand something that we
214      * should, just skip it over. */
215     if (q) {
216       len = MIN(p == q ? 2 : strlen(q), destlen);
217       strncpy(dest, q, len);
218       dest += len;
219       destlen -= len;
220     }
221
222     /* stuff up to next $ */
223     src = p + 2;
224     p = strchr(src, '$');
225     len = p ? MIN(p - src, destlen) : destlen;
226     if (len > 0) {
227       strncpy(dest, src, len);
228       dest += len;
229       destlen -= len;
230     }
231   }
232 }
233
234 /* to make sure that val is valid, make sure to select an opt that
235    includes val */
236 #define optionok(buf,opt,val) (strstr((buf),(opt)) && ((val)[1] != '\0'))
237
238 static __inline__ char *get_codepage_path(const char *path, const char *name)
239 {
240   char *page;
241   int len;
242
243   if (path) {
244     page = (char *) malloc((len = strlen(path)) + strlen(name) + 2);
245     if (page) {
246       strcpy(page, path);
247       if (path[len - 1] != '/') /* add a / */
248         strcat(page, "/");
249       strcat(page, name);
250     }
251   } else {
252     page = strdup(name);
253   }
254
255   /* debug: show which codepage directory we are using */
256   syslog(LOG_DEBUG, "using codepage directory: %s", page);
257
258   return page;
259 }
260
261 /* handle all the options. tmp can't be NULL. */
262 static void volset(struct vol_option *options, char *volname, int vlen, 
263                    const char *nlspath, const char *tmp)
264 {
265   char *val;
266
267   val = strchr(tmp, ':');
268   if (optionok(tmp, "allow:", val)) {
269     if (options[VOLOPT_ALLOW].c_value)
270       free(options[VOLOPT_ALLOW].c_value);
271     options[VOLOPT_ALLOW].c_value = strdup(val + 1);
272
273   } else if (optionok(tmp, "deny:", val)) {
274     if (options[VOLOPT_DENY].c_value)
275       free(options[VOLOPT_DENY].c_value);
276     options[VOLOPT_DENY].c_value = strdup(val + 1);
277
278   } else if (optionok(tmp, "rwlist:", val)) {
279     if (options[VOLOPT_RWLIST].c_value)
280       free(options[VOLOPT_RWLIST].c_value);
281     options[VOLOPT_RWLIST].c_value = strdup(val + 1);
282
283   } else if (optionok(tmp, "rolist:", val)) {
284     if (options[VOLOPT_ROLIST].c_value)
285       free(options[VOLOPT_ROLIST].c_value);
286     options[VOLOPT_ROLIST].c_value = strdup(val + 1);
287
288   } else if (optionok(tmp, "codepage:", val)) {
289     if (options[VOLOPT_CODEPAGE].c_value)
290       free(options[VOLOPT_CODEPAGE].c_value);
291     options[VOLOPT_CODEPAGE].c_value = get_codepage_path(nlspath, val + 1);
292
293   } else if (optionok(tmp, "casefold:", val)) {
294     if (strcasecmp(val + 1, "tolower") == 0)
295       options[VOLOPT_CASEFOLD].i_value = AFPVOL_UMLOWER;
296     else if (strcasecmp(val + 1, "toupper") == 0)
297       options[VOLOPT_CASEFOLD].i_value = AFPVOL_UMUPPER;
298     else if (strcasecmp(val + 1, "xlatelower") == 0)
299       options[VOLOPT_CASEFOLD].i_value = AFPVOL_UUPPERMLOWER;
300     else if (strcasecmp(val + 1, "xlateupper") == 0)
301       options[VOLOPT_CASEFOLD].i_value = AFPVOL_ULOWERMUPPER;
302
303   } else if (optionok(tmp, "options:", val)) {
304     char *p;
305     
306     if ((p = strtok(val + 1, ",")) == NULL) /* nothing */
307       return;
308     
309     while (p) {
310       if (strcasecmp(p, "prodos") == 0)
311         options[VOLOPT_FLAGS].i_value |= AFPVOL_A2VOL;
312       else if (strcasecmp(p, "mswindows") == 0) {
313         options[VOLOPT_FLAGS].i_value |= AFPVOL_MSWINDOWS;
314         if (!options[VOLOPT_CODEPAGE].c_value)
315           options[VOLOPT_CODEPAGE].c_value = 
316             get_codepage_path(nlspath, MSWINDOWS_CODEPAGE);
317
318       } else if (strcasecmp(p, "crlf") == 0)
319         options[VOLOPT_FLAGS].i_value |= AFPVOL_CRLF;
320       else if (strcasecmp(p, "noadouble") == 0)
321         options[VOLOPT_FLAGS].i_value |= AFPVOL_NOADOUBLE;
322       else if (strcasecmp(p, "ro") == 0)
323         options[VOLOPT_FLAGS].i_value |= AFPVOL_RO;
324       else if (strcasecmp(p, "nohex") == 0)
325         options[VOLOPT_FLAGS].i_value |= AFPVOL_NOHEX;
326       else if (strcasecmp(p, "usedots") == 0)
327         options[VOLOPT_FLAGS].i_value |= AFPVOL_USEDOTS;
328       else if (strcasecmp(p, "limitsize") == 0)
329         options[VOLOPT_FLAGS].i_value |= AFPVOL_LIMITSIZE;
330
331       p = strtok(NULL, ",");
332     }
333
334 #if AD_VERSION > AD_VERSION1
335   } else if (optionok(tmp, "dbpath:", val)) {
336     if (options[VOLOPT_DBPATH].c_value)
337       free(options[VOLOPT_DBPATH].c_value);
338     
339     options[VOLOPT_DBPATH].c_value = strdup(val + 1);
340 #endif
341   } else if (optionok(tmp, "mapchars:",val)) {
342     if (options[VOLOPT_MAPCHARS].c_value)
343       free(options[VOLOPT_MAPCHARS].c_value);
344     options[VOLOPT_MAPCHARS].c_value = strdup(val + 1);
345
346   } else if (optionok(tmp, "password:", val)) {
347     if (options[VOLOPT_PASSWORD].c_value)
348       free(options[VOLOPT_PASSWORD].c_value);
349     options[VOLOPT_PASSWORD].c_value = strdup(val + 1);
350
351 #ifdef FORCE_UIDGID
352
353         /* this code allows forced uid/gid per volume settings */
354   } else if (optionok(tmp, "forceuid:", val)) {
355     if (options[VOLOPT_FORCEUID].c_value)
356       free(options[VOLOPT_FORCEUID].c_value);
357     options[VOLOPT_FORCEUID].c_value = strdup(val + 1);
358   } else if (optionok(tmp, "forcegid:", val)) {
359     if (options[VOLOPT_FORCEGID].c_value)
360       free(options[VOLOPT_FORCEGID].c_value);
361     options[VOLOPT_FORCEGID].c_value = strdup(val + 1);
362
363 #endif FORCE_UIDGID
364
365   } else if (val) {
366     /* ignore unknown options */
367     syslog(LOG_DEBUG, "ignoring unknown volume option: %s", tmp);
368
369   } else {
370     /* we'll assume it's a volume name. */
371     strncpy(volname, tmp, vlen); 
372   }
373 }
374
375 static int creatvol(const char *path, char *name, struct vol_option *options)
376 {
377     struct vol  *volume;
378     int         vlen;
379
380     if ( name == NULL || *name == '\0' ) {
381         if ((name = strrchr( path, '/' )) == NULL) {
382             return -1;  /* Obviously not a fully qualified path */
383         }
384
385         /* if you wish to share /, you need to specify a name. */
386         if (*++name == '\0')   
387           return -1; 
388     }
389
390     for ( volume = volumes; volume; volume = volume->v_next ) {
391         if ( strcasecmp( volume->v_name, name ) == 0 ) {
392             return -1;  /* Won't be able to access it, anyway... */
393         }
394     }
395
396     vlen = strlen( name );
397     if ( vlen > AFPVOL_NAMELEN ) {
398         vlen = AFPVOL_NAMELEN;
399         name[AFPVOL_NAMELEN] = '\0';
400     }
401
402     if (( volume =
403             (struct vol *)calloc(1, sizeof( struct vol ))) == NULL ) {
404         syslog( LOG_ERR, "creatvol: malloc: %m" );
405         return -1;
406     }
407     if (( volume->v_name =
408             (char *)malloc( vlen + 1 )) == NULL ) {
409         syslog( LOG_ERR, "creatvol: malloc: %m" );
410         free(volume);
411         return -1;
412     }
413     if (( volume->v_path =
414             (char *)malloc( strlen( path ) + 1 )) == NULL ) {
415         syslog( LOG_ERR, "creatvol: malloc: %m" );
416         free(volume->v_name);
417         free(volume);
418         return -1;
419     }
420
421     strcpy( volume->v_name, name);
422     strcpy( volume->v_path, path );
423
424 #ifdef __svr4__
425     volume->v_qfd = -1;
426 #endif
427     volume->v_vid = lastvid++;
428     volume->v_lastdid = 3;
429
430     /* handle options */
431     if (options) {
432       /* should we casefold? */
433       volume->v_casefold = options[VOLOPT_CASEFOLD].i_value;
434
435       /* shift in some flags */
436       volume->v_flags = options[VOLOPT_FLAGS].i_value;
437
438       /* read in the code pages */
439       if (options[VOLOPT_CODEPAGE].c_value)
440         codepage_read(volume, options[VOLOPT_CODEPAGE].c_value);
441
442       if (options[VOLOPT_PASSWORD].c_value) 
443         volume->v_password = strdup(options[VOLOPT_PASSWORD].c_value);
444
445 #if AD_VERSION > AD_VERSION1
446       if (options[VOLOPT_DBPATH].c_value)
447         volume->v_dbpath = strdup(options[VOLOPT_DBPATH].c_value);
448 #endif
449
450 #ifdef FORCE_UIDGID
451
452           if (options[VOLOPT_FORCEUID].c_value) {
453         volume->v_forceuid = strdup(options[VOLOPT_FORCEUID].c_value);
454           } else {
455         volume->v_forceuid = NULL; /* set as null so as to return 0 later on */
456           }
457
458           if (options[VOLOPT_FORCEGID].c_value) {
459         volume->v_forcegid = strdup(options[VOLOPT_FORCEGID].c_value);
460           } else {
461         volume->v_forcegid = NULL; /* set as null so as to return 0 later on */
462           }
463
464 #endif FORCE_UIDGID
465
466     }
467
468     volume->v_next = volumes;
469     volumes = volume;
470     return 0;
471 }
472
473 static char *myfgets( buf, size, fp )
474     char        *buf;
475     int         size;
476     FILE        *fp;
477 {
478     char        *p;
479     int         c;
480
481     p = buf;
482     while ((( c = getc( fp )) != EOF ) && ( size > 0 )) {
483         if ( c == '\n' || c == '\r' ) {
484             *p++ = '\n';
485             break;
486         } else {
487             *p++ = c;
488         }
489         size--;
490     }
491
492     if ( p == buf ) {
493         return( NULL );
494     } else {
495         *p = '\0';
496         return( buf );
497     }
498 }
499
500
501 /* check access list. this function wants something of the following
502  * form:
503  *        @group,name,name2,@group2,name3
504  *
505  * a NULL argument allows everybody to have access.
506  * we return three things:
507  *     -1: no list
508  *      0: list exists, but name isn't in it
509  *      1: in list
510  */
511 static int accessvol(args, name)
512     const char *args;
513     const char *name;
514 {
515     char buf[MAXPATHLEN + 1], *p;
516     struct group *gr;
517
518     if (!args)
519       return -1;
520
521     strncpy(buf, args, sizeof(buf));
522     if ((p = strtok(buf, ",")) == NULL) /* nothing, return okay */
523       return -1;
524
525     while (p) {
526       if (*p == '@') { /* it's a group */
527         if ((gr = getgrnam(p + 1)) && gmem(gr->gr_gid))
528             return 1;
529       } else if (strcmp(p, name) == 0) /* it's a user name */
530         return 1;
531       p = strtok(NULL, ",");
532     }
533
534     return 0;
535 }
536
537 static void setextmap( ext, type, creator, user)
538     char                *ext, *type, *creator;
539     int                 user;
540 {
541     struct extmap       *em;
542
543     for ( em = extmap; em; em = em->em_next ) {
544         if ( strdiacasecmp( em->em_ext, ext ) == 0 ) {
545             break;
546         }
547     }
548
549     if ( em == NULL ) {
550         if (( em =
551                 (struct extmap *)malloc( sizeof( struct extmap ))) == NULL ) {
552             syslog( LOG_ERR, "setextmap: malloc: %m" );
553             return;
554         }
555         em->em_next = extmap;
556         extmap = em;
557     } else if ( !user ) {
558         return;
559     }
560
561     strcpy( em->em_ext, ext );
562
563     if ( *type == '\0' ) {
564         memcpy(em->em_type, "????", sizeof( em->em_type ));
565     } else {
566         memcpy(em->em_type, type, sizeof( em->em_type ));
567     }
568     if ( *creator == '\0' ) {
569         memcpy(em->em_creator, "UNIX", sizeof( em->em_creator ));
570     } else {
571         memcpy(em->em_creator, creator, sizeof( em->em_creator ));
572     }
573
574     if ( strcmp( ext, "." ) == 0 ) {
575         defextmap = em;
576     }
577 }
578
579 /*
580  * Read a volume configuration file and add the volumes contained within to
581  * the global volume list.  If p2 is non-NULL, the file that is opened is
582  * p1/p2
583  *
584  * Lines that begin with # and blank lines are ignored.
585  * Volume lines are of the form:
586  *              <unix path> [<volume name>] [allow:<user>,<@group>,...] \
587  *                           [codepage:<file>] [casefold:<num>]
588  *              <extension> TYPE [CREATOR]
589  */
590 static int readvolfile(obj, p1, p2, user, pwent)
591     AFPObj      *obj;
592     char        *p1, *p2;
593     int         user;
594     struct passwd *pwent;
595 {
596     FILE                *fp;
597     char                path[ MAXPATHLEN + 1], tmp[ MAXPATHLEN + 1],
598                         volname[ AFPVOL_NAMELEN + 1 ], buf[ BUFSIZ ],
599                         type[ 5 ], creator[ 5 ];
600     char                *u, *p;
601     struct passwd       *pw;
602     struct vol_option   options[VOLOPT_NUM], save_options[VOLOPT_NUM];
603     int                 i;
604
605     if (!p1)
606         return -1;
607
608     strcpy( path, p1 );
609     if ( p2 != NULL ) {
610         strcat( path, "/" );
611         strcat( path, p2 );
612     }
613
614     if (( fp = fopen( path, "r" )) == NULL ) {
615         return( -1 );
616     }
617     
618     memset(save_options, 0, sizeof(save_options));
619     while ( myfgets( buf, sizeof( buf ), fp ) != NULL ) {
620         initline( strlen( buf ), buf );
621         parseline( sizeof( path ) - 1, path );
622         switch ( *path ) {
623         case '\0' :
624         case '#' :
625             continue;
626
627         case ':':
628           /* change the default options for this file */
629           if (strncmp(path, VOLOPT_DEFAULT, VOLOPT_DEFAULT_LEN) == 0) {
630             *tmp = '\0';
631             for (i = 0; i < VOLOPT_NUM; i++) {
632               if (parseline( sizeof( path ) - VOLOPT_DEFAULT_LEN - 1, 
633                              path + VOLOPT_DEFAULT_LEN) < 0)
634                 break;
635               volset(save_options, tmp, sizeof(tmp) - 1, 
636                      obj->options.nlspath, path + VOLOPT_DEFAULT_LEN);
637             }
638           }
639           break;
640
641         case '~' :
642             if (( p = strchr( path, '/' )) != NULL ) {
643                 *p++ = '\0';
644             }
645             u = path;
646             u++;
647             if ( *u == '\0' ) {
648                 u = obj->username;
649             }
650             if ( u == NULL || *u == '\0' || ( pw = getpwnam( u )) == NULL ) {
651                 continue;
652             }
653             strcpy( tmp, pw->pw_dir );
654             if ( p != NULL && *p != '\0' ) {
655                 strcat( tmp, "/" );
656                 strcat( tmp, p );
657             }
658             /* fall through */
659
660         case '/' :
661             /* send path through variable substitution */
662             if (*path != '~') /* need to copy path to tmp */
663               strcpy(tmp, path);
664             if (!pwent)
665               pwent = getpwnam(obj->username);
666             volxlate(obj, path, sizeof(path) - 1, tmp, pwent, NULL);
667
668             /* this is sort of braindead. basically, i want to be
669              * able to specify things in any order, but i don't want to 
670              * re-write everything. 
671              *
672              * currently we have 11 options: 
673              *   volname
674              *   codepage:x
675              *   casefold:x
676              *   allow:x,y,@z
677              *   deny:x,y,@z
678              *   rwlist:x,y,@z
679              *   rolist:x,y,@z
680              *   options:prodos,crlf,noadouble,ro
681              *   dbpath:x
682              *   password:x
683              *   namemask:x,y,!z  (not implemented yet)
684              */
685             memcpy(options, save_options, sizeof(options));
686             *volname = '\0';
687
688             /* read in up to 11 possible options */
689             for (i = 0; i < VOLOPT_NUM; i++) {
690               if (parseline( sizeof( tmp ) - 1, tmp ) < 0)
691                 break;
692
693               volset(options, volname, sizeof(volname) - 1, 
694                      obj->options.nlspath, tmp);
695             }
696
697             /* check allow/deny lists: 
698                allow -> either no list (-1), or in list (1)
699                deny -> either no list (-1), or not in list (0) */
700             if (accessvol(options[VOLOPT_ALLOW].c_value, obj->username) &&
701                 (accessvol(options[VOLOPT_DENY].c_value, obj->username) < 1)) {
702
703               /* handle read-only behaviour. semantics: 
704                * 1) neither the rolist nor the rwlist exist -> rw
705                * 2) rolist exists -> ro if user is in it.
706                * 3) rwlist exists -> ro unless user is in it. */
707               if (((options[VOLOPT_FLAGS].i_value & AFPVOL_RO) == 0) && 
708                   ((accessvol(options[VOLOPT_ROLIST].c_value, 
709                               obj->username) == 1) ||
710                    !accessvol(options[VOLOPT_RWLIST].c_value, 
711                               obj->username))) 
712                 options[VOLOPT_FLAGS].i_value |= AFPVOL_RO;
713
714               /* do variable substitution */
715               volxlate(obj, tmp, sizeof(tmp) - 1, volname, pwent, path);
716               creatvol(path, tmp, options);
717             }
718             volfree(options, save_options);
719             break;
720
721         case '.' :
722             parseline( sizeof( type ) - 1, type );
723             parseline( sizeof( creator ) - 1, creator );
724             setextmap( path, type, creator, user);
725             break;
726
727         default :
728             break;
729         }
730     }
731     volfree(save_options, NULL);
732     if ( fclose( fp ) != 0 ) {
733         syslog( LOG_ERR, "readvolfile: fclose: %m" );
734     }
735     return( 0 );
736 }
737
738
739 static void load_volumes(AFPObj *obj)
740 {
741   struct passwd *pwent = getpwnam(obj->username);
742
743   if ( (obj->options.flags & OPTION_USERVOLFIRST) == 0 ) {
744     readvolfile(obj, obj->options.systemvol, 0, pwent);
745   }
746
747   if ((*obj->username == '\0') || (obj->options.flags & OPTION_NOUSERVOL)) {
748     readvolfile(obj, obj->options.defaultvol, NULL, 1, pwent);
749   } else if (pwent) {
750         /*
751          * Read user's AppleVolumes or .AppleVolumes file
752          * If neither are readable, read the default volumes file. if 
753          * that doesn't work, create a user share.
754          */
755     if ( readvolfile(obj, pwent->pw_dir, "AppleVolumes", 1, pwent) < 0 &&
756          readvolfile(obj, pwent->pw_dir, ".AppleVolumes", 1, pwent) < 0 &&
757          readvolfile(obj, pwent->pw_dir, "applevolumes", 1, pwent) < 0 &&
758          readvolfile(obj, pwent->pw_dir, ".applevolumes", 1, pwent) < 0 &&
759          obj->options.defaultvol != NULL ) {
760       if (readvolfile(obj, obj->options.defaultvol, NULL, 1, pwent) < 0)
761         creatvol(pwent->pw_dir, NULL, NULL);
762     }
763   }
764   if ( obj->options.flags & OPTION_USERVOLFIRST ) {
765     readvolfile(obj, obj->options.systemvol, NULL, 0, pwent );
766   }
767 }
768
769 static int getvolspace( vol, bfree, btotal, xbfree, xbtotal, bsize )
770     struct vol  *vol;
771     u_int32_t   *bfree, *btotal, *bsize;
772     VolSpace    *xbfree, *xbtotal;
773 {
774     int         spaceflag, rc;
775     u_int32_t   maxsize;
776 #ifndef NO_QUOTA_SUPPORT
777     VolSpace    qfree, qtotal;
778 #endif
779
780     spaceflag = AFPVOL_GVSMASK & vol->v_flags;
781     /* report up to 2GB if afp version is < 2.2 (4GB if not) */
782     maxsize = (vol->v_flags & AFPVOL_A2VOL) ? 0x01fffe00 :
783       (((afp_version < 22) || (vol->v_flags & AFPVOL_LIMITSIZE))
784        ? 0x7fffffffL : 0xffffffffL);
785
786 #ifdef AFS
787     if ( spaceflag == AFPVOL_NONE || spaceflag == AFPVOL_AFSGVS ) {
788         if ( afs_getvolspace( vol, xbfree, xbtotal, bsize ) == AFP_OK ) {
789             vol->v_flags = ( ~AFPVOL_GVSMASK & vol->v_flags ) | AFPVOL_AFSGVS;
790             goto getvolspace_done;
791         }
792     }
793 #endif AFS
794
795     if (( rc = ustatfs_getvolspace( vol, xbfree, xbtotal,
796                                     bsize)) != AFP_OK ) {
797         return( rc );
798     }
799
800 #define min(a,b)        ((a)<(b)?(a):(b))
801 #ifndef NO_QUOTA_SUPPORT
802     if ( spaceflag == AFPVOL_NONE || spaceflag == AFPVOL_UQUOTA ) {
803         if ( uquota_getvolspace( vol, &qfree, &qtotal, *bsize ) == AFP_OK ) {
804             vol->v_flags = ( ~AFPVOL_GVSMASK & vol->v_flags ) | AFPVOL_UQUOTA;
805             *xbfree = min(*xbfree, qfree);
806             *xbtotal = min( *xbtotal, qtotal);
807             goto getvolspace_done;
808         }
809     }
810 #endif
811     vol->v_flags = ( ~AFPVOL_GVSMASK & vol->v_flags ) | AFPVOL_USTATFS;
812
813 getvolspace_done:
814     *bfree = min( *xbfree, maxsize);
815     *btotal = min( *xbtotal, maxsize);
816     return( AFP_OK );
817 }
818
819 static int getvolparams( bitmap, vol, st, buf, buflen )
820     u_int16_t   bitmap;
821     struct vol  *vol;
822     struct stat *st;
823     char        *buf;
824     int         *buflen;
825 {
826     struct adouble      ad;
827     int                 bit = 0, aint, isad = 1;
828     u_short             ashort;
829     u_int32_t           bfree, btotal, bsize;
830     VolSpace            xbfree, xbtotal; /* extended bytes */
831     char                *data, *nameoff = NULL;
832     char                *slash;
833
834     /* courtesy of jallison@whistle.com:
835      * For MacOS8.x support we need to create the
836      * .Parent file here if it doesn't exist. */
837     
838     memset(&ad, 0, sizeof(ad));
839     if ( ad_open( vol->v_path, vol_noadouble(vol) | 
840                   ADFLAGS_HF|ADFLAGS_DIR, O_RDWR | O_CREAT, 
841                   0666, &ad) < 0 ) {
842           isad = 0;
843
844     } else if (ad_getoflags( &ad, ADFLAGS_HF ) & O_CREAT) {
845           slash = strrchr( vol->v_path, '/' );
846           if(slash)
847               slash++;
848           else
849               slash = vol->v_path;
850
851           ad_setentrylen( &ad, ADEID_NAME, strlen( slash ));
852           memcpy(ad_entry( &ad, ADEID_NAME ), slash, 
853                  ad_getentrylen( &ad, ADEID_NAME ));
854           ad_flush(&ad, ADFLAGS_HF);
855     }
856
857     if (( bitmap & ( (1<<VOLPBIT_BFREE)|(1<<VOLPBIT_BTOTAL) |
858                      (1<<VOLPBIT_XBFREE)|(1<<VOLPBIT_XBTOTAL) |
859                      (1<<VOLPBIT_BSIZE)) ) != 0 ) {
860         if ( getvolspace( vol, &bfree, &btotal, &xbfree, &xbtotal,
861                           &bsize) < 0 ) {
862             if ( isad ) {
863                 ad_close( &ad, ADFLAGS_HF );
864             }
865             return( AFPERR_PARAM );
866         }
867     }
868
869     data = buf;
870     while ( bitmap != 0 ) {
871         while (( bitmap & 1 ) == 0 ) {
872             bitmap = bitmap>>1;
873             bit++;
874         }
875
876         switch ( bit ) {
877         case VOLPBIT_ATTR :
878 #if AD_VERSION > AD_VERSION1
879             ashort = VOLPBIT_ATTR_FILEID;
880 #else
881             ashort = 0;
882 #endif
883             /* check for read-only.
884              * NOTE: we don't actually set the read-only flag unless
885              *       it's passed in that way as it's possible to mount
886              *       a read-write filesystem under a read-only one. */
887             if ((vol->v_flags & AFPVOL_RO) ||
888                 ((utime(vol->v_path, NULL) < 0) && (errno == EROFS)))
889               ashort |= VOLPBIT_ATTR_RO;
890             ashort = htons(ashort);
891             memcpy(data, &ashort, sizeof( ashort ));
892             data += sizeof( ashort );
893             break;
894
895         case VOLPBIT_SIG :
896             ashort = htons( AFPVOLSIG_DEFAULT );
897             memcpy(data, &ashort, sizeof( ashort ));
898             data += sizeof( ashort );
899             break;
900
901         case VOLPBIT_CDATE :
902             if (!isad || (ad_getdate(&ad, AD_DATE_CREATE, &aint) < 0))
903                 aint = AD_DATE_FROM_UNIX(st->st_mtime);
904             memcpy(data, &aint, sizeof( aint ));
905             data += sizeof( aint );
906             break;
907
908         case VOLPBIT_MDATE :
909             if ( st->st_mtime > vol->v_time ) {
910                 vol->v_time = st->st_mtime;
911                 aint = AD_DATE_FROM_UNIX(st->st_mtime);
912             } else {
913                 aint = AD_DATE_FROM_UNIX(vol->v_time);
914             }
915             memcpy(data, &aint, sizeof( aint ));
916             data += sizeof( aint );
917             break;
918
919         case VOLPBIT_BDATE :
920             if (!isad ||  (ad_getdate(&ad, AD_DATE_BACKUP, &aint) < 0))
921                 aint = AD_DATE_START;
922             memcpy(data, &aint, sizeof( aint ));
923             data += sizeof( aint );
924             break;
925
926         case VOLPBIT_VID :
927             memcpy(data, &vol->v_vid, sizeof( vol->v_vid ));
928             data += sizeof( vol->v_vid );
929             break;
930
931         case VOLPBIT_BFREE :
932             bfree = htonl( bfree );
933             memcpy(data, &bfree, sizeof( bfree ));
934             data += sizeof( bfree );
935             break;
936
937         case VOLPBIT_BTOTAL :
938             btotal = htonl( btotal );
939             memcpy(data, &btotal, sizeof( btotal ));
940             data += sizeof( btotal );
941             break;
942
943 #ifndef NO_LARGE_VOL_SUPPORT
944         case VOLPBIT_XBFREE :
945             xbfree = hton64( xbfree );
946 #if defined(__GNUC__) && defined(HAVE_GCC_MEMCPY_BUG)
947             bcopy(&xbfree, data, sizeof(xbfree));
948 #else
949             memcpy(data, &xbfree, sizeof( xbfree ));
950 #endif
951             data += sizeof( xbfree );
952             break;
953
954         case VOLPBIT_XBTOTAL :
955             xbtotal = hton64( xbtotal );
956 #if defined(__GNUC__) && defined(HAVE_GCC_MEMCPY_BUG)
957             bcopy(&xbtotal, data, sizeof(xbtotal));
958 #else
959             memcpy(data, &xbtotal, sizeof( xbtotal ));
960 #endif
961             data += sizeof( xbfree );
962             break;
963 #endif
964
965         case VOLPBIT_NAME :
966             nameoff = data;
967             data += sizeof( u_int16_t );
968             break;
969
970         case VOLPBIT_BSIZE:  /* block size */
971             bsize = htonl(bsize);
972             memcpy(data, &bsize, sizeof(bsize));
973             data += sizeof(bsize);
974             break;
975
976         default :
977             if ( isad ) {
978                 ad_close( &ad, ADFLAGS_HF );
979             }
980             return( AFPERR_BITMAP );
981         }
982         bitmap = bitmap>>1;
983         bit++;
984     }
985     if ( nameoff ) {
986         ashort = htons( data - buf );
987         memcpy(nameoff, &ashort, sizeof( ashort ));
988         aint = strlen( vol->v_name );
989         *data++ = aint;
990         memcpy(data, vol->v_name, aint );
991         data += aint;
992     }
993     if ( isad ) {
994         ad_close( &ad, ADFLAGS_HF );
995     }
996     *buflen = data - buf;
997     return( AFP_OK );
998 }
999
1000
1001
1002 int afp_getsrvrparms(obj, ibuf, ibuflen, rbuf, rbuflen )
1003     AFPObj      *obj;
1004     char        *ibuf, *rbuf;
1005     int         ibuflen, *rbuflen;
1006 {
1007     struct timeval      tv;
1008     struct stat         st;
1009     struct vol          *volume;
1010     char        *data;
1011     int                 vcnt, len;
1012
1013   
1014     if (!volumes)
1015       load_volumes(obj);
1016
1017     data = rbuf + 5;
1018     for ( vcnt = 0, volume = volumes; volume; volume = volume->v_next ) {
1019         if ( stat( volume->v_path, &st ) < 0 ) {
1020             syslog( LOG_INFO, "afp_getsrvrparms: stat %s: %m", 
1021                     volume->v_path );
1022             continue;           /* can't access directory */
1023         }
1024         if (!S_ISDIR(st.st_mode)) {
1025             continue;           /* not a dir */
1026         }
1027
1028         /* set password bit if there's a volume password */
1029         *data = (volume->v_password) ? AFPSRVR_PASSWD : 0;
1030
1031         /* Apple 2 clients running ProDOS-8 expect one volume to have
1032            bit 0 of this byte set.  They will not recognize anything
1033            on the server unless this is the case.  I have not
1034            completely worked this out, but it's related to booting
1035            from the server.  Support for that function is a ways
1036            off.. <shirsch@ibm.net> */
1037         *data++ |= (volume->v_flags & AFPVOL_A2VOL) ? AFPSRVR_CONFIGINFO : 0;
1038         len = strlen( volume->v_name );
1039         *data++ = len;
1040         memcpy(data, volume->v_name, len );
1041         data += len;
1042         vcnt++;
1043     }
1044
1045     *rbuflen = data - rbuf;
1046     data = rbuf;
1047     if ( gettimeofday( &tv, 0 ) < 0 ) {
1048         syslog( LOG_ERR, "afp_getsrvrparms: gettimeofday: %m" );
1049         *rbuflen = 0;
1050         return AFPERR_PARAM;
1051     }
1052     tv.tv_sec = AD_DATE_FROM_UNIX(tv.tv_sec);
1053     memcpy(data, &tv.tv_sec, sizeof( u_int32_t));
1054     data += sizeof( u_int32_t);
1055     *data = vcnt;
1056     return( AFP_OK );
1057 }
1058
1059 int afp_openvol(obj, ibuf, ibuflen, rbuf, rbuflen )
1060     AFPObj      *obj;
1061     char        *ibuf, *rbuf;
1062     int         ibuflen, *rbuflen;
1063 {
1064     struct stat st;
1065     char        *volname;
1066 #if AD_VERSION == AD_VERSION1
1067     char *p;
1068 #endif
1069     struct vol  *volume;
1070     struct dir  *dir;
1071     int         len, ret, buflen;
1072     u_int16_t   bitmap;
1073
1074     ibuf += 2;
1075     memcpy(&bitmap, ibuf, sizeof( bitmap ));
1076     bitmap = ntohs( bitmap );
1077     ibuf += sizeof( bitmap );
1078     if (( bitmap & (1<<VOLPBIT_VID)) == 0 ) {
1079         ret = AFPERR_BITMAP;
1080         goto openvol_err;
1081     }
1082
1083     len = (unsigned char)*ibuf++;
1084     volname = obj->oldtmp;
1085     memcpy(volname, ibuf, len );
1086     *(volname +  len) = '\0';
1087     ibuf += len;
1088     if ((len + 1) & 1) /* pad to an even boundary */
1089       ibuf++;
1090
1091     if (!volumes)
1092       load_volumes(obj);
1093
1094     for ( volume = volumes; volume; volume = volume->v_next ) {
1095         if ( strcasecmp( volname, volume->v_name ) == 0 ) {
1096             break;
1097         }
1098     }
1099
1100     if ( volume == NULL ) {
1101         ret = AFPERR_PARAM;
1102         goto openvol_err;
1103     }
1104
1105     /* check for a volume password */
1106     if (volume->v_password && 
1107         strncmp(ibuf, volume->v_password, VOLPASSLEN)) {
1108         ret = AFPERR_ACCESS;
1109         goto openvol_err;
1110     }
1111
1112     if (( volume->v_flags & AFPVOL_OPEN  ) == 0 ) {
1113         if ((dir = dirnew(strlen(volume->v_name) + 1)) == NULL) {
1114             syslog( LOG_ERR, "afp_openvol: malloc: %m" );
1115             ret = AFPERR_MISC;
1116             goto openvol_err;
1117         }
1118         dir->d_did = DIRDID_ROOT;
1119         dir->d_color = DIRTREE_COLOR_BLACK; /* root node is black */
1120         strcpy( dir->d_name, volume->v_name );
1121         volume->v_dir = volume->v_root = dir;
1122         volume->v_flags |= AFPVOL_OPEN;
1123     }
1124
1125     if ( stat( volume->v_path, &st ) < 0 ) {
1126         ret = AFPERR_PARAM;
1127         goto openvol_err;
1128     }
1129
1130     buflen = *rbuflen - sizeof( bitmap );
1131     if (( ret = getvolparams( bitmap, volume, &st,
1132             rbuf + sizeof(bitmap), &buflen )) != AFP_OK ) {
1133         goto openvol_err;
1134     }
1135     *rbuflen = buflen + sizeof( bitmap );
1136     bitmap = htons( bitmap );
1137     memcpy(rbuf, &bitmap, sizeof( bitmap ));
1138
1139     curdir = volume->v_dir;
1140     if ( chdir( volume->v_path ) < 0 ) {
1141         ret = AFPERR_PARAM;
1142         goto openvol_err;
1143     }
1144 #if AD_VERSION == AD_VERSION1
1145     /*
1146      * If you mount a volume twice, the second time the trash appears on
1147      * the desk-top.  That's because the Mac remembers the DID for the
1148      * trash (even for volumes in different zones, on different servers).
1149      * Just so this works better, we prime the DID cache with the trash,
1150      * fixing the trash at DID 3.
1151      */
1152     p = Trash;
1153     cname( volume, volume->v_dir, &p );
1154 #endif
1155
1156     return( AFP_OK );
1157
1158 openvol_err:
1159     *rbuflen = 0;
1160     return ret;
1161 }
1162
1163 int afp_closevol(obj, ibuf, ibuflen, rbuf, rbuflen )
1164     AFPObj      *obj;
1165     char        *ibuf, *rbuf;
1166     int         ibuflen, *rbuflen;
1167 {
1168     struct vol  *vol, *ovol;
1169     u_int16_t   vid;
1170
1171     *rbuflen = 0;
1172     ibuf += 2;
1173     memcpy(&vid, ibuf, sizeof( vid ));
1174     if (( vol = getvolbyvid( vid )) == NULL ) {
1175         return( AFPERR_PARAM );
1176     }
1177
1178     vol->v_flags &= ~AFPVOL_OPEN;
1179     for ( ovol = volumes; ovol; ovol = ovol->v_next ) {
1180         if ( ovol->v_flags & AFPVOL_OPEN ) {
1181             break;
1182         }
1183     }
1184     if ( ovol != NULL ) {
1185         curdir = ovol->v_dir;
1186         if ( chdir( ovol->v_path ) < 0 ) {
1187             return( AFPERR_PARAM );
1188         }
1189     }
1190
1191     dirfree( vol->v_root );
1192     vol->v_dir = NULL;
1193 #if AD_VERSION > AD_VERSION1
1194     cnid_close(vol->v_db);
1195     vol->v_db = NULL;
1196 #endif
1197     return( AFP_OK );
1198 }
1199
1200 struct vol *getvolbyvid(const u_int16_t vid )
1201 {
1202     struct vol  *vol;
1203
1204     for ( vol = volumes; vol; vol = vol->v_next ) {
1205         if ( vid == vol->v_vid ) {
1206             break;
1207         }
1208     }
1209     if ( vol == NULL || ( vol->v_flags & AFPVOL_OPEN ) == 0 ) {
1210         return( NULL );
1211     }
1212
1213     return( vol );
1214 }
1215
1216 struct extmap *getextmap(const char *path)
1217 {
1218     char        *p;
1219     struct extmap       *em;
1220
1221     if (( p = strrchr( path, '.' )) == NULL ) {
1222         return( defextmap );
1223     }
1224
1225     for ( em = extmap; em; em = em->em_next ) {
1226         if ( strdiacasecmp( em->em_ext, p ) == 0 ) {
1227             break;
1228         }
1229     }
1230     if ( em == NULL ) {
1231         return( defextmap );
1232     } else {
1233         return( em );
1234     }
1235 }
1236
1237 void setvoltime(obj, vol )
1238     AFPObj *obj;
1239     struct vol  *vol;
1240 {
1241     struct timeval      tv;
1242
1243     /* just looking at vol->v_time is broken seriously since updates
1244      * from other users afpd processes never are seen.
1245      * This is not the most elegant solution (a shared memory between
1246      * the afpd processes would come closer)
1247      * [RS] */
1248
1249     if ( gettimeofday( &tv, 0 ) < 0 ) {
1250         syslog( LOG_ERR, "setvoltime: gettimeofday: %m" );
1251         return;
1252     }
1253     if( utime( vol->v_path, NULL ) < 0 ) {
1254         /* write of time failed ... probably a read only filesys,
1255          * where no other users can interfere, so there's no issue here
1256          */
1257     }
1258     
1259     /* a little granularity */
1260     if (vol->v_time < tv.tv_sec) {
1261       vol->v_time = tv.tv_sec;
1262       obj->attention(obj->handle, AFPATTN_NOTIFY | AFPATTN_VOLCHANGED);
1263     }
1264 }
1265
1266 int afp_getvolparams(obj, ibuf, ibuflen, rbuf, rbuflen )
1267     AFPObj      *obj;
1268     char        *ibuf, *rbuf;
1269     int         ibuflen, *rbuflen;
1270 {
1271     struct stat st;
1272     struct vol  *vol;
1273     int         buflen, ret;
1274     u_int16_t   vid, bitmap;
1275
1276     ibuf += 2;
1277     memcpy(&vid, ibuf, sizeof( vid ));
1278     ibuf += sizeof( vid );
1279     memcpy(&bitmap, ibuf, sizeof( bitmap ));
1280     bitmap = ntohs( bitmap );
1281
1282     if (( vol = getvolbyvid( vid )) == NULL ) {
1283         *rbuflen = 0;
1284         return( AFPERR_PARAM );
1285     }
1286
1287     if ( stat( vol->v_path, &st ) < 0 ) {
1288         *rbuflen = 0;
1289         return( AFPERR_PARAM );
1290     }
1291
1292     buflen = *rbuflen - sizeof( bitmap );
1293     if (( ret = getvolparams( bitmap, vol, &st,
1294             rbuf + sizeof( bitmap ), &buflen )) != AFP_OK ) {
1295         *rbuflen = 0;
1296         return( ret );
1297     }
1298     *rbuflen = buflen + sizeof( bitmap );
1299     bitmap = htons( bitmap );
1300     memcpy(rbuf, &bitmap, sizeof( bitmap ));
1301     return( AFP_OK );
1302 }
1303
1304 int afp_setvolparams(obj, ibuf, ibuflen, rbuf, rbuflen )
1305     AFPObj      *obj;
1306     char        *ibuf, *rbuf;
1307     int         ibuflen, *rbuflen;
1308 {
1309     struct adouble ad;
1310     struct vol  *vol;
1311     u_int16_t   vid, bitmap;
1312     u_int32_t   aint;
1313
1314     ibuf += 2;
1315     *rbuflen = 0;
1316
1317     memcpy(&vid, ibuf, sizeof( vid ));
1318     ibuf += sizeof( vid );
1319     memcpy(&bitmap, ibuf, sizeof( bitmap ));
1320     bitmap = ntohs( bitmap );
1321     ibuf += sizeof(bitmap);
1322
1323     if (( vol = getvolbyvid( vid )) == NULL ) {
1324         return( AFPERR_PARAM );
1325     }
1326
1327     if (vol->v_flags & AFPVOL_RO)
1328         return AFPERR_VLOCK;
1329
1330     /* we can only set the backup date. */
1331     if (bitmap != VOLPBIT_BDATE)
1332       return AFPERR_BITMAP;
1333
1334     memset(&ad, 0, sizeof(ad));
1335     if ( ad_open( vol->v_path, ADFLAGS_HF|ADFLAGS_DIR, O_RDWR, 
1336                   0666, &ad) < 0 ) {
1337       if (errno == EROFS)
1338         return AFPERR_VLOCK;
1339
1340       return AFPERR_ACCESS;
1341     }
1342
1343     memcpy(&aint, ibuf, sizeof(aint));
1344     ad_setdate(&ad, AD_DATE_BACKUP, aint);
1345     ad_flush(&ad, ADFLAGS_HF);
1346     ad_close(&ad, ADFLAGS_HF);
1347     return( AFP_OK );
1348 }