$OpenBSD: patch-salt_modules_groupadd_py,v 1.3 2015/01/07 09:57:39 ajacoutot Exp $

https://github.com/saltstack/salt/commit/7f302190ebe517b8e18f836e20fa535e7ea37b96

--- salt/modules/groupadd.py.orig	Mon Nov  3 20:38:21 2014
+++ salt/modules/groupadd.py	Wed Jan  7 10:33:06 2015
@@ -1,6 +1,6 @@
 # -*- coding: utf-8 -*-
 '''
-Manage groups on Linux and OpenBSD
+Manage groups on Linux, OpenBSD and NetBSD
 '''
 
 # Import python libs
@@ -35,7 +35,7 @@ def add(name, gid=None, system=False):
     cmd = 'groupadd '
     if gid:
         cmd += '-g {0} '.format(gid)
-    if system:
+    if system and __grains__['kernel'] != 'OpenBSD':
         cmd += '-r '
     cmd += name
 
@@ -126,6 +126,98 @@ def chgid(name, gid):
     if post_gid != pre_gid:
         return post_gid == gid
     return False
+
+
+def adduser(name, username):
+    '''
+    Add a user in the group.
+
+    CLI Example:
+
+    .. code-block:: bash
+
+         salt '*' group.adduser foo bar
+
+    Verifies if a valid username 'bar' as a member of an existing group 'foo',
+    if not then adds it.
+    '''
+    if __grains__['kernel'] == 'Linux':
+        retcode = __salt__['cmd.retcode']('gpasswd --add {0} {1}'.format(
+            username,name))
+    else:
+        retcode = __salt__['cmd.retcode']('usermod -G {0} {1}'.format(
+            name,username))
+
+    return not retcode
+
+
+def deluser(name, username):
+    '''
+    Remove a user from the group.
+
+    CLI Example:
+
+    .. code-block:: bash
+
+         salt '*' group.deluser foo bar
+
+    Removes a member user 'bar' from a group 'foo'. If group is not present
+    then returns True.
+    '''
+    grp_info = __salt__['group.info'](name)
+    try:
+        if username in grp_info['members']:
+            print username
+            if __grains__['kernel'] == 'Linux':
+                retcode = __salt__['cmd.retcode']('gpasswd --del {0} {1}'
+                    .format(username, name))
+            elif __grains__['kernel'] == 'OpenBSD':
+                cmd = 'usermod -S '
+                out = __salt__['cmd.run_stdout']('id -Gn {0}'.format(username))
+                for group in out.split(" "):
+                    if group != format(name):
+                        cmd += '{0},'.format(group)
+                retcode = __salt__['cmd.retcode']('{0} {1}'.format(
+                    cmd, username))
+            return not retcode
+        else:
+            return True
+    except Exception:
+        return True
+
+
+def members(name, members_list):
+    '''
+    Replaces members of the group with a provided list.
+
+    CLI Example:
+
+        salt '*' group.members foo 'user1,user2,user3,...'
+
+    Replaces a membership list for a local group 'foo'.
+        foo:x:1234:user1,user2,user3,...
+    '''
+    if __grains__['kernel'] == 'Linux':
+        retcode = __salt__['cmd.retcode']('gpasswd --members {0} {1}'.format(
+            members_list, name))
+    elif __grains__['kernel'] == 'OpenBSD':
+        retcode = 1
+        grp_info = __salt__['group.info'](name)
+        if grp_info and name in grp_info['name']:
+            __salt__['cmd.run']('groupdel {0}'.format(name))
+            __salt__['cmd.run']('groupadd -g {0} {1}'.format(
+                grp_info['gid'], name))
+            for user in members_list.split(","):
+                if user:
+                    retcode = __salt__['cmd.retcode'](
+                        'usermod -G {0} {1}'.format(name,user))
+                    if not retcode == 0:
+                        break
+                # provided list is '': users previously deleted from group
+                else:
+                    retcode = 0
+
+    return not retcode
 
 
 def adduser(name, username):
