624c7ebe1d9cc3f4280ecbb7e2375420c555db1f
[samba.git] / source4 / libcli / auth / 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
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
25 struct gensec_security;
26 struct gensec_user {
27         const char *domain;
28         const char *realm;
29         const char *name;
30         const char *password;
31         char schan_session_key[16];
32 };
33 struct gensec_target {
34         const char *principal;
35         const char *hostname;
36         const struct sock_addr *addr;
37         const char *service;
38 };
39
40 #define GENSEC_WANT_SESSION_KEY 0x1
41 #define GENSEC_WANT_SIGN 0x2
42 #define GENSEC_WANT_SEAL 0x4
43
44 /* GENSEC mode */
45 enum gensec_role
46 {
47         GENSEC_SERVER,
48         GENSEC_CLIENT
49 };
50
51 struct auth_session_info;
52
53 struct gensec_security_ops {
54         const char *name;
55         const char *sasl_name;
56         uint8 auth_type;  /* 0 if not offered on DCE-RPC */
57         const char *oid;  /* NULL if not offered by SPENGO */
58         NTSTATUS (*client_start)(struct gensec_security *gensec_security);
59         NTSTATUS (*server_start)(struct gensec_security *gensec_security);
60         NTSTATUS (*update)(struct gensec_security *gensec_security, TALLOC_CTX *out_mem_ctx,
61                            const DATA_BLOB in, DATA_BLOB *out);
62         NTSTATUS (*seal_packet)(struct gensec_security *gensec_security, TALLOC_CTX *sig_mem_ctx,
63                                 uint8_t *data, size_t length, 
64                                 const uint8_t *whole_pdu, size_t pdu_length, 
65                                 DATA_BLOB *sig);
66         NTSTATUS (*sign_packet)(struct gensec_security *gensec_security, TALLOC_CTX *sig_mem_ctx,
67                                 const uint8_t *data, size_t length, 
68                                 const uint8_t *whole_pdu, size_t pdu_length, 
69                                 DATA_BLOB *sig);
70         size_t   (*sig_size)(struct gensec_security *gensec_security);
71         NTSTATUS (*check_packet)(struct gensec_security *gensec_security, TALLOC_CTX *sig_mem_ctx, 
72                                  const uint8_t *data, size_t length, 
73                                  const uint8_t *whole_pdu, size_t pdu_length, 
74                                  const DATA_BLOB *sig);
75         NTSTATUS (*unseal_packet)(struct gensec_security *gensec_security, TALLOC_CTX *sig_mem_ctx,
76                                   uint8_t *data, size_t length, 
77                                   const uint8_t *whole_pdu, size_t pdu_length, 
78                                   DATA_BLOB *sig);
79         NTSTATUS (*session_key)(struct gensec_security *gensec_security, DATA_BLOB *session_key);
80         NTSTATUS (*session_info)(struct gensec_security *gensec_security, 
81                                  struct auth_session_info **session_info); 
82         void (*end)(struct gensec_security *gensec_security);
83 };
84         
85 typedef NTSTATUS (*gensec_password_callback)(struct gensec_security *gensec_security, TALLOC_CTX *mem_ctx, 
86                                              char **password);
87
88 #define GENSEC_INTERFACE_VERSION 0
89
90 struct gensec_security {
91         gensec_password_callback password_callback;
92         void *password_callback_private;
93         const struct gensec_security_ops *ops;
94         void *private_data;
95         struct gensec_user user;
96         struct gensec_user default_user;
97         struct gensec_target target;
98         enum gensec_role gensec_role;
99         BOOL subcontext;
100         uint32 want_features;
101 };
102
103 /* this structure is used by backends to determine the size of some critical types */
104 struct gensec_critical_sizes {
105         int interface_version;
106         int sizeof_gensec_security_ops;
107         int sizeof_gensec_security;
108 };
109
110
111 /* pre-declare schannel structure for schannel backend */       
112 struct schannel_state;