LCOV - code coverage report
Current view: top level - source4/torture/libnetapi - libnetapi.c (source / functions) Hit Total Coverage
Test: coverage report for v4-17-test 1498b464 Lines: 27 32 84.4 %
Date: 2024-06-13 04:01:37 Functions: 3 3 100.0 %

          Line data    Source code
       1             : /*
       2             :    Unix SMB/CIFS implementation.
       3             :    SMB torture tester
       4             :    Copyright (C) Guenther Deschner 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 "source3/include/includes.h"
      21             : #include "torture/smbtorture.h"
      22             : #include "auth/credentials/credentials.h"
      23             : #include "lib/cmdline/cmdline.h"
      24             : #include "source3/lib/netapi/netapi.h"
      25             : #include "source3/lib/netapi/netapi_private.h"
      26             : #include "lib/param/param.h"
      27             : #include "torture/libnetapi/proto.h"
      28             : 
      29           4 : bool torture_libnetapi_init_context(struct torture_context *tctx,
      30             :                                     struct libnetapi_ctx **ctx_p)
      31             : {
      32             :         NET_API_STATUS status;
      33             :         struct libnetapi_ctx *ctx;
      34           4 :         TALLOC_CTX *frame = talloc_stackframe();
      35             : 
      36           4 :         if (!lp_load_global(lpcfg_configfile(tctx->lp_ctx))) {
      37           0 :                 fprintf(stderr, "error loading %s\n", lpcfg_configfile(tctx->lp_ctx));
      38           0 :                 talloc_free(frame);
      39           0 :                 return W_ERROR_V(WERR_GEN_FAILURE);
      40             :         }
      41             : 
      42           4 :         load_interfaces();
      43             : 
      44           4 :         status = libnetapi_net_init(&ctx);
      45           4 :         if (status != 0) {
      46           0 :                 talloc_free(frame);
      47           0 :                 return false;
      48             :         }
      49             : 
      50           4 :         libnetapi_set_username(ctx,
      51             :                 cli_credentials_get_username(samba_cmdline_get_creds()));
      52           4 :         libnetapi_set_password(ctx,
      53             :                 cli_credentials_get_password(samba_cmdline_get_creds()));
      54             : 
      55           4 :         *ctx_p = ctx;
      56             : 
      57           4 :         talloc_free(frame);
      58           4 :         return true;
      59             : }
      60             : 
      61           1 : static bool torture_libnetapi_initialize(struct torture_context *tctx)
      62             : {
      63             :         NET_API_STATUS status;
      64             :         struct libnetapi_ctx *ctx;
      65             : 
      66             :         /* We must do this first, as otherwise we fail if we don't
      67             :          * have an smb.conf in the default path (we need to use the
      68             :          * torture smb.conf */
      69           1 :         torture_assert(tctx, torture_libnetapi_init_context(tctx, &ctx),
      70             :                        "failed to initialize libnetapi");
      71             : 
      72           1 :         status = libnetapi_init(&ctx);
      73             : 
      74           1 :         torture_assert(tctx, ctx != NULL, "Failed to get a libnetapi_ctx");
      75           1 :         torture_assert_int_equal(tctx, status, 0, "libnetapi_init failed despite alredy being set up");
      76             : 
      77           1 :         libnetapi_free(ctx);
      78             : 
      79           1 :         return true;
      80             : }
      81             : 
      82         964 : NTSTATUS torture_libnetapi_init(TALLOC_CTX *ctx)
      83             : {
      84             :         struct torture_suite *suite;
      85             : 
      86         964 :         suite = torture_suite_create(ctx, "netapi");
      87             : 
      88         964 :         torture_suite_add_simple_test(suite, "server", torture_libnetapi_server);
      89         964 :         torture_suite_add_simple_test(suite, "group", torture_libnetapi_group);
      90         964 :         torture_suite_add_simple_test(suite, "user", torture_libnetapi_user);
      91         964 :         torture_suite_add_simple_test(suite, "initialize", torture_libnetapi_initialize);
      92             : 
      93         964 :         suite->description = talloc_strdup(suite, "libnetapi convenience interface tests");
      94             : 
      95         964 :         torture_register_suite(ctx, suite);
      96             : 
      97         964 :         return NT_STATUS_OK;
      98             : }

Generated by: LCOV version 1.13