diff options
author | Günther Deschner <gd@samba.org> | 2014-05-15 15:57:06 +0200 |
---|---|---|
committer | Günther Deschner <gd@samba.org> | 2015-03-27 01:26:16 +0100 |
commit | 6d6e411fb8f118dcbc3b77f88b9d19121b29b806 (patch) | |
tree | 7a01b56a31920aa7c3b3307b5cf3a4ec4b9a1f07 /source4/kdc | |
parent | 714862defd5dc318e3ff4360165ce92be4098cb8 (diff) | |
download | samba-6d6e411fb8f118dcbc3b77f88b9d19121b29b806.tar.gz |
s4-kdc/db-glue: add principal_comp_str{case}cmp
Guenther
Signed-off-by: Günther Deschner <gd@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
Diffstat (limited to 'source4/kdc')
-rw-r--r-- | source4/kdc/db-glue.c | 54 |
1 files changed, 54 insertions, 0 deletions
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. */ |