2 Unix SMB/CIFS implementation.
3 Test suite for libnet calls.
5 Copyright (C) Rafal Szczesniak 2007
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.
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.
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/>.
23 #include "lib/cmdline/popt_common.h"
24 #include "libnet/libnet.h"
25 #include "librpc/gen_ndr/ndr_samr_c.h"
26 #include "librpc/gen_ndr/ndr_lsa_c.h"
27 #include "torture/rpc/torture_rpc.h"
28 #include "torture/libnet/proto.h"
29 #include "param/param.h"
32 #define TEST_GROUPNAME "libnetgrouptest"
35 bool torture_groupinfo_api(struct torture_context
*torture
)
37 const char *name
= TEST_GROUPNAME
;
40 TALLOC_CTX
*mem_ctx
= NULL
, *prep_mem_ctx
;
41 struct libnet_context
*ctx
= NULL
;
42 struct dcerpc_pipe
*p
;
43 struct policy_handle h
;
44 struct lsa_String domain_name
;
45 struct libnet_GroupInfo req
;
47 prep_mem_ctx
= talloc_init("prepare torture group info");
49 status
= torture_rpc_connection(torture
,
52 if (!NT_STATUS_IS_OK(status
)) {
56 domain_name
.string
= lpcfg_workgroup(torture
->lp_ctx
);
57 if (!test_domain_open(torture
, p
->binding_handle
, &domain_name
, prep_mem_ctx
, &h
, NULL
)) {
62 if (!test_group_create(torture
, p
->binding_handle
, prep_mem_ctx
, &h
, name
, NULL
)) {
67 mem_ctx
= talloc_init("torture group info");
69 if (!test_libnet_context_init(torture
, true, &ctx
)) {
75 req
.in
.domain_name
= domain_name
.string
;
76 req
.in
.level
= GROUP_INFO_BY_NAME
;
77 req
.in
.data
.group_name
= name
;
79 status
= libnet_GroupInfo(ctx
, mem_ctx
, &req
);
80 if (!NT_STATUS_IS_OK(status
)) {
81 torture_comment(torture
, "libnet_GroupInfo call failed: %s\n", nt_errstr(status
));
86 if (!test_group_cleanup(torture
, ctx
->samr
.pipe
->binding_handle
,
87 mem_ctx
, &ctx
->samr
.handle
, TEST_GROUPNAME
)) {
88 torture_comment(torture
, "cleanup failed\n");
93 if (!test_samr_close_handle(torture
,
94 ctx
->samr
.pipe
->binding_handle
, mem_ctx
, &ctx
->samr
.handle
)) {
95 torture_comment(torture
, "domain close failed\n");
101 talloc_free(mem_ctx
);
106 bool torture_grouplist(struct torture_context
*torture
)
110 TALLOC_CTX
*mem_ctx
= NULL
;
111 struct libnet_context
*ctx
;
112 struct lsa_String domain_name
;
113 struct libnet_GroupList req
;
116 ctx
= libnet_context_init(torture
->ev
, torture
->lp_ctx
);
117 ctx
->cred
= cmdline_credentials
;
119 domain_name
.string
= lpcfg_workgroup(torture
->lp_ctx
);
120 mem_ctx
= talloc_init("torture group list");
124 torture_comment(torture
, "listing group accounts:\n");
127 req
.in
.domain_name
= domain_name
.string
;
128 req
.in
.page_size
= 128;
129 req
.in
.resume_index
= req
.out
.resume_index
;
131 status
= libnet_GroupList(ctx
, mem_ctx
, &req
);
132 if (!NT_STATUS_IS_OK(status
) &&
133 !NT_STATUS_EQUAL(status
, STATUS_MORE_ENTRIES
)) break;
135 for (i
= 0; i
< req
.out
.count
; i
++) {
136 torture_comment(torture
, "\tgroup: %s, sid=%s\n",
137 req
.out
.groups
[i
].groupname
, req
.out
.groups
[i
].sid
);
140 } while (NT_STATUS_EQUAL(status
, STATUS_MORE_ENTRIES
));
142 if (!(NT_STATUS_IS_OK(status
) ||
143 NT_STATUS_EQUAL(status
, NT_STATUS_NO_MORE_ENTRIES
))) {
144 torture_comment(torture
, "libnet_GroupList call failed: %s\n", nt_errstr(status
));
149 if (!test_samr_close_handle(torture
,
150 ctx
->samr
.pipe
->binding_handle
, mem_ctx
, &ctx
->samr
.handle
)) {
151 torture_comment(torture
, "domain close failed\n");
155 if (!test_lsa_close_handle(torture
,
156 ctx
->lsa
.pipe
->binding_handle
, mem_ctx
, &ctx
->lsa
.handle
)) {
157 torture_comment(torture
, "lsa domain close failed\n");
164 talloc_free(mem_ctx
);
169 bool torture_creategroup(struct torture_context
*torture
)
173 TALLOC_CTX
*mem_ctx
= NULL
;
174 struct libnet_context
*ctx
;
175 struct libnet_CreateGroup req
;
177 mem_ctx
= talloc_init("test_creategroup");
179 ctx
= libnet_context_init(torture
->ev
, torture
->lp_ctx
);
180 ctx
->cred
= cmdline_credentials
;
182 req
.in
.group_name
= TEST_GROUPNAME
;
183 req
.in
.domain_name
= lpcfg_workgroup(torture
->lp_ctx
);
184 req
.out
.error_string
= NULL
;
186 status
= libnet_CreateGroup(ctx
, mem_ctx
, &req
);
187 if (!NT_STATUS_IS_OK(status
)) {
188 torture_comment(torture
, "libnet_CreateGroup call failed: %s\n", nt_errstr(status
));
193 if (!test_group_cleanup(torture
, ctx
->samr
.pipe
->binding_handle
,
194 mem_ctx
, &ctx
->samr
.handle
, TEST_GROUPNAME
)) {
195 torture_comment(torture
, "cleanup failed\n");
200 if (!test_samr_close_handle(torture
,
201 ctx
->samr
.pipe
->binding_handle
, mem_ctx
, &ctx
->samr
.handle
)) {
202 torture_comment(torture
, "domain close failed\n");
208 talloc_free(mem_ctx
);