LCOV - code coverage report
Current view: top level - source3/winbindd - wb_query_user_list.c (source / functions) Hit Total Coverage
Test: coverage report for master 98b443d9 Lines: 43 64 67.2 %
Date: 2024-05-31 13:13:24 Functions: 4 4 100.0 %

          Line data    Source code
       1             : /*
       2             :    Unix SMB/CIFS implementation.
       3             :    async query_user_list
       4             :    Copyright (C) Volker Lendecke 2009
       5             : 
       6             :    This program is free software; you can redistribute it and/or modify
       7             :    it under the terms of the GNU General Public License as published by
       8             :    the Free Software Foundation; either version 3 of the License, or
       9             :    (at your option) any later version.
      10             : 
      11             :    This program is distributed in the hope that it will be useful,
      12             :    but WITHOUT ANY WARRANTY; without even the implied warranty of
      13             :    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      14             :    GNU General Public License for more details.
      15             : 
      16             :    You should have received a copy of the GNU General Public License
      17             :    along with this program.  If not, see <http://www.gnu.org/licenses/>.
      18             : */
      19             : 
      20             : #include "includes.h"
      21             : #include "winbindd.h"
      22             : #include "librpc/gen_ndr/ndr_winbind_c.h"
      23             : #include "lib/util/strv.h"
      24             : 
      25             : struct wb_query_user_list_state {
      26             :         struct tevent_context *ev;
      27             :         struct winbindd_domain *domain;
      28             :         struct wbint_RidArray rids;
      29             :         const char *domain_name;
      30             :         struct wbint_Principals names;
      31             :         char *users;
      32             : };
      33             : 
      34             : static void wb_query_user_list_gotrids(struct tevent_req *subreq);
      35             : static void wb_query_user_list_done(struct tevent_req *subreq);
      36             : 
      37          62 : struct tevent_req *wb_query_user_list_send(TALLOC_CTX *mem_ctx,
      38             :                                            struct tevent_context *ev,
      39             :                                            struct winbindd_domain *domain)
      40             : {
      41           0 :         struct tevent_req *req, *subreq;
      42           0 :         struct wb_query_user_list_state *state;
      43             : 
      44          62 :         req = tevent_req_create(mem_ctx, &state,
      45             :                                 struct wb_query_user_list_state);
      46          62 :         if (req == NULL) {
      47           0 :                 return NULL;
      48             :         }
      49             : 
      50          62 :         D_INFO("WB command user_list start.\nQuery users in domain %s.\n",
      51             :                domain->name);
      52          62 :         state->ev = ev;
      53          62 :         state->domain = domain;
      54             : 
      55          62 :         subreq = dcerpc_wbint_QueryUserRidList_send(
      56          62 :                 state, ev, dom_child_handle(domain), &state->rids);
      57          62 :         if (tevent_req_nomem(subreq, req)) {
      58           0 :                 return tevent_req_post(req, ev);
      59             :         }
      60          62 :         tevent_req_set_callback(subreq, wb_query_user_list_gotrids, req);
      61          62 :         return req;
      62             : }
      63             : 
      64          62 : static void wb_query_user_list_gotrids(struct tevent_req *subreq)
      65             : {
      66          62 :         struct tevent_req *req = tevent_req_callback_data(
      67             :                 subreq, struct tevent_req);
      68          62 :         struct wb_query_user_list_state *state = tevent_req_data(
      69             :                 req, struct wb_query_user_list_state);
      70           0 :         NTSTATUS status, result;
      71             : 
      72          62 :         status = dcerpc_wbint_QueryUserRidList_recv(subreq, state, &result);
      73          62 :         TALLOC_FREE(subreq);
      74          62 :         if (any_nt_status_not_ok(status, result, &status)) {
      75           0 :                 tevent_req_nterror(req, status);
      76           0 :                 return;
      77             :         }
      78             : 
      79          62 :         D_DEBUG("dcerpc_wbint_QueryUserRidList returned %"PRIu32" users\n",
      80             :                 state->rids.num_rids);
      81             : 
      82          62 :         subreq = dcerpc_wbint_LookupRids_send(
      83             :                 state, state->ev, dom_child_handle(state->domain),
      84          62 :                 &state->domain->sid, &state->rids,
      85             :                 &state->domain_name, &state->names);
      86          62 :         if (tevent_req_nomem(subreq, req)) {
      87           0 :                 return;
      88             :         }
      89          62 :         tevent_req_set_callback(subreq, wb_query_user_list_done, req);
      90             : }
      91             : 
      92          62 : static void wb_query_user_list_done(struct tevent_req *subreq)
      93             : {
      94          62 :         struct tevent_req *req = tevent_req_callback_data(
      95             :                 subreq, struct tevent_req);
      96          62 :         struct wb_query_user_list_state *state = tevent_req_data(
      97             :                 req, struct wb_query_user_list_state);
      98           0 :         NTSTATUS status, result;
      99           0 :         uint32_t i;
     100             : 
     101          62 :         status = dcerpc_wbint_LookupRids_recv(subreq, state, &result);
     102          62 :         TALLOC_FREE(subreq);
     103          62 :         if (any_nt_status_not_ok(status, result, &status)) {
     104           0 :                 tevent_req_nterror(req, status);
     105           0 :                 return;
     106             :         }
     107          62 :         D_DEBUG("Processing %"PRIu32" principal(s).\n",
     108             :                 state->names.num_principals);
     109        3466 :         for (i=0; i<state->names.num_principals; i++) {
     110        3404 :                 struct wbint_Principal *p = &state->names.principals[i];
     111           0 :                 const char *name;
     112           0 :                 int ret;
     113             : 
     114        3404 :                 name = fill_domain_username_talloc(state, state->domain_name, p->name, true);
     115        3404 :                 if (name == NULL) {
     116           0 :                         tevent_req_nterror(req, NT_STATUS_NO_MEMORY);
     117           0 :                         return;
     118             :                 }
     119        3404 :                 ret = strv_add(state, &state->users, name);
     120        3404 :                 if (ret != 0) {
     121           0 :                         tevent_req_nterror(req, map_nt_error_from_unix(ret));
     122           0 :                         return;
     123             :                 }
     124        3404 :                 D_DEBUG("%"PRIu32": Adding user %s\n", i, name);
     125             :         }
     126             : 
     127          62 :         tevent_req_done(req);
     128             : }
     129             : 
     130          62 : NTSTATUS wb_query_user_list_recv(struct tevent_req *req, TALLOC_CTX *mem_ctx,
     131             :                                  char **users)
     132             : {
     133          62 :         struct wb_query_user_list_state *state = tevent_req_data(
     134             :                 req, struct wb_query_user_list_state);
     135           0 :         NTSTATUS status;
     136             : 
     137          62 :         D_INFO("WB command user_list end.\n");
     138          62 :         if (tevent_req_is_nterror(req, &status)) {
     139           0 :                 D_WARNING("Failed with: %s\n", nt_errstr(status));
     140           0 :                 return status;
     141             :         }
     142             : 
     143          62 :         *users = talloc_move(mem_ctx, &state->users);
     144             : 
     145          62 :         return NT_STATUS_OK;
     146             : }

Generated by: LCOV version 1.14