LCOV - code coverage report
Current view: top level - source3/winbindd - wb_alias_members.c (source / functions) Hit Total Coverage
Test: coverage report for master 2f515e9b Lines: 39 64 60.9 %
Date: 2024-04-21 15:09:00 Functions: 3 3 100.0 %

          Line data    Source code
       1             : /*
       2             :    Unix SMB/CIFS implementation.
       3             :    async alias_members
       4             :    Copyright (C) Pavel Filipenský 2023
       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 "../libcli/security/security.h"
      24             : 
      25             : struct wb_alias_members_state {
      26             :         struct tevent_context *ev;
      27             :         struct dom_sid sid;
      28             :         struct wbint_SidArray sids;
      29             : };
      30             : 
      31             : static void wb_alias_members_done(struct tevent_req *subreq);
      32             : 
      33         640 : struct tevent_req *wb_alias_members_send(TALLOC_CTX *mem_ctx,
      34             :                                          struct tevent_context *ev,
      35             :                                          const struct dom_sid *sid,
      36             :                                          enum lsa_SidType type,
      37             :                                          int max_nesting)
      38             : {
      39           0 :         struct tevent_req *req, *subreq;
      40           0 :         struct wb_alias_members_state *state;
      41           0 :         struct winbindd_domain *domain;
      42           0 :         NTSTATUS status;
      43           0 :         struct dom_sid_buf buf;
      44             : 
      45         640 :         req = tevent_req_create(mem_ctx, &state, struct wb_alias_members_state);
      46         640 :         if (req == NULL) {
      47           0 :                 return NULL;
      48             :         }
      49         640 :         D_INFO("WB command alias_members start.\nLooking up SID %s.\n",
      50             :                dom_sid_str_buf(sid, &buf));
      51             : 
      52         640 :         if (max_nesting <= 0) {
      53         638 :                 D_DEBUG("Finished. The depth based on 'winbind expand groups' is %d.\n", max_nesting);
      54         638 :                 state->sids.num_sids = 0;
      55         638 :                 state->sids.sids = NULL;
      56         638 :                 tevent_req_done(req);
      57         638 :                 return tevent_req_post(req, ev);
      58             :         }
      59             : 
      60           2 :         sid_copy(&state->sid, sid);
      61             : 
      62           2 :         status = lookup_usergroups_cached(state,
      63           2 :                                           &state->sid,
      64           2 :                                           &state->sids.num_sids,
      65           2 :                                           &state->sids.sids);
      66           2 :         if (NT_STATUS_IS_OK(status)) {
      67           0 :                 tevent_req_done(req);
      68           0 :                 return tevent_req_post(req, ev);
      69             :         }
      70             : 
      71           2 :         domain = find_domain_from_sid_noinit(&state->sid);
      72           2 :         if (domain == NULL) {
      73           0 :                 DBG_WARNING("could not find domain entry for sid %s\n",
      74             :                             dom_sid_str_buf(&state->sid, &buf));
      75           0 :                 tevent_req_nterror(req, NT_STATUS_NO_SUCH_ALIAS);
      76           0 :                 return tevent_req_post(req, ev);
      77             :         }
      78             : 
      79           2 :         subreq = dcerpc_wbint_LookupAliasMembers_send(state,
      80             :                                                       ev,
      81             :                                                       dom_child_handle(domain),
      82           2 :                                                       &state->sid,
      83             :                                                       type,
      84           2 :                                                       &state->sids);
      85           2 :         if (tevent_req_nomem(subreq, req)) {
      86           0 :                 return tevent_req_post(req, ev);
      87             :         }
      88           2 :         tevent_req_set_callback(subreq, wb_alias_members_done, req);
      89           2 :         return req;
      90             : }
      91             : 
      92           2 : static void wb_alias_members_done(struct tevent_req *subreq)
      93             : {
      94           0 :         struct tevent_req *req =
      95           2 :                 tevent_req_callback_data(subreq, struct tevent_req);
      96           0 :         struct wb_alias_members_state *state =
      97           2 :                 tevent_req_data(req, struct wb_alias_members_state);
      98           0 :         NTSTATUS status, result;
      99             : 
     100           2 :         status = dcerpc_wbint_LookupAliasMembers_recv(subreq, state, &result);
     101           2 :         TALLOC_FREE(subreq);
     102           2 :         if (any_nt_status_not_ok(status, result, &status)) {
     103           0 :                 D_WARNING("Failed with %s.\n", nt_errstr(status));
     104           0 :                 tevent_req_nterror(req, status);
     105           0 :                 return;
     106             :         }
     107           2 :         tevent_req_done(req);
     108             : }
     109             : 
     110         640 : NTSTATUS wb_alias_members_recv(struct tevent_req *req,
     111             :                                TALLOC_CTX *mem_ctx,
     112             :                                uint32_t *num_sids,
     113             :                                struct dom_sid **sids)
     114             : {
     115           0 :         struct wb_alias_members_state *state =
     116         640 :                 tevent_req_data(req, struct wb_alias_members_state);
     117           0 :         NTSTATUS status;
     118           0 :         uint32_t i;
     119             : 
     120         640 :         if (tevent_req_is_nterror(req, &status)) {
     121           0 :                 return status;
     122             :         }
     123         640 :         *num_sids = state->sids.num_sids;
     124         640 :         *sids = talloc_move(mem_ctx, &state->sids.sids);
     125             : 
     126         640 :         D_INFO("WB command alias_members end.\nReceived %" PRIu32 " SID(s).\n",
     127             :                *num_sids);
     128         640 :         if (CHECK_DEBUGLVL(DBGLVL_INFO)) {
     129           0 :                 for (i = 0; i < *num_sids; i++) {
     130           0 :                         struct dom_sid_buf buf;
     131           0 :                         D_INFO("%" PRIu32 ": %s\n",
     132             :                                i,
     133             :                                dom_sid_str_buf(&(*sids)[i], &buf));
     134             :                 }
     135             :         }
     136         640 :         return NT_STATUS_OK;
     137             : }

Generated by: LCOV version 1.14