Blame SOURCES/autofs-5.1.2-check-for-conflicting-amd-section-mounts.patch

304803
autofs-5.1.2 - check for conflicting amd section mounts
304803
304803
From: Ian Kent <raven@themaw.net>
304803
304803
Allowing the addition of amd section mounts to the master mounts list
304803
can lead to conflicting mount point paths.
304803
304803
Check for conflicts and skip the amd mount section mounts if a conflict
304803
with the master map mounts is found.
304803
304803
Signed-off-by: Ian Kent <raven@themaw.net>
304803
---
304803
 CHANGELOG        |    1 
304803
 include/master.h |    1 
304803
 lib/master.c     |   59 ++++++++++++++++++++++++++++++++++++++++++++++++++++---
304803
 3 files changed, 58 insertions(+), 3 deletions(-)
304803
304803
--- autofs-5.0.7.orig/CHANGELOG
304803
+++ autofs-5.0.7/CHANGELOG
304803
@@ -228,6 +228,7 @@
304803
 - add function conf_amd_get_map_name().
304803
 - add function conf_amd_get_mount_paths().
304803
 - include amd mount sections mounts in master mounts list.
304803
+- check for conflicting amd section mounts.
304803
 
304803
 25/07/2012 autofs-5.0.7
304803
 =======================
304803
--- autofs-5.0.7.orig/include/master.h
304803
+++ autofs-5.0.7/include/master.h
304803
@@ -106,6 +106,7 @@ void master_source_lock_cleanup(void *);
304803
 void master_source_current_wait(struct master_mapent *);
304803
 void master_source_current_signal(struct master_mapent *);
304803
 struct master_mapent *master_find_mapent(struct master *, const char *);
304803
+unsigned int master_partial_match_mapent(struct master *, const char *);
304803
 struct autofs_point *__master_find_submount(struct autofs_point *, const char *);
304803
 struct autofs_point *master_find_submount(struct autofs_point *, const char *);
304803
 struct amd_entry *__master_find_amdmount(struct autofs_point *, const char *);
304803
--- autofs-5.0.7.orig/lib/master.c
304803
+++ autofs-5.0.7/lib/master.c
304803
@@ -710,6 +710,53 @@ struct master_mapent *master_find_mapent
304803
 	return NULL;
304803
 }
304803
 
304803
+unsigned int master_partial_match_mapent(struct master *master, const char *path)
304803
+{
304803
+	struct list_head *head, *p;
304803
+	size_t path_len = strlen(path);
304803
+	int ret = 0;
304803
+
304803
+	head = &master->mounts;
304803
+	list_for_each(p, head) {
304803
+		struct master_mapent *entry;
304803
+		size_t entry_len;
304803
+		size_t cmp_len;
304803
+
304803
+		entry = list_entry(p, struct master_mapent, list);
304803
+
304803
+		entry_len = strlen(entry->path);
304803
+		cmp_len = min(entry_len, path_len);
304803
+
304803
+		if (!strncmp(entry->path, path, cmp_len)) {
304803
+			/* paths are equal, matching master map entry ? */
304803
+			if (entry_len == path_len) {
304803
+				if (entry->maps &&
304803
+				    entry->maps->flags & MAP_FLAG_FORMAT_AMD)
304803
+					ret = 1;
304803
+				else
304803
+					ret = -1;
304803
+				break;
304803
+			}
304803
+
304803
+			/* amd mount conflicts with entry mount */
304803
+			if (entry_len > path_len &&
304803
+			    *(entry->path + path_len) == '/') {
304803
+				ret = -1;
304803
+				break;
304803
+			}
304803
+
304803
+			/* entry mount conflicts with amd mount */
304803
+			if (entry_len < path_len &&
304803
+			    *(path + entry_len) == '/') {
304803
+				ret = -1;
304803
+				break;
304803
+			}
304803
+		}
304803
+	}
304803
+
304803
+	return ret;
304803
+}
304803
+
304803
 struct autofs_point *__master_find_submount(struct autofs_point *ap, const char *path)
304803
 {
304803
 	struct list_head *head, *p;
304803
@@ -936,10 +983,16 @@ static void master_add_amd_mount_section
304803
 		char *type = NULL;
304803
 		char *map = NULL;
304803
 
304803
-		entry = master_find_mapent(master, path);
304803
-		if (entry) {
304803
+		ret = master_partial_match_mapent(master, path);
304803
+		if (ret) {
304803
+			/* If this amd entry is already present in the
304803
+			 * master map it's not a duplicate, don't issue
304803
+			 * an error message.
304803
+			 */
304803
+			if (ret == 1)
304803
+				goto next;
304803
 			info(m_logopt,
304803
-			     "ignoring duplicate amd section mount %s",
304803
+			     "amd section mount path conflict, %s ignored",
304803
 			     path);
304803
 			goto next;
304803
 		}