autofs-5.1.4 - fix incorrect locking in sss lookup

From: Ian Kent <raven@themaw.net>

Commit 766e0f6c4, autofs-5.0.7 - fix fix wildcard multi map regression,
introduced a deadlock during restart when the sss modules is used.

Looking at the comment above the code which takes the lock it clearly
does this incorrectly.

Signed-off-by: Ian Kent <raven@themaw.net>
---
 CHANGELOG            |    1 +
 modules/lookup_sss.c |    4 ++--
 2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/CHANGELOG b/CHANGELOG
index 3bf86e84..aa485e8f 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -37,6 +37,7 @@ xx/xx/2018 autofs-5.1.5
 - set bind mount as propagation slave.
 - add master map pseudo options for mount propagation.
 - fix use after free in parse_ldap_config().
+- fix incorrect locking in sss lookup.
 
 19/12/2017 autofs-5.1.4
 - fix spec file url.
diff --git a/modules/lookup_sss.c b/modules/lookup_sss.c
index 88ec1693..78598300 100644
--- a/modules/lookup_sss.c
+++ b/modules/lookup_sss.c
@@ -786,9 +786,9 @@ int lookup_mount(struct autofs_point *ap, const char *name, int name_len, void *
 	 * when we're starting up so just take the readlock in that
 	 */
 	if (ap->flags & MOUNT_FLAG_REMOUNT)
-		cache_writelock(mc);
-	else
 		cache_readlock(mc);
+	else
+		cache_writelock(mc);
 	me = cache_lookup(mc, key);
 	/* Stale mapent => check for entry in alternate source or wildcard */
 	if (me && !me->mapent) {