From ad14812b8f036fb47b4817d5ee391416dd9bf567 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Thu, 1 Sep 2005 23:31:51 +0000 Subject: r9931: Make use of new 'norealm' parsing functions rather than strchr(p '@'). Merge these norealm functions from lorikeet-heimdal. Andrew Bartlett (This used to be commit 6aef275efd7f434f65824eb3dd129c8e5efd8731) --- source4/kdc/hdb-ldb.c | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) (limited to 'source4/kdc') diff --git a/source4/kdc/hdb-ldb.c b/source4/kdc/hdb-ldb.c index ccdd64f40b..ecdda16150 100644 --- a/source4/kdc/hdb-ldb.c +++ b/source4/kdc/hdb-ldb.c @@ -454,11 +454,11 @@ static krb5_error_code LDB_lookup_principal(krb5_context context, struct ldb_con int count; char *filter = NULL; const char * const *princ_attrs = krb5_attrs; - char *p; char *princ_str; char *princ_str_talloc; char *short_princ; + char *short_princ_talloc; char *realm_dn_str; @@ -481,20 +481,24 @@ static krb5_error_code LDB_lookup_principal(krb5_context context, struct ldb_con return ret; } + ret = krb5_unparse_name_norealm(context, &princ, &short_princ); + + if (ret != 0) { + free(princ_str); + krb5_set_error_string(context, "LDB_lookup_principal: could not parse principal"); + krb5_warnx(context, "LDB_lookup_principal: could not parse principal"); + return ret; + } + princ_str_talloc = talloc_strdup(mem_ctx, princ_str); - short_princ = talloc_strdup(mem_ctx, princ_str); + short_princ_talloc = talloc_strdup(mem_ctx, short_princ); free(princ_str); + free(short_princ); if (!short_princ || !princ_str_talloc) { krb5_set_error_string(context, "LDB_lookup_principal: talloc_strdup() failed!"); return ENOMEM; } - p = strchr(short_princ, '@'); - if (p) { - p[0] = '\0'; - } - - switch (ent_type) { case HDB_LDB_ENT_TYPE_KRBTGT: filter = talloc_asprintf(mem_ctx, "(&(objectClass=user)(samAccountName=%s))", @@ -502,15 +506,15 @@ static krb5_error_code LDB_lookup_principal(krb5_context context, struct ldb_con break; case HDB_LDB_ENT_TYPE_CLIENT: filter = talloc_asprintf(mem_ctx, "(&(objectClass=user)(|(samAccountName=%s)(userPrincipalName=%s)))", - short_princ, princ_str_talloc); + short_princ_talloc, princ_str_talloc); break; case HDB_LDB_ENT_TYPE_SERVER: filter = talloc_asprintf(mem_ctx, "(&(objectClass=user)(|(samAccountName=%s)(servicePrincipalName=%s)))", - short_princ, short_princ); + short_princ_talloc, short_princ_talloc); break; case HDB_LDB_ENT_TYPE_ANY: filter = talloc_asprintf(mem_ctx, "(&(objectClass=user)(|(|(samAccountName=%s)(servicePrincipalName=%s))(userPrincipalName=%s)))", - short_princ, short_princ, princ_str_talloc); + short_princ_talloc, short_princ_talloc, princ_str_talloc); break; } -- cgit