File: setfields

package info (click to toggle)
libafs-perl 2.6.2-1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 2,244 kB
  • ctags: 268
  • sloc: perl: 5,159; ansic: 135; sh: 36; makefile: 7
file content (72 lines) | stat: -rwxr-xr-x 2,586 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/usr/local/bin/perl -w

use blib;
use AFS::KAS;
use AFS::KTC_PRINCIPAL;
use AFS::KTC_TOKEN;
use AFS::KTC_EKEY;
use AFS qw(checkafs raise_exception);

die "Usage: admin user \n" if ($#ARGV != 1);

raise_exception(1);

$admin = AFS::KTC_PRINCIPAL->new(shift);
$user  = AFS::KTC_PRINCIPAL->new(shift);
$key   = AFS::KTC_EKEY->ReadPassword($admin->principal . "'s Password:");

$reason = '';
$token = AFS::KTC_TOKEN->GetAdminToken($admin, $key, 300, 1, $reason);
if ($reason) { print "reason = $reason\n"; }
checkafs('AdminToken');

$kas = AFS::KAS->AuthServerConn($token, &AFS::KA_MAINTENANCE_SERVICE);
checkafs('AuthServerConn');

$entry = $kas->getentry($user->name, $user->instance);
print "\n\nUser data for ", $user->name, $user->instance, ": \n";
foreach my $tp_key (sort keys %$entry) {
    printf("%20s  %s\n",$tp_key, $$entry{$tp_key});
}

my $flags    = 1;        # (1 = normal, 4 = admin)
my $expire   = 925715000;# 03 May 1999 07:03
my $maxassoc = 0;
my $lifetime = 48*60*60; # unit is secs; => 48 hrs
my $pwexpire = 10;       # number of days
my $pw_reuse = 2;        # pwreuse allowed: [1 = yes], [2 = no], [0 = not changed]
my $nfail    = 4;        # (nfail - 1) tries are allowed; => 3 tries
my $locktime = 3;        # unit is 8.5 min => 3 * (8.5)

$pwexpire++;
$nfail++;
$locktime++;

my $packed= (($pwexpire << 24) | ($pw_reuse  << 16) | ($nfail << 8) | $locktime );
#my $ok = $kas->setfields($user->name, $user->instance, $flags, $expire, $lifetime, $maxassoc, $packed);
my $ok = $kas->KAM_SetFields($user->name, $user->instance, $flags, $expire, $lifetime, $maxassoc, $packed);
printf("KAS setfields: %s \n", $ok ? 'yes' : 'no');
checkafs('SetFields');

$entry = $kas->getentry($user->name, $user->instance);
print "\n\nUser data for ", $user->name, $user->instance, ": \n";
foreach my $tp_key (sort keys %$entry) {
    printf("%20s  %s\n",$tp_key, $$entry{$tp_key});
    if ($tp_key =~ 'misc_auth_bytes') {
        if ($$entry{$tp_key}) {
            my $packed    = $$entry{$tp_key};
            my $pwexpire  = (($packed >> 24) & 0xff);
            my $is_locked = (($packed >> 16) & 0xff);
            my $nfail     = (($packed >>  8) & 0xff);
            my $locktime  = (($packed >>  0) & 0xff);
            print "\t\t pwexpire  $pwexpire\n";
            print "\t\t nfail     $nfail\n";
            print "\t\t locktime  $locktime\n";
            print "\t\t is_locked $is_locked\n";
        }
    }
    if ($tp_key =~ 'passwd_reuse') {
        my $reused = $$entry{'passwd_reuse'} - 0x12340000;
        print "\t\t permit password reuse $reused \n";
    }
}