[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Auth-Methoden von Mailservern



Hallo Kai,
ich habe mal noch SSL und TLS eingebaut, kannst es ja zerbasteln wie
Du's braucht. Das müsste alle Fälle abdecken, ist aber jetzt nur mal
schnell zusammengehackt.

,----------------
| #! /usr/bin/perl
| use strict;
| use warnings;
| use Sys::Hostname;
| use IO::Socket::INET;
| use IO::Socket::SSL;
| 
| use Getopt::Long;
| 
| my $opt_ssl   = 0;
| my $opt_debug = 0;
| 
| sub check_auth($$;\$);
| 
| GetOptions(
|     "d|debug" => \$opt_debug,
|     "s|ssl"   => \$opt_ssl,
| ) or die "bad usage\n";
| 
| my $HOSTNAME = hostname();
| my $REMOTE = shift or die "need remote host[:port]\n";
| 
| $REMOTE .= $opt_ssl ? ":465" : ":25" if not $REMOTE =~ /:/;
| 
| warn "connecting to $REMOTE\n" if $opt_debug;
| my $s =
|   $opt_ssl
|   ? new IO::Socket::SSL($REMOTE)
|   : new IO::Socket::INET($REMOTE)
|   or die "Can't open socket to $REMOTE\n";
| 
| # Get the greeting and even expect continuation lines
| # I do not know if they may appear in the greeting, probably not,
| # because it's feature of ESMTP and the server doesn't know if the
| # client would understand it)
| 
| while (<$s>) { last if /^\d{3}\s/ }
| 
| # Do not continue on any error
| /^2/ or die "expected 2xx\n";
| 
| # Do not continue if the server does not speak ESMTP
| /ESMTP/ or die "expected ESMTP";
| 
| # first attempt plain (or SSL)
| print map { "$_\n" } check_auth( $s, $HOSTNAME );
| 
| # if still not closed we should try STARTTLS
| if ( $s->connected ) {
|     warn "trying STARTTLS\n" if $opt_debug;
| 
|     print {$s} "STARTTLS\r\n";
|     while (<$s>) { last if /^\d{3}\s/ }
|     /^2.. TLS/ or die "can't start TLS: $_";
| 
|     IO::Socket::SSL->start_SSL($s);
|     print map { "$_\n" } check_auth( $s, $HOSTNAME );
| }
| 
| sub check_auth($$;\$) {
|     my ( $socket, $hostname, $tls ) = @_;
|     my $close = 1;
|     my @auth;
| 
|     print {$socket} "EHLO $HOSTNAME\r\n";
| 
|     my $prefix = ref($socket) =~ /::SSL$/ ? "ssl" : "plain";
| 
|     # Parse the response to the EHLO
|     while (<$socket>) {
|         print STDERR if $opt_debug;
|         /STARTTLS/ and $close = 0;
|         push @auth, map { "$prefix:$_" } split if s/^.*AUTH\s+//;
|         last if /^\d{3}\s/;    # last line
|     }
| 
|     if ($close) {
|         print {$socket} "QUIT\r\n";
|         $socket->close;
|     }
| 
|     return @auth;
| }
| 
| exit 0;
`---------

    Best regards from currently Atlanta (Georgia/USA)
    Viele Grüße aus z.Z. Atlanta
    Heiko Schlittermann
-- 
 SCHLITTERMANN.de ---------------------------- internet & unix support -
 Heiko Schlittermann HS12-RIPE -----------------------------------------
 gnupg encrypted messages are welcome - key ID: 48D0359B ---------------
 gnupg fingerprint: 3061 CFBF 2D88 F034 E8D2  7E92 EE4E AC98 48D0 359B -

Attachment: signature.asc
Description: Digital signature


Reply to: