Blame SOURCES/Fix-bugs-in-kdcpolicy-commit.patch

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