Merge pull request #25702 from twangboy/fix_25144

Fixed win_user module for groups with spaces in the name
This commit is contained in:
David Boucha 2015-07-27 09:06:33 -06:00
commit dea3d31578

View File

@ -128,14 +128,18 @@ def addgroup(name, group):
salt '*' user.addgroup username groupname
'''
name = _cmd_quote(name)
group = _cmd_quote(group).lstrip('\'').rstrip('\'')
user = info(name)
if not user:
return False
if group in user['groups']:
return True
ret = __salt__['cmd.run_all'](
'net localgroup {0} {1} /add'.format(group, name)
)
cmd = 'net localgroup "{0}" {1} /add'.format(group, name)
ret = __salt__['cmd.run_all'](cmd, python_shell=True)
return ret['retcode'] == 0
@ -149,6 +153,9 @@ def removegroup(name, group):
salt '*' user.removegroup username groupname
'''
name = _cmd_quote(name)
group = _cmd_quote(group).lstrip('\'').rstrip('\'')
user = info(name)
if not user:
@ -157,9 +164,9 @@ def removegroup(name, group):
if group not in user['groups']:
return True
ret = __salt__['cmd.run_all'](
'net localgroup {0} {1} /delete'.format(group, name)
)
cmd = 'net localgroup "{0}" {1} /delete'.format(group, name)
ret = __salt__['cmd.run_all'](cmd, python_shell=True)
return ret['retcode'] == 0
@ -257,10 +264,10 @@ def chfullname(name, fullname):
return False
def chgroups(name, groups, append=False):
def chgroups(name, groups, append=True):
'''
Change the groups this user belongs to, add append to append the specified
groups
Change the groups this user belongs to, add append=False to make the user a
member of only the specified groups
CLI Example:
@ -276,17 +283,22 @@ def chgroups(name, groups, append=False):
if ugrps == set(groups):
return True
name = _cmd_quote(name)
if not append:
for group in ugrps:
group = _cmd_quote(group).lstrip('\'').rstrip('\'')
if group not in groups:
__salt__['cmd.retcode'](
'net localgroup {0} {1} /delete'.format(group, name))
cmd = 'net localgroup "{0}" {1} /delete'.format(group, name)
__salt__['cmd.run_all'](cmd, python_shell=True)
for group in groups:
if group in ugrps:
continue
__salt__['cmd.retcode'](
'net localgroup {0} {1} /add'.format(group, name))
group = _cmd_quote(group).lstrip('\'').rstrip('\'')
cmd = 'net localgroup "{0}" {1} /add'.format(group, name)
__salt__['cmd.run_all'](cmd, python_shell=True)
agrps = set(list_groups(name))
return len(ugrps - agrps) == 0