2 Unix SMB/CIFS implementation.
4 test suite for schannel operations
6 Copyright (C) Andrew Tridgell 2004
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 #include "librpc/gen_ndr/ndr_netlogon.h"
26 #define TEST_MACHINE_NAME "schannel"
29 do some samr ops using the schannel connection
31 static BOOL test_samr_ops(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx)
34 struct samr_GetDomPwInfo r;
35 struct samr_Connect connect;
36 struct samr_OpenDomain opendom;
38 struct lsa_String name;
39 struct policy_handle handle;
40 struct policy_handle domain_handle;
42 name.string = lp_workgroup();
43 r.in.domain_name = &name;
45 connect.in.system_name = 0;
46 connect.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
47 connect.out.connect_handle = &handle;
49 printf("Testing Connect and OpenDomain on BUILTIN\n");
51 status = dcerpc_samr_Connect(p, mem_ctx, &connect);
52 if (!NT_STATUS_IS_OK(status)) {
53 if (NT_STATUS_EQUAL(status, NT_STATUS_ACCESS_DENIED)) {
54 printf("Connect failed (expected, schannel mapped to anonymous): %s\n",
57 printf("Connect failed - %s\n", nt_errstr(status));
61 opendom.in.connect_handle = &handle;
62 opendom.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
63 opendom.in.sid = dom_sid_parse_talloc(mem_ctx, "S-1-5-32");
64 opendom.out.domain_handle = &domain_handle;
66 status = dcerpc_samr_OpenDomain(p, mem_ctx, &opendom);
67 if (!NT_STATUS_IS_OK(status)) {
68 printf("OpenDomain failed - %s\n", nt_errstr(status));
73 printf("Testing GetDomPwInfo with name %s\n", r.in.domain_name->string);
75 /* do several ops to test credential chaining */
77 status = dcerpc_samr_GetDomPwInfo(p, mem_ctx, &r);
78 if (!NT_STATUS_IS_OK(status)) {
79 if (!NT_STATUS_EQUAL(status, NT_STATUS_ACCESS_DENIED)) {
80 printf("GetDomPwInfo op %d failed - %s\n", i, nt_errstr(status));
91 do some lsa ops using the schannel connection
93 static BOOL test_lsa_ops(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx)
95 struct lsa_GetUserName r;
98 struct lsa_StringPointer authority_name_p;
100 printf("\nTesting GetUserName\n");
102 r.in.system_name = "\\";
103 r.in.account_name = NULL;
104 r.in.authority_name = &authority_name_p;
105 authority_name_p.string = NULL;
107 /* do several ops to test credential chaining and various operations */
108 status = dcerpc_lsa_GetUserName(p, mem_ctx, &r);
110 if (NT_STATUS_EQUAL(status, NT_STATUS_RPC_PROTSEQ_NOT_SUPPORTED)) {
111 printf("not considering %s to be an error\n", nt_errstr(status));
112 } else if (!NT_STATUS_IS_OK(status)) {
113 printf("GetUserName failed - %s\n", nt_errstr(status));
116 if (!r.out.account_name) {
120 if (strcmp(r.out.account_name->string, "ANONYMOUS LOGON") != 0) {
121 printf("GetUserName returned wrong user: %s, expected %s\n",
122 r.out.account_name->string, "ANONYMOUS LOGON");
125 if (!r.out.authority_name || !r.out.authority_name->string) {
129 if (strcmp(r.out.authority_name->string->string, "NT AUTHORITY") != 0) {
130 printf("GetUserName returned wrong user: %s, expected %s\n",
131 r.out.authority_name->string->string, "NT AUTHORITY");
135 if (!test_many_LookupSids(p, mem_ctx, NULL)) {
136 printf("LsaLookupSids3 failed!\n");
145 test a schannel connection with the given flags
147 static BOOL test_schannel(TALLOC_CTX *mem_ctx,
148 uint16_t acct_flags, uint32_t dcerpc_flags,
153 struct test_join *join_ctx;
155 const char *binding = lp_parm_string(-1, "torture", "binding");
156 struct dcerpc_binding *b;
157 struct dcerpc_pipe *p = NULL;
158 struct dcerpc_pipe *p_netlogon = NULL;
159 struct dcerpc_pipe *p_lsa = NULL;
160 struct creds_CredentialState *creds;
161 struct cli_credentials *credentials;
163 TALLOC_CTX *test_ctx = talloc_named(mem_ctx, 0, "test_schannel context");
165 join_ctx = torture_join_domain(talloc_asprintf(mem_ctx, "%s%d", TEST_MACHINE_NAME, i),
166 acct_flags, &credentials);
168 printf("Failed to join domain with acct_flags=0x%x\n", acct_flags);
169 talloc_free(test_ctx);
173 status = dcerpc_parse_binding(test_ctx, binding, &b);
174 if (!NT_STATUS_IS_OK(status)) {
175 printf("Bad binding string %s\n", binding);
179 b->flags &= ~DCERPC_AUTH_OPTIONS;
180 b->flags |= dcerpc_flags;
182 status = dcerpc_pipe_connect_b(test_ctx, &p, b, &dcerpc_table_samr,
184 if (!NT_STATUS_IS_OK(status)) {
185 printf("Failed to connect with schannel: %s\n", nt_errstr(status));
189 if (!test_samr_ops(p, test_ctx)) {
190 printf("Failed to process schannel secured SAMR ops\n");
194 /* Also test that when we connect to the netlogon pipe, that
195 * the credentials we setup on the first pipe are valid for
198 /* Swap the binding details from SAMR to NETLOGON */
199 status = dcerpc_epm_map_binding(test_ctx, b, &dcerpc_table_netlogon, NULL);
200 if (!NT_STATUS_IS_OK(status)) {
204 status = dcerpc_secondary_connection(p, &p_netlogon,
207 if (!NT_STATUS_IS_OK(status)) {
211 status = dcerpc_bind_auth(p_netlogon, &dcerpc_table_netlogon,
212 credentials, DCERPC_AUTH_TYPE_SCHANNEL,
215 if (!NT_STATUS_IS_OK(status)) {
219 status = dcerpc_schannel_creds(p_netlogon->conn->security_state.generic_state, test_ctx, &creds);
220 if (!NT_STATUS_IS_OK(status)) {
224 /* do a couple of logins */
225 if (!test_netlogon_ops(p_netlogon, test_ctx, credentials, creds)) {
226 printf("Failed to process schannel secured NETLOGON ops\n");
230 /* Swap the binding details from SAMR to LSARPC */
231 status = dcerpc_epm_map_binding(test_ctx, b, &dcerpc_table_lsarpc, NULL);
232 if (!NT_STATUS_IS_OK(status)) {
236 status = dcerpc_secondary_connection(p, &p_lsa,
239 if (!NT_STATUS_IS_OK(status)) {
243 status = dcerpc_bind_auth(p_lsa, &dcerpc_table_lsarpc,
244 credentials, DCERPC_AUTH_TYPE_SCHANNEL,
247 if (!NT_STATUS_IS_OK(status)) {
251 if (!test_lsa_ops(p_lsa, test_ctx)) {
252 printf("Failed to process schannel secured LSA ops\n");
256 torture_leave_domain(join_ctx);
257 talloc_free(test_ctx);
261 torture_leave_domain(join_ctx);
262 talloc_free(test_ctx);
267 a schannel test suite
269 BOOL torture_rpc_schannel(void)
275 uint32_t dcerpc_flags;
277 { ACB_WSTRUST, DCERPC_SCHANNEL | DCERPC_SIGN},
278 { ACB_WSTRUST, DCERPC_SCHANNEL | DCERPC_SEAL},
279 { ACB_WSTRUST, DCERPC_SCHANNEL | DCERPC_SIGN | DCERPC_SCHANNEL_128},
280 { ACB_WSTRUST, DCERPC_SCHANNEL | DCERPC_SEAL | DCERPC_SCHANNEL_128 },
281 { ACB_SVRTRUST, DCERPC_SCHANNEL | DCERPC_SIGN },
282 { ACB_SVRTRUST, DCERPC_SCHANNEL | DCERPC_SEAL },
283 { ACB_SVRTRUST, DCERPC_SCHANNEL | DCERPC_SIGN | DCERPC_SCHANNEL_128 },
284 { ACB_SVRTRUST, DCERPC_SCHANNEL | DCERPC_SEAL | DCERPC_SCHANNEL_128 }
288 mem_ctx = talloc_init("torture_rpc_schannel");
290 for (i=0;i<ARRAY_SIZE(tests);i++) {
291 if (!test_schannel(mem_ctx,
292 tests[i].acct_flags, tests[i].dcerpc_flags,
294 printf("Failed with acct_flags=0x%x dcerpc_flags=0x%x \n",
295 tests[i].acct_flags, tests[i].dcerpc_flags);
301 talloc_free(mem_ctx);