s4:gensec: pass down want_features to the spnego backend mech
[kai/samba.git] / source4 / auth / gensec / gensec.h
1 /* 
2    Unix SMB/CIFS implementation.
3  
4    Generic Authentication Interface
5
6    Copyright (C) Andrew Tridgell 2003
7    Copyright (C) Andrew Bartlett <abartlet@samba.org> 2004-2005
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 3 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, see <http://www.gnu.org/licenses/>.
21 */
22
23 #ifndef __GENSEC_H__
24 #define __GENSEC_H__
25
26 #define GENSEC_OID_NTLMSSP "1.3.6.1.4.1.311.2.2.10"
27 #define GENSEC_OID_SPNEGO "1.3.6.1.5.5.2"
28 #define GENSEC_OID_KERBEROS5 "1.2.840.113554.1.2.2"
29 #define GENSEC_OID_KERBEROS5_OLD "1.2.840.48018.1.2.2"
30 #define GENSEC_OID_KERBEROS5_USER2USER "1.2.840.113554.1.2.2.3"
31
32 enum gensec_priority {
33         GENSEC_SPNEGO = 90,
34         GENSEC_GSSAPI = 80,
35         GENSEC_KRB5 = 70,
36         GENSEC_SCHANNEL = 60,
37         GENSEC_NTLMSSP = 50,
38         GENSEC_SASL = 20,
39         GENSEC_OTHER = 0
40 };
41
42 struct gensec_security;
43 struct gensec_target {
44         const char *principal;
45         const char *hostname;
46         const char *service;
47 };
48
49 #define GENSEC_FEATURE_SESSION_KEY      0x00000001
50 #define GENSEC_FEATURE_SIGN             0x00000002
51 #define GENSEC_FEATURE_SEAL             0x00000004
52 #define GENSEC_FEATURE_DCE_STYLE        0x00000008
53 #define GENSEC_FEATURE_ASYNC_REPLIES    0x00000010
54 #define GENSEC_FEATURE_DATAGRAM_MODE    0x00000020
55 #define GENSEC_FEATURE_SIGN_PKT_HEADER  0x00000040
56 #define GENSEC_FEATURE_NEW_SPNEGO       0x00000080
57
58 /* GENSEC mode */
59 enum gensec_role
60 {
61         GENSEC_SERVER,
62         GENSEC_CLIENT
63 };
64
65 struct auth_session_info;
66 struct cli_credentials;
67
68 struct gensec_update_request {
69         struct gensec_security *gensec_security;
70         void *private_data;
71         DATA_BLOB in;
72         DATA_BLOB out;
73         NTSTATUS status;
74         struct {
75                 void (*fn)(struct gensec_update_request *req, void *private_data);
76                 void *private_data;
77         } callback;
78 };
79
80 struct gensec_security_ops {
81         const char *name;
82         const char *sasl_name;
83         uint8_t auth_type;  /* 0 if not offered on DCE-RPC */
84         const char **oid;  /* NULL if not offered by SPNEGO */
85         NTSTATUS (*client_start)(struct gensec_security *gensec_security);
86         NTSTATUS (*server_start)(struct gensec_security *gensec_security);
87         /**
88            Determine if a packet has the right 'magic' for this mechanism
89         */
90         NTSTATUS (*magic)(struct gensec_security *gensec_security, 
91                           const DATA_BLOB *first_packet);
92         NTSTATUS (*update)(struct gensec_security *gensec_security, TALLOC_CTX *out_mem_ctx,
93                            const DATA_BLOB in, DATA_BLOB *out);
94         NTSTATUS (*seal_packet)(struct gensec_security *gensec_security, TALLOC_CTX *sig_mem_ctx,
95                                 uint8_t *data, size_t length, 
96                                 const uint8_t *whole_pdu, size_t pdu_length, 
97                                 DATA_BLOB *sig);
98         NTSTATUS (*sign_packet)(struct gensec_security *gensec_security, TALLOC_CTX *sig_mem_ctx,
99                                 const uint8_t *data, size_t length, 
100                                 const uint8_t *whole_pdu, size_t pdu_length, 
101                                 DATA_BLOB *sig);
102         size_t   (*sig_size)(struct gensec_security *gensec_security, size_t data_size);
103         size_t   (*max_input_size)(struct gensec_security *gensec_security);
104         size_t   (*max_wrapped_size)(struct gensec_security *gensec_security);
105         NTSTATUS (*check_packet)(struct gensec_security *gensec_security, TALLOC_CTX *sig_mem_ctx, 
106                                  const uint8_t *data, size_t length, 
107                                  const uint8_t *whole_pdu, size_t pdu_length, 
108                                  const DATA_BLOB *sig);
109         NTSTATUS (*unseal_packet)(struct gensec_security *gensec_security, TALLOC_CTX *sig_mem_ctx,
110                                   uint8_t *data, size_t length, 
111                                   const uint8_t *whole_pdu, size_t pdu_length, 
112                                   const DATA_BLOB *sig);
113         NTSTATUS (*wrap)(struct gensec_security *gensec_security, 
114                                   TALLOC_CTX *mem_ctx, 
115                                   const DATA_BLOB *in, 
116                                   DATA_BLOB *out); 
117         NTSTATUS (*unwrap)(struct gensec_security *gensec_security, 
118                            TALLOC_CTX *mem_ctx, 
119                            const DATA_BLOB *in, 
120                            DATA_BLOB *out); 
121         NTSTATUS (*wrap_packets)(struct gensec_security *gensec_security, 
122                                  TALLOC_CTX *mem_ctx, 
123                                  const DATA_BLOB *in, 
124                                  DATA_BLOB *out,
125                                  size_t *len_processed); 
126         NTSTATUS (*unwrap_packets)(struct gensec_security *gensec_security, 
127                                    TALLOC_CTX *mem_ctx, 
128                                    const DATA_BLOB *in, 
129                                    DATA_BLOB *out,
130                                    size_t *len_processed); 
131         NTSTATUS (*packet_full_request)(struct gensec_security *gensec_security,
132                                         DATA_BLOB blob, size_t *size);
133         NTSTATUS (*session_key)(struct gensec_security *gensec_security, DATA_BLOB *session_key);
134         NTSTATUS (*session_info)(struct gensec_security *gensec_security, 
135                                  struct auth_session_info **session_info); 
136         void (*want_feature)(struct gensec_security *gensec_security,
137                                     uint32_t feature);
138         bool (*have_feature)(struct gensec_security *gensec_security,
139                                     uint32_t feature); 
140         bool enabled;
141         bool kerberos;
142         enum gensec_priority priority;
143 };
144         
145 struct gensec_security_ops_wrapper {
146         const struct gensec_security_ops *op;
147         const char *oid;
148 };
149
150 #define GENSEC_INTERFACE_VERSION 0
151
152 struct gensec_security {
153         const struct gensec_security_ops *ops;
154         struct loadparm_context *lp_ctx;
155         void *private_data;
156         struct cli_credentials *credentials;
157         struct gensec_target target;
158         enum gensec_role gensec_role;
159         bool subcontext;
160         uint32_t want_features;
161         struct event_context *event_ctx;
162         struct messaging_context *msg_ctx; /* only valid as server */
163         struct socket_address *my_addr, *peer_addr;
164 };
165
166 /* this structure is used by backends to determine the size of some critical types */
167 struct gensec_critical_sizes {
168         int interface_version;
169         int sizeof_gensec_security_ops;
170         int sizeof_gensec_security;
171 };
172
173 /* Socket wrapper */
174
175 struct gensec_security;
176 struct socket_context;
177
178 NTSTATUS gensec_socket_init(struct gensec_security *gensec_security,
179                             TALLOC_CTX *mem_ctx, 
180                             struct socket_context *current_socket,
181                             struct event_context *ev,
182                             void (*recv_handler)(void *, uint16_t),
183                             void *recv_private,
184                             struct socket_context **new_socket);
185 /* These functions are for use here only (public because SPNEGO must
186  * use them for recursion) */
187 NTSTATUS gensec_wrap_packets(struct gensec_security *gensec_security, 
188                              TALLOC_CTX *mem_ctx, 
189                              const DATA_BLOB *in, 
190                              DATA_BLOB *out,
191                              size_t *len_processed);
192 /* These functions are for use here only (public because SPNEGO must
193  * use them for recursion) */
194 NTSTATUS gensec_unwrap_packets(struct gensec_security *gensec_security, 
195                                TALLOC_CTX *mem_ctx, 
196                                const DATA_BLOB *in, 
197                                DATA_BLOB *out,
198                                size_t *len_processed);
199
200 /* These functions are for use here only (public because SPNEGO must
201  * use them for recursion) */
202 NTSTATUS gensec_packet_full_request(struct gensec_security *gensec_security,
203                                     DATA_BLOB blob, size_t *size);
204
205 struct loadparm_context;
206
207 NTSTATUS gensec_subcontext_start(TALLOC_CTX *mem_ctx, 
208                                  struct gensec_security *parent, 
209                                  struct gensec_security **gensec_security);
210 NTSTATUS gensec_client_start(TALLOC_CTX *mem_ctx, 
211                              struct gensec_security **gensec_security,
212                              struct event_context *ev,
213                              struct loadparm_context *lp_ctx);
214 NTSTATUS gensec_start_mech_by_sasl_list(struct gensec_security *gensec_security, 
215                                                  const char **sasl_names);
216 NTSTATUS gensec_update(struct gensec_security *gensec_security, TALLOC_CTX *out_mem_ctx, 
217                        const DATA_BLOB in, DATA_BLOB *out);
218 void gensec_update_send(struct gensec_security *gensec_security, const DATA_BLOB in,
219                                  void (*callback)(struct gensec_update_request *req, void *private_data),
220                                  void *private_data);
221 NTSTATUS gensec_update_recv(struct gensec_update_request *req, TALLOC_CTX *out_mem_ctx, DATA_BLOB *out);
222 void gensec_want_feature(struct gensec_security *gensec_security,
223                          uint32_t feature);
224 bool gensec_have_feature(struct gensec_security *gensec_security,
225                          uint32_t feature);
226 NTSTATUS gensec_set_credentials(struct gensec_security *gensec_security, struct cli_credentials *credentials);
227 NTSTATUS gensec_set_target_service(struct gensec_security *gensec_security, const char *service);
228 const char *gensec_get_target_service(struct gensec_security *gensec_security);
229 NTSTATUS gensec_set_target_hostname(struct gensec_security *gensec_security, const char *hostname);
230 const char *gensec_get_target_hostname(struct gensec_security *gensec_security);
231 NTSTATUS gensec_session_key(struct gensec_security *gensec_security, 
232                             DATA_BLOB *session_key);
233 NTSTATUS gensec_start_mech_by_oid(struct gensec_security *gensec_security, 
234                                   const char *mech_oid);
235 const char *gensec_get_name_by_oid(const char *oid_string);
236 struct cli_credentials *gensec_get_credentials(struct gensec_security *gensec_security);
237 struct socket_address *gensec_get_peer_addr(struct gensec_security *gensec_security);
238 NTSTATUS gensec_init(struct loadparm_context *lp_ctx);
239 NTSTATUS gensec_unseal_packet(struct gensec_security *gensec_security, 
240                               TALLOC_CTX *mem_ctx, 
241                               uint8_t *data, size_t length, 
242                               const uint8_t *whole_pdu, size_t pdu_length, 
243                               const DATA_BLOB *sig);
244 NTSTATUS gensec_check_packet(struct gensec_security *gensec_security, 
245                              TALLOC_CTX *mem_ctx, 
246                              const uint8_t *data, size_t length, 
247                              const uint8_t *whole_pdu, size_t pdu_length, 
248                              const DATA_BLOB *sig);
249 size_t gensec_sig_size(struct gensec_security *gensec_security, size_t data_size);
250 NTSTATUS gensec_seal_packet(struct gensec_security *gensec_security, 
251                             TALLOC_CTX *mem_ctx, 
252                             uint8_t *data, size_t length, 
253                             const uint8_t *whole_pdu, size_t pdu_length, 
254                             DATA_BLOB *sig);
255 NTSTATUS gensec_sign_packet(struct gensec_security *gensec_security, 
256                             TALLOC_CTX *mem_ctx, 
257                             const uint8_t *data, size_t length, 
258                             const uint8_t *whole_pdu, size_t pdu_length, 
259                             DATA_BLOB *sig);
260 NTSTATUS gensec_start_mech_by_authtype(struct gensec_security *gensec_security, 
261                                        uint8_t auth_type, uint8_t auth_level);
262 const char *gensec_get_name_by_authtype(uint8_t authtype);
263 NTSTATUS gensec_server_start(TALLOC_CTX *mem_ctx, 
264                              struct event_context *ev,
265                              struct loadparm_context *lp_ctx,
266                              struct messaging_context *msg,
267                              struct gensec_security **gensec_security);
268 NTSTATUS gensec_session_info(struct gensec_security *gensec_security, 
269                              struct auth_session_info **session_info);
270 NTSTATUS auth_nt_status_squash(NTSTATUS nt_status);
271 struct creds_CredentialState;
272 NTSTATUS dcerpc_schannel_creds(struct gensec_security *gensec_security,
273                                TALLOC_CTX *mem_ctx,
274                                struct creds_CredentialState **creds);
275 NTSTATUS gensec_set_peer_addr(struct gensec_security *gensec_security, struct socket_address *peer_addr);
276 NTSTATUS gensec_set_my_addr(struct gensec_security *gensec_security, struct socket_address *my_addr);
277
278 NTSTATUS gensec_start_mech_by_name(struct gensec_security *gensec_security, 
279                                         const char *name);
280
281 NTSTATUS gensec_unwrap(struct gensec_security *gensec_security, 
282                        TALLOC_CTX *mem_ctx, 
283                        const DATA_BLOB *in, 
284                        DATA_BLOB *out);
285 NTSTATUS gensec_wrap(struct gensec_security *gensec_security, 
286                      TALLOC_CTX *mem_ctx, 
287                      const DATA_BLOB *in, 
288                      DATA_BLOB *out);
289
290 struct gensec_security_ops **gensec_security_all(void);
291 struct gensec_security_ops **gensec_use_kerberos_mechs(TALLOC_CTX *mem_ctx, 
292                                                        struct gensec_security_ops **old_gensec_list, 
293                                                        struct cli_credentials *creds);
294
295 NTSTATUS gensec_start_mech_by_sasl_name(struct gensec_security *gensec_security, 
296                                         const char *sasl_name);
297
298
299 #endif /* __GENSEC_H__ */