view plugins/password/helpers/chpass-wrapper.py @ 24:4869fae20b88

do better at flag deletion, unthreaded dates sort working, preparing for threaded
author Charlie Root
date Wed, 17 Jan 2018 17:40:51 -0500
parents 1e000243b222
children
line wrap: on
line source

#!/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)