exit(1);
}
+ if (cache_name != NULL) {
+ code = krb5_cc_set_default_name(context, cache_name);
+ if (code) {
+ com_err(progname, code, _("while setting default cache name"));
+ exit(1);
+ }
+ }
+
if (all) {
code = krb5_cccol_cursor_new(context, &cursor);
if (code) {
return 0;
}
- if (cache_name != NULL) {
- code = krb5_cc_resolve(context, cache_name, &cache);
- if (code != 0) {
- com_err(progname, code, _("while resolving %s"), cache_name);
- exit(1);
- }
- } else {
- code = krb5_cc_default(context, &cache);
- if (code) {
- com_err(progname, code, _("while getting default ccache"));
- exit(1);
- }
+ code = krb5_cc_default(context, &cache);
+ if (code) {
+ com_err(progname, code, _("while resolving ccache"));
+ exit(1);
}
code = krb5_cc_destroy(context, cache);
static void list_all_ccaches(void);
static int list_ccache(krb5_ccache);
static void show_all_ccaches(void);
-static void do_ccache_name(char *);
+static void do_ccache(void);
static int show_ccache(krb5_ccache);
static int check_ccache(krb5_ccache);
static void do_keytab(const char *);
exit(1);
}
+ if (name != NULL && mode != KEYTAB) {
+ ret = krb5_cc_set_default_name(context, name);
+ if (ret) {
+ com_err(progname, ret, _("while setting default cache name"));
+ exit(1);
+ }
+ }
+
if (list_all)
list_all_ccaches();
else if (show_all)
show_all_ccaches();
else if (mode == DEFAULT || mode == CCACHE)
- do_ccache_name(name);
+ do_ccache();
else
do_keytab(name);
return 0;
}
static void
-do_ccache_name(char *name)
+do_ccache()
{
krb5_error_code ret;
krb5_ccache cache;
- if (name == NULL) {
- ret = krb5_cc_default(context, &cache);
- if (ret) {
- if (!status_only)
- com_err(progname, ret, _("while getting default ccache"));
- exit(1);
- }
- } else {
- ret = krb5_cc_resolve(context, name, &cache);
- if (ret) {
- if (!status_only)
- com_err(progname, ret, _("while resolving ccache %s"), name);
- exit(1);
- }
+ ret = krb5_cc_default(context, &cache);
+ if (ret) {
+ if (!status_only)
+ com_err(progname, ret, _("while resolving ccache"));
+ exit(1);
}
exit(status_only ? check_ccache(cache) : show_ccache(cache));
}
realm.addprinc('carol', password('carol'))
def collection_test(realm, ccname):
+ oldccname = realm.env['KRB5CCNAME']
realm.env['KRB5CCNAME'] = ccname
realm.run([klist, '-A', '-s'], expected_code=1)
if '---\nalice@' not in output or output.count('\n') != 4:
fail('klist -l did not show expected output after re-kinit for alice.')
realm.kinit('bob', password('bob'))
- output = realm.run([klist, '-A'])
+ output = realm.run([klist, '-A', ccname])
if 'bob@' not in output.splitlines()[1] or 'alice@' not in output or \
'carol' not in output or output.count('Default principal:') != 3:
fail('klist -A did not show expected output after kinit for bob.')
output = realm.run([klist, '-l'])
if '---\ncarol@' not in output or output.count('\n') != 5:
fail('klist -l did not show expected output after kswitch to carol.')
- realm.run([kdestroy])
- output = realm.run([klist, '-l'])
+
+ # Switch to specifying the collection name on the command line
+ # (only works with klist/kdestroy for now, not kinit/kswitch).
+ realm.env['KRB5CCNAME'] = oldccname
+
+ realm.run([kdestroy, '-c', ccname])
+ output = realm.run([klist, '-l', ccname])
if 'carol@' in output or 'bob@' not in output or output.count('\n') != 4:
fail('kdestroy failed to remove only primary ccache.')
- realm.run([klist, '-s'], expected_code=1)
- realm.run([klist, '-A', '-s'])
- realm.run([kdestroy, '-A'])
- output = realm.run([klist, '-l'], expected_code=1)
+ realm.run([klist, '-s', ccname], expected_code=1)
+ realm.run([klist, '-A', '-s', ccname])
+ realm.run([kdestroy, '-A', '-c', ccname])
+ output = realm.run([klist, '-l', ccname], expected_code=1)
if not output.endswith('---\n') or output.count('\n') != 2:
fail('kdestroy -a failed to empty cache collection.')
- realm.run([klist, '-A', '-s'], expected_code=1)
+ realm.run([klist, '-A', '-s', ccname], expected_code=1)
collection_test(realm, 'DIR:' + os.path.join(realm.testdir, 'cc'))