Skip to contentSkip to conversation

implement included map support

PATCH In review Jeff Moyer 2 participants 4 messages Nov 9, 2006 – Nov 10, 2006

Subsystems (2)
lore
Share & tools
lore

Jeff Moyer

author
#0 lore raw

PATCH 1/1 implement included map support

Hi, Ian, list, (again, sorry if this is a dup)

Here is an implementation of included map support for autofs v4. This supports included maps in both the master map, and regular direct or indirect file maps.

Because I dread writing bash code, I implemented the included map checking for the master map in C. We basically just call into the daemon with a bogus mount point, asking for it to dump out all of the maps. This works well for 2 reasons: 1) it's not bash, and 2) it re-uses the code that the daemon will use to read the included maps anyway.

Review would be greatly appreciated. I tested this in my environment by creating a number of included maps, and modifying /etc/nsswitch.conf to ensure that it works as expected for file and NIS maps.

-Jeff

daemon/Makefile +1 -1
index 4cf1907..7789c79 100644
@@ -13,7 +13,7 @@ version := $(shell cat ../.version)
 
 CFLAGS += -rdynamic $(DAEMON_CFLAGS) -DAUTOFS_LIB_DIR=\"$(autofslibdir)\" -DVERSION_STRING=\"$(version)\" -I../include
 LDFLAGS += -rdynamic
-LIBS = -ldl
+LIBS = -ldl -lldap
 
 all: automount
 
daemon/automount.c +22 -2
index eb0cdd3..3c42c8a 100644
@@ -82,6 +82,7 @@ struct daemon_status_msg {
 
 int kproto_version;		/* Kernel protocol version used */
 int kproto_sub_version = 0;	/* Kernel protocol version used */
+int dumpmap = 0;		/* cmdline arg to dump map contents */
 
 static int submount = 0;
 
@@ -99,6 +100,10 @@ #define AUTOFS_SYSLOG_CONTEXT {-1, 0, 0,
 
 volatile struct pending_mount *junk_mounts = NULL;
 
+/* this has to go in the automounter proper, so that each shared library
+ * doesn't get its own copy */
+struct mapent_cache *mapent_hash[HASHSIZE];
+
 #define CHECK_RATIO     4	/* exp_runfreq = exp_timeout/CHECK_RATIO */
 #define DEFAULT_GHOST_MODE	0
 
@@ -1848,6 +1853,7 @@ int main(int argc, char *argv[])
 		{"version", 0, 0, 'V'},
 		{"ghost", 0, 0, 'g'},
 		{"submount", 0, &submount, 1},
+		{"dumpmap", 0, 0, 'D'},
 		{0, 0, 0, 0}
 	};
 
@@ -1860,7 +1866,7 @@ int main(int argc, char *argv[])
 	ap.dir_created = 0; /* We haven't created the main directory yet */
 
 	opterr = 0;
-	while ((opt = getopt_long(argc, argv, "+hp:t:vdVg", long_options, NULL)) != EOF) {
+	while ((opt = getopt_long(argc, argv, "+hp:t:vdVgD", long_options, NULL)) != EOF) {
 		switch (opt) {
 		case 'h':
 			usage();
@@ -1890,6 +1896,9 @@ int main(int argc, char *argv[])
 			ap.ghost = LKP_GHOST;
 			break;
 
+		case 'D':
+			dumpmap = 1;
+			break;
 		case '?':
 		case ':':
 			printf("%s: Ambiguous or unknown options\n", program);
@@ -1911,7 +1920,8 @@ int main(int argc, char *argv[])
 		exit(1);
 	}
 
-	become_daemon();
+	if (!dumpmap)
+		become_daemon();
 
 	path = argv[0];
 	map = argv[1];
@@ -1942,6 +1952,16 @@ #endif
 		cleanup_exit(path, 1);
 	}
 
+	if (dumpmap) {
+		int ret;
+		openlog("automount", LOG_PID, LOG_DAEMON);
+		ret = ap.lookup->lookup_ghost(ap.path, ap.ghost,
+					      0, ap.lookup->context);
+		if (ret & LKP_FAIL)
+			exit(ret);
+		exit(0);
+	}
+
 	if (!strncmp(path, "/-", 2)) {
 		supervisor(path);
 	} else {
include/automount.h +9 -6
index d256b3e..14ec07b 100644
@@ -161,6 +161,9 @@ typedef int (*lookup_init_t) (const char
 typedef int (*lookup_ghost_t) (const char *, int, time_t, void *);
 typedef int (*lookup_mount_t) (const char *, const char *, int, void *);
 typedef int (*lookup_done_t) (void *);
+/* the following two are used by the included map (+mapname) code */
+typedef int (*lookup_one_t) (const char *, const char *, const char *, int);
+typedef int (*lookup_readmap_t) (const char *, const char *, time_t);
 
 struct lookup_mod {
 	lookup_init_t lookup_init;
@@ -241,6 +244,8 @@ struct mapent_cache {
 	char *mapent;
 	time_t age;
 };
+#define HASHSIZE      27
+extern struct mapent_cache *mapent_hash[];
 
 void cache_init(void);
 struct mapent_cache *cache_lookup(const char *key);
@@ -294,17 +299,15 @@ int has_fstab_option(const char *path, c
 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 *);
+char *get_nsswitch_map(const char *, char *);
 
 /* log notification */
 extern int do_verbose;
 extern int do_debug;
 
+/* command line option to print out included map contents */
+extern int dumpmap;
+
 #define info(msg, args...) 		\
 if (do_verbose || do_debug) 		\
 	syslog(LOG_INFO, msg, ##args);
lib/Makefile +7 -2
index 92931b0..a35b208 100644
@@ -16,12 +16,13 @@ OBJS = cache.o mount_clnt.o mount_xdr.o 
 	cat_path.o rpc_subs.o mounts.o lock.o syslog.o vsprintf.o nsswitch.o
 
 LIB = autofs.a
+NSSWITCH = nsswitch
 
 CFLAGS += -I../include -fPIC -D_GNU_SOURCE -DHAVE_TCP_WRAPPER -DNFS3_SUPPORTED
 
 .PHONY: all install clean
 
-all: autofs.a
+all: autofs.a nsswitch
 
 autofs.a: $(OBJS)
 	rm -f $(LIB)
@@ -49,8 +50,12 @@ listmount.o: listmount.c
 	$(CC) $(CFLAGS) -o listmount.o -c listmount.c
 	$(STRIP) listmount.o
 
+nsswitch: nsswitch.c
+	$(CC) $(CFLAGS) -DSTANDALONE -o nsswitch nsswitch.c -lnsl -lldap
+
 install: all
+	install -c nsswitch -m 755 $(INSTALLROOT)$(autofslibdir)
 
 clean:
-	rm -f $(LIB) $(RPCS) $(OBJS) *~
+	rm -f $(LIB) $(RPCS) $(OBJS) $(NSSWITCH) *~
 
lib/cache.c +10 -4
index e49edf0..0f71fe2 100644
@@ -33,8 +33,6 @@ #include "automount.h"
 extern int kproto_version;	/* Kernel protocol major version */
 extern int kproto_sub_version;	/* Kernel protocol minor version */
 
-#define HASHSIZE      27
-
 struct ghost_context {
 	const char *root;
 	char *mapname;
@@ -43,8 +41,6 @@ struct ghost_context {
 	char mapent[MAPENT_MAX_LEN + 1];
 };
 
-static struct mapent_cache *mapent_hash[HASHSIZE];
-
 static unsigned long ent_check(struct ghost_context *gc, char **key, int ghost);
 
 static char *cache_fullpath(const char *root, const char *key)
@@ -169,6 +165,11 @@ int cache_add(const char *root, const ch
 	char *pkey, *pent;
 	unsigned int hashval = hash(key);
 
+	if (dumpmap) {
+		fprintf(stdout, "%s %s\n", key, mapent);
+		return CHE_OK;
+	}
+
 	me = (struct mapent_cache *) malloc(sizeof(struct mapent_cache));
 	if (!me)
 		return CHE_FAIL;
@@ -221,6 +222,11 @@ int cache_update(const char *root, const
 	char *pent;
 	int ret = CHE_OK;
 
+	if (dumpmap) {
+		fprintf(stdout, "%s %s\n", key, mapent);
+		return CHE_OK;
+	}
+
 	for (s = mapent_hash[hash(key)]; s != NULL; s = s->next)
 		if (strcmp(key, s->key) == 0)
 			me = s;
lib/nsswitch.c +262 -42

376 lines not on this page · raw message

modules/Makefile +4 -0
index 1e5bece..f87721a 100644
@@ -68,6 +68,10 @@ endif
 #
 # Ad hoc compilation rules for modules which need auxilliary libraries
 #
+lookup_file.so: lookup_file.c
+	$(CC) $(SOLDFLAGS) $(CFLAGS) -o lookup_file.so lookup_file.c $(AUTOFS_LIB) $(LIBNSL)
+	$(STRIP) lookup_file.so
+
 lookup_yp.so: lookup_yp.c
 	$(CC) $(SOLDFLAGS) $(CFLAGS) -o lookup_yp.so lookup_yp.c $(AUTOFS_LIB) $(LIBNSL)
 	$(STRIP) lookup_yp.so
modules/lookup_file.c +592 -50

821 lines not on this page · raw message

modules/lookup_ldap.c +104 -28

177 lines not on this page · raw message

modules/lookup_yp.c +94 -13

151 lines not on this page · raw message

modules/parse_sun.c +1 -1
index 2e95a45..9c8bca2 100644
@@ -661,7 +661,7 @@ static int sun_mount(const char *root, c
 	 * to detect what type of map it is.
 	 */
 	if (!strcmp(fstype, "autofs") && strchr(loc, ':') == NULL) {
-		nsswitch_map = get_nsswitch_map(loc);
+		nsswitch_map = get_nsswitch_map(loc, NULL);
 		if (!nsswitch_map) {
 			error(MODPREFIX "unable to find map %s",loc);
 			return 1;
samples/rc.autofs.in +15 -20
index d00f2ab..27ef6bb 100644
@@ -143,10 +143,11 @@ function getfilemounts()
             if [ "`echo $auto_master_in | grep '^+'`" = "" ]; then
                 echo $auto_master_in
             else
-                for nismap in `cat /etc/auto.master | grep '^\+' |
-                        sed -e '/^#/d' -e '/^$/d'`; do
-                    catnismap `echo "$nismap" | sed -e 's/^\+//'`
-                done
+		mapname=`echo $auto_master_in | sed -e 's/\+//g'`
+		expanded_mapname=`@@autofslibdir@@/nsswitch $mapname 2>/dev/null`
+		expanded_mapname=`echo $expanded_mapname | sed -e 's/:/ /g'`
+		: $DAEMON -D /bogus $expanded_mapname
+		$DAEMON -D /bogus $expanded_mapname
             fi
         done
         )
@@ -177,7 +178,7 @@ function getrawmounts()
             files)
                 if [ -z "$filescheme" ] ; then
                     FILEMOUNTS=`getfilemounts`
-                    if [ -n "$FILEMOUNTS" ] && [ "$ONE_AUTO_MASTER" -eq 1 ];
+                    if [ -n "$FILEMOUNTS" -o -f /etc/auto.master ] && [ "$ONE_AUTO_MASTER" -eq 1 ];
                     then
                         getfilemounts
                         return
@@ -333,24 +334,18 @@ function getmounts()
 		    elif [ "$map" = "multi" ] ; then
 			maptype=$map
 			map=
-#		    elif echo "$map" | grep -q '^!'; then
-#		        map=`echo "$map"| sed -e 's/^!//g'`
-		    elif `echo $map | grep -q "^/"` && [ -x "$map" ]; then
-			maptype=program
-		    elif [ -x "/etc/$map" ]; then
-			maptype=program
-			map=`echo /etc/$map | sed 's^//^/^g'`
-		    elif `echo $map | grep -q "^/"` && [ -f "$map" ]; then
-			maptype=file
-		    elif [ -f "/etc/$map" ]; then
-			maptype=file
-			map=`echo /etc/$map | sed 's^//^/^g'`
 		    else
-			maptype=yp
 			if [ "$UNDERSCORETODOT" = "1" ] ; then
-			    map=`basename $map | sed -e s/^auto_/auto./`
+			    nsswitch_opts="-u"
 			else
-			    map=`basename $map | sed 's^//^/^g'`
+			    nsswitch_opts=""
+			fi
+			nsswitch_output=`@@autofslibdir@@/nsswitch $nsswitch_opts $map 2>/dev/null`
+			if [ $? -eq 0 ]; then
+			    maptype=`echo $nsswitch_output | cut -d: -f 1`
+			    map=`echo $nsswitch_output | cut -d: -f 2`
+			else
+			    continue;
 			fi
 		    fi
 		fi
maintainer
#1 lore raw
Quoted 13 lines · Jeff Moyer

Hi, Ian, list, (again, sorry if this is a dup)

Here is an implementation of included map support for autofs v4. This supports included maps in both the master map, and regular direct or indirect file maps.

Because I dread writing bash code, I implemented the included map checking for the master map in C. We basically just call into the daemon with a bogus mount point, asking for it to dump out all of the maps. This works well for 2 reasons: 1) it's not bash, and 2) it re-uses the code that the daemon will use to read the included maps anyway.

Quoted 4 lines

Review would be greatly appreciated. I tested this in my environment by creating a number of included maps, and modifying /etc/nsswitch.conf to ensure that it works as expected for file and NIS maps.

I've only looked briefly at this but I get the impression that it will allow "+" map inclusion from other than file maps. Is that right?

If that is the case we need to explicitly ignore "+" map entries in map sources other than file maps as it's not legal or at least for consistency.

Ian

author
#2 lore raw

==> On Thu, 09 Nov 2006 13:20:40 +0800, Ian Kent <[email protected]> said:

Ian> On Wed, 2006-11-08 at 22:37 -0500, Jeff Moyer wrote: > Hi, Ian, Ian> list, (again, sorry if this is a dup)
Ian> >
Ian> > Here is an implementation of included map support for autofs Ian> v4. This > supports included maps in both the master map, and Ian> regular direct or > indirect file maps.
Ian> >
Ian> > Because I dread writing bash code, I implemented the included Ian> map > checking for the master map in C. We basically just call Ian> into the > daemon with a bogus mount point, asking for it to dump Ian> out all of the > maps. This works well for 2 reasons: 1) it's Ian> not bash, and 2) it > re-uses the code that the daemon will use Ian> to read the included maps > anyway.
Ian> >
Ian> > Review would be greatly appreciated. I tested this in my Ian> environment > by creating a number of included maps, and Ian> modifying > /etc/nsswitch.conf to ensure that it works as Ian> expected for file and > NIS maps.

Ian> I've only looked briefly at this but I get the impression that it Ian> will allow "+" map inclusion from other than file maps. Is that Ian> right?

That was not the intent, and upon testing, it certainly doesn't follow included maps from yp. It does, however, interpret the included map as a key in the map, which give a directory listing like this:

# ls /test/
+auto.test  repltest  sbox

Wrong, and somewhat amusing. I'm not sure how best to deal with that. I guess we need to throw out entries which do not have a "value" portion. I'm surprised we don't handle that already.

-Jeff

maintainer
#3 lore raw
Quoted 25 lines · Jeff Moyer

==> On Thu, 09 Nov 2006 13:20:40 +0800, Ian Kent <[email protected]> said:

Ian> On Wed, 2006-11-08 at 22:37 -0500, Jeff Moyer wrote: > Hi, Ian, Ian> list, (again, sorry if this is a dup)
Ian> >
Ian> > Here is an implementation of included map support for autofs Ian> v4. This > supports included maps in both the master map, and Ian> regular direct or > indirect file maps.
Ian> >
Ian> > Because I dread writing bash code, I implemented the included Ian> map > checking for the master map in C. We basically just call Ian> into the > daemon with a bogus mount point, asking for it to dump Ian> out all of the > maps. This works well for 2 reasons: 1) it's Ian> not bash, and 2) it > re-uses the code that the daemon will use Ian> to read the included maps > anyway.
Ian> >
Ian> > Review would be greatly appreciated. I tested this in my Ian> environment > by creating a number of included maps, and Ian> modifying > /etc/nsswitch.conf to ensure that it works as Ian> expected for file and > NIS maps.

Ian> I've only looked briefly at this but I get the impression that it Ian> will allow "+" map inclusion from other than file maps. Is that Ian> right?

Quoted 6 lines

That was not the intent, and upon testing, it certainly doesn't follow included maps from yp. It does, however, interpret the included map as a key in the map, which give a directory listing like this:

# ls /test/
+auto.test  repltest  sbox

I'm impressed!

You've been able to duplicate the broken Solaris behavior I've seen in the past. Hehe!

Ian