r19339: Merge my 4.0-unittest branch. This adds an API for more fine-grained
[Samba.git] / source / torture / libnet / domain.c
blob991fe8e51aba1ba0ca5bcc8437870b46070c4471
1 /*
2 Unix SMB/CIFS implementation.
3 Test suite for libnet calls.
5 Copyright (C) Rafal Szczesniak 2005
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.
22 #include "includes.h"
23 #include "torture/rpc/rpc.h"
24 #include "lib/events/events.h"
25 #include "libnet/libnet.h"
26 #include "librpc/gen_ndr/ndr_samr_c.h"
28 static BOOL test_domainopen(struct libnet_context *net_ctx, TALLOC_CTX *mem_ctx,
29 struct lsa_String *domname,
30 struct policy_handle *domain_handle)
32 NTSTATUS status;
33 struct libnet_DomainOpen io;
35 printf("opening domain\n");
37 io.in.domain_name = talloc_strdup(mem_ctx, domname->string);
38 io.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
40 status = libnet_DomainOpen(net_ctx, mem_ctx, &io);
41 if (!NT_STATUS_IS_OK(status)) {
42 printf("Composite domain open failed - %s\n", nt_errstr(status));
43 return False;
46 *domain_handle = io.out.domain_handle;
47 return True;
51 static BOOL test_cleanup(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
52 struct policy_handle *domain_handle)
54 NTSTATUS status;
55 struct samr_Close r;
56 struct policy_handle handle;
58 r.in.handle = domain_handle;
59 r.out.handle = &handle;
61 printf("closing domain handle\n");
63 status = dcerpc_samr_Close(p, mem_ctx, &r);
64 if (!NT_STATUS_IS_OK(status)) {
65 printf("Close failed - %s\n", nt_errstr(status));
66 return False;
69 return True;
73 BOOL torture_domainopen(struct torture_context *torture)
75 NTSTATUS status;
76 const char *binding;
77 struct libnet_context *net_ctx;
78 struct event_context *evt_ctx;
79 TALLOC_CTX *mem_ctx;
80 BOOL ret = True;
81 struct policy_handle h;
82 struct lsa_String name;
84 mem_ctx = talloc_init("test_domain_open");
85 binding = lp_parm_string(-1, "torture", "binding");
87 evt_ctx = event_context_find(torture);
88 net_ctx = libnet_context_init(evt_ctx);
90 status = torture_rpc_connection(mem_ctx,
91 &net_ctx->samr.pipe,
92 &dcerpc_table_samr);
94 if (!NT_STATUS_IS_OK(status)) {
95 return False;
98 name.string = lp_workgroup();
101 * Testing synchronous version
103 if (!test_domainopen(net_ctx, mem_ctx, &name, &h)) {
104 ret = False;
105 goto done;
108 if (!test_cleanup(net_ctx->samr.pipe, mem_ctx, &h)) {
109 ret = False;
110 goto done;
113 done:
114 talloc_free(mem_ctx);
116 return ret;