From: Greg Hudson Date: Thu, 10 May 2012 17:34:10 +0000 (+0000) Subject: Add krb5_parse_name flag to ignore realm X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=0eb4672034bc48c94f0ab4775b114d5b8b89e696;p=krb5.git Add krb5_parse_name flag to ignore realm The flag KRB5_PRINCIPAL_PARSE_IGNORE_REALM causes krb5_parse_name to return the principal with an empty realm whether or not a realm is present in the name. ticket: 7129 git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@25862 dc483132-0cff-0310-8789-dd5450dbe970 --- diff --git a/src/include/krb5/krb5.hin b/src/include/krb5/krb5.hin index 284e6b327..3208be54c 100644 --- a/src/include/krb5/krb5.hin +++ b/src/include/krb5/krb5.hin @@ -3409,6 +3409,7 @@ krb5_parse_name(krb5_context context, const char *name, #define KRB5_PRINCIPAL_PARSE_REQUIRE_REALM 0x2 /**< Error if realm is not present */ #define KRB5_PRINCIPAL_PARSE_ENTERPRISE 0x4 /**< Create single-component enterprise principle */ +#define KRB5_PRINCIPAL_PARSE_IGNORE_REALM 0x8 /**< Ignore realm if present */ /** * Convert a string principal name to a krb5_principal with flags. @@ -3426,6 +3427,12 @@ krb5_parse_name(krb5_context context, const char *name, * @li #KRB5_PRINCIPAL_PARSE_REQUIRE_REALM - realm must be present in @a name * @li #KRB5_PRINCIPAL_PARSE_ENTERPRISE - create single-component enterprise * principal + * @li #KRB5_PRINCIPAL_PARSE_IGNORE_REALM - ignore realm if present in @a name + * + * If @c KRB5_PRINCIPAL_PARSE_NO_REALM or @c KRB5_PRINCIPAL_PARSE_IGNORE_REALM + * is specified in @a flags, the realm of the new principal will be empty. + * Otherwise, the default realm for @a context will be used if @a name does not + * specify a realm. * * Use krb5_free_principal() to free @a principal_out when it is no longer * needed. diff --git a/src/lib/krb5/krb/parse.c b/src/lib/krb5/krb/parse.c index fb28229a3..dd4f44d11 100644 --- a/src/lib/krb5/krb/parse.c +++ b/src/lib/krb5/krb/parse.c @@ -180,6 +180,7 @@ krb5_parse_name_flags(krb5_context context, const char *name, krb5_boolean enterprise = (flags & KRB5_PRINCIPAL_PARSE_ENTERPRISE); krb5_boolean require_realm = (flags & KRB5_PRINCIPAL_PARSE_REQUIRE_REALM); krb5_boolean no_realm = (flags & KRB5_PRINCIPAL_PARSE_NO_REALM); + krb5_boolean ignore_realm = (flags & KRB5_PRINCIPAL_PARSE_IGNORE_REALM); *principal_out = NULL; @@ -201,7 +202,7 @@ krb5_parse_name_flags(krb5_context context, const char *name, name); goto cleanup; } - if (!no_realm) { + if (!no_realm && !ignore_realm) { ret = krb5_get_default_realm(context, &default_realm); if (ret) goto cleanup; @@ -212,6 +213,9 @@ krb5_parse_name_flags(krb5_context context, const char *name, krb5_set_error_message(context, ret, _("Principal %s has realm present"), name); goto cleanup; + } else if (ignore_realm) { + krb5_free_data_contents(context, &princ->realm); + princ->realm = empty_data(); } princ->type = (enterprise) ? KRB5_NT_ENTERPRISE_PRINCIPAL :