autofs-5.0.9 - fix mount as you go offset selection From: Ian Kent The function cache_get_offset() returns offsets to be mounted that are within the current current subtree for the mount-as-you-go functionality used for nested multi-mount map entries. However, the function was returning offsets from the subree below nesting points which prevented the mount at the containing nesting point from being mounted. This is because the kernel will see a non-empty directory and conclude it isn't a mount point. --- CHANGELOG | 1 + lib/cache.c | 27 ++++++++++++++++++++++++--- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index fc2b2d4..ffdee2a 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -34,6 +34,7 @@ - fix macro usage in lookup_program.c. - fix gcc5 complaints. - remove unused offset handling code. +- fix mount as you go offset selection. 28/03/2014 autofs-5.0.9 ======================= diff --git a/lib/cache.c b/lib/cache.c index 5495238..7d54a84 100644 --- a/lib/cache.c +++ b/lib/cache.c @@ -1174,7 +1174,6 @@ struct mapent *cache_enumerate(struct mapent_cache *mc, struct mapent *me) * Get each offset from list head under prefix. * Maintain traversal current position in pos for subsequent calls. * Return each offset into offset. - * TODO: length check on offset. */ /* cache must be read locked by caller */ char *cache_get_offset(const char *prefix, char *offset, int start, @@ -1203,6 +1202,9 @@ char *cache_get_offset(const char *prefix, char *offset, int start, continue; if (!strncmp(prefix, offset_start, plen)) { + struct mapent *np = NULL; + char pe[PATH_MAX + 1]; + /* "/" doesn't count for root offset */ if (plen == 1) pstart = &offset_start[plen - 1]; @@ -1215,7 +1217,24 @@ char *cache_get_offset(const char *prefix, char *offset, int start, /* get next offset */ pend = pstart; - while (*pend++) ; + while (*pend++) { + size_t nest_pt_offset; + + if (*pend != '/') + continue; + + nest_pt_offset = start + pend - pstart; + if (plen > 1) + nest_pt_offset += plen; + strcpy(pe, this->key); + pe[nest_pt_offset] = '\0'; + + np = cache_lookup_distinct(this->mc, pe); + if (np) + break; + } + if (np) + continue; len = pend - pstart - 1; strncpy(offset, pstart, len); offset[len] ='\0'; @@ -1248,7 +1267,9 @@ char *cache_get_offset(const char *prefix, char *offset, int start, break; /* compare offset */ - if (pstart[len] != '/' || strncmp(offset, pstart, len)) + if (pstart[len] != '/' || + strlen(pstart) != len || + strncmp(offset, pstart, len)) break; *pos = next;