From 9aeef7726043762f7a0e0dacee18819106a34ec2 Mon Sep 17 00:00:00 2001
From: Ian Kent <raven@themaw.net>
Date: Mon, 10 Aug 2015 11:56:52 +0800
Subject: [PATCH] autofs-5.1.1 - add configuration option to use fqdn in mounts

When a server name returns multiple IP addresses autofs uses the IP
address when performing the mount to ensure that the the host proximity
order is respected, and that servers that aren't responding aren't
tried.

But sometimes people need to use the server name for the mount so
add a configuration option to enable that.

Signed-off-by: Ian Kent <raven@themaw.net>
---
 CHANGELOG                      |    1 +
 include/defaults.h             |    3 +++
 lib/defaults.c                 |   14 ++++++++++++++
 modules/mount_nfs.c            |    3 ++-
 modules/replicated.c           |    6 ++++++
 samples/autofs.conf.default.in |    8 ++++++++
 6 files changed, 34 insertions(+), 1 deletion(-)

--- a/CHANGELOG
+++ b/CHANGELOG
@@ -365,6 +365,7 @@ Post-5.0.6 patches included in the SUSE
 - add "@network" and .domain.name export check.
 - fix display map name in mount entry for "-hosts" map.
 - update kernel patches.
+- add configuration option to use fqdn in mounts.
 
 4/1/2007 autofs-5.0.1 rc3
 -------------------------
--- a/include/defaults.h
+++ b/include/defaults.h
@@ -44,6 +44,8 @@
 
 #define DEFAULT_MAP_HASH_TABLE_SIZE	1024
 
+#define DEFAULT_USE_HOSTNAME_FOR_MOUNTS	"0"
+
 struct ldap_schema;
 struct ldap_searchdn;
 
@@ -69,6 +71,7 @@ unsigned int defaults_get_mount_wait(voi
 unsigned int defaults_get_umount_wait(void);
 const char *defaults_get_auth_conf_file(void);
 unsigned int defaults_get_map_hash_table_size(void);
+unsigned int defaults_use_hostname_for_mounts(void);
 
 #endif
 
--- a/lib/defaults.c
+++ b/lib/defaults.c
@@ -26,6 +26,8 @@
 #define DEFAULTS_CONFIG_FILE		AUTOFS_CONF_DIR "/autofs"
 #define MAX_LINE_LEN			256
 
+#define ENV_NAME_USE_HOSTNAME_FOR_MOUNTS	"USE_HOSTNAME_FOR_MOUNTS"
+
 #define ENV_NAME_MASTER_MAP		"MASTER_MAP_NAME"
 
 #define ENV_NAME_TIMEOUT		"TIMEOUT"
@@ -317,6 +319,7 @@ unsigned int defaults_read_config(unsign
 		    check_set_config_value(key, ENV_NAME_TIMEOUT, value, to_syslog) ||
 		    check_set_config_value(key, ENV_NAME_NEGATIVE_TIMEOUT, value, to_syslog) ||
 		    check_set_config_value(key, ENV_NAME_BROWSE_MODE, value, to_syslog) ||
+		    check_set_config_value(key, ENV_NAME_USE_HOSTNAME_FOR_MOUNTS, value, to_syslog) ||
 		    check_set_config_value(key, ENV_NAME_LOGGING, value, to_syslog) ||
 		    check_set_config_value(key, ENV_LDAP_TIMEOUT, value, to_syslog) ||
 		    check_set_config_value(key, ENV_LDAP_NETWORK_TIMEOUT, value, to_syslog) ||
@@ -382,6 +385,17 @@ unsigned int defaults_get_timeout(void)
 	return (unsigned int) timeout;
 }
 
+unsigned int defaults_use_hostname_for_mounts(void)
+{
+	int res;
+
+	res = get_env_yesno(ENV_NAME_USE_HOSTNAME_FOR_MOUNTS);
+	if (res < 0)
+		res = atoi(DEFAULT_USE_HOSTNAME_FOR_MOUNTS);
+
+	return res;
+}
+
 unsigned int defaults_get_negative_timeout(void)
 {
 	long n_timeout;
--- a/modules/mount_nfs.c
+++ b/modules/mount_nfs.c
@@ -229,7 +229,8 @@ int mount_mount(struct autofs_point *ap,
 
 		/* Not a local host - do an NFS mount */
 
-		if (this->rr && this->addr) {
+		if (this->rr && this->addr &&
+		    !defaults_use_hostname_for_mounts()) {
 			socklen_t len = INET6_ADDRSTRLEN;
 			char n_buf[len + 1];
 			const char *n_addr;
--- a/modules/replicated.c
+++ b/modules/replicated.c
@@ -901,6 +901,12 @@ int prune_host_list(unsigned logopt, str
 	if (!*list)
 		return 0;
 
+	/* If we're using the host name then there's no point probing
+	 * avialability and respose time.
+	 */
+	if (defaults_use_hostname_for_mounts())
+		return 1;
+
 	/* Use closest hosts to choose NFS version */
 
 	first = *list;
--- a/samples/autofs.conf.default.in
+++ b/samples/autofs.conf.default.in
@@ -69,6 +69,14 @@ BROWSE_MODE="no"
 #	     after one hour, whichever is less.
 #
 #LDAP_URI=""
+# USE_HOSTNAME_FOR_MOUNTS - nfs mounts where the host name resolves
+# 			to more than one IP address normally need
+# 			to use the IP address to esure a mount to
+# 			a host that isn't responding isn't done.
+# 			If that behaviour is not wanted then set
+#			ths to "yes", default is "no".
+#
+#USE_HOSTNAME_FOR_MOUNTS = "no"
 #
 # LDAP__TIMEOUT - timeout value for the synchronous API  calls
 #		  (default is LDAP library default).
