Revert "pidl: Use non-existent function dissect_ndr_int64()"
[Samba.git] / auth / gensec / gensec.h
blob24abacfb2aa1c1a59e49c919710dc91abc5aac8b
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"
28 #include "lib/util/time.h"
30 #define GENSEC_SASL_NAME_NTLMSSP "NTLM"
32 #define GENSEC_OID_NTLMSSP "1.3.6.1.4.1.311.2.2.10"
33 #define GENSEC_OID_SPNEGO "1.3.6.1.5.5.2"
34 #define GENSEC_OID_KERBEROS5 "1.2.840.113554.1.2.2"
35 #define GENSEC_OID_KERBEROS5_OLD "1.2.840.48018.1.2.2"
36 #define GENSEC_OID_KERBEROS5_USER2USER "1.2.840.113554.1.2.2.3"
38 #define GENSEC_FINAL_AUTH_TYPE_KRB5 "krb5"
39 #define GENSEC_FINAL_AUTH_TYPE_NTLMSSP "NTLMSSP"
41 enum gensec_priority {
42 GENSEC_SPNEGO = 90,
43 GENSEC_GSSAPI = 80,
44 GENSEC_KRB5 = 70,
45 GENSEC_SCHANNEL = 60,
46 GENSEC_NTLMSSP = 50,
47 GENSEC_SASL = 20,
48 GENSEC_OTHER = 10,
49 GENSEC_EXTERNAL = 0
52 struct gensec_security;
53 struct gensec_target {
54 const char *principal;
55 const char *hostname;
56 const char *service;
57 const char *service_description;
60 #define GENSEC_FEATURE_SESSION_KEY 0x00000001
61 #define GENSEC_FEATURE_SIGN 0x00000002
62 #define GENSEC_FEATURE_SEAL 0x00000004
63 #define GENSEC_FEATURE_DCE_STYLE 0x00000008
64 #define GENSEC_FEATURE_ASYNC_REPLIES 0x00000010
65 #define GENSEC_FEATURE_DATAGRAM_MODE 0x00000020
66 #define GENSEC_FEATURE_SIGN_PKT_HEADER 0x00000040
67 #define GENSEC_FEATURE_NEW_SPNEGO 0x00000080
68 #define GENSEC_FEATURE_UNIX_TOKEN 0x00000100
69 #define GENSEC_FEATURE_NTLM_CCACHE 0x00000200
70 #define GENSEC_FEATURE_LDAP_STYLE 0x00000400
71 #define GENSEC_FEATURE_NO_AUTHZ_LOG 0x00000800
72 #define GENSEC_FEATURE_SMB_TRANSPORT 0x00001000
73 #define GENSEC_FEATURE_LDAPS_TRANSPORT 0x00002000
74 #define GENSEC_FEATURE_CB_OPTIONAL 0x00004000
76 #define GENSEC_EXPIRE_TIME_INFINITY (NTTIME)0x8000000000000000LL
78 /* GENSEC mode */
79 enum gensec_role
81 GENSEC_SERVER,
82 GENSEC_CLIENT
85 struct auth_session_info;
86 struct cli_credentials;
87 struct gensec_settings;
88 struct tevent_context;
89 struct tevent_req;
90 struct smb_krb5_context;
91 struct tsocket_address;
93 struct gensec_settings {
94 struct loadparm_context *lp_ctx;
95 const char *target_hostname;
97 /* this allows callers to specify a specific set of ops that
98 * should be used, rather than those loaded by the plugin
99 * mechanism */
100 const struct gensec_security_ops * const *backends;
102 /* To fill in our own name in the NTLMSSP server */
103 const char *server_dns_domain;
104 const char *server_dns_name;
105 const char *server_netbios_domain;
106 const char *server_netbios_name;
109 struct gensec_security_ops;
110 struct gensec_security_ops_wrapper;
112 /* Change to 1, loadable modules now take a TALLOC_CTX * init() parameter. */
113 #define GENSEC_INTERFACE_VERSION 1
115 /* this structure is used by backends to determine the size of some critical types */
116 struct gensec_critical_sizes;
117 const struct gensec_critical_sizes *gensec_interface_version(void);
119 /* Socket wrapper */
121 struct gensec_security;
122 struct auth4_context;
123 struct auth_user_info_dc;
125 struct loadparm_context;
127 NTSTATUS gensec_subcontext_start(TALLOC_CTX *mem_ctx,
128 struct gensec_security *parent,
129 struct gensec_security **gensec_security);
130 NTSTATUS gensec_client_start(TALLOC_CTX *mem_ctx,
131 struct gensec_security **gensec_security,
132 struct gensec_settings *settings);
133 NTSTATUS gensec_start_mech_by_ops(struct gensec_security *gensec_security,
134 const struct gensec_security_ops *ops);
135 NTSTATUS gensec_start_mech_by_sasl_list(struct gensec_security *gensec_security,
136 const char **sasl_names);
137 void gensec_set_max_update_size(struct gensec_security *gensec_security,
138 uint32_t max_update_size);
139 size_t gensec_max_update_size(struct gensec_security *gensec_security);
140 NTSTATUS gensec_update(struct gensec_security *gensec_security,
141 TALLOC_CTX *out_mem_ctx,
142 const DATA_BLOB in, DATA_BLOB *out);
143 struct tevent_req *gensec_update_send(TALLOC_CTX *mem_ctx,
144 struct tevent_context *ev,
145 struct gensec_security *gensec_security,
146 const DATA_BLOB in);
147 NTSTATUS gensec_update_recv(struct tevent_req *req, TALLOC_CTX *out_mem_ctx, DATA_BLOB *out);
149 #define GENSEC_UPDATE_IS_NTERROR(status) ( \
150 !NT_STATUS_IS_OK(status) && \
151 !NT_STATUS_EQUAL(status, NT_STATUS_MORE_PROCESSING_REQUIRED) \
155 * @brief Ask for features for a following authentication
157 * Typically only one specific feature bit should be passed,
158 * but it also works to ask for more features.
160 * The features must be requested before starting the
161 * gensec_update*() loop.
163 * The current exception is GENSEC_FEATURE_SIGN_PKT_HEADER,
164 * it can also be requested once the gensec_update*() loop
165 * returned NT_STATUS_OK.
167 * The features should not be changed during the gensec_update*()
168 * loop.
170 * @param[in] gensec_security The context to be used
172 * @param[in] feature The requested feature[s].
175 void gensec_want_feature(struct gensec_security *gensec_security,
176 uint32_t feature);
178 * @brief Ask for one feature after the finished authentication
180 * Because the return value is bool, the caller can only
181 * ask for one feature at a time.
183 * The features must be requested after the finished
184 * gensec_update*() loop.
186 * The current exception is GENSEC_FEATURE_SIGN_PKT_HEADER,
187 * it can also be requested before the gensec_update*() loop,
188 * as the return value only indicates if the backend supports
189 * dcerpc header signing, not if header signing will be used
190 * between client and server. It will be used only if the caller
191 * also used gensec_want_feature(GENSEC_FEATURE_SIGN_PKT_HEADER).
193 * @param[in] gensec_security The context to be used.
195 * @param[in] feature The requested feature.
197 * @return true if the feature is supported, false if not.
199 bool gensec_have_feature(struct gensec_security *gensec_security,
200 uint32_t feature);
201 NTTIME gensec_expire_time(struct gensec_security *gensec_security);
202 NTSTATUS gensec_set_credentials(struct gensec_security *gensec_security, struct cli_credentials *credentials);
204 * Set the target service (such as 'http' or 'host') on a GENSEC context - ensures it is talloc()ed
206 * This is used for Kerberos service principal name resolution.
209 NTSTATUS gensec_set_target_service(struct gensec_security *gensec_security, const char *service);
210 const char *gensec_get_target_service(struct gensec_security *gensec_security);
211 NTSTATUS gensec_set_target_hostname(struct gensec_security *gensec_security, const char *hostname);
212 const char *gensec_get_target_hostname(struct gensec_security *gensec_security);
214 * Set the target service (such as 'samr') on an GENSEC context - ensures it is talloc()ed.
216 * This is not the Kerberos service principal, instead this is a
217 * constant value that can be logged as part of authentication and
218 * authorization logging
220 const char *gensec_get_target_service_description(struct gensec_security *gensec_security);
221 NTSTATUS gensec_set_target_service_description(struct gensec_security *gensec_security,
222 const char *service);
223 NTSTATUS gensec_session_key(struct gensec_security *gensec_security,
224 TALLOC_CTX *mem_ctx,
225 DATA_BLOB *session_key);
226 NTSTATUS gensec_start_mech_by_oid(struct gensec_security *gensec_security,
227 const char *mech_oid);
228 const char *gensec_get_name_by_oid(struct gensec_security *gensec_security, const char *oid_string);
229 struct cli_credentials *gensec_get_credentials(struct gensec_security *gensec_security);
230 NTSTATUS gensec_init(void);
231 NTSTATUS gensec_register(TALLOC_CTX *ctx,
232 const struct gensec_security_ops *ops);
233 const struct gensec_security_ops *gensec_security_by_oid(struct gensec_security *gensec_security,
234 const char *oid_string);
235 const struct gensec_security_ops *gensec_security_by_sasl_name(struct gensec_security *gensec_security,
236 const char *sasl_name);
237 const struct gensec_security_ops *gensec_security_by_auth_type(
238 struct gensec_security *gensec_security,
239 uint32_t auth_type);
240 const struct gensec_security_ops *gensec_security_by_name(struct gensec_security *gensec_security,
241 const char *name);
242 const struct gensec_security_ops **gensec_security_mechs(struct gensec_security *gensec_security,
243 TALLOC_CTX *mem_ctx);
244 const struct gensec_security_ops_wrapper *gensec_security_by_oid_list(
245 struct gensec_security *gensec_security,
246 TALLOC_CTX *mem_ctx,
247 const char * const *oid_strings,
248 const char *skip);
249 const char **gensec_security_oids(struct gensec_security *gensec_security,
250 TALLOC_CTX *mem_ctx,
251 const char *skip);
252 const char **gensec_security_oids_from_ops_wrapped(TALLOC_CTX *mem_ctx,
253 const struct gensec_security_ops_wrapper *wops);
254 size_t gensec_max_input_size(struct gensec_security *gensec_security);
255 size_t gensec_max_wrapped_size(struct gensec_security *gensec_security);
256 NTSTATUS gensec_unseal_packet(struct gensec_security *gensec_security,
257 uint8_t *data, size_t length,
258 const uint8_t *whole_pdu, size_t pdu_length,
259 const DATA_BLOB *sig);
260 NTSTATUS gensec_check_packet(struct gensec_security *gensec_security,
261 const uint8_t *data, size_t length,
262 const uint8_t *whole_pdu, size_t pdu_length,
263 const DATA_BLOB *sig);
264 size_t gensec_sig_size(struct gensec_security *gensec_security, size_t data_size);
265 NTSTATUS gensec_seal_packet(struct gensec_security *gensec_security,
266 TALLOC_CTX *mem_ctx,
267 uint8_t *data, size_t length,
268 const uint8_t *whole_pdu, size_t pdu_length,
269 DATA_BLOB *sig);
270 NTSTATUS gensec_sign_packet(struct gensec_security *gensec_security,
271 TALLOC_CTX *mem_ctx,
272 const uint8_t *data, size_t length,
273 const uint8_t *whole_pdu, size_t pdu_length,
274 DATA_BLOB *sig);
275 NTSTATUS gensec_start_mech_by_authtype(struct gensec_security *gensec_security,
276 uint8_t auth_type, uint8_t auth_level);
277 const char *gensec_get_name_by_authtype(struct gensec_security *gensec_security, uint8_t authtype);
278 NTSTATUS gensec_server_start(TALLOC_CTX *mem_ctx,
279 struct gensec_settings *settings,
280 struct auth4_context *auth_context,
281 struct gensec_security **gensec_security);
282 NTSTATUS gensec_session_info(struct gensec_security *gensec_security,
283 TALLOC_CTX *mem_ctx,
284 struct auth_session_info **session_info);
286 NTSTATUS gensec_set_local_address(struct gensec_security *gensec_security,
287 const struct tsocket_address *local);
288 NTSTATUS gensec_set_remote_address(struct gensec_security *gensec_security,
289 const struct tsocket_address *remote);
290 const struct tsocket_address *gensec_get_local_address(struct gensec_security *gensec_security);
291 const struct tsocket_address *gensec_get_remote_address(struct gensec_security *gensec_security);
293 NTSTATUS gensec_start_mech_by_name(struct gensec_security *gensec_security,
294 const char *name);
296 NTSTATUS gensec_unwrap(struct gensec_security *gensec_security,
297 TALLOC_CTX *mem_ctx,
298 const DATA_BLOB *in,
299 DATA_BLOB *out);
300 NTSTATUS gensec_wrap(struct gensec_security *gensec_security,
301 TALLOC_CTX *mem_ctx,
302 const DATA_BLOB *in,
303 DATA_BLOB *out);
305 NTSTATUS gensec_start_mech_by_sasl_name(struct gensec_security *gensec_security,
306 const char *sasl_name);
307 const char **gensec_security_sasl_names(struct gensec_security *gensec_security,
308 TALLOC_CTX *mem_ctx);
310 int gensec_setting_int(struct gensec_settings *settings, const char *mechanism, const char *name, int default_value);
311 bool gensec_setting_bool(struct gensec_settings *settings, const char *mechanism, const char *name, bool default_value);
313 NTSTATUS gensec_set_target_principal(struct gensec_security *gensec_security, const char *principal);
314 const char *gensec_get_target_principal(struct gensec_security *gensec_security);
316 NTSTATUS gensec_set_channel_bindings(struct gensec_security *gensec_security,
317 uint32_t initiator_addrtype,
318 const DATA_BLOB *initiator_address,
319 uint32_t acceptor_addrtype,
320 const DATA_BLOB *acceptor_address,
321 const DATA_BLOB *application_data);
323 NTSTATUS gensec_generate_session_info_pac(TALLOC_CTX *mem_ctx,
324 struct gensec_security *gensec_security,
325 struct smb_krb5_context *smb_krb5_context,
326 DATA_BLOB *pac_blob,
327 const char *principal_string,
328 const struct tsocket_address *remote_address,
329 struct auth_session_info **session_info);
331 NTSTATUS gensec_magic_check_krb5_oid(struct gensec_security *unused,
332 const DATA_BLOB *blob);
334 #endif /* __GENSEC_H__ */