LCOV - code coverage report
Current view: top level - source3/winbindd - wb_lookupname.c (source / functions) Hit Total Coverage
Test: coverage report for vadcx-master-patch-75612 fe003de8 Lines: 38 48 79.2 %
Date: 2024-02-29 22:57:05 Functions: 3 3 100.0 %

          Line data    Source code
       1             : /*
       2             :    Unix SMB/CIFS implementation.
       3             :    async lookupname
       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_lookupname_state {
      26             :         struct tevent_context *ev;
      27             :         const char *dom_name;
      28             :         const char *name;
      29             :         uint32_t flags;
      30             :         struct dom_sid sid;
      31             :         enum lsa_SidType type;
      32             : };
      33             : 
      34             : static void wb_lookupname_done(struct tevent_req *subreq);
      35             : 
      36       99402 : struct tevent_req *wb_lookupname_send(TALLOC_CTX *mem_ctx,
      37             :                                       struct tevent_context *ev,
      38             :                                       const char *namespace,
      39             :                                       const char *dom_name,
      40             :                                       const char *name,
      41             :                                       uint32_t flags)
      42             : {
      43           0 :         struct tevent_req *req, *subreq;
      44           0 :         struct wb_lookupname_state *state;
      45           0 :         struct winbindd_domain *domain;
      46             : 
      47       99402 :         req = tevent_req_create(mem_ctx, &state, struct wb_lookupname_state);
      48       99402 :         if (req == NULL) {
      49           0 :                 return NULL;
      50             :         }
      51             : 
      52       99402 :         D_INFO("WB command lookupname start.\n"
      53             :                "Search namespace '%s' and domain '%s' for name '%s'.\n",
      54             :                 namespace, dom_name, name);
      55       99402 :         state->ev = ev;
      56       99402 :         state->flags = flags;
      57             : 
      58             :         /*
      59             :          * Uppercase domain and name so that we become cache-friendly
      60             :          */
      61       99402 :         state->dom_name = talloc_strdup_upper(state, dom_name);
      62       99402 :         if (tevent_req_nomem(state->dom_name, req)) {
      63           0 :                 return tevent_req_post(req, ev);
      64             :         }
      65       99402 :         state->name = talloc_strdup_upper(state, name);
      66       99402 :         if (tevent_req_nomem(state->name, req)) {
      67           0 :                 return tevent_req_post(req, ev);
      68             :         }
      69             : 
      70       99402 :         domain = find_lookup_domain_from_name(namespace);
      71       99402 :         if (domain == NULL) {
      72           2 :                 D_WARNING("Could not find domain for %s\n", namespace);
      73           2 :                 tevent_req_nterror(req, NT_STATUS_NONE_MAPPED);
      74           2 :                 return tevent_req_post(req, ev);
      75             :         }
      76             : 
      77       99400 :         subreq = dcerpc_wbint_LookupName_send(
      78             :                 state, ev, dom_child_handle(domain),
      79       99400 :                 state->dom_name, state->name,
      80       99400 :                 flags, &state->type, &state->sid);
      81       99400 :         if (tevent_req_nomem(subreq, req)) {
      82           0 :                 return tevent_req_post(req, ev);
      83             :         }
      84       99400 :         tevent_req_set_callback(subreq, wb_lookupname_done, req);
      85       99400 :         return req;
      86             : }
      87             : 
      88       99400 : static void wb_lookupname_done(struct tevent_req *subreq)
      89             : {
      90       99400 :         struct tevent_req *req = tevent_req_callback_data(
      91             :                 subreq, struct tevent_req);
      92       99400 :         struct wb_lookupname_state *state = tevent_req_data(
      93             :                 req, struct wb_lookupname_state);
      94           0 :         NTSTATUS status, result;
      95             : 
      96       99400 :         status = dcerpc_wbint_LookupName_recv(subreq, state, &result);
      97       99400 :         TALLOC_FREE(subreq);
      98       99400 :         if (any_nt_status_not_ok(status, result, &status)) {
      99         866 :                 tevent_req_nterror(req, status);
     100         866 :                 return;
     101             :         }
     102       98534 :         tevent_req_done(req);
     103             : }
     104             : 
     105       99402 : NTSTATUS wb_lookupname_recv(struct tevent_req *req, struct dom_sid *sid,
     106             :                             enum lsa_SidType *type)
     107             : {
     108       99402 :         struct wb_lookupname_state *state = tevent_req_data(
     109             :                 req, struct wb_lookupname_state);
     110           0 :         NTSTATUS status;
     111           0 :         struct dom_sid_buf buf;
     112             : 
     113       99402 :         if (tevent_req_is_nterror(req, &status)) {
     114         868 :                 return status;
     115             :         }
     116       98534 :         sid_copy(sid, &state->sid);
     117       98534 :         *type = state->type;
     118       98534 :         D_INFO("WB command lookupname end.\n"
     119             :                "Found SID %s with SID type %d.\n",
     120             :                dom_sid_str_buf(sid, &buf),
     121             :                *type);
     122       98534 :         return NT_STATUS_OK;
     123             : }

Generated by: LCOV version 1.14