LCOV - code coverage report
Current view: top level - source3/winbindd - winbindd_domain_info.c (source / functions) Hit Total Coverage
Test: coverage report for master 70ed9daf Lines: 39 57 68.4 %
Date: 2024-01-11 09:59:51 Functions: 3 3 100.0 %

          Line data    Source code
       1             : /*
       2             :  * Unix SMB/CIFS implementation.
       3             :  * async implementation of WINBINDD_DOMAIN_INFO
       4             :  * Copyright (C) Volker Lendecke 2018
       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 "lib/util/string_wrappers.h"
      23             : #include "lib/global_contexts.h"
      24             : #include "librpc/gen_ndr/ndr_winbind_c.h"
      25             : 
      26             : struct winbindd_domain_info_state {
      27             :         struct winbindd_domain *domain;
      28             :         uint32_t in;
      29             :         uint32_t out;
      30             : };
      31             : 
      32             : static void winbindd_domain_info_done(struct tevent_req *subreq);
      33             : 
      34         753 : struct tevent_req *winbindd_domain_info_send(
      35             :         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_domain_info_state *state;
      42             : 
      43         753 :         req = tevent_req_create(mem_ctx, &state,
      44             :                                 struct winbindd_domain_info_state);
      45         753 :         if (req == NULL) {
      46           0 :                 return NULL;
      47             :         }
      48             : 
      49         753 :         DEBUG(3, ("[%5lu]: domain_info [%s]\n", (unsigned long)cli->pid,
      50             :                   cli->request->domain_name));
      51             : 
      52        1506 :         state->domain = find_domain_from_name_noinit(
      53         753 :                 cli->request->domain_name);
      54             : 
      55         753 :         if (state->domain == NULL) {
      56           0 :                 DEBUG(3, ("Did not find domain [%s]\n",
      57             :                           cli->request->domain_name));
      58           0 :                 tevent_req_nterror(req, NT_STATUS_NO_SUCH_DOMAIN);
      59           0 :                 return tevent_req_post(req, ev);
      60             :         }
      61             : 
      62         753 :         if (state->domain->initialized) {
      63         749 :                 tevent_req_done(req);
      64         749 :                 return tevent_req_post(req, ev);
      65             :         }
      66             : 
      67             :         /*
      68             :          * Send a ping down. This implicitly initializes the domain.
      69             :          */
      70             : 
      71           4 :         state->in = cli->pid;
      72           4 :         state->out = 0;
      73           4 :         subreq = dcerpc_wbint_Ping_send(state,
      74             :                                         global_event_context(),
      75           4 :                                         dom_child_handle(state->domain),
      76           4 :                                         state->in,
      77           4 :                                         &state->out);
      78           4 :         if (tevent_req_nomem(subreq, req)) {
      79           0 :                 return tevent_req_post(req, ev);
      80             :         }
      81           4 :         tevent_req_set_callback(subreq, winbindd_domain_info_done, req);
      82             : 
      83           4 :         return req;
      84             : }
      85             : 
      86           4 : static void winbindd_domain_info_done(struct tevent_req *subreq)
      87             : {
      88           4 :         struct tevent_req *req = tevent_req_callback_data(
      89             :                 subreq, struct tevent_req);
      90           4 :         struct winbindd_domain_info_state *state = tevent_req_data(
      91             :                 req, struct winbindd_domain_info_state);
      92           0 :         NTSTATUS status, result;
      93             : 
      94           4 :         status = dcerpc_wbint_Ping_recv(subreq, state, &result);
      95           4 :         TALLOC_FREE(subreq);
      96           4 :         if (tevent_req_nterror(req, status)) {
      97           0 :                 DBG_NOTICE("dcerpc_wbint_Ping call failed: %s\n",
      98             :                            nt_errstr(status));
      99           0 :                 return;
     100             :         }
     101             : 
     102           4 :         if (tevent_req_nterror(req, result)) {
     103           0 :                 DBG_NOTICE("dcerpc_wbint_Ping failed: %s\n",
     104             :                            nt_errstr(result));
     105           0 :                 return;
     106             :         }
     107             : 
     108           4 :         if (!state->domain->initialized) {
     109           0 :                 DBG_INFO("dcerpc_wbint_Ping did not initialize domain %s\n",
     110             :                          state->domain->name);
     111           0 :                 tevent_req_nterror(req, NT_STATUS_INTERNAL_ERROR);
     112           0 :                 return;
     113             :         }
     114             : 
     115           4 :         tevent_req_done(req);
     116             : }
     117             : 
     118         753 : NTSTATUS winbindd_domain_info_recv(struct tevent_req *req,
     119             :                                    struct winbindd_response *response)
     120             : {
     121         753 :         struct winbindd_domain_info_state *state = tevent_req_data(
     122             :                 req, struct winbindd_domain_info_state);
     123         753 :         struct winbindd_domain *domain = state->domain;
     124           0 :         NTSTATUS status;
     125             : 
     126         753 :         if (tevent_req_is_nterror(req, &status)) {
     127           0 :                 DBG_NOTICE("winbindd_domain_info failed: %s\n",
     128             :                            nt_errstr(status));
     129           0 :                 return status;
     130             :         }
     131             : 
     132         753 :         fstrcpy(response->data.domain_info.name, domain->name);
     133         753 :         fstrcpy(response->data.domain_info.alt_name, domain->alt_name);
     134         753 :         sid_to_fstring(response->data.domain_info.sid, &domain->sid);
     135             : 
     136         753 :         response->data.domain_info.native_mode = domain->native_mode;
     137         753 :         response->data.domain_info.active_directory = domain->active_directory;
     138         753 :         response->data.domain_info.primary = domain->primary;
     139             : 
     140         753 :         return NT_STATUS_OK;
     141             : }

Generated by: LCOV version 1.14