2 * $Id: volume.c,v 1.51.2.7 2003-07-21 05:50:54 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 else if (strcasecmp(p, "upriv") == 0)
436 options[VOLOPT_FLAGS].i_value |= AFPVOL_UNIX_PRIV;
438 p = strtok(NULL, ",");
443 } else if (optionok(tmp, "dbpath:", val)) {
444 setoption(options, save, VOLOPT_DBPATH, val);
447 } else if (optionok(tmp, "umask:", val)) {
448 options[VOLOPT_UMASK].i_value = (int)strtol(val, (char **)NULL, 8);
449 } else if (optionok(tmp, "mapchars:",val)) {
450 setoption(options, save, VOLOPT_MAPCHARS, val);
452 } else if (optionok(tmp, "password:", val)) {
453 setoption(options, save, VOLOPT_PASSWORD, val);
457 /* this code allows forced uid/gid per volume settings */
458 } else if (optionok(tmp, "forceuid:", val)) {
459 setoption(options, save, VOLOPT_FORCEUID, val);
460 } else if (optionok(tmp, "forcegid:", val)) {
461 setoption(options, save, VOLOPT_FORCEGID, val);
463 #endif /* FORCE_UIDGID */
464 } else if (optionok(tmp, "root_preexec:", val)) {
465 setoption(options, save, VOLOPT_ROOTPREEXEC, val);
467 } else if (optionok(tmp, "preexec:", val)) {
468 setoption(options, save, VOLOPT_PREEXEC, val);
470 } else if (optionok(tmp, "root_postexec:", val)) {
471 setoption(options, save, VOLOPT_ROOTPOSTEXEC, val);
473 } else if (optionok(tmp, "postexec:", val)) {
474 setoption(options, save, VOLOPT_POSTEXEC, val);
477 /* ignore unknown options */
478 LOG(log_debug, logtype_afpd, "ignoring unknown volume option: %s", tmp);
483 /* ----------------- */
484 static void showvol(const char *name)
487 for ( volume = Volumes; volume; volume = volume->v_next ) {
488 if ( !strcasecmp( volume->v_name, name ) && volume->v_hide) {
495 /* ------------------------------- */
496 static int creatvol(AFPObj *obj, struct passwd *pwd,
497 char *path, char *name,
498 struct vol_option *options,
499 const int user /* user defined volume */
506 if ( name == NULL || *name == '\0' ) {
507 if ((name = strrchr( path, '/' )) == NULL) {
508 return -1; /* Obviously not a fully qualified path */
511 /* if you wish to share /, you need to specify a name. */
516 for ( volume = Volumes; volume; volume = volume->v_next ) {
517 if ( strcasecmp( volume->v_name, name ) == 0 ) {
518 if (volume->v_deleted) {
522 return -1; /* Won't be able to access it, anyway... */
527 vlen = strlen( name );
528 if ( vlen > AFPVOL_NAMELEN ) {
529 vlen = AFPVOL_NAMELEN;
530 name[AFPVOL_NAMELEN] = '\0';
533 if (!( volume = (struct vol *)calloc(1, sizeof( struct vol ))) ) {
534 LOG(log_error, logtype_afpd, "creatvol: malloc: %s", strerror(errno) );
537 if (! ( volume->v_name = (char *)malloc( vlen + 1 ) ) ) {
538 LOG(log_error, logtype_afpd, "creatvol: malloc: %s", strerror(errno) );
542 if (!( volume->v_path = (char *)malloc( strlen( path ) + 1 )) ) {
543 LOG(log_error, logtype_afpd, "creatvol: malloc: %s", strerror(errno) );
544 free(volume->v_name);
548 volume->v_hide = hide;
549 strcpy( volume->v_name, name);
550 strcpy( volume->v_path, path );
554 #endif /* __svr4__ */
555 volume->v_vid = lastvid++;
556 volume->v_lastdid = 17;
560 /* should we casefold? */
561 volume->v_casefold = options[VOLOPT_CASEFOLD].i_value;
563 /* shift in some flags */
564 volume->v_flags = options[VOLOPT_FLAGS].i_value;
566 /* read in the code pages */
567 if (options[VOLOPT_CODEPAGE].c_value)
568 codepage_read(volume, options[VOLOPT_CODEPAGE].c_value);
570 if (options[VOLOPT_PASSWORD].c_value)
571 volume->v_password = strdup(options[VOLOPT_PASSWORD].c_value);
573 if (options[VOLOPT_VETO].c_value)
574 volume->v_veto = strdup(options[VOLOPT_VETO].c_value);
576 if (options[VOLOPT_ENCODING].c_value)
577 volume->v_encoding = strdup(options[VOLOPT_ENCODING].c_value);
579 if (options[VOLOPT_DBPATH].c_value)
580 volume->v_dbpath = volxlate(obj, NULL, MAXPATHLEN, options[VOLOPT_DBPATH].c_value, pwd, path);
583 if (options[VOLOPT_UMASK].i_value)
584 volume->v_umask = (mode_t)options[VOLOPT_UMASK].i_value;
587 if (options[VOLOPT_FORCEUID].c_value) {
588 volume->v_forceuid = strdup(options[VOLOPT_FORCEUID].c_value);
590 volume->v_forceuid = NULL; /* set as null so as to return 0 later on */
593 if (options[VOLOPT_FORCEGID].c_value) {
594 volume->v_forcegid = strdup(options[VOLOPT_FORCEGID].c_value);
596 volume->v_forcegid = NULL; /* set as null so as to return 0 later on */
600 if (options[VOLOPT_PREEXEC].c_value)
601 volume->v_preexec = volxlate(obj, NULL, MAXPATHLEN, options[VOLOPT_PREEXEC].c_value, pwd, path);
602 volume->v_preexec_close = options[VOLOPT_PREEXEC].i_value;
604 if (options[VOLOPT_POSTEXEC].c_value)
605 volume->v_postexec = volxlate(obj, NULL, MAXPATHLEN, options[VOLOPT_POSTEXEC].c_value, pwd, path);
607 if (options[VOLOPT_ROOTPREEXEC].c_value)
608 volume->v_root_preexec = volxlate(obj, NULL, MAXPATHLEN, options[VOLOPT_ROOTPREEXEC].c_value, pwd, path);
609 volume->v_root_preexec_close = options[VOLOPT_ROOTPREEXEC].i_value;
611 if (options[VOLOPT_ROOTPOSTEXEC].c_value)
612 volume->v_root_postexec = volxlate(obj, NULL, MAXPATHLEN, options[VOLOPT_ROOTPOSTEXEC].c_value, pwd, path);
616 volume->v_next = Volumes;
621 /* ---------------- */
622 static char *myfgets( buf, size, fp )
631 while ((EOF != ( c = getc( fp )) ) && ( size > 0 )) {
632 if ( c == '\n' || c == '\r' ) {
650 /* check access list. this function wants something of the following
652 * @group,name,name2,@group2,name3
654 * a NULL argument allows everybody to have access.
655 * we return three things:
657 * 0: list exists, but name isn't in it
660 static int accessvol(args, name)
664 char buf[MAXPATHLEN + 1], *p;
670 strncpy(buf, args, sizeof(buf));
671 if ((p = strtok(buf, ",")) == NULL) /* nothing, return okay */
675 if (*p == '@') { /* it's a group */
676 if ((gr = getgrnam(p + 1)) && gmem(gr->gr_gid))
678 } else if (strcmp(p, name) == 0) /* it's a user name */
680 p = strtok(NULL, ",");
686 static void setextmap( ext, type, creator, user)
687 char *ext, *type, *creator;
693 if (Extmap == NULL) {
694 if (( Extmap = calloc(1, sizeof( struct extmap ))) == NULL ) {
695 LOG(log_error, logtype_afpd, "setextmap: calloc: %s", strerror(errno) );
700 for ( em = Extmap, cnt = 0; em->em_ext; em++, cnt++) {
701 if ( (strdiacasecmp( em->em_ext, ext )) == 0 ) {
706 if ( em->em_ext == NULL ) {
707 if (!(Extmap = realloc( Extmap, sizeof( struct extmap ) * (cnt +2))) ) {
708 LOG(log_error, logtype_afpd, "setextmap: realloc: %s", strerror(errno) );
711 (Extmap +cnt +1)->em_ext = NULL;
713 } else if ( !user ) {
719 if (!(em->em_ext = strdup( ext))) {
720 LOG(log_error, logtype_afpd, "setextmap: strdup: %s", strerror(errno) );
724 if ( *type == '\0' ) {
725 memcpy(em->em_type, "????", sizeof( em->em_type ));
727 memcpy(em->em_type, type, sizeof( em->em_type ));
729 if ( *creator == '\0' ) {
730 memcpy(em->em_creator, "UNIX", sizeof( em->em_creator ));
732 memcpy(em->em_creator, creator, sizeof( em->em_creator ));
736 /* -------------------------- */
737 static int extmap_cmp(const void *map1, const void *map2)
739 const struct extmap *em1 = map1;
740 const struct extmap *em2 = map2;
741 return strdiacasecmp(em1->em_ext, em2->em_ext);
744 static void sortextmap( void)
749 if ((em = Extmap) == NULL) {
757 qsort(Extmap, Extmap_cnt, sizeof(struct extmap), extmap_cmp);
762 /* ----------------------
764 static void free_extmap( void)
774 /* ----------------------
776 static int volfile_changed(struct afp_volume_name *p)
786 if (!stat( name, &st) && st.st_mtime > p->mtime) {
787 p->mtime = st.st_mtime;
793 /* ----------------------
794 * Read a volume configuration file and add the volumes contained within to
795 * the global volume list. If p2 is non-NULL, the file that is opened is
798 * Lines that begin with # and blank lines are ignored.
799 * Volume lines are of the form:
800 * <unix path> [<volume name>] [allow:<user>,<@group>,...] \
801 * [codepage:<file>] [casefold:<num>]
802 * <extension> TYPE [CREATOR]
804 static int readvolfile(obj, p1, p2, user, pwent)
806 struct afp_volume_name *p1;
809 struct passwd *pwent;
812 char path[ MAXPATHLEN + 1], tmp[ MAXPATHLEN + 1],
813 volname[ AFPVOL_NAMELEN + 1 ], buf[ BUFSIZ ],
814 type[ 5 ], creator[ 5 ];
817 struct vol_option options[VOLOPT_NUM], save_options[VOLOPT_NUM];
825 strcpy( path, p1->name );
832 p1->full_name = strdup(path);
835 if (NULL == ( fp = fopen( path, "r" )) ) {
839 if (fd != -1 && !fstat( fd, &st) ) {
840 p1->mtime = st.st_mtime;
843 memset(save_options, 0, sizeof(save_options));
844 while ( myfgets( buf, sizeof( buf ), fp ) != NULL ) {
845 initline( strlen( buf ), buf );
846 parseline( sizeof( path ) - 1, path );
853 /* change the default options for this file */
854 if (strncmp(path, VOLOPT_DEFAULT, VOLOPT_DEFAULT_LEN) == 0) {
856 for (i = 0; i < VOLOPT_NUM; i++) {
857 if (parseline( sizeof( path ) - VOLOPT_DEFAULT_LEN - 1,
858 path + VOLOPT_DEFAULT_LEN) < 0)
860 volset(save_options, NULL, tmp, sizeof(tmp) - 1,
861 obj->options.nlspath, path + VOLOPT_DEFAULT_LEN);
867 if (( p = strchr( path, '/' )) != NULL ) {
875 if ( u == NULL || *u == '\0' || ( pw = getpwnam( u )) == NULL ) {
878 strcpy( tmp, pw->pw_dir );
879 if ( p != NULL && *p != '\0' ) {
883 /* Tag a user's home directory with their umask. Note, this will
884 * be overwritten if the user actually specifies a umask: option
885 * for a '~' volume. */
886 save_options[VOLOPT_UMASK].i_value = obj->options.save_mask;
890 /* send path through variable substitution */
891 if (*path != '~') /* need to copy path to tmp */
894 pwent = getpwnam(obj->username);
895 volxlate(obj, path, sizeof(path) - 1, tmp, pwent, NULL);
897 /* this is sort of braindead. basically, i want to be
898 * able to specify things in any order, but i don't want to
899 * re-write everything.
901 * currently we have options:
909 * options:prodos,crlf,noadouble,ro...
914 * namemask:x,y,!z (not implemented yet)
916 memcpy(options, save_options, sizeof(options));
919 /* read in up to VOLOP_NUM possible options */
920 for (i = 0; i < VOLOPT_NUM; i++) {
921 if (parseline( sizeof( tmp ) - 1, tmp ) < 0)
924 volset(options, save_options, volname, sizeof(volname) - 1,obj->options.nlspath, tmp);
927 /* check allow/deny lists:
928 allow -> either no list (-1), or in list (1)
929 deny -> either no list (-1), or not in list (0) */
930 if (accessvol(options[VOLOPT_ALLOW].c_value, obj->username) &&
931 (accessvol(options[VOLOPT_DENY].c_value, obj->username) < 1)) {
933 /* handle read-only behaviour. semantics:
934 * 1) neither the rolist nor the rwlist exist -> rw
935 * 2) rolist exists -> ro if user is in it.
936 * 3) rwlist exists -> ro unless user is in it. */
937 if (((options[VOLOPT_FLAGS].i_value & AFPVOL_RO) == 0) &&
938 ((accessvol(options[VOLOPT_ROLIST].c_value,
939 obj->username) == 1) ||
940 !accessvol(options[VOLOPT_RWLIST].c_value,
942 options[VOLOPT_FLAGS].i_value |= AFPVOL_RO;
944 /* do variable substitution for volname */
945 volxlate(obj, tmp, sizeof(tmp) - 1, volname, pwent, path);
946 creatvol(obj, pwent, path, tmp, options, p2 != NULL);
948 volfree(options, save_options);
952 parseline( sizeof( type ) - 1, type );
953 parseline( sizeof( creator ) - 1, creator );
954 setextmap( path, type, creator, user);
961 volfree(save_options, NULL);
963 if ( fclose( fp ) != 0 ) {
964 LOG(log_error, logtype_afpd, "readvolfile: fclose: %s", strerror(errno) );
970 /* ------------------------------- */
971 static void volume_free(struct vol *vol)
977 free(vol->v_password);
979 free(vol->v_encoding);
984 free(vol->v_forceuid);
985 free(vol->v_forcegid);
986 #endif /* FORCE_UIDGID */
989 /* ------------------------------- */
990 static void free_volumes(void )
993 struct vol *nvol, *ovol;
995 for ( vol = Volumes; vol; vol = vol->v_next ) {
996 if (( vol->v_flags & AFPVOL_OPEN ) ) {
1003 for ( vol = Volumes, ovol = NULL; vol; vol = nvol) {
1006 if (vol->v_name == NULL) {
1007 if (Volumes == vol) {
1014 ovol->v_next = nvol;
1024 /* ------------------------------- */
1025 static void volume_unlink(struct vol *volume)
1027 struct vol *vol, *ovol, *nvol;
1029 if (volume == Volumes) {
1030 Volumes = Volumes->v_next;
1033 for ( vol = Volumes, ovol = NULL; vol; vol = nvol) {
1036 if (vol == volume) {
1041 ovol->v_next = nvol;
1052 static int getvolspace( vol, bfree, btotal, xbfree, xbtotal, bsize )
1054 u_int32_t *bfree, *btotal, *bsize;
1055 VolSpace *xbfree, *xbtotal;
1059 #ifndef NO_QUOTA_SUPPORT
1060 VolSpace qfree, qtotal;
1063 spaceflag = AFPVOL_GVSMASK & vol->v_flags;
1064 /* report up to 2GB if afp version is < 2.2 (4GB if not) */
1065 maxsize = (vol->v_flags & AFPVOL_A2VOL) ? 0x01fffe00 :
1066 (((afp_version < 22) || (vol->v_flags & AFPVOL_LIMITSIZE))
1067 ? 0x7fffffffL : 0xffffffffL);
1070 if ( spaceflag == AFPVOL_NONE || spaceflag == AFPVOL_AFSGVS ) {
1071 if ( afs_getvolspace( vol, xbfree, xbtotal, bsize ) == AFP_OK ) {
1072 vol->v_flags = ( ~AFPVOL_GVSMASK & vol->v_flags ) | AFPVOL_AFSGVS;
1073 goto getvolspace_done;
1078 if (( rc = ustatfs_getvolspace( vol, xbfree, xbtotal,
1079 bsize)) != AFP_OK ) {
1083 #define min(a,b) ((a)<(b)?(a):(b))
1084 #ifndef NO_QUOTA_SUPPORT
1085 if ( spaceflag == AFPVOL_NONE || spaceflag == AFPVOL_UQUOTA ) {
1086 if ( uquota_getvolspace( vol, &qfree, &qtotal, *bsize ) == AFP_OK ) {
1087 vol->v_flags = ( ~AFPVOL_GVSMASK & vol->v_flags ) | AFPVOL_UQUOTA;
1088 *xbfree = min(*xbfree, qfree);
1089 *xbtotal = min( *xbtotal, qtotal);
1090 goto getvolspace_done;
1094 vol->v_flags = ( ~AFPVOL_GVSMASK & vol->v_flags ) | AFPVOL_USTATFS;
1097 *bfree = min( *xbfree, maxsize);
1098 *btotal = min( *xbtotal, maxsize);
1102 /* ----------------------- */
1103 static int getvolparams( bitmap, vol, st, buf, buflen )
1111 int bit = 0, isad = 1;
1114 u_int32_t bfree, btotal, bsize;
1115 VolSpace xbfree, xbtotal; /* extended bytes */
1116 char *data, *nameoff = NULL;
1119 /* courtesy of jallison@whistle.com:
1120 * For MacOS8.x support we need to create the
1121 * .Parent file here if it doesn't exist. */
1123 memset(&ad, 0, sizeof(ad));
1124 if ( ad_open( vol->v_path, vol_noadouble(vol) |
1125 ADFLAGS_HF|ADFLAGS_DIR, O_RDWR | O_CREAT,
1129 } else if (ad_get_HF_flags( &ad ) & O_CREAT) {
1130 slash = strrchr( vol->v_path, '/' );
1134 slash = vol->v_path;
1136 ad_setentrylen( &ad, ADEID_NAME, strlen( slash ));
1137 memcpy(ad_entry( &ad, ADEID_NAME ), slash,
1138 ad_getentrylen( &ad, ADEID_NAME ));
1139 ad_setdate(&ad, AD_DATE_CREATE | AD_DATE_UNIX, st->st_mtime);
1140 ad_flush(&ad, ADFLAGS_HF);
1143 if (( bitmap & ( (1<<VOLPBIT_BFREE)|(1<<VOLPBIT_BTOTAL) |
1144 (1<<VOLPBIT_XBFREE)|(1<<VOLPBIT_XBTOTAL) |
1145 (1<<VOLPBIT_BSIZE)) ) != 0 ) {
1146 if ( getvolspace( vol, &bfree, &btotal, &xbfree, &xbtotal,
1149 ad_close( &ad, ADFLAGS_HF );
1151 return( AFPERR_PARAM );
1156 while ( bitmap != 0 ) {
1157 while (( bitmap & 1 ) == 0 ) {
1166 if (0 == (vol->v_flags & AFPVOL_NOFILEID) && vol->v_db != NULL) {
1167 ashort = VOLPBIT_ATTR_FILEID;
1169 #endif /* CNID_DB */
1170 /* check for read-only.
1171 * NOTE: we don't actually set the read-only flag unless
1172 * it's passed in that way as it's possible to mount
1173 * a read-write filesystem under a read-only one. */
1174 if ((vol->v_flags & AFPVOL_RO) ||
1175 ((utime(vol->v_path, NULL) < 0) && (errno == EROFS))) {
1176 ashort |= VOLPBIT_ATTR_RO;
1178 ashort |= VOLPBIT_ATTR_CATSEARCH;
1179 if (afp_version >= 30) {
1180 ashort |= VOLPBIT_ATTR_UTF8;
1181 if (vol->v_flags & AFPVOL_UNIX_PRIV)
1182 ashort |= VOLPBIT_ATTR_UNIXPRIV;
1184 ashort = htons(ashort);
1185 memcpy(data, &ashort, sizeof( ashort ));
1186 data += sizeof( ashort );
1190 ashort = htons( AFPVOLSIG_DEFAULT );
1191 memcpy(data, &ashort, sizeof( ashort ));
1192 data += sizeof( ashort );
1195 case VOLPBIT_CDATE :
1196 if (!isad || (ad_getdate(&ad, AD_DATE_CREATE, &aint) < 0))
1197 aint = AD_DATE_FROM_UNIX(st->st_mtime);
1198 memcpy(data, &aint, sizeof( aint ));
1199 data += sizeof( aint );
1202 case VOLPBIT_MDATE :
1203 if ( st->st_mtime > vol->v_time ) {
1204 vol->v_time = st->st_mtime;
1205 aint = AD_DATE_FROM_UNIX(st->st_mtime);
1207 aint = AD_DATE_FROM_UNIX(vol->v_time);
1209 memcpy(data, &aint, sizeof( aint ));
1210 data += sizeof( aint );
1213 case VOLPBIT_BDATE :
1214 if (!isad || (ad_getdate(&ad, AD_DATE_BACKUP, &aint) < 0))
1215 aint = AD_DATE_START;
1216 memcpy(data, &aint, sizeof( aint ));
1217 data += sizeof( aint );
1221 memcpy(data, &vol->v_vid, sizeof( vol->v_vid ));
1222 data += sizeof( vol->v_vid );
1225 case VOLPBIT_BFREE :
1226 bfree = htonl( bfree );
1227 memcpy(data, &bfree, sizeof( bfree ));
1228 data += sizeof( bfree );
1231 case VOLPBIT_BTOTAL :
1232 btotal = htonl( btotal );
1233 memcpy(data, &btotal, sizeof( btotal ));
1234 data += sizeof( btotal );
1237 #ifndef NO_LARGE_VOL_SUPPORT
1238 case VOLPBIT_XBFREE :
1239 xbfree = hton64( xbfree );
1240 #if defined(__GNUC__) && defined(HAVE_GCC_MEMCPY_BUG)
1241 bcopy(&xbfree, data, sizeof(xbfree));
1242 #else /* __GNUC__ && HAVE_GCC_MEMCPY_BUG */
1243 memcpy(data, &xbfree, sizeof( xbfree ));
1244 #endif /* __GNUC__ && HAVE_GCC_MEMCPY_BUG */
1245 data += sizeof( xbfree );
1248 case VOLPBIT_XBTOTAL :
1249 xbtotal = hton64( xbtotal );
1250 #if defined(__GNUC__) && defined(HAVE_GCC_MEMCPY_BUG)
1251 bcopy(&xbtotal, data, sizeof(xbtotal));
1252 #else /* __GNUC__ && HAVE_GCC_MEMCPY_BUG */
1253 memcpy(data, &xbtotal, sizeof( xbtotal ));
1254 #endif /* __GNUC__ && HAVE_GCC_MEMCPY_BUG */
1255 data += sizeof( xbfree );
1257 #endif /* ! NO_LARGE_VOL_SUPPORT */
1261 data += sizeof( u_int16_t );
1264 case VOLPBIT_BSIZE: /* block size */
1265 bsize = htonl(bsize);
1266 memcpy(data, &bsize, sizeof(bsize));
1267 data += sizeof(bsize);
1272 ad_close( &ad, ADFLAGS_HF );
1274 return( AFPERR_BITMAP );
1280 ashort = htons( data - buf );
1281 memcpy(nameoff, &ashort, sizeof( ashort ));
1282 aint = strlen( vol->v_name );
1284 memcpy(data, vol->v_name, aint );
1288 ad_close( &ad, ADFLAGS_HF );
1290 *buflen = data - buf;
1294 /* ------------------------- */
1295 int static stat_vol(u_int16_t bitmap, struct vol *vol, char *rbuf, int *rbuflen)
1300 if ( stat( vol->v_path, &st ) < 0 ) {
1302 return( AFPERR_PARAM );
1305 buflen = *rbuflen - sizeof( bitmap );
1306 if (( ret = getvolparams( bitmap, vol, &st,
1307 rbuf + sizeof( bitmap ), &buflen )) != AFP_OK ) {
1311 *rbuflen = buflen + sizeof( bitmap );
1312 bitmap = htons( bitmap );
1313 memcpy(rbuf, &bitmap, sizeof( bitmap ));
1318 /* ------------------------------- */
1319 void load_volumes(AFPObj *obj)
1321 struct passwd *pwent;
1326 /* check files date */
1327 if (obj->options.defaultvol.loaded) {
1328 changed = volfile_changed(&obj->options.defaultvol);
1330 if (obj->options.systemvol.loaded) {
1331 changed |= volfile_changed(&obj->options.systemvol);
1333 if (obj->options.uservol.loaded) {
1334 changed |= volfile_changed(&obj->options.uservol);
1343 pwent = getpwnam(obj->username);
1344 if ( (obj->options.flags & OPTION_USERVOLFIRST) == 0 ) {
1345 readvolfile(obj, &obj->options.systemvol, NULL, 0, pwent);
1348 if ((*obj->username == '\0') || (obj->options.flags & OPTION_NOUSERVOL)) {
1349 readvolfile(obj, &obj->options.defaultvol, NULL, 1, pwent);
1352 * Read user's AppleVolumes or .AppleVolumes file
1353 * If neither are readable, read the default volumes file. if
1354 * that doesn't work, create a user share.
1356 obj->options.uservol.name = strdup(pwent->pw_dir);
1357 if ( readvolfile(obj, &obj->options.uservol, "AppleVolumes", 1, pwent) < 0 &&
1358 readvolfile(obj, &obj->options.uservol, ".AppleVolumes", 1, pwent) < 0 &&
1359 readvolfile(obj, &obj->options.uservol, "applevolumes", 1, pwent) < 0 &&
1360 readvolfile(obj, &obj->options.uservol, ".applevolumes", 1, pwent) < 0 &&
1361 obj->options.defaultvol.name != NULL ) {
1362 if (readvolfile(obj, &obj->options.defaultvol, NULL, 1, pwent) < 0)
1363 creatvol(obj, pwent, pwent->pw_dir, NULL, NULL, 1);
1366 if ( obj->options.flags & OPTION_USERVOLFIRST ) {
1367 readvolfile(obj, &obj->options.systemvol, NULL, 0, pwent );
1371 /* ------------------------------- */
1372 int afp_getsrvrparms(obj, ibuf, ibuflen, rbuf, rbuflen )
1375 int ibuflen, *rbuflen;
1387 for ( vcnt = 0, volume = Volumes; volume; volume = volume->v_next ) {
1388 if (!(volume->v_flags & AFPVOL_NOSTAT)) {
1389 if ( stat( volume->v_path, &st ) < 0 ) {
1390 LOG(log_info, logtype_afpd, "afp_getsrvrparms: stat %s: %s",
1391 volume->v_path, strerror(errno) );
1392 continue; /* can't access directory */
1394 if (!S_ISDIR(st.st_mode)) {
1395 continue; /* not a dir */
1398 if (volume->v_hide) {
1399 continue; /* config file changed but the volume was mounted */
1402 /* set password bit if there's a volume password */
1403 *data = (volume->v_password) ? AFPSRVR_PASSWD : 0;
1405 /* Apple 2 clients running ProDOS-8 expect one volume to have
1406 bit 0 of this byte set. They will not recognize anything
1407 on the server unless this is the case. I have not
1408 completely worked this out, but it's related to booting
1409 from the server. Support for that function is a ways
1410 off.. <shirsch@ibm.net> */
1411 *data |= (volume->v_flags & AFPVOL_A2VOL) ? AFPSRVR_CONFIGINFO : 0;
1412 *data++ |= 0; /* UNIX PRIVS BIT ..., OSX doesn't seem to use it, so we don't either */
1413 len = strlen( volume->v_name );
1415 memcpy(data, volume->v_name, len );
1420 *rbuflen = data - rbuf;
1422 if ( gettimeofday( &tv, 0 ) < 0 ) {
1423 LOG(log_error, logtype_afpd, "afp_getsrvrparms: gettimeofday: %s", strerror(errno) );
1425 return AFPERR_PARAM;
1427 tv.tv_sec = AD_DATE_FROM_UNIX(tv.tv_sec);
1428 memcpy(data, &tv.tv_sec, sizeof( u_int32_t));
1429 data += sizeof( u_int32_t);
1434 /* -------------------------
1435 * we are the user here
1437 int afp_openvol(obj, ibuf, ibuflen, rbuf, rbuflen )
1440 int ibuflen, *rbuflen;
1453 memcpy(&bitmap, ibuf, sizeof( bitmap ));
1454 bitmap = ntohs( bitmap );
1455 ibuf += sizeof( bitmap );
1456 if (( bitmap & (1<<VOLPBIT_VID)) == 0 ) {
1458 return AFPERR_BITMAP;
1461 len = (unsigned char)*ibuf++;
1462 volname = obj->oldtmp;
1463 memcpy(volname, ibuf, len );
1464 *(volname + len) = '\0';
1466 if ((len + 1) & 1) /* pad to an even boundary */
1471 for ( volume = Volumes; volume; volume = volume->v_next ) {
1472 if ( strcasecmp( volname, volume->v_name ) == 0 ) {
1477 if ( volume == NULL ) {
1479 return AFPERR_PARAM;
1482 /* check for a volume password */
1483 if (volume->v_password && strncmp(ibuf, volume->v_password, VOLPASSLEN)) {
1485 return AFPERR_ACCESS;
1488 if (( volume->v_flags & AFPVOL_OPEN ) ) {
1489 /* the volume is already open */
1491 set_uidgid ( volume );
1493 return stat_vol(bitmap, volume, rbuf, rbuflen);
1496 /* initialize volume variables
1499 if (afp_version >= 30) {
1500 volume->max_filename = 255;
1503 volume->max_filename = MACFILELEN;
1507 volume->v_db = NULL;
1509 volume->v_dir = volume->v_root = NULL;
1511 /* FIXME unix name != mac name */
1512 if ((dir = dirnew(volume->v_name, volume->v_name) ) == NULL) {
1513 LOG(log_error, logtype_afpd, "afp_openvol: malloc: %s", strerror(errno) );
1518 dir->d_did = DIRDID_ROOT;
1519 dir->d_color = DIRTREE_COLOR_BLACK; /* root node is black */
1520 volume->v_dir = volume->v_root = dir;
1521 volume->v_flags |= AFPVOL_OPEN;
1523 if (volume->v_root_preexec) {
1524 if ((ret = afprun(1, volume->v_root_preexec, NULL)) && volume->v_root_preexec_close) {
1525 LOG(log_error, logtype_afpd, "afp_openvol: root preexec : %d", ret );
1532 set_uidgid ( volume );
1535 if (volume->v_preexec) {
1536 if ((ret = afprun(0, volume->v_preexec, NULL)) && volume->v_preexec_close) {
1537 LOG(log_error, logtype_afpd, "afp_openvol: preexec : %d", ret );
1543 if ( stat( volume->v_path, &st ) < 0 ) {
1548 if ( chdir( volume->v_path ) < 0 ) {
1552 curdir = volume->v_dir;
1555 if (volume->v_dbpath)
1556 volume->v_db = cnid_open (volume->v_dbpath, volume->v_umask);
1557 if (volume->v_db == NULL)
1558 volume->v_db = cnid_open (volume->v_path, volume->v_umask);
1559 if (volume->v_db == NULL) {
1560 /* FIXME config option?
1561 * - mount the volume readonly
1563 * - read/write with other scheme
1568 if ( 0 == ( volume->v_maccharset = add_charset(volume->v_encoding?volume->v_encoding:"MAC")) )
1569 volume->v_maccharset = CH_MAC;
1571 ret = stat_vol(bitmap, volume, rbuf, rbuflen);
1572 if (ret == AFP_OK) {
1575 * If you mount a volume twice, the second time the trash appears on
1576 * the desk-top. That's because the Mac remembers the DID for the
1577 * trash (even for volumes in different zones, on different servers).
1578 * Just so this works better, we prime the DID cache with the trash,
1579 * fixing the trash at DID 17.
1582 cname( volume, volume->v_dir, &p );
1588 if (volume->v_dir) {
1589 dirfree( volume->v_dir );
1590 volume->v_dir = volume->v_root = NULL;
1593 volume->v_flags &= ~AFPVOL_OPEN;
1596 if (volume->v_db != NULL) {
1597 cnid_close(volume->v_db);
1598 volume->v_db = NULL;
1605 /* ------------------------- */
1606 static void closevol(struct vol *vol)
1611 dirfree( vol->v_root );
1614 cnid_close(vol->v_db);
1616 #endif /* CNID_DB */
1618 if (vol->v_postexec) {
1619 afprun(0, vol->v_postexec, NULL);
1621 if (vol->v_root_postexec) {
1622 afprun(1, vol->v_root_postexec, NULL);
1626 /* ------------------------- */
1627 void close_all_vol(void)
1631 for ( ovol = Volumes; ovol; ovol = ovol->v_next ) {
1632 if ( ovol->v_flags & AFPVOL_OPEN ) {
1633 ovol->v_flags &= ~AFPVOL_OPEN;
1639 /* ------------------------- */
1640 int afp_closevol(obj, ibuf, ibuflen, rbuf, rbuflen )
1643 int ibuflen, *rbuflen;
1645 struct vol *vol, *ovol;
1650 memcpy(&vid, ibuf, sizeof( vid ));
1651 if (NULL == ( vol = getvolbyvid( vid )) ) {
1652 return( AFPERR_PARAM );
1655 vol->v_flags &= ~AFPVOL_OPEN;
1656 for ( ovol = Volumes; ovol; ovol = ovol->v_next ) {
1657 if ( ovol->v_flags & AFPVOL_OPEN ) {
1661 if ( ovol != NULL ) {
1662 /* Even if chdir fails, we can't say afp_closevol fails. */
1663 if ( chdir( ovol->v_path ) == 0 ) {
1664 curdir = ovol->v_dir;
1669 if (vol->v_deleted) {
1670 showvol(vol->v_name);
1677 /* ------------------------- */
1678 struct vol *getvolbyvid(const u_int16_t vid )
1682 for ( vol = Volumes; vol; vol = vol->v_next ) {
1683 if ( vid == vol->v_vid ) {
1687 if ( vol == NULL || ( vol->v_flags & AFPVOL_OPEN ) == 0 ) {
1693 #endif /* FORCE_UIDGID */
1698 /* ------------------------ */
1699 static int ext_cmp_key(const void *key, const void *obj)
1701 const char *p = key;
1702 const struct extmap *em = obj;
1703 return strdiacasecmp(p, em->em_ext);
1705 struct extmap *getextmap(const char *path)
1710 if (NULL == ( p = strrchr( path, '.' )) ) {
1711 return( Defextmap );
1714 if (!*p || !Extmap_cnt) {
1715 return( Defextmap );
1717 em = bsearch(p, Extmap, Extmap_cnt, sizeof(struct extmap), ext_cmp_key);
1721 return( Defextmap );
1725 /* ------------------------- */
1726 struct extmap *getdefextmap(void)
1728 return( Defextmap );
1731 /* --------------------------
1732 poll if a volume is changed by other processes.
1734 int pollvoltime(obj)
1741 if (!(afp_version > 21 && obj->options.server_notif))
1744 if ( gettimeofday( &tv, 0 ) < 0 )
1747 for ( vol = Volumes; vol; vol = vol->v_next ) {
1748 if ( (vol->v_flags & AFPVOL_OPEN) && vol->v_time + 30 < tv.tv_sec) {
1749 if ( !stat( vol->v_path, &st ) && vol->v_time != st.st_mtime ) {
1750 vol->v_time = st.st_mtime;
1751 if (!obj->attention(obj->handle, AFPATTN_NOTIFY | AFPATTN_VOLCHANGED))
1760 /* ------------------------- */
1761 void setvoltime(obj, vol )
1767 /* just looking at vol->v_time is broken seriously since updates
1768 * from other users afpd processes never are seen.
1769 * This is not the most elegant solution (a shared memory between
1770 * the afpd processes would come closer)
1773 if ( gettimeofday( &tv, 0 ) < 0 ) {
1774 LOG(log_error, logtype_afpd, "setvoltime: gettimeofday: %s", strerror(errno) );
1777 if( utime( vol->v_path, NULL ) < 0 ) {
1778 /* write of time failed ... probably a read only filesys,
1779 * where no other users can interfere, so there's no issue here
1783 /* a little granularity */
1784 if (vol->v_time < tv.tv_sec) {
1785 vol->v_time = tv.tv_sec;
1786 if (afp_version > 21 && obj->options.server_notif) {
1787 obj->attention(obj->handle, AFPATTN_NOTIFY | AFPATTN_VOLCHANGED);
1792 /* ------------------------- */
1793 int afp_getvolparams(obj, ibuf, ibuflen, rbuf, rbuflen )
1796 int ibuflen, *rbuflen;
1799 u_int16_t vid, bitmap;
1802 memcpy(&vid, ibuf, sizeof( vid ));
1803 ibuf += sizeof( vid );
1804 memcpy(&bitmap, ibuf, sizeof( bitmap ));
1805 bitmap = ntohs( bitmap );
1807 if (NULL == ( vol = getvolbyvid( vid )) ) {
1809 return( AFPERR_PARAM );
1812 return stat_vol(bitmap, vol, rbuf, rbuflen);
1815 /* ------------------------- */
1816 int afp_setvolparams(obj, ibuf, ibuflen, rbuf, rbuflen )
1819 int ibuflen, *rbuflen;
1823 u_int16_t vid, bitmap;
1829 memcpy(&vid, ibuf, sizeof( vid ));
1830 ibuf += sizeof( vid );
1831 memcpy(&bitmap, ibuf, sizeof( bitmap ));
1832 bitmap = ntohs( bitmap );
1833 ibuf += sizeof(bitmap);
1835 if (( vol = getvolbyvid( vid )) == NULL ) {
1836 return( AFPERR_PARAM );
1839 if (vol->v_flags & AFPVOL_RO)
1840 return AFPERR_VLOCK;
1842 /* we can only set the backup date. */
1843 if (bitmap != (1 << VOLPBIT_BDATE))
1844 return AFPERR_BITMAP;
1846 memset(&ad, 0, sizeof(ad));
1847 if ( ad_open( vol->v_path, ADFLAGS_HF|ADFLAGS_DIR, O_RDWR,
1850 return AFPERR_VLOCK;
1852 return AFPERR_ACCESS;
1855 memcpy(&aint, ibuf, sizeof(aint));
1856 ad_setdate(&ad, AD_DATE_BACKUP, aint);
1857 ad_flush(&ad, ADFLAGS_HF);
1858 ad_close(&ad, ADFLAGS_HF);
1862 /* ------------------------- */
1863 int wincheck(const struct vol *vol, const char *path)
1867 if (!(vol->v_flags & AFPVOL_MSWINDOWS))
1870 /* empty paths are not allowed */
1871 if ((len = strlen(path)) == 0)
1874 /* leading or trailing whitespaces are not allowed, carriage returns
1875 * and probably other whitespace is okay, tabs are not allowed
1877 if ((path[0] == ' ') || (path[len-1] == ' '))
1880 /* certain characters are not allowed */
1881 if (strpbrk(path, MSWINDOWS_BADCHARS))
1884 /* everything else is okay */