libwbclient: add wbcGetGroups()
authorStefan Metzmacher <metze@samba.org>
Sun, 6 Apr 2008 09:55:57 +0000 (11:55 +0200)
committerStefan Metzmacher <metze@samba.org>
Sun, 6 Apr 2008 11:42:00 +0000 (13:42 +0200)
metze

source/nsswitch/libwbclient/wbc_pwd.c
source/nsswitch/libwbclient/wbclient.h

index b7febcce0c49cea777bd3d9151f72196dc4039d9..baee3c378162b9429711288987c67363824ff331 100644 (file)
@@ -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;
+}
index 8590a3079549e9672a527a2bfa09e3f79e37a82a..16b68c0802ba391d43f5248e5e891fc766bd6c92 100644 (file)
@@ -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