2 Unix SMB/CIFS implementation.
3 Test suite for libnet calls.
5 Copyright (C) Rafal Szczesniak 2006
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 2 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, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 #include "lib/cmdline/popt_common.h"
25 #include "lib/events/events.h"
26 #include "auth/credentials/credentials.h"
27 #include "libnet/libnet.h"
28 #include "librpc/gen_ndr/ndr_samr_c.h"
29 #include "librpc/gen_ndr/ndr_lsa_c.h"
30 #include "libcli/security/security.h"
31 #include "librpc/rpc/dcerpc.h"
32 #include "torture/torture.h"
33 #include "torture/rpc/rpc.h"
36 static BOOL
test_opendomain_samr(struct dcerpc_pipe
*p
, TALLOC_CTX
*mem_ctx
,
37 struct policy_handle
*handle
, struct lsa_String
*domname
,
38 uint32_t *access_mask
)
41 struct policy_handle h
, domain_handle
;
42 struct samr_Connect r1
;
43 struct samr_LookupDomain r2
;
44 struct samr_OpenDomain r3
;
46 printf("connecting\n");
48 *access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
50 r1
.in
.system_name
= 0;
51 r1
.in
.access_mask
= *access_mask
;
52 r1
.out
.connect_handle
= &h
;
54 status
= dcerpc_samr_Connect(p
, mem_ctx
, &r1
);
55 if (!NT_STATUS_IS_OK(status
)) {
56 printf("Connect failed - %s\n", nt_errstr(status
));
60 r2
.in
.connect_handle
= &h
;
61 r2
.in
.domain_name
= domname
;
63 printf("domain lookup on %s\n", domname
->string
);
65 status
= dcerpc_samr_LookupDomain(p
, mem_ctx
, &r2
);
66 if (!NT_STATUS_IS_OK(status
)) {
67 printf("LookupDomain failed - %s\n", nt_errstr(status
));
71 r3
.in
.connect_handle
= &h
;
72 r3
.in
.access_mask
= *access_mask
;
73 r3
.in
.sid
= r2
.out
.sid
;
74 r3
.out
.domain_handle
= &domain_handle
;
76 printf("opening domain\n");
78 status
= dcerpc_samr_OpenDomain(p
, mem_ctx
, &r3
);
79 if (!NT_STATUS_IS_OK(status
)) {
80 printf("OpenDomain failed - %s\n", nt_errstr(status
));
83 *handle
= domain_handle
;
90 static BOOL
test_opendomain_lsa(struct dcerpc_pipe
*p
, TALLOC_CTX
*mem_ctx
,
91 struct policy_handle
*handle
, struct lsa_String
*domname
,
92 uint32_t *access_mask
)
95 struct lsa_OpenPolicy2 open
;
96 struct lsa_ObjectAttribute attr
;
97 struct lsa_QosInfo qos
;
99 *access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
105 qos
.impersonation_level
= 2;
106 qos
.context_mode
= 1;
107 qos
.effective_only
= 0;
111 open
.in
.system_name
= domname
->string
;
112 open
.in
.attr
= &attr
;
113 open
.in
.access_mask
= *access_mask
;
114 open
.out
.handle
= handle
;
116 status
= dcerpc_lsa_OpenPolicy2(p
, mem_ctx
, &open
);
117 if (!NT_STATUS_IS_OK(status
)) {
125 BOOL
torture_domain_open_lsa(struct torture_context
*torture
)
129 struct libnet_context
*ctx
;
130 struct libnet_DomainOpen r
;
131 struct lsa_Close close
;
132 struct dcerpc_binding
*binding
;
133 struct policy_handle h
;
136 bindstr
= lp_parm_string(-1, "torture", "binding");
137 status
= dcerpc_parse_binding(torture
, bindstr
, &binding
);
138 if (!NT_STATUS_IS_OK(status
)) {
139 d_printf("failed to parse binding string\n");
143 ctx
= libnet_context_init(NULL
);
145 d_printf("failed to create libnet context\n");
149 ctx
->cred
= cmdline_credentials
;
152 r
.in
.type
= DOMAIN_LSA
;
153 r
.in
.domain_name
= binding
->host
;
154 r
.in
.access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
156 status
= libnet_DomainOpen(ctx
, torture
, &r
);
157 if (!NT_STATUS_IS_OK(status
)) {
158 d_printf("failed to open domain on lsa service: %s\n", nt_errstr(status
));
164 close
.in
.handle
= &ctx
->lsa
.handle
;
165 close
.out
.handle
= &h
;
167 status
= dcerpc_lsa_Close(ctx
->lsa
.pipe
, ctx
, &close
);
168 if (!NT_STATUS_IS_OK(status
)) {
169 d_printf("failed to close domain on lsa service: %s\n", nt_errstr(status
));
179 BOOL
torture_domain_close_lsa(struct torture_context
*torture
)
183 TALLOC_CTX
*mem_ctx
=NULL
;
184 struct libnet_context
*ctx
;
185 struct lsa_String domain_name
;
186 struct dcerpc_binding
*binding
;
188 uint32_t access_mask
;
189 struct policy_handle h
;
190 struct dcerpc_pipe
*p
;
191 struct libnet_DomainClose r
;
193 bindstr
= lp_parm_string(-1, "torture", "binding");
194 status
= dcerpc_parse_binding(torture
, bindstr
, &binding
);
195 if (!NT_STATUS_IS_OK(status
)) {
196 d_printf("failed to parse binding string\n");
200 ctx
= libnet_context_init(NULL
);
202 d_printf("failed to create libnet context\n");
207 ctx
->cred
= cmdline_credentials
;
209 mem_ctx
= talloc_init("torture_domain_close_lsa");
210 status
= dcerpc_pipe_connect(mem_ctx
, &p
, bindstr
, &dcerpc_table_lsarpc
,
211 cmdline_credentials
, NULL
);
212 if (!NT_STATUS_IS_OK(status
)) {
213 d_printf("failed to connect to server %s: %s\n", bindstr
,
219 domain_name
.string
= lp_workgroup();
221 if (!test_opendomain_lsa(p
, torture
, &h
, &domain_name
, &access_mask
)) {
222 d_printf("failed to open domain on lsa service\n");
228 ctx
->lsa
.name
= domain_name
.string
;
229 ctx
->lsa
.access_mask
= access_mask
;
231 /* we have to use pipe's event context, otherwise the call will
233 ctx
->event_ctx
= p
->conn
->event_ctx
;
236 r
.in
.type
= DOMAIN_LSA
;
237 r
.in
.domain_name
= domain_name
.string
;
239 status
= libnet_DomainClose(ctx
, mem_ctx
, &r
);
240 if (!NT_STATUS_IS_OK(status
)) {
246 talloc_free(mem_ctx
);
252 BOOL
torture_domain_open_samr(struct torture_context
*torture
)
256 struct libnet_context
*ctx
;
257 struct event_context
*evt_ctx
=NULL
;
259 struct policy_handle domain_handle
, handle
;
260 struct lsa_String name
;
261 struct libnet_DomainOpen io
;
265 mem_ctx
= talloc_init("test_domainopen_lsa");
266 binding
= lp_parm_string(-1, "torture", "binding");
268 ctx
= libnet_context_init(evt_ctx
);
269 ctx
->cred
= cmdline_credentials
;
271 name
.string
= lp_workgroup();
274 * Testing synchronous version
276 printf("opening domain\n");
278 io
.in
.type
= DOMAIN_SAMR
;
279 io
.in
.domain_name
= name
.string
;
280 io
.in
.access_mask
= SEC_FLAG_MAXIMUM_ALLOWED
;
282 status
= libnet_DomainOpen(ctx
, mem_ctx
, &io
);
283 if (!NT_STATUS_IS_OK(status
)) {
284 printf("Composite domain open failed - %s\n", nt_errstr(status
));
289 domain_handle
= ctx
->samr
.handle
;
291 r
.in
.handle
= &domain_handle
;
292 r
.out
.handle
= &handle
;
294 printf("closing domain handle\n");
296 status
= dcerpc_samr_Close(ctx
->samr
.pipe
, mem_ctx
, &r
);
297 if (!NT_STATUS_IS_OK(status
)) {
298 printf("Close failed - %s\n", nt_errstr(status
));
304 talloc_free(mem_ctx
);
311 BOOL
torture_domain_close_samr(struct torture_context
*torture
)
315 TALLOC_CTX
*mem_ctx
=NULL
;
316 struct libnet_context
*ctx
;
317 struct lsa_String domain_name
;
318 struct dcerpc_binding
*binding
;
320 uint32_t access_mask
;
321 struct policy_handle h
;
322 struct dcerpc_pipe
*p
;
323 struct libnet_DomainClose r
;
325 bindstr
= lp_parm_string(-1, "torture", "binding");
326 status
= dcerpc_parse_binding(torture
, bindstr
, &binding
);
327 if (!NT_STATUS_IS_OK(status
)) {
328 d_printf("failed to parse binding string\n");
332 ctx
= libnet_context_init(NULL
);
334 d_printf("failed to create libnet context\n");
339 ctx
->cred
= cmdline_credentials
;
341 mem_ctx
= talloc_init("torture_domain_close_samr");
342 status
= dcerpc_pipe_connect(mem_ctx
, &p
, bindstr
, &dcerpc_table_samr
,
343 cmdline_credentials
, NULL
);
344 if (!NT_STATUS_IS_OK(status
)) {
345 d_printf("failed to connect to server %s: %s\n", bindstr
,
351 domain_name
.string
= lp_workgroup();
353 if (!test_opendomain_samr(p
, torture
, &h
, &domain_name
, &access_mask
)) {
354 d_printf("failed to open domain on samr service\n");
360 ctx
->samr
.name
= domain_name
.string
;
361 ctx
->samr
.access_mask
= access_mask
;
362 ctx
->samr
.handle
= h
;
363 /* we have to use pipe's event context, otherwise the call will
365 ctx
->event_ctx
= p
->conn
->event_ctx
;
368 r
.in
.type
= DOMAIN_SAMR
;
369 r
.in
.domain_name
= domain_name
.string
;
371 status
= libnet_DomainClose(ctx
, mem_ctx
, &r
);
372 if (!NT_STATUS_IS_OK(status
)) {
378 talloc_free(mem_ctx
);