r4635: Fix NTLMSSP to return NT_STATUS_OK when it has constructed the auth
[sfrench/samba-autobuild/.git] / source4 / torture / rpc / bind.c
1 /* 
2    Unix SMB/CIFS implementation.
3
4    dcerpc torture tests
5
6    Copyright (C) Andrew Tridgell 2003
7    Copyright (C) Andrew Bartlett <abartlet@samba.org 2004
8
9    This program is free software; you can redistribute it and/or modify
10    it under the terms of the GNU General Public License as published by
11    the Free Software Foundation; either version 2 of the License, or
12    (at your option) any later version.
13    
14    This program is distributed in the hope that it will be useful,
15    but WITHOUT ANY WARRANTY; without even the implied warranty of
16    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17    GNU General Public License for more details.
18    
19    You should have received a copy of the GNU General Public License
20    along with this program; if not, write to the Free Software
21    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 */
23
24 #include "includes.h"
25 #include "librpc/gen_ndr/ndr_lsa.h"
26
27 /*
28   This test is 'bogus' in that it doesn't actually perform to the
29   spec.  We need to deal with other things inside the DCERPC layer,
30   before we could have multiple binds.
31
32   We should never pass this test, until such details are fixed in our
33   client, and it looks like multible binds are never used anyway.
34
35 */
36
37 BOOL torture_multi_bind(void) 
38 {
39         struct dcerpc_pipe *p;
40         const char *domain = lp_parm_string(-1, "torture", "userdomain");
41         const char *username = lp_parm_string(-1, "torture", "username");
42         const char *password = lp_parm_string(-1, "torture", "password");
43         const char *pipe_uuid = DCERPC_LSARPC_UUID;
44         uint32_t pipe_version = DCERPC_LSARPC_VERSION;
45         struct dcerpc_binding b;
46         struct dcerpc_binding *binding;
47         const char *binding_string = lp_parm_string(-1, "torture", "binding");
48         TALLOC_CTX *mem_ctx;
49         NTSTATUS status;
50         BOOL ret;
51
52         mem_ctx = talloc_init("torture_multi_bind");
53
54         status = dcerpc_parse_binding(mem_ctx, binding_string, &b);
55         if (!NT_STATUS_IS_OK(status)) {
56                 DEBUG(0,("Failed to parse dcerpc binding '%s'\n", binding_string));
57                 talloc_destroy(mem_ctx);
58                 return False;
59         }
60
61         binding = &b;
62
63         status = torture_rpc_connection(&p, 
64                                         NULL,
65                                         pipe_uuid,
66                                         pipe_version);
67         
68         if (!NT_STATUS_IS_OK(status)) {
69                 return False;
70         }
71
72         if (username && username[0] && (binding->flags & DCERPC_SCHANNEL_ANY)) {
73                 status = dcerpc_bind_auth_schannel(p, pipe_uuid, pipe_version, 
74                                                    domain, username, password);
75         } else if (username && username[0]) {
76                 uint8_t auth_type;
77                 if (binding->flags & DCERPC_AUTH_SPNEGO) {
78                         auth_type = DCERPC_AUTH_TYPE_SPNEGO;
79                 } else {
80                         auth_type = DCERPC_AUTH_TYPE_NTLMSSP;
81                 }
82
83                 status = dcerpc_bind_auth_password(p, pipe_uuid, pipe_version, 
84                                                    domain, username, password, 
85                                                    auth_type);
86         } else {    
87                 status = dcerpc_bind_auth_none(p, pipe_uuid, pipe_version);
88         }
89
90         if (NT_STATUS_IS_OK(status)) {
91                 DEBUG(0,("(incorrectly) allowed re-bind to uuid %s - %s\n", 
92                          pipe_uuid, nt_errstr(status)));
93                 ret = False;
94         } else {
95                 ret = True;
96         }
97
98         printf("\n");
99         
100         talloc_destroy(mem_ctx);
101         torture_rpc_close(p);
102
103         return ret;
104 }