diff options
author | thomascube <thomas@roundcube.net> | 2011-10-19 15:28:11 +0000 |
---|---|---|
committer | thomascube <thomas@roundcube.net> | 2011-10-19 15:28:11 +0000 |
commit | 5da48a95224e925f4b070f2581a121516df33829 (patch) | |
tree | fadc87888faae54cdb1efc6f7b73fbfce79e0fe7 /plugins/password/drivers/chpass-wrapper.py | |
parent | b03854de3a36a322bf98c733ed9b75d996694e38 (diff) |
Copy plugins to release branch
Diffstat (limited to 'plugins/password/drivers/chpass-wrapper.py')
-rw-r--r-- | plugins/password/drivers/chpass-wrapper.py | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/plugins/password/drivers/chpass-wrapper.py b/plugins/password/drivers/chpass-wrapper.py new file mode 100644 index 000000000..61bba849e --- /dev/null +++ b/plugins/password/drivers/chpass-wrapper.py @@ -0,0 +1,32 @@ +#!/usr/bin/env python + +import sys +import pwd +import subprocess + +BLACKLIST = ( + # add blacklisted users here + #'user1', +) + +try: + username, password = sys.stdin.readline().split(':', 1) +except ValueError, e: + sys.exit('Malformed input') + +try: + user = pwd.getpwnam(username) +except KeyError, e: + sys.exit('No such user: %s' % username) + +if user.pw_uid < 1000: + sys.exit('Changing the password for user id < 1000 is forbidden') + +if username in BLACKLIST: + sys.exit('Changing password for user %s is forbidden (user blacklisted)' % + username) + +handle = subprocess.Popen('/usr/sbin/chpasswd', stdin = subprocess.PIPE) +handle.communicate('%s:%s' % (username, password)) + +sys.exit(handle.returncode) |