s4-provision: set 'dcerpc endpoint servers' but not 'vfs objects'
[Samba/gebeck_regimport.git] / auth / gensec / gensec.h
blob0b0689fbcefae4b31aafae34410ba2e1f0c2f82f
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 = 0
47 struct gensec_security;
48 struct gensec_target {
49 const char *principal;
50 const char *hostname;
51 const char *service;
54 #define GENSEC_FEATURE_SESSION_KEY 0x00000001
55 #define GENSEC_FEATURE_SIGN 0x00000002
56 #define GENSEC_FEATURE_SEAL 0x00000004
57 #define GENSEC_FEATURE_DCE_STYLE 0x00000008
58 #define GENSEC_FEATURE_ASYNC_REPLIES 0x00000010
59 #define GENSEC_FEATURE_DATAGRAM_MODE 0x00000020
60 #define GENSEC_FEATURE_SIGN_PKT_HEADER 0x00000040
61 #define GENSEC_FEATURE_NEW_SPNEGO 0x00000080
62 #define GENSEC_FEATURE_UNIX_TOKEN 0x00000100
64 /* GENSEC mode */
65 enum gensec_role
67 GENSEC_SERVER,
68 GENSEC_CLIENT
71 struct auth_session_info;
72 struct cli_credentials;
73 struct gensec_settings;
74 struct tevent_context;
75 struct tevent_req;
76 struct smb_krb5_context;
78 struct gensec_settings {
79 struct loadparm_context *lp_ctx;
80 const char *target_hostname;
82 /* this allows callers to specify a specific set of ops that
83 * should be used, rather than those loaded by the plugin
84 * mechanism */
85 struct gensec_security_ops **backends;
87 /* To fill in our own name in the NTLMSSP server */
88 const char *server_dns_domain;
89 const char *server_dns_name;
90 const char *server_netbios_domain;
91 const char *server_netbios_name;
94 struct gensec_security_ops {
95 const char *name;
96 const char *sasl_name;
97 uint8_t auth_type; /* 0 if not offered on DCE-RPC */
98 const char **oid; /* NULL if not offered by SPNEGO */
99 NTSTATUS (*client_start)(struct gensec_security *gensec_security);
100 NTSTATUS (*server_start)(struct gensec_security *gensec_security);
102 Determine if a packet has the right 'magic' for this mechanism
104 NTSTATUS (*magic)(struct gensec_security *gensec_security,
105 const DATA_BLOB *first_packet);
106 NTSTATUS (*update)(struct gensec_security *gensec_security, TALLOC_CTX *out_mem_ctx,
107 struct tevent_context *ev,
108 const DATA_BLOB in, DATA_BLOB *out);
109 NTSTATUS (*seal_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 DATA_BLOB *sig);
113 NTSTATUS (*sign_packet)(struct gensec_security *gensec_security, TALLOC_CTX *sig_mem_ctx,
114 const uint8_t *data, size_t length,
115 const uint8_t *whole_pdu, size_t pdu_length,
116 DATA_BLOB *sig);
117 size_t (*sig_size)(struct gensec_security *gensec_security, size_t data_size);
118 size_t (*max_input_size)(struct gensec_security *gensec_security);
119 size_t (*max_wrapped_size)(struct gensec_security *gensec_security);
120 NTSTATUS (*check_packet)(struct gensec_security *gensec_security,
121 const uint8_t *data, size_t length,
122 const uint8_t *whole_pdu, size_t pdu_length,
123 const DATA_BLOB *sig);
124 NTSTATUS (*unseal_packet)(struct gensec_security *gensec_security,
125 uint8_t *data, size_t length,
126 const uint8_t *whole_pdu, size_t pdu_length,
127 const DATA_BLOB *sig);
128 NTSTATUS (*wrap)(struct gensec_security *gensec_security,
129 TALLOC_CTX *mem_ctx,
130 const DATA_BLOB *in,
131 DATA_BLOB *out);
132 NTSTATUS (*unwrap)(struct gensec_security *gensec_security,
133 TALLOC_CTX *mem_ctx,
134 const DATA_BLOB *in,
135 DATA_BLOB *out);
136 NTSTATUS (*wrap_packets)(struct gensec_security *gensec_security,
137 TALLOC_CTX *mem_ctx,
138 const DATA_BLOB *in,
139 DATA_BLOB *out,
140 size_t *len_processed);
141 NTSTATUS (*unwrap_packets)(struct gensec_security *gensec_security,
142 TALLOC_CTX *mem_ctx,
143 const DATA_BLOB *in,
144 DATA_BLOB *out,
145 size_t *len_processed);
146 NTSTATUS (*packet_full_request)(struct gensec_security *gensec_security,
147 DATA_BLOB blob, size_t *size);
148 NTSTATUS (*session_key)(struct gensec_security *gensec_security, TALLOC_CTX *mem_ctx,
149 DATA_BLOB *session_key);
150 NTSTATUS (*session_info)(struct gensec_security *gensec_security, TALLOC_CTX *mem_ctx,
151 struct auth_session_info **session_info);
152 void (*want_feature)(struct gensec_security *gensec_security,
153 uint32_t feature);
154 bool (*have_feature)(struct gensec_security *gensec_security,
155 uint32_t feature);
156 bool enabled;
157 bool kerberos;
158 enum gensec_priority priority;
161 struct gensec_security_ops_wrapper {
162 const struct gensec_security_ops *op;
163 const char *oid;
166 #define GENSEC_INTERFACE_VERSION 0
168 struct gensec_security {
169 const struct gensec_security_ops *ops;
170 void *private_data;
171 struct cli_credentials *credentials;
172 struct gensec_target target;
173 enum gensec_role gensec_role;
174 bool subcontext;
175 uint32_t want_features;
176 uint32_t max_update_size;
177 uint8_t dcerpc_auth_level;
178 struct tsocket_address *local_addr, *remote_addr;
179 struct gensec_settings *settings;
181 /* When we are a server, this may be filled in to provide an
182 * NTLM authentication backend, and user lookup (such as if no
183 * PAC is found) */
184 struct auth4_context *auth_context;
187 /* this structure is used by backends to determine the size of some critical types */
188 struct gensec_critical_sizes {
189 int interface_version;
190 int sizeof_gensec_security_ops;
191 int sizeof_gensec_security;
194 /* Socket wrapper */
196 struct gensec_security;
197 struct socket_context;
198 struct auth4_context;
199 struct auth_user_info_dc;
201 /* These functions are for use here only (public because SPNEGO must
202 * use them for recursion) */
203 NTSTATUS gensec_wrap_packets(struct gensec_security *gensec_security,
204 TALLOC_CTX *mem_ctx,
205 const DATA_BLOB *in,
206 DATA_BLOB *out,
207 size_t *len_processed);
208 /* These functions are for use here only (public because SPNEGO must
209 * use them for recursion) */
210 NTSTATUS gensec_unwrap_packets(struct gensec_security *gensec_security,
211 TALLOC_CTX *mem_ctx,
212 const DATA_BLOB *in,
213 DATA_BLOB *out,
214 size_t *len_processed);
216 /* These functions are for use here only (public because SPNEGO must
217 * use them for recursion) */
218 NTSTATUS gensec_packet_full_request(struct gensec_security *gensec_security,
219 DATA_BLOB blob, size_t *size);
221 struct loadparm_context;
223 NTSTATUS gensec_subcontext_start(TALLOC_CTX *mem_ctx,
224 struct gensec_security *parent,
225 struct gensec_security **gensec_security);
226 NTSTATUS gensec_client_start(TALLOC_CTX *mem_ctx,
227 struct gensec_security **gensec_security,
228 struct gensec_settings *settings);
229 NTSTATUS gensec_start_mech_by_ops(struct gensec_security *gensec_security,
230 const struct gensec_security_ops *ops);
231 NTSTATUS gensec_start_mech_by_sasl_list(struct gensec_security *gensec_security,
232 const char **sasl_names);
233 void gensec_set_max_update_size(struct gensec_security *gensec_security,
234 uint32_t max_update_size);
235 size_t gensec_max_update_size(struct gensec_security *gensec_security);
236 NTSTATUS gensec_update(struct gensec_security *gensec_security, TALLOC_CTX *out_mem_ctx,
237 struct tevent_context *ev,
238 const DATA_BLOB in, DATA_BLOB *out);
239 struct tevent_req *gensec_update_send(TALLOC_CTX *mem_ctx,
240 struct tevent_context *ev,
241 struct gensec_security *gensec_security,
242 const DATA_BLOB in);
243 NTSTATUS gensec_update_recv(struct tevent_req *req, TALLOC_CTX *out_mem_ctx, DATA_BLOB *out);
244 void gensec_want_feature(struct gensec_security *gensec_security,
245 uint32_t feature);
246 bool gensec_have_feature(struct gensec_security *gensec_security,
247 uint32_t feature);
248 NTSTATUS gensec_set_credentials(struct gensec_security *gensec_security, struct cli_credentials *credentials);
249 NTSTATUS gensec_set_target_service(struct gensec_security *gensec_security, const char *service);
250 const char *gensec_get_target_service(struct gensec_security *gensec_security);
251 NTSTATUS gensec_set_target_hostname(struct gensec_security *gensec_security, const char *hostname);
252 const char *gensec_get_target_hostname(struct gensec_security *gensec_security);
253 NTSTATUS gensec_session_key(struct gensec_security *gensec_security,
254 TALLOC_CTX *mem_ctx,
255 DATA_BLOB *session_key);
256 NTSTATUS gensec_start_mech_by_oid(struct gensec_security *gensec_security,
257 const char *mech_oid);
258 const char *gensec_get_name_by_oid(struct gensec_security *gensec_security, const char *oid_string);
259 struct cli_credentials *gensec_get_credentials(struct gensec_security *gensec_security);
260 NTSTATUS gensec_init(void);
261 NTSTATUS gensec_register(const struct gensec_security_ops *ops);
262 const struct gensec_security_ops *gensec_security_by_oid(struct gensec_security *gensec_security,
263 const char *oid_string);
264 const struct gensec_security_ops *gensec_security_by_sasl_name(struct gensec_security *gensec_security,
265 const char *sasl_name);
266 struct gensec_security_ops **gensec_security_mechs(struct gensec_security *gensec_security,
267 TALLOC_CTX *mem_ctx);
268 const struct gensec_security_ops_wrapper *gensec_security_by_oid_list(
269 struct gensec_security *gensec_security,
270 TALLOC_CTX *mem_ctx,
271 const char **oid_strings,
272 const char *skip);
273 const char **gensec_security_oids(struct gensec_security *gensec_security,
274 TALLOC_CTX *mem_ctx,
275 const char *skip);
276 const char **gensec_security_oids_from_ops_wrapped(TALLOC_CTX *mem_ctx,
277 const struct gensec_security_ops_wrapper *wops);
278 size_t gensec_max_input_size(struct gensec_security *gensec_security);
279 size_t gensec_max_wrapped_size(struct gensec_security *gensec_security);
280 NTSTATUS gensec_unseal_packet(struct gensec_security *gensec_security,
281 uint8_t *data, size_t length,
282 const uint8_t *whole_pdu, size_t pdu_length,
283 const DATA_BLOB *sig);
284 NTSTATUS gensec_check_packet(struct gensec_security *gensec_security,
285 const uint8_t *data, size_t length,
286 const uint8_t *whole_pdu, size_t pdu_length,
287 const DATA_BLOB *sig);
288 size_t gensec_sig_size(struct gensec_security *gensec_security, size_t data_size);
289 NTSTATUS gensec_seal_packet(struct gensec_security *gensec_security,
290 TALLOC_CTX *mem_ctx,
291 uint8_t *data, size_t length,
292 const uint8_t *whole_pdu, size_t pdu_length,
293 DATA_BLOB *sig);
294 NTSTATUS gensec_sign_packet(struct gensec_security *gensec_security,
295 TALLOC_CTX *mem_ctx,
296 const uint8_t *data, size_t length,
297 const uint8_t *whole_pdu, size_t pdu_length,
298 DATA_BLOB *sig);
299 NTSTATUS gensec_start_mech(struct gensec_security *gensec_security);
300 NTSTATUS gensec_start_mech_by_authtype(struct gensec_security *gensec_security,
301 uint8_t auth_type, uint8_t auth_level);
302 const char *gensec_get_name_by_authtype(struct gensec_security *gensec_security, uint8_t authtype);
303 NTSTATUS gensec_server_start(TALLOC_CTX *mem_ctx,
304 struct gensec_settings *settings,
305 struct auth4_context *auth_context,
306 struct gensec_security **gensec_security);
307 NTSTATUS gensec_session_info(struct gensec_security *gensec_security,
308 TALLOC_CTX *mem_ctx,
309 struct auth_session_info **session_info);
311 NTSTATUS gensec_set_local_address(struct gensec_security *gensec_security,
312 const struct tsocket_address *local);
313 NTSTATUS gensec_set_remote_address(struct gensec_security *gensec_security,
314 const struct tsocket_address *remote);
315 const struct tsocket_address *gensec_get_local_address(struct gensec_security *gensec_security);
316 const struct tsocket_address *gensec_get_remote_address(struct gensec_security *gensec_security);
318 NTSTATUS gensec_start_mech_by_name(struct gensec_security *gensec_security,
319 const char *name);
321 NTSTATUS gensec_unwrap(struct gensec_security *gensec_security,
322 TALLOC_CTX *mem_ctx,
323 const DATA_BLOB *in,
324 DATA_BLOB *out);
325 NTSTATUS gensec_wrap(struct gensec_security *gensec_security,
326 TALLOC_CTX *mem_ctx,
327 const DATA_BLOB *in,
328 DATA_BLOB *out);
330 struct gensec_security_ops **gensec_security_all(void);
331 bool gensec_security_ops_enabled(struct gensec_security_ops *ops, struct gensec_security *security);
332 struct gensec_security_ops **gensec_use_kerberos_mechs(TALLOC_CTX *mem_ctx,
333 struct gensec_security_ops **old_gensec_list,
334 struct cli_credentials *creds);
336 NTSTATUS gensec_start_mech_by_sasl_name(struct gensec_security *gensec_security,
337 const char *sasl_name);
339 int gensec_setting_int(struct gensec_settings *settings, const char *mechanism, const char *name, int default_value);
340 bool gensec_setting_bool(struct gensec_settings *settings, const char *mechanism, const char *name, bool default_value);
342 NTSTATUS gensec_set_target_principal(struct gensec_security *gensec_security, const char *principal);
343 const char *gensec_get_target_principal(struct gensec_security *gensec_security);
345 NTSTATUS gensec_generate_session_info_pac(TALLOC_CTX *mem_ctx,
346 struct gensec_security *gensec_security,
347 struct smb_krb5_context *smb_krb5_context,
348 DATA_BLOB *pac_blob,
349 const char *principal_string,
350 const struct tsocket_address *remote_address,
351 struct auth_session_info **session_info);
353 NTSTATUS gensec_magic_check_krb5_oid(struct gensec_security *unused,
354 const DATA_BLOB *blob);
356 #endif /* __GENSEC_H__ */