2 * $Id: volume.c,v 1.51.2.4 2003-05-26 17:02:47 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 */
119 #define VOLOPT_FORCEUID 15 /* force uid for username x */
120 #define VOLOPT_FORCEGID 16 /* force gid for group x */
121 #define VOLOPT_UMASK 17
123 #define VOLOPT_UMASK 15
124 #endif /* FORCE_UIDGID */
126 #define VOLOPT_MAX (VOLOPT_UMASK +1)
128 #define VOLOPT_NUM (VOLOPT_MAX + 1)
131 #define VOLOPT_DEFAULT ":DEFAULT:"
132 #define VOLOPT_DEFAULT_LEN 9
138 static __inline__ void volfree(struct vol_option *options,
139 const struct vol_option *save)
144 for (i = 0; i < VOLOPT_MAX; i++) {
145 if (options[i].c_value && (options[i].c_value != save[i].c_value))
146 free(options[i].c_value);
149 for (i = 0; i < VOLOPT_MAX; i++) {
150 if (options[i].c_value)
151 free(options[i].c_value);
157 /* handle variable substitutions. here's what we understand:
158 * $b -> basename of path
159 * $c -> client ip/appletalk address
160 * $d -> volume pathname on server
161 * $f -> full name (whatever's in the gecos field)
164 * $s -> server name (hostname if it doesn't exist)
165 * $u -> username (guest is usually nobody)
166 * $v -> volume name (ADEID_NAME or basename if ADEID_NAME is empty)
167 * $z -> zone (may not exist)
170 #define is_var(a, b) (strncmp((a), (b), 2) == 0)
172 static char *volxlate(AFPObj *obj, char *dest, size_t destlen,
173 char *src, struct passwd *pwd, char *path)
183 dest = calloc(destlen +1, 1);
189 strncpy(dest, src, destlen);
190 if ((p = strchr(src, '$')) == NULL) /* nothing to do */
193 /* first part of the path. just forward to the next variable. */
194 len = MIN(p - src, destlen);
200 while (p && destlen > 0) {
201 /* now figure out what the variable is */
203 if (is_var(p, "$b")) {
205 if ((q = strrchr(path, '/')) == NULL)
207 else if (*(q + 1) != '\0')
210 } else if (is_var(p, "$c")) {
211 if (obj->proto == AFPPROTO_ASP) {
212 ASP asp = obj->handle;
214 len = sprintf(dest, "%u.%u", ntohs(asp->asp_sat.sat_addr.s_net),
215 asp->asp_sat.sat_addr.s_node);
219 } else if (obj->proto == AFPPROTO_DSI) {
220 DSI *dsi = obj->handle;
222 len = sprintf(dest, "%s:%u", inet_ntoa(dsi->client.sin_addr),
223 ntohs(dsi->client.sin_port));
227 } else if (is_var(p, "$d")) {
229 } else if (is_var(p, "$f")) {
230 if ((q = strchr(pwd->pw_gecos, ',')))
233 } else if (is_var(p, "$g")) {
234 struct group *grp = getgrgid(pwd->pw_gid);
237 } else if (is_var(p, "$h")) {
238 q = obj->options.hostname;
239 } else if (is_var(p, "$s")) {
242 else if (obj->options.server) {
243 q = obj->options.server;
245 q = obj->options.hostname;
246 } else if (is_var(p, "$u")) {
248 } else if (is_var(p, "$v")) {
252 memset(&ad, 0, sizeof(ad));
253 if (ad_open(path, ADFLAGS_HF, O_RDONLY, 0, &ad) < 0)
256 if ((len = MIN(ad_getentrylen(&ad, ADEID_NAME), destlen)) > 0) {
257 memcpy(dest, ad_entry(&ad, ADEID_NAME), len);
258 ad_close(&ad, ADFLAGS_HF);
262 ad_close(&ad, ADFLAGS_HF);
263 no_volname: /* simple basename */
264 if ((q = strrchr(path, '/')) == NULL)
266 else if (*(q + 1) != '\0')
270 } else if (is_var(p, "$z")) {
272 } else if (is_var(p, "$$")) {
277 /* copy the stuff over. if we don't understand something that we
278 * should, just skip it over. */
280 len = MIN(p == q ? 2 : strlen(q), destlen);
281 strncpy(dest, q, len);
286 /* stuff up to next $ */
288 p = strchr(src, '$');
289 len = p ? MIN(p - src, destlen) : destlen;
291 strncpy(dest, src, len);
299 /* to make sure that val is valid, make sure to select an opt that
301 static int optionok(const char *buf, const char *opt, const char *val)
303 if (!strstr(buf,opt))
310 static __inline__ char *get_codepage_path(const char *path, const char *name)
316 page = (char *) malloc((len = strlen(path)) + strlen(name) + 2);
319 if (path[len - 1] != '/') /* add a / */
327 /* debug: show which codepage directory we are using */
328 LOG(log_debug, logtype_afpd, "using codepage directory: %s", page);
333 /* -------------------- */
334 static void setoption(struct vol_option *options, struct vol_option *save, int opt, const char *val)
336 if (options[opt].c_value && (!save || options[opt].c_value != save[opt].c_value))
337 free(options[opt].c_value);
338 options[opt].c_value = strdup(val + 1);
341 /* ------------------------------------------
342 handle all the options. tmp can't be NULL. */
343 static void volset(struct vol_option *options, struct vol_option *save,
344 char *volname, int vlen,
345 const char *nlspath, const char *tmp)
349 val = strchr(tmp, ':');
351 /* we'll assume it's a volume name. */
352 strncpy(volname, tmp, vlen);
357 LOG(log_debug, logtype_afpd, "Parsing volset %s", val);
359 if (optionok(tmp, "allow:", val)) {
360 setoption(options, save, VOLOPT_ALLOW, val);
362 } else if (optionok(tmp, "deny:", val)) {
363 setoption(options, save, VOLOPT_DENY, val);
365 } else if (optionok(tmp, "rwlist:", val)) {
366 setoption(options, save, VOLOPT_RWLIST, val);
368 } else if (optionok(tmp, "rolist:", val)) {
369 setoption(options, save, VOLOPT_ROLIST, val);
371 } else if (optionok(tmp, "codepage:", val)) {
372 if (options[VOLOPT_CODEPAGE].c_value &&
373 (!save || options[VOLOPT_CODEPAGE].c_value != save[VOLOPT_CODEPAGE].c_value)) {
374 free(options[VOLOPT_CODEPAGE].c_value);
376 options[VOLOPT_CODEPAGE].c_value = get_codepage_path(nlspath, val + 1);
378 } else if (optionok(tmp, "veto:", val)) {
379 setoption(options, save, VOLOPT_VETO, val);
380 } else if (optionok(tmp, "casefold:", val)) {
381 if (strcasecmp(val + 1, "tolower") == 0)
382 options[VOLOPT_CASEFOLD].i_value = AFPVOL_UMLOWER;
383 else if (strcasecmp(val + 1, "toupper") == 0)
384 options[VOLOPT_CASEFOLD].i_value = AFPVOL_UMUPPER;
385 else if (strcasecmp(val + 1, "xlatelower") == 0)
386 options[VOLOPT_CASEFOLD].i_value = AFPVOL_UUPPERMLOWER;
387 else if (strcasecmp(val + 1, "xlateupper") == 0)
388 options[VOLOPT_CASEFOLD].i_value = AFPVOL_ULOWERMUPPER;
390 } else if (optionok(tmp, "options:", val)) {
393 if ((p = strtok(val + 1, ",")) == NULL) /* nothing */
397 if (strcasecmp(p, "prodos") == 0)
398 options[VOLOPT_FLAGS].i_value |= AFPVOL_A2VOL;
399 else if (strcasecmp(p, "mswindows") == 0) {
400 options[VOLOPT_FLAGS].i_value |= AFPVOL_MSWINDOWS;
401 if (!options[VOLOPT_CODEPAGE].c_value)
402 options[VOLOPT_CODEPAGE].c_value =
403 get_codepage_path(nlspath, MSWINDOWS_CODEPAGE);
405 } else if (strcasecmp(p, "crlf") == 0)
406 options[VOLOPT_FLAGS].i_value |= AFPVOL_CRLF;
407 else if (strcasecmp(p, "noadouble") == 0)
408 options[VOLOPT_FLAGS].i_value |= AFPVOL_NOADOUBLE;
409 else if (strcasecmp(p, "ro") == 0)
410 options[VOLOPT_FLAGS].i_value |= AFPVOL_RO;
411 else if (strcasecmp(p, "nohex") == 0)
412 options[VOLOPT_FLAGS].i_value |= AFPVOL_NOHEX;
413 else if (strcasecmp(p, "usedots") == 0)
414 options[VOLOPT_FLAGS].i_value |= AFPVOL_USEDOTS;
415 else if (strcasecmp(p, "limitsize") == 0)
416 options[VOLOPT_FLAGS].i_value |= AFPVOL_LIMITSIZE;
417 /* support for either "dropbox" or "dropkludge" */
418 else if (strcasecmp(p, "dropbox") == 0)
419 options[VOLOPT_FLAGS].i_value |= AFPVOL_DROPBOX;
420 else if (strcasecmp(p, "dropkludge") == 0)
421 options[VOLOPT_FLAGS].i_value |= AFPVOL_DROPBOX;
422 else if (strcasecmp(p, "nofileid") == 0)
423 options[VOLOPT_FLAGS].i_value |= AFPVOL_NOFILEID;
424 else if (strcasecmp(p, "utf8") == 0)
425 options[VOLOPT_FLAGS].i_value |= AFPVOL_UTF8;
426 else if (strcasecmp(p, "nostat") == 0)
427 options[VOLOPT_FLAGS].i_value |= AFPVOL_NOSTAT;
428 else if (strcasecmp(p, "preexec_close") == 0)
429 options[VOLOPT_PREEXEC].i_value = 1;
430 else if (strcasecmp(p, "root_preexec_close") == 0)
431 options[VOLOPT_ROOTPREEXEC].i_value = 1;
432 p = strtok(NULL, ",");
437 } else if (optionok(tmp, "dbpath:", val)) {
438 setoption(options, save, VOLOPT_DBPATH, val);
441 } else if (optionok(tmp, "umask:", val)) {
442 options[VOLOPT_UMASK].i_value = (int)strtol(val, (char **)NULL, 8);
443 } else if (optionok(tmp, "mapchars:",val)) {
444 setoption(options, save, VOLOPT_MAPCHARS, val);
446 } else if (optionok(tmp, "password:", val)) {
447 setoption(options, save, VOLOPT_PASSWORD, val);
451 /* this code allows forced uid/gid per volume settings */
452 } else if (optionok(tmp, "forceuid:", val)) {
453 setoption(options, save, VOLOPT_FORCEUID, val);
454 } else if (optionok(tmp, "forcegid:", val)) {
455 setoption(options, save, VOLOPT_FORCEGID, val);
457 #endif /* FORCE_UIDGID */
458 } else if (optionok(tmp, "root_preexec:", val)) {
459 setoption(options, save, VOLOPT_ROOTPREEXEC, val);
461 } else if (optionok(tmp, "preexec:", val)) {
462 setoption(options, save, VOLOPT_PREEXEC, val);
464 } else if (optionok(tmp, "root_postexec:", val)) {
465 setoption(options, save, VOLOPT_ROOTPOSTEXEC, val);
467 } else if (optionok(tmp, "postexec:", val)) {
468 setoption(options, save, VOLOPT_POSTEXEC, val);
471 /* ignore unknown options */
472 LOG(log_debug, logtype_afpd, "ignoring unknown volume option: %s", tmp);
477 /* ----------------- */
478 static void showvol(const char *name)
481 for ( volume = Volumes; volume; volume = volume->v_next ) {
482 if ( !strcasecmp( volume->v_name, name ) && volume->v_hide) {
489 /* ------------------------------- */
490 static int creatvol(AFPObj *obj, struct passwd *pwd,
491 char *path, char *name,
492 struct vol_option *options,
493 const int user /* user defined volume */
500 if ( name == NULL || *name == '\0' ) {
501 if ((name = strrchr( path, '/' )) == NULL) {
502 return -1; /* Obviously not a fully qualified path */
505 /* if you wish to share /, you need to specify a name. */
510 for ( volume = Volumes; volume; volume = volume->v_next ) {
511 if ( strcasecmp( volume->v_name, name ) == 0 ) {
512 if (volume->v_deleted) {
516 return -1; /* Won't be able to access it, anyway... */
521 vlen = strlen( name );
522 if ( vlen > AFPVOL_NAMELEN ) {
523 vlen = AFPVOL_NAMELEN;
524 name[AFPVOL_NAMELEN] = '\0';
527 if (!( volume = (struct vol *)calloc(1, sizeof( struct vol ))) ) {
528 LOG(log_error, logtype_afpd, "creatvol: malloc: %s", strerror(errno) );
531 if (! ( volume->v_name = (char *)malloc( vlen + 1 ) ) ) {
532 LOG(log_error, logtype_afpd, "creatvol: malloc: %s", strerror(errno) );
536 if (!( volume->v_path = (char *)malloc( strlen( path ) + 1 )) ) {
537 LOG(log_error, logtype_afpd, "creatvol: malloc: %s", strerror(errno) );
538 free(volume->v_name);
542 volume->v_hide = hide;
543 strcpy( volume->v_name, name);
544 strcpy( volume->v_path, path );
548 #endif /* __svr4__ */
549 volume->v_vid = lastvid++;
550 volume->v_lastdid = 17;
554 /* should we casefold? */
555 volume->v_casefold = options[VOLOPT_CASEFOLD].i_value;
557 /* shift in some flags */
558 volume->v_flags = options[VOLOPT_FLAGS].i_value;
560 /* read in the code pages */
561 if (options[VOLOPT_CODEPAGE].c_value)
562 codepage_read(volume, options[VOLOPT_CODEPAGE].c_value);
564 if (options[VOLOPT_PASSWORD].c_value)
565 volume->v_password = strdup(options[VOLOPT_PASSWORD].c_value);
567 if (options[VOLOPT_VETO].c_value)
568 volume->v_veto = strdup(options[VOLOPT_VETO].c_value);
571 if (options[VOLOPT_DBPATH].c_value)
572 volume->v_dbpath = volxlate(obj, NULL, MAXPATHLEN, options[VOLOPT_DBPATH].c_value, pwd, path);
575 if (options[VOLOPT_UMASK].i_value)
576 volume->v_umask = (mode_t)options[VOLOPT_UMASK].i_value;
579 if (options[VOLOPT_FORCEUID].c_value) {
580 volume->v_forceuid = strdup(options[VOLOPT_FORCEUID].c_value);
582 volume->v_forceuid = NULL; /* set as null so as to return 0 later on */
585 if (options[VOLOPT_FORCEGID].c_value) {
586 volume->v_forcegid = strdup(options[VOLOPT_FORCEGID].c_value);
588 volume->v_forcegid = NULL; /* set as null so as to return 0 later on */
592 if (options[VOLOPT_PREEXEC].c_value)
593 volume->v_preexec = volxlate(obj, NULL, MAXPATHLEN, options[VOLOPT_PREEXEC].c_value, pwd, path);
594 volume->v_preexec_close = options[VOLOPT_PREEXEC].i_value;
596 if (options[VOLOPT_POSTEXEC].c_value)
597 volume->v_postexec = volxlate(obj, NULL, MAXPATHLEN, options[VOLOPT_POSTEXEC].c_value, pwd, path);
599 if (options[VOLOPT_ROOTPREEXEC].c_value)
600 volume->v_root_preexec = volxlate(obj, NULL, MAXPATHLEN, options[VOLOPT_ROOTPREEXEC].c_value, pwd, path);
601 volume->v_root_preexec_close = options[VOLOPT_ROOTPREEXEC].i_value;
603 if (options[VOLOPT_ROOTPOSTEXEC].c_value)
604 volume->v_root_postexec = volxlate(obj, NULL, MAXPATHLEN, options[VOLOPT_ROOTPOSTEXEC].c_value, pwd, path);
608 volume->v_next = Volumes;
613 /* ---------------- */
614 static char *myfgets( buf, size, fp )
623 while ((EOF != ( c = getc( fp )) ) && ( size > 0 )) {
624 if ( c == '\n' || c == '\r' ) {
642 /* check access list. this function wants something of the following
644 * @group,name,name2,@group2,name3
646 * a NULL argument allows everybody to have access.
647 * we return three things:
649 * 0: list exists, but name isn't in it
652 static int accessvol(args, name)
656 char buf[MAXPATHLEN + 1], *p;
662 strncpy(buf, args, sizeof(buf));
663 if ((p = strtok(buf, ",")) == NULL) /* nothing, return okay */
667 if (*p == '@') { /* it's a group */
668 if ((gr = getgrnam(p + 1)) && gmem(gr->gr_gid))
670 } else if (strcmp(p, name) == 0) /* it's a user name */
672 p = strtok(NULL, ",");
678 static void setextmap( ext, type, creator, user)
679 char *ext, *type, *creator;
685 if (Extmap == NULL) {
686 if (( Extmap = calloc(1, sizeof( struct extmap ))) == NULL ) {
687 LOG(log_error, logtype_afpd, "setextmap: calloc: %s", strerror(errno) );
692 for ( em = Extmap, cnt = 0; em->em_ext; em++, cnt++) {
693 if ( (strdiacasecmp( em->em_ext, ext )) == 0 ) {
698 if ( em->em_ext == NULL ) {
699 if (!(Extmap = realloc( Extmap, sizeof( struct extmap ) * (cnt +2))) ) {
700 LOG(log_error, logtype_afpd, "setextmap: realloc: %s", strerror(errno) );
703 (Extmap +cnt +1)->em_ext = NULL;
705 } else if ( !user ) {
711 if (!(em->em_ext = strdup( ext))) {
712 LOG(log_error, logtype_afpd, "setextmap: strdup: %s", strerror(errno) );
716 if ( *type == '\0' ) {
717 memcpy(em->em_type, "????", sizeof( em->em_type ));
719 memcpy(em->em_type, type, sizeof( em->em_type ));
721 if ( *creator == '\0' ) {
722 memcpy(em->em_creator, "UNIX", sizeof( em->em_creator ));
724 memcpy(em->em_creator, creator, sizeof( em->em_creator ));
728 /* -------------------------- */
729 static int extmap_cmp(const void *map1, const void *map2)
731 const struct extmap *em1 = map1;
732 const struct extmap *em2 = map2;
733 return strdiacasecmp(em1->em_ext, em2->em_ext);
736 static void sortextmap( void)
741 if ((em = Extmap) == NULL) {
749 qsort(Extmap, Extmap_cnt, sizeof(struct extmap), extmap_cmp);
754 /* ----------------------
756 static void free_extmap( void)
766 /* ----------------------
768 static int volfile_changed(struct afp_volume_name *p)
778 if (!stat( name, &st) && st.st_mtime > p->mtime) {
779 p->mtime = st.st_mtime;
785 /* ----------------------
786 * Read a volume configuration file and add the volumes contained within to
787 * the global volume list. If p2 is non-NULL, the file that is opened is
790 * Lines that begin with # and blank lines are ignored.
791 * Volume lines are of the form:
792 * <unix path> [<volume name>] [allow:<user>,<@group>,...] \
793 * [codepage:<file>] [casefold:<num>]
794 * <extension> TYPE [CREATOR]
796 static int readvolfile(obj, p1, p2, user, pwent)
798 struct afp_volume_name *p1;
801 struct passwd *pwent;
804 char path[ MAXPATHLEN + 1], tmp[ MAXPATHLEN + 1],
805 volname[ AFPVOL_NAMELEN + 1 ], buf[ BUFSIZ ],
806 type[ 5 ], creator[ 5 ];
809 struct vol_option options[VOLOPT_NUM], save_options[VOLOPT_NUM];
817 strcpy( path, p1->name );
824 p1->full_name = strdup(path);
827 if (NULL == ( fp = fopen( path, "r" )) ) {
831 if (fd != -1 && !fstat( fd, &st) ) {
832 p1->mtime = st.st_mtime;
835 memset(save_options, 0, sizeof(save_options));
836 while ( myfgets( buf, sizeof( buf ), fp ) != NULL ) {
837 initline( strlen( buf ), buf );
838 parseline( sizeof( path ) - 1, path );
845 /* change the default options for this file */
846 if (strncmp(path, VOLOPT_DEFAULT, VOLOPT_DEFAULT_LEN) == 0) {
848 for (i = 0; i < VOLOPT_NUM; i++) {
849 if (parseline( sizeof( path ) - VOLOPT_DEFAULT_LEN - 1,
850 path + VOLOPT_DEFAULT_LEN) < 0)
852 volset(save_options, NULL, tmp, sizeof(tmp) - 1,
853 obj->options.nlspath, path + VOLOPT_DEFAULT_LEN);
859 if (( p = strchr( path, '/' )) != NULL ) {
867 if ( u == NULL || *u == '\0' || ( pw = getpwnam( u )) == NULL ) {
870 strcpy( tmp, pw->pw_dir );
871 if ( p != NULL && *p != '\0' ) {
875 /* Tag a user's home directory with their umask. Note, this will
876 * be overwritten if the user actually specifies a umask: option
877 * for a '~' volume. */
878 save_options[VOLOPT_UMASK].i_value = obj->options.save_mask;
882 /* send path through variable substitution */
883 if (*path != '~') /* need to copy path to tmp */
886 pwent = getpwnam(obj->username);
887 volxlate(obj, path, sizeof(path) - 1, tmp, pwent, NULL);
889 /* this is sort of braindead. basically, i want to be
890 * able to specify things in any order, but i don't want to
891 * re-write everything.
893 * currently we have options:
901 * options:prodos,crlf,noadouble,ro...
906 * namemask:x,y,!z (not implemented yet)
908 memcpy(options, save_options, sizeof(options));
911 /* read in up to VOLOP_NUM possible options */
912 for (i = 0; i < VOLOPT_NUM; i++) {
913 if (parseline( sizeof( tmp ) - 1, tmp ) < 0)
916 volset(options, save_options, volname, sizeof(volname) - 1,obj->options.nlspath, tmp);
919 /* check allow/deny lists:
920 allow -> either no list (-1), or in list (1)
921 deny -> either no list (-1), or not in list (0) */
922 if (accessvol(options[VOLOPT_ALLOW].c_value, obj->username) &&
923 (accessvol(options[VOLOPT_DENY].c_value, obj->username) < 1)) {
925 /* handle read-only behaviour. semantics:
926 * 1) neither the rolist nor the rwlist exist -> rw
927 * 2) rolist exists -> ro if user is in it.
928 * 3) rwlist exists -> ro unless user is in it. */
929 if (((options[VOLOPT_FLAGS].i_value & AFPVOL_RO) == 0) &&
930 ((accessvol(options[VOLOPT_ROLIST].c_value,
931 obj->username) == 1) ||
932 !accessvol(options[VOLOPT_RWLIST].c_value,
934 options[VOLOPT_FLAGS].i_value |= AFPVOL_RO;
936 /* do variable substitution for volname */
937 volxlate(obj, tmp, sizeof(tmp) - 1, volname, pwent, path);
938 creatvol(obj, pwent, path, tmp, options, p2 != NULL);
940 volfree(options, save_options);
944 parseline( sizeof( type ) - 1, type );
945 parseline( sizeof( creator ) - 1, creator );
946 setextmap( path, type, creator, user);
953 volfree(save_options, NULL);
955 if ( fclose( fp ) != 0 ) {
956 LOG(log_error, logtype_afpd, "readvolfile: fclose: %s", strerror(errno) );
962 /* ------------------------------- */
963 static void volume_free(struct vol *vol)
969 free(vol->v_password);
975 free(vol->v_forceuid);
976 free(vol->v_forcegid);
977 #endif /* FORCE_UIDGID */
980 /* ------------------------------- */
981 static void free_volumes(void )
984 struct vol *nvol, *ovol;
986 for ( vol = Volumes; vol; vol = vol->v_next ) {
987 if (( vol->v_flags & AFPVOL_OPEN ) ) {
994 for ( vol = Volumes, ovol = NULL; vol; vol = nvol) {
997 if (vol->v_name == NULL) {
998 if (Volumes == vol) {
1005 ovol->v_next = nvol;
1015 /* ------------------------------- */
1016 static void volume_unlink(struct vol *volume)
1018 struct vol *vol, *ovol, *nvol;
1020 if (volume == Volumes) {
1021 Volumes = Volumes->v_next;
1024 for ( vol = Volumes, ovol = NULL; vol; vol = nvol) {
1027 if (vol == volume) {
1032 ovol->v_next = nvol;
1043 static int getvolspace( vol, bfree, btotal, xbfree, xbtotal, bsize )
1045 u_int32_t *bfree, *btotal, *bsize;
1046 VolSpace *xbfree, *xbtotal;
1050 #ifndef NO_QUOTA_SUPPORT
1051 VolSpace qfree, qtotal;
1054 spaceflag = AFPVOL_GVSMASK & vol->v_flags;
1055 /* report up to 2GB if afp version is < 2.2 (4GB if not) */
1056 maxsize = (vol->v_flags & AFPVOL_A2VOL) ? 0x01fffe00 :
1057 (((afp_version < 22) || (vol->v_flags & AFPVOL_LIMITSIZE))
1058 ? 0x7fffffffL : 0xffffffffL);
1061 if ( spaceflag == AFPVOL_NONE || spaceflag == AFPVOL_AFSGVS ) {
1062 if ( afs_getvolspace( vol, xbfree, xbtotal, bsize ) == AFP_OK ) {
1063 vol->v_flags = ( ~AFPVOL_GVSMASK & vol->v_flags ) | AFPVOL_AFSGVS;
1064 goto getvolspace_done;
1069 if (( rc = ustatfs_getvolspace( vol, xbfree, xbtotal,
1070 bsize)) != AFP_OK ) {
1074 #define min(a,b) ((a)<(b)?(a):(b))
1075 #ifndef NO_QUOTA_SUPPORT
1076 if ( spaceflag == AFPVOL_NONE || spaceflag == AFPVOL_UQUOTA ) {
1077 if ( uquota_getvolspace( vol, &qfree, &qtotal, *bsize ) == AFP_OK ) {
1078 vol->v_flags = ( ~AFPVOL_GVSMASK & vol->v_flags ) | AFPVOL_UQUOTA;
1079 *xbfree = min(*xbfree, qfree);
1080 *xbtotal = min( *xbtotal, qtotal);
1081 goto getvolspace_done;
1085 vol->v_flags = ( ~AFPVOL_GVSMASK & vol->v_flags ) | AFPVOL_USTATFS;
1088 *bfree = min( *xbfree, maxsize);
1089 *btotal = min( *xbtotal, maxsize);
1093 static int getvolparams( bitmap, vol, st, buf, buflen )
1101 int bit = 0, isad = 1;
1104 u_int32_t bfree, btotal, bsize;
1105 VolSpace xbfree, xbtotal; /* extended bytes */
1106 char *data, *nameoff = NULL;
1109 /* courtesy of jallison@whistle.com:
1110 * For MacOS8.x support we need to create the
1111 * .Parent file here if it doesn't exist. */
1113 memset(&ad, 0, sizeof(ad));
1114 if ( ad_open( vol->v_path, vol_noadouble(vol) |
1115 ADFLAGS_HF|ADFLAGS_DIR, O_RDWR | O_CREAT,
1119 } else if (ad_get_HF_flags( &ad ) & O_CREAT) {
1120 slash = strrchr( vol->v_path, '/' );
1124 slash = vol->v_path;
1126 ad_setentrylen( &ad, ADEID_NAME, strlen( slash ));
1127 memcpy(ad_entry( &ad, ADEID_NAME ), slash,
1128 ad_getentrylen( &ad, ADEID_NAME ));
1129 ad_setdate(&ad, AD_DATE_CREATE | AD_DATE_UNIX, st->st_mtime);
1130 ad_flush(&ad, ADFLAGS_HF);
1133 if (( bitmap & ( (1<<VOLPBIT_BFREE)|(1<<VOLPBIT_BTOTAL) |
1134 (1<<VOLPBIT_XBFREE)|(1<<VOLPBIT_XBTOTAL) |
1135 (1<<VOLPBIT_BSIZE)) ) != 0 ) {
1136 if ( getvolspace( vol, &bfree, &btotal, &xbfree, &xbtotal,
1139 ad_close( &ad, ADFLAGS_HF );
1141 return( AFPERR_PARAM );
1146 while ( bitmap != 0 ) {
1147 while (( bitmap & 1 ) == 0 ) {
1156 if (0 == (vol->v_flags & AFPVOL_NOFILEID) && vol->v_db != NULL) {
1157 ashort = VOLPBIT_ATTR_FILEID;
1159 #endif /* CNID_DB */
1160 /* check for read-only.
1161 * NOTE: we don't actually set the read-only flag unless
1162 * it's passed in that way as it's possible to mount
1163 * a read-write filesystem under a read-only one. */
1164 if ((vol->v_flags & AFPVOL_RO) ||
1165 ((utime(vol->v_path, NULL) < 0) && (errno == EROFS))) {
1166 ashort |= VOLPBIT_ATTR_RO;
1168 ashort |= VOLPBIT_ATTR_CATSEARCH;
1169 if (afp_version >= 30) {
1170 ashort |= VOLPBIT_ATTR_UTF8;
1172 ashort = htons(ashort);
1173 memcpy(data, &ashort, sizeof( ashort ));
1174 data += sizeof( ashort );
1178 ashort = htons( AFPVOLSIG_DEFAULT );
1179 memcpy(data, &ashort, sizeof( ashort ));
1180 data += sizeof( ashort );
1183 case VOLPBIT_CDATE :
1184 if (!isad || (ad_getdate(&ad, AD_DATE_CREATE, &aint) < 0))
1185 aint = AD_DATE_FROM_UNIX(st->st_mtime);
1186 memcpy(data, &aint, sizeof( aint ));
1187 data += sizeof( aint );
1190 case VOLPBIT_MDATE :
1191 if ( st->st_mtime > vol->v_time ) {
1192 vol->v_time = st->st_mtime;
1193 aint = AD_DATE_FROM_UNIX(st->st_mtime);
1195 aint = AD_DATE_FROM_UNIX(vol->v_time);
1197 memcpy(data, &aint, sizeof( aint ));
1198 data += sizeof( aint );
1201 case VOLPBIT_BDATE :
1202 if (!isad || (ad_getdate(&ad, AD_DATE_BACKUP, &aint) < 0))
1203 aint = AD_DATE_START;
1204 memcpy(data, &aint, sizeof( aint ));
1205 data += sizeof( aint );
1209 memcpy(data, &vol->v_vid, sizeof( vol->v_vid ));
1210 data += sizeof( vol->v_vid );
1213 case VOLPBIT_BFREE :
1214 bfree = htonl( bfree );
1215 memcpy(data, &bfree, sizeof( bfree ));
1216 data += sizeof( bfree );
1219 case VOLPBIT_BTOTAL :
1220 btotal = htonl( btotal );
1221 memcpy(data, &btotal, sizeof( btotal ));
1222 data += sizeof( btotal );
1225 #ifndef NO_LARGE_VOL_SUPPORT
1226 case VOLPBIT_XBFREE :
1227 xbfree = hton64( xbfree );
1228 #if defined(__GNUC__) && defined(HAVE_GCC_MEMCPY_BUG)
1229 bcopy(&xbfree, data, sizeof(xbfree));
1230 #else /* __GNUC__ && HAVE_GCC_MEMCPY_BUG */
1231 memcpy(data, &xbfree, sizeof( xbfree ));
1232 #endif /* __GNUC__ && HAVE_GCC_MEMCPY_BUG */
1233 data += sizeof( xbfree );
1236 case VOLPBIT_XBTOTAL :
1237 xbtotal = hton64( xbtotal );
1238 #if defined(__GNUC__) && defined(HAVE_GCC_MEMCPY_BUG)
1239 bcopy(&xbtotal, data, sizeof(xbtotal));
1240 #else /* __GNUC__ && HAVE_GCC_MEMCPY_BUG */
1241 memcpy(data, &xbtotal, sizeof( xbtotal ));
1242 #endif /* __GNUC__ && HAVE_GCC_MEMCPY_BUG */
1243 data += sizeof( xbfree );
1245 #endif /* ! NO_LARGE_VOL_SUPPORT */
1249 data += sizeof( u_int16_t );
1252 case VOLPBIT_BSIZE: /* block size */
1253 bsize = htonl(bsize);
1254 memcpy(data, &bsize, sizeof(bsize));
1255 data += sizeof(bsize);
1260 ad_close( &ad, ADFLAGS_HF );
1262 return( AFPERR_BITMAP );
1268 ashort = htons( data - buf );
1269 memcpy(nameoff, &ashort, sizeof( ashort ));
1270 aint = strlen( vol->v_name );
1272 memcpy(data, vol->v_name, aint );
1276 ad_close( &ad, ADFLAGS_HF );
1278 *buflen = data - buf;
1282 /* ------------------------------- */
1283 void load_volumes(AFPObj *obj)
1285 struct passwd *pwent;
1290 /* check files date */
1291 if (obj->options.defaultvol.loaded) {
1292 changed = volfile_changed(&obj->options.defaultvol);
1294 if (obj->options.systemvol.loaded) {
1295 changed |= volfile_changed(&obj->options.systemvol);
1297 if (obj->options.uservol.loaded) {
1298 changed |= volfile_changed(&obj->options.uservol);
1307 pwent = getpwnam(obj->username);
1308 if ( (obj->options.flags & OPTION_USERVOLFIRST) == 0 ) {
1309 readvolfile(obj, &obj->options.systemvol, NULL, 0, pwent);
1312 if ((*obj->username == '\0') || (obj->options.flags & OPTION_NOUSERVOL)) {
1313 readvolfile(obj, &obj->options.defaultvol, NULL, 1, pwent);
1316 * Read user's AppleVolumes or .AppleVolumes file
1317 * If neither are readable, read the default volumes file. if
1318 * that doesn't work, create a user share.
1320 obj->options.uservol.name = strdup(pwent->pw_dir);
1321 if ( readvolfile(obj, &obj->options.uservol, "AppleVolumes", 1, pwent) < 0 &&
1322 readvolfile(obj, &obj->options.uservol, ".AppleVolumes", 1, pwent) < 0 &&
1323 readvolfile(obj, &obj->options.uservol, "applevolumes", 1, pwent) < 0 &&
1324 readvolfile(obj, &obj->options.uservol, ".applevolumes", 1, pwent) < 0 &&
1325 obj->options.defaultvol.name != NULL ) {
1326 if (readvolfile(obj, &obj->options.defaultvol, NULL, 1, pwent) < 0)
1327 creatvol(obj, pwent, pwent->pw_dir, NULL, NULL, 1);
1330 if ( obj->options.flags & OPTION_USERVOLFIRST ) {
1331 readvolfile(obj, &obj->options.systemvol, NULL, 0, pwent );
1335 /* ------------------------------- */
1336 int afp_getsrvrparms(obj, ibuf, ibuflen, rbuf, rbuflen )
1339 int ibuflen, *rbuflen;
1351 for ( vcnt = 0, volume = Volumes; volume; volume = volume->v_next ) {
1352 if (!(volume->v_flags & AFPVOL_NOSTAT)) {
1353 if ( stat( volume->v_path, &st ) < 0 ) {
1354 LOG(log_info, logtype_afpd, "afp_getsrvrparms: stat %s: %s",
1355 volume->v_path, strerror(errno) );
1356 continue; /* can't access directory */
1358 if (!S_ISDIR(st.st_mode)) {
1359 continue; /* not a dir */
1362 if (volume->v_hide) {
1363 continue; /* config file changed but the volume was mounted */
1366 /* set password bit if there's a volume password */
1367 *data = (volume->v_password) ? AFPSRVR_PASSWD : 0;
1369 /* Apple 2 clients running ProDOS-8 expect one volume to have
1370 bit 0 of this byte set. They will not recognize anything
1371 on the server unless this is the case. I have not
1372 completely worked this out, but it's related to booting
1373 from the server. Support for that function is a ways
1374 off.. <shirsch@ibm.net> */
1375 *data++ |= (volume->v_flags & AFPVOL_A2VOL) ? AFPSRVR_CONFIGINFO : 0;
1376 len = strlen( volume->v_name );
1378 memcpy(data, volume->v_name, len );
1383 *rbuflen = data - rbuf;
1385 if ( gettimeofday( &tv, 0 ) < 0 ) {
1386 LOG(log_error, logtype_afpd, "afp_getsrvrparms: gettimeofday: %s", strerror(errno) );
1388 return AFPERR_PARAM;
1390 tv.tv_sec = AD_DATE_FROM_UNIX(tv.tv_sec);
1391 memcpy(data, &tv.tv_sec, sizeof( u_int32_t));
1392 data += sizeof( u_int32_t);
1397 /* -------------------------
1398 * we are the user here
1400 int afp_openvol(obj, ibuf, ibuflen, rbuf, rbuflen )
1403 int ibuflen, *rbuflen;
1411 #endif /* CNID_DB */
1414 int len, ret, buflen;
1418 memcpy(&bitmap, ibuf, sizeof( bitmap ));
1419 bitmap = ntohs( bitmap );
1420 ibuf += sizeof( bitmap );
1421 if (( bitmap & (1<<VOLPBIT_VID)) == 0 ) {
1422 ret = AFPERR_BITMAP;
1426 len = (unsigned char)*ibuf++;
1427 volname = obj->oldtmp;
1428 memcpy(volname, ibuf, len );
1429 *(volname + len) = '\0';
1431 if ((len + 1) & 1) /* pad to an even boundary */
1436 for ( volume = Volumes; volume; volume = volume->v_next ) {
1437 if ( strcasecmp( volname, volume->v_name ) == 0 ) {
1442 if ( volume == NULL ) {
1447 /* check for a volume password */
1448 if (volume->v_password && strncmp(ibuf, volume->v_password, VOLPASSLEN)) {
1449 ret = AFPERR_ACCESS;
1454 if (afp_version >= 30) {
1455 volume->max_filename = 255;
1458 volume->max_filename = MACFILELEN;
1460 if (( volume->v_flags & AFPVOL_OPEN ) == 0 ) {
1461 /* FIXME unix name != mac name */
1462 if ((dir = dirnew(volume->v_name, volume->v_name) ) == NULL) {
1463 LOG(log_error, logtype_afpd, "afp_openvol: malloc: %s", strerror(errno) );
1467 dir->d_did = DIRDID_ROOT;
1468 dir->d_color = DIRTREE_COLOR_BLACK; /* root node is black */
1469 volume->v_dir = volume->v_root = dir;
1470 volume->v_flags |= AFPVOL_OPEN;
1472 volume->v_db = NULL;
1475 if (volume->v_root_preexec) {
1476 if ((ret = afprun(1, volume->v_root_preexec, NULL)) && volume->v_root_preexec_close) {
1477 LOG(log_error, logtype_afpd, "afp_openvol: root preexec : %d", ret );
1482 if (volume->v_preexec) {
1483 if ((ret = afprun(0, volume->v_preexec, NULL)) && volume->v_preexec_close) {
1484 LOG(log_error, logtype_afpd, "afp_openvol: preexec : %d", ret );
1494 set_uidgid ( volume );
1495 #endif /* FORCE_UIDGID */
1497 if ( stat( volume->v_path, &st ) < 0 ) {
1502 if ( chdir( volume->v_path ) < 0 ) {
1506 curdir = volume->v_dir;
1510 if (volume->v_dbpath)
1511 volume->v_db = cnid_open (volume->v_dbpath, volume->v_umask);
1512 if (volume->v_db == NULL)
1513 volume->v_db = cnid_open (volume->v_path, volume->v_umask);
1514 if (volume->v_db == NULL) {
1516 * - mount the volume readonly
1518 * - read/write with other scheme
1522 #endif /* CNID_DB */
1524 buflen = *rbuflen - sizeof( bitmap );
1525 if (( ret = getvolparams( bitmap, volume, &st,
1526 rbuf + sizeof(bitmap), &buflen )) != AFP_OK ) {
1530 volume->v_utf8toucs2 = (iconv_t)(-1);
1531 volume->v_ucs2toutf8 = (iconv_t)(-1);
1532 volume->v_mactoutf8 = (iconv_t)(-1);
1533 volume->v_ucs2tomac = (iconv_t)(-1);
1535 if (vol_utf8(volume)) {
1536 if ((iconv_t)(-1) == (volume->v_utf8toucs2 = iconv_open("UCS-2LE", "UTF-8"))) {
1537 LOG(log_error, logtype_afpd, "openvol: no UTF8 to UCS-2LE");
1540 if ((iconv_t)(-1) == (volume->v_ucs2toutf8 = iconv_open("UTF-8", "UCS-2LE"))) {
1541 LOG(log_error, logtype_afpd, "openvol: no UCS-2LE to UTF-8");
1542 goto openvol_err_iconv;
1544 if ((iconv_t)(-1) == (volume->v_mactoutf8 = iconv_open("UTF-8", "MAC"))) {
1545 LOG(log_error, logtype_afpd, "openvol: no MAC to UTF-8");
1546 goto openvol_err_iconv;
1548 if ((iconv_t)(-1) == (volume->v_ucs2tomac = iconv_open("MAC", "UCS-2LE"))) {
1549 LOG(log_error, logtype_afpd, "openvol: no UCS-2LE to MAC");
1550 goto openvol_err_iconv;
1554 *rbuflen = buflen + sizeof( bitmap );
1555 bitmap = htons( bitmap );
1556 memcpy(rbuf, &bitmap, sizeof( bitmap ));
1560 * If you mount a volume twice, the second time the trash appears on
1561 * the desk-top. That's because the Mac remembers the DID for the
1562 * trash (even for volumes in different zones, on different servers).
1563 * Just so this works better, we prime the DID cache with the trash,
1564 * fixing the trash at DID 17.
1567 cname( volume, volume->v_dir, &p );
1568 #endif /* CNID_DB */
1573 if (volume->v_utf8toucs2 != (iconv_t)(-1))
1574 iconv_close(volume->v_utf8toucs2);
1575 if (volume->v_ucs2toutf8 != (iconv_t)(-1))
1576 iconv_close(volume->v_ucs2toutf8);
1577 if (volume->v_mactoutf8 != (iconv_t)(-1))
1578 iconv_close(volume->v_mactoutf8);
1579 if (volume->v_ucs2tomac != (iconv_t)(-1))
1580 iconv_close(volume->v_ucs2tomac);
1584 if (opened && volume->v_db != NULL) {
1585 cnid_close(volume->v_db);
1586 volume->v_db = NULL;
1593 /* ------------------------- */
1594 static void closevol(struct vol *vol)
1599 dirfree( vol->v_root );
1602 cnid_close(vol->v_db);
1604 #endif /* CNID_DB */
1607 if (vol->v_utf8toucs2 != (iconv_t)(-1))
1608 iconv_close(vol->v_utf8toucs2);
1609 if (vol->v_ucs2toutf8 != (iconv_t)(-1))
1610 iconv_close(vol->v_ucs2toutf8);
1611 if (vol->v_mactoutf8 != (iconv_t)(-1))
1612 iconv_close(vol->v_mactoutf8);
1613 if (vol->v_ucs2tomac != (iconv_t)(-1))
1614 iconv_close(vol->v_ucs2tomac);
1617 if (vol->v_postexec) {
1618 afprun(0, vol->v_postexec, NULL);
1620 if (vol->v_root_postexec) {
1621 afprun(1, vol->v_root_postexec, NULL);
1625 /* ------------------------- */
1626 void close_all_vol(void)
1630 for ( ovol = Volumes; ovol; ovol = ovol->v_next ) {
1631 if ( ovol->v_flags & AFPVOL_OPEN ) {
1632 ovol->v_flags &= ~AFPVOL_OPEN;
1638 /* ------------------------- */
1639 int afp_closevol(obj, ibuf, ibuflen, rbuf, rbuflen )
1642 int ibuflen, *rbuflen;
1644 struct vol *vol, *ovol;
1649 memcpy(&vid, ibuf, sizeof( vid ));
1650 if (NULL == ( vol = getvolbyvid( vid )) ) {
1651 return( AFPERR_PARAM );
1654 vol->v_flags &= ~AFPVOL_OPEN;
1655 for ( ovol = Volumes; ovol; ovol = ovol->v_next ) {
1656 if ( ovol->v_flags & AFPVOL_OPEN ) {
1660 if ( ovol != NULL ) {
1661 /* Even if chdir fails, we can't say afp_closevol fails. */
1662 if ( chdir( ovol->v_path ) == 0 ) {
1663 curdir = ovol->v_dir;
1668 if (vol->v_deleted) {
1669 showvol(vol->v_name);
1676 /* ------------------------- */
1677 struct vol *getvolbyvid(const u_int16_t vid )
1681 for ( vol = Volumes; vol; vol = vol->v_next ) {
1682 if ( vid == vol->v_vid ) {
1686 if ( vol == NULL || ( vol->v_flags & AFPVOL_OPEN ) == 0 ) {
1692 #endif /* FORCE_UIDGID */
1697 /* ------------------------ */
1698 static int ext_cmp_key(const void *key, const void *obj)
1700 const char *p = key;
1701 const struct extmap *em = obj;
1702 return strdiacasecmp(p, em->em_ext);
1704 struct extmap *getextmap(const char *path)
1709 if (NULL == ( p = strrchr( path, '.' )) ) {
1710 return( Defextmap );
1713 if (!*p || !Extmap_cnt) {
1714 return( Defextmap );
1716 em = bsearch(p, Extmap, Extmap_cnt, sizeof(struct extmap), ext_cmp_key);
1720 return( Defextmap );
1724 /* ------------------------- */
1725 struct extmap *getdefextmap(void)
1727 return( Defextmap );
1730 /* --------------------------
1731 poll if a volume is changed by other processes.
1733 int pollvoltime(obj)
1740 if (!(afp_version > 21 && obj->options.server_notif))
1743 if ( gettimeofday( &tv, 0 ) < 0 )
1746 for ( vol = Volumes; vol; vol = vol->v_next ) {
1747 if ( (vol->v_flags & AFPVOL_OPEN) && vol->v_time + 30 < tv.tv_sec) {
1748 if ( !stat( vol->v_path, &st ) && vol->v_time != st.st_mtime ) {
1749 vol->v_time = st.st_mtime;
1750 if (!obj->attention(obj->handle, AFPATTN_NOTIFY | AFPATTN_VOLCHANGED))
1759 /* ------------------------- */
1760 void setvoltime(obj, vol )
1766 /* just looking at vol->v_time is broken seriously since updates
1767 * from other users afpd processes never are seen.
1768 * This is not the most elegant solution (a shared memory between
1769 * the afpd processes would come closer)
1772 if ( gettimeofday( &tv, 0 ) < 0 ) {
1773 LOG(log_error, logtype_afpd, "setvoltime: gettimeofday: %s", strerror(errno) );
1776 if( utime( vol->v_path, NULL ) < 0 ) {
1777 /* write of time failed ... probably a read only filesys,
1778 * where no other users can interfere, so there's no issue here
1782 /* a little granularity */
1783 if (vol->v_time < tv.tv_sec) {
1784 vol->v_time = tv.tv_sec;
1785 if (afp_version > 21 && obj->options.server_notif) {
1786 obj->attention(obj->handle, AFPATTN_NOTIFY | AFPATTN_VOLCHANGED);
1791 /* ------------------------- */
1792 int afp_getvolparams(obj, ibuf, ibuflen, rbuf, rbuflen )
1795 int ibuflen, *rbuflen;
1800 u_int16_t vid, bitmap;
1803 memcpy(&vid, ibuf, sizeof( vid ));
1804 ibuf += sizeof( vid );
1805 memcpy(&bitmap, ibuf, sizeof( bitmap ));
1806 bitmap = ntohs( bitmap );
1808 if (NULL == ( vol = getvolbyvid( vid )) ) {
1810 return( AFPERR_PARAM );
1813 if ( stat( vol->v_path, &st ) < 0 ) {
1815 return( AFPERR_PARAM );
1818 buflen = *rbuflen - sizeof( bitmap );
1819 if (( ret = getvolparams( bitmap, vol, &st,
1820 rbuf + sizeof( bitmap ), &buflen )) != AFP_OK ) {
1824 *rbuflen = buflen + sizeof( bitmap );
1825 bitmap = htons( bitmap );
1826 memcpy(rbuf, &bitmap, sizeof( bitmap ));
1830 /* ------------------------- */
1831 int afp_setvolparams(obj, ibuf, ibuflen, rbuf, rbuflen )
1834 int ibuflen, *rbuflen;
1838 u_int16_t vid, bitmap;
1844 memcpy(&vid, ibuf, sizeof( vid ));
1845 ibuf += sizeof( vid );
1846 memcpy(&bitmap, ibuf, sizeof( bitmap ));
1847 bitmap = ntohs( bitmap );
1848 ibuf += sizeof(bitmap);
1850 if (( vol = getvolbyvid( vid )) == NULL ) {
1851 return( AFPERR_PARAM );
1854 if (vol->v_flags & AFPVOL_RO)
1855 return AFPERR_VLOCK;
1857 /* we can only set the backup date. */
1858 if (bitmap != (1 << VOLPBIT_BDATE))
1859 return AFPERR_BITMAP;
1861 memset(&ad, 0, sizeof(ad));
1862 if ( ad_open( vol->v_path, ADFLAGS_HF|ADFLAGS_DIR, O_RDWR,
1865 return AFPERR_VLOCK;
1867 return AFPERR_ACCESS;
1870 memcpy(&aint, ibuf, sizeof(aint));
1871 ad_setdate(&ad, AD_DATE_BACKUP, aint);
1872 ad_flush(&ad, ADFLAGS_HF);
1873 ad_close(&ad, ADFLAGS_HF);
1877 /* ------------------------- */
1878 int wincheck(const struct vol *vol, const char *path)
1882 if (!(vol->v_flags & AFPVOL_MSWINDOWS))
1885 /* empty paths are not allowed */
1886 if ((len = strlen(path)) == 0)
1889 /* leading or trailing whitespaces are not allowed, carriage returns
1890 * and probably other whitespace is okay, tabs are not allowed
1892 if ((path[0] == ' ') || (path[len-1] == ' '))
1895 /* certain characters are not allowed */
1896 if (strpbrk(path, MSWINDOWS_BADCHARS))
1899 /* everything else is okay */