2 Copyright (c) 2012 Frank Lahm <franklahm@gmail.com>
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
17 #endif /* HAVE_CONFIG_H */
27 #include <sys/param.h>
28 #include <sys/socket.h>
29 #include <netinet/in.h>
30 #include <arpa/inet.h>
35 #include <atalk/afp.h>
36 #include <atalk/util.h>
37 #include <atalk/logger.h>
39 #include <atalk/globals.h>
40 #include <atalk/errchk.h>
41 #include <atalk/iniparser.h>
42 #include <atalk/unix.h>
43 #include <atalk/cnid.h>
44 #include <atalk/dsi.h>
45 #include <atalk/uuid.h>
46 #include <atalk/netatalk_conf.h>
50 #define IS_VAR(a, b) (strncmp((a), (b), 2) == 0)
52 /**************************************************************
54 **************************************************************/
56 static int have_uservol = 0; /* whether there's generic user home share in config ("~" or "~/path", but not "~user") */
57 static struct vol *Volumes = NULL;
58 static uint16_t lastvid = 0;
61 * Get a volumes UUID from the config file.
62 * If there is none, it is generated and stored there.
64 * Returns pointer to allocated storage on success, NULL on error.
66 static char *get_vol_uuid(const AFPObj *obj, const char *volname)
69 char buf[1024], uuid[UUID_PRINTABLE_STRING_LENGTH], *p;
74 if ((fp = fopen(obj->options.uuidconf, "r")) != NULL) { /* read open? */
75 /* scan in the conf file */
76 while (fgets(buf, sizeof(buf), fp) != NULL) {
78 while (p && isblank(*p))
80 if (!p || (*p == '#') || (*p == '\n'))
81 continue; /* invalid line */
84 if ((volname_conf = strtok( p, "\"" )) == NULL)
85 continue; /* syntax error */
87 if ((volname_conf = strtok( p, " \t" )) == NULL)
88 continue; /* syntax error: invalid name */
93 continue; /* syntax error */
95 if (strcmp(volname, volname_conf) != 0)
96 continue; /* another volume name */
98 while (p && isblank(*p))
101 if (sscanf(p, "%36s", uuid) == 1 ) {
102 for (int i=0; uuid[i]; i++)
103 uuid[i] = toupper(uuid[i]);
104 LOG(log_debug, logtype_afpd, "get_uuid('%s'): UUID: '%s'", volname, uuid);
114 /* not found or no file, reopen in append mode */
116 if (stat(obj->options.uuidconf, &tmpstat)) { /* no file */
117 if (( fd = creat(obj->options.uuidconf, 0644 )) < 0 ) {
118 LOG(log_error, logtype_afpd, "ERROR: Cannot create %s (%s).",
119 obj->options.uuidconf, strerror(errno));
122 if (( fp = fdopen( fd, "w" )) == NULL ) {
123 LOG(log_error, logtype_afpd, "ERROR: Cannot fdopen %s (%s).",
124 obj->options.uuidconf, strerror(errno));
128 } else if ((fp = fopen(obj->options.uuidconf, "a+")) == NULL) { /* not found */
129 LOG(log_error, logtype_afpd, "Cannot create or append to %s (%s).",
130 obj->options.uuidconf, strerror(errno));
133 fseek(fp, 0L, SEEK_END);
134 if(ftell(fp) == 0) { /* size = 0 */
135 fprintf(fp, "# DON'T TOUCH NOR COPY THOUGHTLESSLY!\n");
136 fprintf(fp, "# This file is auto-generated by afpd\n");
137 fprintf(fp, "# and stores UUIDs for TM volumes.\n\n");
139 fseek(fp, -1L, SEEK_END);
140 if(fgetc(fp) != '\n') fputc('\n', fp); /* last char is \n? */
143 /* generate uuid and write to file */
146 randombytes((void *)id, 16);
147 cp = uuid_bin2string(id);
149 LOG(log_debug, logtype_afpd, "get_uuid('%s'): generated UUID '%s'", volname, cp);
151 fprintf(fp, "\"%s\"\t%36s\n", volname, cp);
158 Check if the underlying filesystem supports EAs.
159 If not, switch to ea:ad.
160 As we can't check (requires write access) on ro-volumes, we switch ea:auto
161 volumes that are options:ro to ea:none.
163 static int do_check_ea_support(const struct vol *vol)
166 char eaname[] = {"org.netatalk.supports-eas.XXXXXX"};
167 const char *eacontent = "yes";
169 if ((vol->v_flags & AFPVOL_RO) == AFPVOL_RO) {
170 LOG(log_note, logtype_afpd, "read-only volume '%s', can't test for EA support, assuming yes", vol->v_localname);
178 if ((sys_setxattr(vol->v_path, eaname, eacontent, 4, 0)) == 0) {
179 sys_removexattr(vol->v_path, eaname);
182 LOG(log_warning, logtype_afpd, "volume \"%s\" does not support Extended Attributes",
192 static void check_ea_support(struct vol *vol)
195 char eaname[] = {"org.netatalk.supports-eas.XXXXXX"};
196 const char *eacontent = "yes";
198 haseas = do_check_ea_support(vol);
200 if (vol->v_vfs_ea == AFPVOL_EA_AUTO) {
201 if ((vol->v_flags & AFPVOL_RO) == AFPVOL_RO) {
202 LOG(log_info, logtype_afpd, "read-only volume '%s', can't test for EA support, disabling EAs", vol->v_localname);
203 vol->v_vfs_ea = AFPVOL_EA_NONE;
208 vol->v_vfs_ea = AFPVOL_EA_SYS;
210 LOG(log_warning, logtype_afpd, "volume \"%s\" does not support Extended Attributes, using ea:ad instead",
212 vol->v_vfs_ea = AFPVOL_EA_AD;
216 if (vol->v_adouble == AD_VERSION_EA) {
218 vol->v_adouble = AD_VERSION2;
223 * Check whether a volume supports ACLs
225 * @param vol (r) volume
227 * @returns 0 if not, 1 if yes
229 static int check_vol_acl_support(const struct vol *vol)
233 #ifdef HAVE_SOLARIS_ACLS
236 if (get_nfsv4_acl(vol->v_path, &aces) == -1)
239 #ifdef HAVE_POSIX_ACLS
242 if ((acl = acl_get_file(vol->v_path, ACL_TYPE_ACCESS)) == NULL)
246 #ifdef HAVE_SOLARIS_ACLS
247 if (aces) free(aces);
249 #ifdef HAVE_POSIX_ACLS
250 if (acl) acl_free(acl);
251 #endif /* HAVE_POSIX_ACLS */
253 LOG(log_debug, logtype_afpd, "Volume \"%s\" ACL support: %s",
254 vol->v_path, ret ? "yes" : "no");
259 * Handle variable substitutions. here's what we understand:
260 * $b -> basename of path
261 * $c -> client ip/appletalk address
262 * $d -> volume pathname on server
263 * $f -> full name (whatever's in the gecos field)
266 * $i -> client ip/appletalk address without port
267 * $s -> server name (hostname if it doesn't exist)
268 * $u -> username (guest is usually nobody)
269 * $v -> volume name or basename if null
272 * This get's called from readvolfile with
273 * path = NULL, volname = NULL for xlating the volumes path
274 * path = path, volname = NULL for xlating the volumes name
275 * ... and from volumes options parsing code when xlating eg dbpath with
276 * path = path, volname = volname
278 * Using this information we can reject xlation of any variable depeninding on a login
279 * context which is not given in the afp master, where we must evaluate this whole stuff
280 * too for the Zeroconf announcements.
282 static char *volxlate(const AFPObj *obj,
286 const struct passwd *pwd,
294 int xlatevolname = 0;
296 if (path && !volname)
304 dest = calloc(destlen +1, 1);
310 strlcpy(dest, src, destlen +1);
311 if ((p = strchr(src, '$')) == NULL) /* nothing to do */
314 /* first part of the path. just forward to the next variable. */
315 len = MIN((size_t)(p - src), destlen);
321 while (p && destlen > 0) {
322 /* now figure out what the variable is */
324 if (IS_VAR(p, "$b")) {
326 if ((q = strrchr(path, '/')) == NULL)
328 else if (*(q + 1) != '\0')
331 } else if (IS_VAR(p, "$c")) {
333 len = sprintf(dest, "%s:%u",
334 getip_string((struct sockaddr *)&dsi->client),
335 getip_port((struct sockaddr *)&dsi->client));
338 } else if (IS_VAR(p, "$d")) {
340 } else if (pwd && IS_VAR(p, "$f")) {
341 if ((r = strchr(pwd->pw_gecos, ',')))
344 } else if (pwd && IS_VAR(p, "$g")) {
345 struct group *grp = getgrgid(pwd->pw_gid);
348 } else if (IS_VAR(p, "$h")) {
349 q = obj->options.hostname;
350 } else if (IS_VAR(p, "$i")) {
352 q = getip_string((struct sockaddr *)&dsi->client);
353 } else if (IS_VAR(p, "$s")) {
354 q = obj->options.hostname;
355 } else if (obj->username && IS_VAR(p, "$u")) {
357 if ( obj->options.ntseparator && (sep = strchr(obj->username, obj->options.ntseparator[0])) != NULL)
361 } else if (IS_VAR(p, "$v")) {
366 if ((q = strrchr(path, '/')) == NULL)
368 else if (*(q + 1) != '\0')
371 } else if (IS_VAR(p, "$$")) {
376 /* copy the stuff over. if we don't understand something that we
377 * should, just skip it over. */
379 len = MIN(p == q ? 2 : strlen(q), destlen);
380 strncpy(dest, q, len);
385 /* stuff up to next $ */
387 p = strchr(src, '$');
388 len = p ? MIN((size_t)(p - src), destlen) : destlen;
390 strncpy(dest, src, len);
401 * this function wants something of the following form:
402 * "@group,name,name2,@group2,name3"
403 * A NULL argument allows everybody to have access.
404 * We return three things:
406 * 0: list exists, but name isn't in it
409 static int accessvol(const AFPObj *obj, const char *args, const char *name)
411 char buf[MAXPATHLEN + 1], *p;
417 strlcpy(buf, args, sizeof(buf));
418 if ((p = strtok(buf, ",")) == NULL) /* nothing, return okay */
422 if (*p == '@') { /* it's a group */
423 if ((gr = getgrnam(p + 1)) && gmem(gr->gr_gid, obj->ngroups, obj->groups))
425 } else if (strcasecmp(p, name) == 0) /* it's a user name */
427 p = strtok(NULL, ",");
433 static int hostaccessvol(const AFPObj *obj, const char *volname, const char *args)
436 char buf[MAXPATHLEN + 1], *p, *b;
437 struct sockaddr_storage client;
438 const DSI *dsi = obj->dsi;
443 strlcpy(buf, args, sizeof(buf));
444 if ((p = strtok_r(buf, ",", &b)) == NULL) /* nothing, return okay */
449 char *ipaddr, *mask_char;
450 struct addrinfo hints, *ai;
452 ipaddr = strtok(p, "/");
453 mask_char = strtok(NULL,"/");
455 /* Get address from string with getaddrinfo */
456 memset(&hints, 0, sizeof hints);
457 hints.ai_family = AF_UNSPEC;
458 hints.ai_socktype = SOCK_STREAM;
459 if ((ret = getaddrinfo(ipaddr, NULL, &hints, &ai)) != 0) {
460 LOG(log_error, logtype_afpd, "hostaccessvol: getaddrinfo: %s\n", gai_strerror(ret));
465 if (mask_char != NULL)
466 mask_int = atoi(mask_char); /* apply_ip_mask does range checking on it */
468 if (ai->ai_family == AF_INET) /* IPv4 */
474 /* Apply mask to addresses */
475 client = dsi->client;
476 apply_ip_mask((struct sockaddr *)&client, mask_int);
477 apply_ip_mask(ai->ai_addr, mask_int);
479 if (compare_ip((struct sockaddr *)&client, ai->ai_addr) == 0) {
486 p = strtok_r(NULL, ",", &b);
493 * Get option string from config, use default value if not set
495 * @param conf (r) config handle
496 * @param vol (r) volume name (must be section name ie wo vars expanded)
497 * @param opt (r) option
498 * @param def (r) if "option" is not found in "name", try to find it in section "def"
500 * @returns const option string or NULL
502 static const char *getoption(const dictionary *conf, const char *vol, const char *opt, const char *def)
505 const char *result = NULL;
507 if (!(result = iniparser_getstring(conf, vol, opt, NULL)))
508 result = iniparser_getstring(conf, def, opt, NULL);
515 * Create volume struct
517 * @param obj (r) handle
518 * @param pwd (r) struct passwd of logged in user, may be NULL in master afpd
519 * @param section (r) volume name wo variables expanded (exactly as in iniconfig)
520 * @param name (r) volume name
521 * @param path (r) volume path
522 * @param preset (r) default preset, may be NULL
523 * @returns vol on success, NULL on error
525 static struct vol *creatvol(AFPObj *obj,
526 const struct passwd *pwd,
533 struct vol *volume = NULL;
534 int suffixlen, vlen, tmpvlen, u8mvlen, macvlen;
535 char tmpname[AFPVOL_U8MNAMELEN+1];
536 ucs2_t u8mtmpname[(AFPVOL_U8MNAMELEN+1)*2], mactmpname[(AFPVOL_MACNAMELEN+1)*2];
537 char suffix[6]; /* max is #FFFF */
542 LOG(log_debug, logtype_afpd, "createvol(volume: '%s', path: \"%s\", preset: '%s'): BEGIN",
543 name, path, preset ? preset : "-");
545 if ( name == NULL || *name == '\0' ) {
546 if ((name = strrchr( path, '/' )) == NULL) {
550 /* if you wish to share /, you need to specify a name. */
555 /* Once volumes are loaded, we never change options again, we just delete em when they're removed from afp.conf */
556 for (struct vol *vol = Volumes; vol; vol = vol->v_next) {
557 if (STRCMP(path, ==, vol->v_path)) {
558 LOG(log_debug, logtype_afpd, "createvol('%s'): already loaded", name);
566 * Check allow/deny lists:
567 * allow -> either no list (-1), or in list (1)
568 * deny -> either no list (-1), or not in list (0)
571 if (accessvol(obj, getoption(obj->iniconfig, section, "deny", preset), pwd->pw_name) == 1)
573 if (accessvol(obj, getoption(obj->iniconfig, section, "allow", preset), pwd->pw_name) == 0)
575 if (hostaccessvol(obj, section, getoption(obj->iniconfig, section, "denied_hosts", preset)) == 1)
577 if (hostaccessvol(obj, section, getoption(obj->iniconfig, section, "allowed_hosts", preset)) == 0)
581 EC_NULL( volume = calloc(1, sizeof(struct vol)) );
583 volume->v_flags = AFPVOL_USEDOTS | AFPVOL_UNIX_PRIV;
584 EC_NULL( volume->v_configname = strdup(section));
587 volume->v_flags |= AFPVOL_ACLS;
589 volume->v_vfs_ea = AFPVOL_EA_AUTO;
590 volume->v_umask = obj->options.umask;
592 if (val = getoption(obj->iniconfig, section, "password", preset))
593 EC_NULL( volume->v_password = strdup(val) );
595 if (val = getoption(obj->iniconfig, section, "veto", preset))
596 EC_NULL( volume->v_password = strdup(val) );
598 if (val = getoption(obj->iniconfig, section, "volcharset", preset))
599 EC_NULL( volume->v_volcodepage = strdup(val) );
601 EC_NULL( volume->v_volcodepage = strdup("UTF8") );
603 if (val = getoption(obj->iniconfig, section, "maccharset", preset))
604 EC_NULL( volume->v_maccodepage = strdup(val) );
606 EC_NULL( volume->v_maccodepage = strdup(obj->options.maccodepage) );
608 if (val = getoption(obj->iniconfig, section, "dbpath", preset))
609 EC_NULL( volume->v_dbpath = volxlate(obj, NULL, MAXPATHLEN, val, pwd, path, name) );
611 if (val = getoption(obj->iniconfig, section, "cnidscheme", preset))
612 EC_NULL( volume->v_cnidscheme = strdup(val) );
614 if (val = getoption(obj->iniconfig, section, "umask", preset))
615 volume->v_umask = (int)strtol(val, NULL, 8);
617 if (val = getoption(obj->iniconfig, section, "dperm", preset))
618 volume->v_dperm = (int)strtol(val, NULL, 8);
620 if (val = getoption(obj->iniconfig, section, "fperm", preset))
621 volume->v_fperm = (int)strtol(val, NULL, 8);
623 if (val = getoption(obj->iniconfig, section, "perm", preset))
624 volume->v_perm = (int)strtol(val, NULL, 8);
626 if (val = getoption(obj->iniconfig, section, "volsizelimit", preset))
627 volume->v_limitsize = (uint32_t)strtoul(val, NULL, 10);
629 if (val = getoption(obj->iniconfig, section, "preexec", preset))
630 EC_NULL( volume->v_preexec = volxlate(obj, NULL, MAXPATHLEN, val, pwd, path, name) );
632 if (val = getoption(obj->iniconfig, section, "postexec", preset))
633 EC_NULL( volume->v_postexec = volxlate(obj, NULL, MAXPATHLEN, val, pwd, path, name) );
635 if (val = getoption(obj->iniconfig, section, "root_preexec", preset))
636 EC_NULL( volume->v_root_preexec = volxlate(obj, NULL, MAXPATHLEN, val, pwd, path, name) );
638 if (val = getoption(obj->iniconfig, section, "root_postexec", preset))
639 EC_NULL( volume->v_root_postexec = volxlate(obj, NULL, MAXPATHLEN, val, pwd, path, name) );
641 if (val = getoption(obj->iniconfig, section, "adouble", preset)) {
642 if (strcmp(val, "v2") == 0)
643 volume->v_adouble = AD_VERSION2;
644 else if (strcmp(val, "ea") == 0)
645 volume->v_adouble = AD_VERSION_EA;
647 volume->v_adouble = AD_VERSION;
650 if (val = getoption(obj->iniconfig, section, "cnidserver", preset)) {
651 EC_NULL( p = strdup(val) );
652 volume->v_cnidserver = p;
653 if (q = strrchr(val, ':')) {
655 volume->v_cnidport = q;
657 volume->v_cnidport = "4700";
662 if (val = getoption(obj->iniconfig, section, "ea", preset)) {
663 if (strcasecmp(val, "ad") == 0)
664 volume->v_vfs_ea = AFPVOL_EA_AD;
665 else if (strcasecmp(val, "sys") == 0)
666 volume->v_vfs_ea = AFPVOL_EA_SYS;
667 else if (strcasecmp(val, "none") == 0)
668 volume->v_vfs_ea = AFPVOL_EA_NONE;
671 if (val = getoption(obj->iniconfig, section, "casefold", preset)) {
672 if (strcasecmp(val, "tolower") == 0)
673 volume->v_casefold = AFPVOL_UMLOWER;
674 else if (strcasecmp(val, "toupper") == 0)
675 volume->v_casefold = AFPVOL_UMUPPER;
676 else if (strcasecmp(val, "xlatelower") == 0)
677 volume->v_casefold = AFPVOL_UUPPERMLOWER;
678 else if (strcasecmp(val, "xlateupper") == 0)
679 volume->v_casefold = AFPVOL_ULOWERMUPPER;
682 if (val = getoption(obj->iniconfig, section, "options", preset)) {
684 if (p = strtok(q, ", ")) {
686 if (strcasecmp(p, "ro") == 0)
687 volume->v_flags |= AFPVOL_RO;
688 else if (strcasecmp(p, "nohex") == 0)
689 volume->v_flags |= AFPVOL_NOHEX;
690 else if (strcasecmp(p, "nousedots") == 0)
691 volume->v_flags &= ~AFPVOL_USEDOTS;
692 else if (strcasecmp(p, "invisibledots") == 0)
693 volume->v_flags |= volume->v_flags;
694 else if (strcasecmp(p, "nostat") == 0)
695 volume->v_flags |= AFPVOL_NOSTAT;
696 else if (strcasecmp(p, "noupriv") == 0)
697 volume->v_flags &= ~AFPVOL_UNIX_PRIV;
698 else if (strcasecmp(p, "nodev") == 0)
699 volume->v_flags |= AFPVOL_NODEV;
700 else if (strcasecmp(p, "caseinsensitive") == 0)
701 volume->v_flags |= AFPVOL_CASEINSEN;
702 else if (strcasecmp(p, "illegalseq") == 0)
703 volume->v_flags |= AFPVOL_EILSEQ;
704 else if (strcasecmp(p, "tm") == 0)
705 volume->v_flags |= AFPVOL_TM;
706 else if (strcasecmp(p, "searchdb") == 0)
707 volume->v_flags |= AFPVOL_SEARCHDB;
708 else if (strcasecmp(p, "nonetids") == 0)
709 volume->v_flags |= AFPVOL_NONETIDS;
710 else if (strcasecmp(p, "noacls") == 0)
711 volume->v_flags &= ~AFPVOL_ACLS;
712 else if (strcasecmp(p, "nov2toeaconv") == 0)
713 volume->v_flags |= AFPVOL_NOV2TOEACONV;
714 else if (strcasecmp(p, "preexec_close") == 0)
715 volume->v_preexec_close = 1;
716 else if (strcasecmp(p, "root_preexec_close") == 0)
717 volume->v_root_preexec_close = 1;
718 p = strtok(NULL, ", ");
725 * Handle read-only behaviour. semantics:
726 * 1) neither the rolist nor the rwlist exist -> rw
727 * 2) rolist exists -> ro if user is in it.
728 * 3) rwlist exists -> ro unless user is in it.
731 if (accessvol(obj, getoption(obj->iniconfig, section, "rolist", preset), pwd->pw_name) == 1
732 || accessvol(obj, getoption(obj->iniconfig, section, "rwlist", preset), pwd->pw_name) == 0)
733 volume->v_flags |= AFPVOL_RO;
736 if ((volume->v_flags & AFPVOL_NODEV))
737 volume->v_ad_options |= ADVOL_NODEV;
738 if ((volume->v_flags & AFPVOL_UNIX_PRIV))
739 volume->v_ad_options |= ADVOL_UNIXPRIV;
740 if ((volume->v_flags & AFPVOL_INV_DOTS))
741 volume->v_ad_options |= ADVOL_INVDOTS;
743 /* Mac to Unix conversion flags*/
744 if (!(volume->v_flags & AFPVOL_NOHEX))
745 volume->v_mtou_flags |= CONV_ESCAPEHEX;
746 if (!(volume->v_flags & AFPVOL_USEDOTS))
747 volume->v_mtou_flags |= CONV_ESCAPEDOTS;
748 if ((volume->v_flags & AFPVOL_EILSEQ))
749 volume->v_mtou_flags |= CONV__EILSEQ;
751 if ((volume->v_casefold & AFPVOL_MTOUUPPER))
752 volume->v_mtou_flags |= CONV_TOUPPER;
753 else if ((volume->v_casefold & AFPVOL_MTOULOWER))
754 volume->v_mtou_flags |= CONV_TOLOWER;
756 /* Unix to Mac conversion flags*/
757 volume->v_utom_flags = CONV_IGNORE | CONV_UNESCAPEHEX;
758 if ((volume->v_casefold & AFPVOL_UTOMUPPER))
759 volume->v_utom_flags |= CONV_TOUPPER;
760 else if ((volume->v_casefold & AFPVOL_UTOMLOWER))
761 volume->v_utom_flags |= CONV_TOLOWER;
762 if ((volume->v_flags & AFPVOL_EILSEQ))
763 volume->v_utom_flags |= CONV__EILSEQ;
765 /* suffix for mangling use (lastvid + 1) */
766 /* because v_vid has not been decided yet. */
767 suffixlen = sprintf(suffix, "#%X", lastvid + 1 );
770 vlen = strlen( name );
772 /* Unicode Volume Name */
773 /* Firstly convert name from unixcharset to UTF8-MAC */
775 tmpvlen = convert_charset(obj->options.unixcharset, CH_UTF8_MAC, 0, name, vlen, tmpname, AFPVOL_U8MNAMELEN, &flags);
777 strcpy(tmpname, "???");
781 /* Do we have to mangle ? */
782 if ( (flags & CONV_REQMANGLE) || (tmpvlen > obj->options.volnamelen)) {
783 if (tmpvlen + suffixlen > obj->options.volnamelen) {
785 tmpvlen = convert_charset(obj->options.unixcharset, CH_UTF8_MAC, 0, name, vlen, tmpname, obj->options.volnamelen - suffixlen, &flags);
786 tmpname[tmpvlen >= 0 ? tmpvlen : 0] = 0;
788 strcat(tmpname, suffix);
789 tmpvlen = strlen(tmpname);
792 /* Secondly convert name from UTF8-MAC to UCS2 */
793 if ( 0 >= ( u8mvlen = convert_string(CH_UTF8_MAC, CH_UCS2, tmpname, tmpvlen, u8mtmpname, AFPVOL_U8MNAMELEN*2)) )
796 LOG(log_maxdebug, logtype_afpd, "createvol: Volume '%s' -> UTF8-MAC Name: '%s'", name, tmpname);
798 /* Maccharset Volume Name */
799 /* Firsty convert name from unixcharset to maccharset */
801 tmpvlen = convert_charset(obj->options.unixcharset, obj->options.maccharset, 0, name, vlen, tmpname, AFPVOL_U8MNAMELEN, &flags);
803 strcpy(tmpname, "???");
807 /* Do we have to mangle ? */
808 if ( (flags & CONV_REQMANGLE) || (tmpvlen > AFPVOL_MACNAMELEN)) {
809 if (tmpvlen + suffixlen > AFPVOL_MACNAMELEN) {
811 tmpvlen = convert_charset(obj->options.unixcharset,
812 obj->options.maccharset,
817 AFPVOL_MACNAMELEN - suffixlen,
819 tmpname[tmpvlen >= 0 ? tmpvlen : 0] = 0;
821 strcat(tmpname, suffix);
822 tmpvlen = strlen(tmpname);
825 /* Secondly convert name from maccharset to UCS2 */
826 if ( 0 >= ( macvlen = convert_string(obj->options.maccharset,
831 AFPVOL_U8MNAMELEN*2)) )
834 LOG(log_maxdebug, logtype_afpd, "createvol: Volume '%s' -> Longname: '%s'", name, tmpname);
836 EC_NULL( volume->v_localname = strdup(name) );
837 EC_NULL( volume->v_u8mname = strdup_w(u8mtmpname) );
838 EC_NULL( volume->v_macname = strdup_w(mactmpname) );
839 EC_NULL( volume->v_path = malloc(strlen(path) + 1) );
841 volume->v_name = utf8_encoding(obj) ? volume->v_u8mname : volume->v_macname;
842 strcpy(volume->v_path, path);
846 #endif /* __svr4__ */
848 /* os X start at 1 and use network order ie. 1 2 3 */
849 volume->v_vid = ++lastvid;
850 volume->v_vid = htons(volume->v_vid);
853 if (!check_vol_acl_support(volume)) {
854 LOG(log_debug, logtype_afpd, "creatvol(\"%s\"): disabling ACL support", volume->v_path);
855 volume->v_flags &= ~AFPVOL_ACLS;
859 volume->v_dperm |= volume->v_perm;
860 volume->v_fperm |= volume->v_perm;
862 /* Check EA support on volume */
863 if (volume->v_vfs_ea == AFPVOL_EA_AUTO || volume->v_adouble == AD_VERSION_EA)
864 check_ea_support(volume);
867 /* get/store uuid from file in afpd master*/
868 if (!(pwd) && (volume->v_flags & AFPVOL_TM)) {
869 char *uuid = get_vol_uuid(obj, volume->v_localname);
871 LOG(log_error, logtype_afpd, "Volume '%s': couldn't get UUID",
872 volume->v_localname);
874 volume->v_uuid = uuid;
875 LOG(log_debug, logtype_afpd, "Volume '%s': UUID '%s'",
876 volume->v_localname, volume->v_uuid);
880 /* no errors shall happen beyond this point because the cleanup would mess the volume chain up */
881 volume->v_next = Volumes;
886 LOG(log_debug, logtype_afpd, "createvol: END: %d", ret);
897 /* ----------------------
899 static int volfile_changed(struct afp_options *p)
903 if (!stat(p->configfile, &st) && st.st_mtime > p->volfile.mtime) {
904 p->volfile.mtime = st.st_mtime;
910 static int vol_section(const char *sec)
912 if (STRCMP(sec, ==, INISEC_GLOBAL))
917 #define MAXPRESETLEN 100
919 * Read volumes from iniconfig and add the volumes contained within to
920 * the global volume list. This gets called from the forked afpd childs.
921 * The master now reads this too for Zeroconf announcements.
923 static int readvolfile(AFPObj *obj, const struct passwd *pwent)
926 char path[MAXPATHLEN + 1];
927 char volname[AFPVOL_U8MNAMELEN + 1];
928 char tmp[MAXPATHLEN + 1];
929 const char *preset, *default_preset, *p;
934 LOG(log_debug, logtype_afpd, "readvolfile: BEGIN");
936 int secnum = iniparser_getnsec(obj->iniconfig);
937 LOG(log_debug, logtype_afpd, "readvolfile: sections: %d", secnum);
940 if ((default_preset = iniparser_getstring(obj->iniconfig, INISEC_GLOBAL, "vol preset", NULL))) {
941 LOG(log_debug, logtype_afpd, "readvolfile: default_preset: %s", default_preset);
944 for (i = 0; i < secnum; i++) {
945 secname = iniparser_getsecname(obj->iniconfig, i);
947 if (!vol_section(secname))
949 if (STRCMP(secname, ==, INISEC_HOMES)) {
952 /* not an AFP session, but cnid daemon, dbd or ad util */
954 strlcpy(tmp, pwent->pw_dir, MAXPATHLEN);
955 strlcat(tmp, "/", MAXPATHLEN);
956 if (p = iniparser_getstring(obj->iniconfig, INISEC_HOMES, "path", NULL))
957 strlcat(tmp, p, MAXPATHLEN);
960 if ((p = iniparser_getstring(obj->iniconfig, secname, "path", NULL)) == NULL)
962 strlcpy(tmp, p, MAXPATHLEN);
965 if (volxlate(obj, path, sizeof(path) - 1, tmp, pwent, NULL, NULL) == NULL)
968 /* do variable substitution for volume name */
969 if (STRCMP(secname, ==, INISEC_HOMES)) {
970 if (p = iniparser_getstring(obj->iniconfig, INISEC_HOMES, "name", "$u's home"))
971 strlcpy(tmp, p, MAXPATHLEN);
973 strlcpy(tmp, p, MAXPATHLEN);
975 strlcpy(tmp, secname, AFPVOL_U8MNAMELEN);
977 if (volxlate(obj, volname, sizeof(volname) - 1, tmp, pwent, path, NULL) == NULL)
980 preset = iniparser_getstring(obj->iniconfig, secname, "vol preset", NULL);
982 creatvol(obj, pwent, secname, volname, path, preset ? preset : default_preset ? default_preset : NULL);
989 /**************************************************************
991 **************************************************************/
994 * Remove a volume from the linked list of volumes
996 void volume_unlink(struct vol *volume)
998 struct vol *vol, *ovol, *nvol;
1000 if (volume == Volumes) {
1004 for ( vol = Volumes->v_next, ovol = Volumes; vol; vol = nvol) {
1007 if (vol == volume) {
1008 ovol->v_next = nvol;
1018 * Free all resources allocated in a struct vol, only struct dir *v_root can't be freed
1020 void volume_free(struct vol *vol)
1022 LOG(log_debug, logtype_afpd, "volume_free('%s'): BEGIN", vol->v_localname);
1024 free(vol->v_localname);
1025 free(vol->v_u8mname);
1026 free(vol->v_macname);
1028 free(vol->v_password);
1030 free(vol->v_volcodepage);
1031 free(vol->v_maccodepage);
1032 free(vol->v_cnidscheme);
1033 free(vol->v_dbpath);
1036 free(vol->v_cnidserver);
1038 /* NO! Just points to v_cnidserver + x */
1039 free(vol->v_cnidport);
1041 free(vol->v_root_preexec);
1042 free(vol->v_postexec);
1044 LOG(log_debug, logtype_afpd, "volume_free: END");
1048 * Load charsets for a volume
1050 int load_charset(struct vol *vol)
1052 if ((vol->v_maccharset = add_charset(vol->v_maccodepage)) == (charset_t)-1) {
1053 LOG(log_error, logtype_default, "Setting Mac codepage '%s' failed", vol->v_maccodepage);
1057 if ((vol->v_volcharset = add_charset(vol->v_volcodepage)) == (charset_t)-1) {
1058 LOG(log_error, logtype_default, "Setting volume codepage '%s' failed", vol->v_volcodepage);
1066 * Initialize volumes and load ini configfile
1068 * Depending on the value of obj->uid either access checks are done (!=0) or skipped (=0)
1070 * @param obj (r) handle
1071 * @param delvol_fn (r) callback called for deleted volumes
1073 int load_volumes(AFPObj *obj, void (*delvol_fn)(struct vol *))
1077 struct passwd *pwent = NULL;
1082 LOG(log_debug, logtype_afpd, "load_volumes: BEGIN");
1085 if (!volfile_changed(&obj->options))
1088 for (vol = Volumes; vol; vol = vol->v_next) {
1089 if (vol->v_flags & AFPVOL_UNIX_CTXT)
1094 LOG(log_debug, logtype_afpd, "load_volumes: no volumes yet");
1095 EC_ZERO_LOG( lstat(obj->options.configfile, &st) );
1096 obj->options.volfile.mtime = st.st_mtime;
1099 /* try putting a read lock on the volume file twice, sleep 1 second if first attempt fails */
1101 fd = open(obj->options.configfile, O_RDONLY);
1103 while (retries < 2) {
1104 if ((read_lock(fd, 0, SEEK_SET, 0)) != 0) {
1107 LOG(log_error, logtype_afpd, "readvolfile: can't lock configfile \"%s\"",
1108 obj->options.configfile);
1118 pwent = getpwuid(obj->uid);
1121 iniparser_freedict(obj->iniconfig);
1122 LOG(log_debug, logtype_afpd, "load_volumes: loading: %s", obj->options.configfile);
1123 obj->iniconfig = iniparser_load(obj->options.configfile);
1125 EC_ZERO_LOG( readvolfile(obj, pwent) );
1127 for ( vol = Volumes; vol; vol = vol->v_next ) {
1128 if (vol->v_deleted) {
1129 LOG(log_debug, logtype_afpd, "load_volumes: deleted: %s", vol->v_localname);
1140 LOG(log_debug, logtype_afpd, "load_volumes: END");
1144 void unload_volumes(AFPObj *obj)
1148 LOG(log_debug, logtype_afpd, "unload_volumes: BEGIN");
1150 for (vol = Volumes; vol; vol = vol->v_next)
1153 obj->options.volfile.mtime = 0;
1155 LOG(log_debug, logtype_afpd, "unload_volumes: END");
1158 struct vol *getvolumes(void)
1163 struct vol *getvolbyvid(const uint16_t vid )
1167 for ( vol = Volumes; vol; vol = vol->v_next ) {
1168 if ( vid == vol->v_vid ) {
1172 if ( vol == NULL || ( vol->v_flags & AFPVOL_OPEN ) == 0 ) {
1179 struct vol *getvolbypath(AFPObj *obj, const char *path)
1184 const struct passwd *pw;
1185 char volname[AFPVOL_U8MNAMELEN + 1];
1186 char volpath[MAXPATHLEN + 1];
1187 char tmpbuf[MAXPATHLEN + 1];
1188 const char *secname, *basedir, *p = NULL, *subpath = NULL, *subpathconfig;
1189 char *user = NULL, *prw;
1192 regmatch_t match[1];
1194 LOG(log_debug, logtype_afpd, "getvolbypath(\"%s\")", path);
1196 for (tmp = Volumes; tmp; tmp = tmp->v_next) {
1197 if (strncmp(path, tmp->v_path, strlen(tmp->v_path)) == 0) {
1203 /* might be a user home, check for that and create a volume if yes */
1205 EC_FAIL_LOG("getvolbypath(\"%s\"): no volume for path", path);
1207 int secnum = iniparser_getnsec(obj->iniconfig);
1209 for (int i = 0; i < secnum; i++) {
1210 secname = iniparser_getsecname(obj->iniconfig, i);
1211 if (STRCMP(secname, ==, INISEC_HOMES))
1215 if (STRCMP(secname, !=, INISEC_HOMES))
1216 EC_FAIL_LOG("getvolbypath(\"%s\"): no volume for path", path);
1218 EC_NULL_LOG( basedir = iniparser_getstring(obj->iniconfig, INISEC_HOMES, "basedir regex", NULL) );
1219 LOG(log_debug, logtype_afpd, "getvolbypath: user home section: '%s', basedir: '%s'", secname, basedir);
1221 if (regexerr != 0 && (regexerr = regcomp(®, basedir, REG_EXTENDED)) != 0) {
1223 regerror(regexerr, ®, errbuf, sizeof(errbuf));
1224 printf("error: %s\n", errbuf);
1225 EC_FAIL_LOG("getvolbypath(\"%s\"): bad basedir regex: %s", errbuf);
1228 if (regexec(®, path, 1, match, 0) == REG_NOMATCH)
1229 EC_FAIL_LOG("getvolbypath(\"%s\"): no volume for path", path);
1231 if (match[0].rm_eo - match[0].rm_so > MAXPATHLEN)
1232 EC_FAIL_LOG("getvolbypath(\"%s\"): path too long", path);
1234 strncpy(tmpbuf, path + match[0].rm_so, match[0].rm_eo - match[0].rm_so);
1235 tmpbuf[match[0].rm_eo - match[0].rm_so] = 0;
1237 LOG(log_debug, logtype_afpd, "getvolbypath: basedir regex: '%s', basedir match: \"%s\"",
1240 strlcat(tmpbuf, "/", MAXPATHLEN);
1242 p = path + strlen(basedir);
1245 EC_NULL_LOG( user = strdup(p) );
1247 if (prw = strchr(user, '/'))
1252 strlcat(tmpbuf, user, MAXPATHLEN);
1253 strlcat(tmpbuf, "/", MAXPATHLEN);
1255 if (subpathconfig = iniparser_getstring(obj->iniconfig, INISEC_HOMES, "path", NULL)) {
1256 if (!subpath || strncmp(subpathconfig, subpath, strlen(subpathconfig)) != 0) {
1261 strlcat(tmpbuf, subpathconfig, MAXPATHLEN);
1262 strlcat(tmpbuf, "/", MAXPATHLEN);
1264 if (volxlate(obj, volpath, sizeof(volpath) - 1, tmpbuf, pw, NULL, NULL) == NULL)
1267 EC_NULL( pw = getpwnam(user) );
1269 LOG(log_debug, logtype_afpd, "getvolbypath(\"%s\"): user: %s, homedir: %s => volpath: \"%s\"",
1270 path, user, pw->pw_dir, volpath);
1272 /* do variable substitution for volume name */
1273 p = iniparser_getstring(obj->iniconfig, INISEC_HOMES, "name", "$u's home");
1274 strlcpy(tmpbuf, p, AFPVOL_U8MNAMELEN);
1275 EC_NULL_LOG( volxlate(obj, volname, sizeof(volname) - 1, tmpbuf, pw, volpath, NULL) );
1277 const char *preset, *default_preset;
1278 default_preset = iniparser_getstring(obj->iniconfig, INISEC_GLOBAL, "vol preset", NULL);
1279 preset = iniparser_getstring(obj->iniconfig, INISEC_HOMES, "vol preset", NULL);
1281 vol = creatvol(obj, pw, INISEC_HOMES, volname, volpath, preset ? preset : default_preset ? default_preset : NULL);
1292 struct vol *getvolbyname(const char *name)
1294 struct vol *vol = NULL;
1297 for (tmp = Volumes; tmp; tmp = tmp->v_next) {
1298 if (strncmp(name, tmp->v_configname, strlen(tmp->v_configname)) == 0) {
1308 * Initialize an AFPObj and options from ini config file
1310 int afp_config_parse(AFPObj *AFPObj)
1314 struct afp_options *options = &AFPObj->options;
1316 const char *p, *tmp;
1320 AFPObj->afp_version = 11;
1321 options->configfile = AFPObj->cmdlineconfigfile ? strdup(AFPObj->cmdlineconfigfile) : strdup(_PATH_CONFDIR "afp.conf");
1322 options->sigconffile = strdup(_PATH_CONFDIR "afp_signature.conf");
1323 options->uuidconf = strdup(_PATH_CONFDIR "afp_voluuid.conf");
1324 options->flags = OPTION_ACL2MACCESS | OPTION_UUID | OPTION_SERVERNOTIF | AFPObj->cmdlineflags;
1326 if ((config = iniparser_load(AFPObj->options.configfile)) == NULL)
1328 AFPObj->iniconfig = config;
1331 options->logconfig = iniparser_getstrdup(config, INISEC_GLOBAL, "loglevel", "default:note");
1332 options->logfile = iniparser_getstrdup(config, INISEC_GLOBAL, "logfile", NULL);
1334 /* [AFP] "options" options wo values */
1335 if (p = iniparser_getstrdup(config, INISEC_GLOBAL, "options", NULL)) {
1336 if (p = strtok(q, ", ")) {
1338 if (strcasecmp(p, "nozeroconf"))
1339 options->flags |= OPTION_NOZEROCONF;
1340 if (strcasecmp(p, "icon"))
1341 options->flags |= OPTION_CUSTOMICON;
1342 if (strcasecmp(p, "noicon"))
1343 options->flags &= ~OPTION_CUSTOMICON;
1344 if (strcasecmp(p, "advertise_ssh"))
1345 options->flags |= OPTION_ANNOUNCESSH;
1346 if (strcasecmp(p, "noacl2maccess"))
1347 options->flags &= ~OPTION_ACL2MACCESS;
1348 if (strcasecmp(p, "keepsessions"))
1349 options->flags |= OPTION_KEEPSESSIONS;
1350 if (strcasecmp(p, "closevol"))
1351 options->flags |= OPTION_CLOSEVOL;
1352 if (strcasecmp(p, "client_polling"))
1353 options->flags &= ~OPTION_SERVERNOTIF;
1354 if (strcasecmp(p, "nosavepassword"))
1355 options->passwdbits |= PASSWD_NOSAVE;
1356 if (strcasecmp(p, "savepassword"))
1357 options->passwdbits &= ~PASSWD_NOSAVE;
1358 if (strcasecmp(p, "nosetpassword"))
1359 options->passwdbits &= ~PASSWD_SET;
1360 if (strcasecmp(p, "setpassword"))
1361 options->passwdbits |= PASSWD_SET;
1362 p = strtok(NULL, ", ");
1366 /* figure out options w values */
1368 options->loginmesg = iniparser_getstrdup(config, INISEC_GLOBAL, "loginmesg", "");
1369 options->guest = iniparser_getstrdup(config, INISEC_GLOBAL, "guestname", "nobody");
1370 options->passwdfile = iniparser_getstrdup(config, INISEC_GLOBAL, "passwdfile", _PATH_AFPDPWFILE);
1371 options->uampath = iniparser_getstrdup(config, INISEC_GLOBAL, "uampath", _PATH_AFPDUAMPATH);
1372 options->uamlist = iniparser_getstrdup(config, INISEC_GLOBAL, "uamlist", "uams_dhx.so,uams_dhx2.so");
1373 options->port = iniparser_getstrdup(config, INISEC_GLOBAL, "afp port", "548");
1374 options->signatureopt = iniparser_getstrdup(config, INISEC_GLOBAL, "signature", "auto");
1375 options->k5service = iniparser_getstrdup(config, INISEC_GLOBAL, "k5service", NULL);
1376 options->k5realm = iniparser_getstrdup(config, INISEC_GLOBAL, "k5realm", NULL);
1377 options->listen = iniparser_getstrdup(config, INISEC_GLOBAL, "afp listen", NULL);
1378 options->ntdomain = iniparser_getstrdup(config, INISEC_GLOBAL, "ntdomain", NULL);
1379 options->ntseparator = iniparser_getstrdup(config, INISEC_GLOBAL, "ntseparator", NULL);
1380 options->mimicmodel = iniparser_getstrdup(config, INISEC_GLOBAL, "mimicmodel", NULL);
1381 options->adminauthuser = iniparser_getstrdup(config, INISEC_GLOBAL, "adminauthuser", NULL);
1382 options->connections = iniparser_getint (config, INISEC_GLOBAL, "maxcon", 200);
1383 options->passwdminlen = iniparser_getint (config, INISEC_GLOBAL, "passwdminlen", 0);
1384 options->tickleval = iniparser_getint (config, INISEC_GLOBAL, "tickleval", 30);
1385 options->timeout = iniparser_getint (config, INISEC_GLOBAL, "timeout", 4);
1386 options->dsireadbuf = iniparser_getint (config, INISEC_GLOBAL, "dsireadbuf", 12);
1387 options->server_quantum = iniparser_getint (config, INISEC_GLOBAL, "server_quantum", DSI_SERVQUANT_DEF);
1388 options->volnamelen = iniparser_getint (config, INISEC_GLOBAL, "volnamelen", 80);
1389 options->dircachesize = iniparser_getint (config, INISEC_GLOBAL, "dircachesize", DEFAULT_MAX_DIRCACHE_SIZE);
1390 options->tcp_sndbuf = iniparser_getint (config, INISEC_GLOBAL, "tcpsndbuf", 0);
1391 options->tcp_rcvbuf = iniparser_getint (config, INISEC_GLOBAL, "tcprcvbuf", 0);
1392 options->fce_fmodwait = iniparser_getint (config, INISEC_GLOBAL, "fceholdfmod", 60);
1393 options->sleep = iniparser_getint (config, INISEC_GLOBAL, "sleep", 10);
1394 options->disconnected = iniparser_getint (config, INISEC_GLOBAL, "disconnect", 24);
1396 if ((p = iniparser_getstring(config, INISEC_GLOBAL, "hostname", NULL))) {
1397 EC_NULL_LOG( options->hostname = strdup(p) );
1399 if (gethostname(val, sizeof(val)) < 0 ) {
1400 perror( "gethostname" );
1403 if ((q = strchr(val, '.')))
1405 options->hostname = strdup(val);
1408 if ((p = iniparser_getstring(config, INISEC_GLOBAL, "k5keytab", NULL))) {
1409 EC_NULL_LOG( options->k5keytab = malloc(strlen(p) + 14) );
1410 snprintf(options->k5keytab, strlen(p) + 14, "KRB5_KTNAME=%s", p);
1411 putenv(options->k5keytab);
1415 if ((p = iniparser_getstring(config, INISEC_GLOBAL, "admingroup", NULL))) {
1416 struct group *gr = getgrnam(p);
1418 options->admingid = gr->gr_gid;
1420 #endif /* ADMIN_GRP */
1422 q = iniparser_getstrdup(config, INISEC_GLOBAL, "cnidserver", "localhost:4700");
1423 r = strrchr(q, ':');
1426 options->Cnid_srv = strdup(q);
1428 options->Cnid_port = strdup(r + 1);
1430 options->Cnid_port = strdup("4700");
1431 LOG(log_debug, logtype_afpd, "CNID Server: %s:%s", options->Cnid_srv, options->Cnid_port);
1435 if ((q = iniparser_getstrdup(config, INISEC_GLOBAL, "fqdn", NULL))) {
1436 /* do a little checking for the domain name. */
1440 if (gethostbyname(q)) {
1443 EC_NULL_LOG( options->fqdn = strdup(q) );
1445 LOG(log_error, logtype_afpd, "error parsing -fqdn, gethostbyname failed for: %s", c);
1450 if (!(p = iniparser_getstring(config, INISEC_GLOBAL, "unixcodepage", NULL))) {
1451 options->unixcharset = CH_UNIX;
1452 options->unixcodepage = strdup("LOCALE");
1454 if ((options->unixcharset = add_charset(p)) == (charset_t)-1) {
1455 options->unixcharset = CH_UNIX;
1456 options->unixcodepage = strdup("LOCALE");
1457 LOG(log_warning, logtype_afpd, "Setting Unix codepage to '%s' failed", p);
1459 options->unixcodepage = strdup(p);
1463 if (!(p = iniparser_getstring(config, INISEC_GLOBAL, "maccodepage", NULL))) {
1464 options->maccharset = CH_MAC;
1465 options->maccodepage = strdup("MAC_ROMAN");
1467 if ((options->maccharset = add_charset(p)) == (charset_t)-1) {
1468 options->maccharset = CH_MAC;
1469 options->maccodepage = strdup("MAC_ROMAN");
1470 LOG(log_warning, logtype_afpd, "Setting Mac codepage to '%s' failed", p);
1472 options->maccodepage = strdup(p);
1476 /* Check for sane values */
1477 if (options->tickleval <= 0)
1478 options->tickleval = 30;
1479 options->disconnected *= 3600 / options->tickleval;
1480 options->sleep *= 3600 / options->tickleval;
1481 if (options->timeout <= 0)
1482 options->timeout = 4;
1483 if (options->sleep <= 4)
1484 options->disconnected = options->sleep = 4;
1485 if (options->dsireadbuf < 6)
1486 options->dsireadbuf = 6;
1487 if (options->volnamelen < 8)
1488 options->volnamelen = 8; /* max mangled volname "???#FFFF" */
1489 if (options->volnamelen > 255)
1490 options->volnamelen = 255; /* AFP3 spec */