Debian Codegraph @

contrib/mm_ckpasswd

raw symbols SCIP
1 #!/usr/bin/env python3
2 # [email protected]
3 #
4 # This is a ckpasswd equivalent that verifies user passwords against the
5 # passwords stored in a Mailman list configuration file. It allows users
6 # to access newsgroups with the same password as they use to access their
7 # Mailman configuration.
8 #
9 # To use this program, it needs to run as the Mailman user, and therefore
10 # may have to be run from a wrapper. Other than that, use it like ckpasswd
11 # in a readers.conf file as an auth parameter, passing it the configuration
12 # file for the list as its only parameter.
13 #
14 # This program is free software; you can redistribute it and/or modify it
15 # under the terms of the GNU General Public License as published by the Free
16 # Software Foundation; either version 2 of the License, or (at your option)
17 # any later version.
18 #
19 # This program is distributed in the hope that it will be useful, but
20 # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
21 # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 # for more details.
23 #
24 # You should have received a copy of the GNU General Public License along
25 # with this program; if not, write to the Free Software Foundation,
26 # Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27
28
29 """Reads username and password from stdin,
30 and database to use as first parameter.
31 and is meant to be used like ckpasswd is.
32 returns:
33 0 success
34 1 bad username &/or password
35 2 other errors"""
36
37 import sys
38 import marshal
39 import string
40 import os
41
42 try:
43 filename = sys.argv[1]
44 except IndexError:
45 sys.stderr.write("Usage: " + sys.argv[0] + " /path/to/config.db\n")
46 sys.exit(2)
47
48 fp = open(filename, "rb")
49 d = marshal.load(fp)
50 passwords = d["passwords"]
51 fp.close()
52
53 username = ""
54 password = ""
55
56 while 1:
57 line = sys.stdin.readline()
58 if line == "":
59 break
60 try:
61 name, value = map(string.strip, line.split(":"))
62 if name == "ClientAuthname":
63 username = value
64 if name == "ClientPassword":
65 password = value
66 except:
67 pass
68
69 if not username or not password:
70 sys.exit(2)
71
72 auth = 0
73 try:
74 if passwords[username] == password:
75 auth = 1
76 except:
77 pass
78
79 if auth == 1:
80 print("User:%s" % username)
81 sys.exit(0)
82 else:
83 sys.exit(1)