[SCM] Samba Shared Repository - branch v3-2-test updated - release-3-2-0pre2-661-gc78f4dc

Stefan Metzmacher metze at samba.org
Sun Apr 6 11:43:15 GMT 2008


The branch, v3-2-test has been updated
       via  c78f4dc043523842cf42f1a3fd4e8f3855518efa (commit)
       via  596d030b976102e7476a2460fce355914c4e8210 (commit)
      from  c274fe7d21badb42ca8d4d1115ae6bffdb19485f (commit)

http://gitweb.samba.org/?p=samba.git;a=shortlog;h=v3-2-test


- Log -----------------------------------------------------------------
commit c78f4dc043523842cf42f1a3fd4e8f3855518efa
Author: Stefan Metzmacher <metze at samba.org>
Date:   Sun Apr 6 11:58:58 2008 +0200

    wbinfo: make use of wbcGetGroups()
    
    metze

commit 596d030b976102e7476a2460fce355914c4e8210
Author: Stefan Metzmacher <metze at samba.org>
Date:   Sun Apr 6 11:55:57 2008 +0200

    libwbclient: add wbcGetGroups()
    
    metze

-----------------------------------------------------------------------

Summary of changes:
 source/nsswitch/libwbclient/wbc_pwd.c  |   60 ++++++++++++++++++++++++++++++++
 source/nsswitch/libwbclient/wbclient.h |    4 ++
 source/nsswitch/wbinfo.c               |   28 ++++++--------
 3 files changed, 76 insertions(+), 16 deletions(-)


Changeset truncated at 500 lines:

diff --git a/source/nsswitch/libwbclient/wbc_pwd.c b/source/nsswitch/libwbclient/wbc_pwd.c
index b7febcc..baee3c3 100644
--- a/source/nsswitch/libwbclient/wbc_pwd.c
+++ b/source/nsswitch/libwbclient/wbc_pwd.c
@@ -374,3 +374,63 @@ wbcErr wbcGetgrent(struct group **grp)
 	return WBC_ERR_NOT_IMPLEMENTED;
 }
 
+/** @brief Return the unix group array belonging to the given user
+ *
+ * @param *account       The given user name
+ * @param *num_groups    Number of elements returned in the groups array
+ * @param **groups       Pointer to resulting gid_t array.
+ *
+ * @return #wbcErr
+ **/
+wbcErr wbcGetGroups(const char *account,
+		    uint32_t *num_groups,
+		    gid_t **_groups)
+{
+	wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
+	struct winbindd_request request;
+	struct winbindd_response response;
+	uint32_t i;
+	gid_t *groups = NULL;
+
+	if (!account) {
+		wbc_status = WBC_ERR_INVALID_PARAM;
+		BAIL_ON_WBC_ERROR(wbc_status);
+	}
+
+	/* Initialize request */
+
+	ZERO_STRUCT(request);
+	ZERO_STRUCT(response);
+
+	/* Send request */
+
+	strncpy(request.data.username, account, sizeof(request.data.username)-1);
+
+	wbc_status = wbcRequestResponse(WINBINDD_GETGROUPS,
+					&request,
+					&response);
+	BAIL_ON_WBC_ERROR(wbc_status);
+
+	groups = talloc_array(NULL, gid_t, response.data.num_entries);
+	BAIL_ON_PTR_ERROR(groups, wbc_status);
+
+	for (i = 0; i < response.data.num_entries; i++) {
+		groups[i] = ((gid_t *)response.extra_data.data)[i];
+	}
+
+	*num_groups = response.data.num_entries;
+	*_groups = groups;
+	groups = NULL;
+
+	wbc_status = WBC_ERR_SUCCESS;
+
+ done:
+	if (response.extra_data.data) {
+		free(response.extra_data.data);
+	}
+	if (groups) {
+		talloc_free(groups);
+	}
+
+	return wbc_status;
+}
diff --git a/source/nsswitch/libwbclient/wbclient.h b/source/nsswitch/libwbclient/wbclient.h
index 8590a30..16b68c0 100644
--- a/source/nsswitch/libwbclient/wbclient.h
+++ b/source/nsswitch/libwbclient/wbclient.h
@@ -370,6 +370,10 @@ wbcErr wbcEndgrent(void);
 
 wbcErr wbcGetgrent(struct group **grp);
 
+wbcErr wbcGetGroups(const char *account,
+		    uint32_t *num_groups,
+		    gid_t **_groups);
+
 
 /*
  * Lookup Domain information
diff --git a/source/nsswitch/wbinfo.c b/source/nsswitch/wbinfo.c
index d3988ca..80a7290 100644
--- a/source/nsswitch/wbinfo.c
+++ b/source/nsswitch/wbinfo.c
@@ -200,29 +200,25 @@ static bool wbinfo_get_groupinfo(const char *group)
 
 /* List groups a user is a member of */
 
-static bool wbinfo_get_usergroups(char *user)
+static bool wbinfo_get_usergroups(const char *user)
 {
-	struct winbindd_request request;
-	struct winbindd_response response;
-	NSS_STATUS result;
-	int i;
-
-	ZERO_STRUCT(request);
-	ZERO_STRUCT(response);
+	wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
+	uint32_t num_groups;
+	uint32_t i;
+	gid_t *groups = NULL;
 
 	/* Send request */
 
-	fstrcpy(request.data.username, user);
-
-	result = winbindd_request_response(WINBINDD_GETGROUPS, &request, &response);
-
-	if (result != NSS_STATUS_SUCCESS)
+	wbc_status = wbcGetGroups(user, &num_groups, &groups);
+	if (!WBC_ERROR_IS_OK(wbc_status)) {
 		return false;
+	}
 
-	for (i = 0; i < response.data.num_entries; i++)
-		d_printf("%d\n", (int)((gid_t *)response.extra_data.data)[i]);
+	for (i = 0; i < num_groups; i++) {
+		d_printf("%d\n", (int)groups[i]);
+	}
 
-	SAFE_FREE(response.extra_data.data);
+	wbcFreeMemory(groups);
 
 	return true;
 }


-- 
Samba Shared Repository


More information about the samba-cvs mailing list