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 "libcli/security/security.h"
25 #include "librpc/gen_ndr/ndr_lsa.h"
26 #include "librpc/gen_ndr/ndr_samr.h"
27 #include "librpc/gen_ndr/ndr_srvsvc.h"
28 #include "torture/rpc/rpc.h"
29 #include "param/param.h"
32 static bool test_connect_service(struct libnet_context *ctx,
33 const struct ndr_interface_table *iface,
34 const char *binding_string,
36 const enum libnet_RpcConnect_level level,
37 bool badcreds, NTSTATUS expected_status)
40 struct libnet_RpcConnect connect_r;
41 ZERO_STRUCT(connect_r);
43 connect_r.level = level;
44 connect_r.in.binding = binding_string;
45 connect_r.in.name = hostname;
46 connect_r.in.dcerpc_iface = iface;
48 /* if bad credentials are needed, set baduser%badpassword instead
49 of default commandline-passed credentials */
51 cli_credentials_set_username(ctx->cred, "baduser", CRED_SPECIFIED);
52 cli_credentials_set_password(ctx->cred, "badpassword", CRED_SPECIFIED);
55 status = libnet_RpcConnect(ctx, ctx, &connect_r);
57 if (!NT_STATUS_EQUAL(status, expected_status)) {
58 d_printf("Connecting to rpc service %s on %s.\n\tFAILED. Expected: %s."
60 connect_r.in.dcerpc_iface->name, connect_r.in.binding, nt_errstr(expected_status),
66 d_printf("PASSED. Expected: %s, received: %s\n", nt_errstr(expected_status),
69 if (connect_r.level == LIBNET_RPC_CONNECT_DC_INFO && NT_STATUS_IS_OK(status)) {
70 d_printf("Domain Controller Info:\n");
71 d_printf("\tDomain Name:\t %s\n", connect_r.out.domain_name);
72 d_printf("\tDomain SID:\t %s\n", dom_sid_string(ctx, connect_r.out.domain_sid));
73 d_printf("\tRealm:\t\t %s\n", connect_r.out.realm);
74 d_printf("\tGUID:\t\t %s\n", GUID_string(ctx, connect_r.out.guid));
76 } else if (!NT_STATUS_IS_OK(status)) {
77 d_printf("Error string: %s\n", connect_r.out.error_string);
84 static bool torture_rpc_connect(struct torture_context *torture,
85 const enum libnet_RpcConnect_level level,
86 const char *bindstr, const char *hostname)
88 struct libnet_context *ctx;
90 ctx = libnet_context_init(torture->ev, torture->lp_ctx);
91 ctx->cred = cmdline_credentials;
93 d_printf("Testing connection to LSA interface\n");
94 if (!test_connect_service(ctx, &ndr_table_lsarpc, bindstr,
95 hostname, level, false, NT_STATUS_OK)) {
96 d_printf("failed to connect LSA interface\n");
100 d_printf("Testing connection to SAMR interface\n");
101 if (!test_connect_service(ctx, &ndr_table_samr, bindstr,
102 hostname, level, false, NT_STATUS_OK)) {
103 d_printf("failed to connect SAMR interface\n");
107 d_printf("Testing connection to SRVSVC interface\n");
108 if (!test_connect_service(ctx, &ndr_table_srvsvc, bindstr,
109 hostname, level, false, NT_STATUS_OK)) {
110 d_printf("failed to connect SRVSVC interface\n");
114 d_printf("Testing connection to LSA interface with wrong credentials\n");
115 if (!test_connect_service(ctx, &ndr_table_lsarpc, bindstr,
116 hostname, level, true, NT_STATUS_LOGON_FAILURE)) {
117 d_printf("failed to test wrong credentials on LSA interface\n");
121 d_printf("Testing connection to SAMR interface with wrong credentials\n");
122 if (!test_connect_service(ctx, &ndr_table_samr, bindstr,
123 hostname, level, true, NT_STATUS_LOGON_FAILURE)) {
124 d_printf("failed to test wrong credentials on SAMR interface\n");
134 bool torture_rpc_connect_srv(struct torture_context *torture)
136 const enum libnet_RpcConnect_level level = LIBNET_RPC_CONNECT_SERVER;
138 struct dcerpc_binding *binding;
140 status = torture_rpc_binding(torture, &binding);
141 if (!NT_STATUS_IS_OK(status)) {
145 return torture_rpc_connect(torture, level, NULL, binding->host);
149 bool torture_rpc_connect_pdc(struct torture_context *torture)
151 const enum libnet_RpcConnect_level level = LIBNET_RPC_CONNECT_PDC;
153 struct dcerpc_binding *binding;
154 const char *domain_name;
156 status = torture_rpc_binding(torture, &binding);
157 if (!NT_STATUS_IS_OK(status)) {
161 /* we're accessing domain controller so the domain name should be
162 passed (it's going to be resolved to dc name and address) instead
163 of specific server name. */
164 domain_name = lp_workgroup(torture->lp_ctx);
165 return torture_rpc_connect(torture, level, NULL, domain_name);
169 bool torture_rpc_connect_dc(struct torture_context *torture)
171 const enum libnet_RpcConnect_level level = LIBNET_RPC_CONNECT_DC;
173 struct dcerpc_binding *binding;
174 const char *domain_name;
176 status = torture_rpc_binding(torture, &binding);
177 if (!NT_STATUS_IS_OK(status)) {
181 /* we're accessing domain controller so the domain name should be
182 passed (it's going to be resolved to dc name and address) instead
183 of specific server name. */
184 domain_name = lp_workgroup(torture->lp_ctx);
185 return torture_rpc_connect(torture, level, NULL, domain_name);
189 bool torture_rpc_connect_dc_info(struct torture_context *torture)
191 const enum libnet_RpcConnect_level level = LIBNET_RPC_CONNECT_DC_INFO;
193 struct dcerpc_binding *binding;
194 const char *domain_name;
196 status = torture_rpc_binding(torture, &binding);
197 if (!NT_STATUS_IS_OK(status)) {
201 /* we're accessing domain controller so the domain name should be
202 passed (it's going to be resolved to dc name and address) instead
203 of specific server name. */
204 domain_name = lp_workgroup(torture->lp_ctx);
205 return torture_rpc_connect(torture, level, NULL, domain_name);
209 bool torture_rpc_connect_binding(struct torture_context *torture)
211 const enum libnet_RpcConnect_level level = LIBNET_RPC_CONNECT_BINDING;
213 struct dcerpc_binding *binding;
216 status = torture_rpc_binding(torture, &binding);
217 if (!NT_STATUS_IS_OK(status)) {
221 bindstr = dcerpc_binding_string(torture, binding);
223 return torture_rpc_connect(torture, level, bindstr, NULL);