LCOV - code coverage report
Current view: top level - source3/winbindd - winbindd_getsidaliases.c (source / functions) Hit Total Coverage
Test: coverage report for support-claim-type-attributes 6b5c566e Lines: 39 71 54.9 %
Date: 2023-11-21 12:31:41 Functions: 3 3 100.0 %

          Line data    Source code
       1             : /*
       2             :    Unix SMB/CIFS implementation.
       3             :    async implementation of WINBINDD_GETSIDALIASES
       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/security.h"
      23             : 
      24             : struct winbindd_getsidaliases_state {
      25             :         struct dom_sid sid;
      26             :         uint32_t num_aliases;
      27             :         uint32_t *aliases;
      28             : };
      29             : 
      30             : static void winbindd_getsidaliases_done(struct tevent_req *subreq);
      31             : 
      32           2 : struct tevent_req *winbindd_getsidaliases_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_getsidaliases_state *state;
      39           0 :         struct winbindd_domain *domain;
      40           0 :         uint32_t num_sids, i;
      41           0 :         struct dom_sid *sids;
      42             : 
      43           2 :         req = tevent_req_create(mem_ctx, &state,
      44             :                                 struct winbindd_getsidaliases_state);
      45           2 :         if (req == NULL) {
      46           0 :                 return NULL;
      47             :         }
      48             : 
      49             :         /* Ensure null termination */
      50           2 :         request->data.sid[sizeof(request->data.sid)-1]='\0';
      51             : 
      52           2 :         if (!string_to_sid(&state->sid, request->data.sid)) {
      53           0 :                 D_WARNING("Could not get convert sid %s from string\n",
      54             :                           request->data.sid);
      55           0 :                 tevent_req_nterror(req, NT_STATUS_INVALID_PARAMETER);
      56           0 :                 return tevent_req_post(req, ev);
      57             :         }
      58             : 
      59           2 :         domain = find_domain_from_sid_noinit(&state->sid);
      60           2 :         if (domain == NULL) {
      61           0 :                 D_WARNING("could not find domain entry for sid %s\n",
      62             :                          request->data.sid);
      63           0 :                 tevent_req_nterror(req, NT_STATUS_NO_SUCH_DOMAIN);
      64           0 :                 return tevent_req_post(req, ev);
      65             :         }
      66             : 
      67           2 :         num_sids = 0;
      68           2 :         sids = NULL;
      69             : 
      70           2 :         if (request->extra_data.data != NULL) {
      71           2 :                 if (request->extra_data.data[request->extra_len-1] != '\0') {
      72           0 :                         D_WARNING("Got non-NULL terminated sidlist\n");
      73           0 :                         tevent_req_nterror(req, NT_STATUS_INVALID_PARAMETER);
      74           0 :                         return tevent_req_post(req, ev);
      75             :                 }
      76           2 :                 if (!parse_sidlist(state, request->extra_data.data,
      77             :                                    &sids, &num_sids)) {
      78           0 :                         D_WARNING("Could not parse SID list: %s\n",
      79             :                                   request->extra_data.data);
      80           0 :                         tevent_req_nterror(req, NT_STATUS_INVALID_PARAMETER);
      81           0 :                         return tevent_req_post(req, ev);
      82             :                 }
      83             :         }
      84             : 
      85           2 :         D_NOTICE("[%s (%u)] Winbind external command GETSIDALIASES start.\n"
      86             :                  "sid=%s\n",
      87             :                  cli->client_name,
      88             :                  (unsigned int)cli->pid,
      89             :                  request->data.sid);
      90           2 :         if (CHECK_DEBUGLVL(DBGLVL_DEBUG)) {
      91           0 :                 for (i = 0; i < num_sids; i++) {
      92           0 :                         struct dom_sid_buf sidstr;
      93           0 :                         D_NOTICE("%"PRIu32": %s\n",
      94             :                                  i, dom_sid_str_buf(&sids[i], &sidstr));
      95             :                 }
      96             :         }
      97             : 
      98           2 :         subreq = wb_lookupuseraliases_send(state, ev, domain, num_sids, sids);
      99           2 :         if (tevent_req_nomem(subreq, req)) {
     100           0 :                 return tevent_req_post(req, ev);
     101             :         }
     102           2 :         tevent_req_set_callback(subreq, winbindd_getsidaliases_done, req);
     103           2 :         return req;
     104             : }
     105             : 
     106           2 : static void winbindd_getsidaliases_done(struct tevent_req *subreq)
     107             : {
     108           2 :         struct tevent_req *req = tevent_req_callback_data(
     109             :                 subreq, struct tevent_req);
     110           2 :         struct winbindd_getsidaliases_state *state = tevent_req_data(
     111             :                 req, struct winbindd_getsidaliases_state);
     112           0 :         NTSTATUS status;
     113             : 
     114           2 :         status = wb_lookupuseraliases_recv(subreq, state, &state->num_aliases,
     115             :                                            &state->aliases);
     116           2 :         TALLOC_FREE(subreq);
     117           2 :         if (tevent_req_nterror(req, status)) {
     118           0 :                 return;
     119             :         }
     120           2 :         tevent_req_done(req);
     121             : }
     122             : 
     123           2 : NTSTATUS winbindd_getsidaliases_recv(struct tevent_req *req,
     124             :                                      struct winbindd_response *response)
     125             : {
     126           2 :         struct winbindd_getsidaliases_state *state = tevent_req_data(
     127             :                 req, struct winbindd_getsidaliases_state);
     128           0 :         NTSTATUS status;
     129           0 :         uint32_t i;
     130           0 :         char *sidlist;
     131             : 
     132           2 :         if (tevent_req_is_nterror(req, &status)) {
     133           0 :                 D_WARNING("Failed with %s.\n", nt_errstr(status));
     134           0 :                 return status;
     135             :         }
     136             : 
     137           2 :         sidlist = talloc_strdup(response, "");
     138             : 
     139           2 :         D_NOTICE("Winbind external command GETSIDALIASES end.\n"
     140             :                  "Received %"PRIu32" alias(es).\n",
     141             :                  state->num_aliases);
     142           4 :         for (i=0; i<state->num_aliases; i++) {
     143           0 :                 struct dom_sid sid;
     144           0 :                 struct dom_sid_buf tmp;
     145           2 :                 sid_compose(&sid, &state->sid, state->aliases[i]);
     146             : 
     147           2 :                 talloc_asprintf_addbuf(
     148             :                         &sidlist, "%s\n", dom_sid_str_buf(&sid, &tmp));
     149           2 :                 D_NOTICE("%"PRIu32": %s\n", i, dom_sid_str_buf(&sid, &tmp));
     150             :         }
     151             : 
     152           2 :         if (sidlist == NULL) {
     153           0 :                 return NT_STATUS_NO_MEMORY;
     154             :         }
     155             : 
     156           2 :         response->extra_data.data = sidlist;
     157           2 :         response->length += talloc_get_size(sidlist);
     158           2 :         response->data.num_entries = state->num_aliases;
     159           2 :         return NT_STATUS_OK;
     160             : }

Generated by: LCOV version 1.14