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

Paste is for source code and general debugging text.

Login or Register to edit, delete and keep track of your pastes and more.

Raw Paste

Login or Register to edit or fork this paste. It's free.