Blame SOURCES/autofs-5.1.0-fix-mount-as-you-go-offset-selection.patch

516ab0
autofs-5.1.0 - fix mount as you go offset selection
516ab0
516ab0
From: Ian Kent <raven@themaw.net>
516ab0
516ab0
The function cache_get_offset() returns offsets to be mounted that
516ab0
are within the current current subtree for the mount-as-you-go
516ab0
functionality used for nested multi-mount map entries.
516ab0
516ab0
However, the function was returning offsets from the subree below
516ab0
nesting points which prevented the mount at the containing nesting
516ab0
point from being mounted. This is because the kernel will see a
516ab0
non-empty directory and conclude it isn't a mount point.
516ab0
---
516ab0
 CHANGELOG   |    1 +
516ab0
 lib/cache.c |   27 ++++++++++++++++++++++++---
516ab0
 2 files changed, 25 insertions(+), 3 deletions(-)
516ab0
516ab0
--- autofs-5.0.7.orig/CHANGELOG
516ab0
+++ autofs-5.0.7/CHANGELOG
516ab0
@@ -168,6 +168,7 @@
516ab0
 - handle duplicates in multi mounts.
516ab0
 - fix macro usage in lookup_program.c.
516ab0
 - remove unused offset handling code.
516ab0
+- fix mount as you go offset selection.
516ab0
 
516ab0
 25/07/2012 autofs-5.0.7
516ab0
 =======================
516ab0
--- autofs-5.0.7.orig/lib/cache.c
516ab0
+++ autofs-5.0.7/lib/cache.c
516ab0
@@ -1183,7 +1183,6 @@ struct mapent *cache_enumerate(struct ma
516ab0
  * Get each offset from list head under prefix.
516ab0
  * Maintain traversal current position in pos for subsequent calls. 
516ab0
  * Return each offset into offset.
516ab0
- * TODO: length check on offset.
516ab0
  */
516ab0
 /* cache must be read locked by caller */
516ab0
 char *cache_get_offset(const char *prefix, char *offset, int start,
516ab0
@@ -1212,6 +1211,9 @@ char *cache_get_offset(const char *prefi
516ab0
 			continue;
516ab0
 
516ab0
 		if (!strncmp(prefix, offset_start, plen)) {
516ab0
+			struct mapent *np = NULL;
516ab0
+			char pe[PATH_MAX + 1];
516ab0
+
516ab0
 			/* "/" doesn't count for root offset */
516ab0
 			if (plen == 1)
516ab0
 				pstart = &offset_start[plen - 1];
516ab0
@@ -1224,7 +1226,24 @@ char *cache_get_offset(const char *prefi
516ab0
 
516ab0
 			/* get next offset */
516ab0
 			pend = pstart;
516ab0
-			while (*pend++) ;
516ab0
+			while (*pend++) {
516ab0
+				size_t nest_pt_offset;
516ab0
+
516ab0
+				if (*pend != '/')
516ab0
+					continue;
516ab0
+
516ab0
+				nest_pt_offset = start + pend - pstart;
516ab0
+				if (plen > 1)
516ab0
+					nest_pt_offset += plen;
516ab0
+				strcpy(pe, this->key);
516ab0
+				pe[nest_pt_offset] = '\0';
516ab0
+
516ab0
+				np = cache_lookup_distinct(this->mc, pe);
516ab0
+				if (np)
516ab0
+					break;
516ab0
+			}
516ab0
+			if (np)
516ab0
+				continue;
516ab0
 			len = pend - pstart - 1;
516ab0
 			strncpy(offset, pstart, len);
516ab0
 			offset[len] ='\0';
516ab0
@@ -1257,7 +1276,9 @@ char *cache_get_offset(const char *prefi
516ab0
 			break;
516ab0
 
516ab0
 		/* compare offset */
516ab0
-		if (pstart[len] != '/' || strncmp(offset, pstart, len))
516ab0
+		if (pstart[len] != '/' ||
516ab0
+		    strlen(pstart) != len ||
516ab0
+		    strncmp(offset, pstart, len))
516ab0
 			break;
516ab0
 
516ab0
 		*pos = next;