ad2a64
From 53f7f75ebf2a5086d63989bdf1da0d42983d6448 Mon Sep 17 00:00:00 2001
ad2a64
From: Alexander Bokovoy <abokovoy@redhat.com>
ad2a64
Date: Fri, 3 Nov 2017 23:49:19 +0200
ad2a64
Subject: [PATCH 17/18] Fix nss_sss callers
ad2a64
ad2a64
---
ad2a64
 src/back-sch-nss_sss.c | 82 +++++++++++++++++++++++++++++++++++---------------
ad2a64
 1 file changed, 57 insertions(+), 25 deletions(-)
ad2a64
ad2a64
diff --git a/src/back-sch-nss_sss.c b/src/back-sch-nss_sss.c
ad2a64
index e3e6628..2b1b8b0 100644
ad2a64
--- a/src/back-sch-nss_sss.c
ad2a64
+++ b/src/back-sch-nss_sss.c
ad2a64
@@ -52,6 +52,20 @@ struct nss_ops_ctx {
ad2a64
 			      int *errnop);
ad2a64
 };
ad2a64
 
ad2a64
+void backend_nss_free_context(struct nss_ops_ctx **nss_context)
ad2a64
+{
ad2a64
+	if (nss_context == NULL) {
ad2a64
+		return;
ad2a64
+	}
ad2a64
+
ad2a64
+	if ((*nss_context)->dl_handle != NULL) {
ad2a64
+		dlclose((*nss_context)->dl_handle);
ad2a64
+	}
ad2a64
+
ad2a64
+	free((*nss_context));
ad2a64
+	*nss_context = NULL;
ad2a64
+}
ad2a64
+
ad2a64
 void backend_nss_init_context(struct nss_ops_ctx **nss_context)
ad2a64
 {
ad2a64
 	struct nss_ops_ctx *ctx = NULL;
ad2a64
@@ -105,21 +119,6 @@ fail:
ad2a64
 	return;
ad2a64
 }
ad2a64
 
ad2a64
-void
ad2a64
-backend_nss_free_context(struct nss_ops_ctx **nss_context)
ad2a64
-{
ad2a64
-	if (nss_context == NULL) {
ad2a64
-		return;
ad2a64
-	}
ad2a64
-
ad2a64
-	if ((*nss_context)->dl_handle != NULL) {
ad2a64
-		dlclose((*nss_context)->dl_handle);
ad2a64
-	}
ad2a64
-
ad2a64
-	free((*nss_context));
ad2a64
-	*nss_context = NULL;
ad2a64
-}
ad2a64
-
ad2a64
 
ad2a64
 /* Following three functions cannot be implemented with nss_sss.so.2
ad2a64
  * As result, we simply do nothing here */
ad2a64
@@ -144,15 +143,22 @@ enum nss_status backend_nss_getpwnam(struct nss_ops_ctx *nss_context,
ad2a64
 				     char *buffer, size_t buflen,
ad2a64
 				     struct passwd **result,
ad2a64
 				     int *lerrno) {
ad2a64
+	enum nss_status ret;
ad2a64
 
ad2a64
 	if (nss_context == NULL) {
ad2a64
 		return NSS_STATUS_UNAVAIL;
ad2a64
 	}
ad2a64
 
ad2a64
-	return (enum nss_status)
ad2a64
+	ret = (enum nss_status)
ad2a64
 		nss_context->getpwnam_r(name, pwd,
ad2a64
 					buffer, buflen,
ad2a64
-					result, lerrno);
ad2a64
+					lerrno);
ad2a64
+
ad2a64
+	if ((ret == NSS_STATUS_SUCCESS) && (result != NULL)) {
ad2a64
+		*result = pwd;
ad2a64
+	}
ad2a64
+
ad2a64
+	return ret;
ad2a64
 }
ad2a64
 
ad2a64
 enum nss_status backend_nss_getpwuid(struct nss_ops_ctx *nss_context,
ad2a64
@@ -160,15 +166,22 @@ enum nss_status backend_nss_getpwuid(struct nss_ops_ctx *nss_context,
ad2a64
 				     char *buffer, size_t buflen,
ad2a64
 				     struct passwd **result,
ad2a64
 				     int *lerrno) {
ad2a64
+	enum nss_status ret;
ad2a64
 
ad2a64
 	if (nss_context == NULL) {
ad2a64
 		return NSS_STATUS_UNAVAIL;
ad2a64
 	}
ad2a64
 
ad2a64
-	return (enum nss_status)
ad2a64
+	ret = (enum nss_status)
ad2a64
 		nss_context->getpwuid_r(uid, pwd,
ad2a64
 					buffer, buflen,
ad2a64
-					result, lerrno);
ad2a64
+					lerrno);
ad2a64
+
ad2a64
+	if ((ret == NSS_STATUS_SUCCESS) && (result != NULL)) {
ad2a64
+		*result = pwd;
ad2a64
+	}
ad2a64
+
ad2a64
+	return ret;
ad2a64
 }
ad2a64
 
ad2a64
 enum nss_status backend_nss_getgrnam(struct nss_ops_ctx *nss_context,
ad2a64
@@ -176,15 +189,22 @@ enum nss_status backend_nss_getgrnam(struct nss_ops_ctx *nss_context,
ad2a64
 				     char *buffer, size_t buflen,
ad2a64
 				     struct group **result,
ad2a64
 				     int *lerrno) {
ad2a64
+	enum nss_status ret;
ad2a64
 
ad2a64
 	if (nss_context == NULL) {
ad2a64
 		return NSS_STATUS_UNAVAIL;
ad2a64
 	}
ad2a64
 
ad2a64
-	return (enum nss_status)
ad2a64
+	ret = (enum nss_status)
ad2a64
 		nss_context->getgrnam_r(name, grp,
ad2a64
 					buffer, buflen,
ad2a64
-					result, lerrno);
ad2a64
+					lerrno);
ad2a64
+
ad2a64
+	if ((ret == NSS_STATUS_SUCCESS) && (result != NULL)) {
ad2a64
+		*result = grp;
ad2a64
+	}
ad2a64
+
ad2a64
+	return ret;
ad2a64
 }
ad2a64
 
ad2a64
 enum nss_status backend_nss_getgrgid(struct nss_ops_ctx *nss_context,
ad2a64
@@ -193,21 +213,31 @@ enum nss_status backend_nss_getgrgid(struct nss_ops_ctx *nss_context,
ad2a64
 				     struct group **result,
ad2a64
 				     int *lerrno) {
ad2a64
 
ad2a64
+	enum nss_status ret;
ad2a64
+
ad2a64
 	if (nss_context == NULL) {
ad2a64
 		return NSS_STATUS_UNAVAIL;
ad2a64
 	}
ad2a64
 
ad2a64
-	return (enum nss_status)
ad2a64
+	ret = (enum nss_status)
ad2a64
 		nss_context->getgrgid_r(gid, grp,
ad2a64
 					buffer, buflen,
ad2a64
-					result, lerrno);
ad2a64
+					lerrno);
ad2a64
+
ad2a64
+	if ((ret == NSS_STATUS_SUCCESS) && (result != NULL)) {
ad2a64
+		*result = grp;
ad2a64
+	}
ad2a64
+
ad2a64
+	return ret;
ad2a64
 }
ad2a64
 
ad2a64
 enum nss_status backend_nss_getgrouplist(struct nss_ops_ctx *nss_context,
ad2a64
 					 const char *name, gid_t group,
ad2a64
 					 gid_t *groups, int *ngroups,
ad2a64
 					 int *lerrno) {
ad2a64
+
ad2a64
 	enum nss_status ret = NSS_STATUS_UNAVAIL;
ad2a64
+	long int size = 0;
ad2a64
 
ad2a64
 	if (nss_context == NULL) {
ad2a64
 		return NSS_STATUS_UNAVAIL;
ad2a64
@@ -220,12 +250,14 @@ enum nss_status backend_nss_getgrouplist(struct nss_ops_ctx *nss_context,
ad2a64
 
ad2a64
 	ret = nss_context->initgroups_dyn(name, group,
ad2a64
 					  &nss_context->initgroups_start,
ad2a64
-					  &ngroups, &groups,
ad2a64
-					  -1, &lerrno);
ad2a64
+					  &size, &groups,
ad2a64
+					  -1, lerrno);
ad2a64
 	if (ret == NSS_STATUS_SUCCESS) {
ad2a64
 		nss_context->initgroups_start = 0;
ad2a64
 	}
ad2a64
 
ad2a64
+	*ngroups = (int) size;
ad2a64
+
ad2a64
 	return ret;
ad2a64
 }
ad2a64
 
ad2a64
-- 
ad2a64
2.13.6
ad2a64