[Mimedefang] md check agains lmtp (Cyrus LMTP)

sendmail-admin at spiresfamily.com sendmail-admin at spiresfamily.com
Thu Jun 14 00:10:00 EDT 2007


I do exactly this with my server setup using the following snippets from my 
mimedefang-filter:

I've been running this for almost a year without trouble.

Hope this is helpful.

-Tyler

sub filter_recipient {

    my ($recipient, $sender, $hostip, $hostname, $first, $helo, 
$rcpt_mailer, $rcpt_host, $rcpt_addr) = @_;
    my $debug = 0;

    if ( $debug eq 1 ) {
       md_syslog( 'info', "$QueueID: Entering filter_recipient()" );
       md_syslog( 'info', "$QueueID: recipient: $recipient" );
       md_syslog( 'info', "$QueueID: sender: $sender" );
       md_syslog( 'info', "$QueueID: hostip: $hostip" );
       md_syslog( 'info', "$QueueID: first: $first" );
       md_syslog( 'info', "$QueueID: rcpt_mailer: $rcpt_mailer" );
       md_syslog( 'info', "$QueueID: rcpt_host: $rcpt_host" );
       md_syslog( 'info', "$QueueID: rcpt_addr: $rcpt_addr" );
    }

    # For Testing purposes.
    # if ( $recipient ne '<test at spiresfamily.com>' ) {
    #    return( 'CONTINUE', 'OK' );
    # }

    #
    # If the 'mailer' is not the cyrusv2 mailer,
    # then we'll let Sendmail wory about checking
    # the recipients.
    #
    # All LOCAL mailboxes should use the cyrusv2 mailer
    # except for mailing-lists which use the 'mailman'
    # mailer, which we don't want to check here; let
    # Sendmail & Mailman worry about those for now.
    if ( $rcpt_mailer ne "cyrusv2" ) {
       md_syslog( 'info', "$QueueID: Mailer is not cyrusv2, mailer is: 
$rcpt_mailer" );
       return( 'CONTINUE', 'OK' );
    }

    #
    # I'm not sure how we could get here without a
    # rcpt_addr (ie - an address after parse3).
    #
    # However, if we do, let sendmail worry about it.
    if ( !$rcpt_addr ) {
       md_syslog( 'err', "$QueueID: ERROR: the rcpt_addr is not set, 
accepting message.");
       return( 'CONTINUE', 'OK' );
    }

    #
    # Check to see if the mailbox exists in the
    # Cyrus Realm.
    my $mailboxExists = 0;
    $rcpt_addr = &canonicalize_email( $rcpt_addr );
    $mailboxExists = &verifyCyrusMailbox( $rcpt_addr );

    #
    # If the mailbox does exist, accept the message.
    if ( $mailboxExists eq 1 ) {
       return( 'CONTINUE', 'OK' );
    }

    #
    # Otherwise reject the message as an unknown mailbox.
    # I would prefer to 'discard' the message, however,
    # that seems to get a little sticky when there are
    # mutiple RCPT TO: commands, if one is discarded, then
    # they all are, which is not the behavior I want.
    # So for lack of anything better, just reject the
    # message.
    md_syslog( 'info', "$QueueID: Rejecting $recipient... Unknown Mailbox" );
    return('REJECT', "$recipient... Unknown Mailbox");
}

sub canonicalize_email ($) {
    my($email) = @_;
    # Remove angle-brackets; convert to lower-case
    $email =~ s/^<//;
    $email =~ s/>$//;
    $email = lc($email);
    return $email;
}
sub verifyCyrusMailbox {

    use strict;
    use IO::Socket::UNIX;

    my $mailbox = shift;
    my $output = 0;

    #
    # Make sure that there is an input argument.
    if ( "missing$mailbox" eq "mailbox" ) {
       syslog( 'err', "ERROR: mailbox argument required\n" );
       return($output);
    }

    my $filename = '/var/extra/imap/socket/lmtp';
    my $sock = new IO::Socket::UNIX (
            'Peer' => $filename,
            'Type' => SOCK_STREAM
    );

    if (!$sock){
       syslog( 'err', "ERROR: Could not attach to socket: ($filename)" );
       #print("could not attach to socket: $filename");
       return($output);
    }

    my $return;
    $sock->send("LHLO localhost\n");
    $sock->recv($return, 256);
    #mta_syslog($LOG_DEBUG, "LHLO Results: $return");

    $sock->send("MAIL FROM:<>" . "\n");
    $sock->recv($return, 256);
    #mta_syslog($LOG_DEBUG, "MAIL FROM Results: $return");

    $sock->send("RCPT TO:<$mailbox>" . "\n");
    $sock->recv($return, 256);
    #mta_syslog( $LOG_DEBUG, "RCPT TO:<$mailbox>" . "\n");
    #mta_syslog( $LOG_DEBUG, "RCPT TO: Results: $return");

    $sock->send("QUIT\n");

    if ($return =~ /^2/) {
       $output = 1;
    }
    return( $output );
}


Nels Lindquist wrote:
> Yizhar Hurwitz wrote:
> 
>> Can I ask for a new feature, which is the same as md_check_against_smtp,
>> but works against Cyrus IMAP (or other) LMTP server instead of SMTP
>> which is installed on the same machine?
> 
> I'm a little unclear what you're asking for here.  You want to check
> against local LMTP rather than remote SMTP?
> 
> Why not just let Sendmail reject unknown recipients using a Cyrus socketmap?
> 
> Have you looked at Andrzej Filip's realtime Cyrus integration stuff?  It
> can be found here:
> 
> http://anfi.homeunix.net/sendmail/rtcyrus2.html
> 
> Nels Lindquist
> _______________________________________________
> NOTE: If there is a disclaimer or other legal boilerplate in the above
> message, it is NULL AND VOID.  You may ignore it.
> 
> Visit http://www.mimedefang.org and http://www.roaringpenguin.com
> MIMEDefang mailing list MIMEDefang at lists.roaringpenguin.com
> http://lists.roaringpenguin.com/mailman/listinfo/mimedefang



More information about the MIMEDefang mailing list