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/heimdal/lib/krb5/krb5-protos.h | 13 +++++++ source4/heimdal/lib/krb5/principal.c | 71 ++++++++++++++++++++++++---------- 2 files changed, 64 insertions(+), 20 deletions(-) (limited to 'source4/heimdal') diff --git a/source4/heimdal/lib/krb5/krb5-protos.h b/source4/heimdal/lib/krb5/krb5-protos.h index 71d42b43b8d..cc619314a3f 100644 --- a/source4/heimdal/lib/krb5/krb5-protos.h +++ b/source4/heimdal/lib/krb5/krb5-protos.h @@ -2377,6 +2377,12 @@ krb5_parse_name ( const char */*name*/, krb5_principal */*principal*/); +krb5_error_code KRB5_LIB_FUNCTION +krb5_parse_name_norealm ( + krb5_context /*context*/, + const char */*name*/, + krb5_principal */*principal*/); + const char* KRB5_LIB_FUNCTION krb5_passwd_result_to_string ( krb5_context /*context*/, @@ -3430,6 +3436,13 @@ krb5_write_safe_message ( krb5_error_code KRB5_LIB_FUNCTION krb5_xfree (void */*ptr*/); +krb5_error_code +parse_name ( + krb5_context /*context*/, + const char */*name*/, + krb5_boolean /*short_form*/, + krb5_principal */*principal*/); + #ifdef __cplusplus } #endif diff --git a/source4/heimdal/lib/krb5/principal.c b/source4/heimdal/lib/krb5/principal.c index 74db080ab7c..8540636403f 100644 --- a/source4/heimdal/lib/krb5/principal.c +++ b/source4/heimdal/lib/krb5/principal.c @@ -91,10 +91,11 @@ krb5_principal_get_comp_string(krb5_context context, return princ_ncomp(principal, component); } -krb5_error_code KRB5_LIB_FUNCTION -krb5_parse_name(krb5_context context, - const char *name, - krb5_principal *principal) +krb5_error_code +parse_name(krb5_context context, + const char *name, + krb5_boolean short_form, + krb5_principal *principal) { krb5_error_code ret; heim_general_string *comp; @@ -184,19 +185,29 @@ krb5_parse_name(krb5_context context, } *q++ = c; } - if(got_realm){ - realm = malloc(q - start + 1); - if (realm == NULL) { - krb5_set_error_string (context, "malloc: out of memory"); - ret = ENOMEM; + if (got_realm) { + if (short_form) { + krb5_set_error_string (context, "realm found in 'short' principal expected to be without one!"); + ret = KRB5_PARSE_MALFORMED; goto exit; + } else { + realm = malloc(q - start + 1); + if (realm == NULL) { + krb5_set_error_string (context, "malloc: out of memory"); + ret = ENOMEM; + goto exit; + } + memcpy(realm, start, q - start); + realm[q - start] = 0; } - memcpy(realm, start, q - start); - realm[q - start] = 0; }else{ - ret = krb5_get_default_realm (context, &realm); - if (ret) - goto exit; + if (short_form) { + ret = krb5_get_default_realm (context, &realm); + if (ret) + goto exit; + } else { + realm = NULL; + } comp[n] = malloc(q - start + 1); if (comp[n] == NULL) { @@ -229,6 +240,21 @@ exit: return ret; } +krb5_error_code KRB5_LIB_FUNCTION +krb5_parse_name(krb5_context context, + const char *name, + krb5_principal *principal) +{ + return parse_name(context, name, FALSE, principal); +} + +krb5_error_code KRB5_LIB_FUNCTION +krb5_parse_name_norealm(krb5_context context, + const char *name, + krb5_principal *principal) +{ + return parse_name(context, name, TRUE, principal); +} static const char quotable_chars[] = " \n\t\b\\/@"; static const char replace_chars[] = " ntb\\/@"; @@ -323,12 +349,17 @@ unparse_name(krb5_context context, int i; krb5_error_code ret; /* count length */ - plen = strlen(princ_realm(principal)); - if(strcspn(princ_realm(principal), quotable_chars) == plen) - len += plen; - else - len += 2*plen; - len++; + if (!short_flag) { + plen = strlen(princ_realm(principal)); + if(strcspn(princ_realm(principal), quotable_chars) == plen) + len += plen; + else + len += 2*plen; + len++; + } else { + len = 0; + } + for(i = 0; i < princ_num_comp(principal); i++){ plen = strlen(princ_ncomp(principal, i)); if(strcspn(princ_ncomp(principal, i), quotable_chars) == plen) -- cgit