summaryrefslogtreecommitdiff
path: root/plugins/password/helpers/chpass-wrapper.py
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/password/helpers/chpass-wrapper.py')
-rw-r--r--plugins/password/helpers/chpass-wrapper.py32
1 files changed, 32 insertions, 0 deletions
diff --git a/plugins/password/helpers/chpass-wrapper.py b/plugins/password/helpers/chpass-wrapper.py
new file mode 100644
index 000000000..61bba849e
--- /dev/null
+++ b/plugins/password/helpers/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)