1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

Merge pull request #1523 from nigelm/user_fixes

Fixes to the user module
This commit is contained in:
Michael DeHaan 2012-11-04 05:50:22 -08:00
commit 37bdee331c

View file

@ -407,8 +407,8 @@ class User(object):
return passwd return passwd
else: else:
# Read shadow file for user's encrypted password string # Read shadow file for user's encrypted password string
if os.path.exists(User.SHADOWFILE) and os.access(User.SHADOWFILE, os.R_OK): if os.path.exists(self.SHADOWFILE) and os.access(self.SHADOWFILE, os.R_OK):
for line in open(User.SHADOWFILE).readlines(): for line in open(self.SHADOWFILE).readlines():
if line.startswith('%s:' % self.name): if line.startswith('%s:' % self.name):
passwd = line.split(':')[1] passwd = line.split(':')[1]
return passwd return passwd
@ -430,6 +430,7 @@ class User(object):
if not os.path.exists(ssh_dir): if not os.path.exists(ssh_dir):
try: try:
os.mkdir(ssh_dir, 0700) os.mkdir(ssh_dir, 0700)
os.chown(ssh_dir, info[2], info[3])
except OSError, e: except OSError, e:
return (1, '', 'Failed to create %s: %s' % (ssh_dir, str(e))) return (1, '', 'Failed to create %s: %s' % (ssh_dir, str(e)))
if os.path.exists(ssh_key_file): if os.path.exists(ssh_key_file):
@ -449,9 +450,7 @@ class User(object):
else: else:
cmd.append('') cmd.append('')
p = subprocess.Popen(cmd, shell=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE) (rc, out, err) = self.execute_command(cmd)
(out, err) = p.communicate()
rc = p.returncode
if rc == 0: if rc == 0:
# If the keys were successfully created, we should be able # If the keys were successfully created, we should be able
# to tweak ownership. # to tweak ownership.
@ -569,6 +568,7 @@ class FreeBsdUser(User):
'usermod', 'usermod',
'-n', '-n',
self.name ] self.name ]
cmd_len = len(cmd)
info = self.user_info() info = self.user_info()
if self.uid is not None and info[2] != int(self.uid): if self.uid is not None and info[2] != int(self.uid):
@ -615,15 +615,19 @@ class FreeBsdUser(User):
groups_need_mod = True groups_need_mod = True
if groups_need_mod: if groups_need_mod:
cmd.append('-G')
new_groups = groups new_groups = groups
if self.append: if self.append:
new_groups.append(current_groups) new_groups.append(current_groups)
cmd.append(','.join(new_groups)) cmd.append(','.join(new_groups))
# modify the user # modify the user if cmd will do anything
if cmd_len != len(cmd):
(rc, out, err) = self.execute_command(cmd) (rc, out, err) = self.execute_command(cmd)
if rc is not None and rc != 0: if rc is not None and rc != 0:
module.fail_json(name=self.name, msg=err, rc=rc) module.fail_json(name=self.name, msg=err, rc=rc)
else:
(rc, out, err) = (None, '', '')
# we have to set the password in a second command # we have to set the password in a second command
if self.password is not None and info[1] != self.password: if self.password is not None and info[1] != self.password: