-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add service and test cases for srsmilter, fix some bugs, update sampl…
…e config.
- Loading branch information
Showing
9 changed files
with
155 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,7 @@ | |
|
||
Summary: Python SRS (Sender Rewriting Scheme) library | ||
Name: %{pythonbase}-pysrs | ||
Version: 1.0.2 | ||
Version: 1.0.3 | ||
Release: 1%{?dist} | ||
Source0: pysrs-%{version}.tar.gz | ||
License: Python license | ||
|
@@ -73,9 +73,11 @@ cp pysrsprog.m4 $RPM_BUILD_ROOT/usr/share/sendmail-cf/hack | |
mkdir -p $RPM_BUILD_ROOT/var/log/milter | ||
mkdir -p $RPM_BUILD_ROOT%{_libexecdir}/milter | ||
cp -p pysrs.py $RPM_BUILD_ROOT%{_libexecdir}/milter/pysrs | ||
cp -p srsmilter.py $RPM_BUILD_ROOT%{_libexecdir}/milter/srsmilter | ||
%if %{use_systemd} | ||
mkdir -p $RPM_BUILD_ROOT%{_unitdir} | ||
cp -p pysrs.service $RPM_BUILD_ROOT%{_unitdir} | ||
cp -p srsmilter.service $RPM_BUILD_ROOT%{_unitdir} | ||
%else | ||
mkdir -p $RPM_BUILD_ROOT/etc/rc.d/init.d | ||
cp %{sysvinit} $RPM_BUILD_ROOT/etc/rc.d/init.d/pysrs | ||
|
@@ -140,6 +142,9 @@ fi | |
%endif | ||
|
||
%changelog | ||
* Mon Nov 13 2017 Stuart Gathman <[email protected]> 1.0.3-1 | ||
- Include srsmilter | ||
|
||
* Tue Nov 3 2017 Stuart Gathman <[email protected]> 1.0.2-1 | ||
- Fix daemon to run in python2 | ||
- Move daemons to /usr/libexec/milter so they get bin_t selinux label | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
[Unit] | ||
Description=Python SRS milter | ||
Wants=network.target | ||
After=network-online.target sendmail.service | ||
|
||
[Service] | ||
Type=simple | ||
WorkingDirectory=/var/log/milter | ||
User=mail | ||
Group=mail | ||
SyslogIdentifier=srsmilter | ||
ExecStart=/usr/libexec/milter/srsmilter | ||
|
||
[Install] | ||
WantedBy=multi-user.target |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,20 +27,80 @@ | |
# Translated to Python by [email protected] | ||
# http://bmsi.com/python/milter.html | ||
# | ||
# Copyright (c) 2017 Stuart Gathman All rights reserved. | ||
# Portions Copyright (c) 2004 Shevek. All rights reserved. | ||
# Portions Copyright (c) 2004 Business Management Systems. All rights reserved. | ||
# Portions Copyright (c) 2004,2006 Business Management Systems. All rights reserved. | ||
# | ||
# This program is free software; you can redistribute it and/or modify | ||
# it under the same terms as Python itself. | ||
|
||
import unittest | ||
import Milter | ||
from Milter.test import TestBase | ||
from SRS.Guarded import Guarded | ||
from SRS.DB import DB | ||
from SRS.Reversible import Reversible | ||
from SRS.Daemon import Daemon | ||
import srsmilter | ||
import SRS | ||
import threading | ||
import socket | ||
try: | ||
from StringIO import StringIO | ||
except: | ||
from io import StringIO | ||
|
||
class TestMilter(TestBase,srsmilter.srsMilter): | ||
def __init__(self): | ||
TestBase.__init__(self) | ||
srsmilter.config = srsmilter.Config(['pysrs.cfg']) | ||
srsmilter.srsMilter.__init__(self) | ||
self.setsymval('j','test.milter.org') | ||
|
||
class SRSMilterTestCase(unittest.TestCase): | ||
|
||
msg = '''From: [email protected] | ||
Subject: test | ||
test | ||
''' | ||
|
||
## Test rejecting bounce spam | ||
def testReject(self): | ||
milter = TestMilter() | ||
milter.conf.srs_domain = set(['example.com']) | ||
milter.conf.srs_reject_spoofed = False | ||
fp = StringIO(self.msg) | ||
rc = milter.connect('testReject',ip='192.0.3.1') | ||
self.assertEqual(rc,Milter.CONTINUE) | ||
rc = milter.feedFile(fp,sender='',rcpt='[email protected]') | ||
self.assertEqual(rc,Milter.CONTINUE) | ||
milter.conf.srs_reject_spoofed = True | ||
fp.seek(0) | ||
rc = milter.feedFile(fp,sender='',rcpt='[email protected]') | ||
self.assertEqual(rc,Milter.REJECT) | ||
milter.close() | ||
|
||
## Test SRS coding of MAIL FROM | ||
def testSign(self): | ||
milter = TestMilter() | ||
milter.conf.signdomain = set(['example.com']) | ||
milter.conf.miltersrs = True | ||
fp = StringIO(self.msg) | ||
rc = milter.connect('testSign',ip='192.0.3.1') | ||
self.assertEqual(rc,Milter.CONTINUE) | ||
fp.seek(0) | ||
rc = milter.feedFile(fp,sender='[email protected]',rcpt='[email protected]') | ||
self.assertEqual(rc,Milter.CONTINUE) | ||
s = milter.conf.srs.reverse(milter._sender[1:-1]) | ||
self.assertEqual(s,'[email protected]') | ||
# check that it doesn't happen when disabled | ||
milter.conf.miltersrs = False | ||
fp.seek(0) | ||
rc = milter.feedFile(fp,sender='[email protected]',rcpt='[email protected]') | ||
self.assertEqual(rc,Milter.CONTINUE) | ||
self.assertEqual(milter._sender,'<[email protected]>') | ||
milter.close() | ||
|
||
class SRSTestCase(unittest.TestCase): | ||
|
||
|
@@ -191,7 +251,11 @@ def testProgMap(self): | |
self.assertEqual(addr2,orig) | ||
self.assertTrue(self.case_smashed) | ||
|
||
def suite(): return unittest.makeSuite(SRSTestCase,'test') | ||
def suite(): | ||
s = unittest.makeSuite(SRSTestCase,'test') | ||
s.addTest(makeSuite(SRSMilterTestCase,'test')) | ||
#s.addTest(doctest.DocTestSuite(bms)) | ||
return s | ||
|
||
if __name__ == '__main__': | ||
unittest.main() |