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

          Line data    Source code
       1             : /*
       2             :    Unix SMB/CIFS implementation.
       3             :    async implementation of WINBINDD_GETPWNAM
       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 "passdb/lookup_sid.h" /* only for LOOKUP_NAME_NO_NSS flag */
      23             : #include "libcli/security/dom_sid.h"
      24             : 
      25             : struct winbindd_getpwnam_state {
      26             :         struct tevent_context *ev;
      27             :         char *namespace;
      28             :         char *domname;
      29             :         char *username;
      30             :         struct dom_sid sid;
      31             :         enum lsa_SidType type;
      32             :         struct winbindd_pw pw;
      33             : };
      34             : 
      35             : static void winbindd_getpwnam_lookupname_done(struct tevent_req *subreq);
      36             : static void winbindd_getpwnam_done(struct tevent_req *subreq);
      37             : 
      38       91415 : struct tevent_req *winbindd_getpwnam_send(TALLOC_CTX *mem_ctx,
      39             :                                           struct tevent_context *ev,
      40             :                                           struct winbindd_cli_state *cli,
      41             :                                           struct winbindd_request *request)
      42             : {
      43           0 :         struct tevent_req *req, *subreq;
      44           0 :         struct winbindd_getpwnam_state *state;
      45           0 :         char *domuser, *mapped_user;
      46           0 :         NTSTATUS status;
      47           0 :         bool ok;
      48             : 
      49       91415 :         req = tevent_req_create(mem_ctx, &state,
      50             :                                 struct winbindd_getpwnam_state);
      51       91415 :         if (req == NULL) {
      52           0 :                 return NULL;
      53             :         }
      54       91415 :         state->ev = ev;
      55             : 
      56             :         /* Ensure null termination */
      57       91415 :         request->data.username[sizeof(request->data.username)-1]='\0';
      58             : 
      59       91415 :         D_NOTICE("[%s (%u)] Winbind external command GETPWNAM start.\n"
      60             :                  "Query username '%s'.\n",
      61             :                  cli->client_name,
      62             :                  (unsigned int)cli->pid,
      63             :                  request->data.username);
      64             : 
      65       91415 :         domuser = request->data.username;
      66             : 
      67       91415 :         status = normalize_name_unmap(state, domuser, &mapped_user);
      68             : 
      69       91415 :         if (NT_STATUS_IS_OK(status)
      70       91415 :             || NT_STATUS_EQUAL(status, NT_STATUS_FILE_RENAMED)) {
      71             :                 /* normalize_name_unmapped did something */
      72           0 :                 domuser = mapped_user;
      73             :         }
      74             : 
      75       91415 :         ok = parse_domain_user(state,
      76             :                                domuser,
      77       91415 :                                &state->namespace,
      78       91415 :                                &state->domname,
      79       91415 :                                &state->username);
      80       91415 :         if (!ok) {
      81           0 :                 D_WARNING("Could not parse domain user: %s\n", domuser);
      82           0 :                 tevent_req_nterror(req, NT_STATUS_INVALID_PARAMETER);
      83           0 :                 return tevent_req_post(req, ev);
      84             :         }
      85             : 
      86       91415 :         subreq = wb_lookupname_send(state, ev,
      87       91415 :                                     state->namespace,
      88       91415 :                                     state->domname,
      89       91415 :                                     state->username,
      90             :                                     LOOKUP_NAME_NO_NSS);
      91       91415 :         if (tevent_req_nomem(subreq, req)) {
      92           0 :                 return tevent_req_post(req, ev);
      93             :         }
      94       91415 :         tevent_req_set_callback(subreq, winbindd_getpwnam_lookupname_done,
      95             :                                 req);
      96       91415 :         return req;
      97             : }
      98             : 
      99       91415 : static void winbindd_getpwnam_lookupname_done(struct tevent_req *subreq)
     100             : {
     101       91415 :         struct tevent_req *req = tevent_req_callback_data(
     102             :                 subreq, struct tevent_req);
     103       91415 :         struct winbindd_getpwnam_state *state = tevent_req_data(
     104             :                 req, struct winbindd_getpwnam_state);
     105           0 :         NTSTATUS status;
     106             : 
     107       91415 :         status = wb_lookupname_recv(subreq, &state->sid, &state->type);
     108       91415 :         TALLOC_FREE(subreq);
     109       91415 :         if (tevent_req_nterror(req, status)) {
     110         278 :                 return;
     111             :         }
     112             : 
     113       91137 :         subreq = wb_getpwsid_send(state, state->ev, &state->sid, &state->pw);
     114       91137 :         if (tevent_req_nomem(subreq, req)) {
     115           0 :                 return;
     116             :         }
     117       91137 :         tevent_req_set_callback(subreq, winbindd_getpwnam_done, req);
     118             : }
     119             : 
     120       91137 : static void winbindd_getpwnam_done(struct tevent_req *subreq)
     121             : {
     122       91137 :         struct tevent_req *req = tevent_req_callback_data(
     123             :                 subreq, struct tevent_req);
     124           0 :         NTSTATUS status;
     125             : 
     126       91137 :         status = wb_getpwsid_recv(subreq);
     127       91137 :         TALLOC_FREE(subreq);
     128       91137 :         if (tevent_req_nterror(req, status)) {
     129          48 :                 return;
     130             :         }
     131       91089 :         tevent_req_done(req);
     132             : }
     133             : 
     134       91415 : NTSTATUS winbindd_getpwnam_recv(struct tevent_req *req,
     135             :                                 struct winbindd_response *response)
     136             : {
     137       91415 :         struct winbindd_getpwnam_state *state = tevent_req_data(
     138             :                 req, struct winbindd_getpwnam_state);
     139           0 :         NTSTATUS status;
     140             : 
     141       91415 :         if (tevent_req_is_nterror(req, &status)) {
     142           0 :                 struct dom_sid_buf buf;
     143         326 :                 D_WARNING("Could not convert sid %s: %s\n",
     144             :                           dom_sid_str_buf(&state->sid, &buf),
     145             :                           nt_errstr(status));
     146         326 :                 return status;
     147             :         }
     148       91089 :         response->data.pw = state->pw;
     149             : 
     150       91089 :         D_NOTICE("Winbind external command GETPWNAM end.\n"
     151             :                  "(name:passwd:uid:gid:gecos:dir:shell)\n"
     152             :                  "%s:%s:%u:%u:%s:%s:%s\n",
     153             :                  state->pw.pw_name,
     154             :                  state->pw.pw_passwd,
     155             :                  (unsigned int)state->pw.pw_uid,
     156             :                  (unsigned int)state->pw.pw_gid,
     157             :                  state->pw.pw_gecos,
     158             :                  state->pw.pw_dir,
     159             :                  state->pw.pw_shell
     160             :                  );
     161             : 
     162       91089 :         return NT_STATUS_OK;
     163             : }

Generated by: LCOV version 1.14