]> eyrie.org Git - kerberos/pam-krb5.git/commitdiff
Fix module/basic test without default realm
authorRuss Allbery <eagle@eyrie.org>
Mon, 2 Mar 2020 04:55:10 +0000 (20:55 -0800)
committerRuss Allbery <eagle@eyrie.org>
Mon, 2 Mar 2020 04:55:10 +0000 (20:55 -0800)
Ensure the module/basic test will run properly when the system
krb5.conf file does not specify a default realm.  Reported by TBK.

Closes #15

NEWS
tests/data/generate-krb5-conf
tests/module/basic-t.c

diff --git a/NEWS b/NEWS
index c9686e4fb34712868a2f72b735b30daaccee56ec..ae2f84211a15f9556c0349b520d43aa13924b56e 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -15,6 +15,9 @@ pam-krb5 4.9 (unreleased)
     of service attack via the Kerberos string to key function.  Thanks to
     Florian Best for pointing out this issue and suggesting a good fix.
 
+    Ensure the module/basic test will run properly when the system
+    krb5.conf file does not specify a default realm.  Reported by TBK.
+
     Update to rra-c-util 8.2:
 
     * Fix support for configuring the test suite with a krb5.conf file.
index 4172fa98e5420888a94c8764b1fd9008cccf065d..712a933d40ba04ac41dd62e2f27192c285c25adf 100755 (executable)
@@ -9,7 +9,7 @@
 # which can be found at <https://www.eyrie.org/~eagle/software/rra-c-util/>.
 #
 # Written by Russ Allbery <eagle@eyrie.org>
-# Copyright 2016 Russ Allbery <eagle@eyrie.org>
+# Copyright 2016, 2020 Russ Allbery <eagle@eyrie.org>
 # Copyright 2006-2008, 2010-2011
 #     The Board of Trustees of the Leland Stanford Junior University
 #
@@ -69,8 +69,17 @@ awk '
     { if (skip == 0) print }
 ' "$krb5conf" > tmp/krb5.conf.tmp
 if [ -n "$realm" ] ; then
-    sed -e "s/\\(default_realm.*=\\) .*/\\1 $realm/" \
-        tmp/krb5.conf.tmp > tmp/krb5.conf
+    pattern='^[        ]*default_realm.*='
+    if grep "$pattern" tmp/krb5.conf.tmp >/dev/null 2>/dev/null; then
+        sed -e "s/\\(default_realm.*=\\) .*/\\1 $realm/" \
+            tmp/krb5.conf.tmp >tmp/krb5.conf
+    else
+        (
+            cat tmp/krb5.conf.tmp
+            echo "[libdefaults]"
+            echo "    default_realm = $realm"
+        ) >tmp/krb5.conf
+    fi
     rm tmp/krb5.conf.tmp
 else
     mv tmp/krb5.conf.tmp tmp/krb5.conf
index e24104049de5e8334ca606c043abda0165a51e31..2f9aa9763537685cd6ce620f850fa995d15c05d0 100644 (file)
@@ -18,6 +18,7 @@
 
 #include <tests/fakepam/script.h>
 #include <tests/tap/basic.h>
+#include <tests/tap/kerberos.h>
 
 
 int
@@ -27,6 +28,12 @@ main(void)
 
     plan_lazy();
 
+    /*
+     * Generate a testing krb5.conf file with a nonexistent default realm so
+     * that this test will run on any system.
+     */
+    kerberos_generate_conf("bogus.example.com");
+
     /* Attempt login as the root user to test ignore_root. */
     memset(&config, 0, sizeof(config));
     config.user = "root";