LCOV - code coverage report
Current view: top level - source4/torture/libnet - libnet_lookup.c (source / functions) Hit Total Coverage
Test: coverage report for abartlet/fix-coverage dd10fb34 Lines: 64 81 79.0 %
Date: 2021-09-23 10:06:22 Functions: 4 4 100.0 %

          Line data    Source code
       1             : /*
       2             :    Unix SMB/CIFS implementation.
       3             :    Test suite for libnet calls.
       4             : 
       5             :    Copyright (C) Rafal Szczesniak 2005
       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 "lib/cmdline/cmdline.h"
      23             : #include "libnet/libnet.h"
      24             : #include "libcli/libcli.h"
      25             : #include "torture/rpc/torture_rpc.h"
      26             : #include "torture/libnet/proto.h"
      27             : #include "param/param.h"
      28             : 
      29             : 
      30           1 : bool torture_lookup(struct torture_context *torture)
      31             : {
      32             :         bool ret;
      33             :         NTSTATUS status;
      34             :         TALLOC_CTX *mem_ctx;
      35             :         struct libnet_context *ctx;
      36             :         struct libnet_Lookup lookup;
      37             :         struct dcerpc_binding *binding;
      38             : 
      39           1 :         mem_ctx = talloc_init("test_lookup");
      40             : 
      41           1 :         ctx = libnet_context_init(torture->ev, torture->lp_ctx);
      42           1 :         ctx->cred = samba_cmdline_get_creds();
      43             : 
      44           1 :         lookup.in.hostname = torture_setting_string(torture, "host", NULL);
      45           1 :         if (lookup.in.hostname == NULL) {
      46           0 :                 status = torture_rpc_binding(torture, &binding);
      47           0 :                 if (NT_STATUS_IS_OK(status)) {
      48           0 :                         lookup.in.hostname = dcerpc_binding_get_string_option(binding, "host");
      49             :                 }
      50             :         }
      51             : 
      52           1 :         lookup.in.type     = NBT_NAME_CLIENT;
      53           1 :         lookup.in.resolve_ctx = NULL;
      54           1 :         lookup.out.address = NULL;
      55             : 
      56           1 :         status = libnet_Lookup(ctx, mem_ctx, &lookup);
      57             : 
      58           1 :         if (!NT_STATUS_IS_OK(status)) {
      59           0 :                 torture_comment(torture, "Couldn't lookup name %s: %s\n", lookup.in.hostname, nt_errstr(status));
      60           0 :                 ret = false;
      61           0 :                 goto done;
      62             :         }
      63             : 
      64           1 :         ret = true;
      65             : 
      66           1 :         torture_comment(torture, "Name [%s] found at address: %s.\n", lookup.in.hostname, *lookup.out.address);
      67             : 
      68           1 : done:
      69           1 :         talloc_free(mem_ctx);
      70           1 :         return ret;
      71             : }
      72             : 
      73             : 
      74           1 : bool torture_lookup_host(struct torture_context *torture)
      75             : {
      76             :         bool ret;
      77             :         NTSTATUS status;
      78             :         TALLOC_CTX *mem_ctx;
      79             :         struct libnet_context *ctx;
      80             :         struct libnet_Lookup lookup;
      81             :         struct dcerpc_binding *binding;
      82             : 
      83           1 :         mem_ctx = talloc_init("test_lookup_host");
      84             : 
      85           1 :         ctx = libnet_context_init(torture->ev, torture->lp_ctx);
      86           1 :         ctx->cred = samba_cmdline_get_creds();
      87             : 
      88           1 :         lookup.in.hostname = torture_setting_string(torture, "host", NULL);
      89           1 :         if (lookup.in.hostname == NULL) {
      90           0 :                 status = torture_rpc_binding(torture, &binding);
      91           0 :                 if (NT_STATUS_IS_OK(status)) {
      92           0 :                         lookup.in.hostname = dcerpc_binding_get_string_option(binding, "host");
      93             :                 }
      94             :         }
      95             : 
      96           1 :         lookup.in.resolve_ctx = NULL;
      97           1 :         lookup.out.address = NULL;
      98             : 
      99           1 :         status = libnet_LookupHost(ctx, mem_ctx, &lookup);
     100             : 
     101           1 :         if (!NT_STATUS_IS_OK(status)) {
     102           0 :                 torture_comment(torture, "Couldn't lookup host %s: %s\n", lookup.in.hostname, nt_errstr(status));
     103           0 :                 ret = false;
     104           0 :                 goto done;
     105             :         }
     106             : 
     107           1 :         ret = true;
     108             : 
     109           1 :         torture_comment(torture, "Host [%s] found at address: %s.\n", lookup.in.hostname, *lookup.out.address);
     110             : 
     111           1 : done:
     112           1 :         talloc_free(mem_ctx);
     113           1 :         return ret;
     114             : }
     115             : 
     116             : 
     117           1 : bool torture_lookup_pdc(struct torture_context *torture)
     118             : {
     119             :         bool ret;
     120             :         NTSTATUS status;
     121             :         TALLOC_CTX *mem_ctx;
     122             :         struct libnet_context *ctx;
     123             :         struct libnet_LookupDCs *lookup;
     124             :         int i;
     125             : 
     126           1 :         mem_ctx = talloc_init("test_lookup_pdc");
     127             : 
     128           1 :         ctx = libnet_context_init(torture->ev, torture->lp_ctx);
     129           1 :         ctx->cred = samba_cmdline_get_creds();
     130             : 
     131           1 :         talloc_steal(ctx, mem_ctx);
     132             : 
     133           1 :         lookup = talloc(mem_ctx, struct libnet_LookupDCs);
     134           1 :         if (!lookup) {
     135           0 :                 ret = false;
     136           0 :                 goto done;
     137             :         }
     138             : 
     139           1 :         lookup->in.domain_name = lpcfg_workgroup(torture->lp_ctx);
     140           1 :         lookup->in.name_type   = NBT_NAME_PDC;
     141             : 
     142           1 :         status = libnet_LookupDCs(ctx, mem_ctx, lookup);
     143             : 
     144           1 :         if (!NT_STATUS_IS_OK(status)) {
     145           0 :                 torture_comment(torture, "Couldn't lookup pdc %s: %s\n", lookup->in.domain_name,
     146             :                        nt_errstr(status));
     147           0 :                 ret = false;
     148           0 :                 goto done;
     149             :         }
     150             : 
     151           1 :         ret = true;
     152             : 
     153           1 :         torture_comment(torture, "DCs of domain [%s] found.\n", lookup->in.domain_name);
     154           2 :         for (i = 0; i < lookup->out.num_dcs; i++) {
     155           1 :                 torture_comment(torture, "\tDC[%d]: name=%s, address=%s\n", i, lookup->out.dcs[i].name,
     156           1 :                        lookup->out.dcs[i].address);
     157             :         }
     158             : 
     159           1 : done:
     160           1 :         talloc_free(mem_ctx);
     161           1 :         return ret;
     162             : }
     163             : 
     164             : 
     165           1 : bool torture_lookup_sam_name(struct torture_context *torture)
     166             : {
     167             :         NTSTATUS status;
     168             :         TALLOC_CTX *mem_ctx;
     169             :         struct libnet_context *ctx;
     170             :         struct libnet_LookupName r;
     171           1 :         bool ret = true;
     172             : 
     173           1 :         ctx = libnet_context_init(torture->ev, torture->lp_ctx);
     174           1 :         ctx->cred = samba_cmdline_get_creds();
     175             : 
     176           1 :         mem_ctx = talloc_init("torture lookup sam name");
     177           1 :         if (mem_ctx == NULL) return false;
     178             : 
     179           1 :         r.in.name = "Administrator";
     180           1 :         r.in.domain_name = lpcfg_workgroup(torture->lp_ctx);
     181             : 
     182           1 :         status = libnet_LookupName(ctx, mem_ctx, &r);
     183           1 :         torture_assert_ntstatus_ok_goto(torture, status, ret, done,
     184             :                                         "libnet_LookupName: failed");
     185             : 
     186           1 : done:
     187           1 :         talloc_free(mem_ctx);
     188           1 :         talloc_free(ctx);
     189             : 
     190           1 :         return ret;
     191             : }

Generated by: LCOV version 1.13