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

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