Merge branch 'master' of ssh://git.samba.org/data/git/samba
[gd/samba-autobuild/.git] / source4 / torture / libnetapi / libnetapi.c
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 "includes.h"
21 #include "torture/smbtorture.h"
22 #include "auth/credentials/credentials.h"
23 #include "lib/cmdline/popt_common.h"
24 #include <netapi.h>
25 #include "torture/libnetapi/proto.h"
26
27 bool torture_libnetapi_init_context(struct torture_context *tctx,
28                                     struct libnetapi_ctx **ctx_p)
29 {
30         NET_API_STATUS status;
31         struct libnetapi_ctx *ctx;
32
33         status = libnetapi_init(&ctx);
34         if (status != 0) {
35                 return false;
36         }
37
38         libnetapi_set_debuglevel(ctx,
39                 talloc_asprintf(ctx, "%d", DEBUGLEVEL));
40         libnetapi_set_username(ctx,
41                 cli_credentials_get_username(cmdline_credentials));
42         libnetapi_set_password(ctx,
43                 cli_credentials_get_password(cmdline_credentials));
44
45         *ctx_p = ctx;
46
47         return true;
48 }
49
50 static bool torture_libnetapi_initialize(struct torture_context *tctx)
51 {
52         NET_API_STATUS status;
53         struct libnetapi_ctx *ctx;
54
55         status = libnetapi_init(&ctx);
56         if (status != 0) {
57                 return false;
58         }
59
60         libnetapi_free(ctx);
61
62         return true;
63 }
64
65 NTSTATUS torture_libnetapi_init(void)
66 {
67         struct torture_suite *suite;
68
69         suite = torture_suite_create(talloc_autofree_context(), "NETAPI");
70
71         torture_suite_add_simple_test(suite, "GROUP", torture_libnetapi_group);
72         torture_suite_add_simple_test(suite, "USER", torture_libnetapi_user);
73         torture_suite_add_simple_test(suite, "INITIALIZE", torture_libnetapi_initialize);
74
75         suite->description = talloc_strdup(suite, "libnetapi convenience interface tests");
76
77         torture_register_suite(suite);
78
79         return NT_STATUS_OK;
80 }