From: Joseph Sutton Date: Tue, 5 Sep 2023 03:07:05 +0000 (+1200) Subject: lib:krb5_wrap: Add Heimdal‐specific smb_krb5_princ_component() implementation X-Git-Tag: tevent-0.16.0~575 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=229d26e25eb4f31d72b6bf650b987e482a44dd32;p=thirdparty%2Fsamba.git lib:krb5_wrap: Add Heimdal‐specific smb_krb5_princ_component() implementation This implementation doesn’t rely on a variable of static storage duration being used as a conduit for the return value. Signed-off-by: Joseph Sutton Reviewed-by: Andrew Bartlett --- diff --git a/lib/krb5_wrap/krb5_samba.c b/lib/krb5_wrap/krb5_samba.c index c9bef2dd1bc..6f9ae4d822b 100644 --- a/lib/krb5_wrap/krb5_samba.c +++ b/lib/krb5_wrap/krb5_samba.c @@ -142,14 +142,30 @@ const krb5_data *krb5_princ_component(krb5_context context, #endif krb5_error_code smb_krb5_princ_component(krb5_context context, - krb5_principal principal, + krb5_const_principal principal, int i, krb5_data *data); krb5_error_code smb_krb5_princ_component(krb5_context context, - krb5_principal principal, + krb5_const_principal principal, int i, krb5_data *data) { +#if defined(HAVE_KRB5_PRINCIPAL_GET_COMP_STRING) && !defined(HAVE_KRB5_PRINC_COMPONENT) + const char *component = NULL; + + if (i < 0) { + return EINVAL; + } + + component = krb5_principal_get_comp_string(context, principal, i); + if (component == NULL) { + return ENOENT; + } + + *data = smb_krb5_make_data(discard_const_p(char, component), strlen(component)); + + return 0; +#else const krb5_data *kdata = NULL; if (i < 0) { @@ -164,6 +180,7 @@ krb5_error_code smb_krb5_princ_component(krb5_context context, *data = *kdata; return 0; +#endif } /********************************************************** diff --git a/source4/auth/kerberos/kerberos.h b/source4/auth/kerberos/kerberos.h index 807b1cde26a..41c9b048aaf 100644 --- a/source4/auth/kerberos/kerberos.h +++ b/source4/auth/kerberos/kerberos.h @@ -66,7 +66,7 @@ const krb5_data *krb5_princ_component(krb5_context context, krb5_principal princ #endif krb5_error_code smb_krb5_princ_component(krb5_context context, - krb5_principal principal, + krb5_const_principal principal, int i, krb5_data *data);