LCOV - code coverage report
Current view: top level - source3/winbindd - winbindd_xids_to_sids.c (source / functions) Hit Total Coverage
Test: coverage report for master 2b515b7d Lines: 39 60 65.0 %
Date: 2024-02-28 12:06:22 Functions: 3 3 100.0 %

          Line data    Source code
       1             : /*
       2             :    Unix SMB/CIFS implementation.
       3             :    async implementation of WINBINDD_SIDS_TO_XIDS
       4             :    Copyright (C) Volker Lendecke 2011
       5             :    Copyright (C) Michael Adam 2012
       6             : 
       7             :    This program is free software; you can redistribute it and/or modify
       8             :    it under the terms of the GNU General Public License as published by
       9             :    the Free Software Foundation; either version 3 of the License, or
      10             :    (at your option) any later version.
      11             : 
      12             :    This program is distributed in the hope that it will be useful,
      13             :    but WITHOUT ANY WARRANTY; without even the implied warranty of
      14             :    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      15             :    GNU General Public License for more details.
      16             : 
      17             :    You should have received a copy of the GNU General Public License
      18             :    along with this program.  If not, see <http://www.gnu.org/licenses/>.
      19             : */
      20             : 
      21             : #include "includes.h"
      22             : #include "winbindd.h"
      23             : #include "../libcli/security/security.h"
      24             : 
      25             : 
      26             : struct winbindd_xids_to_sids_state {
      27             :         struct tevent_context *ev;
      28             : 
      29             :         struct unixid *xids;
      30             :         uint32_t num_xids;
      31             : 
      32             :         struct dom_sid *sids;
      33             : };
      34             : 
      35             : static void winbindd_xids_to_sids_done(struct tevent_req *subreq);
      36             : 
      37        1990 : struct tevent_req *winbindd_xids_to_sids_send(TALLOC_CTX *mem_ctx,
      38             :                                               struct tevent_context *ev,
      39             :                                               struct winbindd_cli_state *cli,
      40             :                                               struct winbindd_request *request)
      41             : {
      42           0 :         struct tevent_req *req, *subreq;
      43           0 :         struct winbindd_xids_to_sids_state *state;
      44             : 
      45        1990 :         req = tevent_req_create(mem_ctx, &state,
      46             :                                 struct winbindd_xids_to_sids_state);
      47        1990 :         if (req == NULL) {
      48           0 :                 return NULL;
      49             :         }
      50        1990 :         state->ev = ev;
      51             : 
      52        1990 :         D_NOTICE("[%s (%u)] Winbind external command XIDS_TO_SIDS start.\n",
      53             :                  cli->client_name,
      54             :                  (unsigned int)cli->pid);
      55             : 
      56        1990 :         if (request->extra_len == 0) {
      57           0 :                 tevent_req_done(req);
      58           0 :                 return tevent_req_post(req, ev);
      59             :         }
      60        1990 :         if (request->extra_data.data[request->extra_len-1] != '\0') {
      61           0 :                 D_DEBUG("Got invalid XID list.\n");
      62           0 :                 tevent_req_nterror(req, NT_STATUS_INVALID_PARAMETER);
      63           0 :                 return tevent_req_post(req, ev);
      64             :         }
      65        1990 :         if (!parse_xidlist(state, request->extra_data.data,
      66        1990 :                            &state->xids, &state->num_xids)) {
      67           0 :                 D_DEBUG("parse_sidlist failed\n");
      68           0 :                 tevent_req_nterror(req, NT_STATUS_INVALID_PARAMETER);
      69           0 :                 return tevent_req_post(req, ev);
      70             :         }
      71             : 
      72        1990 :         D_DEBUG("Resolving %"PRIu32" XID(s):\n%s\n",
      73             :                 state->num_xids,
      74             :                 (char *)request->extra_data.data);
      75             : 
      76        1990 :         subreq = wb_xids2sids_send(state, ev, state->xids, state->num_xids);
      77        1990 :         if (tevent_req_nomem(subreq, req)) {
      78           0 :                 return tevent_req_post(req, ev);
      79             :         }
      80        1990 :         tevent_req_set_callback(subreq, winbindd_xids_to_sids_done, req);
      81        1990 :         return req;
      82             : }
      83             : 
      84        1990 : static void winbindd_xids_to_sids_done(struct tevent_req *subreq)
      85             : {
      86        1990 :         struct tevent_req *req = tevent_req_callback_data(
      87             :                 subreq, struct tevent_req);
      88        1990 :         struct winbindd_xids_to_sids_state *state = tevent_req_data(
      89             :                 req, struct winbindd_xids_to_sids_state);
      90           0 :         NTSTATUS status;
      91             : 
      92        1990 :         status = wb_xids2sids_recv(subreq, state, &state->sids);
      93        1990 :         TALLOC_FREE(subreq);
      94        1990 :         if (tevent_req_nterror(req, status)) {
      95           0 :                 return;
      96             :         }
      97        1990 :         tevent_req_done(req);
      98             : }
      99             : 
     100        1990 : NTSTATUS winbindd_xids_to_sids_recv(struct tevent_req *req,
     101             :                                     struct winbindd_response *response)
     102             : {
     103        1990 :         struct winbindd_xids_to_sids_state *state = tevent_req_data(
     104             :                 req, struct winbindd_xids_to_sids_state);
     105           0 :         NTSTATUS status;
     106        1990 :         char *result = NULL;
     107           0 :         uint32_t i;
     108             : 
     109        1990 :         D_NOTICE("Winbind external command XIDS_TO_SIDS end.\n");
     110        1990 :         if (tevent_req_is_nterror(req, &status)) {
     111           0 :                 D_WARNING("Could not convert xids: %s\n", nt_errstr(status));
     112           0 :                 return status;
     113             :         }
     114             : 
     115        1990 :         result = talloc_strdup(response, "");
     116        1990 :         if (result == NULL) {
     117           0 :                 return NT_STATUS_NO_MEMORY;
     118             :         }
     119             : 
     120        4048 :         for (i=0; i<state->num_xids; i++) {
     121           0 :                 struct dom_sid_buf sid_buf;
     122        2058 :                 const char *str = "-";
     123             : 
     124        2058 :                 if (!is_null_sid(&state->sids[i])) {
     125        1769 :                         dom_sid_str_buf(&state->sids[i], &sid_buf);
     126        1769 :                         str = sid_buf.buf;
     127             :                 }
     128             : 
     129        2058 :                 D_NOTICE("%"PRIu32": XID %"PRIu32" mapped to SID %s.\n",
     130             :                          i, state->xids[i].id, str);
     131        2058 :                 result = talloc_asprintf_append_buffer(
     132             :                         result, "%s\n", str);
     133        2058 :                 if (result == NULL) {
     134           0 :                         return NT_STATUS_NO_MEMORY;
     135             :                 }
     136             :         }
     137             : 
     138        1990 :         response->extra_data.data = result;
     139        1990 :         response->length += talloc_get_size(result);
     140             : 
     141        1990 :         return NT_STATUS_OK;
     142             : }

Generated by: LCOV version 1.14