--- Begin Message ---
Package: greylistd
Version: 0.8.8.8
Severity: grave
The conversion to Python 3.x between versions 0.8.8.7 and 0.8.8.8 is
deeply broken. There are many Python 2.x-only pieces of code still in
the two scripts, and the daemon fails to even start. I have done some
work to improve the situation, but it is still far from working
properly, and unfortunately I do not have any more time right now to
help fix it further. I attach my current patches, which at least
allow the program to start without crashing, but it does not work
properly: "greylist list" reports "(No response from greylistd)", and
this then crashes greylistd - the socket is deleted.
Best wishes,
Julian
--- /usr/bin/greylist.orig 2019-12-20 18:25:21.000000000 +0000
+++ /usr/bin/greylist 2020-01-12 11:50:31.148328897 +0000
@@ -25,10 +25,6 @@
from configparser import ConfigParser
-### Define values not yet availble in Python 2.1
-False, True = (0 is 1), (1 is 1)
-
-
### Exit codes based on responses from greylistd
exitcodes = { "error:" : -1,
"white" : 0,
@@ -128,36 +124,36 @@
try:
sock.connect(sockfile)
-except Exception as e:
- stderr.write("%s: %s\n"%(sockfile, e[1]))
- exit(-1)
+except:
+ stderr.write("sock.connect(%s) failed\n"%sockfile)
+ raise
try:
- sock.send(" ".join(argv[1:]))
-except Exception as e:
- stderr.write("%s: %s\n"%(sockfile, e[1]))
- exit(-1)
-
+ sock.send((" ".join(argv[1:])).encode())
+except:
+ stderr.write("sock.send (socket=%s) failed\n"%sockfile)
+ raise
stat = True
firstword = None
while stat:
stat = sock.recv(1024)
+ stats = stat.decode()
try:
- stdout.write("%s"%stat)
+ stdout.write("%s"%stats)
- except IOError:
+ except OSError:
break
else:
- if not firstword and stat.strip():
- firstword = stat.split(None, 1)[0]
+ if not firstword and stats.strip():
+ firstword = stats.split(None, 1)[0]
else:
try:
stdout.write("\n")
- except IOError:
+ except OSError:
pass
--- /usr/sbin/greylistd.orig 2019-12-20 18:25:24.000000000 +0000
+++ /usr/sbin/greylistd 2020-01-12 11:54:47.287105887 +0000
@@ -30,7 +30,7 @@
########################################################################
from time import time, ctime, localtime, strftime
-from socket import socket, AF_UNIX, SOCK_STREAM, error as SocketError,
gethostname
+from socket import socket, AF_UNIX, SOCK_STREAM, gethostname
from os import remove, rename, chmod, chown, getuid, getpid, isatty
from pwd import getpwnam
from grp import getgrnam
@@ -119,9 +119,14 @@
for (listKey, timeoutKey) in ((GREY, RETRYMAX),
(WHITE, EXPIRE),
(BLACK, EXPIRE)):
- for (dataKey, dataValue) in data[listKey].items():
- if dataValue[IDX_LAST] + config[TIMEOUTS][timeoutKey] < now:
- del data[listKey][dataKey]
+ deleted = True
+ while deleted:
+ deleted = False
+ for (dataKey, dataValue) in data[listKey].items():
+ if dataValue[IDX_LAST] + config[TIMEOUTS][timeoutKey] < now:
+ del data[listKey][dataKey]
+ deleted = True
+ break
def listStatus (searchkey):
@@ -210,7 +215,7 @@
def loadFromFile (datafile, dictionary, typelist=None):
try:
- fp = file(datafile)
+ fp = open(datafile)
section = None
logPfx = 'In %s:'%datafile
@@ -260,14 +265,14 @@
fp.close()
- except IOError as e:
+ except OSError as e:
raise RunException("Cannot read from '%s': %s"%(datafile, e[1]))
-def saveToFile (datafile, dictionary, perm=0600):
+def saveToFile (datafile, dictionary, perm=0o600):
try:
- fp = file(datafile, 'w')
+ fp = open(datafile, 'w')
chmod(datafile, perm)
@@ -283,7 +288,7 @@
fp.close()
- except IOError as e:
+ except OSError as e:
raise RunException("Cannot write to %s: %s"%(datafile, e[1]))
except OSError as e:
@@ -323,17 +328,17 @@
-def syncTriplets (datafile, perm=0600):
+def syncTriplets (datafile, perm=0o600):
source = datafile
target = "%s.%s"%(source, getpid())
try:
- infile = file(source, "r")
- except IOError:
+ infile = open(source, "r")
+ except OSError:
infile = None
try:
- outfile = file(target, "w")
+ outfile = open(target, "w")
chmod(target, perm)
@@ -356,7 +361,7 @@
newTriplets.clear()
outfile.close()
- except IOError as e:
+ except OSError as e:
raise RunException("Could not write to %s: %s"%(target, e[1]))
except OSError as e:
@@ -589,11 +594,11 @@
do_save()
try:
- infile = file(config[DATA][TRIPLETFILE], "r")
+ infile = open(config[DATA][TRIPLETFILE], "r")
error = listTriplets(infile, socket, options)
infile.close()
- except IOError as e:
+ except OSError as e:
raise CommandError("Cannot read from '%s':
%s\n"%(config[DATA][TRIPLETFILE], e[1]))
@@ -639,8 +644,9 @@
def runCommand (line, client):
+ lines = line.decode()
now = int(time())
- words = line.lower().split()
+ words = lines.lower().split()
options = []
if not words:
@@ -750,8 +756,8 @@
try:
listener = createSocket(**config[SOCKET])
- except SocketError as e:
- log("Could not bind/listen to socket %s:
%s"%(config[SOCKET][SOCKPATH], str(e)))
+ except OSError as e:
+ log("Could not bind/listen to socket %s:
%s"%(config[SOCKET][SOCKPATH], e[1]))
exit(-1)
except RunException as e:
@@ -811,9 +817,9 @@
try:
line = client.recv(16384)
reply = runCommand(line, client)
- client.send(reply)
+ client.send(reply.encode())
- except SocketError as e:
+ except OSError as e:
log("Socket error: %s"%e[1])
client.close()
--- End Message ---