LCOV - code coverage report
Current view: top level - source3/lib/netapi - getdc.c (source / functions) Hit Total Coverage
Test: coverage report for master 2f515e9b Lines: 0 76 0.0 %
Date: 2024-04-21 15:09:00 Functions: 0 6 0.0 %

          Line data    Source code
       1             : /*
       2             :  *  Unix SMB/CIFS implementation.
       3             :  *  NetApi GetDC Support
       4             :  *  Copyright (C) Guenther Deschner 2007
       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             : 
      22             : #include "../librpc/gen_ndr/ndr_netlogon_c.h"
      23             : #include "librpc/gen_ndr/libnetapi.h"
      24             : #include "lib/netapi/netapi.h"
      25             : #include "lib/netapi/netapi_private.h"
      26             : #include "lib/netapi/libnetapi.h"
      27             : #include "libsmb/dsgetdcname.h"
      28             : 
      29             : /********************************************************************
      30             : ********************************************************************/
      31             : 
      32           0 : WERROR NetGetDCName_l(struct libnetapi_ctx *ctx,
      33             :                       struct NetGetDCName *r)
      34             : {
      35           0 :         LIBNETAPI_REDIRECT_TO_LOCALHOST(ctx, r, NetGetDCName);
      36             : }
      37             : 
      38             : /********************************************************************
      39             : ********************************************************************/
      40             : 
      41           0 : WERROR NetGetDCName_r(struct libnetapi_ctx *ctx,
      42             :                       struct NetGetDCName *r)
      43             : {
      44           0 :         NTSTATUS status;
      45           0 :         WERROR werr;
      46           0 :         struct dcerpc_binding_handle *b;
      47           0 :         const char *dcname;
      48           0 :         void *buffer;
      49             : 
      50           0 :         werr = libnetapi_get_binding_handle(ctx, r->in.server_name,
      51             :                                             &ndr_table_netlogon,
      52             :                                             &b);
      53           0 :         if (!W_ERROR_IS_OK(werr)) {
      54           0 :                 goto done;
      55             :         }
      56             : 
      57           0 :         status = dcerpc_netr_GetDcName(b, talloc_tos(),
      58             :                                        r->in.server_name,
      59             :                                        r->in.domain_name,
      60             :                                        &dcname,
      61             :                                        &werr);
      62             : 
      63           0 :         if (!NT_STATUS_IS_OK(status)) {
      64           0 :                 werr = ntstatus_to_werror(status);
      65           0 :                 goto done;
      66             :         }
      67             : 
      68           0 :         if (!W_ERROR_IS_OK(werr)) {
      69           0 :                 goto done;
      70             :         }
      71             : 
      72           0 :         if (NetApiBufferAllocate(strlen_m_term(dcname), &buffer)) {
      73           0 :                 werr = WERR_NOT_ENOUGH_MEMORY;
      74           0 :                 goto done;
      75             :         }
      76           0 :         memcpy(buffer, dcname, strlen_m_term(dcname));
      77           0 :         *r->out.buffer = buffer;
      78           0 :  done:
      79             : 
      80           0 :         return werr;
      81             : }
      82             : 
      83             : /********************************************************************
      84             : ********************************************************************/
      85             : 
      86           0 : WERROR NetGetAnyDCName_l(struct libnetapi_ctx *ctx,
      87             :                          struct NetGetAnyDCName *r)
      88             : {
      89           0 :         LIBNETAPI_REDIRECT_TO_LOCALHOST(ctx, r, NetGetAnyDCName);
      90             : }
      91             : 
      92             : /********************************************************************
      93             : ********************************************************************/
      94             : 
      95           0 : WERROR NetGetAnyDCName_r(struct libnetapi_ctx *ctx,
      96             :                          struct NetGetAnyDCName *r)
      97             : {
      98           0 :         NTSTATUS status;
      99           0 :         WERROR werr;
     100           0 :         struct dcerpc_binding_handle *b;
     101           0 :         const char *dcname;
     102           0 :         void *buffer;
     103             : 
     104           0 :         werr = libnetapi_get_binding_handle(ctx, r->in.server_name,
     105             :                                             &ndr_table_netlogon,
     106             :                                             &b);
     107           0 :         if (!W_ERROR_IS_OK(werr)) {
     108           0 :                 goto done;
     109             :         }
     110             : 
     111           0 :         status = dcerpc_netr_GetAnyDCName(b, talloc_tos(),
     112             :                                           r->in.server_name,
     113             :                                           r->in.domain_name,
     114             :                                           &dcname,
     115             :                                           &werr);
     116           0 :         if (!NT_STATUS_IS_OK(status)) {
     117           0 :                 werr = ntstatus_to_werror(status);
     118           0 :                 goto done;
     119             :         }
     120             : 
     121           0 :         if (!W_ERROR_IS_OK(werr)) {
     122           0 :                 goto done;
     123             :         }
     124             : 
     125           0 :         if (NetApiBufferAllocate(strlen_m_term(dcname), &buffer)) {
     126           0 :                 werr = WERR_NOT_ENOUGH_MEMORY;
     127           0 :                 goto done;
     128             :         }
     129           0 :         memcpy(buffer, dcname, strlen_m_term(dcname));
     130           0 :         *r->out.buffer = buffer;
     131             : 
     132           0 :  done:
     133             : 
     134           0 :         return werr;
     135             : 
     136             : }
     137             : 
     138             : /********************************************************************
     139             : ********************************************************************/
     140             : 
     141           0 : WERROR DsGetDcName_l(struct libnetapi_ctx *ctx,
     142             :                      struct DsGetDcName *r)
     143             : {
     144           0 :         NTSTATUS status;
     145           0 :         struct libnetapi_private_ctx *priv;
     146             : 
     147           0 :         priv = talloc_get_type_abort(ctx->private_data,
     148             :                 struct libnetapi_private_ctx);
     149             : 
     150           0 :         status = dsgetdcname(ctx,
     151             :                              priv->msg_ctx,
     152             :                              r->in.domain_name,
     153           0 :                              r->in.domain_guid,
     154             :                              r->in.site_name,
     155             :                              r->in.flags,
     156           0 :                              (struct netr_DsRGetDCNameInfo **)r->out.dc_info);
     157           0 :         if (!NT_STATUS_IS_OK(status)) {
     158           0 :                 libnetapi_set_error_string(ctx,
     159             :                         "failed to find DC: %s",
     160             :                         get_friendly_nt_error_msg(status));
     161             :         }
     162             : 
     163           0 :         return ntstatus_to_werror(status);
     164             : }
     165             : 
     166             : /********************************************************************
     167             : ********************************************************************/
     168             : 
     169           0 : WERROR DsGetDcName_r(struct libnetapi_ctx *ctx,
     170             :                      struct DsGetDcName *r)
     171             : {
     172           0 :         WERROR werr;
     173           0 :         NTSTATUS status;
     174           0 :         struct dcerpc_binding_handle *b;
     175             : 
     176           0 :         werr = libnetapi_get_binding_handle(ctx, r->in.server_name,
     177             :                                             &ndr_table_netlogon,
     178             :                                             &b);
     179           0 :         if (!W_ERROR_IS_OK(werr)) {
     180           0 :                 goto done;
     181             :         }
     182             : 
     183           0 :         status = dcerpc_netr_DsRGetDCNameEx(b,
     184             :                                             ctx,
     185             :                                             r->in.server_name,
     186             :                                             r->in.domain_name,
     187             :                                             r->in.domain_guid,
     188             :                                             r->in.site_name,
     189             :                                             r->in.flags,
     190           0 :                                             (struct netr_DsRGetDCNameInfo **)r->out.dc_info,
     191             :                                             &werr);
     192           0 :         if (NT_STATUS_IS_OK(status) && W_ERROR_IS_OK(werr)) {
     193           0 :                 goto done;
     194             :         }
     195             : 
     196           0 :         status = dcerpc_netr_DsRGetDCName(b,
     197             :                                           ctx,
     198             :                                           r->in.server_name,
     199             :                                           r->in.domain_name,
     200             :                                           r->in.domain_guid,
     201             :                                           NULL,
     202             :                                           r->in.flags,
     203           0 :                                           (struct netr_DsRGetDCNameInfo **)r->out.dc_info,
     204             :                                           &werr);
     205           0 :         if (!NT_STATUS_IS_OK(status)) {
     206           0 :                 werr = ntstatus_to_werror(status);
     207           0 :                 goto done;
     208             :         }
     209             : 
     210           0 :  done:
     211           0 :         return werr;
     212             : }

Generated by: LCOV version 1.14