d738b9
From ffd715b98da026a6a9b3aac48de42e4f19860ce4 Mon Sep 17 00:00:00 2001
d738b9
From: Greg Hudson <ghudson@mit.edu>
d738b9
Date: Sat, 19 Aug 2017 19:09:24 -0400
d738b9
Subject: [PATCH] Fix bugs in kdcpolicy commit
d738b9
d738b9
Commit d0969f6a8170344031ef58fd2a161190f1edfb96 added tests using
d738b9
"klist ccachname -e", which does not work with a POSIX-conformant
d738b9
getopt() implementation such as the one in Solaris.  Fix
d738b9
t_kdcpolicy.py to use "klist -e ccachename" instead.
d738b9
d738b9
The tests could fail if the clock second rolled over between kinit and
d738b9
kvno.  Divide service ticket maximum lifetimes by 2 in the test module
d738b9
to correctly exercise TGS policy restrictions and ensure that service
d738b9
tickets are not constrained by the TGT end time.
d738b9
d738b9
Also use the correct trace macro when a kdcpolicy module declines to
d738b9
initialize (my mistake when revising the commit, noted by rharwood).
d738b9
d738b9
ticket: 8606
d738b9
(cherry picked from commit 09acbd91efc6df54e1572285ffc94c6acb3a9113)
d738b9
---
d738b9
 src/kdc/policy.c                  |  2 +-
d738b9
 src/plugins/kdcpolicy/test/main.c | 10 +++++-----
d738b9
 src/tests/t_kdcpolicy.py          | 13 +++++++++----
d738b9
 3 files changed, 15 insertions(+), 10 deletions(-)
d738b9
d738b9
diff --git a/src/kdc/policy.c b/src/kdc/policy.c
d738b9
index e49644e06..26c16f97c 100644
d738b9
--- a/src/kdc/policy.c
d738b9
+++ b/src/kdc/policy.c
d738b9
@@ -222,7 +222,7 @@ load_kdcpolicy_plugins(krb5_context context)
d738b9
         if (h->vt.init != NULL) {
d738b9
             ret = h->vt.init(context, &h->moddata);
d738b9
             if (ret == KRB5_PLUGIN_NO_HANDLE) {
d738b9
-                TRACE_KADM5_AUTH_INIT_SKIP(context, h->vt.name);
d738b9
+                TRACE_KDCPOLICY_INIT_SKIP(context, h->vt.name);
d738b9
                 free(h);
d738b9
                 continue;
d738b9
             }
d738b9
diff --git a/src/plugins/kdcpolicy/test/main.c b/src/plugins/kdcpolicy/test/main.c
d738b9
index eb8fde053..86c808958 100644
d738b9
--- a/src/plugins/kdcpolicy/test/main.c
d738b9
+++ b/src/plugins/kdcpolicy/test/main.c
d738b9
@@ -35,7 +35,7 @@
d738b9
 #include <krb5/kdcpolicy_plugin.h>
d738b9
 
d738b9
 static krb5_error_code
d738b9
-output_from_indicator(const char *const *auth_indicators,
d738b9
+output_from_indicator(const char *const *auth_indicators, int divisor,
d738b9
                       krb5_deltat *lifetime_out,
d738b9
                       krb5_deltat *renew_lifetime_out,
d738b9
                       const char **status)
d738b9
@@ -46,11 +46,11 @@ output_from_indicator(const char *const *auth_indicators,
d738b9
     }
d738b9
 
d738b9
     if (strcmp(auth_indicators[0], "ONE_HOUR") == 0) {
d738b9
-        *lifetime_out = 3600;
d738b9
+        *lifetime_out = 3600 / divisor;
d738b9
         *renew_lifetime_out = *lifetime_out * 2;
d738b9
         return 0;
d738b9
     } else if (strcmp(auth_indicators[0], "SEVEN_HOURS") == 0) {
d738b9
-        *lifetime_out = 7 * 3600;
d738b9
+        *lifetime_out = 7 * 3600 / divisor;
d738b9
         *renew_lifetime_out = *lifetime_out * 2;
d738b9
         return 0;
d738b9
     }
d738b9
@@ -71,7 +71,7 @@ test_check_as(krb5_context context, krb5_kdcpolicy_moddata moddata,
d738b9
         *status = "LOCAL_POLICY";
d738b9
         return KRB5KDC_ERR_POLICY;
d738b9
     }
d738b9
-    return output_from_indicator(auth_indicators, lifetime_out,
d738b9
+    return output_from_indicator(auth_indicators, 1, lifetime_out,
d738b9
                                  renew_lifetime_out, status);
d738b9
 }
d738b9
 
d738b9
@@ -87,7 +87,7 @@ test_check_tgs(krb5_context context, krb5_kdcpolicy_moddata moddata,
d738b9
         *status = "LOCAL_POLICY";
d738b9
         return KRB5KDC_ERR_POLICY;
d738b9
     }
d738b9
-    return output_from_indicator(auth_indicators, lifetime_out,
d738b9
+    return output_from_indicator(auth_indicators, 2, lifetime_out,
d738b9
                                  renew_lifetime_out, status);
d738b9
 }
d738b9
 
d738b9
diff --git a/src/tests/t_kdcpolicy.py b/src/tests/t_kdcpolicy.py
d738b9
index 6a745b959..b5d308461 100644
d738b9
--- a/src/tests/t_kdcpolicy.py
d738b9
+++ b/src/tests/t_kdcpolicy.py
d738b9
@@ -18,16 +18,21 @@ realm.run([kadminl, 'addprinc', '-pw', password('fail'), 'fail'])
d738b9
 def verify_time(out, target_time):
d738b9
     times = re.findall(r'\d\d/\d\d/\d\d \d\d:\d\d:\d\d', out)
d738b9
     times = [datetime.strptime(t, '%m/%d/%y %H:%M:%S') for t in times]
d738b9
+    divisor = 1
d738b9
     while len(times) > 0:
d738b9
         starttime = times.pop(0)
d738b9
         endtime = times.pop(0)
d738b9
         renewtime = times.pop(0)
d738b9
 
d738b9
-        if str(endtime - starttime) != target_time:
d738b9
+        if str((endtime - starttime) * divisor) != target_time:
d738b9
             fail('unexpected lifetime value')
d738b9
-        if str(renewtime - endtime) != target_time:
d738b9
+        if str((renewtime - endtime) * divisor) != target_time:
d738b9
             fail('unexpected renewable value')
d738b9
 
d738b9
+        # Service tickets should have half the lifetime of initial
d738b9
+        # tickets.
d738b9
+        divisor = 2
d738b9
+
d738b9
 rflags = ['-r', '1d', '-l', '12h']
d738b9
 
d738b9
 # Test AS+TGS success path.
d738b9
@@ -35,7 +40,7 @@ realm.kinit(realm.user_princ, password('user'),
d738b9
             rflags + ['-X', 'indicators=SEVEN_HOURS'])
d738b9
 realm.run([kvno, realm.host_princ])
d738b9
 realm.run(['./adata', realm.host_princ], expected_msg='+97: [SEVEN_HOURS]')
d738b9
-out = realm.run([klist, realm.ccache, '-e'])
d738b9
+out = realm.run([klist, '-e', realm.ccache])
d738b9
 verify_time(out, '7:00:00')
d738b9
 
d738b9
 # Test AS+TGS success path with different values.
d738b9
@@ -43,7 +48,7 @@ realm.kinit(realm.user_princ, password('user'),
d738b9
             rflags + ['-X', 'indicators=ONE_HOUR'])
d738b9
 realm.run([kvno, realm.host_princ])
d738b9
 realm.run(['./adata', realm.host_princ], expected_msg='+97: [ONE_HOUR]')
d738b9
-out = realm.run([klist, realm.ccache, '-e'])
d738b9
+out = realm.run([klist, '-e', realm.ccache])
d738b9
 verify_time(out, '1:00:00')
d738b9
 
d738b9
 # Test TGS failure path (using previous creds).