| 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 withing barnowl |
|---|
| 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; |
|---|
| 67 | my $w; |
|---|
| 68 | |
|---|
| 69 | my $a_hdlerr; |
|---|
| 70 | my $a; |
|---|
| 71 | |
|---|
| 72 | sub do_renew { |
|---|
| 73 | |
|---|
| 74 | my $password = shift; |
|---|
| 75 | my($stdin, $stdout, $stderr); |
|---|
| 76 | use Symbol 'gensym'; $stderr = gensym; |
|---|
| 77 | my $pid = open3($stdin, $stdout, $stderr, 'kinit', '-l7d') or die("Failed to run kinit"); |
|---|
| 78 | |
|---|
| 79 | $hdlerr = new AnyEvent::Handle(fh => $stderr); |
|---|
| 80 | $hdlin = new AnyEvent::Handle(fh => $stdin); |
|---|
| 81 | |
|---|
| 82 | my $output = ""; |
|---|
| 83 | |
|---|
| 84 | $hdlin->push_write($password . "\n"); |
|---|
| 85 | $hdlerr->push_read (line => sub { |
|---|
| 86 | my ($hdl, $line) = @_; |
|---|
| 87 | $output .= $line; |
|---|
| 88 | }); |
|---|
| 89 | close $stdout; |
|---|
| 90 | $w = AnyEvent->child (pid => $pid, cb => sub { |
|---|
| 91 | my ($pid, $status) = @_; |
|---|
| 92 | if ($status != 0){ |
|---|
| 93 | BarnOwl::error($output); |
|---|
| 94 | } |
|---|
| 95 | else{ |
|---|
| 96 | if(BarnOwl::getvar("aklog") == 'on'){ |
|---|
| 97 | my $status = system('aklog'); |
|---|
| 98 | if ($status != 0){ |
|---|
| 99 | BarnOwl::error('Aklog Failed'); |
|---|
| 100 | } |
|---|
| 101 | } |
|---|
| 102 | } |
|---|
| 103 | }); |
|---|
| 104 | |
|---|
| 105 | } |
|---|
| 106 | |
|---|
| 107 | |
|---|
| 108 | 1; |
|---|