waf: Fix parsing of cross-answers file in case answer includes a colon
[Samba.git] / auth / gensec / gensec.h
blob0d3a29ca831e8a3fbd835426beaf071748be11be
1 /*
2 Unix SMB/CIFS implementation.
4 Generic Authentication Interface
6 Copyright (C) Andrew Tridgell 2003
7 Copyright (C) Andrew Bartlett <abartlet@samba.org> 2004-2005
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.
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.
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/>.
23 #ifndef __GENSEC_H__
24 #define __GENSEC_H__
26 #include "../lib/util/data_blob.h"
27 #include "libcli/util/ntstatus.h"
29 #define GENSEC_SASL_NAME_NTLMSSP "NTLM"
31 #define GENSEC_OID_NTLMSSP "1.3.6.1.4.1.311.2.2.10"
32 #define GENSEC_OID_SPNEGO "1.3.6.1.5.5.2"
33 #define GENSEC_OID_KERBEROS5 "1.2.840.113554.1.2.2"
34 #define GENSEC_OID_KERBEROS5_OLD "1.2.840.48018.1.2.2"
35 #define GENSEC_OID_KERBEROS5_USER2USER "1.2.840.113554.1.2.2.3"
37 enum gensec_priority {
38 GENSEC_SPNEGO = 90,
39 GENSEC_GSSAPI = 80,
40 GENSEC_KRB5 = 70,
41 GENSEC_SCHANNEL = 60,
42 GENSEC_NTLMSSP = 50,
43 GENSEC_SASL = 20,
44 GENSEC_OTHER = 10,
45 GENSEC_EXTERNAL = 0
48 struct gensec_security;
49 struct gensec_target {
50 const char *principal;
51 const char *hostname;
52 const char *service;
55 #define GENSEC_FEATURE_SESSION_KEY 0x00000001
56 #define GENSEC_FEATURE_SIGN 0x00000002
57 #define GENSEC_FEATURE_SEAL 0x00000004
58 #define GENSEC_FEATURE_DCE_STYLE 0x00000008
59 #define GENSEC_FEATURE_ASYNC_REPLIES 0x00000010
60 #define GENSEC_FEATURE_DATAGRAM_MODE 0x00000020
61 #define GENSEC_FEATURE_SIGN_PKT_HEADER 0x00000040
62 #define GENSEC_FEATURE_NEW_SPNEGO 0x00000080
63 #define GENSEC_FEATURE_UNIX_TOKEN 0x00000100
65 #define GENSEC_EXPIRE_TIME_INFINITY (NTTIME)0x8000000000000000LL
67 /* GENSEC mode */
68 enum gensec_role
70 GENSEC_SERVER,
71 GENSEC_CLIENT
74 struct auth_session_info;
75 struct cli_credentials;
76 struct gensec_settings;
77 struct tevent_context;
78 struct tevent_req;
79 struct smb_krb5_context;
80 struct tsocket_address;
82 struct gensec_settings {
83 struct loadparm_context *lp_ctx;
84 const char *target_hostname;
86 /* this allows callers to specify a specific set of ops that
87 * should be used, rather than those loaded by the plugin
88 * mechanism */
89 const struct gensec_security_ops * const *backends;
91 /* To fill in our own name in the NTLMSSP server */
92 const char *server_dns_domain;
93 const char *server_dns_name;
94 const char *server_netbios_domain;
95 const char *server_netbios_name;
98 struct gensec_security_ops;
99 struct gensec_security_ops_wrapper;
101 #define GENSEC_INTERFACE_VERSION 0
103 /* this structure is used by backends to determine the size of some critical types */
104 struct gensec_critical_sizes;
105 const struct gensec_critical_sizes *gensec_interface_version(void);
107 /* Socket wrapper */
109 struct gensec_security;
110 struct socket_context;
111 struct auth4_context;
112 struct auth_user_info_dc;
114 /* These functions are for use here only (public because SPNEGO must
115 * use them for recursion) */
116 NTSTATUS gensec_wrap_packets(struct gensec_security *gensec_security,
117 TALLOC_CTX *mem_ctx,
118 const DATA_BLOB *in,
119 DATA_BLOB *out,
120 size_t *len_processed);
121 /* These functions are for use here only (public because SPNEGO must
122 * use them for recursion) */
123 NTSTATUS gensec_unwrap_packets(struct gensec_security *gensec_security,
124 TALLOC_CTX *mem_ctx,
125 const DATA_BLOB *in,
126 DATA_BLOB *out,
127 size_t *len_processed);
129 /* These functions are for use here only (public because SPNEGO must
130 * use them for recursion) */
131 NTSTATUS gensec_packet_full_request(struct gensec_security *gensec_security,
132 DATA_BLOB blob, size_t *size);
134 struct loadparm_context;
136 NTSTATUS gensec_subcontext_start(TALLOC_CTX *mem_ctx,
137 struct gensec_security *parent,
138 struct gensec_security **gensec_security);
139 NTSTATUS gensec_client_start(TALLOC_CTX *mem_ctx,
140 struct gensec_security **gensec_security,
141 struct gensec_settings *settings);
142 NTSTATUS gensec_start_mech_by_ops(struct gensec_security *gensec_security,
143 const struct gensec_security_ops *ops);
144 NTSTATUS gensec_start_mech_by_sasl_list(struct gensec_security *gensec_security,
145 const char **sasl_names);
146 void gensec_set_max_update_size(struct gensec_security *gensec_security,
147 uint32_t max_update_size);
148 size_t gensec_max_update_size(struct gensec_security *gensec_security);
149 NTSTATUS gensec_update(struct gensec_security *gensec_security,
150 TALLOC_CTX *out_mem_ctx,
151 const DATA_BLOB in, DATA_BLOB *out);
152 NTSTATUS gensec_update_ev(struct gensec_security *gensec_security,
153 TALLOC_CTX *out_mem_ctx,
154 struct tevent_context *ev,
155 const DATA_BLOB in, DATA_BLOB *out);
156 struct tevent_req *gensec_update_send(TALLOC_CTX *mem_ctx,
157 struct tevent_context *ev,
158 struct gensec_security *gensec_security,
159 const DATA_BLOB in);
160 NTSTATUS gensec_update_recv(struct tevent_req *req, TALLOC_CTX *out_mem_ctx, DATA_BLOB *out);
161 void gensec_want_feature(struct gensec_security *gensec_security,
162 uint32_t feature);
163 bool gensec_have_feature(struct gensec_security *gensec_security,
164 uint32_t feature);
165 NTTIME gensec_expire_time(struct gensec_security *gensec_security);
166 NTSTATUS gensec_set_credentials(struct gensec_security *gensec_security, struct cli_credentials *credentials);
167 NTSTATUS gensec_set_target_service(struct gensec_security *gensec_security, const char *service);
168 const char *gensec_get_target_service(struct gensec_security *gensec_security);
169 NTSTATUS gensec_set_target_hostname(struct gensec_security *gensec_security, const char *hostname);
170 const char *gensec_get_target_hostname(struct gensec_security *gensec_security);
171 NTSTATUS gensec_session_key(struct gensec_security *gensec_security,
172 TALLOC_CTX *mem_ctx,
173 DATA_BLOB *session_key);
174 NTSTATUS gensec_start_mech_by_oid(struct gensec_security *gensec_security,
175 const char *mech_oid);
176 const char *gensec_get_name_by_oid(struct gensec_security *gensec_security, const char *oid_string);
177 struct cli_credentials *gensec_get_credentials(struct gensec_security *gensec_security);
178 NTSTATUS gensec_init(void);
179 NTSTATUS gensec_register(const struct gensec_security_ops *ops);
180 const struct gensec_security_ops *gensec_security_by_oid(struct gensec_security *gensec_security,
181 const char *oid_string);
182 const struct gensec_security_ops *gensec_security_by_sasl_name(struct gensec_security *gensec_security,
183 const char *sasl_name);
184 const struct gensec_security_ops *gensec_security_by_auth_type(
185 struct gensec_security *gensec_security,
186 uint32_t auth_type);
187 const struct gensec_security_ops **gensec_security_mechs(struct gensec_security *gensec_security,
188 TALLOC_CTX *mem_ctx);
189 const struct gensec_security_ops_wrapper *gensec_security_by_oid_list(
190 struct gensec_security *gensec_security,
191 TALLOC_CTX *mem_ctx,
192 const char * const *oid_strings,
193 const char *skip);
194 const char **gensec_security_oids(struct gensec_security *gensec_security,
195 TALLOC_CTX *mem_ctx,
196 const char *skip);
197 const char **gensec_security_oids_from_ops_wrapped(TALLOC_CTX *mem_ctx,
198 const struct gensec_security_ops_wrapper *wops);
199 size_t gensec_max_input_size(struct gensec_security *gensec_security);
200 size_t gensec_max_wrapped_size(struct gensec_security *gensec_security);
201 NTSTATUS gensec_unseal_packet(struct gensec_security *gensec_security,
202 uint8_t *data, size_t length,
203 const uint8_t *whole_pdu, size_t pdu_length,
204 const DATA_BLOB *sig);
205 NTSTATUS gensec_check_packet(struct gensec_security *gensec_security,
206 const uint8_t *data, size_t length,
207 const uint8_t *whole_pdu, size_t pdu_length,
208 const DATA_BLOB *sig);
209 size_t gensec_sig_size(struct gensec_security *gensec_security, size_t data_size);
210 NTSTATUS gensec_seal_packet(struct gensec_security *gensec_security,
211 TALLOC_CTX *mem_ctx,
212 uint8_t *data, size_t length,
213 const uint8_t *whole_pdu, size_t pdu_length,
214 DATA_BLOB *sig);
215 NTSTATUS gensec_sign_packet(struct gensec_security *gensec_security,
216 TALLOC_CTX *mem_ctx,
217 const uint8_t *data, size_t length,
218 const uint8_t *whole_pdu, size_t pdu_length,
219 DATA_BLOB *sig);
220 NTSTATUS gensec_start_mech(struct gensec_security *gensec_security);
221 NTSTATUS gensec_start_mech_by_authtype(struct gensec_security *gensec_security,
222 uint8_t auth_type, uint8_t auth_level);
223 const char *gensec_get_name_by_authtype(struct gensec_security *gensec_security, uint8_t authtype);
224 NTSTATUS gensec_server_start(TALLOC_CTX *mem_ctx,
225 struct gensec_settings *settings,
226 struct auth4_context *auth_context,
227 struct gensec_security **gensec_security);
228 NTSTATUS gensec_session_info(struct gensec_security *gensec_security,
229 TALLOC_CTX *mem_ctx,
230 struct auth_session_info **session_info);
232 NTSTATUS gensec_set_local_address(struct gensec_security *gensec_security,
233 const struct tsocket_address *local);
234 NTSTATUS gensec_set_remote_address(struct gensec_security *gensec_security,
235 const struct tsocket_address *remote);
236 const struct tsocket_address *gensec_get_local_address(struct gensec_security *gensec_security);
237 const struct tsocket_address *gensec_get_remote_address(struct gensec_security *gensec_security);
239 NTSTATUS gensec_start_mech_by_name(struct gensec_security *gensec_security,
240 const char *name);
242 NTSTATUS gensec_unwrap(struct gensec_security *gensec_security,
243 TALLOC_CTX *mem_ctx,
244 const DATA_BLOB *in,
245 DATA_BLOB *out);
246 NTSTATUS gensec_wrap(struct gensec_security *gensec_security,
247 TALLOC_CTX *mem_ctx,
248 const DATA_BLOB *in,
249 DATA_BLOB *out);
251 const struct gensec_security_ops * const *gensec_security_all(void);
252 bool gensec_security_ops_enabled(const struct gensec_security_ops *ops, struct gensec_security *security);
253 const struct gensec_security_ops **gensec_use_kerberos_mechs(TALLOC_CTX *mem_ctx,
254 const struct gensec_security_ops * const *old_gensec_list,
255 struct cli_credentials *creds);
257 NTSTATUS gensec_start_mech_by_sasl_name(struct gensec_security *gensec_security,
258 const char *sasl_name);
260 int gensec_setting_int(struct gensec_settings *settings, const char *mechanism, const char *name, int default_value);
261 bool gensec_setting_bool(struct gensec_settings *settings, const char *mechanism, const char *name, bool default_value);
263 NTSTATUS gensec_set_target_principal(struct gensec_security *gensec_security, const char *principal);
264 const char *gensec_get_target_principal(struct gensec_security *gensec_security);
266 NTSTATUS gensec_generate_session_info_pac(TALLOC_CTX *mem_ctx,
267 struct gensec_security *gensec_security,
268 struct smb_krb5_context *smb_krb5_context,
269 DATA_BLOB *pac_blob,
270 const char *principal_string,
271 const struct tsocket_address *remote_address,
272 struct auth_session_info **session_info);
274 NTSTATUS gensec_magic_check_krb5_oid(struct gensec_security *unused,
275 const DATA_BLOB *blob);
277 #endif /* __GENSEC_H__ */