kinit: Add --cache-default-for flag (fix check-cc)
authorNicolas Williams <nico@twosigma.com>
Thu, 12 Mar 2020 16:46:47 +0000 (11:46 -0500)
committerNicolas Williams <nico@twosigma.com>
Fri, 13 Mar 2020 02:02:09 +0000 (21:02 -0500)
kuser/kinit.1
kuser/kinit.c
tests/kdc/check-cc.in

index fd74844bc41e0df7b8c1a07ab194a80c1c8321d9..16cf4019f506035b49b09b54213b30e4ced42a7c 100644 (file)
@@ -100,6 +100,10 @@ Supported options:
 .It Fl c Ar cachename Fl Fl cache= Ns Ar cachename
 The credentials cache to put the acquired ticket in, if other than
 default.
+.It Fl Fl cache-default-for
+Use a cache in the default collection (for the default cache type)
+named after the client principal.  This is useful for users with
+multiple client principals.
 .It Fl f Fl Fl forwardable
 Obtain a ticket than can be forwarded to another host.
 .It Fl F Fl Fl no-forwardable
index d32be43160a7558d99d751e2f25745ce381b3d30..367630621d6c37df41ec86fc7ca7f6a3a834c3d2 100644 (file)
@@ -56,6 +56,7 @@ int validate_flag     = 0;
 int version_flag       = 0;
 int help_flag          = 0;
 int addrs_flag         = -1;
+int default_for_flag   = 0;
 struct getarg_strings extra_addresses;
 int anonymous_flag     = 0;
 char *lifetime                 = NULL;
@@ -108,6 +109,9 @@ static struct getargs args[] = {
     { "cache",                 'c', arg_string, &cred_cache,
       NP_("credentials cache", ""), "cachename" },
 
+    { "cache-default-for"  , 0, arg_flag, &default_for_flag,
+      NP_("name cache after client principal", ""), NULL },
+
     { "forwardable",   'F', arg_negative_flag, &forwardable_flag,
       NP_("get tickets not forwardable", ""), NULL },
 
@@ -1475,9 +1479,11 @@ main(int argc, char **argv)
                                krb5_principal_get_realm(context, principal),
                                "afslog", TRUE, &do_afslog);
 
-    if (cred_cache)
+    if (cred_cache) {
        ret = krb5_cc_resolve(context, cred_cache, &ccache);
-    else {
+    } else if (default_for_flag) {
+        ret = krb5_cc_default_for(context, principal, &ccache);
+    } else {
        if (argc > 1) {
            char s[1024];
            ret = krb5_cc_new_unique(context, NULL, NULL, &ccache);
index e696215237e8aa9cb33853c104440b2db6d53092..8dcb306d694c20852d066635a1d038ba425344fd 100644 (file)
@@ -139,8 +139,8 @@ export KRB5_CONFIG
 unset KRB5CCNAME
 rm -rf ${objdir}/kt ${objdir}/cc_dir
 mkdir ${objdir}/cc_dir || { ec=1 ; eval "${testfailed}"; }
-${kinit} foo@${R} || { ec=1 ; eval "${testfailed}"; }
-${kinit} --no-change-default bar@${R} || { ec=1 ; eval "${testfailed}"; }
+${kinit} --cache-default-for foo@${R} || { ec=1 ; eval "${testfailed}"; }
+${kinit} --cache-default-for --no-change-default bar@${R} || { ec=1 ; eval "${testfailed}"; }
 primary=`cat ${objdir}/cc_dir/primary`
 [ "x$primary" = xtkt.foo@${R} ] || { ec=1 ; eval "${testfailed}"; }
 ${klist} -l |