From: Stefan Metzmacher Date: Tue, 26 Nov 2024 11:54:02 +0000 (+0100) Subject: libcli/auth: let schannel_check_creds_state() take an access_check callback X-Git-Tag: tdb-1.4.13~349 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=2cf8a8ea35d75c7dcac0e724b473f66a36acd8b2;p=thirdparty%2Fsamba.git libcli/auth: let schannel_check_creds_state() take an access_check callback This allows the callback to decide if the updated creds should be stored or not. Signed-off-by: Stefan Metzmacher Reviewed-by: Andreas Schneider --- diff --git a/libcli/auth/schannel_state.h b/libcli/auth/schannel_state.h index 5b33ba0ab23..de6efe345c4 100644 --- a/libcli/auth/schannel_state.h +++ b/libcli/auth/schannel_state.h @@ -39,6 +39,11 @@ NTSTATUS schannel_check_creds_state(TALLOC_CTX *mem_ctx, struct netr_Authenticator *return_authenticator, enum dcerpc_AuthType auth_type, enum dcerpc_AuthLevel auth_level, + NTSTATUS (*access_check_cb)(struct netlogon_creds_CredentialState *creds, + NTSTATUS step_status, + bool *store, + void *access_check_private), + void *access_check_private, struct netlogon_creds_CredentialState **creds_out); NTSTATUS schannel_get_challenge(struct loadparm_context *lp_ctx, diff --git a/libcli/auth/schannel_state_tdb.c b/libcli/auth/schannel_state_tdb.c index 6deeff08288..c7f38dfbb91 100644 --- a/libcli/auth/schannel_state_tdb.c +++ b/libcli/auth/schannel_state_tdb.c @@ -562,6 +562,11 @@ NTSTATUS schannel_check_creds_state(TALLOC_CTX *mem_ctx, struct netr_Authenticator *return_authenticator, enum dcerpc_AuthType auth_type, enum dcerpc_AuthLevel auth_level, + NTSTATUS (*access_check_cb)(struct netlogon_creds_CredentialState *creds, + NTSTATUS step_status, + bool *store, + void *access_check_private), + void *access_check_private, struct netlogon_creds_CredentialState **creds_out) { TALLOC_CTX *tmpctx; @@ -572,6 +577,7 @@ NTSTATUS schannel_check_creds_state(TALLOC_CTX *mem_ctx, char *keystr = NULL; struct db_record *record; TDB_DATA key; + bool store = true; if (creds_out != NULL) { *creds_out = NULL; @@ -624,13 +630,22 @@ NTSTATUS schannel_check_creds_state(TALLOC_CTX *mem_ctx, return_authenticator, auth_type, auth_level); + if (access_check_cb != NULL) { + NTSTATUS step_status = status; + status = access_check_cb(creds, + step_status, + &store, + access_check_private); + } if (!NT_STATUS_IS_OK(status)) { goto done; } - status = schannel_store_session_key_tdb(db_sc, tmpctx, creds); - if (!NT_STATUS_IS_OK(status)) { - goto done; + if (store) { + status = schannel_store_session_key_tdb(db_sc, tmpctx, creds); + if (!NT_STATUS_IS_OK(status)) { + goto done; + } } if (creds_out) { diff --git a/librpc/rpc/server/netlogon/schannel_util.c b/librpc/rpc/server/netlogon/schannel_util.c index 69773ea30e8..cc1355670d6 100644 --- a/librpc/rpc/server/netlogon/schannel_util.c +++ b/librpc/rpc/server/netlogon/schannel_util.c @@ -600,6 +600,8 @@ NTSTATUS dcesrv_netr_creds_server_step_check(struct dcesrv_call_state *dce_call, return_authenticator, auth_type, auth_level, + NULL, /* access_check_cb */ + NULL, /* access_check_private */ &creds); if (!NT_STATUS_IS_OK(nt_status)) { ZERO_STRUCTP(return_authenticator);