s4-idmap: Add mapping using uidNumber and gidNumber like idmap_ad
[samba.git] / source4 / winbind / wb_cmd_list_users.c
index 080ddf271bf457e95fd70ee4707cb9d5538ed132..03544f6585b20191642a547d7c7dd5aa25f57028 100644 (file)
 #include "includes.h"
 #include "libcli/composite/composite.h"
 #include "winbind/wb_server.h"
-#include "winbind/wb_async_helpers.h"
-#include "winbind/wb_helper.h"
 #include "smbd/service_task.h"
-#include "nsswitch/winbindd_nss.h"
-#include "libnet/libnet_proto.h"
 
 struct cmd_list_users_state {
        struct composite_context *ctx;
@@ -34,8 +30,9 @@ struct cmd_list_users_state {
 
        struct wbsrv_domain *domain;
        char *domain_name;
-       uint resume_index;
+       uint32_t resume_index;
        char *result;
+       uint32_t num_users;
 };
 
 static void cmd_list_users_recv_domain(struct composite_context *ctx);
@@ -59,6 +56,7 @@ struct composite_context *wb_cmd_list_users_send(TALLOC_CTX *mem_ctx,
        result->private_data = state;
        state->service = service;
        state->resume_index = 0;
+       state->num_users = 0;
        state->result = talloc_strdup(state, "");
        if (composite_nomem(state->result, state->ctx)) return result;
 
@@ -137,22 +135,24 @@ static void cmd_list_users_recv_user_list(struct composite_context *ctx)
 
        /* If NTSTATUS is neither OK nor MORE_ENTRIES, something broke */
        if (!NT_STATUS_IS_OK(status) &&
-            !NT_STATUS_EQUAL(status, STATUS_MORE_ENTRIES)) {
+           !NT_STATUS_EQUAL(status, STATUS_MORE_ENTRIES) &&
+           !NT_STATUS_EQUAL(status, NT_STATUS_NO_MORE_ENTRIES)) {
                composite_error(state->ctx, status);
                return;
        }
 
        for (i = 0; i < user_list->out.count; ++i) {
                DEBUG(5, ("Appending user '%s'\n", user_list->out.users[i].username));
-               state->result = talloc_asprintf_append(state->result, "%s,",
+               state->result = talloc_asprintf_append_buffer(state->result, "%s,",
                                        user_list->out.users[i].username);
+               state->num_users++;
        }
 
        /* If the status is OK, we're finished, there's no more users.
         * So we'll trim off the trailing ',' and are done.*/
        if (NT_STATUS_IS_OK(status)) {
                int str_len = strlen(state->result);
-               DEBUG(1, ("list_UserList_recv returned NT_STATUS_OK\n"));
+               DEBUG(5, ("list_UserList_recv returned NT_STATUS_OK\n"));
                state->result[str_len - 1] = '\0';
                composite_done(state->ctx);
                return;
@@ -178,7 +178,7 @@ static void cmd_list_users_recv_user_list(struct composite_context *ctx)
 
 NTSTATUS wb_cmd_list_users_recv(struct composite_context *ctx,
                TALLOC_CTX *mem_ctx, uint32_t *extra_data_len,
-               char **extra_data)
+               char **extra_data, uint32_t *num_users)
 {
        NTSTATUS status = composite_wait(ctx);
 
@@ -190,6 +190,7 @@ NTSTATUS wb_cmd_list_users_recv(struct composite_context *ctx,
 
                *extra_data_len = strlen(state->result);
                *extra_data = talloc_steal(mem_ctx, state->result);
+               *num_users = state->num_users;
        }
 
        talloc_free(ctx);