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 "auth/credentials/credentials.h"
24 #include "libnet/libnet.h"
25 #include "libcli/security/security.h"
26 #include "librpc/ndr/libndr.h"
27 #include "librpc/gen_ndr/ndr_lsa.h"
28 #include "librpc/gen_ndr/ndr_samr.h"
29 #include "librpc/gen_ndr/ndr_srvsvc.h"
30 #include "librpc/rpc/dcerpc.h"
31 #include "torture/torture.h"
34 static BOOL test_connect_service(struct libnet_context *ctx,
35 const struct dcerpc_interface_table *iface,
36 const char *binding_string,
38 const enum libnet_RpcConnect_level level,
39 BOOL badcreds, NTSTATUS expected_status)
42 struct libnet_RpcConnect connect;
43 connect.level = level;
44 connect.in.binding = binding_string;
45 connect.in.name = hostname;
46 connect.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);
57 if (!NT_STATUS_EQUAL(status, expected_status)) {
58 d_printf("Connecting to rpc service %s on %s.\n\tFAILED. Expected: %s."
60 connect.in.dcerpc_iface->name, connect.in.binding, nt_errstr(expected_status),
66 d_printf("PASSED. Expected: %s, received: %s\n", nt_errstr(expected_status),
69 if (connect.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.out.domain_name);
72 d_printf("\tDomain SID:\t %s\n", dom_sid_string(ctx, connect.out.domain_sid));
73 d_printf("\tRealm:\t\t %s\n", connect.out.realm);
74 d_printf("\tGUID:\t\t %s\n", GUID_string(ctx, connect.out.guid));
76 } else if (!NT_STATUS_IS_OK(status)) {
77 d_printf("Error string: %s\n", connect.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(NULL);
91 ctx->cred = cmdline_credentials;
93 d_printf("Testing connection to LSA interface\n");
94 if (!test_connect_service(ctx, &dcerpc_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, &dcerpc_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, &dcerpc_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, &dcerpc_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, &dcerpc_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;
139 const char *bindstr;;
141 bindstr = torture_setting_string(torture, "binding", NULL);
142 status = dcerpc_parse_binding(torture, bindstr, &binding);
143 if (!NT_STATUS_IS_OK(status)) {
144 d_printf("failed to parse binding string\n");
148 return torture_rpc_connect(torture, level, NULL, binding->host);
152 BOOL torture_rpc_connect_pdc(struct torture_context *torture)
154 const enum libnet_RpcConnect_level level = LIBNET_RPC_CONNECT_PDC;
156 struct dcerpc_binding *binding;
158 const char *domain_name;
160 bindstr = torture_setting_string(torture, "binding", NULL);
161 status = dcerpc_parse_binding(torture, bindstr, &binding);
162 if (!NT_STATUS_IS_OK(status)) {
163 d_printf("failed to parse binding string\n");
167 /* we're accessing domain controller so the domain name should be
168 passed (it's going to be resolved to dc name and address) instead
169 of specific server name. */
170 domain_name = lp_workgroup();
171 return torture_rpc_connect(torture, level, NULL, domain_name);
175 BOOL torture_rpc_connect_dc(struct torture_context *torture)
177 const enum libnet_RpcConnect_level level = LIBNET_RPC_CONNECT_DC;
179 struct dcerpc_binding *binding;
181 const char *domain_name;
183 bindstr = torture_setting_string(torture, "binding", NULL);
184 status = dcerpc_parse_binding(torture, bindstr, &binding);
185 if (!NT_STATUS_IS_OK(status)) {
186 d_printf("failed to parse binding string\n");
190 /* we're accessing domain controller so the domain name should be
191 passed (it's going to be resolved to dc name and address) instead
192 of specific server name. */
193 domain_name = lp_workgroup();
194 return torture_rpc_connect(torture, level, NULL, domain_name);
198 BOOL torture_rpc_connect_dc_info(struct torture_context *torture)
200 const enum libnet_RpcConnect_level level = LIBNET_RPC_CONNECT_DC_INFO;
202 struct dcerpc_binding *binding;
204 const char *domain_name;
206 bindstr = torture_setting_string(torture, "binding", NULL);
207 status = dcerpc_parse_binding(torture, bindstr, &binding);
208 if (!NT_STATUS_IS_OK(status)) {
209 d_printf("failed to parse binding string\n");
213 /* we're accessing domain controller so the domain name should be
214 passed (it's going to be resolved to dc name and address) instead
215 of specific server name. */
216 domain_name = lp_workgroup();
217 return torture_rpc_connect(torture, level, NULL, domain_name);
221 BOOL torture_rpc_connect_binding(struct torture_context *torture)
223 const enum libnet_RpcConnect_level level = LIBNET_RPC_CONNECT_BINDING;
225 struct dcerpc_binding *binding;
228 bindstr = torture_setting_string(torture, "binding", NULL);
229 status = dcerpc_parse_binding(torture, bindstr, &binding);
230 if (!NT_STATUS_IS_OK(status)) {
231 d_printf("failed to parse binding string\n");
235 return torture_rpc_connect(torture, level, bindstr, NULL);