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 "system/network.h"
25 #define TEVENT_DEPRECATED 1
27 #include "lib/tsocket/tsocket.h"
28 #include "lib/util/tevent_ntstatus.h"
29 #include "auth/gensec/gensec.h"
30 #include "auth/gensec/gensec_internal.h"
31 #include "librpc/gen_ndr/dcerpc.h"
32 #include "auth/common_auth.h"
35 #define DBGC_CLASS DBGC_AUTH
37 _PRIVATE_ NTSTATUS
gensec_may_reset_crypto(struct gensec_security
*gensec_security
,
40 if (!gensec_security
->ops
->may_reset_crypto
) {
44 return gensec_security
->ops
->may_reset_crypto(gensec_security
, full_reset
);
48 wrappers for the gensec function pointers
50 _PUBLIC_ NTSTATUS
gensec_unseal_packet(struct gensec_security
*gensec_security
,
51 uint8_t *data
, size_t length
,
52 const uint8_t *whole_pdu
, size_t pdu_length
,
55 if (!gensec_security
->ops
->unseal_packet
) {
56 return NT_STATUS_NOT_IMPLEMENTED
;
58 if (!gensec_have_feature(gensec_security
, GENSEC_FEATURE_SIGN
)) {
59 return NT_STATUS_INVALID_PARAMETER
;
61 if (!gensec_have_feature(gensec_security
, GENSEC_FEATURE_SEAL
)) {
62 return NT_STATUS_INVALID_PARAMETER
;
64 if (!gensec_have_feature(gensec_security
, GENSEC_FEATURE_DCE_STYLE
)) {
65 return NT_STATUS_INVALID_PARAMETER
;
68 return gensec_security
->ops
->unseal_packet(gensec_security
,
70 whole_pdu
, pdu_length
,
74 _PUBLIC_ NTSTATUS
gensec_check_packet(struct gensec_security
*gensec_security
,
75 const uint8_t *data
, size_t length
,
76 const uint8_t *whole_pdu
, size_t pdu_length
,
79 if (!gensec_security
->ops
->check_packet
) {
80 return NT_STATUS_NOT_IMPLEMENTED
;
82 if (!gensec_have_feature(gensec_security
, GENSEC_FEATURE_SIGN
)) {
83 return NT_STATUS_INVALID_PARAMETER
;
86 return gensec_security
->ops
->check_packet(gensec_security
, data
, length
, whole_pdu
, pdu_length
, sig
);
89 _PUBLIC_ NTSTATUS
gensec_seal_packet(struct gensec_security
*gensec_security
,
91 uint8_t *data
, size_t length
,
92 const uint8_t *whole_pdu
, size_t pdu_length
,
95 if (!gensec_security
->ops
->seal_packet
) {
96 return NT_STATUS_NOT_IMPLEMENTED
;
98 if (!gensec_have_feature(gensec_security
, GENSEC_FEATURE_SEAL
)) {
99 return NT_STATUS_INVALID_PARAMETER
;
101 if (!gensec_have_feature(gensec_security
, GENSEC_FEATURE_SIGN
)) {
102 return NT_STATUS_INVALID_PARAMETER
;
104 if (!gensec_have_feature(gensec_security
, GENSEC_FEATURE_DCE_STYLE
)) {
105 return NT_STATUS_INVALID_PARAMETER
;
108 return gensec_security
->ops
->seal_packet(gensec_security
, mem_ctx
, data
, length
, whole_pdu
, pdu_length
, sig
);
111 _PUBLIC_ NTSTATUS
gensec_sign_packet(struct gensec_security
*gensec_security
,
113 const uint8_t *data
, size_t length
,
114 const uint8_t *whole_pdu
, size_t pdu_length
,
117 if (!gensec_security
->ops
->sign_packet
) {
118 return NT_STATUS_NOT_IMPLEMENTED
;
120 if (!gensec_have_feature(gensec_security
, GENSEC_FEATURE_SIGN
)) {
121 return NT_STATUS_INVALID_PARAMETER
;
124 return gensec_security
->ops
->sign_packet(gensec_security
, mem_ctx
, data
, length
, whole_pdu
, pdu_length
, sig
);
127 _PUBLIC_
size_t gensec_sig_size(struct gensec_security
*gensec_security
, size_t data_size
)
129 if (!gensec_security
->ops
->sig_size
) {
132 if (!gensec_have_feature(gensec_security
, GENSEC_FEATURE_SIGN
)) {
135 if (gensec_have_feature(gensec_security
, GENSEC_FEATURE_SEAL
)) {
136 if (!gensec_have_feature(gensec_security
, GENSEC_FEATURE_DCE_STYLE
)) {
141 return gensec_security
->ops
->sig_size(gensec_security
, data_size
);
144 _PUBLIC_
size_t gensec_max_wrapped_size(struct gensec_security
*gensec_security
)
146 if (!gensec_security
->ops
->max_wrapped_size
) {
150 return gensec_security
->ops
->max_wrapped_size(gensec_security
);
153 _PUBLIC_
size_t gensec_max_input_size(struct gensec_security
*gensec_security
)
155 if (!gensec_security
->ops
->max_input_size
) {
156 return (1 << 17) - gensec_sig_size(gensec_security
, 1 << 17);
159 return gensec_security
->ops
->max_input_size(gensec_security
);
162 _PUBLIC_ NTSTATUS
gensec_wrap(struct gensec_security
*gensec_security
,
167 if (!gensec_security
->ops
->wrap
) {
168 return NT_STATUS_NOT_IMPLEMENTED
;
170 return gensec_security
->ops
->wrap(gensec_security
, mem_ctx
, in
, out
);
173 _PUBLIC_ NTSTATUS
gensec_unwrap(struct gensec_security
*gensec_security
,
178 if (!gensec_security
->ops
->unwrap
) {
179 return NT_STATUS_NOT_IMPLEMENTED
;
181 return gensec_security
->ops
->unwrap(gensec_security
, mem_ctx
, in
, out
);
184 _PUBLIC_ NTSTATUS
gensec_session_key(struct gensec_security
*gensec_security
,
186 DATA_BLOB
*session_key
)
188 if (!gensec_have_feature(gensec_security
, GENSEC_FEATURE_SESSION_KEY
)) {
189 return NT_STATUS_NO_USER_SESSION_KEY
;
192 if (!gensec_security
->ops
->session_key
) {
193 return NT_STATUS_NOT_IMPLEMENTED
;
196 return gensec_security
->ops
->session_key(gensec_security
, mem_ctx
, session_key
);
199 const char *gensec_final_auth_type(struct gensec_security
*gensec_security
)
201 if (!gensec_security
->ops
->final_auth_type
) {
202 return gensec_security
->ops
->name
;
205 return gensec_security
->ops
->final_auth_type(gensec_security
);
209 * Log details of a successful GENSEC authorization to a service.
211 * Only successful authorizations are logged, as only these call gensec_session_info()
213 * The service may later refuse authorization due to an ACL.
216 static void log_successful_gensec_authz_event(struct gensec_security
*gensec_security
,
217 struct auth_session_info
*session_info
)
219 const struct tsocket_address
*remote
220 = gensec_get_remote_address(gensec_security
);
221 const struct tsocket_address
*local
222 = gensec_get_local_address(gensec_security
);
223 const char *service_description
224 = gensec_get_target_service_description(gensec_security
);
225 const char *final_auth_type
226 = gensec_final_auth_type(gensec_security
);
227 const char *transport_protection
= NULL
;
228 if (gensec_security
->want_features
& GENSEC_FEATURE_SMB_TRANSPORT
) {
229 transport_protection
= AUTHZ_TRANSPORT_PROTECTION_SMB
;
230 } else if (gensec_security
->want_features
& GENSEC_FEATURE_LDAPS_TRANSPORT
) {
231 transport_protection
= AUTHZ_TRANSPORT_PROTECTION_TLS
;
232 } else if (gensec_have_feature(gensec_security
, GENSEC_FEATURE_SEAL
)) {
233 transport_protection
= AUTHZ_TRANSPORT_PROTECTION_SEAL
;
234 } else if (gensec_have_feature(gensec_security
, GENSEC_FEATURE_SIGN
)) {
235 transport_protection
= AUTHZ_TRANSPORT_PROTECTION_SIGN
;
237 transport_protection
= AUTHZ_TRANSPORT_PROTECTION_NONE
;
239 log_successful_authz_event(gensec_security
->auth_context
->msg_ctx
,
240 gensec_security
->auth_context
->lp_ctx
,
244 transport_protection
,
246 NULL
/* client_audit_info */,
247 NULL
/* server_audit_info */);
252 * Return the credentials of a logged on user, including session keys
255 * Only valid after a successful authentication
257 * May only be called once per authentication. This will also make an
258 * authorization log entry, as it is already called by all the
263 _PUBLIC_ NTSTATUS
gensec_session_info(struct gensec_security
*gensec_security
,
265 struct auth_session_info
**session_info
)
268 if (!gensec_security
->ops
->session_info
) {
269 return NT_STATUS_NOT_IMPLEMENTED
;
271 status
= gensec_security
->ops
->session_info(gensec_security
, mem_ctx
, session_info
);
273 if (NT_STATUS_IS_OK(status
) && !gensec_security
->subcontext
274 && (gensec_security
->want_features
& GENSEC_FEATURE_NO_AUTHZ_LOG
) == 0) {
275 log_successful_gensec_authz_event(gensec_security
, *session_info
);
281 _PUBLIC_
void gensec_set_max_update_size(struct gensec_security
*gensec_security
,
282 uint32_t max_update_size
)
284 gensec_security
->max_update_size
= max_update_size
;
287 _PUBLIC_
size_t gensec_max_update_size(struct gensec_security
*gensec_security
)
289 if (gensec_security
->max_update_size
== 0) {
293 return gensec_security
->max_update_size
;
296 static NTSTATUS
gensec_verify_features(struct gensec_security
*gensec_security
)
301 * gensec_want_feature(GENSEC_FEATURE_SIGN)
303 * gensec_want_feature(GENSEC_FEATURE_SEAL)
304 * require these flags to be available.
306 if (gensec_security
->want_features
& GENSEC_FEATURE_SIGN
) {
307 if (!gensec_have_feature(gensec_security
, GENSEC_FEATURE_SIGN
)) {
308 DEBUG(0,("Did not manage to negotiate mandatory feature "
310 return NT_STATUS_ACCESS_DENIED
;
313 if (gensec_security
->want_features
& GENSEC_FEATURE_SEAL
) {
314 if (!gensec_have_feature(gensec_security
, GENSEC_FEATURE_SEAL
)) {
315 DEBUG(0,("Did not manage to negotiate mandatory feature "
317 return NT_STATUS_ACCESS_DENIED
;
319 if (!gensec_have_feature(gensec_security
, GENSEC_FEATURE_SIGN
)) {
320 DEBUG(0,("Did not manage to negotiate mandatory feature "
322 return NT_STATUS_ACCESS_DENIED
;
326 if (gensec_security
->dcerpc_auth_level
< DCERPC_AUTH_LEVEL_PACKET
) {
330 ok
= gensec_have_feature(gensec_security
,
331 GENSEC_FEATURE_SIGN_PKT_HEADER
);
333 DBG_ERR("backend [%s] does not support header signing! "
334 "auth_level[0x%x]\n",
335 gensec_security
->ops
->name
,
336 gensec_security
->dcerpc_auth_level
);
337 return NT_STATUS_INTERNAL_ERROR
;
344 * Next state function for the GENSEC state machine
346 * @param gensec_security GENSEC State
347 * @param out_mem_ctx The TALLOC_CTX for *out to be allocated on
348 * @param in The request, as a DATA_BLOB
349 * @param out The reply, as an talloc()ed DATA_BLOB, on *out_mem_ctx
350 * @return Error, MORE_PROCESSING_REQUIRED if a reply is sent,
351 * or NT_STATUS_OK if the user is authenticated.
353 _PUBLIC_ NTSTATUS
gensec_update(struct gensec_security
*gensec_security
,
354 TALLOC_CTX
*out_mem_ctx
,
355 const DATA_BLOB in
, DATA_BLOB
*out
)
358 TALLOC_CTX
*frame
= NULL
;
359 struct tevent_context
*ev
= NULL
;
360 struct tevent_req
*subreq
= NULL
;
363 if (gensec_security
->subcontext
) {
365 * gensec modules are not allowed to call the sync version.
367 return NT_STATUS_INTERNAL_ERROR
;
370 frame
= talloc_stackframe();
372 ev
= samba_tevent_context_init(frame
);
374 status
= NT_STATUS_NO_MEMORY
;
379 * TODO: remove this hack once the backends
382 tevent_loop_allow_nesting(ev
);
384 subreq
= gensec_update_send(frame
, ev
, gensec_security
, in
);
385 if (subreq
== NULL
) {
386 status
= NT_STATUS_NO_MEMORY
;
389 ok
= tevent_req_poll_ntstatus(subreq
, ev
, &status
);
393 status
= gensec_update_recv(subreq
, out_mem_ctx
, out
);
399 struct gensec_update_state
{
400 const struct gensec_security_ops
*ops
;
401 struct gensec_security
*gensec_security
;
406 static void gensec_update_cleanup(struct tevent_req
*req
,
407 enum tevent_req_state req_state
);
408 static void gensec_update_done(struct tevent_req
*subreq
);
411 * Next state function for the GENSEC state machine async version
413 * @param mem_ctx The memory context for the request
414 * @param ev The event context for the request
415 * @param gensec_security GENSEC State
416 * @param in The request, as a DATA_BLOB
418 * @return The request handle or NULL on no memory failure
421 _PUBLIC_
struct tevent_req
*gensec_update_send(TALLOC_CTX
*mem_ctx
,
422 struct tevent_context
*ev
,
423 struct gensec_security
*gensec_security
,
426 struct tevent_req
*req
= NULL
;
427 struct gensec_update_state
*state
= NULL
;
428 struct tevent_req
*subreq
= NULL
;
430 req
= tevent_req_create(mem_ctx
, &state
,
431 struct gensec_update_state
);
435 state
->ops
= gensec_security
->ops
;
436 state
->gensec_security
= gensec_security
;
438 if (gensec_security
->update_busy_ptr
!= NULL
) {
439 tevent_req_nterror(req
, NT_STATUS_INTERNAL_ERROR
);
440 return tevent_req_post(req
, ev
);
443 if (gensec_security
->child_security
!= NULL
) {
444 tevent_req_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
445 return tevent_req_post(req
, ev
);
448 gensec_security
->update_busy_ptr
= &state
->gensec_security
;
449 tevent_req_set_cleanup_fn(req
, gensec_update_cleanup
);
451 subreq
= state
->ops
->update_send(state
, ev
, gensec_security
, in
);
452 if (tevent_req_nomem(subreq
, req
)) {
453 return tevent_req_post(req
, ev
);
455 tevent_req_set_callback(subreq
, gensec_update_done
, req
);
457 DBG_DEBUG("%s[%p]: subreq: %p\n", state
->ops
->name
,
458 state
->gensec_security
, subreq
);
463 static void gensec_update_cleanup(struct tevent_req
*req
,
464 enum tevent_req_state req_state
)
466 struct gensec_update_state
*state
=
468 struct gensec_update_state
);
470 if (state
->gensec_security
== NULL
) {
474 if (state
->gensec_security
->update_busy_ptr
== &state
->gensec_security
) {
475 state
->gensec_security
->update_busy_ptr
= NULL
;
478 state
->gensec_security
= NULL
;
481 static void gensec_update_done(struct tevent_req
*subreq
)
483 struct tevent_req
*req
=
484 tevent_req_callback_data(subreq
,
486 struct gensec_update_state
*state
=
488 struct gensec_update_state
);
490 const char *debug_subreq
= NULL
;
492 if (CHECK_DEBUGLVL(DBGLVL_DEBUG
)) {
494 * We need to call tevent_req_print()
495 * before calling the _recv function,
496 * before tevent_req_received() was called.
497 * in order to print the pointer value of
500 debug_subreq
= tevent_req_print(state
, subreq
);
503 status
= state
->ops
->update_recv(subreq
, state
, &state
->out
);
505 state
->status
= status
;
506 if (GENSEC_UPDATE_IS_NTERROR(status
)) {
507 NTSTATUS orig_status
= status
;
508 bool force_no_such_user
= false;
511 * callers only expect NT_STATUS_NO_SUCH_USER.
513 if (NT_STATUS_EQUAL(status
, NT_STATUS_INVALID_ACCOUNT_NAME
)) {
514 force_no_such_user
= true;
515 } else if (NT_STATUS_EQUAL(status
, NT_STATUS_NO_SUCH_DOMAIN
)) {
516 force_no_such_user
= true;
519 if (state
->gensec_security
->subcontext
) {
521 * We should only map on the outer
522 * gensec_update exchange, spnego
523 * needs the raw status.
525 force_no_such_user
= false;
528 if (force_no_such_user
) {
530 * nt_status_squash() may map
531 * to NT_STATUS_LOGON_FAILURE later
533 status
= NT_STATUS_NO_SUCH_USER
;
536 DBG_INFO("%s[%p]: %s%s%s%s%s\n",
538 state
->gensec_security
,
539 NT_STATUS_EQUAL(status
, orig_status
) ?
540 "" : nt_errstr(orig_status
),
541 NT_STATUS_EQUAL(status
, orig_status
) ?
544 debug_subreq
? " " : "",
545 debug_subreq
? debug_subreq
: "");
546 tevent_req_nterror(req
, status
);
549 DBG_DEBUG("%s[%p]: %s %s\n", state
->ops
->name
,
550 state
->gensec_security
, nt_errstr(status
),
552 if (NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
553 tevent_req_done(req
);
558 * Because callers using the
559 * gensec_start_mech_by_authtype() never call
560 * gensec_want_feature(), it isn't sensible for them
561 * to have to call gensec_have_feature() manually, and
562 * these are not points of negotiation, but are
563 * asserted by the client
565 status
= gensec_verify_features(state
->gensec_security
);
566 if (tevent_req_nterror(req
, status
)) {
570 tevent_req_done(req
);
574 * Next state function for the GENSEC state machine
576 * @param req request state
577 * @param out_mem_ctx The TALLOC_CTX for *out to be allocated on
578 * @param out The reply, as an talloc()ed DATA_BLOB, on *out_mem_ctx
579 * @return Error, MORE_PROCESSING_REQUIRED if a reply is sent,
580 * or NT_STATUS_OK if the user is authenticated.
582 _PUBLIC_ NTSTATUS
gensec_update_recv(struct tevent_req
*req
,
583 TALLOC_CTX
*out_mem_ctx
,
586 struct gensec_update_state
*state
=
587 tevent_req_data(req
, struct gensec_update_state
);
590 *out
= data_blob_null
;
592 if (tevent_req_is_nterror(req
, &status
)) {
593 tevent_req_received(req
);
598 talloc_steal(out_mem_ctx
, out
->data
);
599 status
= state
->status
;
600 tevent_req_received(req
);
605 * Set the requirement for a certain feature on the connection
609 _PUBLIC_
void gensec_want_feature(struct gensec_security
*gensec_security
,
612 if (!gensec_security
->ops
|| !gensec_security
->ops
->want_feature
) {
613 gensec_security
->want_features
|= feature
;
616 gensec_security
->ops
->want_feature(gensec_security
, feature
);
620 * Check the requirement for a certain feature on the connection
624 _PUBLIC_
bool gensec_have_feature(struct gensec_security
*gensec_security
,
627 if (!gensec_security
->ops
|| !gensec_security
->ops
->have_feature
) {
631 /* We might 'have' features that we don't 'want', because the
632 * other end demanded them, or we can't negotiate them off */
633 return gensec_security
->ops
->have_feature(gensec_security
, feature
);
636 _PUBLIC_ NTTIME
gensec_expire_time(struct gensec_security
*gensec_security
)
638 if (!gensec_security
->ops
->expire_time
) {
639 return GENSEC_EXPIRE_TIME_INFINITY
;
642 return gensec_security
->ops
->expire_time(gensec_security
);
645 * Return the credentials structure associated with a GENSEC context
649 _PUBLIC_
struct cli_credentials
*gensec_get_credentials(struct gensec_security
*gensec_security
)
651 if (!gensec_security
) {
654 return gensec_security
->credentials
;
658 * Set the target service (such as 'http' or 'host') on a GENSEC context - ensures it is talloc()ed
660 * This is used for Kerberos service principal name resolution.
663 _PUBLIC_ NTSTATUS
gensec_set_target_service(struct gensec_security
*gensec_security
, const char *service
)
665 gensec_security
->target
.service
= talloc_strdup(gensec_security
, service
);
666 if (!gensec_security
->target
.service
) {
667 return NT_STATUS_NO_MEMORY
;
672 _PUBLIC_
const char *gensec_get_target_service(struct gensec_security
*gensec_security
)
674 if (gensec_security
->target
.service
) {
675 return gensec_security
->target
.service
;
682 * Set the target service (such as 'samr') on an GENSEC context - ensures it is talloc()ed.
684 * This is not the Kerberos service principal, instead this is a
685 * constant value that can be logged as part of authentication and
686 * authorization logging
688 _PUBLIC_ NTSTATUS
gensec_set_target_service_description(struct gensec_security
*gensec_security
,
691 gensec_security
->target
.service_description
= talloc_strdup(gensec_security
, service
);
692 if (!gensec_security
->target
.service_description
) {
693 return NT_STATUS_NO_MEMORY
;
698 _PUBLIC_
const char *gensec_get_target_service_description(struct gensec_security
*gensec_security
)
700 if (gensec_security
->target
.service_description
) {
701 return gensec_security
->target
.service_description
;
702 } else if (gensec_security
->target
.service
) {
703 return gensec_security
->target
.service
;
710 * Set the target hostname (suitable for kerberos resolutation) on a GENSEC context - ensures it is talloc()ed
714 _PUBLIC_ NTSTATUS
gensec_set_target_hostname(struct gensec_security
*gensec_security
, const char *hostname
)
716 gensec_security
->target
.hostname
= talloc_strdup(gensec_security
, hostname
);
717 if (hostname
&& !gensec_security
->target
.hostname
) {
718 return NT_STATUS_NO_MEMORY
;
723 _PUBLIC_
const char *gensec_get_target_hostname(struct gensec_security
*gensec_security
)
725 /* We allow the target hostname to be overridden for testing purposes */
726 if (gensec_security
->settings
->target_hostname
) {
727 return gensec_security
->settings
->target_hostname
;
730 if (gensec_security
->target
.hostname
) {
731 return gensec_security
->target
.hostname
;
734 /* We could add use the 'set sockaddr' call, and do a reverse
735 * lookup, but this would be both insecure (compromising the
736 * way kerberos works) and add DNS timeouts */
741 * Set (and copy) local and peer socket addresses onto a socket
742 * context on the GENSEC context.
744 * This is so that kerberos can include these addresses in
745 * cryptographic tokens, to avoid certain attacks.
749 * @brief Set the local gensec address.
751 * @param gensec_security The gensec security context to use.
753 * @param remote The local address to set.
755 * @return On success NT_STATUS_OK is returned or an NT_STATUS
758 _PUBLIC_ NTSTATUS
gensec_set_local_address(struct gensec_security
*gensec_security
,
759 const struct tsocket_address
*local
)
761 TALLOC_FREE(gensec_security
->local_addr
);
767 gensec_security
->local_addr
= tsocket_address_copy(local
, gensec_security
);
768 if (gensec_security
->local_addr
== NULL
) {
769 return NT_STATUS_NO_MEMORY
;
776 * @brief Set the remote gensec address.
778 * @param gensec_security The gensec security context to use.
780 * @param remote The remote address to set.
782 * @return On success NT_STATUS_OK is returned or an NT_STATUS
785 _PUBLIC_ NTSTATUS
gensec_set_remote_address(struct gensec_security
*gensec_security
,
786 const struct tsocket_address
*remote
)
788 TALLOC_FREE(gensec_security
->remote_addr
);
790 if (remote
== NULL
) {
794 gensec_security
->remote_addr
= tsocket_address_copy(remote
, gensec_security
);
795 if (gensec_security
->remote_addr
== NULL
) {
796 return NT_STATUS_NO_MEMORY
;
803 * @brief Get the local address from a gensec security context.
805 * @param gensec_security The security context to get the address from.
807 * @return The address as tsocket_address which could be NULL if
810 _PUBLIC_
const struct tsocket_address
*gensec_get_local_address(struct gensec_security
*gensec_security
)
812 if (gensec_security
== NULL
) {
815 return gensec_security
->local_addr
;
819 * @brief Get the remote address from a gensec security context.
821 * @param gensec_security The security context to get the address from.
823 * @return The address as tsocket_address which could be NULL if
826 _PUBLIC_
const struct tsocket_address
*gensec_get_remote_address(struct gensec_security
*gensec_security
)
828 if (gensec_security
== NULL
) {
831 return gensec_security
->remote_addr
;
835 * Set the target principal (assuming it it known, say from the SPNEGO reply)
836 * - ensures it is talloc()ed
840 _PUBLIC_ NTSTATUS
gensec_set_target_principal(struct gensec_security
*gensec_security
, const char *principal
)
842 gensec_security
->target
.principal
= talloc_strdup(gensec_security
, principal
);
843 if (!gensec_security
->target
.principal
) {
844 return NT_STATUS_NO_MEMORY
;
849 _PUBLIC_
const char *gensec_get_target_principal(struct gensec_security
*gensec_security
)
851 if (gensec_security
->target
.principal
) {
852 return gensec_security
->target
.principal
;
858 static int gensec_channel_bindings_destructor(struct gensec_channel_bindings
*cb
)
860 data_blob_clear_free(&cb
->initiator_address
);
861 data_blob_clear_free(&cb
->acceptor_address
);
862 data_blob_clear_free(&cb
->application_data
);
863 *cb
= (struct gensec_channel_bindings
) { .initiator_addrtype
= 0, };
867 _PUBLIC_ NTSTATUS
gensec_set_channel_bindings(struct gensec_security
*gensec_security
,
868 uint32_t initiator_addrtype
,
869 const DATA_BLOB
*initiator_address
,
870 uint32_t acceptor_addrtype
,
871 const DATA_BLOB
*acceptor_address
,
872 const DATA_BLOB
*application_data
)
874 struct gensec_channel_bindings
*cb
= NULL
;
876 if (gensec_security
->subcontext
) {
877 return NT_STATUS_INTERNAL_ERROR
;
880 if (gensec_security
->channel_bindings
!= NULL
) {
881 return NT_STATUS_ALREADY_REGISTERED
;
884 cb
= talloc_zero(gensec_security
, struct gensec_channel_bindings
);
886 return NT_STATUS_NO_MEMORY
;
888 talloc_set_destructor(cb
, gensec_channel_bindings_destructor
);
890 cb
->initiator_addrtype
= initiator_addrtype
;
891 if (initiator_address
!= NULL
) {
892 cb
->initiator_address
= data_blob_dup_talloc(cb
,
894 if (cb
->initiator_address
.length
!= initiator_address
->length
) {
896 return NT_STATUS_NO_MEMORY
;
899 cb
->acceptor_addrtype
= acceptor_addrtype
;
900 if (acceptor_address
!= NULL
) {
901 cb
->acceptor_address
= data_blob_dup_talloc(cb
,
903 if (cb
->acceptor_address
.length
!= acceptor_address
->length
) {
905 return NT_STATUS_NO_MEMORY
;
908 if (application_data
!= NULL
) {
909 cb
->application_data
= data_blob_dup_talloc(cb
,
911 if (cb
->application_data
.length
!= application_data
->length
) {
913 return NT_STATUS_NO_MEMORY
;
917 gensec_security
->channel_bindings
= cb
;