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

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