summaryrefslogtreecommitdiff
path: root/source3/nsswitch
diff options
context:
space:
mode:
authorStefan Metzmacher <metze@samba.org>2008-03-24 20:31:37 +0100
committerStefan Metzmacher <metze@samba.org>2008-03-28 15:11:41 +0100
commiteb98b08ccbd3f0128db07f84951f577450bb3f77 (patch)
tree7da37ae8e275ec08b63f68ae676478464fc23712 /source3/nsswitch
parentf58ca063bba86b74f1f4982694b5a7ead442becb (diff)
downloadsamba-eb98b08ccbd3f0128db07f84951f577450bb3f77.tar.gz
samba-eb98b08ccbd3f0128db07f84951f577450bb3f77.tar.bz2
samba-eb98b08ccbd3f0128db07f84951f577450bb3f77.zip
libwbclient: add wbcListUsers() and wbcListGroups()
metze (This used to be commit df127f0b40d36ea8ee605c24ea88558c7d40a7fe)
Diffstat (limited to 'source3/nsswitch')
-rw-r--r--source3/nsswitch/libwbclient/wbc_sid.c142
-rw-r--r--source3/nsswitch/libwbclient/wbclient.h8
2 files changed, 150 insertions, 0 deletions
diff --git a/source3/nsswitch/libwbclient/wbc_sid.c b/source3/nsswitch/libwbclient/wbc_sid.c
index cd865b9bb5..6ef9f44c3b 100644
--- a/source3/nsswitch/libwbclient/wbc_sid.c
+++ b/source3/nsswitch/libwbclient/wbc_sid.c
@@ -505,3 +505,145 @@ wbcErr wbcLookupUserSids(const struct wbcDomainSid *user_sid,
return wbc_status;
}
+
+/** @brief Lists Users
+ *
+ **/
+
+wbcErr wbcListUsers(const char *domain_name,
+ uint32_t *_num_users,
+ const char ***_users)
+{
+ wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
+ struct winbindd_request request;
+ struct winbindd_response response;
+ uint32_t num_users = 0;
+ const char **users = NULL;
+ const char *next;
+
+ /* Initialise request */
+
+ ZERO_STRUCT(request);
+ ZERO_STRUCT(response);
+
+ if (domain_name) {
+ strncpy(request.domain_name, domain_name,
+ sizeof(request.domain_name)-1);
+ }
+
+ wbc_status = wbcRequestResponse(WINBINDD_LIST_USERS,
+ &request,
+ &response);
+ BAIL_ON_WBC_ERROR(wbc_status);
+
+ /* Look through extra data */
+
+ next = (const char *)response.extra_data.data;
+ while (next) {
+ const char **tmp;
+ const char *current = next;
+ char *k = strchr(next, ',');
+ if (k) {
+ k[0] = '\0';
+ next = k+1;
+ } else {
+ next = NULL;
+ }
+
+ tmp = talloc_realloc(NULL, users,
+ const char *,
+ num_users+1);
+ BAIL_ON_PTR_ERROR(tmp, wbc_status);
+ users = tmp;
+
+ users[num_users] = talloc_strdup(users, current);
+ BAIL_ON_PTR_ERROR(users[num_users], wbc_status);
+
+ num_users++;
+ }
+
+ *_num_users = num_users;
+ *_users = users;
+ users = NULL;
+ wbc_status = WBC_ERR_SUCCESS;
+
+ done:
+ if (response.extra_data.data) {
+ free(response.extra_data.data);
+ }
+ if (users) {
+ talloc_free(users);
+ }
+ return wbc_status;
+}
+
+/** @brief Lists Groups
+ *
+ **/
+
+wbcErr wbcListGroups(const char *domain_name,
+ uint32_t *_num_groups,
+ const char ***_groups)
+{
+ wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
+ struct winbindd_request request;
+ struct winbindd_response response;
+ uint32_t num_groups = 0;
+ const char **groups = NULL;
+ const char *next;
+
+ /* Initialise request */
+
+ ZERO_STRUCT(request);
+ ZERO_STRUCT(response);
+
+ if (domain_name) {
+ strncpy(request.domain_name, domain_name,
+ sizeof(request.domain_name)-1);
+ }
+
+ wbc_status = wbcRequestResponse(WINBINDD_LIST_GROUPS,
+ &request,
+ &response);
+ BAIL_ON_WBC_ERROR(wbc_status);
+
+ /* Look through extra data */
+
+ next = (const char *)response.extra_data.data;
+ while (next) {
+ const char **tmp;
+ const char *current = next;
+ char *k = strchr(next, ',');
+ if (k) {
+ k[0] = '\0';
+ next = k+1;
+ } else {
+ next = NULL;
+ }
+
+ tmp = talloc_realloc(NULL, groups,
+ const char *,
+ num_groups+1);
+ BAIL_ON_PTR_ERROR(tmp, wbc_status);
+ groups = tmp;
+
+ groups[num_groups] = talloc_strdup(groups, current);
+ BAIL_ON_PTR_ERROR(groups[num_groups], wbc_status);
+
+ num_groups++;
+ }
+
+ *_num_groups = num_groups;
+ *_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/source3/nsswitch/libwbclient/wbclient.h b/source3/nsswitch/libwbclient/wbclient.h
index 4b6978080b..30d8b761a3 100644
--- a/source3/nsswitch/libwbclient/wbclient.h
+++ b/source3/nsswitch/libwbclient/wbclient.h
@@ -303,6 +303,14 @@ wbcErr wbcLookupUserSids(const struct wbcDomainSid *user_sid,
uint32_t *num_sids,
struct wbcDomainSid **sids);
+wbcErr wbcListUsers(const char *domain_name,
+ uint32_t *num_users,
+ const char ***users);
+
+wbcErr wbcListGroups(const char *domain_name,
+ uint32_t *num_groups,
+ const char ***groups);
+
/*
* SID/uid/gid Mappings
*/