LCOV - code coverage report
Current view: top level - source3/winbindd - winbindd_getdcname.c (source / functions) Hit Total Coverage
Test: coverage report for master 2f515e9b Lines: 25 31 80.6 %
Date: 2024-04-21 15:09:00 Functions: 3 3 100.0 %

          Line data    Source code
       1             : /*
       2             :    Unix SMB/CIFS implementation.
       3             :    async implementation of WINBINDD_GETDCNAME
       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 "librpc/gen_ndr/ndr_winbind_c.h"
      23             : #include "lib/util/string_wrappers.h"
      24             : 
      25             : struct winbindd_getdcname_state {
      26             :         struct netr_DsRGetDCNameInfo *dcinfo;
      27             : };
      28             : 
      29             : static void winbindd_getdcname_done(struct tevent_req *subreq);
      30             : 
      31           6 : struct tevent_req *winbindd_getdcname_send(TALLOC_CTX *mem_ctx,
      32             :                                            struct tevent_context *ev,
      33             :                                            struct winbindd_cli_state *cli,
      34             :                                            struct winbindd_request *request)
      35             : {
      36           0 :         struct tevent_req *req, *subreq;
      37           0 :         struct winbindd_getdcname_state *state;
      38             : 
      39           6 :         req = tevent_req_create(mem_ctx, &state,
      40             :                                 struct winbindd_getdcname_state);
      41           6 :         if (req == NULL) {
      42           0 :                 return NULL;
      43             :         }
      44             : 
      45           6 :         request->domain_name[sizeof(request->domain_name)-1] = '\0';
      46             : 
      47           6 :         D_NOTICE("[%s (%u)] Winbind external command GETDCNAME start.\n"
      48             :                  "Search DCNAME for domain %s.\n",
      49             :                  cli->client_name,
      50             :                  (unsigned int)cli->pid,
      51             :                  request->domain_name);
      52             : 
      53           6 :         subreq = wb_dsgetdcname_send(state, ev, request->domain_name, NULL,
      54             :                                      NULL, 0);
      55           6 :         if (tevent_req_nomem(subreq, req)) {
      56           0 :                 return tevent_req_post(req, ev);
      57             :         }
      58           6 :         tevent_req_set_callback(subreq, winbindd_getdcname_done, req);
      59           6 :         return req;
      60             : }
      61             : 
      62           6 : static void winbindd_getdcname_done(struct tevent_req *subreq)
      63             : {
      64           6 :         struct tevent_req *req = tevent_req_callback_data(
      65             :                 subreq, struct tevent_req);
      66           6 :         struct winbindd_getdcname_state *state = tevent_req_data(
      67             :                 req, struct winbindd_getdcname_state);
      68           0 :         NTSTATUS status;
      69             : 
      70           6 :         status = wb_dsgetdcname_recv(subreq, state, &state->dcinfo);
      71           6 :         TALLOC_FREE(subreq);
      72           6 :         if (tevent_req_nterror(req, status)) {
      73           4 :                 return;
      74             :         }
      75           2 :         tevent_req_done(req);
      76             : }
      77             : 
      78           6 : NTSTATUS winbindd_getdcname_recv(struct tevent_req *req,
      79             :                                  struct winbindd_response *response)
      80             : {
      81           6 :         struct winbindd_getdcname_state *state = tevent_req_data(
      82             :                 req, struct winbindd_getdcname_state);
      83           0 :         NTSTATUS status;
      84             : 
      85           6 :         if (tevent_req_is_nterror(req, &status)) {
      86           4 :                 D_WARNING("getdcname failed: %s\n", nt_errstr(status));
      87           4 :                 return status;
      88             :         }
      89           2 :         fstrcpy(response->data.dc_name, strip_hostname(state->dcinfo->dc_unc));
      90             : 
      91           2 :         D_NOTICE("Winbind external command GETDCNAME end.\n"
      92             :                  "Got DCNAME '%s'.\n",
      93             :                  response->data.dc_name);
      94           2 :         return NT_STATUS_OK;
      95             : }

Generated by: LCOV version 1.14