2 * $Id: volume.c,v 1.51.2.1 2003-05-26 11:04:36 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";
85 static struct extmap *extmap = NULL, *defextmap = NULL;
86 static int extmap_cnt;
88 #define VOLOPT_ALLOW 0 /* user allow list */
89 #define VOLOPT_DENY 1 /* user deny list */
90 #define VOLOPT_RWLIST 2 /* user rw list */
91 #define VOLOPT_ROLIST 3 /* user ro list */
92 #define VOLOPT_CODEPAGE 4 /* codepage */
93 #define VOLOPT_PASSWORD 5 /* volume password */
94 #define VOLOPT_CASEFOLD 6 /* character case mangling */
95 #define VOLOPT_FLAGS 7 /* various flags */
96 #define VOLOPT_DBPATH 8 /* path to database */
97 #define VOLOPT_MAPCHARS 9 /* does mtou and utom mappings. syntax:
98 m and u can be double-byte hex
103 !u -> make u illegal always
104 ~u -> make u illegal only as the first
105 part of a double-byte character.
107 #define VOLOPT_VETO 10 /* list of veto filespec */
108 #define VOLOPT_PREEXEC 11 /* preexec command */
109 #define VOLOPT_ROOTPREEXEC 12 /* root preexec command */
111 #define VOLOPT_POSTEXEC 13 /* postexec command */
112 #define VOLOPT_ROOTPOSTEXEC 14 /* root postexec command */
117 #define VOLOPT_FORCEUID 15 /* force uid for username x */
118 #define VOLOPT_FORCEGID 16 /* force gid for group x */
119 #define VOLOPT_UMASK 17
121 #define VOLOPT_UMASK 15
122 #endif /* FORCE_UIDGID */
124 #define VOLOPT_MAX (VOLOPT_UMASK +1)
126 #define VOLOPT_NUM (VOLOPT_MAX + 1)
129 #define VOLOPT_DEFAULT ":DEFAULT:"
130 #define VOLOPT_DEFAULT_LEN 9
136 static __inline__ void volfree(struct vol_option *options,
137 const struct vol_option *save)
142 for (i = 0; i < VOLOPT_MAX; i++) {
143 if (options[i].c_value && (options[i].c_value != save[i].c_value))
144 free(options[i].c_value);
147 for (i = 0; i < VOLOPT_MAX; i++) {
148 if (options[i].c_value)
149 free(options[i].c_value);
155 /* handle variable substitutions. here's what we understand:
156 * $b -> basename of path
157 * $c -> client ip/appletalk address
158 * $d -> volume pathname on server
159 * $f -> full name (whatever's in the gecos field)
162 * $s -> server name (hostname if it doesn't exist)
163 * $u -> username (guest is usually nobody)
164 * $v -> volume name (ADEID_NAME or basename if ADEID_NAME is empty)
165 * $z -> zone (may not exist)
168 #define is_var(a, b) (strncmp((a), (b), 2) == 0)
170 static char *volxlate(AFPObj *obj, char *dest, size_t destlen,
171 char *src, struct passwd *pwd, char *path)
181 dest = calloc(destlen +1, 1);
187 strncpy(dest, src, destlen);
188 if ((p = strchr(src, '$')) == NULL) /* nothing to do */
191 /* first part of the path. just forward to the next variable. */
192 len = MIN(p - src, destlen);
198 while (p && destlen > 0) {
199 /* now figure out what the variable is */
201 if (is_var(p, "$b")) {
203 if ((q = strrchr(path, '/')) == NULL)
205 else if (*(q + 1) != '\0')
208 } else if (is_var(p, "$c")) {
209 if (obj->proto == AFPPROTO_ASP) {
210 ASP asp = obj->handle;
212 len = sprintf(dest, "%u.%u", ntohs(asp->asp_sat.sat_addr.s_net),
213 asp->asp_sat.sat_addr.s_node);
217 } else if (obj->proto == AFPPROTO_DSI) {
218 DSI *dsi = obj->handle;
220 len = sprintf(dest, "%s:%u", inet_ntoa(dsi->client.sin_addr),
221 ntohs(dsi->client.sin_port));
225 } else if (is_var(p, "$d")) {
227 } else if (is_var(p, "$f")) {
228 if ((q = strchr(pwd->pw_gecos, ',')))
231 } else if (is_var(p, "$g")) {
232 struct group *grp = getgrgid(pwd->pw_gid);
235 } else if (is_var(p, "$h")) {
236 q = obj->options.hostname;
237 } else if (is_var(p, "$s")) {
240 else if (obj->options.server) {
241 q = obj->options.server;
243 q = obj->options.hostname;
244 } else if (is_var(p, "$u")) {
246 } else if (is_var(p, "$v")) {
250 memset(&ad, 0, sizeof(ad));
251 if (ad_open(path, ADFLAGS_HF, O_RDONLY, 0, &ad) < 0)
254 if ((len = MIN(ad_getentrylen(&ad, ADEID_NAME), destlen)) > 0) {
255 memcpy(dest, ad_entry(&ad, ADEID_NAME), len);
256 ad_close(&ad, ADFLAGS_HF);
260 ad_close(&ad, ADFLAGS_HF);
261 no_volname: /* simple basename */
262 if ((q = strrchr(path, '/')) == NULL)
264 else if (*(q + 1) != '\0')
268 } else if (is_var(p, "$z")) {
270 } else if (is_var(p, "$$")) {
275 /* copy the stuff over. if we don't understand something that we
276 * should, just skip it over. */
278 len = MIN(p == q ? 2 : strlen(q), destlen);
279 strncpy(dest, q, len);
284 /* stuff up to next $ */
286 p = strchr(src, '$');
287 len = p ? MIN(p - src, destlen) : destlen;
289 strncpy(dest, src, len);
297 /* to make sure that val is valid, make sure to select an opt that
299 static int optionok(const char *buf, const char *opt, const char *val)
301 if (!strstr(buf,opt))
308 static __inline__ char *get_codepage_path(const char *path, const char *name)
314 page = (char *) malloc((len = strlen(path)) + strlen(name) + 2);
317 if (path[len - 1] != '/') /* add a / */
325 /* debug: show which codepage directory we are using */
326 LOG(log_debug, logtype_afpd, "using codepage directory: %s", page);
331 /* -------------------- */
332 static void setoption(struct vol_option *options, struct vol_option *save, int opt, const char *val)
334 if (options[opt].c_value && (!save || options[opt].c_value != save[opt].c_value))
335 free(options[opt].c_value);
336 options[opt].c_value = strdup(val + 1);
339 /* ------------------------------------------
340 handle all the options. tmp can't be NULL. */
341 static void volset(struct vol_option *options, struct vol_option *save,
342 char *volname, int vlen,
343 const char *nlspath, const char *tmp)
347 val = strchr(tmp, ':');
349 /* we'll assume it's a volume name. */
350 strncpy(volname, tmp, vlen);
355 LOG(log_debug, logtype_afpd, "Parsing volset %s", val);
357 if (optionok(tmp, "allow:", val)) {
358 setoption(options, save, VOLOPT_ALLOW, val);
360 } else if (optionok(tmp, "deny:", val)) {
361 setoption(options, save, VOLOPT_DENY, val);
363 } else if (optionok(tmp, "rwlist:", val)) {
364 setoption(options, save, VOLOPT_RWLIST, val);
366 } else if (optionok(tmp, "rolist:", val)) {
367 setoption(options, save, VOLOPT_ROLIST, val);
369 } else if (optionok(tmp, "codepage:", val)) {
370 if (options[VOLOPT_CODEPAGE].c_value &&
371 (!save || options[VOLOPT_CODEPAGE].c_value != save[VOLOPT_CODEPAGE].c_value)) {
372 free(options[VOLOPT_CODEPAGE].c_value);
374 options[VOLOPT_CODEPAGE].c_value = get_codepage_path(nlspath, val + 1);
376 } else if (optionok(tmp, "veto:", val)) {
377 setoption(options, save, VOLOPT_VETO, val);
378 } else if (optionok(tmp, "casefold:", val)) {
379 if (strcasecmp(val + 1, "tolower") == 0)
380 options[VOLOPT_CASEFOLD].i_value = AFPVOL_UMLOWER;
381 else if (strcasecmp(val + 1, "toupper") == 0)
382 options[VOLOPT_CASEFOLD].i_value = AFPVOL_UMUPPER;
383 else if (strcasecmp(val + 1, "xlatelower") == 0)
384 options[VOLOPT_CASEFOLD].i_value = AFPVOL_UUPPERMLOWER;
385 else if (strcasecmp(val + 1, "xlateupper") == 0)
386 options[VOLOPT_CASEFOLD].i_value = AFPVOL_ULOWERMUPPER;
388 } else if (optionok(tmp, "options:", val)) {
391 if ((p = strtok(val + 1, ",")) == NULL) /* nothing */
395 if (strcasecmp(p, "prodos") == 0)
396 options[VOLOPT_FLAGS].i_value |= AFPVOL_A2VOL;
397 else if (strcasecmp(p, "mswindows") == 0) {
398 options[VOLOPT_FLAGS].i_value |= AFPVOL_MSWINDOWS;
399 if (!options[VOLOPT_CODEPAGE].c_value)
400 options[VOLOPT_CODEPAGE].c_value =
401 get_codepage_path(nlspath, MSWINDOWS_CODEPAGE);
403 } else if (strcasecmp(p, "crlf") == 0)
404 options[VOLOPT_FLAGS].i_value |= AFPVOL_CRLF;
405 else if (strcasecmp(p, "noadouble") == 0)
406 options[VOLOPT_FLAGS].i_value |= AFPVOL_NOADOUBLE;
407 else if (strcasecmp(p, "ro") == 0)
408 options[VOLOPT_FLAGS].i_value |= AFPVOL_RO;
409 else if (strcasecmp(p, "nohex") == 0)
410 options[VOLOPT_FLAGS].i_value |= AFPVOL_NOHEX;
411 else if (strcasecmp(p, "usedots") == 0)
412 options[VOLOPT_FLAGS].i_value |= AFPVOL_USEDOTS;
413 else if (strcasecmp(p, "limitsize") == 0)
414 options[VOLOPT_FLAGS].i_value |= AFPVOL_LIMITSIZE;
415 /* support for either "dropbox" or "dropkludge" */
416 else if (strcasecmp(p, "dropbox") == 0)
417 options[VOLOPT_FLAGS].i_value |= AFPVOL_DROPBOX;
418 else if (strcasecmp(p, "dropkludge") == 0)
419 options[VOLOPT_FLAGS].i_value |= AFPVOL_DROPBOX;
420 else if (strcasecmp(p, "nofileid") == 0)
421 options[VOLOPT_FLAGS].i_value |= AFPVOL_NOFILEID;
422 else if (strcasecmp(p, "utf8") == 0)
423 options[VOLOPT_FLAGS].i_value |= AFPVOL_UTF8;
424 else if (strcasecmp(p, "preexec_close") == 0)
425 options[VOLOPT_PREEXEC].i_value = 1;
426 else if (strcasecmp(p, "root_preexec_close") == 0)
427 options[VOLOPT_ROOTPREEXEC].i_value = 1;
428 p = strtok(NULL, ",");
433 } else if (optionok(tmp, "dbpath:", val)) {
434 setoption(options, save, VOLOPT_DBPATH, val);
437 } else if (optionok(tmp, "umask:", val)) {
438 options[VOLOPT_UMASK].i_value = (int)strtol(val, (char **)NULL, 8);
439 } else if (optionok(tmp, "mapchars:",val)) {
440 setoption(options, save, VOLOPT_MAPCHARS, val);
442 } else if (optionok(tmp, "password:", val)) {
443 setoption(options, save, VOLOPT_PASSWORD, val);
447 /* this code allows forced uid/gid per volume settings */
448 } else if (optionok(tmp, "forceuid:", val)) {
449 setoption(options, save, VOLOPT_FORCEUID, val);
450 } else if (optionok(tmp, "forcegid:", val)) {
451 setoption(options, save, VOLOPT_FORCEGID, val);
453 #endif /* FORCE_UIDGID */
454 } else if (optionok(tmp, "root_preexec:", val)) {
455 setoption(options, save, VOLOPT_ROOTPREEXEC, val);
457 } else if (optionok(tmp, "preexec:", val)) {
458 setoption(options, save, VOLOPT_PREEXEC, val);
460 } else if (optionok(tmp, "root_postexec:", val)) {
461 setoption(options, save, VOLOPT_ROOTPOSTEXEC, val);
463 } else if (optionok(tmp, "postexec:", val)) {
464 setoption(options, save, VOLOPT_POSTEXEC, val);
467 /* ignore unknown options */
468 LOG(log_debug, logtype_afpd, "ignoring unknown volume option: %s", tmp);
473 /* ------------------------------- */
474 static int creatvol(AFPObj *obj, struct passwd *pwd,
475 char *path, char *name,
476 struct vol_option *options,
477 const int user /* user defined volume */
483 if ( name == NULL || *name == '\0' ) {
484 if ((name = strrchr( path, '/' )) == NULL) {
485 return -1; /* Obviously not a fully qualified path */
488 /* if you wish to share /, you need to specify a name. */
493 for ( volume = volumes; volume; volume = volume->v_next ) {
494 if ( strcasecmp( volume->v_name, name ) == 0 ) {
495 return -1; /* Won't be able to access it, anyway... */
499 vlen = strlen( name );
500 if ( vlen > AFPVOL_NAMELEN ) {
501 vlen = AFPVOL_NAMELEN;
502 name[AFPVOL_NAMELEN] = '\0';
505 if (!( volume = (struct vol *)calloc(1, sizeof( struct vol ))) ) {
506 LOG(log_error, logtype_afpd, "creatvol: malloc: %s", strerror(errno) );
509 if (! ( volume->v_name = (char *)malloc( vlen + 1 ) ) ) {
510 LOG(log_error, logtype_afpd, "creatvol: malloc: %s", strerror(errno) );
514 if (!( volume->v_path = (char *)malloc( strlen( path ) + 1 )) ) {
515 LOG(log_error, logtype_afpd, "creatvol: malloc: %s", strerror(errno) );
516 free(volume->v_name);
521 strcpy( volume->v_name, name);
522 strcpy( volume->v_path, path );
526 #endif /* __svr4__ */
527 volume->v_vid = lastvid++;
528 volume->v_lastdid = 17;
532 /* should we casefold? */
533 volume->v_casefold = options[VOLOPT_CASEFOLD].i_value;
535 /* shift in some flags */
536 volume->v_flags = options[VOLOPT_FLAGS].i_value;
538 /* read in the code pages */
539 if (options[VOLOPT_CODEPAGE].c_value)
540 codepage_read(volume, options[VOLOPT_CODEPAGE].c_value);
542 if (options[VOLOPT_PASSWORD].c_value)
543 volume->v_password = strdup(options[VOLOPT_PASSWORD].c_value);
545 if (options[VOLOPT_VETO].c_value)
546 volume->v_veto = strdup(options[VOLOPT_VETO].c_value);
549 if (options[VOLOPT_DBPATH].c_value)
550 volume->v_dbpath = volxlate(obj, NULL, MAXPATHLEN, options[VOLOPT_DBPATH].c_value, pwd, path);
553 if (options[VOLOPT_UMASK].i_value)
554 volume->v_umask = (mode_t)options[VOLOPT_UMASK].i_value;
557 if (options[VOLOPT_FORCEUID].c_value) {
558 volume->v_forceuid = strdup(options[VOLOPT_FORCEUID].c_value);
560 volume->v_forceuid = NULL; /* set as null so as to return 0 later on */
563 if (options[VOLOPT_FORCEGID].c_value) {
564 volume->v_forcegid = strdup(options[VOLOPT_FORCEGID].c_value);
566 volume->v_forcegid = NULL; /* set as null so as to return 0 later on */
570 if (options[VOLOPT_PREEXEC].c_value)
571 volume->v_preexec = volxlate(obj, NULL, MAXPATHLEN, options[VOLOPT_PREEXEC].c_value, pwd, path);
572 volume->v_preexec_close = options[VOLOPT_PREEXEC].i_value;
574 if (options[VOLOPT_POSTEXEC].c_value)
575 volume->v_postexec = volxlate(obj, NULL, MAXPATHLEN, options[VOLOPT_POSTEXEC].c_value, pwd, path);
577 if (options[VOLOPT_ROOTPREEXEC].c_value)
578 volume->v_root_preexec = volxlate(obj, NULL, MAXPATHLEN, options[VOLOPT_ROOTPREEXEC].c_value, pwd, path);
579 volume->v_root_preexec_close = options[VOLOPT_ROOTPREEXEC].i_value;
581 if (options[VOLOPT_ROOTPOSTEXEC].c_value)
582 volume->v_root_postexec = volxlate(obj, NULL, MAXPATHLEN, options[VOLOPT_ROOTPOSTEXEC].c_value, pwd, path);
586 volume->v_next = volumes;
591 /* ---------------- */
592 static char *myfgets( buf, size, fp )
601 while ((EOF != ( c = getc( fp )) ) && ( size > 0 )) {
602 if ( c == '\n' || c == '\r' ) {
620 /* check access list. this function wants something of the following
622 * @group,name,name2,@group2,name3
624 * a NULL argument allows everybody to have access.
625 * we return three things:
627 * 0: list exists, but name isn't in it
630 static int accessvol(args, name)
634 char buf[MAXPATHLEN + 1], *p;
640 strncpy(buf, args, sizeof(buf));
641 if ((p = strtok(buf, ",")) == NULL) /* nothing, return okay */
645 if (*p == '@') { /* it's a group */
646 if ((gr = getgrnam(p + 1)) && gmem(gr->gr_gid))
648 } else if (strcmp(p, name) == 0) /* it's a user name */
650 p = strtok(NULL, ",");
656 static void setextmap( ext, type, creator, user)
657 char *ext, *type, *creator;
663 if (extmap == NULL) {
664 if (( extmap = calloc(1, sizeof( struct extmap ))) == NULL ) {
665 LOG(log_error, logtype_afpd, "setextmap: calloc: %s", strerror(errno) );
670 for ( em = extmap, cnt = 0; em->em_ext; em++, cnt++) {
671 if ( (strdiacasecmp( em->em_ext, ext )) == 0 ) {
676 if ( em->em_ext == NULL ) {
677 if (!(extmap = realloc( extmap, sizeof( struct extmap ) * (cnt +2))) ) {
678 LOG(log_error, logtype_afpd, "setextmap: realloc: %s", strerror(errno) );
681 (extmap +cnt +1)->em_ext = NULL;
683 } else if ( !user ) {
689 if (!(em->em_ext = strdup( ext))) {
690 LOG(log_error, logtype_afpd, "setextmap: strdup: %s", strerror(errno) );
694 if ( *type == '\0' ) {
695 memcpy(em->em_type, "????", sizeof( em->em_type ));
697 memcpy(em->em_type, type, sizeof( em->em_type ));
699 if ( *creator == '\0' ) {
700 memcpy(em->em_creator, "UNIX", sizeof( em->em_creator ));
702 memcpy(em->em_creator, creator, sizeof( em->em_creator ));
706 /* -------------------------- */
707 static int extmap_cmp(const void *map1, const void *map2)
709 const struct extmap *em1 = map1;
710 const struct extmap *em2 = map2;
711 return strdiacasecmp(em1->em_ext, em2->em_ext);
714 static void sortextmap( void)
719 if ((em = extmap) == NULL) {
727 qsort(extmap, extmap_cnt, sizeof(struct extmap), extmap_cmp);
734 * Read a volume configuration file and add the volumes contained within to
735 * the global volume list. If p2 is non-NULL, the file that is opened is
738 * Lines that begin with # and blank lines are ignored.
739 * Volume lines are of the form:
740 * <unix path> [<volume name>] [allow:<user>,<@group>,...] \
741 * [codepage:<file>] [casefold:<num>]
742 * <extension> TYPE [CREATOR]
744 static int readvolfile(obj, p1, p2, user, pwent)
748 struct passwd *pwent;
751 char path[ MAXPATHLEN + 1], tmp[ MAXPATHLEN + 1],
752 volname[ AFPVOL_NAMELEN + 1 ], buf[ BUFSIZ ],
753 type[ 5 ], creator[ 5 ];
756 struct vol_option options[VOLOPT_NUM], save_options[VOLOPT_NUM];
768 if (NULL == ( fp = fopen( path, "r" )) ) {
772 memset(save_options, 0, sizeof(save_options));
773 while ( myfgets( buf, sizeof( buf ), fp ) != NULL ) {
774 initline( strlen( buf ), buf );
775 parseline( sizeof( path ) - 1, path );
782 /* change the default options for this file */
783 if (strncmp(path, VOLOPT_DEFAULT, VOLOPT_DEFAULT_LEN) == 0) {
785 for (i = 0; i < VOLOPT_NUM; i++) {
786 if (parseline( sizeof( path ) - VOLOPT_DEFAULT_LEN - 1,
787 path + VOLOPT_DEFAULT_LEN) < 0)
789 volset(save_options, NULL, tmp, sizeof(tmp) - 1,
790 obj->options.nlspath, path + VOLOPT_DEFAULT_LEN);
796 if (( p = strchr( path, '/' )) != NULL ) {
804 if ( u == NULL || *u == '\0' || ( pw = getpwnam( u )) == NULL ) {
807 strcpy( tmp, pw->pw_dir );
808 if ( p != NULL && *p != '\0' ) {
812 /* Tag a user's home directory with their umask. Note, this will
813 * be overwritten if the user actually specifies a umask: option
814 * for a '~' volume. */
815 save_options[VOLOPT_UMASK].i_value = obj->options.save_mask;
819 /* send path through variable substitution */
820 if (*path != '~') /* need to copy path to tmp */
823 pwent = getpwnam(obj->username);
824 volxlate(obj, path, sizeof(path) - 1, tmp, pwent, NULL);
826 /* this is sort of braindead. basically, i want to be
827 * able to specify things in any order, but i don't want to
828 * re-write everything.
830 * currently we have options:
838 * options:prodos,crlf,noadouble,ro...
843 * namemask:x,y,!z (not implemented yet)
845 memcpy(options, save_options, sizeof(options));
848 /* read in up to VOLOP_NUM possible options */
849 for (i = 0; i < VOLOPT_NUM; i++) {
850 if (parseline( sizeof( tmp ) - 1, tmp ) < 0)
853 volset(options, save_options, volname, sizeof(volname) - 1,obj->options.nlspath, tmp);
856 /* check allow/deny lists:
857 allow -> either no list (-1), or in list (1)
858 deny -> either no list (-1), or not in list (0) */
859 if (accessvol(options[VOLOPT_ALLOW].c_value, obj->username) &&
860 (accessvol(options[VOLOPT_DENY].c_value, obj->username) < 1)) {
862 /* handle read-only behaviour. semantics:
863 * 1) neither the rolist nor the rwlist exist -> rw
864 * 2) rolist exists -> ro if user is in it.
865 * 3) rwlist exists -> ro unless user is in it. */
866 if (((options[VOLOPT_FLAGS].i_value & AFPVOL_RO) == 0) &&
867 ((accessvol(options[VOLOPT_ROLIST].c_value,
868 obj->username) == 1) ||
869 !accessvol(options[VOLOPT_RWLIST].c_value,
871 options[VOLOPT_FLAGS].i_value |= AFPVOL_RO;
873 /* do variable substitution for volname */
874 volxlate(obj, tmp, sizeof(tmp) - 1, volname, pwent, path);
875 creatvol(obj, pwent, path, tmp, options, p2 != NULL);
877 volfree(options, save_options);
881 parseline( sizeof( type ) - 1, type );
882 parseline( sizeof( creator ) - 1, creator );
883 setextmap( path, type, creator, user);
890 volfree(save_options, NULL);
892 if ( fclose( fp ) != 0 ) {
893 LOG(log_error, logtype_afpd, "readvolfile: fclose: %s", strerror(errno) );
899 static void load_volumes(AFPObj *obj)
901 struct passwd *pwent = getpwnam(obj->username);
903 if ( (obj->options.flags & OPTION_USERVOLFIRST) == 0 ) {
904 readvolfile(obj, obj->options.systemvol, NULL, 0, pwent);
907 if ((*obj->username == '\0') || (obj->options.flags & OPTION_NOUSERVOL)) {
908 readvolfile(obj, obj->options.defaultvol, NULL, 1, pwent);
911 * Read user's AppleVolumes or .AppleVolumes file
912 * If neither are readable, read the default volumes file. if
913 * that doesn't work, create a user share.
915 if ( readvolfile(obj, pwent->pw_dir, "AppleVolumes", 1, pwent) < 0 &&
916 readvolfile(obj, pwent->pw_dir, ".AppleVolumes", 1, pwent) < 0 &&
917 readvolfile(obj, pwent->pw_dir, "applevolumes", 1, pwent) < 0 &&
918 readvolfile(obj, pwent->pw_dir, ".applevolumes", 1, pwent) < 0 &&
919 obj->options.defaultvol != NULL ) {
920 if (readvolfile(obj, obj->options.defaultvol, NULL, 1, pwent) < 0)
921 creatvol(obj, pwent, pwent->pw_dir, NULL, NULL, 1);
924 if ( obj->options.flags & OPTION_USERVOLFIRST ) {
925 readvolfile(obj, obj->options.systemvol, NULL, 0, pwent );
929 static int getvolspace( vol, bfree, btotal, xbfree, xbtotal, bsize )
931 u_int32_t *bfree, *btotal, *bsize;
932 VolSpace *xbfree, *xbtotal;
936 #ifndef NO_QUOTA_SUPPORT
937 VolSpace qfree, qtotal;
940 spaceflag = AFPVOL_GVSMASK & vol->v_flags;
941 /* report up to 2GB if afp version is < 2.2 (4GB if not) */
942 maxsize = (vol->v_flags & AFPVOL_A2VOL) ? 0x01fffe00 :
943 (((afp_version < 22) || (vol->v_flags & AFPVOL_LIMITSIZE))
944 ? 0x7fffffffL : 0xffffffffL);
947 if ( spaceflag == AFPVOL_NONE || spaceflag == AFPVOL_AFSGVS ) {
948 if ( afs_getvolspace( vol, xbfree, xbtotal, bsize ) == AFP_OK ) {
949 vol->v_flags = ( ~AFPVOL_GVSMASK & vol->v_flags ) | AFPVOL_AFSGVS;
950 goto getvolspace_done;
955 if (( rc = ustatfs_getvolspace( vol, xbfree, xbtotal,
956 bsize)) != AFP_OK ) {
960 #define min(a,b) ((a)<(b)?(a):(b))
961 #ifndef NO_QUOTA_SUPPORT
962 if ( spaceflag == AFPVOL_NONE || spaceflag == AFPVOL_UQUOTA ) {
963 if ( uquota_getvolspace( vol, &qfree, &qtotal, *bsize ) == AFP_OK ) {
964 vol->v_flags = ( ~AFPVOL_GVSMASK & vol->v_flags ) | AFPVOL_UQUOTA;
965 *xbfree = min(*xbfree, qfree);
966 *xbtotal = min( *xbtotal, qtotal);
967 goto getvolspace_done;
971 vol->v_flags = ( ~AFPVOL_GVSMASK & vol->v_flags ) | AFPVOL_USTATFS;
974 *bfree = min( *xbfree, maxsize);
975 *btotal = min( *xbtotal, maxsize);
979 static int getvolparams( bitmap, vol, st, buf, buflen )
987 int bit = 0, isad = 1;
990 u_int32_t bfree, btotal, bsize;
991 VolSpace xbfree, xbtotal; /* extended bytes */
992 char *data, *nameoff = NULL;
995 /* courtesy of jallison@whistle.com:
996 * For MacOS8.x support we need to create the
997 * .Parent file here if it doesn't exist. */
999 memset(&ad, 0, sizeof(ad));
1000 if ( ad_open( vol->v_path, vol_noadouble(vol) |
1001 ADFLAGS_HF|ADFLAGS_DIR, O_RDWR | O_CREAT,
1005 } else if (ad_get_HF_flags( &ad ) & O_CREAT) {
1006 slash = strrchr( vol->v_path, '/' );
1010 slash = vol->v_path;
1012 ad_setentrylen( &ad, ADEID_NAME, strlen( slash ));
1013 memcpy(ad_entry( &ad, ADEID_NAME ), slash,
1014 ad_getentrylen( &ad, ADEID_NAME ));
1015 ad_setdate(&ad, AD_DATE_CREATE | AD_DATE_UNIX, st->st_mtime);
1016 ad_flush(&ad, ADFLAGS_HF);
1019 if (( bitmap & ( (1<<VOLPBIT_BFREE)|(1<<VOLPBIT_BTOTAL) |
1020 (1<<VOLPBIT_XBFREE)|(1<<VOLPBIT_XBTOTAL) |
1021 (1<<VOLPBIT_BSIZE)) ) != 0 ) {
1022 if ( getvolspace( vol, &bfree, &btotal, &xbfree, &xbtotal,
1025 ad_close( &ad, ADFLAGS_HF );
1027 return( AFPERR_PARAM );
1032 while ( bitmap != 0 ) {
1033 while (( bitmap & 1 ) == 0 ) {
1042 if (0 == (vol->v_flags & AFPVOL_NOFILEID) && vol->v_db != NULL) {
1043 ashort = VOLPBIT_ATTR_FILEID;
1045 #endif /* CNID_DB */
1046 /* check for read-only.
1047 * NOTE: we don't actually set the read-only flag unless
1048 * it's passed in that way as it's possible to mount
1049 * a read-write filesystem under a read-only one. */
1050 if ((vol->v_flags & AFPVOL_RO) ||
1051 ((utime(vol->v_path, NULL) < 0) && (errno == EROFS))) {
1052 ashort |= VOLPBIT_ATTR_RO;
1054 ashort |= VOLPBIT_ATTR_CATSEARCH;
1055 if (afp_version >= 30) {
1056 ashort |= VOLPBIT_ATTR_UTF8;
1058 ashort = htons(ashort);
1059 memcpy(data, &ashort, sizeof( ashort ));
1060 data += sizeof( ashort );
1064 ashort = htons( AFPVOLSIG_DEFAULT );
1065 memcpy(data, &ashort, sizeof( ashort ));
1066 data += sizeof( ashort );
1069 case VOLPBIT_CDATE :
1070 if (!isad || (ad_getdate(&ad, AD_DATE_CREATE, &aint) < 0))
1071 aint = AD_DATE_FROM_UNIX(st->st_mtime);
1072 memcpy(data, &aint, sizeof( aint ));
1073 data += sizeof( aint );
1076 case VOLPBIT_MDATE :
1077 if ( st->st_mtime > vol->v_time ) {
1078 vol->v_time = st->st_mtime;
1079 aint = AD_DATE_FROM_UNIX(st->st_mtime);
1081 aint = AD_DATE_FROM_UNIX(vol->v_time);
1083 memcpy(data, &aint, sizeof( aint ));
1084 data += sizeof( aint );
1087 case VOLPBIT_BDATE :
1088 if (!isad || (ad_getdate(&ad, AD_DATE_BACKUP, &aint) < 0))
1089 aint = AD_DATE_START;
1090 memcpy(data, &aint, sizeof( aint ));
1091 data += sizeof( aint );
1095 memcpy(data, &vol->v_vid, sizeof( vol->v_vid ));
1096 data += sizeof( vol->v_vid );
1099 case VOLPBIT_BFREE :
1100 bfree = htonl( bfree );
1101 memcpy(data, &bfree, sizeof( bfree ));
1102 data += sizeof( bfree );
1105 case VOLPBIT_BTOTAL :
1106 btotal = htonl( btotal );
1107 memcpy(data, &btotal, sizeof( btotal ));
1108 data += sizeof( btotal );
1111 #ifndef NO_LARGE_VOL_SUPPORT
1112 case VOLPBIT_XBFREE :
1113 xbfree = hton64( xbfree );
1114 #if defined(__GNUC__) && defined(HAVE_GCC_MEMCPY_BUG)
1115 bcopy(&xbfree, data, sizeof(xbfree));
1116 #else /* __GNUC__ && HAVE_GCC_MEMCPY_BUG */
1117 memcpy(data, &xbfree, sizeof( xbfree ));
1118 #endif /* __GNUC__ && HAVE_GCC_MEMCPY_BUG */
1119 data += sizeof( xbfree );
1122 case VOLPBIT_XBTOTAL :
1123 xbtotal = hton64( xbtotal );
1124 #if defined(__GNUC__) && defined(HAVE_GCC_MEMCPY_BUG)
1125 bcopy(&xbtotal, data, sizeof(xbtotal));
1126 #else /* __GNUC__ && HAVE_GCC_MEMCPY_BUG */
1127 memcpy(data, &xbtotal, sizeof( xbtotal ));
1128 #endif /* __GNUC__ && HAVE_GCC_MEMCPY_BUG */
1129 data += sizeof( xbfree );
1131 #endif /* ! NO_LARGE_VOL_SUPPORT */
1135 data += sizeof( u_int16_t );
1138 case VOLPBIT_BSIZE: /* block size */
1139 bsize = htonl(bsize);
1140 memcpy(data, &bsize, sizeof(bsize));
1141 data += sizeof(bsize);
1146 ad_close( &ad, ADFLAGS_HF );
1148 return( AFPERR_BITMAP );
1154 ashort = htons( data - buf );
1155 memcpy(nameoff, &ashort, sizeof( ashort ));
1156 aint = strlen( vol->v_name );
1158 memcpy(data, vol->v_name, aint );
1162 ad_close( &ad, ADFLAGS_HF );
1164 *buflen = data - buf;
1168 /* ------------------------- */
1169 int afp_getsrvrparms(obj, ibuf, ibuflen, rbuf, rbuflen )
1172 int ibuflen, *rbuflen;
1185 for ( vcnt = 0, volume = volumes; volume; volume = volume->v_next ) {
1186 if ( stat( volume->v_path, &st ) < 0 ) {
1187 LOG(log_info, logtype_afpd, "afp_getsrvrparms: stat %s: %s",
1188 volume->v_path, strerror(errno) );
1189 continue; /* can't access directory */
1191 if (!S_ISDIR(st.st_mode)) {
1192 continue; /* not a dir */
1195 /* set password bit if there's a volume password */
1196 *data = (volume->v_password) ? AFPSRVR_PASSWD : 0;
1198 /* Apple 2 clients running ProDOS-8 expect one volume to have
1199 bit 0 of this byte set. They will not recognize anything
1200 on the server unless this is the case. I have not
1201 completely worked this out, but it's related to booting
1202 from the server. Support for that function is a ways
1203 off.. <shirsch@ibm.net> */
1204 *data++ |= (volume->v_flags & AFPVOL_A2VOL) ? AFPSRVR_CONFIGINFO : 0;
1205 len = strlen( volume->v_name );
1207 memcpy(data, volume->v_name, len );
1212 *rbuflen = data - rbuf;
1214 if ( gettimeofday( &tv, 0 ) < 0 ) {
1215 LOG(log_error, logtype_afpd, "afp_getsrvrparms: gettimeofday: %s", strerror(errno) );
1217 return AFPERR_PARAM;
1219 tv.tv_sec = AD_DATE_FROM_UNIX(tv.tv_sec);
1220 memcpy(data, &tv.tv_sec, sizeof( u_int32_t));
1221 data += sizeof( u_int32_t);
1226 /* -------------------------
1227 * we are the user here
1229 int afp_openvol(obj, ibuf, ibuflen, rbuf, rbuflen )
1232 int ibuflen, *rbuflen;
1240 #endif /* CNID_DB */
1243 int len, ret, buflen;
1247 memcpy(&bitmap, ibuf, sizeof( bitmap ));
1248 bitmap = ntohs( bitmap );
1249 ibuf += sizeof( bitmap );
1250 if (( bitmap & (1<<VOLPBIT_VID)) == 0 ) {
1251 ret = AFPERR_BITMAP;
1255 len = (unsigned char)*ibuf++;
1256 volname = obj->oldtmp;
1257 memcpy(volname, ibuf, len );
1258 *(volname + len) = '\0';
1260 if ((len + 1) & 1) /* pad to an even boundary */
1266 for ( volume = volumes; volume; volume = volume->v_next ) {
1267 if ( strcasecmp( volname, volume->v_name ) == 0 ) {
1272 if ( volume == NULL ) {
1277 /* check for a volume password */
1278 if (volume->v_password && strncmp(ibuf, volume->v_password, VOLPASSLEN)) {
1279 ret = AFPERR_ACCESS;
1284 if (afp_version >= 30) {
1285 volume->max_filename = 255;
1288 volume->max_filename = MACFILELEN;
1290 if (( volume->v_flags & AFPVOL_OPEN ) == 0 ) {
1291 /* FIXME unix name != mac name */
1292 if ((dir = dirnew(volume->v_name, volume->v_name) ) == NULL) {
1293 LOG(log_error, logtype_afpd, "afp_openvol: malloc: %s", strerror(errno) );
1297 dir->d_did = DIRDID_ROOT;
1298 dir->d_color = DIRTREE_COLOR_BLACK; /* root node is black */
1299 volume->v_dir = volume->v_root = dir;
1300 volume->v_flags |= AFPVOL_OPEN;
1302 volume->v_db = NULL;
1305 if (volume->v_root_preexec) {
1306 if ((ret = afprun(1, volume->v_root_preexec, NULL)) && volume->v_root_preexec_close) {
1307 LOG(log_error, logtype_afpd, "afp_openvol: root preexec : %d", ret );
1312 if (volume->v_preexec) {
1313 if ((ret = afprun(0, volume->v_preexec, NULL)) && volume->v_preexec_close) {
1314 LOG(log_error, logtype_afpd, "afp_openvol: preexec : %d", ret );
1324 set_uidgid ( volume );
1325 #endif /* FORCE_UIDGID */
1327 if ( stat( volume->v_path, &st ) < 0 ) {
1332 if ( chdir( volume->v_path ) < 0 ) {
1336 curdir = volume->v_dir;
1340 if (volume->v_dbpath)
1341 volume->v_db = cnid_open (volume->v_dbpath, volume->v_umask);
1342 if (volume->v_db == NULL)
1343 volume->v_db = cnid_open (volume->v_path, volume->v_umask);
1344 if (volume->v_db == NULL) {
1346 * - mount the volume readonly
1348 * - read/write with other scheme
1352 #endif /* CNID_DB */
1354 buflen = *rbuflen - sizeof( bitmap );
1355 if (( ret = getvolparams( bitmap, volume, &st,
1356 rbuf + sizeof(bitmap), &buflen )) != AFP_OK ) {
1360 volume->v_utf8toucs2 = (iconv_t)(-1);
1361 volume->v_ucs2toutf8 = (iconv_t)(-1);
1362 volume->v_mactoutf8 = (iconv_t)(-1);
1363 volume->v_ucs2tomac = (iconv_t)(-1);
1365 if (vol_utf8(volume)) {
1366 if ((iconv_t)(-1) == (volume->v_utf8toucs2 = iconv_open("UCS-2LE", "UTF-8"))) {
1367 LOG(log_error, logtype_afpd, "openvol: no UTF8 to UCS-2LE");
1370 if ((iconv_t)(-1) == (volume->v_ucs2toutf8 = iconv_open("UTF-8", "UCS-2LE"))) {
1371 LOG(log_error, logtype_afpd, "openvol: no UCS-2LE to UTF-8");
1372 goto openvol_err_iconv;
1374 if ((iconv_t)(-1) == (volume->v_mactoutf8 = iconv_open("UTF-8", "MAC"))) {
1375 LOG(log_error, logtype_afpd, "openvol: no MAC to UTF-8");
1376 goto openvol_err_iconv;
1378 if ((iconv_t)(-1) == (volume->v_ucs2tomac = iconv_open("MAC", "UCS-2LE"))) {
1379 LOG(log_error, logtype_afpd, "openvol: no UCS-2LE to MAC");
1380 goto openvol_err_iconv;
1384 *rbuflen = buflen + sizeof( bitmap );
1385 bitmap = htons( bitmap );
1386 memcpy(rbuf, &bitmap, sizeof( bitmap ));
1390 * If you mount a volume twice, the second time the trash appears on
1391 * the desk-top. That's because the Mac remembers the DID for the
1392 * trash (even for volumes in different zones, on different servers).
1393 * Just so this works better, we prime the DID cache with the trash,
1394 * fixing the trash at DID 17.
1397 cname( volume, volume->v_dir, &p );
1398 #endif /* CNID_DB */
1403 if (volume->v_utf8toucs2 != (iconv_t)(-1))
1404 iconv_close(volume->v_utf8toucs2);
1405 if (volume->v_ucs2toutf8 != (iconv_t)(-1))
1406 iconv_close(volume->v_ucs2toutf8);
1407 if (volume->v_mactoutf8 != (iconv_t)(-1))
1408 iconv_close(volume->v_mactoutf8);
1409 if (volume->v_ucs2tomac != (iconv_t)(-1))
1410 iconv_close(volume->v_ucs2tomac);
1414 if (opened && volume->v_db != NULL) {
1415 cnid_close(volume->v_db);
1416 volume->v_db = NULL;
1423 /* ------------------------- */
1424 static void closevol(struct vol *vol)
1429 dirfree( vol->v_root );
1432 cnid_close(vol->v_db);
1434 #endif /* CNID_DB */
1435 if (vol->v_postexec) {
1436 afprun(0, vol->v_postexec, NULL);
1438 if (vol->v_root_postexec) {
1439 afprun(1, vol->v_root_postexec, NULL);
1443 /* ------------------------- */
1444 void close_all_vol(void)
1448 for ( ovol = volumes; ovol; ovol = ovol->v_next ) {
1449 if ( ovol->v_flags & AFPVOL_OPEN ) {
1450 ovol->v_flags &= ~AFPVOL_OPEN;
1456 /* ------------------------- */
1457 int afp_closevol(obj, ibuf, ibuflen, rbuf, rbuflen )
1460 int ibuflen, *rbuflen;
1462 struct vol *vol, *ovol;
1467 memcpy(&vid, ibuf, sizeof( vid ));
1468 if (NULL == ( vol = getvolbyvid( vid )) ) {
1469 return( AFPERR_PARAM );
1472 vol->v_flags &= ~AFPVOL_OPEN;
1473 for ( ovol = volumes; ovol; ovol = ovol->v_next ) {
1474 if ( ovol->v_flags & AFPVOL_OPEN ) {
1478 if ( ovol != NULL ) {
1479 /* Even if chdir fails, we can't say afp_closevol fails. */
1480 if ( chdir( ovol->v_path ) == 0 ) {
1481 curdir = ovol->v_dir;
1488 /* ------------------------- */
1489 struct vol *getvolbyvid(const u_int16_t vid )
1493 for ( vol = volumes; vol; vol = vol->v_next ) {
1494 if ( vid == vol->v_vid ) {
1498 if ( vol == NULL || ( vol->v_flags & AFPVOL_OPEN ) == 0 ) {
1504 #endif /* FORCE_UIDGID */
1509 /* ------------------------ */
1510 static int ext_cmp_key(const void *key, const void *obj)
1512 const char *p = key;
1513 const struct extmap *em = obj;
1514 return strdiacasecmp(p, em->em_ext);
1516 struct extmap *getextmap(const char *path)
1521 if (NULL == ( p = strrchr( path, '.' )) ) {
1522 return( defextmap );
1525 if (!*p || !extmap_cnt) {
1526 return( defextmap );
1528 em = bsearch(p, extmap, extmap_cnt, sizeof(struct extmap), ext_cmp_key);
1532 return( defextmap );
1536 /* ------------------------- */
1537 struct extmap *getdefextmap(void)
1539 return( defextmap );
1542 /* --------------------------
1543 poll if a volume is changed by other processes.
1545 int pollvoltime(obj)
1552 if (!(afp_version > 21 && obj->options.server_notif))
1555 if ( gettimeofday( &tv, 0 ) < 0 )
1558 for ( vol = volumes; vol; vol = vol->v_next ) {
1559 if ( (vol->v_flags & AFPVOL_OPEN) && vol->v_time + 30 < tv.tv_sec) {
1560 if ( !stat( vol->v_path, &st ) && vol->v_time != st.st_mtime ) {
1561 vol->v_time = st.st_mtime;
1562 if (!obj->attention(obj->handle, AFPATTN_NOTIFY | AFPATTN_VOLCHANGED))
1571 /* ------------------------- */
1572 void setvoltime(obj, vol )
1578 /* just looking at vol->v_time is broken seriously since updates
1579 * from other users afpd processes never are seen.
1580 * This is not the most elegant solution (a shared memory between
1581 * the afpd processes would come closer)
1584 if ( gettimeofday( &tv, 0 ) < 0 ) {
1585 LOG(log_error, logtype_afpd, "setvoltime: gettimeofday: %s", strerror(errno) );
1588 if( utime( vol->v_path, NULL ) < 0 ) {
1589 /* write of time failed ... probably a read only filesys,
1590 * where no other users can interfere, so there's no issue here
1594 /* a little granularity */
1595 if (vol->v_time < tv.tv_sec) {
1596 vol->v_time = tv.tv_sec;
1597 if (afp_version > 21 && obj->options.server_notif) {
1598 obj->attention(obj->handle, AFPATTN_NOTIFY | AFPATTN_VOLCHANGED);
1603 /* ------------------------- */
1604 int afp_getvolparams(obj, ibuf, ibuflen, rbuf, rbuflen )
1607 int ibuflen, *rbuflen;
1612 u_int16_t vid, bitmap;
1615 memcpy(&vid, ibuf, sizeof( vid ));
1616 ibuf += sizeof( vid );
1617 memcpy(&bitmap, ibuf, sizeof( bitmap ));
1618 bitmap = ntohs( bitmap );
1620 if (NULL == ( vol = getvolbyvid( vid )) ) {
1622 return( AFPERR_PARAM );
1625 if ( stat( vol->v_path, &st ) < 0 ) {
1627 return( AFPERR_PARAM );
1630 buflen = *rbuflen - sizeof( bitmap );
1631 if (( ret = getvolparams( bitmap, vol, &st,
1632 rbuf + sizeof( bitmap ), &buflen )) != AFP_OK ) {
1636 *rbuflen = buflen + sizeof( bitmap );
1637 bitmap = htons( bitmap );
1638 memcpy(rbuf, &bitmap, sizeof( bitmap ));
1642 /* ------------------------- */
1643 int afp_setvolparams(obj, ibuf, ibuflen, rbuf, rbuflen )
1646 int ibuflen, *rbuflen;
1650 u_int16_t vid, bitmap;
1656 memcpy(&vid, ibuf, sizeof( vid ));
1657 ibuf += sizeof( vid );
1658 memcpy(&bitmap, ibuf, sizeof( bitmap ));
1659 bitmap = ntohs( bitmap );
1660 ibuf += sizeof(bitmap);
1662 if (( vol = getvolbyvid( vid )) == NULL ) {
1663 return( AFPERR_PARAM );
1666 if (vol->v_flags & AFPVOL_RO)
1667 return AFPERR_VLOCK;
1669 /* we can only set the backup date. */
1670 if (bitmap != (1 << VOLPBIT_BDATE))
1671 return AFPERR_BITMAP;
1673 memset(&ad, 0, sizeof(ad));
1674 if ( ad_open( vol->v_path, ADFLAGS_HF|ADFLAGS_DIR, O_RDWR,
1677 return AFPERR_VLOCK;
1679 return AFPERR_ACCESS;
1682 memcpy(&aint, ibuf, sizeof(aint));
1683 ad_setdate(&ad, AD_DATE_BACKUP, aint);
1684 ad_flush(&ad, ADFLAGS_HF);
1685 ad_close(&ad, ADFLAGS_HF);
1689 /* ------------------------- */
1690 int wincheck(const struct vol *vol, const char *path)
1694 if (!(vol->v_flags & AFPVOL_MSWINDOWS))
1697 /* empty paths are not allowed */
1698 if ((len = strlen(path)) == 0)
1701 /* leading or trailing whitespaces are not allowed, carriage returns
1702 * and probably other whitespace is okay, tabs are not allowed
1704 if ((path[0] == ' ') || (path[len-1] == ' '))
1707 /* certain characters are not allowed */
1708 if (strpbrk(path, MSWINDOWS_BADCHARS))
1711 /* everything else is okay */