r2552: Character set conversion and string handling updates.
[Samba/gebeck_regimport.git] / source4 / torture / rpc / schannel.c
blobf6c94b145adadd619105bb2ef8f874dbeaf4e8af
1 /*
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.
23 #include "includes.h"
25 #define TEST_MACHINE_NAME "schanneltest"
28 do some samr ops using the schannel connection
30 static BOOL test_samr_ops(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx)
32 NTSTATUS status;
33 struct samr_GetDomPwInfo r;
34 int i;
35 struct samr_Name name;
37 name.name = lp_workgroup();
38 r.in.name = &name;
40 printf("Testing GetDomPwInfo with name %s\n", r.in.name->name);
42 /* do several ops to test credential chaining */
43 for (i=0;i<5;i++) {
44 status = dcerpc_samr_GetDomPwInfo(p, mem_ctx, &r);
45 if (!NT_STATUS_IS_OK(status)) {
46 printf("GetDomPwInfo op %d failed - %s\n", i, nt_errstr(status));
47 return False;
51 return True;
55 test a schannel connection with the given flags
57 static BOOL test_schannel(TALLOC_CTX *mem_ctx,
58 uint16 acct_flags, uint32 dcerpc_flags,
59 uint32 schannel_type)
61 void *join_ctx;
62 const char *machine_password;
63 NTSTATUS status;
64 const char *binding = lp_parm_string(-1, "torture", "binding");
65 struct dcerpc_binding b;
66 struct dcerpc_pipe *p;
68 join_ctx = torture_join_domain(TEST_MACHINE_NAME, lp_workgroup(), acct_flags,
69 &machine_password);
70 if (!join_ctx) {
71 printf("Failed to join domain with acct_flags=0x%x\n", acct_flags);
72 return False;
75 status = dcerpc_parse_binding(mem_ctx, binding, &b);
76 if (!NT_STATUS_IS_OK(status)) {
77 printf("Bad binding string %s\n", binding);
78 goto failed;
81 b.flags &= ~DCERPC_AUTH_OPTIONS;
82 b.flags |= dcerpc_flags;
84 status = dcerpc_pipe_connect_b(&p, &b,
85 DCERPC_SAMR_UUID,
86 DCERPC_SAMR_VERSION,
87 lp_workgroup(),
88 TEST_MACHINE_NAME,
89 machine_password);
90 if (!NT_STATUS_IS_OK(status)) {
91 printf("Failed to connect with schannel\n");
92 goto failed;
95 if (!test_samr_ops(p, mem_ctx)) {
96 printf("Failed to process schannel secured ops\n");
97 goto failed;
100 torture_leave_domain(join_ctx);
101 return True;
103 failed:
104 torture_leave_domain(join_ctx);
105 return False;
109 a schannel test suite
111 BOOL torture_rpc_schannel(int dummy)
113 TALLOC_CTX *mem_ctx;
114 BOOL ret = True;
115 struct {
116 uint16 acct_flags;
117 uint32 dcerpc_flags;
118 uint32 schannel_type;
119 } tests[] = {
120 { ACB_WSTRUST, DCERPC_SCHANNEL_WORKSTATION | DCERPC_SIGN, 3 },
121 { ACB_WSTRUST, DCERPC_SCHANNEL_WORKSTATION | DCERPC_SEAL, 3 },
122 { ACB_WSTRUST, DCERPC_SCHANNEL_WORKSTATION | DCERPC_SIGN | DCERPC_SCHANNEL_128, 3 },
123 { ACB_WSTRUST, DCERPC_SCHANNEL_WORKSTATION | DCERPC_SEAL | DCERPC_SCHANNEL_128, 3 },
124 { ACB_SVRTRUST, DCERPC_SCHANNEL_BDC | DCERPC_SIGN, 3 },
125 { ACB_SVRTRUST, DCERPC_SCHANNEL_BDC | DCERPC_SEAL, 3 },
126 { ACB_SVRTRUST, DCERPC_SCHANNEL_BDC | DCERPC_SIGN | DCERPC_SCHANNEL_128, 3 },
127 { ACB_SVRTRUST, DCERPC_SCHANNEL_BDC | DCERPC_SEAL | DCERPC_SCHANNEL_128, 3 }
129 int i;
131 mem_ctx = talloc_init("torture_rpc_schannel");
133 for (i=0;i<ARRAY_SIZE(tests);i++) {
134 if (!test_schannel(mem_ctx,
135 tests[i].acct_flags, tests[i].dcerpc_flags, tests[i].schannel_type)) {
136 printf("Failed with acct_flags=0x%x dcerpc_flags=0x%x schannel_type=%d\n",
137 tests[i].acct_flags, tests[i].dcerpc_flags, tests[i].schannel_type);
138 ret = False;
139 break;
143 return ret;