Blame SOURCES/autofs-5.0.9-amd-lookup-check-for-required-options-for-mounts.patch

306fa1
autofs-5.0.9 - amd lookup check for required options for mounts
306fa1
306fa1
From: Ian Kent <raven@themaw.net>
306fa1
306fa1
306fa1
---
306fa1
 modules/parse_amd.c |  103 ++++++++++++++++++++++++++++++++++++++++++++++++++-
306fa1
 1 file changed, 101 insertions(+), 2 deletions(-)
306fa1
306fa1
diff --git a/modules/parse_amd.c b/modules/parse_amd.c
306fa1
index 2056ed9..bc53b1d 100644
306fa1
--- a/modules/parse_amd.c
306fa1
+++ b/modules/parse_amd.c
306fa1
@@ -1070,7 +1070,7 @@ static int do_nfsl_mount(struct autofs_point *ap, const char *name,
306fa1
 
306fa1
 static int wait_for_expire(struct autofs_point *ap)
306fa1
 {
306fa1
-	int ret = 1;
306fa1
+	int ret = 0;
306fa1
 
306fa1
 	st_wait_task(ap, ST_EXPIRE, 0);
306fa1
 
306fa1
@@ -1078,7 +1078,7 @@ static int wait_for_expire(struct autofs_point *ap)
306fa1
 	if (ap->state != ST_SHUTDOWN &&
306fa1
 	    ap->state != ST_SHUTDOWN_PENDING &&
306fa1
 	    ap->state != ST_SHUTDOWN_FORCE) {
306fa1
-		ret = 0;
306fa1
+		ret = 1;
306fa1
 	}
306fa1
 	st_mutex_unlock();
306fa1
 
306fa1
@@ -1181,6 +1181,88 @@ out:
306fa1
 	return ret;
306fa1
 }
306fa1
 
306fa1
+static unsigned int validate_auto_options(unsigned int logopt,
306fa1
+					  struct amd_entry *entry)
306fa1
+{
306fa1
+	/*
306fa1
+	 * The amd manual implies all the mount type auto options
306fa1
+	 * are optional but I don't think there's much point if
306fa1
+	 * no map is given.
306fa1
+	 */
306fa1
+	if (!entry->fs) {
306fa1
+		error(logopt, MODPREFIX
306fa1
+		      "%s: file system not given", entry->type);
306fa1
+		return 0;
306fa1
+	}
306fa1
+	return 1;
306fa1
+}
306fa1
+
306fa1
+static unsigned int validate_link_options(unsigned int logopt,
306fa1
+					  struct amd_entry *entry)
306fa1
+{
306fa1
+	/* fs is the destimation of the link */
306fa1
+	return validate_auto_options(logopt, entry);
306fa1
+}
306fa1
+
306fa1
+static unsigned int validate_nfs_options(unsigned int logopt,
306fa1
+					 struct amd_entry *entry)
306fa1
+{
306fa1
+	/*
306fa1
+	 * Required option rhost will always have a value.
306fa1
+	 * It is set from ${host} if it is found to be NULL
306fa1
+	 * earlier in the parsing process.
306fa1
+	 */
306fa1
+	if (!entry->rfs) {
306fa1
+		if (entry->fs)
306fa1
+			entry->rfs = strdup(entry->fs);
306fa1
+		if (!entry->rfs) {
306fa1
+			error(logopt, MODPREFIX
306fa1
+			      "%s: remote file system not given", entry->type);
306fa1
+			return 0;
306fa1
+		}
306fa1
+	}
306fa1
+	return 1;
306fa1
+}
306fa1
+
306fa1
+static unsigned int validate_generic_options(unsigned int logopt,
306fa1
+					     unsigned long fstype,
306fa1
+					     struct amd_entry *entry)
306fa1
+{
306fa1
+	if (fstype != AMD_MOUNT_TYPE_LOFS) {
306fa1
+		if (!entry->dev) {
306fa1
+			error(logopt, MODPREFIX
306fa1
+			      "%s: mount device not given", entry->type);
306fa1
+			return 0;
306fa1
+		}
306fa1
+	} else {
306fa1
+		if (!entry->rfs) {
306fa1
+			/*
306fa1
+			 * Can't use entry->type as the mount type to reprot
306fa1
+			 * the error since entry->type == "bind" not "lofs".
306fa1
+			 */
306fa1
+			error(logopt, "lofs: mount device not given");
306fa1
+			return 0;
306fa1
+		}
306fa1
+	}
306fa1
+	return 1;
306fa1
+}
306fa1
+
306fa1
+static unsigned int validate_host_options(unsigned int logopt,
306fa1
+					  struct amd_entry *entry)
306fa1
+{
306fa1
+	/*
306fa1
+	 * Not really that useful since rhost is always non-null
306fa1
+	 * because it will have the the value of the host name if
306fa1
+	 * it isn't set in the map entry.
306fa1
+	 */
306fa1
+	if (!entry->rhost) {
306fa1
+		error(logopt, MODPREFIX
306fa1
+		      "%s: remote host name not given", entry->type);
306fa1
+		return 0;
306fa1
+	}
306fa1
+	return 1;
306fa1
+}
306fa1
+
306fa1
 static int amd_mount(struct autofs_point *ap, const char *name,
306fa1
 		     struct amd_entry *entry, struct map_source *source,
306fa1
 		     struct substvar *sv, unsigned int flags,
306fa1
@@ -1191,35 +1273,52 @@ static int amd_mount(struct autofs_point *ap, const char *name,
306fa1
 
306fa1
 	switch (fstype) {
306fa1
 	case AMD_MOUNT_TYPE_AUTO:
306fa1
+		if (!validate_auto_options(ap->logopt, entry))
306fa1
+			return 1;
306fa1
 		ret = do_auto_mount(ap, name, entry, flags);
306fa1
 		break;
306fa1
 
306fa1
 	case AMD_MOUNT_TYPE_LOFS:
306fa1
+		if (!validate_generic_options(ap->logopt, fstype, entry))
306fa1
+			return 1;
306fa1
 		ret = do_generic_mount(ap, name, entry, entry->rfs, flags);
306fa1
 		break;
306fa1
 
306fa1
 	case AMD_MOUNT_TYPE_EXT:
306fa1
 	case AMD_MOUNT_TYPE_XFS:
306fa1
+		if (!validate_generic_options(ap->logopt, fstype, entry))
306fa1
+			return 1;
306fa1
 		ret = do_generic_mount(ap, name, entry, entry->dev, flags);
306fa1
 		break;
306fa1
 
306fa1
 	case AMD_MOUNT_TYPE_NFS:
306fa1
+		if (!validate_nfs_options(ap->logopt, entry))
306fa1
+			return 1;
306fa1
 		ret = do_nfs_mount(ap, name, entry, flags);
306fa1
 		break;
306fa1
 
306fa1
 	case AMD_MOUNT_TYPE_NFSL:
306fa1
+		if (!validate_nfs_options(ap->logopt, entry) ||
306fa1
+		    !validate_link_options(ap->logopt, entry))
306fa1
+			return 1;
306fa1
 		ret = do_nfsl_mount(ap, name, entry, sv, flags);
306fa1
 		break;
306fa1
 
306fa1
 	case AMD_MOUNT_TYPE_LINK:
306fa1
+		if (!validate_link_options(ap->logopt, entry))
306fa1
+			return 1;
306fa1
 		ret = do_link_mount(ap, name, entry, flags);
306fa1
 		break;
306fa1
 
306fa1
 	case AMD_MOUNT_TYPE_LINKX:
306fa1
+		if (!validate_link_options(ap->logopt, entry))
306fa1
+			return 1;
306fa1
 		ret = do_linkx_mount(ap, name, entry, flags);
306fa1
 		break;
306fa1
 
306fa1
 	case AMD_MOUNT_TYPE_HOST:
306fa1
+		if (!validate_host_options(ap->logopt, entry))
306fa1
+			return 1;
306fa1
 		ret = do_host_mount(ap, name, entry, source, flags);
306fa1
 		break;
306fa1