From a204827d0c338d1c6afa9edd6e8eeb95b34cea64 Mon Sep 17 00:00:00 2001 From: Matt Sergeant Date: Thu, 29 Jul 2004 14:40:32 +0000 Subject: [PATCH] Fix for AUTH PLAIN from Michael Holzt git-svn-id: https://svn.perl.org/qpsmtpd/trunk@280 958fd67b-6ff1-0310-b445-bb7760255be9 --- lib/Qpsmtpd/Auth.pm | 86 +++++++++++++++++++-------------------------- 1 file changed, 37 insertions(+), 49 deletions(-) diff --git a/lib/Qpsmtpd/Auth.pm b/lib/Qpsmtpd/Auth.pm index ba4eb17..72c0c24 100644 --- a/lib/Qpsmtpd/Auth.pm +++ b/lib/Qpsmtpd/Auth.pm @@ -214,6 +214,14 @@ package Qpsmtpd::Auth; use Qpsmtpd::Constants; use MIME::Base64; +sub e64 +{ + my ($arg) = @_; + my $res = encode_base64($arg); + chomp($res); + return($res); +} + sub Qpsmtpd::SMTP::auth { my ( $self, $arg, @stuff ) = @_; @@ -235,59 +243,39 @@ sub SASL { $mechanism = lc($mechanism); if ( $mechanism eq "plain" ) { - if ($prekey) { - ( $passHash, $user, $passClear ) = split /\x0/, - decode_base64($prekey); - } - else { - - $session->respond( 334, "Username:" ); - - # We read the username and password from STDIN - $user = <>; - chop($user); - chop($user); - if ( $user eq '*' ) { - $session->respond( 501, "Authentification canceled" ); - return DECLINED; - } - - $session->respond( 334, "Password:" ); - $passClear = <>; - chop($passClear); - chop($passClear); - if ( $passClear eq '*' ) { - $session->respond( 501, "Authentification canceled" ); - return DECLINED; - } + if (!$prekey) { + $session->respond( 334, "Please continue" ); + $prekey= <>; } + ( $passHash, $user, $passClear ) = split /\x0/, + decode_base64($prekey); } + elsif ($mechanism eq "login") { - # elsif ($mechanism eq "login") { - # if ( $prekey ) { - # ($passHash, $user, $passClear) = split /\x0/, decode_base64($prekey); - # } - # else { - # - # $session->respond(334, encode_base64("User Name:")); - # $user = decode_base64(<>); - # #warn("Debug: User: '$user'"); - # if ($user eq '*') { - # $session->respond(501, "Authentification canceled"); - # return DECLINED; - # } - # - # $session->respond(334, encode_base64("Password:")); - # $passClear = <>; - # $passClear = decode_base64($passClear); - # #warn("Debug: Pass: '$pass'"); - # if ($passClear eq '*') { - # $session->respond(501, "Authentification canceled"); - # return DECLINED; - # } - # } - # } + if ( $prekey ) { + ($passHash, $user, $passClear) = split /\x0/, decode_base64($prekey); + } + else { + + $session->respond(334, e64("Username:")); + $user = decode_base64(<>); + #warn("Debug: User: '$user'"); + if ($user eq '*') { + $session->respond(501, "Authentification canceled"); + return DECLINED; + } + + $session->respond(334, e64("Password:")); + $passClear = <>; + $passClear = decode_base64($passClear); + #warn("Debug: Pass: '$pass'"); + if ($passClear eq '*') { + $session->respond(501, "Authentification canceled"); + return DECLINED; + } + } + } elsif ( $mechanism eq "cram-md5" ) { # rand() is not cryptographic, but we only need to generate a globally