Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

chpass-wrapper.py 728B

1234567891011121314151617181920212223242526272829303132
  1. #!/usr/bin/env python
  2. import sys
  3. import pwd
  4. import subprocess
  5. BLACKLIST = (
  6. # add blacklisted users here
  7. #'user1',
  8. )
  9. try:
  10. username, password = sys.stdin.readline().split(':', 1)
  11. except ValueError, e:
  12. sys.exit('Malformed input')
  13. try:
  14. user = pwd.getpwnam(username)
  15. except KeyError, e:
  16. sys.exit('No such user: %s' % username)
  17. if user.pw_uid < 1000:
  18. sys.exit('Changing the password for user id < 1000 is forbidden')
  19. if username in BLACKLIST:
  20. sys.exit('Changing password for user %s is forbidden (user blacklisted)' %
  21. username)
  22. handle = subprocess.Popen('/usr/sbin/chpasswd', stdin = subprocess.PIPE)
  23. handle.communicate('%s:%s' % (username, password))
  24. sys.exit(handle.returncode)