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

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