Blame SOURCES/autofs-5.1.6-add-support-for-new-sss-autofs-proto-version-call.patch

1b50e3
autofs-5.1.6 - add support for new sss autofs proto version call
1b50e3
1b50e3
From: Ian Kent <raven@themaw.net>
1b50e3
1b50e3
Add sss protocol feature version function existence check and local get
1b50e3
function.
1b50e3
1b50e3
Signed-off-by: Ian Kent <raven@themaw.net>
1b50e3
---
1b50e3
 CHANGELOG            |    1 +
1b50e3
 modules/lookup_sss.c |   44 ++++++++++++++++++++++++++++++++++++++++++++
1b50e3
 2 files changed, 45 insertions(+)
1b50e3
1b50e3
diff --git a/CHANGELOG b/CHANGELOG
1b50e3
index 1830730..7c22aa1 100644
1b50e3
--- a/CHANGELOG
1b50e3
+++ b/CHANGELOG
1b50e3
@@ -96,6 +96,7 @@ xx/xx/2018 autofs-5.1.5
1b50e3
 - fix sss_master_map_wait timing.
1b50e3
 - add sss ECONREFUSED return handling.
1b50e3
 - use mapname in sss context for setautomntent().
1b50e3
+- add support for new sss autofs proto version call.
1b50e3
 
1b50e3
 19/12/2017 autofs-5.1.4
1b50e3
 - fix spec file url.
1b50e3
diff --git a/modules/lookup_sss.c b/modules/lookup_sss.c
1b50e3
index c44c55d..3819981 100644
1b50e3
--- a/modules/lookup_sss.c
1b50e3
+++ b/modules/lookup_sss.c
1b50e3
@@ -37,11 +37,29 @@
1b50e3
 
1b50e3
 #define SSS_SO_NAME "libsss_autofs"
1b50e3
 
1b50e3
+/* If the sss library protocol version is greater than 0 there are
1b50e3
+ * more possibile error returns from the sss autofs library calls.
1b50e3
+ *
1b50e3
+ * If ECONNREFUSED is returned then sssd is not running or not
1b50e3
+ * configured on the system, immediately return an unavailable
1b50e3
+ * status.
1b50e3
+ *
1b50e3
+ * A return of EHOSTDOWN means sss backend server is down so we
1b50e3
+ * should retry.
1b50e3
+ *
1b50e3
+ * With older sss ilibrary we can get a return of ENOENT for the
1b50e3
+ * above cases so also wait in that case since we can't be sure
1b50e3
+ * the map doesn't exist.
1b50e3
+ */
1b50e3
+#define SSS_PROTO_VERSION 1
1b50e3
+
1b50e3
+unsigned int _sss_auto_protocol_version(unsigned int);
1b50e3
 int _sss_setautomntent(const char *, void **);
1b50e3
 int _sss_getautomntent_r(char **, char **, void *);
1b50e3
 int _sss_getautomntbyname_r(char *, char **, void *);
1b50e3
 int _sss_endautomntent(void **);
1b50e3
 
1b50e3
+typedef unsigned int (*protocol_version_t) (unsigned int);
1b50e3
 typedef int (*setautomntent_t) (const char *, void **);
1b50e3
 typedef int (*getautomntent_t) (char **, char **, void *);
1b50e3
 typedef int (*getautomntbyname_t) (char *, char **, void *);
1b50e3
@@ -50,6 +68,7 @@ typedef int (*endautomntent_t) (void **);
1b50e3
 struct lookup_context {
1b50e3
 	const char *mapname;
1b50e3
     	void *dlhandle;
1b50e3
+	protocol_version_t protocol_version;
1b50e3
 	setautomntent_t setautomntent;
1b50e3
 	getautomntent_t getautomntent_r;
1b50e3
 	getautomntbyname_t getautomntbyname_r;
1b50e3
@@ -58,6 +77,8 @@ struct lookup_context {
1b50e3
 };
1b50e3
 
1b50e3
 int lookup_version = AUTOFS_LOOKUP_VERSION;	/* Required by protocol */
1b50e3
+int sss_proto_version = SSS_PROTO_VERSION;	/* 0 => initial version,
1b50e3
+						 * >= 1 => new error handling. */
1b50e3
 
1b50e3
 static int open_sss_lib(struct lookup_context *ctxt)
1b50e3
 {
1b50e3
@@ -78,6 +99,11 @@ static int open_sss_lib(struct lookup_context *ctxt)
1b50e3
 		return 1;
1b50e3
 	ctxt->dlhandle = dh;
1b50e3
 
1b50e3
+	/* Don't fail on NULL, it's simply not present in this version of the
1b50e3
+	 * sss autofs library.
1b50e3
+	 */
1b50e3
+	ctxt->protocol_version = (protocol_version_t) dlsym(dh, "_sss_auto_protocol_version");
1b50e3
+
1b50e3
 	ctxt->setautomntent = (setautomntent_t) dlsym(dh, "_sss_setautomntent");
1b50e3
 	if (!ctxt->setautomntent)
1b50e3
 		goto lib_names_fail;
1b50e3
@@ -193,6 +219,7 @@ int lookup_reinit(const char *mapfmt,
1b50e3
 	}
1b50e3
 
1b50e3
 	new->dlhandle = ctxt->dlhandle;
1b50e3
+	new->protocol_version = ctxt->protocol_version;
1b50e3
 	new->setautomntent = ctxt->setautomntent;
1b50e3
 	new->getautomntent_r = ctxt->getautomntent_r;
1b50e3
 	new->getautomntbyname_r = ctxt->getautomntbyname_r;
1b50e3
@@ -219,6 +246,23 @@ static int setautomntent(unsigned int logopt,
1b50e3
 	return ret;
1b50e3
 }
1b50e3
 
1b50e3
+static unsigned int proto_version(struct lookup_context *ctxt)
1b50e3
+{
1b50e3
+	unsigned int proto_version = 0;
1b50e3
+
1b50e3
+	if (ctxt->protocol_version) {
1b50e3
+		/* If ctxt->protocol_version() is defined it's assumed
1b50e3
+		 * that for sss_proto_version <= sss autofs library
1b50e3
+		 * protocol version ctxt->protocol_version() will
1b50e3
+		 * return the version requested by autofs to indicate
1b50e3
+		 * it userstands what the autofs module is capable of
1b50e3
+		 * handling.
1b50e3
+		 */
1b50e3
+		proto_version = ctxt->protocol_version(sss_proto_version);
1b50e3
+	}
1b50e3
+	return proto_version;
1b50e3
+}
1b50e3
+
1b50e3
 static int setautomntent_wait(unsigned int logopt,
1b50e3
 			      struct lookup_context *ctxt,
1b50e3
 			      void **sss_ctxt, unsigned int retries)