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 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/>.
22 #include "lib/cmdline/cmdline.h"
23 #include "libnet/libnet.h"
24 #include "libcli/libcli.h"
25 #include "torture/rpc/torture_rpc.h"
26 #include "torture/libnet/proto.h"
27 #include "param/param.h"
30 bool torture_lookup(struct torture_context
*torture
)
35 struct libnet_context
*ctx
;
36 struct libnet_Lookup lookup
;
37 struct dcerpc_binding
*binding
;
39 mem_ctx
= talloc_init("test_lookup");
41 ctx
= libnet_context_init(torture
->ev
, torture
->lp_ctx
);
42 ctx
->cred
= samba_cmdline_get_creds();
44 lookup
.in
.hostname
= torture_setting_string(torture
, "host", NULL
);
45 if (lookup
.in
.hostname
== NULL
) {
46 status
= torture_rpc_binding(torture
, &binding
);
47 if (NT_STATUS_IS_OK(status
)) {
48 lookup
.in
.hostname
= dcerpc_binding_get_string_option(binding
, "host");
52 lookup
.in
.type
= NBT_NAME_CLIENT
;
53 lookup
.in
.resolve_ctx
= NULL
;
54 lookup
.out
.address
= NULL
;
56 status
= libnet_Lookup(ctx
, mem_ctx
, &lookup
);
58 if (!NT_STATUS_IS_OK(status
)) {
59 torture_comment(torture
, "Couldn't lookup name %s: %s\n", lookup
.in
.hostname
, nt_errstr(status
));
66 torture_comment(torture
, "Name [%s] found at address: %s.\n", lookup
.in
.hostname
, *lookup
.out
.address
);
74 bool torture_lookup_host(struct torture_context
*torture
)
79 struct libnet_context
*ctx
;
80 struct libnet_Lookup lookup
;
81 struct dcerpc_binding
*binding
;
83 mem_ctx
= talloc_init("test_lookup_host");
85 ctx
= libnet_context_init(torture
->ev
, torture
->lp_ctx
);
86 ctx
->cred
= samba_cmdline_get_creds();
88 lookup
.in
.hostname
= torture_setting_string(torture
, "host", NULL
);
89 if (lookup
.in
.hostname
== NULL
) {
90 status
= torture_rpc_binding(torture
, &binding
);
91 if (NT_STATUS_IS_OK(status
)) {
92 lookup
.in
.hostname
= dcerpc_binding_get_string_option(binding
, "host");
96 lookup
.in
.resolve_ctx
= NULL
;
97 lookup
.out
.address
= NULL
;
99 status
= libnet_LookupHost(ctx
, mem_ctx
, &lookup
);
101 if (!NT_STATUS_IS_OK(status
)) {
102 torture_comment(torture
, "Couldn't lookup host %s: %s\n", lookup
.in
.hostname
, nt_errstr(status
));
109 torture_comment(torture
, "Host [%s] found at address: %s.\n", lookup
.in
.hostname
, *lookup
.out
.address
);
112 talloc_free(mem_ctx
);
117 bool torture_lookup_pdc(struct torture_context
*torture
)
122 struct libnet_context
*ctx
;
123 struct libnet_LookupDCs
*lookup
;
126 mem_ctx
= talloc_init("test_lookup_pdc");
128 ctx
= libnet_context_init(torture
->ev
, torture
->lp_ctx
);
129 ctx
->cred
= samba_cmdline_get_creds();
131 talloc_steal(ctx
, mem_ctx
);
133 lookup
= talloc(mem_ctx
, struct libnet_LookupDCs
);
139 lookup
->in
.domain_name
= lpcfg_workgroup(torture
->lp_ctx
);
140 lookup
->in
.name_type
= NBT_NAME_PDC
;
142 status
= libnet_LookupDCs(ctx
, mem_ctx
, lookup
);
144 if (!NT_STATUS_IS_OK(status
)) {
145 torture_comment(torture
, "Couldn't lookup pdc %s: %s\n", lookup
->in
.domain_name
,
153 torture_comment(torture
, "DCs of domain [%s] found.\n", lookup
->in
.domain_name
);
154 for (i
= 0; i
< lookup
->out
.num_dcs
; i
++) {
155 torture_comment(torture
, "\tDC[%d]: name=%s, address=%s\n", i
, lookup
->out
.dcs
[i
].name
,
156 lookup
->out
.dcs
[i
].address
);
160 talloc_free(mem_ctx
);
165 bool torture_lookup_sam_name(struct torture_context
*torture
)
169 struct libnet_context
*ctx
;
170 struct libnet_LookupName r
;
173 ctx
= libnet_context_init(torture
->ev
, torture
->lp_ctx
);
174 ctx
->cred
= samba_cmdline_get_creds();
176 mem_ctx
= talloc_init("torture lookup sam name");
177 if (mem_ctx
== NULL
) return false;
179 r
.in
.name
= "Administrator";
180 r
.in
.domain_name
= lpcfg_workgroup(torture
->lp_ctx
);
182 status
= libnet_LookupName(ctx
, mem_ctx
, &r
);
183 torture_assert_ntstatus_ok_goto(torture
, status
, ret
, done
,
184 "libnet_LookupName: failed");
187 talloc_free(mem_ctx
);