--- autofs-4.1.4/include/automount.h.orig 2005-04-13 20:54:52.749944144 -0400 +++ autofs-4.1.4/include/automount.h 2005-04-13 20:56:21.850398816 -0400 @@ -282,6 +282,14 @@ int is_mounted(const char *table, const int has_fstab_option(const char *path, const char *opt); int allow_owner_mount(const char *); +/* nsswitch parsing */ +#define MAPTYPE_FILE 1 +#define MAPTYPE_PROGRAM 2 + +char *get_nsswitch_map(const char *); +int isfilemap(const char *); +int isypmap(const char *); + /* log notification */ extern int do_verbose; extern int do_debug; --- autofs-4.1.4/lib/nsswitch.c.orig 2005-04-13 20:54:25.405101192 -0400 +++ autofs-4.1.4/lib/nsswitch.c 2005-04-13 20:54:07.827773352 -0400 @@ -0,0 +1,154 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "automount.h" + +#define MODPREFIX "nsswitch: " + +/* + * Function which takes in a partial map name (ie. auto.misc), parses the + * nsswitch.conf file and returns a valid map name (ie. yp:auto.misc or + * file:/etc/auto.misc + */ +char *get_nsswitch_map(const char *loc) +{ + char buf[1024]; + char *ordering; + const char *automount_str = "automount:"; + char *comment = NULL; + FILE *nsswitch; + int found_automount = 0; + char *retval = NULL; + int retsize = 0; + + debug(MODPREFIX "called nsswitch with: '%s'", loc); + nsswitch = fopen(_PATH_NSSWITCH_CONF, "r"); + if (!nsswitch) { + error(MODPREFIX "Unable to open %s", _PATH_NSSWITCH_CONF); + return NULL; + } + + while ((ordering = fgets((char *)buf, sizeof(buf), nsswitch))) { + if ((comment = strchr(ordering,'#'))) + *comment = '\0'; + while (isspace(*ordering)) ordering++; + if (!strncmp(ordering, automount_str, sizeof(automount_str))) { + ordering += strlen(automount_str); + found_automount = 1; + break; + } + } + + fclose(nsswitch); + + if (!found_automount) + return NULL; + + while (*ordering != '\0') { + while (isspace(*ordering)) ordering++; + if (!strncmp(ordering, "files", 5)) { + switch (isfilemap(loc)) { + case MAPTYPE_FILE: + retsize = strlen(loc) + 11; + retval = malloc(retsize); + if (!retval) + return NULL; + snprintf(retval, retsize, + "file:/etc/%s", loc); + return retval; + case MAPTYPE_PROGRAM: + retsize = strlen(loc) + 14; + retval = malloc(retsize); + if (!retval) + return NULL; + snprintf(retval, retsize, + "program:/etc/%s", loc); + return retval; + default: // filemap doesn't exist + break; + } + + } else if ((!strncmp(ordering, "yp", 2) || + !strncmp(ordering,"nis", 3)) && + isypmap(loc)) { + retsize = strlen(loc) + 4; + retval = malloc(retsize); + snprintf(retval, retsize, "yp:%s", loc); + return retval; + } + while (!isspace(*ordering) && (*ordering != '\0')) ordering++; + } + error(MODPREFIX "couldn't find map"); + return retval; +} + +/* + * Function takes in a filename and tests if it exists in "/etc/" + * Returns: MAPTYPE_FILE if it is not executable, MAPTYPE_PROGRAM if it + * is executable and 0 if it doesn't exists or has incorrect permissions. + */ + +int isfilemap(const char *loc) +{ + struct stat st; + int ret = 0; + char *realfilemap; + + realfilemap = malloc(strlen(loc) + 6); /* '/etc/' + '\0' */ + if (!realfilemap) { + crit(MODPREFIX "malloc failed."); + return 0; + } + + snprintf(realfilemap, strlen(loc) + 6, "/etc/%s", loc); + + ret = stat(realfilemap, &st); + free (realfilemap); + + if (!ret) { + if (st.st_uid != 0) { + error(MODPREFIX "file /etc/%s exists but is not" + " owned by root.", loc); + return 0; + } else if (st.st_mode & S_IRUSR) { + if (st.st_mode & S_IXUSR) + return MAPTYPE_PROGRAM; + else + return MAPTYPE_FILE; + } + } + return 0; +} + +/* + * Function takes in a yp map name and returns + * 1 if it exists or 0 if it doesn't. + * + * Some of this code borrowed from ypcat + */ + +int isypmap(const char *loc) +{ + int err; + char *domainname; + int order; + + if ((err = yp_get_default_domain(&domainname)) != YPERR_SUCCESS) { + error (MODPREFIX "unable to get default yp domain"); + return 0; + } + if ((err = yp_order(domainname, loc, &order)) != YPERR_SUCCESS) { + error (MODPREFIX "unable to find map, %s in domain, %s", + loc, domainname); + return 0; + } + + return 1; +} --- autofs-4.1.4/lib/Makefile.orig 2005-04-13 20:55:00.260802320 -0400 +++ autofs-4.1.4/lib/Makefile 2005-04-13 20:56:21.850398816 -0400 @@ -9,10 +9,10 @@ include ../Makefile.rules RPCGEN = /usr/bin/rpcgen RANLIB = /usr/bin/ranlib -SRCS = cache.c listmount.c cat_path.c rpc_subs.c mounts.c lock.c +SRCS = cache.c listmount.c cat_path.c rpc_subs.c mounts.c lock.c nsswitch.c RPCS = mount.h mount_clnt.c mount_xdr.c OBJS = cache.o mount_clnt.o mount_xdr.o listmount.o \ - cat_path.o rpc_subs.o mounts.o lock.o + cat_path.o rpc_subs.o mounts.o lock.o nsswitch.o LIB = autofs.a --- autofs-4.1.4/modules/parse_sun.c.orig 2005-04-13 20:55:18.508028320 -0400 +++ autofs-4.1.4/modules/parse_sun.c 2005-04-13 20:56:21.852398512 -0400 @@ -566,6 +566,8 @@ static int sun_mount(const char *root, c int rv; char *mountpoint; char *what; + char *nsswitch_map; + int newmaplen = 0; if (*options == '\0') options = NULL; @@ -651,25 +653,21 @@ static int sun_mount(const char *root, c memcpy(what, loc, loclen); what[loclen] = '\0'; + /* + * If we have an autofs map that doesn't contain a ':' then we need + * to detect what type of map it is. + */ if (!strcmp(fstype, "autofs") && strchr(loc, ':') == NULL) { - char mtype[7]; - int mtype_len; - - if (loc[0] == '/') { - mtype_len = 5; - if (loc[1] == '/') - strcpy(mtype, "ldap:"); - else - strcpy(mtype, "file:"); - } else { - mtype_len = 3; - strcpy(mtype, "yp:"); + nsswitch_map = get_nsswitch_map(loc); + if (!nsswitch_map) { + error(MODPREFIX "unable to find map %s",loc); + return 1; } - - what = alloca(loclen + mtype_len + 1); - memcpy(what, mtype, mtype_len); - memcpy(what + mtype_len, loc, loclen); - what[loclen + mtype_len] = '\0'; + newmaplen = strlen(nsswitch_map); + what = alloca(newmaplen + 1); + memcpy(what, nsswitch_map, newmaplen); + what[newmaplen] = '\0'; + free (nsswitch_map); } else { what = alloca(loclen + 1); memcpy(what, loc, loclen); --- autofs-4.1.4/modules/Makefile.orig 2005-04-13 20:55:31.997977536 -0400 +++ autofs-4.1.4/modules/Makefile 2005-04-13 20:56:21.851398664 -0400 @@ -86,3 +86,7 @@ lookup_ldap.so: lookup_ldap.c $(CC) $(SOLDFLAGS) $(CFLAGS) $(LDAP_FLAGS) -o lookup_ldap.so \ lookup_ldap.c $(AUTOFS_LIB) $(LIBLDAP) $(STRIP) lookup_ldap.so + +parse_sun.so: parse_sun.c + $(CC) $(SOLDFLAGS) $(CFLAGS) -o parse_sun.so parse_sun.c $(AUTOFS_LIB) $(LIBNSL) + $(STRIP) parse_sun.so