From eec9e545923179626e047c897376499ec9348802 Mon Sep 17 00:00:00 2001 From: Joseph Sutton Date: Tue, 5 Sep 2023 14:52:02 +1200 Subject: [PATCH] lib:krb5_wrap: Add smb_krb5_princ_component() For now this function is a mere wrapper round krb5_princ_component(), but one whose interface allows for a more sensible implementation. Signed-off-by: Joseph Sutton Reviewed-by: Andrew Bartlett --- lib/krb5_wrap/krb5_samba.c | 24 ++++++++++++++++++++++++ source4/auth/kerberos/kerberos.h | 5 +++++ 2 files changed, 29 insertions(+) diff --git a/lib/krb5_wrap/krb5_samba.c b/lib/krb5_wrap/krb5_samba.c index 1183338e2b2..c9bef2dd1bc 100644 --- a/lib/krb5_wrap/krb5_samba.c +++ b/lib/krb5_wrap/krb5_samba.c @@ -141,6 +141,30 @@ const krb5_data *krb5_princ_component(krb5_context context, } #endif +krb5_error_code smb_krb5_princ_component(krb5_context context, + krb5_principal principal, + int i, + krb5_data *data); +krb5_error_code smb_krb5_princ_component(krb5_context context, + krb5_principal principal, + int i, + krb5_data *data) +{ + const krb5_data *kdata = NULL; + + if (i < 0) { + return EINVAL; + } + + kdata = krb5_princ_component(context, principal, i); + if (kdata == NULL) { + return ENOENT; + } + + *data = *kdata; + + return 0; +} /********************************************************** * WRAPPING FUNCTIONS diff --git a/source4/auth/kerberos/kerberos.h b/source4/auth/kerberos/kerberos.h index cc61dccd820..807b1cde26a 100644 --- a/source4/auth/kerberos/kerberos.h +++ b/source4/auth/kerberos/kerberos.h @@ -65,6 +65,11 @@ krb5_error_code krb5_auth_con_setuseruserkey(krb5_context context, krb5_auth_con const krb5_data *krb5_princ_component(krb5_context context, krb5_principal principal, int i ); #endif +krb5_error_code smb_krb5_princ_component(krb5_context context, + krb5_principal principal, + int i, + krb5_data *data); + /* Samba wrapper function for krb5 functionality. */ krb5_error_code kerberos_encode_pac(TALLOC_CTX *mem_ctx, struct PAC_DATA *pac_data,