Blob Blame History Raw
From 53f7f75ebf2a5086d63989bdf1da0d42983d6448 Mon Sep 17 00:00:00 2001
From: Alexander Bokovoy <abokovoy@redhat.com>
Date: Fri, 3 Nov 2017 23:49:19 +0200
Subject: [PATCH 17/18] Fix nss_sss callers

---
 src/back-sch-nss_sss.c | 82 +++++++++++++++++++++++++++++++++++---------------
 1 file changed, 57 insertions(+), 25 deletions(-)

diff --git a/src/back-sch-nss_sss.c b/src/back-sch-nss_sss.c
index e3e6628..2b1b8b0 100644
--- a/src/back-sch-nss_sss.c
+++ b/src/back-sch-nss_sss.c
@@ -52,6 +52,20 @@ struct nss_ops_ctx {
 			      int *errnop);
 };
 
+void backend_nss_free_context(struct nss_ops_ctx **nss_context)
+{
+	if (nss_context == NULL) {
+		return;
+	}
+
+	if ((*nss_context)->dl_handle != NULL) {
+		dlclose((*nss_context)->dl_handle);
+	}
+
+	free((*nss_context));
+	*nss_context = NULL;
+}
+
 void backend_nss_init_context(struct nss_ops_ctx **nss_context)
 {
 	struct nss_ops_ctx *ctx = NULL;
@@ -105,21 +119,6 @@ fail:
 	return;
 }
 
-void
-backend_nss_free_context(struct nss_ops_ctx **nss_context)
-{
-	if (nss_context == NULL) {
-		return;
-	}
-
-	if ((*nss_context)->dl_handle != NULL) {
-		dlclose((*nss_context)->dl_handle);
-	}
-
-	free((*nss_context));
-	*nss_context = NULL;
-}
-
 
 /* Following three functions cannot be implemented with nss_sss.so.2
  * As result, we simply do nothing here */
@@ -144,15 +143,22 @@ enum nss_status backend_nss_getpwnam(struct nss_ops_ctx *nss_context,
 				     char *buffer, size_t buflen,
 				     struct passwd **result,
 				     int *lerrno) {
+	enum nss_status ret;
 
 	if (nss_context == NULL) {
 		return NSS_STATUS_UNAVAIL;
 	}
 
-	return (enum nss_status)
+	ret = (enum nss_status)
 		nss_context->getpwnam_r(name, pwd,
 					buffer, buflen,
-					result, lerrno);
+					lerrno);
+
+	if ((ret == NSS_STATUS_SUCCESS) && (result != NULL)) {
+		*result = pwd;
+	}
+
+	return ret;
 }
 
 enum nss_status backend_nss_getpwuid(struct nss_ops_ctx *nss_context,
@@ -160,15 +166,22 @@ enum nss_status backend_nss_getpwuid(struct nss_ops_ctx *nss_context,
 				     char *buffer, size_t buflen,
 				     struct passwd **result,
 				     int *lerrno) {
+	enum nss_status ret;
 
 	if (nss_context == NULL) {
 		return NSS_STATUS_UNAVAIL;
 	}
 
-	return (enum nss_status)
+	ret = (enum nss_status)
 		nss_context->getpwuid_r(uid, pwd,
 					buffer, buflen,
-					result, lerrno);
+					lerrno);
+
+	if ((ret == NSS_STATUS_SUCCESS) && (result != NULL)) {
+		*result = pwd;
+	}
+
+	return ret;
 }
 
 enum nss_status backend_nss_getgrnam(struct nss_ops_ctx *nss_context,
@@ -176,15 +189,22 @@ enum nss_status backend_nss_getgrnam(struct nss_ops_ctx *nss_context,
 				     char *buffer, size_t buflen,
 				     struct group **result,
 				     int *lerrno) {
+	enum nss_status ret;
 
 	if (nss_context == NULL) {
 		return NSS_STATUS_UNAVAIL;
 	}
 
-	return (enum nss_status)
+	ret = (enum nss_status)
 		nss_context->getgrnam_r(name, grp,
 					buffer, buflen,
-					result, lerrno);
+					lerrno);
+
+	if ((ret == NSS_STATUS_SUCCESS) && (result != NULL)) {
+		*result = grp;
+	}
+
+	return ret;
 }
 
 enum nss_status backend_nss_getgrgid(struct nss_ops_ctx *nss_context,
@@ -193,21 +213,31 @@ enum nss_status backend_nss_getgrgid(struct nss_ops_ctx *nss_context,
 				     struct group **result,
 				     int *lerrno) {
 
+	enum nss_status ret;
+
 	if (nss_context == NULL) {
 		return NSS_STATUS_UNAVAIL;
 	}
 
-	return (enum nss_status)
+	ret = (enum nss_status)
 		nss_context->getgrgid_r(gid, grp,
 					buffer, buflen,
-					result, lerrno);
+					lerrno);
+
+	if ((ret == NSS_STATUS_SUCCESS) && (result != NULL)) {
+		*result = grp;
+	}
+
+	return ret;
 }
 
 enum nss_status backend_nss_getgrouplist(struct nss_ops_ctx *nss_context,
 					 const char *name, gid_t group,
 					 gid_t *groups, int *ngroups,
 					 int *lerrno) {
+
 	enum nss_status ret = NSS_STATUS_UNAVAIL;
+	long int size = 0;
 
 	if (nss_context == NULL) {
 		return NSS_STATUS_UNAVAIL;
@@ -220,12 +250,14 @@ enum nss_status backend_nss_getgrouplist(struct nss_ops_ctx *nss_context,
 
 	ret = nss_context->initgroups_dyn(name, group,
 					  &nss_context->initgroups_start,
-					  &ngroups, &groups,
-					  -1, &lerrno);
+					  &size, &groups,
+					  -1, lerrno);
 	if (ret == NSS_STATUS_SUCCESS) {
 		nss_context->initgroups_start = 0;
 	}
 
+	*ngroups = (int) size;
+
 	return ret;
 }
 
-- 
2.13.6