]> eyrie.org Git - kerberos/heimdal-kadm5.git/commitdiff
Improved dump() output for attributes and ticket lifetime
authorJon Robertson <jonrober@stanford.edu>
Wed, 6 Jan 2010 21:43:49 +0000 (13:43 -0800)
committerJon Robertson <jonrober@stanford.edu>
Fri, 5 Feb 2010 22:18:20 +0000 (14:18 -0800)
dump() has been improved to print out the attribute constant names rather
than the attribute bitmask itself.  Also, the two ticket lifetime values
(lifetime and max lifetime) print out days and weeks rather than seconds.

Kadm5.pm

index 72c7a6832d916e9aa0b8950504c3cf298f63df2c..85918ed8fc1475ebfa86cb9ffd4c2fdf54d2fcae 100644 (file)
--- a/Kadm5.pm
+++ b/Kadm5.pm
@@ -36,6 +36,8 @@
 package Heimdal::Kadm5;
 
 use strict;
+no strict qw(refs);
+
 use Carp;
 use vars qw($VERSION @ISA @EXPORT @EXPORT_OK $AUTOLOAD);
 
@@ -480,14 +482,59 @@ package Heimdal::Kadm5::Principal;
 # @Heimdal::Kadm5::Principal::ISA = qw(Heimdal::Kadm5::SPrincipal);
 
 use POSIX qw(strftime);
+use Time::Seconds;
 
 sub _sec2date { $_[0] ? strftime "%Y-%m-%d %T UTC", gmtime($_[0]): 'never'; }
 
-sub _attr2str { }
+# Convert seconds into a days and weeks format for ticket lifetime and
+# maximum lifetime.
+# TODO: This assumes you have an even number of days, and will fail at
+# anything like '25 hours'.  The handling should be improved.
+sub _sec2days {
+    my $seconds = shift;
+    my $val = Time::Seconds->new($seconds);
+    my $str = '';
+    if ($val->weeks >= 1) {
+       if ($val->weeks == 1) {
+           $str = $val->weeks . ' week';
+       } else {
+           $str = $val->weeks . ' weeks';
+       }
+    }
+    if ($val->days % 7 == 0) {
+       return $str;
+    } else {
+       $str .= ', ' if $str;
+       return $str . $val->days . ' day' if $val->days == 1;
+       return $str . $val->days.' days';
+    }
+}
+
+# Given an attribute bitmask, convert it into a string of attribute text.
+sub _attr2str {
+    my $mask = shift;
+    my @attrs = ();
+    my @possible = ('KRB5_KDB_DISALLOW_ALL_TIX',
+                   'KRB5_KDB_DISALLOW_DUP_SKEY',
+                   'KRB5_KDB_DISALLOW_FORWARDABLE',
+                   'KRB5_KDB_DISALLOW_POSTDATED',
+                   'KRB5_KDB_DISALLOW_PROXIABLE',
+                   'KRB5_KDB_DISALLOW_RENEWABLE',
+                   'KRB5_KDB_DISALLOW_SVR',
+                   'KRB5_KDB_DISALLOW_TGT_BASED',
+                   'KRB5_KDB_NEW_PRINC',
+                   'KRB5_KDB_REQUIRES_HW_AUTH',
+                   'KRB5_KDB_REQUIRES_PRE_AUTH',
+                   'KRB5_KDB_REQUIRES_PWCHANGE',
+                   'KRB5_KDB_SUPPORT_DESMD5',
+                   );
+
+    foreach my $test (@possible) {
+       push (@attrs, $test) if $mask & &{"Heimdal::Kadm5::$test"}();
+    }
+    return join (', ', sort @attrs);
+}
 
-# TODO: Test new format.
-# TODO: Convert bitmap of attributes to a string.
-# TODO: Convert seconds to days/week format for Max ticket/renewable life.
 sub dump
   {
     my $sp = shift;
@@ -500,9 +547,10 @@ sub dump
                _sec2date($sp->getPwExpiration);
     printf $io "%21s: %s\n", 'Last password change',
                _sec2date($sp->getLastPwdChange);
-    printf $io "%21s: %d seconds\n", 'Max ticket life', $sp->getMaxLife;
-    printf $io "%21s: %d seconds\n", 'Max renewable life',
-               $sp->getMaxRenewableLife;
+    printf $io "%21s: %s\n", 'Max ticket life',
+               _sec2days($sp->getMaxLife);
+    printf $io "%21s: %s\n", 'Max renewable life',
+               _sec2days($sp->getMaxRenewableLife);
     printf $io "%21s: %s\n", 'Kvno', $sp->getKvno;
     printf $io "%21s: %s\n", 'Mkvno', $sp->getMKvno;
     printf $io "%21s: %s\n", 'Last successful login', 
@@ -512,7 +560,7 @@ sub dump
     printf $io "%21s: %d\n", 'Failed login count', $sp->getFailAuthCounts;
     printf $io "%21s: %s\n", 'Last modified', _sec2date($sp->getModDate);
     printf $io "%21s: %s\n", 'Modifier', $sp->getModName;
-    printf $io "%21s: %s\n", 'Attributes', $sp->getAttributes;
+    printf $io "%21s: %s\n", 'Attributes', _attr2str($sp->getAttributes);
     my @keys;
     foreach my $kt (@{$sp->getKeytypes}) 
       {