HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: //lib/python3/dist-packages/samba/netcmd/__pycache__/group.cpython-310.pyc
o

�/aϼ�@s�ddlmZddlmZmZmZmZddlZddl	m
Z
ddlmZddl
mZddlmZddlmZmZmZmZmZmZmZmZmZddlmZdd	lmZmZdd
l m!Z!ddl"Z"ddl#Z#ddl$m%Z%e&eeeed
��Z'e&eeed��Z(Gdd�de�Z)Gdd�de�Z*Gdd�de�Z+Gdd�de�Z,Gdd�de�Z-Gdd�de�Z.Gdd�de�Z/Gdd�de�Z0Gdd �d e�Z1Gd!d"�d"e�Z2Gd#d$�d$e�Z3Gd%d&�d&e�Z4Gd'd(�d(e�Z5dS))�N)�Command�SuperCommand�CommandError�Option)�
ndr_unpack)�security)�system_session)�SamDB)	�ATYPE_SECURITY_GLOBAL_GROUP�"GTYPE_SECURITY_BUILTIN_LOCAL_GROUP�!GTYPE_SECURITY_DOMAIN_LOCAL_GROUP�GTYPE_SECURITY_GLOBAL_GROUP�GTYPE_SECURITY_UNIVERSAL_GROUP�%GTYPE_DISTRIBUTION_DOMAIN_LOCAL_GROUP�GTYPE_DISTRIBUTION_GLOBAL_GROUP�"GTYPE_DISTRIBUTION_UNIVERSAL_GROUP�UF_ACCOUNTDISABLE)�defaultdict)�
check_call�CalledProcessError)�	get_bytes�)�common)�Builtin�Domain�Global�	Universal�rrrc
@s�eZdZdZdZejejejd�Z	e
dddeddd	�e
d
ded�e
d
dgd�dd�e
ddddgdd�e
dded�e
dded�e
dded�e
dded�e
dded�g	Z
d gZ	!	!	!d$d"d#�Zd!S)%�
cmd_group_addaCreates a new AD group.

This command adds a new Active Directory group.  The groupname specified on the command is a unique sAMAccountName.

An Active Directory group may contain user and computer accounts as well as other groups.  An administrator adds a new group and adds members to that group so they can be managed as a single entity.  This helps to simplify security and system administration.

Groups may also be used to establish email distribution lists, using --group-type=Distribution.

Groups are located in domains in organizational units (OUs).  The group's scope is a characteristic of the group that designates the extent to which the group is applied within the domain tree or forest.

The group location (OU), type (security or distribution) and scope may all be specified on the samba-tool command when the group is created.

The command may be run from the root userid or another authorized userid.  The
-H or --URL= option can be used to execute the command on a remote server.

Example1:
samba-tool group add Group1 -H ldap://samba.samdom.example.com --description='Simple group'

Example1 adds a new group with the name Group1 added to the Users container on a remote LDAP server.  The -U parameter is used to pass the userid and password of a user that exists on the remote server and is authorized to issue the command on that server.  It defaults to the security type and global scope.

Example2:
sudo samba-tool group add Group2 --group-type=Distribution

Example2 adds a new distribution group to the local server.  The command is run under root using the sudo command.

Example3:
samba-tool group add Group3 --nis-domain=samdom --gid-number=12345

Example3 adds a new RFC2307 enabled group for NIS domain samdom and GID 12345 (both options are required to enable this feature).
�%prog <groupname> [options]��	sambaopts�versionopts�credopts�-H�--URL�%LDB URL for database or target server�URL�H��help�type�metavar�destz	--groupouzpAlternative location (without domainDN counterpart) to default CN=Users in which new user object will be created�r*r+z
--group-scope�choicerz)Group scope (Domain | Global | Universal))r+�choicesr*z--group-type�Security�Distributionz$Group type (Security | Distribution)z
--descriptionzGroup's description�--mail-addresszGroup's email addressz--noteszGroups's notesz--gid-numberzGroup's Unix/RFC2307 GID numberz--nis-domainzSFU30 NIS Domain�	groupnameNc
Cs�|pddkr
t�|t�}nt�|t�}|dur|
dus#|dur'|
dur'td��|��}|j|dd�}zt|t	�||d�}|j
||||	|
|||
d�Wnty]}ztd||��d}~ww|j�
d|�dS)	Nr1zcBoth --gid-number and --nis-domain have to be set for a RFC2307-enabled group. Operation cancelled.T��fallback_machine��url�session_info�credentials�lp)�groupou�	grouptype�description�mailaddress�notes�	gidnumber�	nisdomainzFailed to add group "%s"zAdded group %s
)�security_group�getr
�distribution_grouprr�get_loadparm�get_credentialsr	r�newgroup�	Exception�outf�write)�selfr4r#r!r"r(r<�group_scope�
group_typer>�mail_addressr@�
gid_number�
nis_domain�gtyper;�creds�samdb�e�rV�4/usr/lib/python3/dist-packages/samba/netcmd/group.py�runqs( �

���zcmd_group_add.run)NNNNNNNNNNNN)�__name__�
__module__�__qualname__�__doc__�synopsis�options�SambaOptions�VersionOptions�CredentialsOptions�takes_optiongroupsr�str�int�
takes_options�
takes_argsrXrVrVrVrWr6s>�
������rc@sLeZdZdZdZejejejd�Z	e
dddeddd	�gZd
gZ
ddd
�ZdS)�cmd_group_deletea�Deletes an AD group.

The command deletes an existing AD group from the Active Directory domain.  The groupname specified on the command is the sAMAccountName.

Deleting a group is a permanent operation.  When a group is deleted, all permissions and rights that users in the group had inherited from the group account are deleted as well.

The command may be run from the root userid or another authorized userid.  The -H or --URL option can be used to execute the command on a remote server.

Example1:
samba-tool group delete Group1 -H ldap://samba.samdom.example.com -Uadministrator%passw0rd

Example1 shows how to delete an AD group from a remote LDAP server.  The -U parameter is used to pass the userid and password of a user that exists on the remote server and is authorized to issue the command on that server.

Example2:
sudo samba-tool group delete Group2

Example2 deletes group Group2 from the local server.  The command is run under root using the sudo command.
rr r$r%r&r'r(r)r4Nc

Cs�|��}|j|dd�}t|t�||d�}dt�|�}	z|j|��tj|	dgd�}
|
dj	}Wn
t
y<td|��wz|�|�Wnt
yW}ztd	||��d}~ww|j�d
|�dS)NTr5r7�)(&(sAMAccountName=%s)(objectClass=group))�dn��base�scope�
expression�attrsr�Unable to find group "%s"zFailed to remove group "%s"zDeleted group %s
)rFrGr	r�ldb�
binary_encode�search�	domain_dn�
SCOPE_SUBTREEri�
IndexErrorr�deleterIrJrK)
rLr4r#r!r"r(r;rSrT�filter�res�group_dnrUrVrVrWrX�s2��
����zcmd_group_delete.run�NNNN�rYrZr[r\r]r^r_r`rarbrrcrerfrXrVrVrVrWrg�s�
��rgc@�eZdZdZdZejejejd�Z	e
dddeddd	�e
d
dedd
�e
ddded�e
dded�gZddgZ
								ddd�ZdS)�cmd_group_add_membersa�Add members to an AD group.

This command adds one or more members to an existing Active Directory group. The command accepts one or more group member names separated by commas.  A group member may be a user or computer account or another Active Directory group.

When a member is added to a group the member may inherit permissions and rights from the group.  Likewise, when permission or rights of a group are changed, the changes may reflect in the members through inheritance.

The member names specified on the command must be the sAMaccountName.

Example1:
samba-tool group addmembers supergroup Group1,Group2,User1 -H ldap://samba.samdom.example.com -Uadministrator%passw0rd

Example1 shows how to add two groups, Group1 and Group2 and one user account, User1, to the existing AD group named supergroup.  The command will be run on a remote server specified with the -H.  The -U parameter is used to pass the userid and password of a user authorized to issue the command on the remote server.

Example2:
sudo samba-tool group addmembers supergroup User2

Example2 shows how to add a single user account, User2, to the supergroup AD group.  It uses the sudo command to run as root when issuing the command.
�F%prog <groupname> (<listofmembers>]|--member-dn=<member-dn>) [options]r r$r%r&r'r(r)�--member-dnzRDN of the new group member to be added.
The --object-types option will be ignored.�append�r*r+�action�--object-types��Comma separated list of object types.
The types are used to filter the search for the specified members.
Valid values are: user, group, computer, serviceaccount, contact and all.
Default: user,group,computer�user,group,computer�r*�defaultr+�--member-base-dn�:Base DN for group member search.
Default is the domain DN.r.r4�listofmembers?Nc

Cs�|��}
|j|
dd�}|dur|dur|��td��z8t|t�||
d�}g}
|dur/|
|7}
|dur:|
|�d�7}
|	�d�}|durH|�|�}|j||
d||d�Wnt	yh}z	td|
||f��d}~ww|j
�d|�dS)	NTr5�6Either listofmembers or --member-dn must be specified.r7�,��add_members_operation�member_types�member_base_dnz+Failed to add members %r to group "%s" - %szAdded members to group %s
�rFrG�usagerr	r�split�normalize_dn_in_domain�add_remove_group_membersrIrJrK�rLr4�
listofmembersr#r!r"r(r��	member_dn�object_typesr;rSrT�groupmembers�group_member_typesrUrVrVrWrX�s>��


����zcmd_group_add_members.run�NNNNNNNr�r{rVrVrVrWr}�sF�
���	���r}c@r|)�cmd_group_remove_membersaRemove members from an AD group.

This command removes one or more members from an existing Active Directory group.  The command accepts one or more group member names separated by commas.  A group member may be a user or computer account or another Active Directory group that is a member of the group specified on the command.

When a member is removed from a group, inherited permissions and rights will no longer apply to the member.

Example1:
samba-tool group removemembers supergroup Group1 -H ldap://samba.samdom.example.com -Uadministrator%passw0rd

Example1 shows how to remove Group1 from supergroup.  The command will run on the remote server specified on the -H parameter.  The -U parameter is used to pass the userid and password of a user authorized to issue the command on the remote server.

Example2:
sudo samba-tool group removemembers supergroup User1

Example2 shows how to remove a single user account, User2, from the supergroup AD group.  It uses the sudo command to run as root when issuing the command.
r~r r$r%r&r'r(r)rzPDN of the group member to be removed.
The --object-types option will be ignored.r�r�r�r�r�r�r�r�r.r4r�Nc

Cs�|��}
|j|
dd�}|dur|dur|��td��z8t|t�||
d�}g}
|dur/|
|7}
|dur:|
|�d�7}
|	�d�}|durH|�|�}|j||
d||d�Wnt	yh}z	td||f|��d}~ww|j
�d	|�dS)
NTr5r�r7r�Fr�z+Failed to remove members %r from group "%s"zRemoved members from group %s
r�r�rVrVrWrX]s<��


���zcmd_group_remove_members.runr�r{rVrVrVrWr�*sF�
���	���r�c
@s�eZdZdZdZedddeddd�ed	d
ddd
�eddded�edddddd�gZej	ej
ejd�Z							ddd�Z
dS)�cmd_group_listzList all groups.�%prog [options]r$r%r&r'r(r)z-vz	--verbosez3Verbose output, showing group type and group scope.�
store_true�r*r�z-bz	--base-dnzSpecify base DN to use.r.�	--full-dn�full_dnF�)Display DN instead of the sAMAccountName.�r-r�r�r*�r!r#r"NcCsH|��}|j|dd�}	t|t�|	|d�}
dg}|r|ddg7}|
��}|r*|
�|�}|
j|tjd|d�}
t	|
�d	kr<dS|r�|j
�d
�|j
�d�|
D]�}|j
�d|jdd	d
��t
td|d�d@�}|t
tt�d���kry|j
�d�nr|t
tt�d���kr�|j
�d�n`|t
tt�d���kr�|j
�d�nN|t
tt�d���kr�|j
�d�n<|t
tt�d���kr�|j
�d�n*|t
tt�d���kr�|j
�d�n|t
tt�d���kr�|j
�d�n|j
�d�t	|jdgd��}|j
�d|�qLdS|
D] }|�r|j
�d|�d���q|j
�d|jdd	d
���qdS) NTr5r7�samaccountnamer=�member�(objectClass=group)�rlrmrnrzQGroup Name                                  Group Type      Group Scope  Members
zQ--------------------------------------------------------------------------------
z%-44s��idxz%sl��rzSecurity         Builtin  rzSecurity         Domain   rzSecurity         Global   rzSecurity         UniversalzDistribution     Global   zDistribution     Domain   zDistribution     Universalz                          �r�z    %6u
�%s
ri)rFrGr	rrsr�rrrprt�lenrJrKrD�hexrdrCrE)rLr!r#r"r(�verbose�base_dnr�r;rSrTrnrsrx�msg�hgtype�num_membersrVrVrWrX�s^�

���zcmd_group_list.run)NNNNFNF)rYrZr[r\r]rrcrer^r_rar`rbrXrVrVrVrWr��s@
�������r�c
@s�eZdZdZdZedddeddd�ed	d
ddd
�eddddd�edddddd�gZej	ej
ejd�ZdgZ
							ddd�ZdS)�cmd_group_list_membersz�List all members of an AD group.

This command lists members from an existing Active Directory group. The command accepts one group name.

Example1:
samba-tool group listmembers "Domain Users" -H ldap://samba.samdom.example.com -Uadministrator%passw0rd
rr$r%r&r'r(r)z--hide-expiredz!Do not list expired group membersFr�)r*r�r�z--hide-disabledz"Do not list disabled group members)r�r�r*r�r�r�r�r�r4Nc	
Cs�|��}	|j|	dd�}
z�t|t�|
|	d�}dt�|�}z|j|��tj|dgd�}
|
dj	ddd�}Wn
t
yAtd	|��wtt
j|�}|��\}}d
|}d}|dur`|��}d|}d}|durmd
tjtf}d||||f}|j|��tj|ddgd�}
t|
�dkr�WdS|
D]*}|r�|j�d|�	d��q�|j	ddd�}|dur�|j	ddd�}|j�d|�q�WdSty�}ztd||f��d}~ww)NTr5r7z)(&(objectClass=group)(sAMAccountName=%s))�	objectSidr�rr�roz<SID=%s>�z>(|(!(accountExpires=*))(accountExpires=0)(accountExpires>=%u))z(!(userAccountControl:%s:=%u))z*(&(|(primaryGroupID=%s)(memberOf=%s))%s%s)�samAccountName�cnr�riz)Failed to list members of "%s" group - %s)rFrGr	rrprqrrrsrtrDrurrr�dom_sidr��
get_nttime�OID_COMPARATOR_ANDrr�rJrKrI)rLr4r#r!r"r(�hide_expired�
hide_disabledr�r;rSrT�
search_filterrx�group_sid_binary�	group_sid�
group_dom_sid�rid�group_sid_dn�filter_expires�current_nttime�filter_disabledrwr��member_namerUrVrVrWrXsp	���������
���zcmd_group_list_members.run)NNNNFFF)rYrZr[r\r]rrcrer^r_rar`rbrfrXrVrVrVrWr��sF
�������r�c@�ReZdZdZdZedddeddd�gZd	d
gZe	j
e	je	jd�Z
		dd
d�ZdS)�cmd_group_movea�Move a group to an organizational unit/container.

    This command moves a group object into the specified organizational unit
    or container.
    The groupname specified on the command is the sAMAccountName.
    The name of the organizational unit or container can be specified as a
    full DN or without the domainDN component.

    The command may be run from the root userid or another authorized userid.

    The -H or --URL= option can be used to execute the command against a remote
    server.

    Example1:
    samba-tool group move Group1 'OU=OrgUnit,DC=samdom.DC=example,DC=com' \
        -H ldap://samba.samdom.example.com -U administrator

    Example1 shows how to move a group Group1 into the 'OrgUnit' organizational
    unit on a remote LDAP server.

    The -H parameter is used to specify the remote target server.

    Example2:
    samba-tool group move Group1 CN=Users

    Example2 shows how to move a group Group1 back into the CN=Users container
    on the local server.
    z+%prog <groupname> <new_parent_dn> [options]r$r%r&r'r(r)r4�
new_parent_dnr�Nc
Cs8|��}|j|dd�}t|t�||d�}	t�|	|	���}
dt�|�}z|	j|
|tj	d�}|dj
}
Wn
ty@td|��wz|	�
|�}Wnty]}z	td||jf��d}~wwt�|	t|
��}|�t|
�d	�|�|�z|	�|
|�Wnty�}ztd
||��d}~ww|j�d||f�dS)NTr5r7rh�rkrmrlrrozInvalid new_parent_dn "%s": %srzFailed to move group "%s"zMoved group "%s" into "%s"
)rFrGr	rrp�Dnrsrqrrrtrirurr�rI�messagerc�remove_base_componentsr��add_base�renamerJrK)rLr4r�r#r!r"r(r;rSrTrsrwrxry�full_new_parent_dnrU�full_new_group_dnrVrVrWrXssL�������
��
�zcmd_group_move.runrz�rYrZr[r\r]rrcrerfr^r_rar`rbrXrVrVrVrWr�Gs����r�c@s^eZdZdZdZedddeddd�ed	d
edd�gZd
gZe	j
e	je	jd�Z
		ddd�ZdS)�cmd_group_showa�Display a group AD object.

This command displays a group object and it's attributes in the Active
Directory domain.
The group name specified on the command is the sAMAccountName of the group.

The command may be run from the root userid or another authorized userid.

The -H or --URL= option can be used to execute the command against a remote
server.

Example1:
samba-tool group show Group1 -H ldap://samba.samdom.example.com \
    -U administrator --password=passw1rd

Example1 shows how to display a group's attributes in the domain against a
remote LDAP server.

The -H parameter is used to specify the remote target server.

Example2:
samba-tool group show Group2

Example2 shows how to display a group's attributes in the domain against a local
LDAP server.

Example3:
samba-tool group show Group3 --attributes=member,objectGUID

Example3 shows how to display a groups objectGUID and member attributes.
z%prog <group name> [options]r$r%r&r'r(r)z--attributesz:Comma separated list of attributes, which will be printed.�group_attrs)r*r+r-r4r�NcCs�|��}|j|dd�}t|t�||d�}	d}
|r|�d�}
dt�|�}|	��}z|	j||tj	|
d�}
|
dj
}Wn
tyFtd|��w|
D]}t
�|	|�}|j�|�qIdS)	NTr5r7r�z,(&(objectCategory=group)(sAMAccountName=%s)))rkrmrlrnrro)rFrGr	rr�rprqrsrrrtrirurr�get_ldif_for_editorrJrK)rLr4r#r!r"r(r�r;rSrTrnrw�domaindnrx�user_dnr��
group_ldifrVrVrWrX�s0�
����zcmd_group_show.run�NNNNNr�rVrVrVrWr��s&���	��r�c@sNeZdZdZdZedddeddd�gZej	ej
ejd	�Zd
d�Z
dd
d�ZdS)�cmd_group_statsz+Summary statistics about group memberships.r�r$r%r&r'r(r)r�cCs2d}|��D]\}}||kr||kr||7}q|S)Nr)�items)rL�	range_min�	range_max�group_freqs�total_count�members�countrVrVrW�num_in_range�s�zcmd_group_stats.num_in_rangeNcCsh|��}|j|dd�}t|t�||d�}|��}|j|tjdddgd�}	i}
d}|	D]}t|�	d��}
t
|j	dgd	��}||
|
<||7}q*|	j}|j�
d
�|j�
d�|j�
d�|��|j�
d
�|��|t|�}|j�
d|�t|
���}t|
���}|�t|��}||}|j�
d�|||��|��|d}||}|ddkr�|||dd}|j�
d�|��tt�}|
��D]\}}||d7<q�dddddddddddddd d!d"d#d$d%d&d'd(d)d*d+d,d-|fg}|j�
d.�|j�
d�|D]-}|d}|d}||k�rn|�|||�}|dk�r+d/�||�}|j�
d0||f�q�|j�
d1�dS)2NTr5r7r�r�r�r�rr�zGroup membership statistics*
z2-------------------------------------------------
zTotal groups: {0}
zTotal memberships: {0}
z Average members per group: %.2f
zMax members: {0} ({1})
�rzMedian members per group: {0}

)rr)r��)��	)�
�)��)��)��)��')�(�1)�2�;)�<�E)�F�O)�P�Y)�Z�c)�d�)���)���)�i+)i,i�)i�i�)i�i�)i�i�)i�i�)i�i�)i�i�)i�i'i'z Members        Number of Groups
z{0}-{1}z	%13s  %u
z7
* Note this does not include nested group memberships
)rFrGr	rrsrrrprtrcrDr�r�rJrK�format�float�list�keys�values�index�max�sortrrdr�r�)rLr!r#r"r(r;rSrTrsrx�group_assignments�total_membershipsr��namer��
num_groups�average�group_names�
group_membersr��max_members�midpoint�medianr��group�bands�band�
band_start�band_end�band_strrVrVrWrX�sx�
�
�

�

�zcmd_group_stats.runrz)rYrZr[r\r]rrcrer^r_rar`rbr�rXrVrVrVrWr��s
���r�c@s\eZdZdZdZedddeddd�ed	d
ed�gZdgZe	j
e	je	jd
�Z
		ddd�ZdS)�cmd_group_editaModify Group AD object.

    This command will allow editing of a group account in the Active Directory
    domain. You will then be able to add or change attributes and their values.

    The groupname specified on the command is the sAMAccountName.

    The command may be run from the root userid or another authorized userid.

    The -H or --URL= option can be used to execute the command against a remote
    server.

    Example1:
    samba-tool group edit Group1 -H ldap://samba.samdom.example.com \
        -U administrator --password=passw1rd

    Example1 shows how to edit a groups attributes in the domain against a
    remote LDAP server.

    The -H parameter is used to specify the remote target server.

    Example2:
    samba-tool group edit Group2

    Example2 shows how to edit a groups attributes in the domain against a local
    server.

    Example3:
    samba-tool group edit Group3 --editor=nano

    Example3 shows how to edit a groups attributes in the domain against a local
    server using the 'nano' editor.
    rr$r%r&r'r(r)z--editorzQEditor to use instead of the system default, or 'vi' if no system default is set.r.r4r�NcCs|��}|j|dd�}t|t�||d�}	dt�|�}
|	��}z|	j||
tjd�}|dj	}
Wn
t
y<td|��wt|�dkrMtd	|t|�f��|d}t
�|	|�}|durgtj�d
�}|durgd}tjdd
��G}|�t|��|��z	t||jg�Wnty�}ztd|��d}~wwt|j��}|��}Wd�n1s�wYWd�n1s�wY|	�|�}t|�d}|	�||�}t|�dkr�|j�d�dSz|	� |�Wnt!y�}ztd||��d}~ww|j�d|�dS)NTr5r7rhr�rrorz'Invalid number of results: for "%s": %d�EDITOR�viz.tmp)�suffixzERROR: zNothing to do
zFailed to modify group '%s': z!Modified group '%s' successfully
)"rFrGr	rrprqrsrrrtrirurr�rr��os�environrD�tempfile�NamedTemporaryFilerKr�flushrrr�open�read�
parse_ldif�next�msg_diffrJ�modifyrI)rLr4r#r!r"r(�editorr;rSrTrwr�rxryr��result_ldif�t_filerU�edited_file�edited_message�msgs_edited�
msg_edited�res_msg_diffrVrVrWrX~sn����
�
��
���

��zcmd_group_edit.runr�r�rVrVrVrWrLs$!�����rc@r�)�cmd_group_add_unix_attrsa�Add RFC2307 attributes to a group.

This command adds Unix attributes to a group account in the Active
Directory domain.
The groupname specified on the command is the sAMaccountName.

Unix (RFC2307) attributes will be added to the group account.

Add 'idmap_ldb:use rfc2307 = Yes' to smb.conf to use these attributes for
UID/GID mapping.

The command may be run from the root userid or another authorized userid.
The -H or --URL= option can be used to execute the command against a
remote server.

Example1:
samba-tool group addunixattrs Group1 10000

Example1 shows how to add RFC2307 attributes to a domain enabled group
account.

The groups Unix ID will be set to '10000', provided this ID isn't already
in use.

z'%prog <groupname> <gidnumber> [options]r$r%r&r'r(r)r4rAr�Nc
Cs4|��}|�|�}t|t�||d�}	|	��}
d�t�|��}|	j|
tj	|d�}t
|�dkr4td�|���|dj}
d|dvrFtd�|���d�|�}|	j|
tj	|d�}t
|�dkratd	�|���|�
d
�sl|j�d�d�|
|�}z|	�|�Wntjy�}ztd
�||���d}~ww|j�d�|��dS)Nr7z(samaccountname={}))rlrmrzUnable to find group '{}'�	gidNumberzGroup {} is a Unix group.z$(&(objectClass=group)(gidNumber={}))zgidNumber {} already used.zidmap_ldb:use rfc2307z�You are setting a Unix/RFC2307 GID. You may want to set 'idmap_ldb:use rfc2307 = Yes' in smb.conf to use the attributes for XID/SID-mapping.
z:
dn: {0}
changetype: modify
add: gidNumber
gidNumber: {1}
z!Failed to modify group '{0}': {1}z!Modified Group '{}' successfully
)rFrGr	rrsrrprqrrrtr�rrirDrJrK�modify_ldif�LdbError)rLr4rAr#r!r"r(r;rSrTr�rwrxry�	group_modrUrVrVrWrX�sJ
��

�
����zcmd_group_add_unix_attrs.runrzr�rVrVrVrWr6�s����r6c	@s�eZdZdZdZedddeddd�ed	d
ed�edd
dd�edded�edded�gZdgZe	j
e	je	jd�Z
			ddd�ZdS)�cmd_group_renamea�Rename a group and related attributes.

    This command allows to set the group's name related attributes. The
    group's CN will be renamed automatically.

    The group's CN will be the sAMAccountName.
    Use the --force-new-cn option to specify the new CN manually and the
    --reset-cn to reset this change.

    Use an empty attribute value to remove the specified attribute.

    The groupname specified on the command is the sAMAccountName.

    The command may be run locally from the root userid or another authorized
    userid.

    The -H or --URL= option can be used to execute the command against a remote
    server.

    Example1:
    samba-tool group rename employees --samaccountname=staff

    Example1 shows how to change the samaccountname of a group 'employees' to
    'staff'. The CN of the group employees will also be changed to 'staff',
    if the previous CN was the previous sAMAccountName.

    Example2:
    samba-tool group rename employees --mail-address='staff@company.com' \
        -H ldap://samba.samdom.example.com -U administrator

    Example2 shows how to rename the mail address of a group 'employees' to
    'staff@company.com'.
    The -H parameter is used to specify the remote target server.
    rr$r%r&r'r(r)z--force-new-cnz;Specify a new CN (RND) instead of using the sAMAccountName.r.z
--reset-cnzqSet the CN (RDN) to the sAMAccountName. Use this option to reset the changes made with the --force-new-cn option.r�r�r3zNew mail addressz--samaccountnamez,New account name (sAMAccountName/logon name)r4r�Nc

CsZ|r|	rtd��|dkrtd��|dkrtd��|��}
|j|
dd�}t|t�||
d�}t�||���}
dt�|�}z|j	|
tj
|gd	�d
�}|d}|j}Wn
ty]td|��w|�
�}|d
d}|duro|}n|durv|}n|d}|d}t|�t|�ko�t|�t|�kp�|	p�t|�}t�|d|�}|�|�t��}||_|�||d|�|�||d|�t|�dk}|��z|r�|�|�|r�|�||�Wnty�}z|��td||��d}~ww|��|r�|j�d|||f�|�r)|j�d|�|��D]}|dk�r�q|j�d|||�r"||ndf��qdSdS)NzEIt is not allowed to specify --force-new-cn together with --reset-cn.r�z8Failed to rename group - delete protected attribute 'CN'zDFailed to rename group - delete protected attribute 'sAMAccountName'Tr5r7z)(&(objectClass=group)(samaccountname=%s)))�sAMAccountNamer��mailrjrror�r<zCN=%sr=zFailed to rename group "%s"z8Renamed CN of group "%s" from "%s" to "%s" successfully
zCFollowing attributes of group "%s" have been changed successfully:
riz%s: %s
z	[removed])rrFrGr	rrpr�rsrqrrrtriru�parentrc�boolr��Message�prepare_attr_replacer��transaction_startr-r�rI�transaction_cancel�transaction_commitrJrKr
)rLr4r#r!r"r(rOr��force_new_cn�reset_cnr;rSrTrsrwrx�	old_groupry�group_parent_dn�old_cn�new_cn�expected_cn�must_change_cn�new_group_dnr��group_attributes_changedrU�attrrVrVrWrXWs����
���

�
�����

���zcmd_group_rename.run)NNNNNNNNr�rVrVrVrWr;sB#��������r;c@s�eZdZdZiZe�ed<e�ed<e�ed<e�ed<e�ed<e	�ed<e
�ed<e�ed	<e�ed
<e
�ed<e�ed<e�ed
<e�ed<dS)�	cmd_groupzGroup management.�add�createrv�edit�
addmembers�
removemembersr	�listmembers�move�show�stats�addunixattrsr�N)rYrZr[r\�subcommandsrrgrr}r�r�r�r�r�r�r6r;rVrVrVrWrP�s 











rP)6�samba.getopt�getoptr^�samba.netcmdrrrrrp�	samba.ndrr�samba.dcerpcr�
samba.authr�samba.samdbr	�
samba.dsdbr
rrr
rrrrr�collectionsr�
subprocessrr�samba.commonrr#r%r�r�dictrCrErrgr}r�r�r�r�r�r�rr6r;rPrVrVrVrW�<module>sJ,��V>`^ViPOfl_