Sophie

Sophie

distrib > Scientific%20Linux > 5x > x86_64 > by-pkgid > 533aea79872ccd7be2635d272acbf7ea > files > 20

autofs-5.0.1-0.rc2.163.el5.src.rpm

autofs-5.0.1 - check for path mount location in generic module

From: Ian Kent <ikent@redhat.com>

Currently we check for dependent mounts in the mount location path
for bind mounts. Version 5.0.3 added a check for this with loopback
mounts (which wasn't included in RHEL autofs). But we can have the
case where a mount other than a loopback mount uses a local path
and is not a bind mount. In this case we need to check the local
path for dependent mounts. To do this we can check the mount
location prior to spawning the mount and if it starts with a "/"
then it is a local path and the check is needed.

---
 daemon/spawn.c |   44 ++++++++++++++++++++++++++++++++------------
 1 file changed, 32 insertions(+), 12 deletions(-)

--- autofs-5.0.1.orig/daemon/spawn.c
+++ autofs-5.0.1/daemon/spawn.c
@@ -156,22 +156,28 @@ static int do_spawn(unsigned logopt, uns
 
 	f = fork();
 	if (f == 0) {
+		char **pargv = (char **) argv;
+		int loc = 0;
+
 		reset_signals();
 		close(pipefd[0]);
 		dup2(pipefd[1], STDOUT_FILENO);
 		dup2(pipefd[1], STDERR_FILENO);
 		close(pipefd[1]);
 
-		/* Bind mount - check target exists */
-		if (use_access) {
-			char **pargv = (char **) argv;
-			int argc = 0;
-			pid_t pgrp = getpgrp();
+		/* what to mount must always be second last */
+		while (*pargv++)
+			loc++;
+		loc -= 2;
 
-			/* what to mount must always be second last */
-			while (*pargv++)
-				argc++;
-			argc -= 2;
+		/*
+		 * If the mount location starts with a "/" then it is
+		 * a local path. In this case it is a bind mount, a
+		 * loopback mount or a file system that uses a local
+		 * path so we need to check for dependent mounts.
+		 */
+		if (use_access && *(argv[loc]) == '/') {
+			pid_t pgrp = getpgrp();
 
 			/*
 			 * Pretend to be requesting user and set non-autofs
@@ -184,7 +190,7 @@ static int do_spawn(unsigned logopt, uns
 			setpgrp();
 
 			/* Trigger the recursive mount */
-			if (access(argv[argc], F_OK) == -1)
+			if (access(argv[loc], F_OK) == -1)
 				_exit(errno);
 
 			seteuid(0);
@@ -319,7 +325,7 @@ int spawn_mount(unsigned logopt, ...)
 #ifdef ENABLE_MOUNT_LOCKING
 	options = SPAWN_OPT_LOCK;
 #else
-	options = SPAWN_OPT_NONE;
+	options = SPAWN_OPT_ACCESS;
 #endif
 
 	va_start(arg, logopt);
@@ -350,7 +356,21 @@ int spawn_mount(unsigned logopt, ...)
 		argv[1] = argn;
 		p = argv + 2;
 	}
-	while ((*p++ = va_arg(arg, char *)));
+	while ((*p = va_arg(arg, char *))) {
+		if (options == SPAWN_OPT_ACCESS && !strcmp(*p, "-t")) {
+			*(++p) = va_arg(arg, char *);
+			if (!*p)
+				break;
+			/*
+			 * A cifs mount location begins with a "/" but
+			 * is not a local path, so don't try to resolve
+			 * it. Mmmm ... does anyone use smbfs these days?
+			 */
+			if (strstr(*p, "cifs"))
+				options = SPAWN_OPT_NONE;
+		}
+		p++;
+	}
 	va_end(arg);
 
 	while (retries--) {