2 * $Id: volume.c,v 1.51.2.6 2003-06-23 10:25:08 didg Exp $
4 * Copyright (c) 1990,1993 Regents of The University of Michigan.
5 * All Rights Reserved. See COPYRIGHT.
10 #endif /* HAVE_CONFIG_H */
13 #include <atalk/logger.h>
14 #include <sys/types.h>
16 #include <sys/param.h>
17 #include <sys/socket.h>
18 #include <netinet/in.h>
19 #include <arpa/inet.h>
20 #include <netatalk/endian.h>
21 #include <atalk/asp.h>
22 #include <atalk/dsi.h>
23 #include <atalk/adouble.h>
24 #include <atalk/afp.h>
25 #include <atalk/util.h>
27 #include <atalk/cnid.h>
32 #endif /* HAVE_FCNTL_H */
40 #else /* STDC_HEADERS */
44 #endif /* HAVE_STRCHR */
45 char *strchr (), *strrchr ();
47 #define memcpy(d,s,n) bcopy ((s), (d), (n))
48 #define memmove(d,s,n) bcopy ((s), (d), (n))
49 #endif /* ! HAVE_MEMCPY */
50 #endif /* STDC_HEADERS */
57 #include "directory.h"
63 extern int afprun(int root, char *cmd, int *outfd);
66 #define MIN(a, b) ((a) < (b) ? (a) : (b))
69 #ifndef NO_LARGE_VOL_SUPPORT
70 #if BYTE_ORDER == BIG_ENDIAN
73 #else /* BYTE_ORDER == BIG_ENDIAN */
74 #define hton64(x) ((u_int64_t) (htonl(((x) >> 32) & 0xffffffffLL)) | \
75 (u_int64_t) ((htonl(x) & 0xffffffffLL) << 32))
76 #define ntoh64(x) (hton64(x))
77 #endif /* BYTE_ORDER == BIG_ENDIAN */
78 #endif /* ! NO_LARGE_VOL_SUPPORT */
80 static struct vol *Volumes = NULL;
81 static int lastvid = 0;
83 static char *Trash = "\02\024Network Trash Folder";
86 static struct extmap *Extmap = NULL, *Defextmap = NULL;
87 static int Extmap_cnt;
88 static void free_extmap(void);
90 #define VOLOPT_ALLOW 0 /* user allow list */
91 #define VOLOPT_DENY 1 /* user deny list */
92 #define VOLOPT_RWLIST 2 /* user rw list */
93 #define VOLOPT_ROLIST 3 /* user ro list */
94 #define VOLOPT_CODEPAGE 4 /* codepage */
95 #define VOLOPT_PASSWORD 5 /* volume password */
96 #define VOLOPT_CASEFOLD 6 /* character case mangling */
97 #define VOLOPT_FLAGS 7 /* various flags */
98 #define VOLOPT_DBPATH 8 /* path to database */
99 #define VOLOPT_MAPCHARS 9 /* does mtou and utom mappings. syntax:
100 m and u can be double-byte hex
101 strings if necessary.
105 !u -> make u illegal always
106 ~u -> make u illegal only as the first
107 part of a double-byte character.
109 #define VOLOPT_VETO 10 /* list of veto filespec */
110 #define VOLOPT_PREEXEC 11 /* preexec command */
111 #define VOLOPT_ROOTPREEXEC 12 /* root preexec command */
113 #define VOLOPT_POSTEXEC 13 /* postexec command */
114 #define VOLOPT_ROOTPOSTEXEC 14 /* root postexec command */
116 #define VOLOPT_ENCODING 15 /* mac encoding (pre OSX)*/
121 #define VOLOPT_FORCEUID 16 /* force uid for username x */
122 #define VOLOPT_FORCEGID 17 /* force gid for group x */
123 #define VOLOPT_UMASK 18
125 #define VOLOPT_UMASK 16
126 #endif /* FORCE_UIDGID */
128 #define VOLOPT_MAX (VOLOPT_UMASK +1)
130 #define VOLOPT_NUM (VOLOPT_MAX + 1)
133 #define VOLOPT_DEFAULT ":DEFAULT:"
134 #define VOLOPT_DEFAULT_LEN 9
140 static __inline__ void volfree(struct vol_option *options,
141 const struct vol_option *save)
146 for (i = 0; i < VOLOPT_MAX; i++) {
147 if (options[i].c_value && (options[i].c_value != save[i].c_value))
148 free(options[i].c_value);
151 for (i = 0; i < VOLOPT_MAX; i++) {
152 if (options[i].c_value)
153 free(options[i].c_value);
159 /* handle variable substitutions. here's what we understand:
160 * $b -> basename of path
161 * $c -> client ip/appletalk address
162 * $d -> volume pathname on server
163 * $f -> full name (whatever's in the gecos field)
166 * $s -> server name (hostname if it doesn't exist)
167 * $u -> username (guest is usually nobody)
168 * $v -> volume name (ADEID_NAME or basename if ADEID_NAME is empty)
169 * $z -> zone (may not exist)
172 #define is_var(a, b) (strncmp((a), (b), 2) == 0)
174 static char *volxlate(AFPObj *obj, char *dest, size_t destlen,
175 char *src, struct passwd *pwd, char *path)
185 dest = calloc(destlen +1, 1);
191 strncpy(dest, src, destlen);
192 if ((p = strchr(src, '$')) == NULL) /* nothing to do */
195 /* first part of the path. just forward to the next variable. */
196 len = MIN(p - src, destlen);
202 while (p && destlen > 0) {
203 /* now figure out what the variable is */
205 if (is_var(p, "$b")) {
207 if ((q = strrchr(path, '/')) == NULL)
209 else if (*(q + 1) != '\0')
212 } else if (is_var(p, "$c")) {
213 if (obj->proto == AFPPROTO_ASP) {
214 ASP asp = obj->handle;
216 len = sprintf(dest, "%u.%u", ntohs(asp->asp_sat.sat_addr.s_net),
217 asp->asp_sat.sat_addr.s_node);
221 } else if (obj->proto == AFPPROTO_DSI) {
222 DSI *dsi = obj->handle;
224 len = sprintf(dest, "%s:%u", inet_ntoa(dsi->client.sin_addr),
225 ntohs(dsi->client.sin_port));
229 } else if (is_var(p, "$d")) {
231 } else if (is_var(p, "$f")) {
232 if ((q = strchr(pwd->pw_gecos, ',')))
235 } else if (is_var(p, "$g")) {
236 struct group *grp = getgrgid(pwd->pw_gid);
239 } else if (is_var(p, "$h")) {
240 q = obj->options.hostname;
241 } else if (is_var(p, "$s")) {
244 else if (obj->options.server) {
245 q = obj->options.server;
247 q = obj->options.hostname;
248 } else if (is_var(p, "$u")) {
250 } else if (is_var(p, "$v")) {
254 memset(&ad, 0, sizeof(ad));
255 if (ad_open(path, ADFLAGS_HF, O_RDONLY, 0, &ad) < 0)
258 if ((len = MIN(ad_getentrylen(&ad, ADEID_NAME), destlen)) > 0) {
259 memcpy(dest, ad_entry(&ad, ADEID_NAME), len);
260 ad_close(&ad, ADFLAGS_HF);
264 ad_close(&ad, ADFLAGS_HF);
265 no_volname: /* simple basename */
266 if ((q = strrchr(path, '/')) == NULL)
268 else if (*(q + 1) != '\0')
272 } else if (is_var(p, "$z")) {
274 } else if (is_var(p, "$$")) {
279 /* copy the stuff over. if we don't understand something that we
280 * should, just skip it over. */
282 len = MIN(p == q ? 2 : strlen(q), destlen);
283 strncpy(dest, q, len);
288 /* stuff up to next $ */
290 p = strchr(src, '$');
291 len = p ? MIN(p - src, destlen) : destlen;
293 strncpy(dest, src, len);
301 /* to make sure that val is valid, make sure to select an opt that
303 static int optionok(const char *buf, const char *opt, const char *val)
305 if (!strstr(buf,opt))
312 static __inline__ char *get_codepage_path(const char *path, const char *name)
318 page = (char *) malloc((len = strlen(path)) + strlen(name) + 2);
321 if (path[len - 1] != '/') /* add a / */
329 /* debug: show which codepage directory we are using */
330 LOG(log_debug, logtype_afpd, "using codepage directory: %s", page);
335 /* -------------------- */
336 static void setoption(struct vol_option *options, struct vol_option *save, int opt, const char *val)
338 if (options[opt].c_value && (!save || options[opt].c_value != save[opt].c_value))
339 free(options[opt].c_value);
340 options[opt].c_value = strdup(val + 1);
343 /* ------------------------------------------
344 handle all the options. tmp can't be NULL. */
345 static void volset(struct vol_option *options, struct vol_option *save,
346 char *volname, int vlen,
347 const char *nlspath, const char *tmp)
351 val = strchr(tmp, ':');
353 /* we'll assume it's a volume name. */
354 strncpy(volname, tmp, vlen);
359 LOG(log_debug, logtype_afpd, "Parsing volset %s", val);
361 if (optionok(tmp, "allow:", val)) {
362 setoption(options, save, VOLOPT_ALLOW, val);
364 } else if (optionok(tmp, "deny:", val)) {
365 setoption(options, save, VOLOPT_DENY, val);
367 } else if (optionok(tmp, "rwlist:", val)) {
368 setoption(options, save, VOLOPT_RWLIST, val);
370 } else if (optionok(tmp, "rolist:", val)) {
371 setoption(options, save, VOLOPT_ROLIST, val);
373 } else if (optionok(tmp, "codepage:", val)) {
374 if (options[VOLOPT_CODEPAGE].c_value &&
375 (!save || options[VOLOPT_CODEPAGE].c_value != save[VOLOPT_CODEPAGE].c_value)) {
376 free(options[VOLOPT_CODEPAGE].c_value);
378 options[VOLOPT_CODEPAGE].c_value = get_codepage_path(nlspath, val + 1);
379 } else if (optionok(tmp, "encoding:", val)) {
380 setoption(options, save, VOLOPT_ENCODING, val);
381 } else if (optionok(tmp, "veto:", val)) {
382 setoption(options, save, VOLOPT_VETO, val);
383 } else if (optionok(tmp, "casefold:", val)) {
384 if (strcasecmp(val + 1, "tolower") == 0)
385 options[VOLOPT_CASEFOLD].i_value = AFPVOL_UMLOWER;
386 else if (strcasecmp(val + 1, "toupper") == 0)
387 options[VOLOPT_CASEFOLD].i_value = AFPVOL_UMUPPER;
388 else if (strcasecmp(val + 1, "xlatelower") == 0)
389 options[VOLOPT_CASEFOLD].i_value = AFPVOL_UUPPERMLOWER;
390 else if (strcasecmp(val + 1, "xlateupper") == 0)
391 options[VOLOPT_CASEFOLD].i_value = AFPVOL_ULOWERMUPPER;
393 } else if (optionok(tmp, "options:", val)) {
396 if ((p = strtok(val + 1, ",")) == NULL) /* nothing */
400 if (strcasecmp(p, "prodos") == 0)
401 options[VOLOPT_FLAGS].i_value |= AFPVOL_A2VOL;
402 else if (strcasecmp(p, "mswindows") == 0) {
403 options[VOLOPT_FLAGS].i_value |= AFPVOL_MSWINDOWS;
404 if (!options[VOLOPT_CODEPAGE].c_value)
405 options[VOLOPT_CODEPAGE].c_value =
406 get_codepage_path(nlspath, MSWINDOWS_CODEPAGE);
408 } else if (strcasecmp(p, "crlf") == 0)
409 options[VOLOPT_FLAGS].i_value |= AFPVOL_CRLF;
410 else if (strcasecmp(p, "noadouble") == 0)
411 options[VOLOPT_FLAGS].i_value |= AFPVOL_NOADOUBLE;
412 else if (strcasecmp(p, "ro") == 0)
413 options[VOLOPT_FLAGS].i_value |= AFPVOL_RO;
414 else if (strcasecmp(p, "nohex") == 0)
415 options[VOLOPT_FLAGS].i_value |= AFPVOL_NOHEX;
416 else if (strcasecmp(p, "usedots") == 0)
417 options[VOLOPT_FLAGS].i_value |= AFPVOL_USEDOTS;
418 else if (strcasecmp(p, "limitsize") == 0)
419 options[VOLOPT_FLAGS].i_value |= AFPVOL_LIMITSIZE;
420 /* support for either "dropbox" or "dropkludge" */
421 else if (strcasecmp(p, "dropbox") == 0)
422 options[VOLOPT_FLAGS].i_value |= AFPVOL_DROPBOX;
423 else if (strcasecmp(p, "dropkludge") == 0)
424 options[VOLOPT_FLAGS].i_value |= AFPVOL_DROPBOX;
425 else if (strcasecmp(p, "nofileid") == 0)
426 options[VOLOPT_FLAGS].i_value |= AFPVOL_NOFILEID;
427 else if (strcasecmp(p, "utf8") == 0)
428 options[VOLOPT_FLAGS].i_value |= AFPVOL_UTF8;
429 else if (strcasecmp(p, "nostat") == 0)
430 options[VOLOPT_FLAGS].i_value |= AFPVOL_NOSTAT;
431 else if (strcasecmp(p, "preexec_close") == 0)
432 options[VOLOPT_PREEXEC].i_value = 1;
433 else if (strcasecmp(p, "root_preexec_close") == 0)
434 options[VOLOPT_ROOTPREEXEC].i_value = 1;
435 p = strtok(NULL, ",");
440 } else if (optionok(tmp, "dbpath:", val)) {
441 setoption(options, save, VOLOPT_DBPATH, val);
444 } else if (optionok(tmp, "umask:", val)) {
445 options[VOLOPT_UMASK].i_value = (int)strtol(val, (char **)NULL, 8);
446 } else if (optionok(tmp, "mapchars:",val)) {
447 setoption(options, save, VOLOPT_MAPCHARS, val);
449 } else if (optionok(tmp, "password:", val)) {
450 setoption(options, save, VOLOPT_PASSWORD, val);
454 /* this code allows forced uid/gid per volume settings */
455 } else if (optionok(tmp, "forceuid:", val)) {
456 setoption(options, save, VOLOPT_FORCEUID, val);
457 } else if (optionok(tmp, "forcegid:", val)) {
458 setoption(options, save, VOLOPT_FORCEGID, val);
460 #endif /* FORCE_UIDGID */
461 } else if (optionok(tmp, "root_preexec:", val)) {
462 setoption(options, save, VOLOPT_ROOTPREEXEC, val);
464 } else if (optionok(tmp, "preexec:", val)) {
465 setoption(options, save, VOLOPT_PREEXEC, val);
467 } else if (optionok(tmp, "root_postexec:", val)) {
468 setoption(options, save, VOLOPT_ROOTPOSTEXEC, val);
470 } else if (optionok(tmp, "postexec:", val)) {
471 setoption(options, save, VOLOPT_POSTEXEC, val);
474 /* ignore unknown options */
475 LOG(log_debug, logtype_afpd, "ignoring unknown volume option: %s", tmp);
480 /* ----------------- */
481 static void showvol(const char *name)
484 for ( volume = Volumes; volume; volume = volume->v_next ) {
485 if ( !strcasecmp( volume->v_name, name ) && volume->v_hide) {
492 /* ------------------------------- */
493 static int creatvol(AFPObj *obj, struct passwd *pwd,
494 char *path, char *name,
495 struct vol_option *options,
496 const int user /* user defined volume */
503 if ( name == NULL || *name == '\0' ) {
504 if ((name = strrchr( path, '/' )) == NULL) {
505 return -1; /* Obviously not a fully qualified path */
508 /* if you wish to share /, you need to specify a name. */
513 for ( volume = Volumes; volume; volume = volume->v_next ) {
514 if ( strcasecmp( volume->v_name, name ) == 0 ) {
515 if (volume->v_deleted) {
519 return -1; /* Won't be able to access it, anyway... */
524 vlen = strlen( name );
525 if ( vlen > AFPVOL_NAMELEN ) {
526 vlen = AFPVOL_NAMELEN;
527 name[AFPVOL_NAMELEN] = '\0';
530 if (!( volume = (struct vol *)calloc(1, sizeof( struct vol ))) ) {
531 LOG(log_error, logtype_afpd, "creatvol: malloc: %s", strerror(errno) );
534 if (! ( volume->v_name = (char *)malloc( vlen + 1 ) ) ) {
535 LOG(log_error, logtype_afpd, "creatvol: malloc: %s", strerror(errno) );
539 if (!( volume->v_path = (char *)malloc( strlen( path ) + 1 )) ) {
540 LOG(log_error, logtype_afpd, "creatvol: malloc: %s", strerror(errno) );
541 free(volume->v_name);
545 volume->v_hide = hide;
546 strcpy( volume->v_name, name);
547 strcpy( volume->v_path, path );
551 #endif /* __svr4__ */
552 volume->v_vid = lastvid++;
553 volume->v_lastdid = 17;
557 /* should we casefold? */
558 volume->v_casefold = options[VOLOPT_CASEFOLD].i_value;
560 /* shift in some flags */
561 volume->v_flags = options[VOLOPT_FLAGS].i_value;
563 /* read in the code pages */
564 if (options[VOLOPT_CODEPAGE].c_value)
565 codepage_read(volume, options[VOLOPT_CODEPAGE].c_value);
567 if (options[VOLOPT_PASSWORD].c_value)
568 volume->v_password = strdup(options[VOLOPT_PASSWORD].c_value);
570 if (options[VOLOPT_VETO].c_value)
571 volume->v_veto = strdup(options[VOLOPT_VETO].c_value);
573 if (options[VOLOPT_ENCODING].c_value)
574 volume->v_encoding = strdup(options[VOLOPT_ENCODING].c_value);
576 if (options[VOLOPT_DBPATH].c_value)
577 volume->v_dbpath = volxlate(obj, NULL, MAXPATHLEN, options[VOLOPT_DBPATH].c_value, pwd, path);
580 if (options[VOLOPT_UMASK].i_value)
581 volume->v_umask = (mode_t)options[VOLOPT_UMASK].i_value;
584 if (options[VOLOPT_FORCEUID].c_value) {
585 volume->v_forceuid = strdup(options[VOLOPT_FORCEUID].c_value);
587 volume->v_forceuid = NULL; /* set as null so as to return 0 later on */
590 if (options[VOLOPT_FORCEGID].c_value) {
591 volume->v_forcegid = strdup(options[VOLOPT_FORCEGID].c_value);
593 volume->v_forcegid = NULL; /* set as null so as to return 0 later on */
597 if (options[VOLOPT_PREEXEC].c_value)
598 volume->v_preexec = volxlate(obj, NULL, MAXPATHLEN, options[VOLOPT_PREEXEC].c_value, pwd, path);
599 volume->v_preexec_close = options[VOLOPT_PREEXEC].i_value;
601 if (options[VOLOPT_POSTEXEC].c_value)
602 volume->v_postexec = volxlate(obj, NULL, MAXPATHLEN, options[VOLOPT_POSTEXEC].c_value, pwd, path);
604 if (options[VOLOPT_ROOTPREEXEC].c_value)
605 volume->v_root_preexec = volxlate(obj, NULL, MAXPATHLEN, options[VOLOPT_ROOTPREEXEC].c_value, pwd, path);
606 volume->v_root_preexec_close = options[VOLOPT_ROOTPREEXEC].i_value;
608 if (options[VOLOPT_ROOTPOSTEXEC].c_value)
609 volume->v_root_postexec = volxlate(obj, NULL, MAXPATHLEN, options[VOLOPT_ROOTPOSTEXEC].c_value, pwd, path);
613 volume->v_next = Volumes;
618 /* ---------------- */
619 static char *myfgets( buf, size, fp )
628 while ((EOF != ( c = getc( fp )) ) && ( size > 0 )) {
629 if ( c == '\n' || c == '\r' ) {
647 /* check access list. this function wants something of the following
649 * @group,name,name2,@group2,name3
651 * a NULL argument allows everybody to have access.
652 * we return three things:
654 * 0: list exists, but name isn't in it
657 static int accessvol(args, name)
661 char buf[MAXPATHLEN + 1], *p;
667 strncpy(buf, args, sizeof(buf));
668 if ((p = strtok(buf, ",")) == NULL) /* nothing, return okay */
672 if (*p == '@') { /* it's a group */
673 if ((gr = getgrnam(p + 1)) && gmem(gr->gr_gid))
675 } else if (strcmp(p, name) == 0) /* it's a user name */
677 p = strtok(NULL, ",");
683 static void setextmap( ext, type, creator, user)
684 char *ext, *type, *creator;
690 if (Extmap == NULL) {
691 if (( Extmap = calloc(1, sizeof( struct extmap ))) == NULL ) {
692 LOG(log_error, logtype_afpd, "setextmap: calloc: %s", strerror(errno) );
697 for ( em = Extmap, cnt = 0; em->em_ext; em++, cnt++) {
698 if ( (strdiacasecmp( em->em_ext, ext )) == 0 ) {
703 if ( em->em_ext == NULL ) {
704 if (!(Extmap = realloc( Extmap, sizeof( struct extmap ) * (cnt +2))) ) {
705 LOG(log_error, logtype_afpd, "setextmap: realloc: %s", strerror(errno) );
708 (Extmap +cnt +1)->em_ext = NULL;
710 } else if ( !user ) {
716 if (!(em->em_ext = strdup( ext))) {
717 LOG(log_error, logtype_afpd, "setextmap: strdup: %s", strerror(errno) );
721 if ( *type == '\0' ) {
722 memcpy(em->em_type, "????", sizeof( em->em_type ));
724 memcpy(em->em_type, type, sizeof( em->em_type ));
726 if ( *creator == '\0' ) {
727 memcpy(em->em_creator, "UNIX", sizeof( em->em_creator ));
729 memcpy(em->em_creator, creator, sizeof( em->em_creator ));
733 /* -------------------------- */
734 static int extmap_cmp(const void *map1, const void *map2)
736 const struct extmap *em1 = map1;
737 const struct extmap *em2 = map2;
738 return strdiacasecmp(em1->em_ext, em2->em_ext);
741 static void sortextmap( void)
746 if ((em = Extmap) == NULL) {
754 qsort(Extmap, Extmap_cnt, sizeof(struct extmap), extmap_cmp);
759 /* ----------------------
761 static void free_extmap( void)
771 /* ----------------------
773 static int volfile_changed(struct afp_volume_name *p)
783 if (!stat( name, &st) && st.st_mtime > p->mtime) {
784 p->mtime = st.st_mtime;
790 /* ----------------------
791 * Read a volume configuration file and add the volumes contained within to
792 * the global volume list. If p2 is non-NULL, the file that is opened is
795 * Lines that begin with # and blank lines are ignored.
796 * Volume lines are of the form:
797 * <unix path> [<volume name>] [allow:<user>,<@group>,...] \
798 * [codepage:<file>] [casefold:<num>]
799 * <extension> TYPE [CREATOR]
801 static int readvolfile(obj, p1, p2, user, pwent)
803 struct afp_volume_name *p1;
806 struct passwd *pwent;
809 char path[ MAXPATHLEN + 1], tmp[ MAXPATHLEN + 1],
810 volname[ AFPVOL_NAMELEN + 1 ], buf[ BUFSIZ ],
811 type[ 5 ], creator[ 5 ];
814 struct vol_option options[VOLOPT_NUM], save_options[VOLOPT_NUM];
822 strcpy( path, p1->name );
829 p1->full_name = strdup(path);
832 if (NULL == ( fp = fopen( path, "r" )) ) {
836 if (fd != -1 && !fstat( fd, &st) ) {
837 p1->mtime = st.st_mtime;
840 memset(save_options, 0, sizeof(save_options));
841 while ( myfgets( buf, sizeof( buf ), fp ) != NULL ) {
842 initline( strlen( buf ), buf );
843 parseline( sizeof( path ) - 1, path );
850 /* change the default options for this file */
851 if (strncmp(path, VOLOPT_DEFAULT, VOLOPT_DEFAULT_LEN) == 0) {
853 for (i = 0; i < VOLOPT_NUM; i++) {
854 if (parseline( sizeof( path ) - VOLOPT_DEFAULT_LEN - 1,
855 path + VOLOPT_DEFAULT_LEN) < 0)
857 volset(save_options, NULL, tmp, sizeof(tmp) - 1,
858 obj->options.nlspath, path + VOLOPT_DEFAULT_LEN);
864 if (( p = strchr( path, '/' )) != NULL ) {
872 if ( u == NULL || *u == '\0' || ( pw = getpwnam( u )) == NULL ) {
875 strcpy( tmp, pw->pw_dir );
876 if ( p != NULL && *p != '\0' ) {
880 /* Tag a user's home directory with their umask. Note, this will
881 * be overwritten if the user actually specifies a umask: option
882 * for a '~' volume. */
883 save_options[VOLOPT_UMASK].i_value = obj->options.save_mask;
887 /* send path through variable substitution */
888 if (*path != '~') /* need to copy path to tmp */
891 pwent = getpwnam(obj->username);
892 volxlate(obj, path, sizeof(path) - 1, tmp, pwent, NULL);
894 /* this is sort of braindead. basically, i want to be
895 * able to specify things in any order, but i don't want to
896 * re-write everything.
898 * currently we have options:
906 * options:prodos,crlf,noadouble,ro...
911 * namemask:x,y,!z (not implemented yet)
913 memcpy(options, save_options, sizeof(options));
916 /* read in up to VOLOP_NUM possible options */
917 for (i = 0; i < VOLOPT_NUM; i++) {
918 if (parseline( sizeof( tmp ) - 1, tmp ) < 0)
921 volset(options, save_options, volname, sizeof(volname) - 1,obj->options.nlspath, tmp);
924 /* check allow/deny lists:
925 allow -> either no list (-1), or in list (1)
926 deny -> either no list (-1), or not in list (0) */
927 if (accessvol(options[VOLOPT_ALLOW].c_value, obj->username) &&
928 (accessvol(options[VOLOPT_DENY].c_value, obj->username) < 1)) {
930 /* handle read-only behaviour. semantics:
931 * 1) neither the rolist nor the rwlist exist -> rw
932 * 2) rolist exists -> ro if user is in it.
933 * 3) rwlist exists -> ro unless user is in it. */
934 if (((options[VOLOPT_FLAGS].i_value & AFPVOL_RO) == 0) &&
935 ((accessvol(options[VOLOPT_ROLIST].c_value,
936 obj->username) == 1) ||
937 !accessvol(options[VOLOPT_RWLIST].c_value,
939 options[VOLOPT_FLAGS].i_value |= AFPVOL_RO;
941 /* do variable substitution for volname */
942 volxlate(obj, tmp, sizeof(tmp) - 1, volname, pwent, path);
943 creatvol(obj, pwent, path, tmp, options, p2 != NULL);
945 volfree(options, save_options);
949 parseline( sizeof( type ) - 1, type );
950 parseline( sizeof( creator ) - 1, creator );
951 setextmap( path, type, creator, user);
958 volfree(save_options, NULL);
960 if ( fclose( fp ) != 0 ) {
961 LOG(log_error, logtype_afpd, "readvolfile: fclose: %s", strerror(errno) );
967 /* ------------------------------- */
968 static void volume_free(struct vol *vol)
974 free(vol->v_password);
976 free(vol->v_encoding);
981 free(vol->v_forceuid);
982 free(vol->v_forcegid);
983 #endif /* FORCE_UIDGID */
986 /* ------------------------------- */
987 static void free_volumes(void )
990 struct vol *nvol, *ovol;
992 for ( vol = Volumes; vol; vol = vol->v_next ) {
993 if (( vol->v_flags & AFPVOL_OPEN ) ) {
1000 for ( vol = Volumes, ovol = NULL; vol; vol = nvol) {
1003 if (vol->v_name == NULL) {
1004 if (Volumes == vol) {
1011 ovol->v_next = nvol;
1021 /* ------------------------------- */
1022 static void volume_unlink(struct vol *volume)
1024 struct vol *vol, *ovol, *nvol;
1026 if (volume == Volumes) {
1027 Volumes = Volumes->v_next;
1030 for ( vol = Volumes, ovol = NULL; vol; vol = nvol) {
1033 if (vol == volume) {
1038 ovol->v_next = nvol;
1049 static int getvolspace( vol, bfree, btotal, xbfree, xbtotal, bsize )
1051 u_int32_t *bfree, *btotal, *bsize;
1052 VolSpace *xbfree, *xbtotal;
1056 #ifndef NO_QUOTA_SUPPORT
1057 VolSpace qfree, qtotal;
1060 spaceflag = AFPVOL_GVSMASK & vol->v_flags;
1061 /* report up to 2GB if afp version is < 2.2 (4GB if not) */
1062 maxsize = (vol->v_flags & AFPVOL_A2VOL) ? 0x01fffe00 :
1063 (((afp_version < 22) || (vol->v_flags & AFPVOL_LIMITSIZE))
1064 ? 0x7fffffffL : 0xffffffffL);
1067 if ( spaceflag == AFPVOL_NONE || spaceflag == AFPVOL_AFSGVS ) {
1068 if ( afs_getvolspace( vol, xbfree, xbtotal, bsize ) == AFP_OK ) {
1069 vol->v_flags = ( ~AFPVOL_GVSMASK & vol->v_flags ) | AFPVOL_AFSGVS;
1070 goto getvolspace_done;
1075 if (( rc = ustatfs_getvolspace( vol, xbfree, xbtotal,
1076 bsize)) != AFP_OK ) {
1080 #define min(a,b) ((a)<(b)?(a):(b))
1081 #ifndef NO_QUOTA_SUPPORT
1082 if ( spaceflag == AFPVOL_NONE || spaceflag == AFPVOL_UQUOTA ) {
1083 if ( uquota_getvolspace( vol, &qfree, &qtotal, *bsize ) == AFP_OK ) {
1084 vol->v_flags = ( ~AFPVOL_GVSMASK & vol->v_flags ) | AFPVOL_UQUOTA;
1085 *xbfree = min(*xbfree, qfree);
1086 *xbtotal = min( *xbtotal, qtotal);
1087 goto getvolspace_done;
1091 vol->v_flags = ( ~AFPVOL_GVSMASK & vol->v_flags ) | AFPVOL_USTATFS;
1094 *bfree = min( *xbfree, maxsize);
1095 *btotal = min( *xbtotal, maxsize);
1099 /* ----------------------- */
1100 static int getvolparams( bitmap, vol, st, buf, buflen )
1108 int bit = 0, isad = 1;
1111 u_int32_t bfree, btotal, bsize;
1112 VolSpace xbfree, xbtotal; /* extended bytes */
1113 char *data, *nameoff = NULL;
1116 /* courtesy of jallison@whistle.com:
1117 * For MacOS8.x support we need to create the
1118 * .Parent file here if it doesn't exist. */
1120 memset(&ad, 0, sizeof(ad));
1121 if ( ad_open( vol->v_path, vol_noadouble(vol) |
1122 ADFLAGS_HF|ADFLAGS_DIR, O_RDWR | O_CREAT,
1126 } else if (ad_get_HF_flags( &ad ) & O_CREAT) {
1127 slash = strrchr( vol->v_path, '/' );
1131 slash = vol->v_path;
1133 ad_setentrylen( &ad, ADEID_NAME, strlen( slash ));
1134 memcpy(ad_entry( &ad, ADEID_NAME ), slash,
1135 ad_getentrylen( &ad, ADEID_NAME ));
1136 ad_setdate(&ad, AD_DATE_CREATE | AD_DATE_UNIX, st->st_mtime);
1137 ad_flush(&ad, ADFLAGS_HF);
1140 if (( bitmap & ( (1<<VOLPBIT_BFREE)|(1<<VOLPBIT_BTOTAL) |
1141 (1<<VOLPBIT_XBFREE)|(1<<VOLPBIT_XBTOTAL) |
1142 (1<<VOLPBIT_BSIZE)) ) != 0 ) {
1143 if ( getvolspace( vol, &bfree, &btotal, &xbfree, &xbtotal,
1146 ad_close( &ad, ADFLAGS_HF );
1148 return( AFPERR_PARAM );
1153 while ( bitmap != 0 ) {
1154 while (( bitmap & 1 ) == 0 ) {
1163 if (0 == (vol->v_flags & AFPVOL_NOFILEID) && vol->v_db != NULL) {
1164 ashort = VOLPBIT_ATTR_FILEID;
1166 #endif /* CNID_DB */
1167 /* check for read-only.
1168 * NOTE: we don't actually set the read-only flag unless
1169 * it's passed in that way as it's possible to mount
1170 * a read-write filesystem under a read-only one. */
1171 if ((vol->v_flags & AFPVOL_RO) ||
1172 ((utime(vol->v_path, NULL) < 0) && (errno == EROFS))) {
1173 ashort |= VOLPBIT_ATTR_RO;
1175 ashort |= VOLPBIT_ATTR_CATSEARCH;
1176 if (afp_version >= 30) {
1177 ashort |= VOLPBIT_ATTR_UTF8;
1179 ashort = htons(ashort);
1180 memcpy(data, &ashort, sizeof( ashort ));
1181 data += sizeof( ashort );
1185 ashort = htons( AFPVOLSIG_DEFAULT );
1186 memcpy(data, &ashort, sizeof( ashort ));
1187 data += sizeof( ashort );
1190 case VOLPBIT_CDATE :
1191 if (!isad || (ad_getdate(&ad, AD_DATE_CREATE, &aint) < 0))
1192 aint = AD_DATE_FROM_UNIX(st->st_mtime);
1193 memcpy(data, &aint, sizeof( aint ));
1194 data += sizeof( aint );
1197 case VOLPBIT_MDATE :
1198 if ( st->st_mtime > vol->v_time ) {
1199 vol->v_time = st->st_mtime;
1200 aint = AD_DATE_FROM_UNIX(st->st_mtime);
1202 aint = AD_DATE_FROM_UNIX(vol->v_time);
1204 memcpy(data, &aint, sizeof( aint ));
1205 data += sizeof( aint );
1208 case VOLPBIT_BDATE :
1209 if (!isad || (ad_getdate(&ad, AD_DATE_BACKUP, &aint) < 0))
1210 aint = AD_DATE_START;
1211 memcpy(data, &aint, sizeof( aint ));
1212 data += sizeof( aint );
1216 memcpy(data, &vol->v_vid, sizeof( vol->v_vid ));
1217 data += sizeof( vol->v_vid );
1220 case VOLPBIT_BFREE :
1221 bfree = htonl( bfree );
1222 memcpy(data, &bfree, sizeof( bfree ));
1223 data += sizeof( bfree );
1226 case VOLPBIT_BTOTAL :
1227 btotal = htonl( btotal );
1228 memcpy(data, &btotal, sizeof( btotal ));
1229 data += sizeof( btotal );
1232 #ifndef NO_LARGE_VOL_SUPPORT
1233 case VOLPBIT_XBFREE :
1234 xbfree = hton64( xbfree );
1235 #if defined(__GNUC__) && defined(HAVE_GCC_MEMCPY_BUG)
1236 bcopy(&xbfree, data, sizeof(xbfree));
1237 #else /* __GNUC__ && HAVE_GCC_MEMCPY_BUG */
1238 memcpy(data, &xbfree, sizeof( xbfree ));
1239 #endif /* __GNUC__ && HAVE_GCC_MEMCPY_BUG */
1240 data += sizeof( xbfree );
1243 case VOLPBIT_XBTOTAL :
1244 xbtotal = hton64( xbtotal );
1245 #if defined(__GNUC__) && defined(HAVE_GCC_MEMCPY_BUG)
1246 bcopy(&xbtotal, data, sizeof(xbtotal));
1247 #else /* __GNUC__ && HAVE_GCC_MEMCPY_BUG */
1248 memcpy(data, &xbtotal, sizeof( xbtotal ));
1249 #endif /* __GNUC__ && HAVE_GCC_MEMCPY_BUG */
1250 data += sizeof( xbfree );
1252 #endif /* ! NO_LARGE_VOL_SUPPORT */
1256 data += sizeof( u_int16_t );
1259 case VOLPBIT_BSIZE: /* block size */
1260 bsize = htonl(bsize);
1261 memcpy(data, &bsize, sizeof(bsize));
1262 data += sizeof(bsize);
1267 ad_close( &ad, ADFLAGS_HF );
1269 return( AFPERR_BITMAP );
1275 ashort = htons( data - buf );
1276 memcpy(nameoff, &ashort, sizeof( ashort ));
1277 aint = strlen( vol->v_name );
1279 memcpy(data, vol->v_name, aint );
1283 ad_close( &ad, ADFLAGS_HF );
1285 *buflen = data - buf;
1289 /* ------------------------- */
1290 int static stat_vol(u_int16_t bitmap, struct vol *vol, char *rbuf, int *rbuflen)
1295 if ( stat( vol->v_path, &st ) < 0 ) {
1297 return( AFPERR_PARAM );
1300 buflen = *rbuflen - sizeof( bitmap );
1301 if (( ret = getvolparams( bitmap, vol, &st,
1302 rbuf + sizeof( bitmap ), &buflen )) != AFP_OK ) {
1306 *rbuflen = buflen + sizeof( bitmap );
1307 bitmap = htons( bitmap );
1308 memcpy(rbuf, &bitmap, sizeof( bitmap ));
1313 /* ------------------------------- */
1314 void load_volumes(AFPObj *obj)
1316 struct passwd *pwent;
1321 /* check files date */
1322 if (obj->options.defaultvol.loaded) {
1323 changed = volfile_changed(&obj->options.defaultvol);
1325 if (obj->options.systemvol.loaded) {
1326 changed |= volfile_changed(&obj->options.systemvol);
1328 if (obj->options.uservol.loaded) {
1329 changed |= volfile_changed(&obj->options.uservol);
1338 pwent = getpwnam(obj->username);
1339 if ( (obj->options.flags & OPTION_USERVOLFIRST) == 0 ) {
1340 readvolfile(obj, &obj->options.systemvol, NULL, 0, pwent);
1343 if ((*obj->username == '\0') || (obj->options.flags & OPTION_NOUSERVOL)) {
1344 readvolfile(obj, &obj->options.defaultvol, NULL, 1, pwent);
1347 * Read user's AppleVolumes or .AppleVolumes file
1348 * If neither are readable, read the default volumes file. if
1349 * that doesn't work, create a user share.
1351 obj->options.uservol.name = strdup(pwent->pw_dir);
1352 if ( readvolfile(obj, &obj->options.uservol, "AppleVolumes", 1, pwent) < 0 &&
1353 readvolfile(obj, &obj->options.uservol, ".AppleVolumes", 1, pwent) < 0 &&
1354 readvolfile(obj, &obj->options.uservol, "applevolumes", 1, pwent) < 0 &&
1355 readvolfile(obj, &obj->options.uservol, ".applevolumes", 1, pwent) < 0 &&
1356 obj->options.defaultvol.name != NULL ) {
1357 if (readvolfile(obj, &obj->options.defaultvol, NULL, 1, pwent) < 0)
1358 creatvol(obj, pwent, pwent->pw_dir, NULL, NULL, 1);
1361 if ( obj->options.flags & OPTION_USERVOLFIRST ) {
1362 readvolfile(obj, &obj->options.systemvol, NULL, 0, pwent );
1366 /* ------------------------------- */
1367 int afp_getsrvrparms(obj, ibuf, ibuflen, rbuf, rbuflen )
1370 int ibuflen, *rbuflen;
1382 for ( vcnt = 0, volume = Volumes; volume; volume = volume->v_next ) {
1383 if (!(volume->v_flags & AFPVOL_NOSTAT)) {
1384 if ( stat( volume->v_path, &st ) < 0 ) {
1385 LOG(log_info, logtype_afpd, "afp_getsrvrparms: stat %s: %s",
1386 volume->v_path, strerror(errno) );
1387 continue; /* can't access directory */
1389 if (!S_ISDIR(st.st_mode)) {
1390 continue; /* not a dir */
1393 if (volume->v_hide) {
1394 continue; /* config file changed but the volume was mounted */
1397 /* set password bit if there's a volume password */
1398 *data = (volume->v_password) ? AFPSRVR_PASSWD : 0;
1400 /* Apple 2 clients running ProDOS-8 expect one volume to have
1401 bit 0 of this byte set. They will not recognize anything
1402 on the server unless this is the case. I have not
1403 completely worked this out, but it's related to booting
1404 from the server. Support for that function is a ways
1405 off.. <shirsch@ibm.net> */
1406 *data++ |= (volume->v_flags & AFPVOL_A2VOL) ? AFPSRVR_CONFIGINFO : 0;
1407 len = strlen( volume->v_name );
1409 memcpy(data, volume->v_name, len );
1414 *rbuflen = data - rbuf;
1416 if ( gettimeofday( &tv, 0 ) < 0 ) {
1417 LOG(log_error, logtype_afpd, "afp_getsrvrparms: gettimeofday: %s", strerror(errno) );
1419 return AFPERR_PARAM;
1421 tv.tv_sec = AD_DATE_FROM_UNIX(tv.tv_sec);
1422 memcpy(data, &tv.tv_sec, sizeof( u_int32_t));
1423 data += sizeof( u_int32_t);
1428 /* -------------------------
1429 * we are the user here
1431 int afp_openvol(obj, ibuf, ibuflen, rbuf, rbuflen )
1434 int ibuflen, *rbuflen;
1447 memcpy(&bitmap, ibuf, sizeof( bitmap ));
1448 bitmap = ntohs( bitmap );
1449 ibuf += sizeof( bitmap );
1450 if (( bitmap & (1<<VOLPBIT_VID)) == 0 ) {
1452 return AFPERR_BITMAP;
1455 len = (unsigned char)*ibuf++;
1456 volname = obj->oldtmp;
1457 memcpy(volname, ibuf, len );
1458 *(volname + len) = '\0';
1460 if ((len + 1) & 1) /* pad to an even boundary */
1465 for ( volume = Volumes; volume; volume = volume->v_next ) {
1466 if ( strcasecmp( volname, volume->v_name ) == 0 ) {
1471 if ( volume == NULL ) {
1473 return AFPERR_PARAM;
1476 /* check for a volume password */
1477 if (volume->v_password && strncmp(ibuf, volume->v_password, VOLPASSLEN)) {
1479 return AFPERR_ACCESS;
1482 if (( volume->v_flags & AFPVOL_OPEN ) ) {
1483 /* the volume is already open */
1485 set_uidgid ( volume );
1487 return stat_vol(bitmap, volume, rbuf, rbuflen);
1490 /* initialize volume variables
1493 if (afp_version >= 30) {
1494 volume->max_filename = 255;
1497 volume->max_filename = MACFILELEN;
1501 volume->v_db = NULL;
1503 volume->v_dir = volume->v_root = NULL;
1505 /* FIXME unix name != mac name */
1506 if ((dir = dirnew(volume->v_name, volume->v_name) ) == NULL) {
1507 LOG(log_error, logtype_afpd, "afp_openvol: malloc: %s", strerror(errno) );
1512 dir->d_did = DIRDID_ROOT;
1513 dir->d_color = DIRTREE_COLOR_BLACK; /* root node is black */
1514 volume->v_dir = volume->v_root = dir;
1515 volume->v_flags |= AFPVOL_OPEN;
1517 if (volume->v_root_preexec) {
1518 if ((ret = afprun(1, volume->v_root_preexec, NULL)) && volume->v_root_preexec_close) {
1519 LOG(log_error, logtype_afpd, "afp_openvol: root preexec : %d", ret );
1526 set_uidgid ( volume );
1529 if (volume->v_preexec) {
1530 if ((ret = afprun(0, volume->v_preexec, NULL)) && volume->v_preexec_close) {
1531 LOG(log_error, logtype_afpd, "afp_openvol: preexec : %d", ret );
1537 if ( stat( volume->v_path, &st ) < 0 ) {
1542 if ( chdir( volume->v_path ) < 0 ) {
1546 curdir = volume->v_dir;
1549 if (volume->v_dbpath)
1550 volume->v_db = cnid_open (volume->v_dbpath, volume->v_umask);
1551 if (volume->v_db == NULL)
1552 volume->v_db = cnid_open (volume->v_path, volume->v_umask);
1553 if (volume->v_db == NULL) {
1554 /* FIXME config option?
1555 * - mount the volume readonly
1557 * - read/write with other scheme
1562 if ( 0 == ( volume->v_maccharset = add_charset(volume->v_encoding?volume->v_encoding:"MAC")) )
1563 volume->v_maccharset = CH_MAC;
1565 ret = stat_vol(bitmap, volume, rbuf, rbuflen);
1566 if (ret == AFP_OK) {
1569 * If you mount a volume twice, the second time the trash appears on
1570 * the desk-top. That's because the Mac remembers the DID for the
1571 * trash (even for volumes in different zones, on different servers).
1572 * Just so this works better, we prime the DID cache with the trash,
1573 * fixing the trash at DID 17.
1576 cname( volume, volume->v_dir, &p );
1582 if (volume->v_dir) {
1583 dirfree( volume->v_dir );
1584 volume->v_dir = volume->v_root = NULL;
1587 volume->v_flags &= ~AFPVOL_OPEN;
1590 if (volume->v_db != NULL) {
1591 cnid_close(volume->v_db);
1592 volume->v_db = NULL;
1599 /* ------------------------- */
1600 static void closevol(struct vol *vol)
1605 dirfree( vol->v_root );
1608 cnid_close(vol->v_db);
1610 #endif /* CNID_DB */
1612 if (vol->v_postexec) {
1613 afprun(0, vol->v_postexec, NULL);
1615 if (vol->v_root_postexec) {
1616 afprun(1, vol->v_root_postexec, NULL);
1620 /* ------------------------- */
1621 void close_all_vol(void)
1625 for ( ovol = Volumes; ovol; ovol = ovol->v_next ) {
1626 if ( ovol->v_flags & AFPVOL_OPEN ) {
1627 ovol->v_flags &= ~AFPVOL_OPEN;
1633 /* ------------------------- */
1634 int afp_closevol(obj, ibuf, ibuflen, rbuf, rbuflen )
1637 int ibuflen, *rbuflen;
1639 struct vol *vol, *ovol;
1644 memcpy(&vid, ibuf, sizeof( vid ));
1645 if (NULL == ( vol = getvolbyvid( vid )) ) {
1646 return( AFPERR_PARAM );
1649 vol->v_flags &= ~AFPVOL_OPEN;
1650 for ( ovol = Volumes; ovol; ovol = ovol->v_next ) {
1651 if ( ovol->v_flags & AFPVOL_OPEN ) {
1655 if ( ovol != NULL ) {
1656 /* Even if chdir fails, we can't say afp_closevol fails. */
1657 if ( chdir( ovol->v_path ) == 0 ) {
1658 curdir = ovol->v_dir;
1663 if (vol->v_deleted) {
1664 showvol(vol->v_name);
1671 /* ------------------------- */
1672 struct vol *getvolbyvid(const u_int16_t vid )
1676 for ( vol = Volumes; vol; vol = vol->v_next ) {
1677 if ( vid == vol->v_vid ) {
1681 if ( vol == NULL || ( vol->v_flags & AFPVOL_OPEN ) == 0 ) {
1687 #endif /* FORCE_UIDGID */
1692 /* ------------------------ */
1693 static int ext_cmp_key(const void *key, const void *obj)
1695 const char *p = key;
1696 const struct extmap *em = obj;
1697 return strdiacasecmp(p, em->em_ext);
1699 struct extmap *getextmap(const char *path)
1704 if (NULL == ( p = strrchr( path, '.' )) ) {
1705 return( Defextmap );
1708 if (!*p || !Extmap_cnt) {
1709 return( Defextmap );
1711 em = bsearch(p, Extmap, Extmap_cnt, sizeof(struct extmap), ext_cmp_key);
1715 return( Defextmap );
1719 /* ------------------------- */
1720 struct extmap *getdefextmap(void)
1722 return( Defextmap );
1725 /* --------------------------
1726 poll if a volume is changed by other processes.
1728 int pollvoltime(obj)
1735 if (!(afp_version > 21 && obj->options.server_notif))
1738 if ( gettimeofday( &tv, 0 ) < 0 )
1741 for ( vol = Volumes; vol; vol = vol->v_next ) {
1742 if ( (vol->v_flags & AFPVOL_OPEN) && vol->v_time + 30 < tv.tv_sec) {
1743 if ( !stat( vol->v_path, &st ) && vol->v_time != st.st_mtime ) {
1744 vol->v_time = st.st_mtime;
1745 if (!obj->attention(obj->handle, AFPATTN_NOTIFY | AFPATTN_VOLCHANGED))
1754 /* ------------------------- */
1755 void setvoltime(obj, vol )
1761 /* just looking at vol->v_time is broken seriously since updates
1762 * from other users afpd processes never are seen.
1763 * This is not the most elegant solution (a shared memory between
1764 * the afpd processes would come closer)
1767 if ( gettimeofday( &tv, 0 ) < 0 ) {
1768 LOG(log_error, logtype_afpd, "setvoltime: gettimeofday: %s", strerror(errno) );
1771 if( utime( vol->v_path, NULL ) < 0 ) {
1772 /* write of time failed ... probably a read only filesys,
1773 * where no other users can interfere, so there's no issue here
1777 /* a little granularity */
1778 if (vol->v_time < tv.tv_sec) {
1779 vol->v_time = tv.tv_sec;
1780 if (afp_version > 21 && obj->options.server_notif) {
1781 obj->attention(obj->handle, AFPATTN_NOTIFY | AFPATTN_VOLCHANGED);
1786 /* ------------------------- */
1787 int afp_getvolparams(obj, ibuf, ibuflen, rbuf, rbuflen )
1790 int ibuflen, *rbuflen;
1793 u_int16_t vid, bitmap;
1796 memcpy(&vid, ibuf, sizeof( vid ));
1797 ibuf += sizeof( vid );
1798 memcpy(&bitmap, ibuf, sizeof( bitmap ));
1799 bitmap = ntohs( bitmap );
1801 if (NULL == ( vol = getvolbyvid( vid )) ) {
1803 return( AFPERR_PARAM );
1806 return stat_vol(bitmap, vol, rbuf, rbuflen);
1809 /* ------------------------- */
1810 int afp_setvolparams(obj, ibuf, ibuflen, rbuf, rbuflen )
1813 int ibuflen, *rbuflen;
1817 u_int16_t vid, bitmap;
1823 memcpy(&vid, ibuf, sizeof( vid ));
1824 ibuf += sizeof( vid );
1825 memcpy(&bitmap, ibuf, sizeof( bitmap ));
1826 bitmap = ntohs( bitmap );
1827 ibuf += sizeof(bitmap);
1829 if (( vol = getvolbyvid( vid )) == NULL ) {
1830 return( AFPERR_PARAM );
1833 if (vol->v_flags & AFPVOL_RO)
1834 return AFPERR_VLOCK;
1836 /* we can only set the backup date. */
1837 if (bitmap != (1 << VOLPBIT_BDATE))
1838 return AFPERR_BITMAP;
1840 memset(&ad, 0, sizeof(ad));
1841 if ( ad_open( vol->v_path, ADFLAGS_HF|ADFLAGS_DIR, O_RDWR,
1844 return AFPERR_VLOCK;
1846 return AFPERR_ACCESS;
1849 memcpy(&aint, ibuf, sizeof(aint));
1850 ad_setdate(&ad, AD_DATE_BACKUP, aint);
1851 ad_flush(&ad, ADFLAGS_HF);
1852 ad_close(&ad, ADFLAGS_HF);
1856 /* ------------------------- */
1857 int wincheck(const struct vol *vol, const char *path)
1861 if (!(vol->v_flags & AFPVOL_MSWINDOWS))
1864 /* empty paths are not allowed */
1865 if ((len = strlen(path)) == 0)
1868 /* leading or trailing whitespaces are not allowed, carriage returns
1869 * and probably other whitespace is okay, tabs are not allowed
1871 if ((path[0] == ' ') || (path[len-1] == ' '))
1874 /* certain characters are not allowed */
1875 if (strpbrk(path, MSWINDOWS_BADCHARS))
1878 /* everything else is okay */