Skip to content

Commit

Permalink
Improve kdb5 error when default realm is unset
Browse files Browse the repository at this point in the history
When the default realm name is unspecified, and none was set in the
krb5_context object, return KRB5_CONFIG_NODEFREALM from libkdb5
instead of the confusing KRB5_KDB_DBTYPE_NOTFOUND.  To accomplish
this, make kdb_get_library_name() return a krb5_error_code.

(cherry picked from commit 4131988)

ticket: 8448
version_fixed: 1.14.3
tags: -pullup
status: resolved
  • Loading branch information
greghudson authored and tlyu committed Jul 6, 2016
1 parent c0a1266 commit dcc8b95
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions src/lib/kdb/kdb5.c
Original file line number Diff line number Diff line change
Expand Up @@ -239,11 +239,13 @@ get_conf_section(krb5_context context, char **section)
return 0;
}

static char *
kdb_get_library_name(krb5_context kcontext)
static krb5_error_code
kdb_get_library_name(krb5_context kcontext, char **libname_out)
{
krb5_error_code status = 0;
char *result = NULL, *value = NULL, *lib = NULL, *defrealm = NULL;
char *value = NULL, *lib = NULL, *defrealm = NULL;

*libname_out = NULL;

status = krb5_get_default_realm(kcontext, &defrealm);
if (status)
Expand Down Expand Up @@ -272,12 +274,15 @@ kdb_get_library_name(krb5_context kcontext)
goto clean_n_exit;
}

result = strdup(lib);
*libname_out = strdup(lib);
if (*libname_out == NULL)
status = ENOMEM;

clean_n_exit:
krb5_free_default_realm(kcontext, defrealm);
profile_release_string(value);
profile_release_string(lib);
return result;
return status;
}

static void
Expand Down Expand Up @@ -554,9 +559,10 @@ krb5_db_setup_lib_handle(krb5_context kcontext)
goto clean_n_exit;
}

library = kdb_get_library_name(kcontext);
status = kdb_get_library_name(kcontext, &library);
if (library == NULL) {
status = KRB5_KDB_DBTYPE_NOTFOUND;
k5_prependmsg(kcontext, status,
_("Cannot initialize database library"));
goto clean_n_exit;
}

Expand Down

0 comments on commit dcc8b95

Please sign in to comment.