Skip to content

Commit

Permalink
Use an extended com_err hook in klist
Browse files Browse the repository at this point in the history
Add an adapted version of extended_com_err_fn from kinit to klist and
use it.  In do_ccache(), rely on the ccache type to set a reasonable
message if krb5_cc_set_flags() or krb5_cc_get_principal() fails due to
a nonexistent or unreadable ccache, and don't confuse the user with
the name of the ccache operation that failed.

(cherry picked from commit ae027dd)

ticket: 7809
version_fixed: 1.12.1
status: resolved
  • Loading branch information
greghudson authored and tlyu committed Jan 9, 2014
1 parent 5571685 commit 23ffdc3
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 23 deletions.
35 changes: 17 additions & 18 deletions src/clients/klist/klist.c
Expand Up @@ -112,6 +112,19 @@ static void usage()
exit(1);
}

static void
extended_com_err_fn(const char *prog, errcode_t code, const char *fmt,
va_list args)
{
const char *msg;

msg = krb5_get_error_message(kcontext, code);
fprintf(stderr, "%s: %s%s", prog, msg, (*fmt == '\0') ? "" : " ");
krb5_free_error_message(kcontext, msg);
vfprintf(stderr, fmt, args);
fprintf(stderr, "\n");
}

int
main(argc, argv)
int argc;
Expand All @@ -123,6 +136,7 @@ main(argc, argv)

setlocale(LC_ALL, "");
progname = GET_PROGNAME(argv[0]);
set_com_err_hook(extended_com_err_fn);

name = NULL;
mode = DEFAULT;
Expand Down Expand Up @@ -472,28 +486,13 @@ do_ccache(krb5_ccache cache)

flags = 0; /* turns off OPENCLOSE mode */
if ((code = krb5_cc_set_flags(kcontext, cache, flags))) {
if (code == KRB5_FCC_NOFILE) {
if (!status_only) {
com_err(progname, code, _("(ticket cache %s:%s)"),
krb5_cc_get_type(kcontext, cache),
krb5_cc_get_name(kcontext, cache));
#ifdef KRB5_KRB4_COMPAT
if (name == NULL)
do_v4_ccache(0);
#endif
}
} else {
if (!status_only)
com_err(progname, code,
_("while setting cache flags (ticket cache %s:%s)"),
krb5_cc_get_type(kcontext, cache),
krb5_cc_get_name(kcontext, cache));
}
if (!status_only)
com_err(progname, code, "");
return 1;
}
if ((code = krb5_cc_get_principal(kcontext, cache, &princ))) {
if (!status_only)
com_err(progname, code, _("while retrieving principal name"));
com_err(progname, code, "");
return 1;
}
if ((code = krb5_unparse_name(kcontext, princ, &defname))) {
Expand Down
2 changes: 1 addition & 1 deletion src/tests/dejagnu/config/default.exp
Expand Up @@ -2205,7 +2205,7 @@ proc do_klist_err { testname } {
spawn $KLIST -5
# Might say "credentials cache" or "credentials cache file".
expect {
-re "klist: No credentials cache.*found.*\r\n" {
-re "klist: Credentials cache file .* not found.*\r\n" {
verbose "klist started"
}
timeout {
Expand Down
2 changes: 1 addition & 1 deletion src/tests/gssapi/t_client_keytab.py
Expand Up @@ -135,7 +135,7 @@
fail('Authenticated as wrong principal')
# Make sure the tickets we acquired didn't become the default
out = realm.run([klist], expected_code=1)
if 'No credentials cache found' not in out:
if ' not found' not in out:
fail('Expected error not seen')
realm.run([kdestroy, '-A'])

Expand Down
6 changes: 3 additions & 3 deletions src/tests/t_ccache.py
Expand Up @@ -33,7 +33,7 @@
# Test kdestroy and klist of a non-existent ccache.
realm.run([kdestroy])
output = realm.run([klist], expected_code=1)
if 'No credentials cache found' not in output:
if ' not found' not in output:
fail('Expected error message not seen in klist output')

realm.addprinc('alice', password('alice'))
Expand All @@ -49,7 +49,7 @@ def collection_test(realm, ccname):
fail('Initial kinit failed to get credentials for alice.')
realm.run([kdestroy])
output = realm.run([klist], expected_code=1)
if 'No credentials cache found' not in output:
if ' not found' not in output:
fail('Initial kdestroy failed to destroy primary cache.')
output = realm.run([klist, '-l'], expected_code=1)
if not output.endswith('---\n') or output.count('\n') != 2:
Expand Down Expand Up @@ -131,7 +131,7 @@ def collection_test(realm, ccname):
del realm.env['KRB5CCNAME']
uidstr = str(os.getuid())
out = realm.run([klist], expected_code=1)
if 'FILE:testdir/abc%s' % uidstr not in out:
if 'testdir/abc%s' % uidstr not in out:
fail('Wrong ccache in klist')

success('Credential cache tests')

0 comments on commit 23ffdc3

Please sign in to comment.