44937c
From 0f700cf71f5531fb6c863990216aa1eb88970dc8 Mon Sep 17 00:00:00 2001
44937c
From: Alexander Bokovoy <abokovoy@redhat.com>
44937c
Date: Wed, 16 Jun 2021 11:08:21 +0300
44937c
Subject: [PATCH] back-sch-nss: only loop if asked to try again
44937c
44937c
slapi-nis uses sss-idmap library to discover user group membership.  Its
44937c
sss_nss_getgrouplist_timeout() function can return timeout errors as
44937c
well which might cause a busy looping.  sss_nss_getgrouplist_timeout()
44937c
will return ERANGE which is translated by slapi-nis to NSS_STATUS_TRYAGAIN.
44937c
44937c
Fixes: rhbz#1967179
44937c
44937c
Signed-off-by: Alexander Bokovoy <abokovoy@redhat.com>
44937c
---
44937c
 src/back-sch-nss.c | 13 ++++++++-----
44937c
 1 file changed, 8 insertions(+), 5 deletions(-)
44937c
44937c
diff --git a/src/back-sch-nss.c b/src/back-sch-nss.c
44937c
index df04a96..b595f3b 100644
44937c
--- a/src/back-sch-nss.c
44937c
+++ b/src/back-sch-nss.c
44937c
@@ -589,19 +589,22 @@ repeat:
44937c
 		return NULL;
44937c
 	}
44937c
 
44937c
-	do {
44937c
+	for(rc = NSS_STATUS_TRYAGAIN; rc == NSS_STATUS_TRYAGAIN;) {
44937c
 		rc = backend_nss_getgrouplist(ctx, user_name, pwd.pw_gid,
44937c
 					      grouplist, &ngroups,
44937c
 					      &lerrno);
44937c
-		if ((rc != NSS_STATUS_SUCCESS)) {
44937c
-			tmp_list = realloc(grouplist, ngroups * sizeof(gid_t));
44937c
-			if (tmp_list == NULL) {
44937c
+		if (rc == NSS_STATUS_TRYAGAIN) {
44937c
+			tmp_list = NULL;
44937c
+			if (lerrno == ERANGE) {
44937c
+				tmp_list = realloc(grouplist, ngroups * sizeof(gid_t));
44937c
+			}
44937c
+			if ((tmp_list == NULL) || (lerrno == ENOMEM)) {
44937c
 				free(grouplist);
44937c
 				return NULL;
44937c
 			}
44937c
 			grouplist = tmp_list;
44937c
 		}
44937c
-	} while (rc != NSS_STATUS_SUCCESS);
44937c
+	}
44937c
 
44937c
 	entries = calloc(ngroups + 1, sizeof(entries[0]));
44937c
 	if (entries == NULL) {
44937c
-- 
44937c
2.31.1
44937c