Skip to content

Commit

Permalink
Fixed user_ensure, user_check
Browse files Browse the repository at this point in the history
  • Loading branch information
akostyuk committed Jun 11, 2011
1 parent e5d5dfc commit 96f28d5
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions cuisine/__init__.py
Expand Up @@ -261,7 +261,7 @@ def user_check( name ):
as a '{"name":<str>,"uid":<str>,"gid":<str>,"home":<str>,"shell":<str>}' or 'None' if
the user does not exists."""
d = sudo("cat /etc/passwd | egrep '^%s:' ; true" % (name))
s = sudo("cat /etc/shadow | egrep '^%s:' | awk -F':' '{print $2}'")
s = sudo("cat /etc/shadow | egrep '^%s:' | awk -F':' '{print $2}'" % (name))
results = {}
if d:
d = d.split(":")
Expand All @@ -284,7 +284,14 @@ def user_ensure( name, passwd=None, home=None, uid=None, gid=None, shell=None):
method, salt = d.get('passwd').split('$')[1:3]
passwd_crypted = crypt.crypt(passwd, '$%s$%s' % (method, salt))
if passwd_crypted != d.get('passwd'):
options.append("-p '%s'" % (passwd))
options.append("-p '%s'" % (passwd_crypted))
if passwd != None and d.get('passwd') is None:
# user doesn't have passwd
method = 6
saltchars = string.ascii_letters + string.digits + './'
salt = ''.join([random.choice(saltchars) for x in range(8)])
passwd_crypted = crypt.crypt(passwd, '$%s$%s' % (method, salt))
options.append("-p '%s'" % (passwd_crypted))
if home != None and d.get("home") != home:
options.append("-d '%s'" % (home))
if uid != None and d.get("uid") != uid:
Expand Down

0 comments on commit 96f28d5

Please sign in to comment.