Skip to contentSkip to conversation

check nsswitch.conf for submounts

PATCH In review Chris Feist 3 participants 6 messages Feb 23, 2005 – Mar 1, 2005

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 check nsswitch.conf for submounts

This patch addresses the problem if a user has the following in one of their automount maps:

# auto.misc
test 	-fstype=autofs    auto.m2

Before it would automatically assume that auto.m2 was a yp/nis map. The patch now checks if the file exists in /etc/ (and if it's a file or program map) or if it exists in yp (according to the order in nsswitch.conf).

In the future we may want to include functionality in the lookup_xxx.so modules so we can more easily detect if a certain map exists.

Thanks,
Chris

include/automount.h +8 -0
diff -uNrp autofs-4.1.4-beta2.orig/include/automount.h autofs-4.1.4-beta2/include/automount.h
@@ -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;
lib/Makefile +2 -2
diff -uNrp autofs-4.1.4-beta2.orig/lib/Makefile autofs-4.1.4-beta2/lib/Makefile
@@ -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
 
lib/Makefile.rej +0 -22
diff -uNrp autofs-4.1.4-beta2.orig/lib/Makefile.rej autofs-4.1.4-beta2/lib/Makefile.rej
@@ -1,22 +0,0 @@
-***************
-*** 9,17 ****
-  RPCGEN = /usr/bin/rpcgen
-  RANLIB = /usr/bin/ranlib
-  
-- SRCS = cache.c listmount.c cat_path.c rpc_subs.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
-  
-  LIB = autofs.a
-  
---- 9,18 ----
-  RPCGEN = /usr/bin/rpcgen
-  RANLIB = /usr/bin/ranlib
-  
-+ SRCS = cache.c listmount.c cat_path.c rpc_subs.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 \
-+        nsswitch.o
-  
-  LIB = autofs.a
-  
lib/nsswitch.c +154 -0

154 lines not on this page · raw message

modules/Makefile +4 -0
diff -uNrp autofs-4.1.4-beta2.orig/modules/Makefile autofs-4.1.4-beta2/modules/Makefile
@@ -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
modules/parse_sun.c +13 -5
diff -uNrp autofs-4.1.4-beta2.orig/modules/parse_sun.c autofs-4.1.4-beta2/modules/parse_sun.c
@@ -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;
@@ -646,11 +648,17 @@ static int sun_mount(const char *root, c
 	memcpy(what, loc, loclen);
 	what[loclen] = '\0';
 
-	if (! strcmp(fstype, "autofs") && strchr(loc, ':') == NULL) {
-		what = alloca(loclen + 3 + 1); /* 1 for '0', 3 for yp: */
-		memcpy(what, "yp:", 3);
-		memcpy(what + 3, loc, loclen);
-		what[loclen + 3] = '\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 &&
+			((nsswitch_map = get_nsswitch_map(loc)) != NULL)) {
+		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 mailing list
[email protected]
http://linux.kernel.org/mailman/listinfo/autofs

#1 lore raw

On Wed, 23 Feb 2005, Chris Feist wrote:

Thanks Chris.

This is a really useful bit of code.
Appart from addressing the default map problem, it is one of the pieces of code needed to move logic out of the init script.

Howerver, we can't assume that maps are stored in "/etc". This really should be a configure logical.

Quoted 12 lines

This patch addresses the problem if a user has the following in one of their automount maps:

# auto.misc
test 	-fstype=autofs    auto.m2

Before it would automatically assume that auto.m2 was a yp/nis map. The patch now checks if the file exists in /etc/ (and if it's a file or program map) or if it exists in yp (according to the order in nsswitch.conf).

In the future we may want to include functionality in the lookup_xxx.so modules so we can more easily detect if a certain map exists.

Thanks,
Chris

#2 lore raw

==> Regarding Re: [autofs] [PATCH] check nsswitch.conf for submounts; [email protected] adds:

raven> On Wed, 23 Feb 2005, Chris Feist wrote: Thanks Chris.

raven> This is a really useful bit of code. Appart from addressing the raven> default map problem, it is one of the pieces of code needed to move raven> logic out of the init script.

raven> Howerver, we can't assume that maps are stored in "/etc". This raven> really should be a configure logical.

And why not? Is this not precisely what the Sun automounter does?

-Jeff

Quoted 8 lines
Quoted 8 lines

This patch addresses the problem if a user has the following in one of their automount maps: # auto.misc test -fstype=autofs auto.m2

Before it would automatically assume that auto.m2 was a yp/nis map. The patch now checks if the file exists in /etc/ (and if it's a file or program map) or if it exists in yp (according to the order in nsswitch.conf).

Quoted 6 lines
Quoted 6 lines

In the future we may want to include functionality in the lookup_xxx.so modules so we can more easily detect if a certain map exists.

Thanks, Chris

raven> _______________________________________________ autofs mailing list raven> [email protected]
raven> http://linux.kernel.org/mailman/listinfo/autofs

#3 lore raw
Quoted 4 lines · Jeff Moyer

==> Regarding Re: [autofs] [PATCH] check nsswitch.conf for submounts; [email protected] adds:

raven> On Wed, 23 Feb 2005, Chris Feist wrote: Thanks Chris.

Quoted 8 lines

raven> This is a really useful bit of code. Appart from addressing the raven> default map problem, it is one of the pieces of code needed to move raven> logic out of the init script.

raven> Howerver, we can't assume that maps are stored in "/etc". This raven> really should be a configure logical.

And why not? Is this not precisely what the Sun automounter does?

Yes but not all distributions store their maps in /etc.
I don't want to make it hard for myself and others that may need this in time to come.

Gentoo stores maps in /etc/autofs for example.

Quoted 22 lines

-Jeff

Quoted 8 lines
Quoted 8 lines

This patch addresses the problem if a user has the following in one of their automount maps: # auto.misc test -fstype=autofs auto.m2

Before it would automatically assume that auto.m2 was a yp/nis map. The patch now checks if the file exists in /etc/ (and if it's a file or program map) or if it exists in yp (according to the order in nsswitch.conf).

Quoted 6 lines
Quoted 6 lines

In the future we may want to include functionality in the lookup_xxx.so modules so we can more easily detect if a certain map exists.

Thanks, Chris

raven> _______________________________________________ autofs mailing list raven> [email protected]
raven> http://linux.kernel.org/mailman/listinfo/autofs

#4 lore raw
In reply to [email protected]
Quoted 5 lines · [email protected] wrote:

This is a really useful bit of code.
Appart from addressing the default map problem, it is one of the pieces of code needed to move logic out of the init script.

Howerver, we can't assume that maps are stored in "/etc". This really should be a configure logical.

We do use _PATH_NSSWITCH_CONF for the location of the nsswitch.conf file which is defined in netdb.h. So if that file was someplace else I would expect that the changes would need to be made in netdb.h (for glibc, etc.)

Thanks,
Chris

#5 lore raw
Quoted 8 lines · Chris Feist
Quoted 5 lines · [email protected] wrote:

This is a really useful bit of code.
Appart from addressing the default map problem, it is one of the pieces of code needed to move logic out of the init script.

Howerver, we can't assume that maps are stored in "/etc". This really should be a configure logical.

We do use _PATH_NSSWITCH_CONF for the location of the nsswitch.conf file which is defined in netdb.h. So if that file was someplace else I would expect that the changes would need to be made in netdb.h (for glibc, etc.)

It's the autofs maps location I'd like to have configurable.

Ian