HEX
Server: Apache
System: Linux server2.voipitup.com.au 4.18.0-553.104.1.lve.el8.x86_64 #1 SMP Tue Feb 10 20:07:30 UTC 2026 x86_64
User: posscale (1027)
PHP: 8.2.29
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //opt/saltstack/salt/lib/python3.10/site-packages/salt/modules/__pycache__/groupadd.cpython-310.pyc
o

�N�gT/�@s�dZddlZddlZddlZddlZddlZddlZddlm	Z	zddl
Z
Wn	ey/Ynwe�e
�ZdZdd�Zdd�Zd"d
d�Zd#dd
�Zd#dd�Zdd�Zd$dd�Zd#dd�Zd%dd�Zd#dd�Zd#dd�Zd#dd�Zd#dd�Zd#d d!�ZdS)&a+
Manage groups on Linux, OpenBSD and NetBSD

.. important::
    If you feel that Salt should be using this module to manage groups on a
    minion, and it is using a different module (or gives an error similar to
    *'group.info' is not available*), see :ref:`here
    <module-provider-override>`.
�N)�CommandExecutionError�groupcCstddvrtSdS)z?
    Set the user module if the kernel is Linux or OpenBSD
    �kernel)�Linux�OpenBSDZNetBSD)Fz\The groupadd execution module cannot be loaded:  only available on Linux, OpenBSD and NetBSD)�
__grains__�__virtualname__�r	r	�I/opt/saltstack/salt/lib/python3.10/site-packages/salt/modules/groupadd.py�__virtual__ srcCs&tjj�|�}|std|�d���|S)zO
    Utility function wrapper to error out early if a command is not found
    z	Command 'z' cannot be found)�salt�utils�path�whichr)�cmdZ_cmdr	r	r
�_which-srFcCs�td�g}|r|�d|���|r|�d�|r#tddkr#|�d�|dur.|�d|f�|�|�td	|d
d�}|dS)
a�
    .. versionchanged:: 3006.0

    Add the specified group

    name
        Name of the new group

    gid
        Use GID for the new group

    system
        Create a system account

    root
        Directory to chroot into

    non_unique
        Allow creating groups with duplicate (non-unique) GIDs

        .. versionadded:: 3006.0

    CLI Example:

    .. code-block:: bash

        salt '*' group.add foo 3456
    �groupaddz-g z-orrz-rN�-R�cmd.run_allF�Zpython_shell�retcode)r�appendr�extend�__salt__)�name�gid�system�root�
non_uniquer�retr	r	r
�add7s




r cCsDtd�g}|dur|�d|f�|�|�td|dd�}|dS)z�
    Remove the named group

    name
        Name group to delete

    root
        Directory to chroot into

    CLI Example:

    .. code-block:: bash

        salt '*' group.delete foo
    �groupdelNrrFrr)rrrr)rrrrr	r	r
�deletefs


r"cCsN|durtjt|d�}nt�tj�}z	||�}Wt|�Sty&iYSw)z�
    Return information about a group

    name
        Name of the group

    root
        Directory to chroot into

    CLI Example:

    .. code-block:: bash

        salt '*' group.info foo
    N�r)�	functools�partial�	_getgrnam�grp�getgrnam�KeyError�_format_info)rrr(�grinfor	r	r
�info�s
��r,cCs|j|j|j|jd�S)z7
    Return formatted information in a pretty way.
    )r�passwdr�members)�gr_name�	gr_passwd�gr_gid�gr_mem)�datar	r	r
r*�s
�r*cCsbdtvr
|s
tdSg}|durtjt|d�}nt�tj�}|�D]	}|�t|��q!|td<|S)z�
    Return info on all groups

    refresh
        Force a refresh of group information

    root
        Directory to chroot into

    CLI Example:

    .. code-block:: bash

        salt '*' group.getent
    zgroup.getentNr#)�__context__r$r%�	_getgrallr'�getgrallrr*)Zrefreshrrr6r+r	r	r
�getent�s
r7cCszt||d�}|s
dS|||krdStd�g}|dur"|�d|f�|�|||f�td|dd�t||d��|�|kS)	z.
    Change an attribute for a named user
    r#FT�groupmodNr�cmd.runr)r,rrr�get)r�key�value�paramrZpre_inforr	r	r
�	_chattrib�s
r>cCsd}|rd}t|d|||d�S)a�
    .. versionchanged:: 3006.0

    Change the gid for a named group

    name
        Name of the group to modify

    gid
        Change the group ID to GID

    root
        Directory to chroot into

    non_unique
        Allow modifying groups with duplicate (non-unique) GIDs

        .. versionadded:: 3006.0

    CLI Example:

    .. code-block:: bash

        salt '*' group.chgid foo 4376
    z-gz-ogrr#)r>)rrrrr=r	r	r
�chgid�sr?cCs�t�d�dko
t�d�dk}t�d�dkot�d�dk}tddkrL|r-td	�d
||g}n|r8td�d||g}ntd	�d
||g}|durK|�d|f�ntd�d||g}|dur_|�d|f�td|dd�}|S)al
    Add a user in the group.

    name
        Name of the group to modify

    username
        Username to add to the group

    root
        Directory to chroot into

    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.
    �	os_family�RedHat�osmajorrelease�5�Suse�11rr�gpasswdz-a�usermod�-Az--addN�--root�-Gr�cmd.retcodeFr)rr:rrr)r�usernamer�on_redhat_5�
on_suse_11rrr	r	r
�addusers(���rOc	stt�d�dko
t�d�dk}t�d�dkot�d�dk}td��}z�||dvr�td	d
krd|r:td�d|�g}n|rEtd
�d�|g}ntd�d|�g}|durX|�d|f�td|dd�}|WStd	dkr�tdd|��dd�}td
�dg}|�d��fdd�|��D���|�|��td|dd�}|WSt�	d�WdSWdSt
y��ty�YdSw)aq
    Remove a user from the group.

    name
        Name of the group to modify

    username
        Username to delete from the group

    root
        Directory to chroot into

    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.
    r@rArBrCrDrE�
group.infor.rrrFz-drGrz--delNrIrKFrrzcmd.run_stdoutzid -Gn z-S�,csg|]
}|t��kr|�qSr	)�str)�.0�g�rr	r
�
<listcomp>cszdeluser.<locals>.<listcomp>z3group.deluser is not yet supported on this platformT)rr:rrrr�join�split�log�errorr�	Exception)	rrLrrMrN�grp_inforr�outr	rUr
�deluser2sH���
�"
��r^c
Cs�t�d�dko
t�d�dk}t�d�dkot�d�dk}tddkrq|r-td	�d
||g}n.|rStd|��d�D]}td
d�td�||�dd�q8td�d||g}ntd	�d||g}|durf|�d|f�td|dd�}|Stddkr�d}td|�}|r�||dvr�td
d�td�|�dd�td
d�td�|d|�dd�|�d�D]}	|	r�tdtd �d!||	gdd�}|d"ks�|Sq�d"}q�|St�d#�dS)$a�
    Replaces members of the group with a provided list.

    name
        Name of the group to modify

    members_list
        Username list to set into the group

    root
        Directory to chroot into

    CLI Example:

    .. code-block:: bash

        salt '*' group.members foo 'user1,user2,user3,...'

    Replaces a membership list for a local group 'foo'.
        foo:x:1234:user1,user2,user3,...
    r@rArBrCrDrErrrFz-MrPr.r9z{} -R {} {}r8FrrHz	--membersNrIrKr�rz{} {}r!z{} -g {} {}rrrQrGrJrz3group.members is not yet supported on this platform)	rr:rr�formatrrXrYrZ)
rZmembers_listrrMrNrZ
old_memberrr\�userr	r	r
r.rsZ��������
�r.cCs�|pd}tj�|d�}tjj�|��S}|D]H}tjj�|�}|�	��
d�}t|�dkr2t�
d|�q|d|kr]t|d�|d<|drK|d�
d	�ng|d<t�|�Wd
�SqWd
�n1shwYtd|����)zK
    Alternative implementation for getgrnam, that use only /etc/group
    �/�	etc/group�:��Ignoring group line: %sr��rQNzgetgrnam(): name not found: )�osrrWrr
�files�fopen�stringutils�
to_unicode�striprX�lenrY�debug�intr'�struct_groupr))rrr-�fp_�line�compsr	r	r
r&�s$���r&ccs��|pd}tj�|d�}tjj�|��F}|D]:}tjj�|�}|�	��
d�}t|�dkr3t�
d|�qt|d�|d<|drF|d�
d�ng|d<t�|�VqWd	�d	S1s\wYd	S)
zK
    Alternative implemetantion for getgrall, that use only /etc/group
    rbrcrdrerfrgrhrQN)rirrWrr
rjrkrlrmrnrXrorYrprqr'rr)rr-rsrtrur	r	r
r5�s��"�r5)NFNF)N)FN)NF)�__doc__r$�loggingriZsalt.utils.filesrZsalt.utils.pathZsalt.utils.stringutilsZsalt.exceptionsrr'�ImportError�	getLogger�__name__rYrrrr r"r,r*r7r>r?rOr^r.r&r5r	r	r	r
�<module>s:
�



/




 
2
@
J