r4618: - tidied up the alter_context client code a bit
[samba.git] / source4 / librpc / rpc / dcerpc_spnego.c
1 /* 
2    Unix SMB/CIFS implementation.
3
4    dcerpc authentication operations
5
6    Copyright (C) Stefan Metzmacher 2004
7    Copyright (C) Andrew Tridgell 2003-2005
8    Copyright (C) Andrew Bartlett 2004
9    
10    This program is free software; you can redistribute it and/or modify
11    it under the terms of the GNU General Public License as published by
12    the Free Software Foundation; either version 2 of the License, or
13    (at your option) any later version.
14    
15    This program is distributed in the hope that it will be useful,
16    but WITHOUT ANY WARRANTY; without even the implied warranty of
17    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18    GNU General Public License for more details.
19    
20    You should have received a copy of the GNU General Public License
21    along with this program; if not, write to the Free Software
22    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 */
24
25 #include "includes.h"
26
27 #if 0
28 /*
29   metze, can you tell me what you're trying to do with this?
30 */
31
32 /*
33   do spnego style authentication on a gensec pipe
34 */
35 NTSTATUS dcerpc_bind_auth_spnego(struct dcerpc_pipe *p,
36                                const char *uuid, uint_t version,
37                                const char *domain,
38                                const char *username,
39                                const char *password)
40 {
41         NTSTATUS status;
42
43         status = gensec_client_start(p, &p->conn->security_state.generic_state);
44         if (!NT_STATUS_IS_OK(status)) {
45                 DEBUG(1, ("Failed to start GENSEC client mode: %s\n", nt_errstr(status)));
46                 return status;
47         }
48
49         status = gensec_set_domain(p->conn->security_state.generic_state, domain);
50         if (!NT_STATUS_IS_OK(status)) {
51                 DEBUG(1, ("Failed to start set GENSEC client domain to %s: %s\n", 
52                           domain, nt_errstr(status)));
53                 return status;
54         }
55
56         status = gensec_set_username(p->conn->security_state.generic_state, username);
57         if (!NT_STATUS_IS_OK(status)) {
58                 DEBUG(1, ("Failed to start set GENSEC client username to %s: %s\n", 
59                           username, nt_errstr(status)));
60                 return status;
61         }
62
63         status = gensec_set_password(p->conn->security_state.generic_state, password);
64         if (!NT_STATUS_IS_OK(status)) {
65                 DEBUG(1, ("Failed to start set GENSEC client password: %s\n", 
66                           nt_errstr(status)));
67                 return status;
68         }
69
70         status = gensec_set_target_hostname(p->conn->security_state.generic_state, 
71                                             p->conn->transport.peer_name(p->conn));
72         if (!NT_STATUS_IS_OK(status)) {
73                 DEBUG(1, ("Failed to start set GENSEC target hostname: %s\n", 
74                           nt_errstr(status)));
75                 return status;
76         }
77
78         status = gensec_start_mech_by_authtype(p->conn->security_state.generic_state, 
79                                                DCERPC_AUTH_TYPE_SPNEGO, 
80                                                dcerpc_auth_level(p->conn));
81         if (!NT_STATUS_IS_OK(status)) {
82                 DEBUG(1, ("Failed to start set GENSEC client SPNEGO mechanism: %s\n",
83                           nt_errstr(status)));
84                 return status;
85         }
86         
87         status = dcerpc_bind_alter(p, DCERPC_AUTH_TYPE_SPNEGO, 
88                                    dcerpc_auth_level(p->conn),
89                                    uuid, version);
90
91         if (!NT_STATUS_IS_OK(status)) {
92                 DEBUG(2, ("Failed to bind to pipe with SPNEGO: %s\n", nt_errstr(status)));
93                 return status;
94         }
95
96         return status;
97 }
98 #endif