POP before SMTP con Sendmail y Qpopper

by Jorge Machin on October 26, 2008 · 0 comments

in Fedora, Linux

Ls solución de POP before SMTP que utilizaba en mis años mozos en Interalia estaba basada enpoprelay, qpopper como servidor pop y sendmail como mi servidor SMTP.

Aunque es cierto que la utilizaba hace mucho tiempo (2001?) y actualmente hay muchas otras opciones, se puede comprobar que sigue siendo una opción válida y efectiva.

Instalación de qpopper

Los fuentes se compilan de la siguiente forma:

./configure --enable-specialauth
make
cp popper/popper /usr/local/bin

Finalmente declaramos el servicio en xinetd, creando el archivo /etc/xinetd.d/qpopper :

service pop3
{
socket_type = stream
protocol = tcp
wait = no
user = root
server = /usr/local/bin/popper
server_args = qpopper –s
port = 110
}

Y reiniciamos xinetd:

/etc/rc.d/init.d/xinetd restart

Poprelay

El código fuente de Poprelay se pueden encontrar en Sourceforge.

Una vez instalado, para hacerlo funcionar con sendmail, se debe integrar el siguiente código al archivo de configuración /etc/sendmail.mc:

# We probably want the access_db feature enabled.

FEATURE(access_db)dnl

# List of IP addresses we allow relaying from.

Klocalip hash -a<MATCH> /etc/mail/localip
Kpopip hash  -a<MATCH> /etc/mail/popip

LOCAL_RULESETS

SLocal_check_rcpt

# Put the address into cannonical form (even if it doesn't resolve to an MX).

R$*   $: $>Parse0 $>3 $1
R$* <$*> $*  $: $1 <$2 .> $3      Pretend it's canonical.
R$* <$* . .> $*  $1 <$2 .> $3   Remove extra dots.

# Allow relaying if the connected host is a local IP address.

R$*   $: <$&{client_addr}>  Get client IP address.
R<>   $#OK    Local is ok.
R<$* . $-> $*      $(localip $1.$2 $: <$1> . $2 $)    Check last three octets.
R$* <MATCH>  $#OK
R<$-> $*        $: $(localip $1 $: <> $1 $2 $)    Check first octet.
R$* <MATCH>  $#OK

# Allow relaying if the connected host has recently POP3 authenticated.

R$*   $: <$&{client_addr}>  Get client IP address.
R<$*>       $(popip $1 $)   Check full address.
R$* <MATCH>  $#OK

# IP address didn't match.

Recreamos el archivo /etc/sendmail.cf con:

m4 /etc/sendmail.mc> /etc/sendmail.cf

Crear el archivo /etc/mail/localip el cual contiene una lista de todas las direcciones IP y redes que se les va a permitir hacer relay sin autentificacion.

touch /etc/mail/localip

Crear el archivo /etc/mail/popip:

makemap hash /etc/mail/popip </dev/null

Modificar la función scanaddr del archivo /sbin/poprelayd según la versión del servidor de correo POP:

qpoper 2.5X

sub scanaddr ($) {
   local $s, $i, @adressen;
   $s = $_[0];
   $i = index ($s,'popper');
   undef @adressen;
   if ($i>=0){
   ($s =~  /.*?popper.*?POP login.*?(d{1,3}.d{1,3}.d{1,3}.d{1,3})/) && (push (@adressen,$1));     
   }
   return @adressen;
}

qpoper 3.X o posterior:

sub scanaddr ($) {
   local $s, $i, @adressen;
   $s = $_[0];
   $i = index ($s,'popper');
   undef @adressen;
   if ($i>=0){
   ($s =~  /.*?popper.*?(d{1,3}.d{1,3}.d{1,3}.d{1,3})/) && (push (@adressen,$1));     
   }
   return @adressen;
}

En la versión 4 de qpopper se debe agregar esta función:

sub log_parse_qpopper_new ($) {
   local $s,$i,@adressen;
   $s = $_[0];
   $i = index($s,'popper');
   undef @adressen;
   if ($i>=0){
   ($s =~ /.*?popper.*?(d{1,3}.d{1,3}.d{1,3}.d{1,3})/) && (push (@adressen,$1));
   }
   return @adressen;
}

Levantar el demonio y colocarlo en /etc/rc.d/rc.local:

poprelay -d

o bien hacer un archivo de inicialización:

#!/bin/bash
#
# Init file for poprelay server daemon
#
# chkconfig: 2345 55 25
# description: pop/imap client relay deamon
#
# processname: poprelayd
# pidfile: /var/run/poprelayd.pid

# source function library
. /etc/rc.d/init.d/functions

# pull in sysconfig settings

RETVAL=0
POPRD="/sbin/poprelayd";
prog="poprelayd"

start()
{
        echo -n $"Starting $prog:"
        initlog -c "$POPRD -d" && success || failure
        RETVAL=$?
        [ "$RETVAL" = 0 ] && touch /var/lock/subsys/poprelayd
        echo
}

stop()
{
        echo -n $"Stopping $prog:"
        killproc $POPRD -TERM
        RETVAL=$?
        [ "$RETVAL" = 0 ] && rm -f /var/lock/subsys/poprelayd
        echo
}

reload()
{
        echo -n $"Reloading $prog:"
        killproc $POPRD -HUP
        RETVAL=$?
        echo
}

check()
{
        PROCS=`ps -ef | grep "poprelayd -d" | grep -v grep | wc -l`
        if [ $PROCS -ne 1 ]; then
        echo "Restarting dead poprelayd: $PROCS running";
                stop;
                start;
        fi
}

case "$1" in
        start)
                start
                ;;
        stop)
                stop
                ;;
        restart)
                stop
                start
                ;;
        reload)
                reload
                ;;
        check)
                check
                ;;
        *)
                echo $"Usage: $0 {start|stop|restart|reload|condrestart|status}"
                RETVAL=1
esac
exit $RETVAL

Leave a Comment

Previous post:

Next post: