Files
roundcubemail/plugins/password/helpers/chpass-wrapper.py
jelle van der Waa 11e5c1af4f Password: Make chpass-wrapper.py Python 3 compatible (#7135)
Remove the ", e" as the exception is never printed and this makes it
Python 3 compatible as well

Closes: #7118
2020-01-05 11:52:04 +01:00

33 lines
722 B
Python

#!/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:
sys.exit('Malformed input')
try:
user = pwd.getpwnam(username)
except KeyError:
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)