]> git.ipfire.org Git - thirdparty/krb5.git/commitdiff
Don't fail krb5_cc_select() for no default realm 1234/head
authorIsaac Boukris <iboukris@gmail.com>
Sun, 26 Dec 2021 01:28:41 +0000 (03:28 +0200)
committerGreg Hudson <ghudson@mit.edu>
Sun, 2 Jan 2022 01:29:08 +0000 (20:29 -0500)
If the target server principal is a host-based service without
multiple dotted components and no default realm is configured,
krb5_cc_select() can fail, and therefore gss_init_sec_context().
Continue without filling in the realm in this case.

[ghudson@mit.edu: edited commit message and comment; slightly adjusted
flow control]

ticket: 9042 (new)

src/lib/krb5/ccache/ccselect.c
src/tests/gssapi/t_gssapi.py

index 6c360e1002ecd0ff65433b6d9e8680a86f557217..dee4c46162fc3c7d7905d4697de8055cd64fb9c9 100644 (file)
@@ -147,18 +147,19 @@ krb5_cc_select(krb5_context context, krb5_principal server,
         server->type == KRB5_NT_SRV_HST && server->length == 2) {
         ret = krb5_get_fallback_host_realm(context, &server->data[1],
                                            &fbrealms);
-        if (ret)
-            goto cleanup;
-
-        /* Make a copy with the first fallback realm. */
-        ret = krb5_copy_principal(context, server, &srvcp);
-        if (ret)
-            goto cleanup;
-        ret = krb5_set_principal_realm(context, srvcp, fbrealms[0]);
-        if (ret)
+        /* Continue without realm if we failed due to no default realm. */
+        if (ret && ret != KRB5_CONFIG_NODEFREALM)
             goto cleanup;
-
-        server = srvcp;
+        if (!ret) {
+            /* Make a copy with the first fallback realm. */
+            ret = krb5_copy_principal(context, server, &srvcp);
+            if (ret)
+                goto cleanup;
+            ret = krb5_set_principal_realm(context, srvcp, fbrealms[0]);
+            if (ret)
+                goto cleanup;
+            server = srvcp;
+        }
     }
 
     /* Consult authoritative modules first, then heuristic ones. */
index 1740a6177a52946bd21027f7f16a5d0262070d31..5f093a198cc53971155442fa0ed1ef5c44141c2c 100755 (executable)
@@ -23,11 +23,20 @@ realm.run([kadminl, 'addprinc', '-randkey', 'service1/barack'])
 realm.run([kadminl, 'addprinc', '-randkey', 'service2/calvin'])
 realm.run([kadminl, 'addprinc', '-randkey', 'service2/dwight'])
 realm.run([kadminl, 'addprinc', '-randkey', 'host/-nomatch-'])
+realm.run([kadminl, 'addprinc', '-randkey', 'http/localhost'])
 realm.run([kadminl, 'xst', 'service1/abraham'])
 realm.run([kadminl, 'xst', 'service1/barack'])
 realm.run([kadminl, 'xst', 'service2/calvin'])
+realm.run([kadminl, 'xst', 'http/localhost'])
 realm.run([kadminl, 'renprinc', 'service1/abraham', 'service1/andrew'])
 
+# Test with no default realm and no dots in the server name.
+realm.run(['./t_accname', 'h:http@localhost'], expected_msg='http/localhost')
+remove_default = {'libdefaults': {'default_realm': None}}
+no_default = realm.special_env('no_default', False, krb5_conf=remove_default)
+realm.run(['./t_accname', 'h:http@localhost'], expected_msg='http/localhost',
+          env=no_default)
+
 # Test with no acceptor name, including client/keytab principal
 # mismatch (non-fatal) and missing keytab entry (fatal).
 realm.run(['./t_accname', 'p:service1/andrew'],