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

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