libnet-smtpauth-perl-0.08/0000755000175000017500000000000010361746166014475 5ustar nachonacholibnet-smtpauth-perl-0.08/eg/0000755000175000017500000000000007703504605015064 5ustar nachonacholibnet-smtpauth-perl-0.08/eg/smtp-tester.pl0000755000175000017500000000561107703255417017722 0ustar nachonacho#!/usr/bin/perl # # Simple SMTP-tester # (c) alex pleiner, zeitform Internet Dienste 2001, 2003 # alex@zeitform.de # # this tool will connect to a SMTP Server and authenticate using # either no authentication or SMTP_AUTH (RFC2554) # # LICENSE: # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # # Get the GPL from: http://www.gnu.org/licenses/gpl.html ############################################### my $default_host = 'mail.zeitform.de'; my $default_touser = 'alex@zf2.de'; my $default_fromuser = 'alex@zf2.de'; my $default_auth = 'CRAM-MD5'; # try NONE, PLAIN or LOGIN ############################################### use lib "/home/ciphelp/perl"; use Getopt::Std; use Net::SMTP_auth; print "-"x70, "\nsmtp-tester (c) alex pleiner, zeitform Internet Dienste 2001, 2003\n", "usage: smtptest [-v] -h host -m method -t recipient -f sender/local -p password\n\n"; getopts('vh:t:f:p:m:'); my $debug = 1 if $opt_v; my $host = $opt_h || get_value("SMTP Server ", $default_host); my $touser = $opt_t || get_value("recipient ", $default_touser); my $fromuser = $opt_f || get_value("sender/local ", $default_fromuser); ## show auth methods my $smtp = Net::SMTP_auth->new($host, Timeout => 60, Hello => "me", Debug => $debug); print "possible auth-types are: NONE ", scalar($smtp->auth_types()), "\n"; my $auth = $opt_m || get_value("AUTH method", $default_auth); my $pass = $opt_p || get_value("password ", "", 1); ### authenticate print "\n", "-"x70, "\nSMTP (AUTH $auth) on $host ($fromuser -> $touser)...\n"; if (uc($auth) ne "NONE") { $ok = $smtp->auth($auth, $fromuser, $pass); $message = $smtp->message(); chomp ($message); } else { $ok = 1; } if ($ok) { $ok = $smtp->mail($fromuser); $message = $smtp->message(); chomp ($message); if ($ok) { $ok = $smtp->to($touser); $message = $smtp->message(); chomp ($message); } } $smtp->quit; if ($ok) { print "... works fine\n"; } else { print "... failed with message:\n$message\n"; } print "-"x70, "\n"; ### sub land sub get_value { my ($text, $default, $noecho) = @_; print "$text [$default]: "; system "stty -echo" if $noecho; my $value= <>; system "stty echo" if $noecho; chomp $value; return $value || $default; } ###-fin- libnet-smtpauth-perl-0.08/SMTP_auth.pm0000644000175000017500000001343110361746166016641 0ustar nachonacho# Net::SMTP_auth.pm # # alex pleiner 2001, 2003, 2006 zeitform Internet Dienste # thanks to Graham Barr for Net::SMTP # This program is free software; you can redistribute it and/or # modify it under the same terms as Perl itself. # Net::SMTP_auth is a small extension to G. Barr's Net::SMTP # to authenticate to an SMTP server using one of the AUTH # methods provided by Authen::SASL and Authen::NTLM (see RFC2554 for details). # This module can be expanded and is a very first implementation. package Net::SMTP_auth; require 5.001; use strict; use vars qw($VERSION @ISA); use Socket 1.3; use Carp; use IO::Socket; use Net::Cmd; use Net::Config; use Net::SMTP; use MIME::Base64; use Digest::HMAC_MD5 qw(hmac_md5_hex); use Authen::SASL; $VERSION = "0.08"; @ISA = qw(Net::SMTP); # all other method taken from Net::SMTP sub auth_types { @_ == 1 or croak 'usage: $pop3->auth_types()'; my $me = shift; if (exists ${*$me}{'net_smtp_esmtp'}) { my $esmtp = ${*$me}{'net_smtp_esmtp'}; if(exists $esmtp->{AUTH}) { return wantarray ? split(/\s+/, $esmtp->{AUTH}) : $esmtp->{AUTH}; } } return; } sub auth { @_ == 4 or croak 'usage: $smtp->auth( AUTH, USER, PASS )'; my ($me, $auth, $user, $pass) = @_; # code by James Fryman if ($auth eq "NTLM") { eval "require Authen::NTLM" or croak 'NTLM not supported. Install Authen::NTLM.'; my $host = ${*$me}{'net_smtp_host'}; Authen::NTLM::ntlm_user($user); ## Init NTLM Variables Authen::NTLM::ntlm_password($pass); my $ntlm_chal = Authen::NTLM::ntlm(); $me->_AUTH("$auth $ntlm_chal"); if ( $me->code() == 334 ) { my $chal = $me->message(); my $ntlm_chal_resp = Authen::NTLM::ntlm($chal); $me->command($ntlm_chal_resp)->response(); Authen::NTLM::ntlm_reset(); return 1 if $me->code() == 235; return if $me->code() == 535; } return; } my $sasl = Authen::SASL->new( mechanism => uc($auth), callback => { authname => $user, user => $user, pass => $pass, }, ); return unless $sasl; my $host = ${*$me}{'net_smtp_host'}; my $conn = $sasl->client_new("smtp", $host);#, "noplaintext noanonymous"); $me->_AUTH($auth) or return; if ( $me->code() == 334 ) { if (my $initial = $conn->client_start) { $me->command(encode_base64($initial, ''))->response(); return 1 if $me->code() == 235; } while ( $me->code() == 334 ) { my $message = decode_base64($me->message()); my $return = $conn->client_step($message); $me->command(encode_base64($return, ''))->response(); return 1 if $me->code() == 235; return if $me->code() == 535; } } } sub _AUTH { shift->command("AUTH", @_)->response() == CMD_MORE } 1; __END__ =head1 NAME Net::SMTP_auth - Simple Mail Transfer Protocol Client with AUTHentication =head1 SYNOPSIS use Net::SMTP_auth; # Constructors $smtp = Net::SMTP_auth->new('mailhost'); $smtp = Net::SMTP_auth->new('mailhost', Timeout => 60); =head1 DESCRIPTION This module implements a client interface to the SMTP and ESMTP protocol AUTH service extension, enabling a perl5 application to talk to and authenticate against SMTP servers. This documentation assumes that you are familiar with the concepts of the SMTP protocol described in RFC821 and with the AUTH service extension described in RFC2554. A new Net::SMTP_auth object must be created with the I method. Once this has been done, all SMTP commands are accessed through this object. The Net::SMTP_auth class is a subclass of Net::SMTP, which itself is a subclass of Net::Cmd and IO::Socket::INET. =head1 EXAMPLES This example authenticates via CRAM-MD5 and sends a small message to the postmaster at the SMTP server known as mailhost: #!/usr/bin/perl -w use Net::SMTP_auth; $smtp = Net::SMTP_auth->new('mailhost'); $smtp->auth('CRAM-MD5', 'user', 'password'); $smtp->mail($ENV{USER}); $smtp->to('postmaster'); $smtp->data(); $smtp->datasend("To: postmaster\n"); $smtp->datasend("\n"); $smtp->datasend("A simple test message\n"); $smtp->dataend(); $smtp->quit; =head1 CONSTRUCTOR =over 4 =item new Net::SMTP_auth [ HOST, ] [ OPTIONS ] This is the constructor for a new Net::SMTP_auth object. It is taken from Net::SMTP as all other methods (except I and I) are, too. =head1 METHODS Unless otherwise stated all methods return either a I or I value, with I meaning that the operation was a success. When a method states that it returns a value, failure will be returned as I or an empty list. =over 4 =item auth_types () Returns the AUTH methods supported by the server as an array or in a space separated string. This string is exacly the line given by the SMTP server after the C command containing the keyword C. =item auth ( AUTH, USER, PASSWORD ) Authenticates the user C via the authentication method C and the password C. Returns I if successful and I if the authentication failed. Remember that the connection is not closed if the authentication fails. You may issue a different authentication attempt. If you once are successfully authenticated, you cannot send the C command again. The C method C is supported via Authen::NTLM (thanks to James Fryman). =back =head1 SEE ALSO L and L =head1 AUTHOR Alex Pleiner , zeitform Internet Dienste. Thanks to Graham Barr for Net::SMTP. NTLM authentication code provided by James Fryman =head1 COPYRIGHT Copyright (c) 2001, 2003, 2006 zeitform Internet Dienste. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =cut libnet-smtpauth-perl-0.08/README0000644000175000017500000000352110361705440015344 0ustar nachonachoCopyright (c) 2003, 2006 Alex Pleiner - zeitform Internet Dienste. alex@zeitform.de - http://www.zeitform.de. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. Note: This version requires Authen::SASL. If you want to want to go without, use version Net::SMTP_auth 0.05. FURTHER NOTE: Net::SMTP can do authentication by itself (with a different Syntax) Can someone please provide me with a SMTP account on a maschine using DIGEST-MD5 or NTLM for testing? -------- Abstract -------- Net::SMTP_auth is a small extension to G. Barr's Net::SMTP to authenticate to an SMTP server using one of the AUTH methods provided by Authen::SASL (see RFC2554 for details). This module can be expanded and is a very first implementation. ------------ Requirements ------------ This module requires: - Net::SMTP (should be obvious) - MIME::Base64 - Digest::HMAC_MD5 - Authen::SASL - Authen::NTLM (optional for NTLM) The requirements are encoded in Makefile.PL. ------------------ Basic Installation ------------------ Net::SMTP_auth may be installed through the CPAN shell in the usual CPAN shell manner. This typically is: $ perl -MCPAN -e 'install Net::SMTP_auth' You can also read this README from the CPAN shell: $ perl -MCPAN -e shell cpan> readme Net::SMTP_auth And you can install the component from the CPAN prompt as well: cpan> install Net::SMTP_auth ------------------- Manual Installation ------------------- Net::SMTP_auth can also be installed manually. Download the package from: http://alex.zeitform.de/smtp_auth/ Downloading and unpacking the distribution are left as exercises for the reader. To build and test it: perl Makefile.PL make test When you're ready to install the component: make install It should now be ready to use. libnet-smtpauth-perl-0.08/Changes0000644000175000017500000000156310361705551015766 0ustar nachonachoRevision history for Perl extension Net::SMTP_auth. 0.08 Fri Jan 13 12:12:57 CET 2006 - added authentication via NTLM (James Fryman) 0.07 Don Aug 7 18:23:51 CEST 2003 - After upgraing Net:SMTP to version 2.26 I noticed that authentication was broken (the response of AUTH does not equal CMD_OK anymore but CMD_MORE). - PLEASE NOTE: Net::SMTP can handle authentication by its own. 0.06 Fre Jul 11 18:36:37 CEST 2003 - changed MIME::Base64 function calls - changed authentication to use Authen::SASL instead of selfmade routines. I currently tested only CRAM-MD5, LOGIN and PLAIN. Can someone please provide me with a SMTP account on a maschine using DIGEST-MD5 or NTLM? 0.05 Thu Jul 10 10:48:41 2003 - original version; created by h2xs 1.20 with options -AXc -n Net::SMTP_auth libnet-smtpauth-perl-0.08/test.pl0000644000175000017500000000122307703224151015776 0ustar nachonacho# Before `make install' is performed this script should be runnable with # `make test'. After `make install' it should work as `perl test.pl' ######################### We start with some black magic to print on failure. # Change 1..1 below to 1..last_test_to_print . # (It may become useful if the test is moved to ./t subdirectory.) BEGIN { $| = 1; print "1..1\n"; } END {print "not ok 1\n" unless $loaded;} use Net::SMTP_auth; $loaded = 1; print "ok 1\n"; ######################### End of black magic. # Insert your test code below (better if it prints "ok 13" # (correspondingly "not ok 13") depending on the success of chunk 13 # of the test code): libnet-smtpauth-perl-0.08/Makefile.PL0000644000175000017500000000076307714476767016474 0ustar nachonacho#!/usr/bin/perl use ExtUtils::MakeMaker; WriteMakefile( 'NAME' => 'Net::SMTP_auth', 'AUTHOR' => 'Alex Pleiner ', 'ABSTRACT' => 'SMTP_AUTH wrapper for Net::SMTP (rfc2554)', 'VERSION_FROM' => 'SMTP_auth.pm', # finds $VERSION 'PREREQ_PM' => { Net::SMTP => 2.26, MIME::Base64 => 2.00, Digest::HMAC_MD5 => 1.00, Authen::SASL => 2.03, }, ); libnet-smtpauth-perl-0.08/MANIFEST0000644000175000017500000000011407703564427015626 0ustar nachonachoChanges MANIFEST Makefile.PL SMTP_auth.pm test.pl README eg/smtp-tester.pl