2 * $Id: volume.c,v 1.51.2.2 2003-05-26 11:17:25 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, "preexec_close") == 0)
427 options[VOLOPT_PREEXEC].i_value = 1;
428 else if (strcasecmp(p, "root_preexec_close") == 0)
429 options[VOLOPT_ROOTPREEXEC].i_value = 1;
430 p = strtok(NULL, ",");
435 } else if (optionok(tmp, "dbpath:", val)) {
436 setoption(options, save, VOLOPT_DBPATH, val);
439 } else if (optionok(tmp, "umask:", val)) {
440 options[VOLOPT_UMASK].i_value = (int)strtol(val, (char **)NULL, 8);
441 } else if (optionok(tmp, "mapchars:",val)) {
442 setoption(options, save, VOLOPT_MAPCHARS, val);
444 } else if (optionok(tmp, "password:", val)) {
445 setoption(options, save, VOLOPT_PASSWORD, val);
449 /* this code allows forced uid/gid per volume settings */
450 } else if (optionok(tmp, "forceuid:", val)) {
451 setoption(options, save, VOLOPT_FORCEUID, val);
452 } else if (optionok(tmp, "forcegid:", val)) {
453 setoption(options, save, VOLOPT_FORCEGID, val);
455 #endif /* FORCE_UIDGID */
456 } else if (optionok(tmp, "root_preexec:", val)) {
457 setoption(options, save, VOLOPT_ROOTPREEXEC, val);
459 } else if (optionok(tmp, "preexec:", val)) {
460 setoption(options, save, VOLOPT_PREEXEC, val);
462 } else if (optionok(tmp, "root_postexec:", val)) {
463 setoption(options, save, VOLOPT_ROOTPOSTEXEC, val);
465 } else if (optionok(tmp, "postexec:", val)) {
466 setoption(options, save, VOLOPT_POSTEXEC, val);
469 /* ignore unknown options */
470 LOG(log_debug, logtype_afpd, "ignoring unknown volume option: %s", tmp);
475 /* ----------------- */
476 static void showvol(const char *name)
479 for ( volume = Volumes; volume; volume = volume->v_next ) {
480 if ( !strcasecmp( volume->v_name, name ) && volume->v_hide) {
487 /* ------------------------------- */
488 static int creatvol(AFPObj *obj, struct passwd *pwd,
489 char *path, char *name,
490 struct vol_option *options,
491 const int user /* user defined volume */
498 if ( name == NULL || *name == '\0' ) {
499 if ((name = strrchr( path, '/' )) == NULL) {
500 return -1; /* Obviously not a fully qualified path */
503 /* if you wish to share /, you need to specify a name. */
508 for ( volume = Volumes; volume; volume = volume->v_next ) {
509 if ( strcasecmp( volume->v_name, name ) == 0 ) {
510 if (volume->v_deleted) {
514 return -1; /* Won't be able to access it, anyway... */
519 vlen = strlen( name );
520 if ( vlen > AFPVOL_NAMELEN ) {
521 vlen = AFPVOL_NAMELEN;
522 name[AFPVOL_NAMELEN] = '\0';
525 if (!( volume = (struct vol *)calloc(1, sizeof( struct vol ))) ) {
526 LOG(log_error, logtype_afpd, "creatvol: malloc: %s", strerror(errno) );
529 if (! ( volume->v_name = (char *)malloc( vlen + 1 ) ) ) {
530 LOG(log_error, logtype_afpd, "creatvol: malloc: %s", strerror(errno) );
534 if (!( volume->v_path = (char *)malloc( strlen( path ) + 1 )) ) {
535 LOG(log_error, logtype_afpd, "creatvol: malloc: %s", strerror(errno) );
536 free(volume->v_name);
540 volume->v_hide = hide;
541 strcpy( volume->v_name, name);
542 strcpy( volume->v_path, path );
546 #endif /* __svr4__ */
547 volume->v_vid = lastvid++;
548 volume->v_lastdid = 17;
552 /* should we casefold? */
553 volume->v_casefold = options[VOLOPT_CASEFOLD].i_value;
555 /* shift in some flags */
556 volume->v_flags = options[VOLOPT_FLAGS].i_value;
558 /* read in the code pages */
559 if (options[VOLOPT_CODEPAGE].c_value)
560 codepage_read(volume, options[VOLOPT_CODEPAGE].c_value);
562 if (options[VOLOPT_PASSWORD].c_value)
563 volume->v_password = strdup(options[VOLOPT_PASSWORD].c_value);
565 if (options[VOLOPT_VETO].c_value)
566 volume->v_veto = strdup(options[VOLOPT_VETO].c_value);
569 if (options[VOLOPT_DBPATH].c_value)
570 volume->v_dbpath = volxlate(obj, NULL, MAXPATHLEN, options[VOLOPT_DBPATH].c_value, pwd, path);
573 if (options[VOLOPT_UMASK].i_value)
574 volume->v_umask = (mode_t)options[VOLOPT_UMASK].i_value;
577 if (options[VOLOPT_FORCEUID].c_value) {
578 volume->v_forceuid = strdup(options[VOLOPT_FORCEUID].c_value);
580 volume->v_forceuid = NULL; /* set as null so as to return 0 later on */
583 if (options[VOLOPT_FORCEGID].c_value) {
584 volume->v_forcegid = strdup(options[VOLOPT_FORCEGID].c_value);
586 volume->v_forcegid = NULL; /* set as null so as to return 0 later on */
590 if (options[VOLOPT_PREEXEC].c_value)
591 volume->v_preexec = volxlate(obj, NULL, MAXPATHLEN, options[VOLOPT_PREEXEC].c_value, pwd, path);
592 volume->v_preexec_close = options[VOLOPT_PREEXEC].i_value;
594 if (options[VOLOPT_POSTEXEC].c_value)
595 volume->v_postexec = volxlate(obj, NULL, MAXPATHLEN, options[VOLOPT_POSTEXEC].c_value, pwd, path);
597 if (options[VOLOPT_ROOTPREEXEC].c_value)
598 volume->v_root_preexec = volxlate(obj, NULL, MAXPATHLEN, options[VOLOPT_ROOTPREEXEC].c_value, pwd, path);
599 volume->v_root_preexec_close = options[VOLOPT_ROOTPREEXEC].i_value;
601 if (options[VOLOPT_ROOTPOSTEXEC].c_value)
602 volume->v_root_postexec = volxlate(obj, NULL, MAXPATHLEN, options[VOLOPT_ROOTPOSTEXEC].c_value, pwd, path);
606 volume->v_next = Volumes;
611 /* ---------------- */
612 static char *myfgets( buf, size, fp )
621 while ((EOF != ( c = getc( fp )) ) && ( size > 0 )) {
622 if ( c == '\n' || c == '\r' ) {
640 /* check access list. this function wants something of the following
642 * @group,name,name2,@group2,name3
644 * a NULL argument allows everybody to have access.
645 * we return three things:
647 * 0: list exists, but name isn't in it
650 static int accessvol(args, name)
654 char buf[MAXPATHLEN + 1], *p;
660 strncpy(buf, args, sizeof(buf));
661 if ((p = strtok(buf, ",")) == NULL) /* nothing, return okay */
665 if (*p == '@') { /* it's a group */
666 if ((gr = getgrnam(p + 1)) && gmem(gr->gr_gid))
668 } else if (strcmp(p, name) == 0) /* it's a user name */
670 p = strtok(NULL, ",");
676 static void setextmap( ext, type, creator, user)
677 char *ext, *type, *creator;
683 if (Extmap == NULL) {
684 if (( Extmap = calloc(1, sizeof( struct extmap ))) == NULL ) {
685 LOG(log_error, logtype_afpd, "setextmap: calloc: %s", strerror(errno) );
690 for ( em = Extmap, cnt = 0; em->em_ext; em++, cnt++) {
691 if ( (strdiacasecmp( em->em_ext, ext )) == 0 ) {
696 if ( em->em_ext == NULL ) {
697 if (!(Extmap = realloc( Extmap, sizeof( struct extmap ) * (cnt +2))) ) {
698 LOG(log_error, logtype_afpd, "setextmap: realloc: %s", strerror(errno) );
701 (Extmap +cnt +1)->em_ext = NULL;
703 } else if ( !user ) {
709 if (!(em->em_ext = strdup( ext))) {
710 LOG(log_error, logtype_afpd, "setextmap: strdup: %s", strerror(errno) );
714 if ( *type == '\0' ) {
715 memcpy(em->em_type, "????", sizeof( em->em_type ));
717 memcpy(em->em_type, type, sizeof( em->em_type ));
719 if ( *creator == '\0' ) {
720 memcpy(em->em_creator, "UNIX", sizeof( em->em_creator ));
722 memcpy(em->em_creator, creator, sizeof( em->em_creator ));
726 /* -------------------------- */
727 static int extmap_cmp(const void *map1, const void *map2)
729 const struct extmap *em1 = map1;
730 const struct extmap *em2 = map2;
731 return strdiacasecmp(em1->em_ext, em2->em_ext);
734 static void sortextmap( void)
739 if ((em = Extmap) == NULL) {
747 qsort(Extmap, Extmap_cnt, sizeof(struct extmap), extmap_cmp);
752 /* ----------------------
754 static void free_extmap( void)
764 /* ----------------------
766 static int volfile_changed(struct afp_volume_name *p)
776 if (!stat( name, &st) && st.st_mtime > p->mtime) {
777 p->mtime = st.st_mtime;
783 /* ----------------------
784 * Read a volume configuration file and add the volumes contained within to
785 * the global volume list. If p2 is non-NULL, the file that is opened is
788 * Lines that begin with # and blank lines are ignored.
789 * Volume lines are of the form:
790 * <unix path> [<volume name>] [allow:<user>,<@group>,...] \
791 * [codepage:<file>] [casefold:<num>]
792 * <extension> TYPE [CREATOR]
794 static int readvolfile(obj, p1, p2, user, pwent)
796 struct afp_volume_name *p1;
799 struct passwd *pwent;
802 char path[ MAXPATHLEN + 1], tmp[ MAXPATHLEN + 1],
803 volname[ AFPVOL_NAMELEN + 1 ], buf[ BUFSIZ ],
804 type[ 5 ], creator[ 5 ];
807 struct vol_option options[VOLOPT_NUM], save_options[VOLOPT_NUM];
815 strcpy( path, p1->name );
822 p1->full_name = strdup(path);
825 if (NULL == ( fp = fopen( path, "r" )) ) {
829 if (fd != -1 && !fstat( fd, &st) ) {
830 p1->mtime = st.st_mtime;
833 memset(save_options, 0, sizeof(save_options));
834 while ( myfgets( buf, sizeof( buf ), fp ) != NULL ) {
835 initline( strlen( buf ), buf );
836 parseline( sizeof( path ) - 1, path );
843 /* change the default options for this file */
844 if (strncmp(path, VOLOPT_DEFAULT, VOLOPT_DEFAULT_LEN) == 0) {
846 for (i = 0; i < VOLOPT_NUM; i++) {
847 if (parseline( sizeof( path ) - VOLOPT_DEFAULT_LEN - 1,
848 path + VOLOPT_DEFAULT_LEN) < 0)
850 volset(save_options, NULL, tmp, sizeof(tmp) - 1,
851 obj->options.nlspath, path + VOLOPT_DEFAULT_LEN);
857 if (( p = strchr( path, '/' )) != NULL ) {
865 if ( u == NULL || *u == '\0' || ( pw = getpwnam( u )) == NULL ) {
868 strcpy( tmp, pw->pw_dir );
869 if ( p != NULL && *p != '\0' ) {
873 /* Tag a user's home directory with their umask. Note, this will
874 * be overwritten if the user actually specifies a umask: option
875 * for a '~' volume. */
876 save_options[VOLOPT_UMASK].i_value = obj->options.save_mask;
880 /* send path through variable substitution */
881 if (*path != '~') /* need to copy path to tmp */
884 pwent = getpwnam(obj->username);
885 volxlate(obj, path, sizeof(path) - 1, tmp, pwent, NULL);
887 /* this is sort of braindead. basically, i want to be
888 * able to specify things in any order, but i don't want to
889 * re-write everything.
891 * currently we have options:
899 * options:prodos,crlf,noadouble,ro...
904 * namemask:x,y,!z (not implemented yet)
906 memcpy(options, save_options, sizeof(options));
909 /* read in up to VOLOP_NUM possible options */
910 for (i = 0; i < VOLOPT_NUM; i++) {
911 if (parseline( sizeof( tmp ) - 1, tmp ) < 0)
914 volset(options, save_options, volname, sizeof(volname) - 1,obj->options.nlspath, tmp);
917 /* check allow/deny lists:
918 allow -> either no list (-1), or in list (1)
919 deny -> either no list (-1), or not in list (0) */
920 if (accessvol(options[VOLOPT_ALLOW].c_value, obj->username) &&
921 (accessvol(options[VOLOPT_DENY].c_value, obj->username) < 1)) {
923 /* handle read-only behaviour. semantics:
924 * 1) neither the rolist nor the rwlist exist -> rw
925 * 2) rolist exists -> ro if user is in it.
926 * 3) rwlist exists -> ro unless user is in it. */
927 if (((options[VOLOPT_FLAGS].i_value & AFPVOL_RO) == 0) &&
928 ((accessvol(options[VOLOPT_ROLIST].c_value,
929 obj->username) == 1) ||
930 !accessvol(options[VOLOPT_RWLIST].c_value,
932 options[VOLOPT_FLAGS].i_value |= AFPVOL_RO;
934 /* do variable substitution for volname */
935 volxlate(obj, tmp, sizeof(tmp) - 1, volname, pwent, path);
936 creatvol(obj, pwent, path, tmp, options, p2 != NULL);
938 volfree(options, save_options);
942 parseline( sizeof( type ) - 1, type );
943 parseline( sizeof( creator ) - 1, creator );
944 setextmap( path, type, creator, user);
951 volfree(save_options, NULL);
953 if ( fclose( fp ) != 0 ) {
954 LOG(log_error, logtype_afpd, "readvolfile: fclose: %s", strerror(errno) );
960 /* ------------------------------- */
961 static void volume_free(struct vol *vol)
967 free(vol->v_password);
973 free(vol->v_forceuid);
974 free(vol->v_forcegid);
975 #endif /* FORCE_UIDGID */
978 /* ------------------------------- */
979 static void free_volumes(void )
982 struct vol *nvol, *ovol;
984 for ( vol = Volumes; vol; vol = vol->v_next ) {
985 if (( vol->v_flags & AFPVOL_OPEN ) ) {
992 for ( vol = Volumes, ovol = NULL; vol; vol = nvol) {
995 if (vol->v_name == NULL) {
996 if (Volumes == vol) {
1003 ovol->v_next = nvol;
1013 /* ------------------------------- */
1014 static void volume_unlink(struct vol *volume)
1016 struct vol *vol, *ovol, *nvol;
1018 if (volume == Volumes) {
1019 Volumes = Volumes->v_next;
1022 for ( vol = Volumes, ovol = NULL; vol; vol = nvol) {
1025 if (vol == volume) {
1030 ovol->v_next = nvol;
1041 static int getvolspace( vol, bfree, btotal, xbfree, xbtotal, bsize )
1043 u_int32_t *bfree, *btotal, *bsize;
1044 VolSpace *xbfree, *xbtotal;
1048 #ifndef NO_QUOTA_SUPPORT
1049 VolSpace qfree, qtotal;
1052 spaceflag = AFPVOL_GVSMASK & vol->v_flags;
1053 /* report up to 2GB if afp version is < 2.2 (4GB if not) */
1054 maxsize = (vol->v_flags & AFPVOL_A2VOL) ? 0x01fffe00 :
1055 (((afp_version < 22) || (vol->v_flags & AFPVOL_LIMITSIZE))
1056 ? 0x7fffffffL : 0xffffffffL);
1059 if ( spaceflag == AFPVOL_NONE || spaceflag == AFPVOL_AFSGVS ) {
1060 if ( afs_getvolspace( vol, xbfree, xbtotal, bsize ) == AFP_OK ) {
1061 vol->v_flags = ( ~AFPVOL_GVSMASK & vol->v_flags ) | AFPVOL_AFSGVS;
1062 goto getvolspace_done;
1067 if (( rc = ustatfs_getvolspace( vol, xbfree, xbtotal,
1068 bsize)) != AFP_OK ) {
1072 #define min(a,b) ((a)<(b)?(a):(b))
1073 #ifndef NO_QUOTA_SUPPORT
1074 if ( spaceflag == AFPVOL_NONE || spaceflag == AFPVOL_UQUOTA ) {
1075 if ( uquota_getvolspace( vol, &qfree, &qtotal, *bsize ) == AFP_OK ) {
1076 vol->v_flags = ( ~AFPVOL_GVSMASK & vol->v_flags ) | AFPVOL_UQUOTA;
1077 *xbfree = min(*xbfree, qfree);
1078 *xbtotal = min( *xbtotal, qtotal);
1079 goto getvolspace_done;
1083 vol->v_flags = ( ~AFPVOL_GVSMASK & vol->v_flags ) | AFPVOL_USTATFS;
1086 *bfree = min( *xbfree, maxsize);
1087 *btotal = min( *xbtotal, maxsize);
1091 static int getvolparams( bitmap, vol, st, buf, buflen )
1099 int bit = 0, isad = 1;
1102 u_int32_t bfree, btotal, bsize;
1103 VolSpace xbfree, xbtotal; /* extended bytes */
1104 char *data, *nameoff = NULL;
1107 /* courtesy of jallison@whistle.com:
1108 * For MacOS8.x support we need to create the
1109 * .Parent file here if it doesn't exist. */
1111 memset(&ad, 0, sizeof(ad));
1112 if ( ad_open( vol->v_path, vol_noadouble(vol) |
1113 ADFLAGS_HF|ADFLAGS_DIR, O_RDWR | O_CREAT,
1117 } else if (ad_get_HF_flags( &ad ) & O_CREAT) {
1118 slash = strrchr( vol->v_path, '/' );
1122 slash = vol->v_path;
1124 ad_setentrylen( &ad, ADEID_NAME, strlen( slash ));
1125 memcpy(ad_entry( &ad, ADEID_NAME ), slash,
1126 ad_getentrylen( &ad, ADEID_NAME ));
1127 ad_setdate(&ad, AD_DATE_CREATE | AD_DATE_UNIX, st->st_mtime);
1128 ad_flush(&ad, ADFLAGS_HF);
1131 if (( bitmap & ( (1<<VOLPBIT_BFREE)|(1<<VOLPBIT_BTOTAL) |
1132 (1<<VOLPBIT_XBFREE)|(1<<VOLPBIT_XBTOTAL) |
1133 (1<<VOLPBIT_BSIZE)) ) != 0 ) {
1134 if ( getvolspace( vol, &bfree, &btotal, &xbfree, &xbtotal,
1137 ad_close( &ad, ADFLAGS_HF );
1139 return( AFPERR_PARAM );
1144 while ( bitmap != 0 ) {
1145 while (( bitmap & 1 ) == 0 ) {
1154 if (0 == (vol->v_flags & AFPVOL_NOFILEID) && vol->v_db != NULL) {
1155 ashort = VOLPBIT_ATTR_FILEID;
1157 #endif /* CNID_DB */
1158 /* check for read-only.
1159 * NOTE: we don't actually set the read-only flag unless
1160 * it's passed in that way as it's possible to mount
1161 * a read-write filesystem under a read-only one. */
1162 if ((vol->v_flags & AFPVOL_RO) ||
1163 ((utime(vol->v_path, NULL) < 0) && (errno == EROFS))) {
1164 ashort |= VOLPBIT_ATTR_RO;
1166 ashort |= VOLPBIT_ATTR_CATSEARCH;
1167 if (afp_version >= 30) {
1168 ashort |= VOLPBIT_ATTR_UTF8;
1170 ashort = htons(ashort);
1171 memcpy(data, &ashort, sizeof( ashort ));
1172 data += sizeof( ashort );
1176 ashort = htons( AFPVOLSIG_DEFAULT );
1177 memcpy(data, &ashort, sizeof( ashort ));
1178 data += sizeof( ashort );
1181 case VOLPBIT_CDATE :
1182 if (!isad || (ad_getdate(&ad, AD_DATE_CREATE, &aint) < 0))
1183 aint = AD_DATE_FROM_UNIX(st->st_mtime);
1184 memcpy(data, &aint, sizeof( aint ));
1185 data += sizeof( aint );
1188 case VOLPBIT_MDATE :
1189 if ( st->st_mtime > vol->v_time ) {
1190 vol->v_time = st->st_mtime;
1191 aint = AD_DATE_FROM_UNIX(st->st_mtime);
1193 aint = AD_DATE_FROM_UNIX(vol->v_time);
1195 memcpy(data, &aint, sizeof( aint ));
1196 data += sizeof( aint );
1199 case VOLPBIT_BDATE :
1200 if (!isad || (ad_getdate(&ad, AD_DATE_BACKUP, &aint) < 0))
1201 aint = AD_DATE_START;
1202 memcpy(data, &aint, sizeof( aint ));
1203 data += sizeof( aint );
1207 memcpy(data, &vol->v_vid, sizeof( vol->v_vid ));
1208 data += sizeof( vol->v_vid );
1211 case VOLPBIT_BFREE :
1212 bfree = htonl( bfree );
1213 memcpy(data, &bfree, sizeof( bfree ));
1214 data += sizeof( bfree );
1217 case VOLPBIT_BTOTAL :
1218 btotal = htonl( btotal );
1219 memcpy(data, &btotal, sizeof( btotal ));
1220 data += sizeof( btotal );
1223 #ifndef NO_LARGE_VOL_SUPPORT
1224 case VOLPBIT_XBFREE :
1225 xbfree = hton64( xbfree );
1226 #if defined(__GNUC__) && defined(HAVE_GCC_MEMCPY_BUG)
1227 bcopy(&xbfree, data, sizeof(xbfree));
1228 #else /* __GNUC__ && HAVE_GCC_MEMCPY_BUG */
1229 memcpy(data, &xbfree, sizeof( xbfree ));
1230 #endif /* __GNUC__ && HAVE_GCC_MEMCPY_BUG */
1231 data += sizeof( xbfree );
1234 case VOLPBIT_XBTOTAL :
1235 xbtotal = hton64( xbtotal );
1236 #if defined(__GNUC__) && defined(HAVE_GCC_MEMCPY_BUG)
1237 bcopy(&xbtotal, data, sizeof(xbtotal));
1238 #else /* __GNUC__ && HAVE_GCC_MEMCPY_BUG */
1239 memcpy(data, &xbtotal, sizeof( xbtotal ));
1240 #endif /* __GNUC__ && HAVE_GCC_MEMCPY_BUG */
1241 data += sizeof( xbfree );
1243 #endif /* ! NO_LARGE_VOL_SUPPORT */
1247 data += sizeof( u_int16_t );
1250 case VOLPBIT_BSIZE: /* block size */
1251 bsize = htonl(bsize);
1252 memcpy(data, &bsize, sizeof(bsize));
1253 data += sizeof(bsize);
1258 ad_close( &ad, ADFLAGS_HF );
1260 return( AFPERR_BITMAP );
1266 ashort = htons( data - buf );
1267 memcpy(nameoff, &ashort, sizeof( ashort ));
1268 aint = strlen( vol->v_name );
1270 memcpy(data, vol->v_name, aint );
1274 ad_close( &ad, ADFLAGS_HF );
1276 *buflen = data - buf;
1280 /* ------------------------------- */
1281 void load_volumes(AFPObj *obj)
1283 struct passwd *pwent;
1288 /* check files date */
1289 if (obj->options.defaultvol.loaded) {
1290 changed = volfile_changed(&obj->options.defaultvol);
1292 if (obj->options.systemvol.loaded) {
1293 changed |= volfile_changed(&obj->options.systemvol);
1295 if (obj->options.uservol.loaded) {
1296 changed |= volfile_changed(&obj->options.uservol);
1305 pwent = getpwnam(obj->username);
1306 if ( (obj->options.flags & OPTION_USERVOLFIRST) == 0 ) {
1307 readvolfile(obj, &obj->options.systemvol, NULL, 0, pwent);
1310 if ((*obj->username == '\0') || (obj->options.flags & OPTION_NOUSERVOL)) {
1311 readvolfile(obj, &obj->options.defaultvol, NULL, 1, pwent);
1314 * Read user's AppleVolumes or .AppleVolumes file
1315 * If neither are readable, read the default volumes file. if
1316 * that doesn't work, create a user share.
1318 obj->options.uservol.name = strdup(pwent->pw_dir);
1319 if ( readvolfile(obj, &obj->options.uservol, "AppleVolumes", 1, pwent) < 0 &&
1320 readvolfile(obj, &obj->options.uservol, ".AppleVolumes", 1, pwent) < 0 &&
1321 readvolfile(obj, &obj->options.uservol, "applevolumes", 1, pwent) < 0 &&
1322 readvolfile(obj, &obj->options.uservol, ".applevolumes", 1, pwent) < 0 &&
1323 obj->options.defaultvol.name != NULL ) {
1324 if (readvolfile(obj, &obj->options.defaultvol, NULL, 1, pwent) < 0)
1325 creatvol(pwent->pw_dir, NULL, NULL);
1328 if ( obj->options.flags & OPTION_USERVOLFIRST ) {
1329 readvolfile(obj, &obj->options.systemvol, NULL, 0, pwent );
1333 /* ------------------------------- */
1334 int afp_getsrvrparms(obj, ibuf, ibuflen, rbuf, rbuflen )
1337 int ibuflen, *rbuflen;
1349 for ( vcnt = 0, volume = Volumes; volume; volume = volume->v_next ) {
1350 if ( stat( volume->v_path, &st ) < 0 ) {
1351 LOG(log_info, logtype_afpd, "afp_getsrvrparms: stat %s: %s",
1352 volume->v_path, strerror(errno) );
1353 continue; /* can't access directory */
1355 if (!S_ISDIR(st.st_mode)) {
1356 continue; /* not a dir */
1358 if (volume->v_hide) {
1359 continue; /* config file changed but the volume was mounted */
1362 /* set password bit if there's a volume password */
1363 *data = (volume->v_password) ? AFPSRVR_PASSWD : 0;
1365 /* Apple 2 clients running ProDOS-8 expect one volume to have
1366 bit 0 of this byte set. They will not recognize anything
1367 on the server unless this is the case. I have not
1368 completely worked this out, but it's related to booting
1369 from the server. Support for that function is a ways
1370 off.. <shirsch@ibm.net> */
1371 *data++ |= (volume->v_flags & AFPVOL_A2VOL) ? AFPSRVR_CONFIGINFO : 0;
1372 len = strlen( volume->v_name );
1374 memcpy(data, volume->v_name, len );
1379 *rbuflen = data - rbuf;
1381 if ( gettimeofday( &tv, 0 ) < 0 ) {
1382 LOG(log_error, logtype_afpd, "afp_getsrvrparms: gettimeofday: %s", strerror(errno) );
1384 return AFPERR_PARAM;
1386 tv.tv_sec = AD_DATE_FROM_UNIX(tv.tv_sec);
1387 memcpy(data, &tv.tv_sec, sizeof( u_int32_t));
1388 data += sizeof( u_int32_t);
1393 /* -------------------------
1394 * we are the user here
1396 int afp_openvol(obj, ibuf, ibuflen, rbuf, rbuflen )
1399 int ibuflen, *rbuflen;
1407 #endif /* CNID_DB */
1410 int len, ret, buflen;
1414 memcpy(&bitmap, ibuf, sizeof( bitmap ));
1415 bitmap = ntohs( bitmap );
1416 ibuf += sizeof( bitmap );
1417 if (( bitmap & (1<<VOLPBIT_VID)) == 0 ) {
1418 ret = AFPERR_BITMAP;
1422 len = (unsigned char)*ibuf++;
1423 volname = obj->oldtmp;
1424 memcpy(volname, ibuf, len );
1425 *(volname + len) = '\0';
1427 if ((len + 1) & 1) /* pad to an even boundary */
1432 for ( volume = Volumes; volume; volume = volume->v_next ) {
1433 if ( strcasecmp( volname, volume->v_name ) == 0 ) {
1438 if ( volume == NULL ) {
1443 /* check for a volume password */
1444 if (volume->v_password && strncmp(ibuf, volume->v_password, VOLPASSLEN)) {
1445 ret = AFPERR_ACCESS;
1450 if (afp_version >= 30) {
1451 volume->max_filename = 255;
1454 volume->max_filename = MACFILELEN;
1456 if (( volume->v_flags & AFPVOL_OPEN ) == 0 ) {
1457 /* FIXME unix name != mac name */
1458 if ((dir = dirnew(volume->v_name, volume->v_name) ) == NULL) {
1459 LOG(log_error, logtype_afpd, "afp_openvol: malloc: %s", strerror(errno) );
1463 dir->d_did = DIRDID_ROOT;
1464 dir->d_color = DIRTREE_COLOR_BLACK; /* root node is black */
1465 volume->v_dir = volume->v_root = dir;
1466 volume->v_flags |= AFPVOL_OPEN;
1468 volume->v_db = NULL;
1471 if (volume->v_root_preexec) {
1472 if ((ret = afprun(1, volume->v_root_preexec, NULL)) && volume->v_root_preexec_close) {
1473 LOG(log_error, logtype_afpd, "afp_openvol: root preexec : %d", ret );
1478 if (volume->v_preexec) {
1479 if ((ret = afprun(0, volume->v_preexec, NULL)) && volume->v_preexec_close) {
1480 LOG(log_error, logtype_afpd, "afp_openvol: preexec : %d", ret );
1490 set_uidgid ( volume );
1491 #endif /* FORCE_UIDGID */
1493 if ( stat( volume->v_path, &st ) < 0 ) {
1498 if ( chdir( volume->v_path ) < 0 ) {
1502 curdir = volume->v_dir;
1506 if (volume->v_dbpath)
1507 volume->v_db = cnid_open (volume->v_dbpath, volume->v_umask);
1508 if (volume->v_db == NULL)
1509 volume->v_db = cnid_open (volume->v_path, volume->v_umask);
1510 if (volume->v_db == NULL) {
1512 * - mount the volume readonly
1514 * - read/write with other scheme
1518 #endif /* CNID_DB */
1520 buflen = *rbuflen - sizeof( bitmap );
1521 if (( ret = getvolparams( bitmap, volume, &st,
1522 rbuf + sizeof(bitmap), &buflen )) != AFP_OK ) {
1526 volume->v_utf8toucs2 = (iconv_t)(-1);
1527 volume->v_ucs2toutf8 = (iconv_t)(-1);
1528 volume->v_mactoutf8 = (iconv_t)(-1);
1529 volume->v_ucs2tomac = (iconv_t)(-1);
1531 if (vol_utf8(volume)) {
1532 if ((iconv_t)(-1) == (volume->v_utf8toucs2 = iconv_open("UCS-2LE", "UTF-8"))) {
1533 LOG(log_error, logtype_afpd, "openvol: no UTF8 to UCS-2LE");
1536 if ((iconv_t)(-1) == (volume->v_ucs2toutf8 = iconv_open("UTF-8", "UCS-2LE"))) {
1537 LOG(log_error, logtype_afpd, "openvol: no UCS-2LE to UTF-8");
1538 goto openvol_err_iconv;
1540 if ((iconv_t)(-1) == (volume->v_mactoutf8 = iconv_open("UTF-8", "MAC"))) {
1541 LOG(log_error, logtype_afpd, "openvol: no MAC to UTF-8");
1542 goto openvol_err_iconv;
1544 if ((iconv_t)(-1) == (volume->v_ucs2tomac = iconv_open("MAC", "UCS-2LE"))) {
1545 LOG(log_error, logtype_afpd, "openvol: no UCS-2LE to MAC");
1546 goto openvol_err_iconv;
1550 *rbuflen = buflen + sizeof( bitmap );
1551 bitmap = htons( bitmap );
1552 memcpy(rbuf, &bitmap, sizeof( bitmap ));
1556 * If you mount a volume twice, the second time the trash appears on
1557 * the desk-top. That's because the Mac remembers the DID for the
1558 * trash (even for volumes in different zones, on different servers).
1559 * Just so this works better, we prime the DID cache with the trash,
1560 * fixing the trash at DID 17.
1563 cname( volume, volume->v_dir, &p );
1564 #endif /* CNID_DB */
1569 if (volume->v_utf8toucs2 != (iconv_t)(-1))
1570 iconv_close(volume->v_utf8toucs2);
1571 if (volume->v_ucs2toutf8 != (iconv_t)(-1))
1572 iconv_close(volume->v_ucs2toutf8);
1573 if (volume->v_mactoutf8 != (iconv_t)(-1))
1574 iconv_close(volume->v_mactoutf8);
1575 if (volume->v_ucs2tomac != (iconv_t)(-1))
1576 iconv_close(volume->v_ucs2tomac);
1580 if (opened && volume->v_db != NULL) {
1581 cnid_close(volume->v_db);
1582 volume->v_db = NULL;
1589 /* ------------------------- */
1590 static void closevol(struct vol *vol)
1595 dirfree( vol->v_root );
1598 cnid_close(vol->v_db);
1600 #endif /* CNID_DB */
1601 if (vol->v_postexec) {
1602 afprun(0, vol->v_postexec, NULL);
1604 if (vol->v_root_postexec) {
1605 afprun(1, vol->v_root_postexec, NULL);
1609 /* ------------------------- */
1610 void close_all_vol(void)
1614 for ( ovol = volumes; ovol; ovol = ovol->v_next ) {
1615 if ( ovol->v_flags & AFPVOL_OPEN ) {
1616 ovol->v_flags &= ~AFPVOL_OPEN;
1622 /* ------------------------- */
1623 int afp_closevol(obj, ibuf, ibuflen, rbuf, rbuflen )
1626 int ibuflen, *rbuflen;
1628 struct vol *vol, *ovol;
1633 memcpy(&vid, ibuf, sizeof( vid ));
1634 if (NULL == ( vol = getvolbyvid( vid )) ) {
1635 return( AFPERR_PARAM );
1638 vol->v_flags &= ~AFPVOL_OPEN;
1639 for ( ovol = Volumes; ovol; ovol = ovol->v_next ) {
1640 if ( ovol->v_flags & AFPVOL_OPEN ) {
1644 if ( ovol != NULL ) {
1645 /* Even if chdir fails, we can't say afp_closevol fails. */
1646 if ( chdir( ovol->v_path ) == 0 ) {
1647 curdir = ovol->v_dir;
1650 dirfree( vol->v_root );
1653 cnid_close(vol->v_db);
1655 #endif /* CNID_DB */
1658 if (vol->v_utf8toucs2 != (iconv_t)(-1))
1659 iconv_close(vol->v_utf8toucs2);
1660 if (vol->v_ucs2toutf8 != (iconv_t)(-1))
1661 iconv_close(vol->v_ucs2toutf8);
1662 if (vol->v_mactoutf8 != (iconv_t)(-1))
1663 iconv_close(vol->v_mactoutf8);
1664 if (vol->v_ucs2tomac != (iconv_t)(-1))
1665 iconv_close(vol->v_ucs2tomac);
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 */