| 1 | package DJabberd::SASL::NTLM; | ||
| 2 | |||
| 3 | 1 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | 1 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 5 | 1 | ▶ | use base qw/DJabberd::SASL/; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 6 | use IPC::Open3; | ||
| 7 | use IO::Select; | ||
| 8 | use Carp; | ||
| 9 | |||
| 10 | our $VERSION = '0.03'; | ||
| 11 | |||
| 12 | sub manager_class { 'DJabberd::SASL::NTLMManager' } | ||
| 13 | |||
| 14 | sub mechanisms { | ||
| 15 | my $plugin = shift; | ||
| 16 | return { NTLM => 1 }; | ||
| 17 | } | ||
| 18 | |||
| 19 | sub set_config_ntlmauthhelper { | ||
| 20 | my ( $self, $val ) = @_; | ||
| 21 | $val =~ s/^\s*\b(.+)\b\s*$/$1/; | ||
| 22 | my ( $ntlmauthhelper, @params ) = split( /\s+/, $val ); | ||
| 23 | croak "Invalid NTLM helper: $ntlmauthhelper" | ||
| 24 | unless ( -f $ntlmauthhelper && -x $ntlmauthhelper ); | ||
| 25 | $self->{err} = 1; # set STDERR for child | ||
| 26 | $self->{pid} = | ||
| 27 | open3( $self->{out}, $self->{in}, $self->{err}, $ntlmauthhelper, | ||
| 28 | @params ); | ||
| 29 | $self->{s} = IO::Select->new(); | ||
| 30 | $self->{s}->add( $self->{in} ); | ||
| 31 | $self->{helper} = $ntlmauthhelper; | ||
| 32 | $self->{params} = [@params]; | ||
| 33 | |||
| 34 | croak "Can't open bidirectional pipe to NTLM helper" | ||
| 35 | unless ( $self->{pid} ); | ||
| 36 | } | ||
| 37 | |||
| 38 | ## XXX dupe sux | ||
| 39 | sub register { | ||
| 40 | my ( $plugin, $vhost ) = @_; | ||
| 41 | $plugin->SUPER::register($vhost); | ||
| 42 | |||
| 43 | $vhost->register_hook( | ||
| 44 | "SendFeatures", | ||
| 45 | sub { | ||
| 46 | my ( $vh, $cb, $conn ) = @_; | ||
| 47 | if ( my $sasl_conn = $conn->sasl ) { | ||
| 48 | if ( $sasl_conn->is_success ) { | ||
| 49 | return; | ||
| 50 | } | ||
| 51 | } | ||
| 52 | my @mech = $plugin->mechanisms_list; | ||
| 53 | my $xml_mechanisms = | ||
| 54 | "<mechanisms xmlns='urn:ietf:params:xml:ns:xmpp-sasl'>"; | ||
| 55 | $xml_mechanisms .= join "", | ||
| 56 | map { "<mechanism>$_</mechanism>" } @mech; | ||
| 57 | $xml_mechanisms .= "<optional/>" if $plugin->is_optional; | ||
| 58 | $xml_mechanisms .= "</mechanisms>"; | ||
| 59 | $cb->stanza($xml_mechanisms); | ||
| 60 | } | ||
| 61 | ); | ||
| 62 | } | ||
| 63 | |||
| 64 | 1; | ||
| 65 | __END__ | ||