[patch] smtp-forward: allow FQDNs and IP-Addrs and add error handling

2003-09-08 Thread Peter J. Holzer
The pod for the smtp-forward plugin says:

| CONFIG
|It takes one required parameter, the IP address or hostname to
|forward to.
| 
|  queue/smtp-forward 10.2.2.2
| 

Unfortunately, that doesn't work because . isn't allowed in the
hostname parameter. 

Also, code for sending the mail to the smtp server only checked whether
opening the connection and the quit command worked. Errors to all other
smtp commands were ignored which could cause mail to be silently
dropped.

This patch fixes both problems. However, I'm not happy with the SMTP
fix. It simply returns a DECLINED on all errors, which causes a
temporary failure, which is not appropriate in many cases, especially
not for 5xx replies to rcpt to. In this case the mail should bounce!

You must make sure that non-existent users are already caught before the
smtp-forward module is called. 

hp

-- 
   _  | Peter J. Holzer| Humor ohne Emoticons ist trockener Humor.
|_|_) | Sysadmin WSR   | 
| |   | [EMAIL PROTECTED] | -- Toni Grass in aip
__/   | http://www.hjp.at/ |
Index: plugins/queue/smtp-forward
===
--- plugins/queue/smtp-forward  (revision 1)
+++ plugins/queue/smtp-forward  (working copy)
@@ -26,7 +26,7 @@
   $self-register_hook(queue, queue_handler);
 
   if (@args  0) {
-if ($args[0] =~ /^([\w_-]+)$/) {
+if ($args[0] =~ /^([.\w_-]+)$/) {
   $self-{_smtp_server} = $1;
 }
 else {
@@ -52,15 +52,17 @@
 Port = $self-{_smtp_port},
 Timeout = 60,
) || die $!;
-  $smtp-mail( $transaction-sender-address ||  );
-  $smtp-to($_-address) for $transaction-recipients;
-  $smtp-data();
-  $smtp-datasend($transaction-header-as_string);
+  $smtp-mail( $transaction-sender-address ||  ) or return(DECLINED, Unable to 
queue message ($!));
+  for ($transaction-recipients) {
+$smtp-to($_-address) or return(DECLINED, Unable to queue message ($!));
+  }
+  $smtp-data() or return(DECLINED, Unable to queue message ($!));
+  $smtp-datasend($transaction-header-as_string) or return(DECLINED, Unable to 
queue message ($!));
   $transaction-body_resetpos;
   while (my $line = $transaction-body_getline) {
-$smtp-datasend($line);
+$smtp-datasend($line) or return(DECLINED, Unable to queue message ($!));
   }
-  $smtp-dataend();
+  $smtp-dataend() or return(DECLINED, Unable to queue message ($!));
   $smtp-quit() or return(DECLINED, Unable to queue message ($!));
   $self-log(1, finished queueing);
   return (OK, Queued!);



pgp0.pgp
Description: PGP signature


[patch] spamassassin: spamc-like headers

2003-09-08 Thread Peter J. Holzer
This patch makes the headers more like those added by spamc. It also
fixes a real bug, but I forgot what that was :-)

hp

-- 
   _  | Peter J. Holzer| Humor ohne Emoticons ist trockener Humor.
|_|_) | Sysadmin WSR   | 
| |   | [EMAIL PROTECTED] | -- Toni Grass in aip
__/   | http://www.hjp.at/ |
Index: plugins/spamassassin
===
--- plugins/spamassassin(revision 1)
+++ plugins/spamassassin(working copy)
@@ -81,6 +81,7 @@
 sub check_spam {
   my ($self, $transaction) = @_;
 
+  $self-log(6, check_spam);
   return (DECLINED) if $transaction-body_size  500_000;
 
   my $remote  = 'localhost';
@@ -97,12 +98,13 @@
 
   connect(SPAMD, $paddr) 
 or $self-log(1, Could not connect to spamassassin daemon: $!) and return 
DECLINED;
+  $self-log(6, check_spam: connected to spamd);
 
   SPAMD-autoflush(1);
   
   $transaction-body_resetpos;
   
-  print SPAMD REPORT_IFSPAM SPAMC/1.0 . CRLF;
+  print SPAMD SYMBOLS SPAMC/1.0 . CRLF;
   # or CHECK or REPORT or SYMBOLS
 
   print SPAMD join CRLF, split /\n/, $transaction-header-as_string
@@ -119,21 +121,33 @@
 
   print SPAMD CRLF;
   shutdown(SPAMD, 1);
+  $self-log(6, check_spam: finished sending to spamd);
   my $line0 = SPAMD; # get the first protocol lines out
   if ($line0) {
+$self-log(6, check_spam: spamd: $line0);
 $transaction-header-add(X-Spam-Check-By, $self-qp-config('me'));
   }
 
+  my ($flag, $hits, $required);
   while (SPAMD) {
+$self-log(6, check_spam: spamd: $_);
 #warn GOT FROM SPAMD1: $_;
-next unless m/\S/;
-s/\r?\n$/\n/;
-my @h = split /: /, $_, 2;
-
-$transaction-header-add(@h);
-last if $h[0] eq Spam and $h[1] =~ m/^False/;
+last unless m/\S/;
+if (m{Spam: (True|False) ; (-?\d+\.\d) / (-?\d+\.\d)}) {
+   ($flag, $hits, $required) = ($1, $2, $3);
+}
 
   }
+  my $tests = SPAMD;
+  $flag = $flag eq 'True' ? 'Yes' : 'No';
+  $self-log(6, check_spam: finished reading from spamd);
+
+  $transaction-header-add('X-Spam-Flag', 'YES') if ($flag eq 'Yes');
+  $transaction-header-add('X-Spam-Status',
+   $flag, hits=$hits required=$required\n .
+   \ttests=$tests);
+  $self-log(5, check_spam: $flag, hits=$hits, required=$required,  .
+tests=$tests);
 
   return (DECLINED);
 }



pgp0.pgp
Description: PGP signature


[patch] Qpsmtpd::TcpServer: Allow running qpsmtpd from xinetd

2003-09-08 Thread Peter J. Holzer
This patch allows running from xinetd and inetd.

Inetd is distributed with almost all Unix versions. Xinetd with most
current Linux distributions. Both lack some features that tcpserver has
(inetd more than xinetd), but for those which want to run qpsmtpd
without qmail (I now have it running with qmail, sendmail and postfix on
different machines), being able to run it without having to install yet
another server may outweigh the disadvantages.

(personally, I wouldn't recommend inetd, but xinetd does everything I
need).

hp

-- 
   _  | Peter J. Holzer| Humor ohne Emoticons ist trockener Humor.
|_|_) | Sysadmin WSR   | 
| |   | [EMAIL PROTECTED] | -- Toni Grass in aip
__/   | http://www.hjp.at/ |
Index: lib/Qpsmtpd/TcpServer.pm
===
--- lib/Qpsmtpd/TcpServer.pm(revision 1)
+++ lib/Qpsmtpd/TcpServer.pm(working copy)
@@ -1,6 +1,7 @@
 package Qpsmtpd::TcpServer;
 use Qpsmtpd::SMTP;
 use Qpsmtpd::Constants;
+use Socket;
 
 @ISA = qw(Qpsmtpd::SMTP);
 use strict;
@@ -8,12 +9,24 @@
 sub start_connection {
 my $self = shift;
 
-die Qpsmtpd::TcpServer must be started by tcpserver\n
-  unless $ENV{TCPREMOTEIP};
+my ($remote_host, $remote_info, $remote_ip);
 
-my $remote_host = $ENV{TCPREMOTEHOST} || ( $ENV{TCPREMOTEIP} ? 
[$ENV{TCPREMOTEIP}] : [noip!]);
-my $remote_info = $ENV{TCPREMOTEINFO} ? [EMAIL PROTECTED] : $remote_host;
-my $remote_ip   = $ENV{TCPREMOTEIP};
+if ($ENV{TCPREMOTEIP}) {
+   # started from tcpserver (or some other superserver which
+   # exports the TCPREMOTE* variables.
+   $remote_host = $ENV{TCPREMOTEHOST} || ( $ENV{TCPREMOTEIP} ? 
[$ENV{TCPREMOTEIP}] : [noip!]);
+   $remote_info = $ENV{TCPREMOTEINFO} ? [EMAIL PROTECTED] : $remote_host;
+   $remote_ip   = $ENV{TCPREMOTEIP};
+} else {
+   # Started from inetd or similar. 
+   # get info on the remote host from the socket.
+   # ignore ident/tap/...
+   my $hersockaddr= getpeername(STDIN);
+   my ($port, $iaddr) = sockaddr_in($hersockaddr);
+   $remote_host= gethostbyaddr($iaddr, AF_INET);
+   $remote_info= $remote_host;
+   $remote_ip = inet_ntoa($iaddr);
+}
 
 # if the local dns resolver doesn't filter it out we might get
 # ansi escape characters that could make a ps axw do funny

Index: run.xi
===
--- run.xi  (revision 1)
+++ run.xi  (working copy)
@@ -0,0 +1,3 @@
+#!/bin/sh
+export HOME=/home/smtpd
+cd $HOME/qpsmtpd  ( ( ./qpsmtpd 3 )  21 | /usr/local/bin/ts  log/current ) 
31 


pgp0.pgp
Description: PGP signature


Re: [patch] Qpsmtpd::TcpServer: Allow running qpsmtpd from xinetd

2003-09-08 Thread Ask Bjørn Hansen
On Monday, Sep 8, 2003, at 03:08 America/Los_Angeles, Peter J. Holzer 
wrote:

This patch allows running from xinetd and inetd.
Very cool.

Is /usr/local/bin/ts a standard program?  Maybe we should have the 
log() thing support using syslog instead of stdout with some option.

Could you add some error checking so it'll still bail out if it's not 
running under tcpserver or (x)inetd?

Do you have a sample xinetd .d file and an inetd.conf line?  (to 
point out that run.xi should be used rather than qpsmtpd).

 - ask

--
http://www.askbjoernhansen.com/


Re: [patch] Qpsmtpd::TcpServer: Allow running qpsmtpd from xinetd

2003-09-08 Thread Peter J. Holzer
On 2003-09-08 03:29:00 -0700, Ask Bjørn Hansen wrote:
 On Monday, Sep 8, 2003, at 03:08 America/Los_Angeles, Peter J. Holzer 
 wrote:
 
 This patch allows running from xinetd and inetd.
 
 Very cool.
 
 Is /usr/local/bin/ts a standard program?

Ups, sorry, that slipped in. No, its a simple program which just prepends
a timestamp to every line I wrote some time ago. Similar to tai64n but
with a human readable format :-).

 Maybe we should have the 
 log() thing support using syslog instead of stdout with some option.

Yes, that would be nice.

 Could you add some error checking so it'll still bail out if it's not 
 running under tcpserver or (x)inetd?

Will do.


 Do you have a sample xinetd .d file and an inetd.conf line?  (to 
 point out that run.xi should be used rather than qpsmtpd).

Here they are. 

# default: on
# description: qpsmtpd is a qmail-smtpd replacement written in perl.
#
# Sample entry:
#
# type = UNLISTED is only necessary if you use a non-standard port
#
# bind may be used to bind at a specific IP address. (E.g., if
# you want sendmail/postfix/... to listen at localhost:25)
# 
# The entry assumes that there is a user smtpd and that 
# qpsmtpd is installed in /home/smtpd/qpsmtpd.

service smtp
{
type= UNLISTED
socket_type = stream
wait= no
user= smtpd
groups  = yes
server  = /home/smtpd/qpsmtpd/run.xi
log_on_failure  += USERID
disable = no
bind= 143.130.20.2
port= 25
}

# similar entry for inetd:
smtp stream tcp nowait smtpd /home/smtpd/qpsmtpd/run.xi run.xi

hp

-- 
   _  | Peter J. Holzer| Humor ohne Emoticons ist trockener Humor.
|_|_) | Sysadmin WSR   | 
| |   | [EMAIL PROTECTED] | -- Toni Grass in aip
__/   | http://www.hjp.at/ |


pgp0.pgp
Description: PGP signature


Reducing Disk Traffic

2003-09-08 Thread Robert James Kaes
Hi,
Does anyone have any ideas on how to reduce the amount of disk IO
Qpsmtpd and qmail do?  Current, my server hits the hard drive four
times for each incoming local message:

  1. Qpsmtpd in spool directory
  2. qmail queue's directories
  3. Amavis to do a virus scan
  4. qmail-local writing to the user's Maildir.

I know there's not much I can do about 2, 3, or 4, so I'm wondering if
there is some way to not have Qpsmtpd also hit the disk for the
message?  Can Qpsmtpd pipe the message directly into qmail-queue for
example, without having to write to the hard drive?

From what I can tell, qmail-smtpd simply piped the message into
qmail-queue as it received it, and if there was a problem it would
close the qmail-queue pipe early, and qmail-queue would then remove
any files it had created.  If Qpsmtpd could do something similar, it
would help with the disk IO traffic.
-- Robert

-- 
Robert James Kaes---  Flarenet Inc.  ---(519) 426-3782
 http://www.flarenet.com/consulting/
  * Putting the Service Back in Internet Service Provider *


Re: sad logfiles

2003-09-08 Thread James H. Thompson
At least in the case of qsmptd running under SpeedyCGI, each instance of qpsmtpd 
gobbles
progressively more memory for each message it processes until it finally hits the 
softlimit setting.
Does that also happen running under Pperl?


Jim

James H. Thompson
[EMAIL PROTECTED]

- Original Message -
From: Matt Sergeant [EMAIL PROTECTED]
To: Jim Winstead [EMAIL PROTECTED]
Cc: Ask Bjørn Hansen [EMAIL PROTECTED]; [EMAIL PROTECTED]
Sent: Friday, September 05, 2003 7:04 AM
Subject: Re: sad logfiles


 On 5 Sep 2003, at 17:52, Jim Winstead wrote:

  i switched to using PPerl, which helped the load average, but it got
  stuck overnight and i had to kill a single qpsmtpd process to get
  things
  going again. i'll try to figure out what caused it to get stuck if it
  happens again.

 Make sure you run with --no-cleanup. qmsmtpd is clean enough to run
 without that.

 Not sure if that will fix things.




Re: sad logfiles

2003-09-08 Thread Ask Bjørn Hansen
On Monday, Sep 8, 2003, at 17:43 America/Los_Angeles, James H. Thompson 
wrote:

At least in the case of qsmptd running under SpeedyCGI, each instance 
of qpsmtpd gobbles
progressively more memory for each message it processes until it 
finally hits the softlimit setting.
Does that also happen running under Pperl?
I've been running PPerl with perl 5.6.1 like the following for a couple 
of days; I didn't notice any memory leaking.

  pperl -Tw -- --prefork=$MAXCLIENTS --maxclients=$MAXCLIENTS 
--no-cleanup ./qpsmtpd 21

(from the ./run file).

And yes, it does speed up things. I think I'll have change my nah, 
it's fast enough so who cares opinion.  :-)

  - ask

--
http://www.askbjoernhansen.com/