r6113: Move GENSEC and the kerberos code out of libcli/auth, and into
[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 #define GENSEC_OID_NTLMSSP "1 3 6 1 4 1 311 2 2 10"
25 #define GENSEC_OID_SPNEGO "1 3 6 1 5 5 2"
26 #define GENSEC_OID_KERBEROS5 "1 2 840 113554 1 2 2"
27 #define GENSEC_OID_KERBEROS5_OLD "1 2 840 48018 1 2 2"
28 #define GENSEC_OID_KERBEROS5_USER2USER "1 2 840 113554 1 2 2 3"
29
30 struct gensec_security;
31 struct gensec_target {
32         const char *principal;
33         const char *hostname;
34         const struct sock_addr *addr;
35         const char *service;
36 };
37
38 #define GENSEC_FEATURE_SESSION_KEY      0x00000001
39 #define GENSEC_FEATURE_SIGN             0x00000002
40 #define GENSEC_FEATURE_SEAL             0x00000004
41 #define GENSEC_FEATURE_DCE_STYLE        0x00000008
42
43 /* GENSEC mode */
44 enum gensec_role
45 {
46         GENSEC_SERVER,
47         GENSEC_CLIENT
48 };
49
50 struct auth_session_info;
51
52 struct gensec_security_ops {
53         const char *name;
54         const char *sasl_name;
55         uint8_t auth_type;  /* 0 if not offered on DCE-RPC */
56         const char *oid;  /* NULL if not offered by SPNEGO */
57         NTSTATUS (*client_start)(struct gensec_security *gensec_security);
58         NTSTATUS (*server_start)(struct gensec_security *gensec_security);
59         NTSTATUS (*update)(struct gensec_security *gensec_security, TALLOC_CTX *out_mem_ctx,
60                            const DATA_BLOB in, DATA_BLOB *out);
61         NTSTATUS (*seal_packet)(struct gensec_security *gensec_security, TALLOC_CTX *sig_mem_ctx,
62                                 uint8_t *data, size_t length, 
63                                 const uint8_t *whole_pdu, size_t pdu_length, 
64                                 DATA_BLOB *sig);
65         NTSTATUS (*sign_packet)(struct gensec_security *gensec_security, TALLOC_CTX *sig_mem_ctx,
66                                 const uint8_t *data, size_t length, 
67                                 const uint8_t *whole_pdu, size_t pdu_length, 
68                                 DATA_BLOB *sig);
69         size_t   (*sig_size)(struct gensec_security *gensec_security);
70         NTSTATUS (*check_packet)(struct gensec_security *gensec_security, TALLOC_CTX *sig_mem_ctx, 
71                                  const uint8_t *data, size_t length, 
72                                  const uint8_t *whole_pdu, size_t pdu_length, 
73                                  const DATA_BLOB *sig);
74         NTSTATUS (*unseal_packet)(struct gensec_security *gensec_security, TALLOC_CTX *sig_mem_ctx,
75                                   uint8_t *data, size_t length, 
76                                   const uint8_t *whole_pdu, size_t pdu_length, 
77                                   DATA_BLOB *sig);
78         NTSTATUS (*wrap)(struct gensec_security *gensec_security, 
79                                   TALLOC_CTX *mem_ctx, 
80                                   const DATA_BLOB *in, 
81                                   DATA_BLOB *out); 
82         NTSTATUS (*unwrap)(struct gensec_security *gensec_security, 
83                                   TALLOC_CTX *mem_ctx, 
84                                   const DATA_BLOB *in, 
85                                   DATA_BLOB *out); 
86         NTSTATUS (*session_key)(struct gensec_security *gensec_security, DATA_BLOB *session_key);
87         NTSTATUS (*session_info)(struct gensec_security *gensec_security, 
88                                  struct auth_session_info **session_info); 
89         BOOL (*have_feature)(struct gensec_security *gensec_security,
90                                     uint32_t feature); 
91         BOOL enabled;
92 };
93         
94 #define GENSEC_INTERFACE_VERSION 0
95
96 struct gensec_security {
97         gensec_password_callback password_callback;
98         void *password_callback_private;
99         const struct gensec_security_ops *ops;
100         void *private_data;
101         struct cli_credentials *credentials;
102         struct gensec_target target;
103         enum gensec_role gensec_role;
104         BOOL subcontext;
105         uint32_t want_features;
106 };
107
108 /* this structure is used by backends to determine the size of some critical types */
109 struct gensec_critical_sizes {
110         int interface_version;
111         int sizeof_gensec_security_ops;
112         int sizeof_gensec_security;
113 };
114
115
116 /* pre-declare schannel structure for schannel backend */       
117 struct schannel_state;