1 | use strict; |
---|
2 | use warnings; |
---|
3 | |
---|
4 | package BarnOwl::Module::Kerberos; |
---|
5 | |
---|
6 | =head1 NAME |
---|
7 | |
---|
8 | BarnOwl::Module::Kerberos |
---|
9 | |
---|
10 | =head1 DESCRIPTION |
---|
11 | |
---|
12 | This module allows someone to renew tickets within BarnOwl |
---|
13 | |
---|
14 | =cut |
---|
15 | |
---|
16 | use BarnOwl; |
---|
17 | use AnyEvent; |
---|
18 | use AnyEvent::Handle; |
---|
19 | use IPC::Open3; |
---|
20 | |
---|
21 | our $VERSION = 1.0; |
---|
22 | |
---|
23 | BarnOwl::new_variable_bool( |
---|
24 | 'aklog', |
---|
25 | { |
---|
26 | default => 1, |
---|
27 | summary => 'Enable running aklog on renew', |
---|
28 | description => "If set, aklog will be run during the renew command." |
---|
29 | } |
---|
30 | ); |
---|
31 | |
---|
32 | sub startup { |
---|
33 | register_commands(); |
---|
34 | } |
---|
35 | |
---|
36 | sub register_commands { |
---|
37 | BarnOwl::new_command( |
---|
38 | 'renew' => \&cmd_renew, |
---|
39 | { |
---|
40 | summary => 'Renew Kerberos Tickets', |
---|
41 | usage => 'renew', |
---|
42 | description => <<END_DESCR |
---|
43 | Renews Kerberos Ticket |
---|
44 | END_DESCR |
---|
45 | } |
---|
46 | ); |
---|
47 | } |
---|
48 | |
---|
49 | |
---|
50 | $BarnOwl::Hooks::startup->add('BarnOwl::Module::Kerberos::startup'); |
---|
51 | |
---|
52 | ################################################################################ |
---|
53 | ######################## Owl command handlers ################################## |
---|
54 | ################################################################################ |
---|
55 | |
---|
56 | |
---|
57 | sub cmd_renew { |
---|
58 | BarnOwl::start_password("Password: ", \&do_renew ); |
---|
59 | return ""; |
---|
60 | } |
---|
61 | |
---|
62 | |
---|
63 | my $hdlin; |
---|
64 | my $hdlerr; |
---|
65 | my $kinit_watcher; |
---|
66 | |
---|
67 | sub do_renew { |
---|
68 | |
---|
69 | my $password = shift; |
---|
70 | my ($stdin, $stdout, $stderr); |
---|
71 | use Symbol 'gensym'; $stderr = gensym; |
---|
72 | my $pid = open3($stdin, $stdout, $stderr, 'kinit', '-l7d') or die("Failed to run kinit"); |
---|
73 | |
---|
74 | $hdlerr = new AnyEvent::Handle(fh => $stderr); |
---|
75 | $hdlin = new AnyEvent::Handle(fh => $stdin); |
---|
76 | |
---|
77 | my $output = ""; |
---|
78 | |
---|
79 | $hdlin->push_write($password . "\n"); |
---|
80 | $hdlerr->push_read(line => sub { |
---|
81 | my ($hdl, $line) = @_; |
---|
82 | $output .= $line; |
---|
83 | }); |
---|
84 | close $stdout; |
---|
85 | $kinit_watcher = AnyEvent->child (pid => $pid, cb => sub { |
---|
86 | my ($pid, $status) = @_; |
---|
87 | if ($status != 0) { |
---|
88 | BarnOwl::error($output); |
---|
89 | } else { |
---|
90 | if (BarnOwl::getvar("aklog") eq 'on') { |
---|
91 | my $status = system('aklog'); |
---|
92 | if ($status != 0) { |
---|
93 | BarnOwl::error('Aklog Failed'); |
---|
94 | } |
---|
95 | } |
---|
96 | } |
---|
97 | }); |
---|
98 | |
---|
99 | } |
---|
100 | |
---|
101 | |
---|
102 | 1; |
---|