Advertisement
dlucio

Roundcubemail password changer in Phython

Nov 14th, 2016
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.74 KB | None | 0 0
  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)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement