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

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