DOCS = doc/overview.txt doc/usage.txt doc/config.txt doc/todo.txt
MANPAGES = doc/pgbouncer.1 doc/pgbouncer.5
DATA = README NEWS AUTHORS COPYRIGHT etc/pgbouncer.ini etc/userlist.txt Makefile \
- config.mak.in include/config.h.in \
+ config.mak.in include/config.h.in etc/mkauth.py \
configure configure.ac debian/packages debian/changelog doc/Makefile \
test/Makefile test/asynctest.c test/conntest.sh test/ctest6000.ini \
test/ctest7000.ini test/run-conntest.sh test/stress.py test/test.ini \
--- /dev/null
+#! /usr/bin/env python
+
+import sys, os, tempfile, psycopg2
+
+if len(sys.argv) != 3:
+ print 'usage: mkauth DSTFN CONNSTR'
+ sys.exit(1)
+
+# read old file
+fn = sys.argv[1]
+try:
+ old = open(fn, 'r').read()
+except IOError:
+ old = ''
+
+# create new file data
+db = psycopg2.connect(sys.argv[2])
+curs = db.cursor()
+curs.execute("select usename, passwd from pg_shadow order by 1")
+lines = []
+for user, psw in curs.fetchall():
+ user = user.replace('"', '""')
+ if not psw: psw = ''
+ psw = psw.replace('"', '""')
+ lines.append('"%s" "%s" ""\n' % (user, psw))
+db.commit()
+cur = "".join(lines)
+
+# if changed, replace data securely
+if old != cur:
+ fd, tmpfn = tempfile.mkstemp(dir = os.path.split(fn)[0])
+ f = os.fdopen(fd, 'w')
+ f.write(cur)
+ f.close()
+ os.rename(tmpfn, fn)
+