All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] check nsswitch.conf for submounts
@ 2005-02-23 22:37 Chris Feist
  2005-02-27  3:27 ` raven
  0 siblings, 1 reply; 6+ messages in thread
From: Chris Feist @ 2005-02-23 22:37 UTC (permalink / raw)
  To: autofs

[-- Attachment #1: Type: text/plain, Size: 511 bytes --]

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

[-- Attachment #2: autofs-4.1.4-beta2-submount-nsswitch.patch --]
[-- Type: text/x-patch, Size: 7979 bytes --]

diff -uNrp autofs-4.1.4-beta2.orig/include/automount.h autofs-4.1.4-beta2/include/automount.h
--- autofs-4.1.4-beta2.orig/include/automount.h	2005-02-23 16:32:05.607695789 -0600
+++ autofs-4.1.4-beta2/include/automount.h	2005-02-23 16:32:18.657490748 -0600
@@ -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;
diff -uNrp autofs-4.1.4-beta2.orig/lib/Makefile autofs-4.1.4-beta2/lib/Makefile
--- autofs-4.1.4-beta2.orig/lib/Makefile	2005-02-23 16:32:05.565696448 -0600
+++ autofs-4.1.4-beta2/lib/Makefile	2005-02-23 16:32:48.610020411 -0600
@@ -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
 
diff -uNrp autofs-4.1.4-beta2.orig/lib/Makefile.rej autofs-4.1.4-beta2/lib/Makefile.rej
--- autofs-4.1.4-beta2.orig/lib/Makefile.rej	2005-02-23 16:32:05.554696621 -0600
+++ autofs-4.1.4-beta2/lib/Makefile.rej	1969-12-31 18:00:00.000000000 -0600
@@ -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
-  
diff -uNrp autofs-4.1.4-beta2.orig/lib/nsswitch.c autofs-4.1.4-beta2/lib/nsswitch.c
--- autofs-4.1.4-beta2.orig/lib/nsswitch.c	1969-12-31 18:00:00.000000000 -0600
+++ autofs-4.1.4-beta2/lib/nsswitch.c	2005-02-23 16:32:18.659490717 -0600
@@ -0,0 +1,154 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <syslog.h>
+#include <ctype.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+#include <rpcsvc/ypclnt.h>
+#include <netdb.h>
+#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;
+}
diff -uNrp autofs-4.1.4-beta2.orig/modules/Makefile autofs-4.1.4-beta2/modules/Makefile
--- autofs-4.1.4-beta2.orig/modules/Makefile	2005-02-23 16:32:05.545696763 -0600
+++ autofs-4.1.4-beta2/modules/Makefile	2005-02-23 16:32:18.659490717 -0600
@@ -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
diff -uNrp autofs-4.1.4-beta2.orig/modules/parse_sun.c autofs-4.1.4-beta2/modules/parse_sun.c
--- autofs-4.1.4-beta2.orig/modules/parse_sun.c	2005-02-23 16:32:05.540696841 -0600
+++ autofs-4.1.4-beta2/modules/parse_sun.c	2005-02-23 16:32:18.661490685 -0600
@@ -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);

[-- Attachment #3: Type: text/plain, Size: 140 bytes --]

_______________________________________________
autofs mailing list
autofs@linux.kernel.org
http://linux.kernel.org/mailman/listinfo/autofs

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] check nsswitch.conf for submounts
  2005-02-23 22:37 [PATCH] check nsswitch.conf for submounts Chris Feist
@ 2005-02-27  3:27 ` raven
  2005-02-28 14:10   ` Jeff Moyer
  2005-02-28 17:00   ` Chris Feist
  0 siblings, 2 replies; 6+ messages in thread
From: raven @ 2005-02-27  3:27 UTC (permalink / raw)
  To: Chris Feist; +Cc: autofs

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.

> 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
>
>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] check nsswitch.conf for submounts
  2005-02-27  3:27 ` raven
@ 2005-02-28 14:10   ` Jeff Moyer
  2005-03-01 13:17     ` raven
  2005-02-28 17:00   ` Chris Feist
  1 sibling, 1 reply; 6+ messages in thread
From: Jeff Moyer @ 2005-02-28 14:10 UTC (permalink / raw)
  To: raven; +Cc: autofs, Chris Feist

==> Regarding Re: [autofs] [PATCH] check nsswitch.conf for submounts; raven@themaw.net 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

>> 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
>> 
>> 

raven> _______________________________________________ autofs mailing list
raven> autofs@linux.kernel.org
raven> http://linux.kernel.org/mailman/listinfo/autofs

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] check nsswitch.conf for submounts
  2005-02-27  3:27 ` raven
  2005-02-28 14:10   ` Jeff Moyer
@ 2005-02-28 17:00   ` Chris Feist
  2005-03-01 13:19     ` raven
  1 sibling, 1 reply; 6+ messages in thread
From: Chris Feist @ 2005-02-28 17:00 UTC (permalink / raw)
  To: raven; +Cc: autofs

raven@themaw.net 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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] check nsswitch.conf for submounts
  2005-02-28 14:10   ` Jeff Moyer
@ 2005-03-01 13:17     ` raven
  0 siblings, 0 replies; 6+ messages in thread
From: raven @ 2005-03-01 13:17 UTC (permalink / raw)
  To: Jeff Moyer; +Cc: autofs, Chris Feist

On Mon, 28 Feb 2005, Jeff Moyer wrote:

> ==> Regarding Re: [autofs] [PATCH] check nsswitch.conf for submounts; raven@themaw.net 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?

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.

>
> -Jeff
>
>>> 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
>>>
>>>
>
> raven> _______________________________________________ autofs mailing list
> raven> autofs@linux.kernel.org
> raven> http://linux.kernel.org/mailman/listinfo/autofs
>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] check nsswitch.conf for submounts
  2005-02-28 17:00   ` Chris Feist
@ 2005-03-01 13:19     ` raven
  0 siblings, 0 replies; 6+ messages in thread
From: raven @ 2005-03-01 13:19 UTC (permalink / raw)
  To: Chris Feist; +Cc: autofs

On Mon, 28 Feb 2005, Chris Feist wrote:

> raven@themaw.net 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

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2005-03-01 13:19 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-02-23 22:37 [PATCH] check nsswitch.conf for submounts Chris Feist
2005-02-27  3:27 ` raven
2005-02-28 14:10   ` Jeff Moyer
2005-03-01 13:17     ` raven
2005-02-28 17:00   ` Chris Feist
2005-03-01 13:19     ` raven

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.