Commit d429d921 authored by Julien Cristau's avatar Julien Cristau

ud-generate: use subprocess.Popen instead of os.popen in GenCDB.

parent a7f7b439
......@@ -13,6 +13,7 @@ userdir-ldap (0.3.97) UNRELEASED; urgency=medium
[ Julien Cristau ]
* ud-mailgate: don't let punycode through.
* ud-generate: use subprocess.Popen instead of os.popen in GenCDB.
-- Peter Palfrader <weasel@debian.org> Sat, 06 Apr 2019 22:04:34 +0200
......
......@@ -645,28 +645,24 @@ def GenForward(accounts, File):
Done(File, F, None)
def GenCDB(accounts, File, key):
Fdb = None
prefix = ["/usr/bin/eatmydata"] if os.path.exists('/usr/bin/eatmydata') else []
# nothing else does the fsync stuff, so why do it here?
Fdb = subprocess.Popen(prefix + ["cdbmake", File, "%s.tmp" % File],
preexec_fn=lambda: os.umask(0022),
stdin=subprocess.PIPE)
try:
OldMask = os.umask(0022)
# nothing else does the fsync stuff, so why do it here?
prefix = "/usr/bin/eatmydata " if os.path.exists('/usr/bin/eatmydata') else ''
Fdb = os.popen("%scdbmake %s %s.tmp"%(prefix, File, File), "w")
os.umask(OldMask)
# Write out the email address for each user
for a in accounts:
if not key in a: continue
value = a[key]
user = a['uid']
Fdb.write("+%d,%d:%s->%s\n" % (len(user), len(value), user, value))
Fdb.stdin.write("+%d,%d:%s->%s\n" % (len(user), len(value), user, value))
Fdb.write("\n")
# Oops, something unspeakable happened.
except:
Fdb.close()
raise
if Fdb.close() != None:
raise "cdbmake gave an error"
Fdb.stdin.write("\n")
finally:
Fdb.stdin.close()
if Fdb.wait() != 0:
raise Exception("cdbmake gave an error")
def GenDBM(accounts, File, key):
Fdb = None
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment