Mercurial > hg > rc1
comparison plugins/password/helpers/chpass-wrapper.py @ 0:1e000243b222
vanilla 1.3.3 distro, I hope
author | Charlie Root |
---|---|
date | Thu, 04 Jan 2018 15:50:29 -0500 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:1e000243b222 |
---|---|
1 #!/usr/bin/env python | |
2 | |
3 import sys | |
4 import pwd | |
5 import subprocess | |
6 | |
7 BLACKLIST = ( | |
8 # add blacklisted users here | |
9 #'user1', | |
10 ) | |
11 | |
12 try: | |
13 username, password = sys.stdin.readline().split(':', 1) | |
14 except ValueError, e: | |
15 sys.exit('Malformed input') | |
16 | |
17 try: | |
18 user = pwd.getpwnam(username) | |
19 except KeyError, e: | |
20 sys.exit('No such user: %s' % username) | |
21 | |
22 if user.pw_uid < 1000: | |
23 sys.exit('Changing the password for user id < 1000 is forbidden') | |
24 | |
25 if username in BLACKLIST: | |
26 sys.exit('Changing password for user %s is forbidden (user blacklisted)' % | |
27 username) | |
28 | |
29 handle = subprocess.Popen('/usr/sbin/chpasswd', stdin = subprocess.PIPE) | |
30 handle.communicate('%s:%s' % (username, password)) | |
31 | |
32 sys.exit(handle.returncode) |