r18250: Add an ordering of GENSEC modules, so we do preferred modules first.
[bbaumbach/samba-autobuild/.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 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 #ifndef __GENSEC_H__
25 #define __GENSEC_H__
26
27 #include "core.h"
28
29 #define GENSEC_OID_NTLMSSP "1 3 6 1 4 1 311 2 2 10"
30 #define GENSEC_OID_SPNEGO "1 3 6 1 5 5 2"
31 #define GENSEC_OID_KERBEROS5 "1 2 840 113554 1 2 2"
32 #define GENSEC_OID_KERBEROS5_OLD "1 2 840 48018 1 2 2"
33 #define GENSEC_OID_KERBEROS5_USER2USER "1 2 840 113554 1 2 2 3"
34
35 enum gensec_order {
36         GENSEC_SPNEGO,
37         GENSEC_GSSAPI,
38         GENSEC_KRB5,
39         GENSEC_SCHANNEL,
40         GENSEC_NTLMSSP,
41         GENSEC_SASL,
42         GENSEC_OTHER
43 };
44
45 struct gensec_security;
46 struct gensec_target {
47         const char *principal;
48         const char *hostname;
49         const char *service;
50 };
51
52 #define GENSEC_FEATURE_SESSION_KEY      0x00000001
53 #define GENSEC_FEATURE_SIGN             0x00000002
54 #define GENSEC_FEATURE_SEAL             0x00000004
55 #define GENSEC_FEATURE_DCE_STYLE        0x00000008
56 #define GENSEC_FEATURE_ASYNC_REPLIES    0x00000010
57 #define GENSEC_FEATURE_DATAGRAM_MODE    0x00000020
58
59 /* GENSEC mode */
60 enum gensec_role
61 {
62         GENSEC_SERVER,
63         GENSEC_CLIENT
64 };
65
66 struct auth_session_info;
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         BOOL (*have_feature)(struct gensec_security *gensec_security,
137                                     uint32_t feature); 
138         BOOL enabled;
139         BOOL kerberos;
140         enum gensec_order order;
141 };
142         
143 struct gensec_security_ops_wrapper {
144         const struct gensec_security_ops *op;
145         const char *oid;
146 };
147
148 #define GENSEC_INTERFACE_VERSION 0
149
150 struct gensec_security {
151         const struct gensec_security_ops *ops;
152         void *private_data;
153         struct cli_credentials *credentials;
154         struct gensec_target target;
155         enum gensec_role gensec_role;
156         BOOL subcontext;
157         uint32_t want_features;
158         struct event_context *event_ctx;
159         struct messaging_context *msg_ctx; /* only valid as server */
160         struct socket_address *my_addr, *peer_addr;
161 };
162
163 /* this structure is used by backends to determine the size of some critical types */
164 struct gensec_critical_sizes {
165         int interface_version;
166         int sizeof_gensec_security_ops;
167         int sizeof_gensec_security;
168 };
169
170 #include "auth/credentials/credentials.h"
171 #include "auth/gensec/gensec_proto.h"
172
173 #endif /* __GENSEC_H__ */