From 6d6e411fb8f118dcbc3b77f88b9d19121b29b806 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=BCnther=20Deschner?= Date: Thu, 15 May 2014 15:57:06 +0200 Subject: s4-kdc/db-glue: add principal_comp_str{case}cmp MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Guenther Signed-off-by: Günther Deschner Reviewed-by: Stefan Metzmacher --- source4/kdc/db-glue.c | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) (limited to 'source4/kdc') diff --git a/source4/kdc/db-glue.c b/source4/kdc/db-glue.c index 1b663595cba..f12c1f3f705 100644 --- a/source4/kdc/db-glue.c +++ b/source4/kdc/db-glue.c @@ -540,6 +540,60 @@ out: return ret; } +static int principal_comp_strcmp_int(krb5_context context, + krb5_const_principal principal, + unsigned int component, + const char *string, + bool do_strcasecmp) +{ + const char *p; + size_t len; + +#if defined(HAVE_KRB5_PRINCIPAL_GET_COMP_STRING) + p = krb5_principal_get_comp_string(context, principal, component); + if (p == NULL) { + return -1; + } + len = strlen(p); +#else + krb5_data *d; + if (component >= krb5_princ_size(context, principal)) { + return -1; + } + + d = krb5_princ_component(context, principal, component); + if (d == NULL) { + return -1; + } + + p = d->data; + len = d->length; +#endif + if (do_strcasecmp) { + return strncasecmp(p, string, len); + } else { + return strncmp(p, string, len); + } +} + +static int principal_comp_strcasecmp(krb5_context context, + krb5_const_principal principal, + unsigned int component, + const char *string) +{ + return principal_comp_strcmp_int(context, principal, + component, string, true); +} + +static int principal_comp_strcmp(krb5_context context, + krb5_const_principal principal, + unsigned int component, + const char *string) +{ + return principal_comp_strcmp_int(context, principal, + component, string, false); +} + /* * Construct an hdb_entry from a directory entry. */ -- cgit v1.2.1