LCOV - code coverage report
Current view: top level - source3/winbindd - winbindd_lookupname.c (source / functions) Hit Total Coverage
Test: coverage report for vadcx-master-patch-75612 fe003de8 Lines: 44 57 77.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 implementation of WINBINDD_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 "libcli/security/dom_sid.h"
      23             : 
      24             : struct winbindd_lookupname_state {
      25             :         struct tevent_context *ev;
      26             :         struct dom_sid sid;
      27             :         enum lsa_SidType type;
      28             : };
      29             : 
      30             : static void winbindd_lookupname_done(struct tevent_req *subreq);
      31             : 
      32        3834 : struct tevent_req *winbindd_lookupname_send(TALLOC_CTX *mem_ctx,
      33             :                                             struct tevent_context *ev,
      34             :                                             struct winbindd_cli_state *cli,
      35             :                                             struct winbindd_request *request)
      36             : {
      37           0 :         struct tevent_req *req, *subreq;
      38           0 :         struct winbindd_lookupname_state *state;
      39        3834 :         char *p = NULL;
      40        3834 :         const char *domname = NULL;
      41        3834 :         const char *name = NULL;
      42        3834 :         const char *namespace = NULL;
      43             : 
      44        3834 :         req = tevent_req_create(mem_ctx, &state,
      45             :                                 struct winbindd_lookupname_state);
      46        3834 :         if (req == NULL) {
      47           0 :                 return NULL;
      48             :         }
      49             : 
      50        3834 :         D_NOTICE("[%s (%u)] Winbind external command LOOKUPNAME start.\n",
      51             :                  cli->client_name,
      52             :                  (unsigned int)cli->pid);
      53             : 
      54        3834 :         state->ev = ev;
      55             : 
      56             :         /* Ensure null termination */
      57           0 :         request->data.name.dom_name[
      58        3834 :                 sizeof(request->data.name.dom_name)-1]='\0';
      59        3834 :         request->data.name.name[sizeof(request->data.name.name)-1]='\0';
      60             : 
      61        3834 :         if (strlen(request->data.name.dom_name) == 0) {
      62             :                 /* cope with the name being a fully qualified name */
      63           8 :                 p = strstr(request->data.name.name, lp_winbind_separator());
      64           8 :                 if (p != NULL) {
      65           0 :                         *p = '\0';
      66           0 :                         domname = request->data.name.name;
      67           0 :                         namespace = domname;
      68           0 :                         name = p + 1;
      69             :                 } else {
      70           8 :                         p = strchr(request->data.name.name, '@');
      71           8 :                         if (p != NULL) {
      72             :                                 /* upn */
      73           8 :                                 namespace = p + 1;
      74             :                         } else {
      75           0 :                                 namespace = "";
      76             :                         }
      77           8 :                         domname = "";
      78           8 :                         name = request->data.name.name;
      79             :                 }
      80             :         } else {
      81        3826 :                 domname = request->data.name.dom_name;
      82        3826 :                 namespace = domname;
      83        3826 :                 name = request->data.name.name;
      84             :         }
      85             : 
      86        3834 :         D_NOTICE("lookupname %s%s%s\n", domname, lp_winbind_separator(), name);
      87             : 
      88        3834 :         subreq = wb_lookupname_send(state, ev, namespace, domname, name, 0);
      89        3834 :         if (tevent_req_nomem(subreq, req)) {
      90           0 :                 return tevent_req_post(req, ev);
      91             :         }
      92        3834 :         tevent_req_set_callback(subreq, winbindd_lookupname_done, req);
      93        3834 :         return req;
      94             : }
      95             : 
      96        3834 : static void winbindd_lookupname_done(struct tevent_req *subreq)
      97             : {
      98        3834 :         struct tevent_req *req = tevent_req_callback_data(
      99             :                 subreq, struct tevent_req);
     100        3834 :         struct winbindd_lookupname_state *state = tevent_req_data(
     101             :                 req, struct winbindd_lookupname_state);
     102           0 :         NTSTATUS status;
     103             : 
     104        3834 :         status = wb_lookupname_recv(subreq, &state->sid, &state->type);
     105        3834 :         TALLOC_FREE(subreq);
     106        3834 :         if (tevent_req_nterror(req, status)) {
     107         272 :                 return;
     108             :         }
     109        3562 :         tevent_req_done(req);
     110             : }
     111             : 
     112        3834 : NTSTATUS winbindd_lookupname_recv(struct tevent_req *req,
     113             :                                   struct winbindd_response *response)
     114             : {
     115        3834 :         struct winbindd_lookupname_state *state = tevent_req_data(
     116             :                 req, struct winbindd_lookupname_state);
     117           0 :         NTSTATUS status;
     118             : 
     119        3834 :         D_NOTICE("Winbind external command LOOKUPNAME end.\n");
     120        3834 :         if (tevent_req_is_nterror(req, &status)) {
     121           0 :                 struct dom_sid_buf buf;
     122         272 :                 D_WARNING("Could not convert SID %s, error is %s\n",
     123             :                           dom_sid_str_buf(&state->sid, &buf),
     124             :                           nt_errstr(status));
     125         272 :                 return status;
     126             :         }
     127        3562 :         sid_to_fstring(response->data.sid.sid, &state->sid);
     128        3562 :         response->data.sid.type = state->type;
     129        3562 :         return NT_STATUS_OK;
     130             : }

Generated by: LCOV version 1.14