LCOV - code coverage report
Current view: top level - source3/winbindd - winbindd_sids_to_xids.c (source / functions) Hit Total Coverage
Test: coverage report for master 2b515b7d Lines: 60 77 77.9 %
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_sids_to_xids_state {
      27             :         struct tevent_context *ev;
      28             :         struct dom_sid *sids;
      29             :         uint32_t num_sids;
      30             :         struct unixid *xids;
      31             : };
      32             : 
      33             : static void winbindd_sids_to_xids_done(struct tevent_req *subreq);
      34             : 
      35        1993 : struct tevent_req *winbindd_sids_to_xids_send(TALLOC_CTX *mem_ctx,
      36             :                                               struct tevent_context *ev,
      37             :                                               struct winbindd_cli_state *cli,
      38             :                                               struct winbindd_request *request)
      39             : {
      40           0 :         struct tevent_req *req, *subreq;
      41           0 :         struct winbindd_sids_to_xids_state *state;
      42             : 
      43        1993 :         req = tevent_req_create(mem_ctx, &state,
      44             :                                 struct winbindd_sids_to_xids_state);
      45        1993 :         if (req == NULL) {
      46           0 :                 return NULL;
      47             :         }
      48        1993 :         state->ev = ev;
      49             : 
      50        1993 :         D_NOTICE("[%s (%u)] Winbind external command SIDS_TO_XIDS start.\n",
      51             :                  cli->client_name,
      52             :                  (unsigned int)cli->pid);
      53             : 
      54        1993 :         if (request->extra_len == 0) {
      55           0 :                 tevent_req_done(req);
      56           0 :                 return tevent_req_post(req, ev);
      57             :         }
      58        1993 :         if (request->extra_data.data[request->extra_len-1] != '\0') {
      59           0 :                 D_DEBUG("Got invalid sids list\n");
      60           0 :                 tevent_req_nterror(req, NT_STATUS_INVALID_PARAMETER);
      61           0 :                 return tevent_req_post(req, ev);
      62             :         }
      63        1993 :         if (!parse_sidlist(state, request->extra_data.data,
      64        1993 :                            &state->sids, &state->num_sids)) {
      65           0 :                 D_DEBUG("parse_sidlist failed\n");
      66           0 :                 tevent_req_nterror(req, NT_STATUS_INVALID_PARAMETER);
      67           0 :                 return tevent_req_post(req, ev);
      68             :         }
      69             : 
      70        1993 :         D_DEBUG("Resolving %"PRIu32" SID(s).\n", state->num_sids);
      71             : 
      72        1993 :         subreq = wb_sids2xids_send(state, ev, state->sids, state->num_sids);
      73        1993 :         if (tevent_req_nomem(subreq, req)) {
      74           0 :                 return tevent_req_post(req, ev);
      75             :         }
      76             : 
      77        1993 :         tevent_req_set_callback(subreq, winbindd_sids_to_xids_done, req);
      78        1993 :         return req;
      79             : }
      80             : 
      81        1993 : static void winbindd_sids_to_xids_done(struct tevent_req *subreq)
      82             : {
      83        1993 :         struct tevent_req *req = tevent_req_callback_data(
      84             :                 subreq, struct tevent_req);
      85        1993 :         struct winbindd_sids_to_xids_state *state = tevent_req_data(
      86             :                 req, struct winbindd_sids_to_xids_state);
      87           0 :         NTSTATUS status;
      88             : 
      89        1993 :         state->xids = talloc_zero_array(state, struct unixid, state->num_sids);
      90        1993 :         if (tevent_req_nomem(state->xids, req)) {
      91         728 :                 return;
      92             :         }
      93             : 
      94        1993 :         status = wb_sids2xids_recv(subreq, state->xids, state->num_sids);
      95        1993 :         TALLOC_FREE(subreq);
      96        1993 :         if (tevent_req_nterror(req, status)) {
      97         728 :                 return;
      98             :         }
      99        1265 :         tevent_req_done(req);
     100             : }
     101             : 
     102        1993 : NTSTATUS winbindd_sids_to_xids_recv(struct tevent_req *req,
     103             :                                     struct winbindd_response *response)
     104             : {
     105        1993 :         struct winbindd_sids_to_xids_state *state = tevent_req_data(
     106             :                 req, struct winbindd_sids_to_xids_state);
     107           0 :         NTSTATUS status;
     108        1993 :         char *result = NULL;
     109           0 :         uint32_t i;
     110             : 
     111        1993 :         D_NOTICE("Winbind external command SIDS_TO_XIDS end.\n");
     112        1993 :         if (tevent_req_is_nterror(req, &status)) {
     113         728 :                 D_WARNING("Could not convert sids: %s\n", nt_errstr(status));
     114         728 :                 return status;
     115             :         }
     116             : 
     117        1265 :         result = talloc_strdup(response, "");
     118             : 
     119        2794 :         for (i=0; i<state->num_sids; i++) {
     120        1529 :                 char type = '\0';
     121        1529 :                 bool found = true;
     122           0 :                 struct unixid xid;
     123             : 
     124        1529 :                 xid = state->xids[i];
     125             : 
     126        1529 :                 switch (xid.type) {
     127         348 :                 case ID_TYPE_UID:
     128         348 :                         type = 'U';
     129         348 :                         break;
     130        1046 :                 case ID_TYPE_GID:
     131        1046 :                         type = 'G';
     132        1046 :                         break;
     133          40 :                 case ID_TYPE_BOTH:
     134          40 :                         type = 'B';
     135          40 :                         break;
     136          95 :                 default:
     137          95 :                         found = false;
     138          95 :                         break;
     139             :                 }
     140             : 
     141        1529 :                 if (xid.id == UINT32_MAX) {
     142          95 :                         found = false;
     143             :                 }
     144             : 
     145        1529 :                 if (found) {
     146        1434 :                         talloc_asprintf_addbuf(
     147             :                                 &result,
     148             :                                 "%c%lu\n",
     149             :                                 type,
     150        1434 :                                 (unsigned long)xid.id);
     151             :                 } else {
     152          95 :                         talloc_asprintf_addbuf(&result, "\n");
     153             :                 }
     154             :         }
     155             : 
     156        1265 :         if (result == NULL) {
     157           0 :                 return NT_STATUS_NO_MEMORY;
     158             :         }
     159             : 
     160        1265 :         response->extra_data.data = result;
     161        1265 :         response->length += talloc_get_size(result);
     162             : 
     163        1265 :         return NT_STATUS_OK;
     164             : }

Generated by: LCOV version 1.14