fuzzing: fix fuzz_stable_sort_r_unstable comparison
[samba.git] / source3 / winbindd / winbindd_getpwent.c
index 3c035eac8a6f7adebeaaa42dbc73cf126e5c9022..5a788831e12a1f47de36b5b0ad641d7442901665 100644 (file)
@@ -23,8 +23,8 @@
 struct winbindd_getpwent_state {
        struct tevent_context *ev;
        struct winbindd_cli_state *cli;
-       int max_users;
-       int num_users;
+       uint32_t max_users;
+       uint32_t num_users;
        struct winbindd_pw *users;
 };
 
@@ -47,12 +47,12 @@ struct tevent_req *winbindd_getpwent_send(TALLOC_CTX *mem_ctx,
        state->num_users = 0;
        state->cli = cli;
 
-       DEBUG(3, ("[%5lu]: getpwent\n", (unsigned long)cli->pid));
-
-       if (!lp_winbind_enum_users()) {
-               tevent_req_nterror(req, NT_STATUS_NO_MORE_ENTRIES);
-               return tevent_req_post(req, ev);
-       }
+       D_NOTICE("[%s (%u)] Winbind external command GETPWENT start.\n"
+                "The caller (%s) provided room for %d entries.\n",
+                cli->client_name,
+                (unsigned int)cli->pid,
+                cli->client_name,
+                request->data.num_entries);
 
        if (cli->pwent_state == NULL) {
                tevent_req_nterror(req, NT_STATUS_NO_MORE_ENTRIES);
@@ -91,8 +91,8 @@ static void winbindd_getpwent_done(struct tevent_req *subreq)
        status = wb_next_pwent_recv(subreq);
        TALLOC_FREE(subreq);
        if (NT_STATUS_EQUAL(status, NT_STATUS_NO_MORE_ENTRIES)) {
-               DEBUG(10, ("winbindd_getpwent_done: done with %d users\n",
-                          (int)state->num_users));
+               D_DEBUG("winbindd_getpwent_done: done with %"PRIu32" users\n",
+                       state->num_users);
                TALLOC_FREE(state->cli->pwent_state);
                tevent_req_done(req);
                return;
@@ -102,14 +102,13 @@ static void winbindd_getpwent_done(struct tevent_req *subreq)
        }
        state->num_users += 1;
        if (state->num_users >= state->max_users) {
-               DEBUG(10, ("winbindd_getpwent_done: Got enough users: %d\n",
-                          (int)state->num_users));
+               D_DEBUG("winbindd_getpwent_done: Got enough users: %"PRIu32"\n",
+                       state->num_users);
                tevent_req_done(req);
                return;
        }
        if (state->cli->pwent_state == NULL) {
-               DEBUG(10, ("winbindd_getpwent_done: endpwent called in "
-                          "between\n"));
+               D_DEBUG("winbindd_getpwent_done: endpwent called in between\n");
                tevent_req_nterror(req, NT_STATUS_INVALID_PARAMETER);
                return;
        }
@@ -127,16 +126,35 @@ NTSTATUS winbindd_getpwent_recv(struct tevent_req *req,
        struct winbindd_getpwent_state *state = tevent_req_data(
                req, struct winbindd_getpwent_state);
        NTSTATUS status;
+       uint32_t i;
 
        if (tevent_req_is_nterror(req, &status)) {
-               DEBUG(5, ("getpwent failed: %s\n", nt_errstr(status)));
+               TALLOC_FREE(state->cli->pwent_state);
+               D_WARNING("getpwent failed: %s\n", nt_errstr(status));
                return status;
        }
 
+       D_NOTICE("Winbind external command GETPWENT end.\n"
+                "Received %"PRIu32" entries.\n"
+                "(name:passwd:uid:gid:gecos:dir:shell)\n",
+                state->num_users);
+
        if (state->num_users == 0) {
                return NT_STATUS_NO_MORE_ENTRIES;
        }
 
+       for (i = 0; i < state->num_users; i++) {
+               D_NOTICE("%"PRIu32": %s:%s:%u:%u:%s:%s:%s\n",
+                       i,
+                       state->users[i].pw_name,
+                       state->users[i].pw_passwd,
+                       (unsigned int)state->users[i].pw_uid,
+                       (unsigned int)state->users[i].pw_gid,
+                       state->users[i].pw_gecos,
+                       state->users[i].pw_dir,
+                       state->users[i].pw_shell
+                       );
+       }
        response->data.num_entries = state->num_users;
        response->extra_data.data = talloc_move(response, &state->users);
        response->length += state->num_users * sizeof(struct winbindd_pw);