LCOV - code coverage report
Current view: top level - source3/winbindd - wb_lookupsid.c (source / functions) Hit Total Coverage
Test: coverage report for fix-15632 9995c5c2 Lines: 35 46 76.1 %
Date: 2024-04-13 12:30:31 Functions: 3 3 100.0 %

          Line data    Source code
       1             : /*
       2             :    Unix SMB/CIFS implementation.
       3             :    async lookupsid
       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 "../libcli/security/security.h"
      24             : 
      25             : struct wb_lookupsid_state {
      26             :         struct tevent_context *ev;
      27             :         struct winbindd_domain *lookup_domain;
      28             :         struct dom_sid sid;
      29             :         enum lsa_SidType type;
      30             :         const char *domname;
      31             :         const char *name;
      32             : };
      33             : 
      34             : static void wb_lookupsid_done(struct tevent_req *subreq);
      35             : 
      36       17674 : struct tevent_req *wb_lookupsid_send(TALLOC_CTX *mem_ctx,
      37             :                                      struct tevent_context *ev,
      38             :                                      const struct dom_sid *sid)
      39             : {
      40           0 :         struct tevent_req *req, *subreq;
      41           0 :         struct wb_lookupsid_state *state;
      42           0 :         struct dom_sid_buf buf;
      43             : 
      44       17674 :         req = tevent_req_create(mem_ctx, &state, struct wb_lookupsid_state);
      45       17674 :         if (req == NULL) {
      46           0 :                 return NULL;
      47             :         }
      48             : 
      49       17674 :         D_INFO("WB command lookupsid start.\n");
      50       17674 :         sid_copy(&state->sid, sid);
      51       17674 :         state->ev = ev;
      52             : 
      53       17674 :         state->lookup_domain = find_lookup_domain_from_sid(sid);
      54       17674 :         if (state->lookup_domain == NULL) {
      55           0 :                 D_WARNING("Could not find domain for sid %s\n",
      56             :                           dom_sid_str_buf(sid, &buf));
      57           0 :                 tevent_req_nterror(req, NT_STATUS_NONE_MAPPED);
      58           0 :                 return tevent_req_post(req, ev);
      59             :         }
      60             : 
      61       17674 :         D_DEBUG("Looking up SID %s in domain %s.\n",
      62             :                 dom_sid_str_buf(&state->sid, &buf),
      63             :                 state->lookup_domain->name);
      64       17674 :         subreq = dcerpc_wbint_LookupSid_send(
      65       17674 :                 state, ev, dom_child_handle(state->lookup_domain),
      66       17674 :                 &state->sid, &state->type, &state->domname, &state->name);
      67       17674 :         if (tevent_req_nomem(subreq, req)) {
      68           0 :                 return tevent_req_post(req, ev);
      69             :         }
      70       17674 :         tevent_req_set_callback(subreq, wb_lookupsid_done, req);
      71       17674 :         return req;
      72             : }
      73             : 
      74       17674 : static void wb_lookupsid_done(struct tevent_req *subreq)
      75             : {
      76       17674 :         struct tevent_req *req = tevent_req_callback_data(
      77             :                 subreq, struct tevent_req);
      78       17674 :         struct wb_lookupsid_state *state = tevent_req_data(
      79             :                 req, struct wb_lookupsid_state);
      80           0 :         NTSTATUS status, result;
      81             : 
      82       17674 :         status = dcerpc_wbint_LookupSid_recv(subreq, state, &result);
      83       17674 :         TALLOC_FREE(subreq);
      84       17674 :         if (any_nt_status_not_ok(status, result, &status)) {
      85         742 :                 tevent_req_nterror(req, status);
      86         742 :                 return;
      87             :         }
      88       16932 :         tevent_req_done(req);
      89             : }
      90             : 
      91       17674 : NTSTATUS wb_lookupsid_recv(struct tevent_req *req, TALLOC_CTX *mem_ctx,
      92             :                            enum lsa_SidType *type, const char **domain,
      93             :                            const char **name)
      94             : {
      95       17674 :         struct wb_lookupsid_state *state = tevent_req_data(
      96             :                 req, struct wb_lookupsid_state);
      97           0 :         NTSTATUS status;
      98           0 :         struct dom_sid_buf buf;
      99             : 
     100       17674 :         D_INFO("WB command lookupsid end.\n");
     101       17674 :         if (tevent_req_is_nterror(req, &status)) {
     102         742 :                 D_WARNING("Failed with %s.\n", nt_errstr(status));
     103         742 :                 return status;
     104             :         }
     105       16932 :         *type = state->type;
     106       16932 :         *domain = talloc_move(mem_ctx, &state->domname);
     107       16932 :         *name = talloc_move(mem_ctx, &state->name);
     108       16932 :         D_INFO("SID %s has name '%s' with type '%d' in domain '%s'.\n",
     109             :                dom_sid_str_buf(&state->sid, &buf),
     110             :                *name,
     111             :                *type,
     112             :                *domain);
     113       16932 :         return NT_STATUS_OK;
     114             : }

Generated by: LCOV version 1.14