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