f6c94b145adadd619105bb2ef8f874dbeaf4e8af
[jra/samba/.git] / source4 / torture / rpc / schannel.c
1 /* 
2    Unix SMB/CIFS implementation.
3
4    test suite for schannel operations
5
6    Copyright (C) Andrew Tridgell 2004
7    
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.
12    
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.
17    
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.
21 */
22
23 #include "includes.h"
24
25 #define TEST_MACHINE_NAME "schanneltest"
26
27 /*
28   do some samr ops using the schannel connection
29  */
30 static BOOL test_samr_ops(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx)
31 {
32         NTSTATUS status;
33         struct samr_GetDomPwInfo r;
34         int i;
35         struct samr_Name name;
36
37         name.name = lp_workgroup();
38         r.in.name = &name;
39
40         printf("Testing GetDomPwInfo with name %s\n", r.in.name->name);
41         
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;
48                 }
49         }
50
51         return True;
52 }
53
54 /*
55   test a schannel connection with the given flags
56  */
57 static BOOL test_schannel(TALLOC_CTX *mem_ctx, 
58                           uint16 acct_flags, uint32 dcerpc_flags,
59                           uint32 schannel_type)
60 {
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;
67
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;
73         }
74
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;
79         }
80
81         b.flags &= ~DCERPC_AUTH_OPTIONS;
82         b.flags |= dcerpc_flags;
83
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;
93         }
94
95         if (!test_samr_ops(p, mem_ctx)) {
96                 printf("Failed to process schannel secured ops\n");
97                 goto failed;
98         }
99
100         torture_leave_domain(join_ctx);
101         return True;
102
103 failed:
104         torture_leave_domain(join_ctx);
105         return False;   
106 }
107
108 /*
109   a schannel test suite
110  */
111 BOOL torture_rpc_schannel(int dummy)
112 {
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 }
128         };
129         int i;
130
131         mem_ctx = talloc_init("torture_rpc_schannel");
132
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;
140                 }
141         }
142
143         return ret;
144 }