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

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