LCOV - code coverage report
Current view: top level - source3/winbindd - wb_next_grent.c (source / functions) Hit Total Coverage
Test: coverage report for master 2f515e9b Lines: 59 78 75.6 %
Date: 2024-04-21 15:09:00 Functions: 5 5 100.0 %

          Line data    Source code
       1             : /*
       2             :    Unix SMB/CIFS implementation.
       3             :    async next_grent
       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 "passdb/machine_sid.h"
      24             : 
      25             : struct wb_next_grent_state {
      26             :         struct tevent_context *ev;
      27             :         int max_nesting;
      28             :         struct getgrent_state *gstate;
      29             :         struct winbindd_gr *gr;
      30             :         struct db_context *members;
      31             : };
      32             : 
      33             : static void wb_next_grent_fetch_done(struct tevent_req *subreq);
      34             : static void wb_next_grent_getgrsid_done(struct tevent_req *subreq);
      35             : 
      36        1860 : static void wb_next_grent_send_do(struct tevent_req *req,
      37             :                                   struct wb_next_grent_state *state)
      38             : {
      39           0 :         struct tevent_req *subreq;
      40             : 
      41        1860 :         if (state->gstate->next_group >= state->gstate->num_groups) {
      42         100 :                 TALLOC_FREE(state->gstate->groups);
      43             : 
      44         100 :                 state->gstate->domain = wb_next_domain(state->gstate->domain);
      45         100 :                 if (state->gstate->domain == NULL) {
      46          30 :                         tevent_req_nterror(req, NT_STATUS_NO_MORE_ENTRIES);
      47          30 :                         return;
      48             :                 }
      49             : 
      50          70 :                 subreq = wb_query_group_list_send(state, state->ev,
      51          70 :                                                   state->gstate->domain);
      52          70 :                 if (tevent_req_nomem(subreq, req)) {
      53           0 :                         return;
      54             :                 }
      55          70 :                 tevent_req_set_callback(subreq, wb_next_grent_fetch_done, req);
      56          70 :                 return;
      57             :         }
      58             : 
      59        1760 :         subreq = wb_getgrsid_send(
      60             :                 state, state->ev,
      61        1760 :                 &state->gstate->groups[state->gstate->next_group].sid,
      62             :                 state->max_nesting);
      63        1760 :         if (tevent_req_nomem(subreq, req)) {
      64           0 :                 return;
      65             :         }
      66        1760 :         tevent_req_set_callback(subreq, wb_next_grent_getgrsid_done, req);
      67             : }
      68             : 
      69        1790 : struct tevent_req *wb_next_grent_send(TALLOC_CTX *mem_ctx,
      70             :                                       struct tevent_context *ev,
      71             :                                       int max_nesting,
      72             :                                       struct getgrent_state *gstate,
      73             :                                       struct winbindd_gr *gr)
      74             : {
      75           0 :         struct tevent_req *req;
      76           0 :         struct wb_next_grent_state *state;
      77             : 
      78        1790 :         req = tevent_req_create(mem_ctx, &state, struct wb_next_grent_state);
      79        1790 :         if (req == NULL) {
      80           0 :                 return NULL;
      81             :         }
      82             : 
      83        1790 :         D_INFO("WB command next_grent start.\n");
      84             : 
      85        1790 :         state->ev = ev;
      86        1790 :         state->gstate = gstate;
      87        1790 :         state->gr = gr;
      88        1790 :         state->max_nesting = max_nesting;
      89             : 
      90        1790 :         wb_next_grent_send_do(req, state);
      91        1790 :         if (!tevent_req_is_in_progress(req)) {
      92          10 :                 return tevent_req_post(req, ev);
      93             :         }
      94             : 
      95        1780 :         return req;
      96             : }
      97             : 
      98          70 : static void wb_next_grent_fetch_done(struct tevent_req *subreq)
      99             : {
     100          70 :         struct tevent_req *req = tevent_req_callback_data(
     101             :                 subreq, struct tevent_req);
     102          70 :         struct wb_next_grent_state *state = tevent_req_data(
     103             :                 req, struct wb_next_grent_state);
     104           0 :         NTSTATUS status;
     105             : 
     106          70 :         status = wb_query_group_list_recv(subreq, state->gstate,
     107          70 :                                           &state->gstate->num_groups,
     108          70 :                                           &state->gstate->groups);
     109          70 :         TALLOC_FREE(subreq);
     110          70 :         if (!NT_STATUS_IS_OK(status)) {
     111             :                 /* Ignore errors here, just log it */
     112           0 :                 D_DEBUG("query_group_list for domain %s returned %s\n",
     113             :                         state->gstate->domain->name, nt_errstr(status));
     114           0 :                 state->gstate->num_groups = 0;
     115             :         }
     116             : 
     117          70 :         state->gstate->next_group = 0;
     118             : 
     119          70 :         wb_next_grent_send_do(req, state);
     120          70 : }
     121             : 
     122        1760 : static void wb_next_grent_getgrsid_done(struct tevent_req *subreq)
     123             : {
     124        1760 :         struct tevent_req *req = tevent_req_callback_data(
     125             :                 subreq, struct tevent_req);
     126        1760 :         struct wb_next_grent_state *state = tevent_req_data(
     127             :                 req, struct wb_next_grent_state);
     128           0 :         const char *domname, *name;
     129           0 :         NTSTATUS status;
     130             : 
     131        1760 :         status = wb_getgrsid_recv(subreq, talloc_tos(), &domname, &name,
     132        1760 :                                   &state->gr->gr_gid, &state->members);
     133        1760 :         TALLOC_FREE(subreq);
     134             : 
     135        1760 :         if (NT_STATUS_EQUAL(status, NT_STATUS_NONE_MAPPED)) {
     136           0 :                 state->gstate->next_group += 1;
     137             : 
     138           0 :                 wb_next_grent_send_do(req, state);
     139             : 
     140           0 :                 return;
     141        1760 :         } else if (tevent_req_nterror(req, status)) {
     142           0 :                 return;
     143             :         }
     144             : 
     145        1760 :         if (!fill_grent(talloc_tos(), state->gr, domname, name,
     146        1760 :                         state->gr->gr_gid)) {
     147           0 :                 D_WARNING("fill_grent failed\n");
     148           0 :                 tevent_req_nterror(req, NT_STATUS_NO_MEMORY);
     149           0 :                 return;
     150             :         }
     151        1760 :         state->gstate->next_group += 1;
     152        1760 :         tevent_req_done(req);
     153             : }
     154             : 
     155        1790 : NTSTATUS wb_next_grent_recv(struct tevent_req *req, TALLOC_CTX *mem_ctx,
     156             :                             struct db_context **members)
     157             : {
     158        1790 :         struct wb_next_grent_state *state = tevent_req_data(
     159             :                 req, struct wb_next_grent_state);
     160           0 :         NTSTATUS status;
     161             : 
     162        1790 :         D_INFO("WB command next_grent end.\n");
     163        1790 :         if (tevent_req_is_nterror(req, &status)) {
     164          30 :                 D_WARNING("Failed with %s.\n", nt_errstr(status));
     165          30 :                 return status;
     166             :         }
     167        1760 :         *members = talloc_move(mem_ctx, &state->members);
     168        1760 :         return NT_STATUS_OK;
     169             : }

Generated by: LCOV version 1.14