2 Unix SMB/CIFS implementation.
4 Generic Authentication Interface
6 Copyright (C) Andrew Tridgell 2003
7 Copyright (C) Andrew Bartlett <abartlet@samba.org> 2004-2006
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/>.
24 #include "auth/gensec/gensec.h"
25 #include "auth/gensec/gensec_internal.h"
26 #include "auth/common_auth.h"
27 #include "../lib/util/asn1.h"
30 #define DBGC_CLASS DBGC_AUTH
32 NTSTATUS
gensec_generate_session_info_pac(TALLOC_CTX
*mem_ctx
,
33 struct gensec_security
*gensec_security
,
34 struct smb_krb5_context
*smb_krb5_context
,
36 const char *principal_string
,
37 const struct tsocket_address
*remote_address
,
38 struct auth_session_info
**session_info
)
40 uint32_t session_info_flags
= 0;
42 if (gensec_security
->want_features
& GENSEC_FEATURE_UNIX_TOKEN
) {
43 session_info_flags
|= AUTH_SESSION_INFO_UNIX_TOKEN
;
46 session_info_flags
|= AUTH_SESSION_INFO_DEFAULT_GROUPS
;
49 if (gensec_setting_bool(gensec_security
->settings
, "gensec", "require_pac", false)) {
50 DEBUG(1, ("Unable to find PAC in ticket from %s, failing to allow access\n",
52 return NT_STATUS_ACCESS_DENIED
;
54 DBG_NOTICE("Unable to find PAC for %s, resorting to local "
55 "user lookup\n", principal_string
);
58 if (gensec_security
->auth_context
&& gensec_security
->auth_context
->generate_session_info_pac
) {
59 return gensec_security
->auth_context
->generate_session_info_pac(gensec_security
->auth_context
,
68 DEBUG(0, ("Cannot generate a session_info without the auth_context\n"));
69 return NT_STATUS_INTERNAL_ERROR
;
74 magic check a GSS-API wrapper packet for an Kerberos OID
76 static bool gensec_gssapi_check_oid(const DATA_BLOB
*blob
, const char *oid
)
79 struct asn1_data
*data
= asn1_init(NULL
, ASN1_MAX_TREE_DEPTH
);
81 if (!data
) return false;
83 if (!asn1_load(data
, *blob
)) goto err
;
84 if (!asn1_start_tag(data
, ASN1_APPLICATION(0))) goto err
;
85 if (!asn1_check_OID(data
, oid
)) goto err
;
87 ret
= !asn1_has_error(data
);
96 * Check if the packet is one for the KRB5 mechansim
98 * NOTE: This is a helper that can be employed by multiple mechanisms, do
99 * not make assumptions about the private_data
101 * @param gensec_security GENSEC state, unused
102 * @param in The request, as a DATA_BLOB
103 * @return Error, INVALID_PARAMETER if it's not a packet for us
104 * or NT_STATUS_OK if the packet is ok.
107 NTSTATUS
gensec_magic_check_krb5_oid(struct gensec_security
*unused
,
108 const DATA_BLOB
*blob
)
110 if (gensec_gssapi_check_oid(blob
, GENSEC_OID_KERBEROS5
)) {
113 return NT_STATUS_INVALID_PARAMETER
;
117 void gensec_child_want_feature(struct gensec_security
*gensec_security
,
120 struct gensec_security
*child_security
= gensec_security
->child_security
;
122 gensec_security
->want_features
|= feature
;
123 if (child_security
== NULL
) {
126 gensec_want_feature(child_security
, feature
);
129 bool gensec_child_have_feature(struct gensec_security
*gensec_security
,
132 struct gensec_security
*child_security
= gensec_security
->child_security
;
134 if (feature
& GENSEC_FEATURE_SIGN_PKT_HEADER
) {
136 * All mechs with sub (child) mechs need to provide DCERPC
137 * header signing! This is required because the negotiation
138 * of header signing is done before the authentication
144 if (child_security
== NULL
) {
148 return gensec_have_feature(child_security
, feature
);
151 NTSTATUS
gensec_child_unseal_packet(struct gensec_security
*gensec_security
,
152 uint8_t *data
, size_t length
,
153 const uint8_t *whole_pdu
, size_t pdu_length
,
154 const DATA_BLOB
*sig
)
156 if (gensec_security
->child_security
== NULL
) {
157 return NT_STATUS_INVALID_PARAMETER
;
160 return gensec_unseal_packet(gensec_security
->child_security
,
162 whole_pdu
, pdu_length
,
166 NTSTATUS
gensec_child_check_packet(struct gensec_security
*gensec_security
,
167 const uint8_t *data
, size_t length
,
168 const uint8_t *whole_pdu
, size_t pdu_length
,
169 const DATA_BLOB
*sig
)
171 if (gensec_security
->child_security
== NULL
) {
172 return NT_STATUS_INVALID_PARAMETER
;
175 return gensec_check_packet(gensec_security
->child_security
,
177 whole_pdu
, pdu_length
,
181 NTSTATUS
gensec_child_seal_packet(struct gensec_security
*gensec_security
,
183 uint8_t *data
, size_t length
,
184 const uint8_t *whole_pdu
, size_t pdu_length
,
187 if (gensec_security
->child_security
== NULL
) {
188 return NT_STATUS_INVALID_PARAMETER
;
191 return gensec_seal_packet(gensec_security
->child_security
,
194 whole_pdu
, pdu_length
,
198 NTSTATUS
gensec_child_sign_packet(struct gensec_security
*gensec_security
,
200 const uint8_t *data
, size_t length
,
201 const uint8_t *whole_pdu
, size_t pdu_length
,
204 if (gensec_security
->child_security
== NULL
) {
205 return NT_STATUS_INVALID_PARAMETER
;
208 return gensec_sign_packet(gensec_security
->child_security
,
211 whole_pdu
, pdu_length
,
215 NTSTATUS
gensec_child_wrap(struct gensec_security
*gensec_security
,
220 if (gensec_security
->child_security
== NULL
) {
221 return NT_STATUS_INVALID_PARAMETER
;
224 return gensec_wrap(gensec_security
->child_security
,
228 NTSTATUS
gensec_child_unwrap(struct gensec_security
*gensec_security
,
233 if (gensec_security
->child_security
== NULL
) {
234 return NT_STATUS_INVALID_PARAMETER
;
237 return gensec_unwrap(gensec_security
->child_security
,
241 size_t gensec_child_sig_size(struct gensec_security
*gensec_security
,
244 if (gensec_security
->child_security
== NULL
) {
248 return gensec_sig_size(gensec_security
->child_security
, data_size
);
251 size_t gensec_child_max_input_size(struct gensec_security
*gensec_security
)
253 if (gensec_security
->child_security
== NULL
) {
257 return gensec_max_input_size(gensec_security
->child_security
);
260 size_t gensec_child_max_wrapped_size(struct gensec_security
*gensec_security
)
262 if (gensec_security
->child_security
== NULL
) {
266 return gensec_max_wrapped_size(gensec_security
->child_security
);
269 NTSTATUS
gensec_child_session_key(struct gensec_security
*gensec_security
,
271 DATA_BLOB
*session_key
)
273 if (gensec_security
->child_security
== NULL
) {
274 return NT_STATUS_INVALID_PARAMETER
;
277 return gensec_session_key(gensec_security
->child_security
,
282 NTSTATUS
gensec_child_session_info(struct gensec_security
*gensec_security
,
284 struct auth_session_info
**session_info
)
286 if (gensec_security
->child_security
== NULL
) {
287 return NT_STATUS_INVALID_PARAMETER
;
290 return gensec_session_info(gensec_security
->child_security
,
295 NTTIME
gensec_child_expire_time(struct gensec_security
*gensec_security
)
297 if (gensec_security
->child_security
== NULL
) {
298 return GENSEC_EXPIRE_TIME_INFINITY
;
301 return gensec_expire_time(gensec_security
->child_security
);
304 const char *gensec_child_final_auth_type(struct gensec_security
*gensec_security
)
306 if (gensec_security
->child_security
== NULL
) {
310 return gensec_final_auth_type(gensec_security
->child_security
);