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

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