From 2a3accc78bb9658401b33ad5a3a2f1bc4bc3c269 Mon Sep 17 00:00:00 2001
From: Sumit Bose <sbose@redhat.com>
Date: Thu, 7 Dec 2017 17:42:45 +0100
Subject: [PATCH 86/86] nss-idmap: allow NULL result in *_timeout calls
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
To make the *_timeout calls more resilient checks are added if the
result parameter is NULL. It will not be used in this case.
Related to https://pagure.io/SSSD/sssd/issue/2478
Reviewed-by: Fabiano FidĂȘncio <fidencio@redhat.com>
Reviewed-by: Alexander Bokovoy <abokovoy@redhat.com>
(cherry picked from commit bba068c535d23eebff61f592bddb3a6438446d6f)
---
src/sss_client/idmap/sss_nss_ex.c | 46 +++++++++++++++++++++++++++------------
1 file changed, 32 insertions(+), 14 deletions(-)
diff --git a/src/sss_client/idmap/sss_nss_ex.c b/src/sss_client/idmap/sss_nss_ex.c
index dcd9619a8b07ced7498f61b7e809fa46ebffe09e..861b1e1e92db4f7e6e8d74a812dc3c9220711773 100644
--- a/src/sss_client/idmap/sss_nss_ex.c
+++ b/src/sss_client/idmap/sss_nss_ex.c
@@ -367,13 +367,17 @@ int sss_nss_getpwnam_timeout(const char *name, struct passwd *pwd,
return ret;
}
- *result = NULL;
-
ret = sss_get_ex(&inp, flags, timeout);
free(discard_const(inp.rd.data));
- if (ret == 0) {
- *result = inp.result.pwrep.result;
+
+ if (result != NULL) {
+ if (ret == 0) {
+ *result = inp.result.pwrep.result;
+ } else {
+ *result = NULL;
+ }
}
+
return ret;
}
@@ -395,12 +399,17 @@ int sss_nss_getpwuid_timeout(uid_t uid, struct passwd *pwd,
SAFEALIGN_COPY_UINT32(&req_data[0], &uid, NULL);
SAFEALIGN_COPY_UINT32(&req_data[1], &flags, NULL);
- *result = NULL;
ret = sss_get_ex(&inp, flags, timeout);
- if (ret == 0) {
- *result = inp.result.pwrep.result;
+
+ if (result != NULL) {
+ if (ret == 0) {
+ *result = inp.result.pwrep.result;
+ } else {
+ *result = NULL;
+ }
}
+
return ret;
}
@@ -421,13 +430,17 @@ int sss_nss_getgrnam_timeout(const char *name, struct group *grp,
return ret;
}
- *result = NULL;
-
ret = sss_get_ex(&inp, flags, timeout);
free(discard_const(inp.rd.data));
- if (ret == 0) {
- *result = inp.result.grrep.result;
+
+ if (result != NULL) {
+ if (ret == 0) {
+ *result = inp.result.grrep.result;
+ } else {
+ *result = NULL;
+ }
}
+
return ret;
}
@@ -448,12 +461,17 @@ int sss_nss_getgrgid_timeout(gid_t gid, struct group *grp,
SAFEALIGN_COPY_UINT32(&req_data[0], &gid, NULL);
SAFEALIGN_COPY_UINT32(&req_data[1], &flags, NULL);
- *result = NULL;
ret = sss_get_ex(&inp, flags, timeout);
- if (ret == 0) {
- *result = inp.result.grrep.result;
+
+ if (result != NULL) {
+ if (ret == 0) {
+ *result = inp.result.grrep.result;
+ } else {
+ *result = NULL;
+ }
}
+
return ret;
}
--
2.14.3