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/popt_common.h"
23 #include "libnet/libnet.h"
24 #include "librpc/gen_ndr/nbt.h"
25 #include "librpc/rpc/dcerpc.h"
26 #include "libcli/libcli.h"
27 #include "torture/torture.h"
30 BOOL torture_lookup(struct torture_context *torture)
35 struct libnet_context *ctx;
36 struct libnet_Lookup lookup;
37 struct dcerpc_binding *bind;
40 mem_ctx = talloc_init("test_lookup");
42 ctx = libnet_context_init(NULL);
43 ctx->cred = cmdline_credentials;
45 lookup.in.hostname = torture_setting_string(torture, "host", NULL);
46 if (lookup.in.hostname == NULL) {
47 bindstr = torture_setting_string(torture, "binding", NULL);
48 status = dcerpc_parse_binding(mem_ctx, bindstr, &bind);
49 if (NT_STATUS_IS_OK(status)) {
50 lookup.in.hostname = bind->host;
54 lookup.in.type = NBT_NAME_CLIENT;
55 lookup.in.methods = NULL;
56 lookup.out.address = NULL;
58 status = libnet_Lookup(ctx, mem_ctx, &lookup);
60 if (!NT_STATUS_IS_OK(status)) {
61 printf("Couldn't lookup name %s: %s\n", lookup.in.hostname, nt_errstr(status));
68 printf("Name [%s] found at adrress: %s.\n", lookup.in.hostname, *lookup.out.address);
76 BOOL torture_lookup_host(struct torture_context *torture)
81 struct libnet_context *ctx;
82 struct libnet_Lookup lookup;
83 struct dcerpc_binding *bind;
86 mem_ctx = talloc_init("test_lookup_host");
88 ctx = libnet_context_init(NULL);
89 ctx->cred = cmdline_credentials;
91 lookup.in.hostname = torture_setting_string(torture, "host", NULL);
92 if (lookup.in.hostname == NULL) {
93 bindstr = torture_setting_string(torture, "binding", NULL);
94 status = dcerpc_parse_binding(mem_ctx, bindstr, &bind);
95 if (NT_STATUS_IS_OK(status)) {
96 lookup.in.hostname = bind->host;
100 lookup.in.methods = NULL;
101 lookup.out.address = NULL;
103 status = libnet_LookupHost(ctx, mem_ctx, &lookup);
105 if (!NT_STATUS_IS_OK(status)) {
106 printf("Couldn't lookup host %s: %s\n", lookup.in.hostname, nt_errstr(status));
113 printf("Host [%s] found at adrress: %s.\n", lookup.in.hostname, *lookup.out.address);
116 talloc_free(mem_ctx);
121 BOOL torture_lookup_pdc(struct torture_context *torture)
126 struct libnet_context *ctx;
127 struct libnet_LookupDCs *lookup;
130 mem_ctx = talloc_init("test_lookup_pdc");
132 ctx = libnet_context_init(NULL);
133 ctx->cred = cmdline_credentials;
135 talloc_steal(ctx, mem_ctx);
137 lookup = talloc(mem_ctx, struct libnet_LookupDCs);
143 lookup->in.domain_name = lp_workgroup();
144 lookup->in.name_type = NBT_NAME_PDC;
146 status = libnet_LookupDCs(ctx, mem_ctx, lookup);
148 if (!NT_STATUS_IS_OK(status)) {
149 printf("Couldn't lookup pdc %s: %s\n", lookup->in.domain_name,
157 printf("DCs of domain [%s] found.\n", lookup->in.domain_name);
158 for (i = 0; i < lookup->out.num_dcs; i++) {
159 printf("\tDC[%d]: name=%s, address=%s\n", i, lookup->out.dcs[i].name,
160 lookup->out.dcs[i].address);
164 talloc_free(mem_ctx);
169 BOOL torture_lookup_sam_name(struct torture_context *torture)
173 struct libnet_context *ctx;
174 struct libnet_LookupName r;
176 ctx = libnet_context_init(NULL);
177 ctx->cred = cmdline_credentials;
179 mem_ctx = talloc_init("torture lookup sam name");
180 if (mem_ctx == NULL) return False;
182 r.in.name = "Administrator";
183 r.in.domain_name = lp_workgroup();
185 status = libnet_LookupName(ctx, mem_ctx, &r);
187 talloc_free(mem_ctx);