diff --git a/milter.patch b/milter.patch new file mode 100644 index 0000000..ead7ca6 --- /dev/null +++ b/milter.patch @@ -0,0 +1,171 @@ +diff --git a/miltermodule.c b/miltermodule.c +index aa10a08..af9a144 100644 +--- a/miltermodule.c ++++ b/miltermodule.c +@@ -343,7 +343,7 @@ static struct MilterCallback { + { NULL , NULL } + }; + +-staticforward struct smfiDesc description; /* forward declaration */ ++static struct smfiDesc description; /* forward declaration */ + + static PyObject *MilterError; + /* The interpreter instance that called milter.main */ +@@ -355,7 +355,7 @@ typedef struct { + + static milter_Diag diag; + +-staticforward PyTypeObject milter_ContextType; ++static PyTypeObject milter_ContextType; + + typedef struct { + PyObject_HEAD +@@ -700,7 +700,7 @@ _generic_wrapper(milter_ContextObject *self, PyObject *cb, PyObject *arglist) { + result = PyEval_CallObject(cb, arglist); + Py_DECREF(arglist); + if (result == NULL) return _report_exception(self); +- if (!PyInt_Check(result)) { ++ if (!PyLong_Check(result)) { + const struct MilterCallback *p; + const char *cbname = "milter"; + char buf[40]; +@@ -715,7 +715,7 @@ _generic_wrapper(milter_ContextObject *self, PyObject *cb, PyObject *arglist) { + PyErr_SetString(MilterError,buf); + return _report_exception(self); + } +- retval = PyInt_AS_LONG(result); ++ retval = PyLong_AS_LONG(result); + Py_DECREF(result); + _release_thread(self->t); + return retval; +@@ -732,7 +732,7 @@ makeipaddr(struct sockaddr_in *addr) { + sprintf(buf, "%d.%d.%d.%d", + (int) (x>>24) & 0xff, (int) (x>>16) & 0xff, + (int) (x>> 8) & 0xff, (int) (x>> 0) & 0xff); +- return PyString_FromString(buf); ++ return PyUnicode_FromString(buf); + } + + #ifdef HAVE_IPV6_SUPPORT +@@ -740,8 +740,8 @@ static PyObject * + makeip6addr(struct sockaddr_in6 *addr) { + char buf[100]; /* must be at least INET6_ADDRSTRLEN + 1 */ + const char *s = inet_ntop(AF_INET6, &addr->sin6_addr, buf, sizeof buf); +- if (s) return PyString_FromString(s); +- return PyString_FromString("inet6:unknown"); ++ if (s) return PyUnicode_FromString(s); ++ return PyUnicode_FromString("inet6:unknown"); + } + #endif + +@@ -832,7 +832,7 @@ generic_env_wrapper(SMFICTX *ctx, PyObject*cb, char **argv) { + for (i=0;i/libmilter/README for details on setting it up.\n"; + + static void setitem(PyObject *d,const char *name,long val) { +- PyObject *v = PyInt_FromLong(val); ++ PyObject *v = PyLong_FromLong(val); + PyDict_SetItemString(d,name,v); + Py_DECREF(v); + } + +-void +-initmilter(void) { ++static struct PyModuleDef moduledef = { ++ PyModuleDef_HEAD_INIT, ++ "milter", /* m_name */ ++ milter_documentation,/* m_doc */ ++ -1, /* m_size */ ++ milter_methods, /* m_methods */ ++ NULL, /* m_reload */ ++ NULL, /* m_traverse */ ++ NULL, /* m_clear */ ++ NULL, /* m_free */ ++}; ++ ++PyMODINIT_FUNC PyInit_milter(void) { + PyObject *m, *d; + +- m = Py_InitModule4("milter", milter_methods, milter_documentation, +- (PyObject*)NULL, PYTHON_API_VERSION); ++ m = PyModule_Create(&moduledef); + d = PyModule_GetDict(m); + MilterError = PyErr_NewException("milter.error", NULL, NULL); + PyDict_SetItemString(d,"error", MilterError); +@@ -1710,4 +1721,5 @@ initmilter(void) { + setitem(d,"DISCARD", SMFIS_DISCARD); + setitem(d,"ACCEPT", SMFIS_ACCEPT); + setitem(d,"TEMPFAIL", SMFIS_TEMPFAIL); ++ return m; + } +diff --git a/setup.cfg b/setup.cfg +index 123f837..96821bb 100644 +--- a/setup.cfg ++++ b/setup.cfg +@@ -1,5 +1,5 @@ + [bdist_rpm] +-python=python2 ++python=python3 + doc_files=README NEWS TODO COPYING CREDITS + packager=Stuart D. Gathman + release=1 diff --git a/py3milter.spec b/py3milter.spec new file mode 100644 index 0000000..8de0c82 --- /dev/null +++ b/py3milter.spec @@ -0,0 +1,181 @@ +%define pythonbase python3 +%define __python python3 + +%define libdir %{_libdir}/pymilter +%{!?python_sitearch: %define python_sitearch %(%{__python} -c "from distutils.sysconfig import get_python_lib; print get_python_lib(1)")} + +Summary: Python interface to sendmail milter API +Name: %{pythonbase}-pymilter +Version: 1.1 +Release: 1%{dist} +Source: http://downloads.sourceforge.net/pymilter/pymilter-%{version}.tar.gz +Source1: pymilter.te +# Patch miltermodule to be python3 +# FIXME: replace with reverse at some point +Patch: milter.patch +License: GPLv2+ +Group: Development/Libraries +BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root +Url: http://www.bmsi.com/python/milter.html +# python-2.6.4 gets RuntimeError: not holding the import lock +Requires: %{pythonbase} >= 2.6.5, sendmail >= 8.13 +# Need python2.6 specific pydns, not the version for system python +Requires: %{pythonbase}-pydns +# Needed for callbacks, not a core function but highly useful for milters +BuildRequires: ed, %{pythonbase}-devel, sendmail-devel >= 8.13 + +%description +This is a python extension module to enable python scripts to +attach to sendmail's libmilter functionality. Additional python +modules provide for navigating and modifying MIME parts, sending +DSNs, and doing CBV. + +%package selinux +Summary: SELinux policy module for pymilter +Group: System Environment/Base +Requires: policycoreutils, selinux-policy, %{name} +BuildRequires: policycoreutils, checkpolicy + +%description selinux +SELinux policy module for using pymilter with sendmail with selinux enforcing + +%prep +%setup -q -n pymilter-%{version} +%patch -b .py3 +cp %{SOURCE1} pymilter.te + +%build +env CFLAGS="$RPM_OPT_FLAGS" %{__python} setup.py build +checkmodule -m -M -o pymilter.mod pymilter.te +semodule_package -o pymilter.pp -m pymilter.mod + +%install +rm -rf $RPM_BUILD_ROOT +%{__python} setup.py install --root=$RPM_BUILD_ROOT +mkdir -p $RPM_BUILD_ROOT%{_localstatedir}/run/milter +mkdir -p $RPM_BUILD_ROOT%{_localstatedir}/log/milter +mkdir -p $RPM_BUILD_ROOT%{libdir} + +# install selinux modules +mkdir -p %{buildroot}%{_datadir}/selinux/targeted +cp -p pymilter.pp %{buildroot}%{_datadir}/selinux/targeted + +%files +%defattr(-,root,root,-) +%doc README ChangeLog NEWS TODO CREDITS sample.py milter-template.py +%{python_sitearch}/* +%{libdir} +%dir %attr(0755,mail,mail) %{_localstatedir}/run/milter +%dir %attr(0755,mail,mail) %{_localstatedir}/log/milter + +%files selinux +%doc pymilter.te +%{_datadir}/selinux/targeted/* + +%clean +rm -rf $RPM_BUILD_ROOT + +%post selinux +/usr/sbin/semodule -s targeted -i %{_datadir}/selinux/targeted/pymilter.pp \ + &>/dev/null || : + +%postun selinux +if [ $1 -eq 0 ] ; then +/usr/sbin/semodule -s targeted -r pymilter &> /dev/null || : +fi + +%changelog +* Tue Sep 20 2016 Stuart Gathman 1.1-1 +- Support python3 + +* Sat Mar 1 2014 Stuart Gathman 1.0-2 +- Remove start.sh to track EPEL repository, suggest daemonize as replacement +- Selinux subpackage should not care about pymilter version + +* Wed Jun 26 2013 Stuart Gathman 1.0-1 +- Allow ACCEPT as untrapped exception policy +- Optional dir for getaddrset and getaddrdict in Milter.config +- Show registered milter name in untrapped exception message. +- Include selinux subpackage +- Provide Milter.greylist export and Milter.greylist import to migrate data + +* Sat Mar 9 2013 Stuart Gathman 0.9.8-1 +- Add Milter.test module for unit testing milters. +- Fix typo that prevented setsymlist from being active. +- Change untrapped exception message to: +- "pymilter: untrapped exception in milter app" + +* Thu Apr 12 2012 Stuart Gathman 0.9.7-1 +- Raise RuntimeError when result != CONTINUE for @noreply and @nocallback +- Remove redundant table in miltermodule +- Fix CNAME chain duplicating TXT records in Milter.dns (from pyspf). + +* Sat Feb 25 2012 Stuart Gathman 0.9.6-1 +- Raise ValueError on unescaped '%' passed to setreply +- Grace time at end of Greylist window + +* Fri Aug 19 2011 Stuart Gathman 0.9.5-1 +- Print milter.error for invalid callback return type. + (Since stacktrace is empty, the TypeError exception is confusing.) +- Fix milter-template.py +- Tweak Milter.utils.addr2bin and Milter.dynip to handle IP6 + +* Tue Mar 02 2010 Stuart Gathman 0.9.4-1 +- Handle IP6 in Milter.utils.iniplist() +- python-2.6 + +* Thu Jul 02 2009 Stuart Gathman 0.9.3-1 +- Handle source route in Milter.utils.parse_addr() +- Fix default arg in chgfrom. +- Disable negotiate callback for libmilter < 8.14.3 (1,0,1) + +* Tue Jun 02 2009 Stuart Gathman 0.9.2-3 +- Change result of @noreply callbacks to NOREPLY when so negotiated. + +* Tue Jun 02 2009 Stuart Gathman 0.9.2-2 +- Cache callback negotiation + +* Thu May 28 2009 Stuart Gathman 0.9.2-1 +- Add new callback support: data,negotiate,unknown +- Auto-negotiate protocol steps + +* Thu Feb 05 2009 Stuart Gathman 0.9.1-1 +- Fix missing address of optional param to addrcpt + +* Wed Jan 07 2009 Stuart Gathman 0.9.0-4 +- Stop using INSTALLED_FILES to make Fedora happy +- Remove config flag from start.sh glue +- Own /var/log/milter +- Use _localstatedir + +* Wed Jan 07 2009 Stuart Gathman 0.9.0-2 +- Changes to meet Fedora standards + +* Mon Nov 24 2008 Stuart Gathman 0.9.0-1 +- Split pymilter into its own CVS module +- Support chgfrom and addrcpt_par +- Support NS records in Milter.dns + +* Mon Aug 25 2008 Stuart Gathman 0.8.10-2 +- /var/run/milter directory must be owned by mail + +* Mon Aug 25 2008 Stuart Gathman 0.8.10-1 +- improved parsing into email and fullname (still 2 self test failures) +- implement no-DSN CBV, reduce full DSNs + +* Mon Sep 24 2007 Stuart Gathman 0.8.9-1 +- Use ifarch hack to build milter and milter-spf packages as noarch +- Remove spf dependency from dsn.py, add dns.py + +* Fri Jan 05 2007 Stuart Gathman 0.8.8-1 +- move AddrCache, parse_addr, iniplist to Milter package +- move parse_header to Milter.utils +- fix plock for missing source and can't change owner/group +- split out pymilter and pymilter-spf packages +- move milter apps to /usr/lib/pymilter + +* Sat Nov 04 2006 Stuart Gathman 0.8.7-1 +- SPF moved to pyspf RPM + +* Tue May 23 2006 Stuart Gathman 0.8.6-2 +- Support CBV timeout diff --git a/pymilter.spec b/pymilter.spec index 481fc3b..03a7ae3 100644 --- a/pymilter.spec +++ b/pymilter.spec @@ -6,10 +6,13 @@ Summary: Python interface to sendmail milter API Name: %{pythonbase}-pymilter -Version: 1.0 +Version: 1.1 Release: 1%{dist} Source: http://downloads.sourceforge.net/pymilter/pymilter-%{version}.tar.gz Source1: pymilter.te +# Patch miltermodule to python3 +# FIXME: replace with reverse patch at some point (make py3 the default) +Patch: milter.patch License: GPLv2+ Group: Development/Libraries BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root @@ -81,6 +84,9 @@ if [ $1 -eq 0 ] ; then fi %changelog +* Tue Sep 20 2016 Stuart Gathman 1.1-1 +- Support python3 + * Sat Mar 1 2014 Stuart Gathman 1.0-2 - Remove start.sh to track EPEL repository, suggest daemonize as replacement - Selinux subpackage should not care about pymilter version @@ -113,7 +119,7 @@ fi - Fix milter-template.py - Tweak Milter.utils.addr2bin and Milter.dynip to handle IP6 -* Wed Mar 02 2010 Stuart Gathman 0.9.4-1 +* Tue Mar 02 2010 Stuart Gathman 0.9.4-1 - Handle IP6 in Milter.utils.iniplist() - python-2.6 diff --git a/setup.cfg b/setup.cfg index 123f837..66862d1 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,5 +1,5 @@ [bdist_rpm] -python=python2.7 +python=python2 doc_files=README NEWS TODO COPYING CREDITS packager=Stuart D. Gathman release=1