torture/ioctl: add range overflow QAR test
[Samba.git] / source4 / torture / libnetapi / libnetapi.c
blob431b531beb11125490063ddd6db6e7d9ec3aa1c7
1 /*
2 Unix SMB/CIFS implementation.
3 SMB torture tester
4 Copyright (C) Guenther Deschner 2009
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.
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.
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/>.
20 #include "source3/include/includes.h"
21 #include "torture/smbtorture.h"
22 #include "auth/credentials/credentials.h"
23 #include "lib/cmdline/popt_common.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"
29 bool torture_libnetapi_init_context(struct torture_context *tctx,
30 struct libnetapi_ctx **ctx_p)
32 NET_API_STATUS status;
33 struct libnetapi_ctx *ctx;
34 TALLOC_CTX *frame = talloc_stackframe();
36 if (!lp_load(lpcfg_configfile(tctx->lp_ctx), true, false, false, true)) {
37 fprintf(stderr, "error loading %s\n", lpcfg_configfile(tctx->lp_ctx));
38 talloc_free(frame);
39 return W_ERROR_V(WERR_GENERAL_FAILURE);
42 init_names();
43 load_interfaces();
45 status = libnetapi_net_init(&ctx);
46 if (status != 0) {
47 talloc_free(frame);
48 return false;
51 libnetapi_set_username(ctx,
52 cli_credentials_get_username(cmdline_credentials));
53 libnetapi_set_password(ctx,
54 cli_credentials_get_password(cmdline_credentials));
56 *ctx_p = ctx;
58 talloc_free(frame);
59 return true;
62 static bool torture_libnetapi_initialize(struct torture_context *tctx)
64 NET_API_STATUS status;
65 struct libnetapi_ctx *ctx;
67 /* We must do this first, as otherwise we fail if we don't
68 * have an smb.conf in the default path (we need to use the
69 * torture smb.conf */
70 torture_assert(tctx, torture_libnetapi_init_context(tctx, &ctx),
71 "failed to initialize libnetapi");
73 status = libnetapi_init(&ctx);
75 torture_assert(tctx, ctx != NULL, "Failed to get a libnetapi_ctx");
76 torture_assert_int_equal(tctx, status, 0, "libnetapi_init failed despite alredy being set up");
78 libnetapi_free(ctx);
80 return true;
83 NTSTATUS torture_libnetapi_init(void)
85 struct torture_suite *suite;
87 suite = torture_suite_create(talloc_autofree_context(), "netapi");
89 torture_suite_add_simple_test(suite, "server", torture_libnetapi_server);
90 torture_suite_add_simple_test(suite, "group", torture_libnetapi_group);
91 torture_suite_add_simple_test(suite, "user", torture_libnetapi_user);
92 torture_suite_add_simple_test(suite, "initialize", torture_libnetapi_initialize);
94 suite->description = talloc_strdup(suite, "libnetapi convenience interface tests");
96 torture_register_suite(suite);
98 return NT_STATUS_OK;