c04164a3dbd0c40c49895a66eb6622eae0032c94
[nivanova/samba-autobuild/.git] / auth / gensec / gensec_internal.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_INTERNAL_H__
24 #define __GENSEC_INTERNAL_H__
25
26 struct gensec_security;
27
28 struct gensec_security_ops {
29         const char *name;
30         const char *sasl_name;
31         uint8_t auth_type;  /* 0 if not offered on DCE-RPC */
32         const char **oid;  /* NULL if not offered by SPNEGO */
33         NTSTATUS (*client_start)(struct gensec_security *gensec_security);
34         NTSTATUS (*server_start)(struct gensec_security *gensec_security);
35         /**
36            Determine if a packet has the right 'magic' for this mechanism
37         */
38         NTSTATUS (*magic)(struct gensec_security *gensec_security,
39                           const DATA_BLOB *first_packet);
40         NTSTATUS (*update)(struct gensec_security *gensec_security, TALLOC_CTX *out_mem_ctx,
41                            struct tevent_context *ev,
42                            const DATA_BLOB in, DATA_BLOB *out);
43         struct tevent_req *(*update_send)(TALLOC_CTX *mem_ctx,
44                                           struct tevent_context *ev,
45                                           struct gensec_security *gensec_security,
46                                           const DATA_BLOB in);
47         NTSTATUS (*update_recv)(struct tevent_req *req,
48                                 TALLOC_CTX *out_mem_ctx,
49                                 DATA_BLOB *out);
50         NTSTATUS (*seal_packet)(struct gensec_security *gensec_security, TALLOC_CTX *sig_mem_ctx,
51                                 uint8_t *data, size_t length,
52                                 const uint8_t *whole_pdu, size_t pdu_length,
53                                 DATA_BLOB *sig);
54         NTSTATUS (*sign_packet)(struct gensec_security *gensec_security, TALLOC_CTX *sig_mem_ctx,
55                                 const uint8_t *data, size_t length,
56                                 const uint8_t *whole_pdu, size_t pdu_length,
57                                 DATA_BLOB *sig);
58         size_t   (*sig_size)(struct gensec_security *gensec_security, size_t data_size);
59         size_t   (*max_input_size)(struct gensec_security *gensec_security);
60         size_t   (*max_wrapped_size)(struct gensec_security *gensec_security);
61         NTSTATUS (*check_packet)(struct gensec_security *gensec_security,
62                                  const uint8_t *data, size_t length,
63                                  const uint8_t *whole_pdu, size_t pdu_length,
64                                  const DATA_BLOB *sig);
65         NTSTATUS (*unseal_packet)(struct gensec_security *gensec_security,
66                                   uint8_t *data, size_t length,
67                                   const uint8_t *whole_pdu, size_t pdu_length,
68                                   const DATA_BLOB *sig);
69         NTSTATUS (*wrap)(struct gensec_security *gensec_security,
70                                   TALLOC_CTX *mem_ctx,
71                                   const DATA_BLOB *in,
72                                   DATA_BLOB *out);
73         NTSTATUS (*unwrap)(struct gensec_security *gensec_security,
74                            TALLOC_CTX *mem_ctx,
75                            const DATA_BLOB *in,
76                            DATA_BLOB *out);
77         NTSTATUS (*wrap_packets)(struct gensec_security *gensec_security,
78                                  TALLOC_CTX *mem_ctx,
79                                  const DATA_BLOB *in,
80                                  DATA_BLOB *out,
81                                  size_t *len_processed);
82         NTSTATUS (*unwrap_packets)(struct gensec_security *gensec_security,
83                                    TALLOC_CTX *mem_ctx,
84                                    const DATA_BLOB *in,
85                                    DATA_BLOB *out,
86                                    size_t *len_processed);
87         NTSTATUS (*packet_full_request)(struct gensec_security *gensec_security,
88                                         DATA_BLOB blob, size_t *size);
89         NTSTATUS (*session_key)(struct gensec_security *gensec_security, TALLOC_CTX *mem_ctx,
90                                 DATA_BLOB *session_key);
91         NTSTATUS (*session_info)(struct gensec_security *gensec_security, TALLOC_CTX *mem_ctx,
92                                  struct auth_session_info **session_info);
93         void (*want_feature)(struct gensec_security *gensec_security,
94                                     uint32_t feature);
95         bool (*have_feature)(struct gensec_security *gensec_security,
96                                     uint32_t feature);
97         NTTIME (*expire_time)(struct gensec_security *gensec_security);
98         bool enabled;
99         bool kerberos;
100         enum gensec_priority priority;
101 };
102
103 struct gensec_security_ops_wrapper {
104         const struct gensec_security_ops *op;
105         const char *oid;
106 };
107
108 struct gensec_security {
109         const struct gensec_security_ops *ops;
110         void *private_data;
111         struct cli_credentials *credentials;
112         struct gensec_target target;
113         enum gensec_role gensec_role;
114         bool subcontext;
115         uint32_t want_features;
116         uint32_t max_update_size;
117         uint8_t dcerpc_auth_level;
118         struct tsocket_address *local_addr, *remote_addr;
119         struct gensec_settings *settings;
120
121         /* When we are a server, this may be filled in to provide an
122          * NTLM authentication backend, and user lookup (such as if no
123          * PAC is found) */
124         struct auth4_context *auth_context;
125 };
126
127 /* this structure is used by backends to determine the size of some critical types */
128 struct gensec_critical_sizes {
129         int interface_version;
130         int sizeof_gensec_security_ops;
131         int sizeof_gensec_security;
132 };
133
134 #endif /* __GENSEC_H__ */