%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python3/dist-packages/samba/netcmd/__pycache__/
Upload File :
Create Path :
Current File : //lib/python3/dist-packages/samba/netcmd/__pycache__/group.cpython-312.pyc

�

�I�d����8�ddlmZddlmZmZmZmZddlZddl	m
Z
mZddlm
Z
ddlmZddlmZddlmZmZmZmZmZmZmZmZmZmZmZmZmZddl m!Z!dd	l"m#Z#m$Z$dd
l%m&Z&m'Z'ddl(Z(ddl)Z)ddl*m+Z+e,eeeed
��Z-e,eeed��Z.Gd�de�Z/Gd�de�Z0Gd�de�Z1Gd�de�Z2Gd�de�Z3Gd�de�Z4Gd�de�Z5Gd�de�Z6Gd�d e�Z7Gd!�d"e�Z8Gd#�d$e�Z9Gd%�d&e�Z:Gd'�d(e�Z;y))�N)�Command�SuperCommand�CommandError�Option)�ndr_pack�
ndr_unpack)�security)�system_session)�SamDB)
�ATYPE_SECURITY_GLOBAL_GROUP�DS_GUID_USERS_CONTAINER�"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�SYSTEM_FLAG_DISALLOW_DELETE� SYSTEM_FLAG_DOMAIN_DISALLOW_MOVE�"SYSTEM_FLAG_DOMAIN_DISALLOW_RENAME�UF_ACCOUNTDISABLE)�defaultdict)�
check_call�CalledProcessError)�	get_bytes�normalise_int32�)�common)�Builtin�Domain�Global�	Universal�r!r"r#c�R�eZdZdZdZejejejd�Z	e
dddedd�	�e
d
de��e
d
dgd�d��e
ddddgd��e
dde��e
dde��e
dde��e
dde��e
dde��e
d d!d"d#�$�g
Z
d%gZ				d(d'�Zy&))�
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�r2r3z
--group-scope�choicer$z)Group scope (Domain | Global | Universal))r3�choicesr2z--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 Domainz	--specialzAdd a special predefined group�
store_trueF)r2�action�default�	groupnameNc
��|xsddk(rtj|t�}ntj|t�}|�|
�|�
|
�td��|j
�}|j|d��}	t|t�||��}|�r�d}|�d}n|�d	}n|	�d
}n|
�d}n|�d}n	|�d
}n|
�d}|�td|�d���|j�std��dj�dttjdfi}|j|j��}|�td|�d���|\}}}}	t|�}|j!�}|tk(rCtj"|j%��d|���}d}|so|j'|t(�}nX|t*k(rAtj"d|���}t,t.zt0z}|s!	|j3d�nt9d|����|r	|j3|�	|j3d|���||d||	t;|�dd �}|�||d!<	|j=|d"g�#�|j>jAd$|�d%��y	|jU||||	|
|||
�@�|j>jAdB|z�y#t$r}td|�d�|��d}~wwxYw#t4j6$rt9d��wxYw#t4j6$rtd|�d���wxYw#t4j6$rtd|�d���wxYw#t4j6$�r�}|jB\}}|t4jDk(r�	|jGd&|�d'�d(g�)�}n'#t4j6$rtd|�d�|��wxYwtI|�d*k7rtd|�d�|��|d+jd(d+�,�}|rd-|�d�} nd.} td|�d/| �d0|d+jJ�d���|t4jLk(�r�	|jG|t4jNgd1��2�}n[#t4j6$rE	|jGd3|�d'�gd1��)�}n'#t4j6$rtd|�d�|��wxYwYnwxYwtI|�d*k7rtd|�d�|��|d+jd(d+�,�}!|!rd4|!�d�}"nd5}"|d+jd6d+�,�jQd7�}#||#k7r"td|�d8|"�d0|d+jJ�d9���|d+jd:d+�,�}$|$�"td|�d;|"�d0|d+jJ�d<���tStj"|$�}$|$|k(r"td|�d=|"�d0|d+jJ�d>���td|�d;|"�d0|d+jJ�d?���td|�d�|��d}~wwxYw#t$r}tdA|z|��d}~wwxYw)CNr9zcBoth --gid-number and --nis-domain have to be set for a RFC2307-enabled group. Operation cancelled.T��fallback_machine��url�session_info�credentials�lpzFailed to add group "�"zgroup-scopez
group-type�descriptionzmail-address�notesz
gid-numberz
nis-domainzSuperfluous option --z specified with --specialz8Adding special groups is only permitted against the PDC!zProtected UserszaMembers of this group are afforded additional protections against authentication security threatszUnknown special group "z".�-z	S-1-5-32-z
CN=Builtinz Error getting Builtin objects DNzUnknown group type zInvalid group OU "zCN=zInvalid group name "�group�TRUE)�dn�sAMAccountName�objectClass�	groupTyperI�	objectSid�isCriticalSystemObject�systemFlagszrelax:0)�controlszAdded group �
z(objectSid=�)rO)�
expression�attrsrr��idxz with name "�z " - Special group already existsz at ")rOrRrQ)�base�scoperYz(sAMAccountName=znamed "zwith no namerQzutf-8z" - An object z�" already exists, but it is not a security group. Rename or remove this existing object before attempting to add this special group.rRz" - A security group zx" already exists, but it lacks a SID. Rename or remove this existing object before attempting to add this special group.z" - The security group z" already exists.z�" already exists, but it has the wrong SID, and will not function as expected. Rename or remove this existing object before attempting to add this special group.)�groupou�	grouptyperI�mailaddressrJ�	gidnumber�	nisdomainzFailed to add group "%s"zAdded group %s
)+�security_group�getr�distribution_grouprr�get_loadparm�get_credentialsrr
�	Exception�am_pdc�lowerr	�DOMAIN_RID_PROTECTED_USERSr�get_default_basedn�dom_sid�get_domain_sid�get_wellknown_dnr
rrrr�	add_child�ldb�LdbError�RuntimeErrorr�add�outf�write�args�ERR_CONSTRAINT_VIOLATION�search�lenrN�ERR_ENTRY_ALREADY_EXISTS�
SCOPE_BASE�decoder�newgroup)%�selfr?r+r)r*r0r_�group_scope�
group_typerI�mail_addressrJ�
gid_number�
nis_domain�special�gtyperG�creds�samdb�e�invalid_option�special_groups�
special_group�rid�group_dn�
object_sid�system_flags�msg�num�estr�res�name�	with_name�got_name�named�got_group_type�sids%                                     �4/usr/lib/python3/dist-packages/samba/netcmd/group.py�runzcmd_group_add.runvs���

�$�*��3�"�&�&�{�4O�P�E�&�*�*�;�8W�X�E���:�#9�z�?U�Zd�Zl�� E�F�
F�
�
#�
#�
%���(�(��d�(�C��	H��a�n�.>�&+��4�E��!�N��&�!.���'�!-���(�!.���)�!/���"�!(���'�!-���'�!-���)�"�%:�>�:J�K>�$?�@�@��<�<�>�"�$6�7�7�"�'�'�)�%�/��7�7�J�	,K�	
�N�+�.�.�y���/@�A�M��$�"�%<�Y�K�r�#J�K�K�1>�.�I�u�c�;�(��/�J��/�/�1�H��3�3�%�-�-��+�+�-�.�a��u�5�7�
�#���$�5�5�h�6M� O�H��<�<�%�-�-�	�#��.?�@�
� @� B�!C� ;�!<���O� �*�*�<�8�#�%8���#@�A�A��H��&�&�w�/�
H��"�"�S���#4�5�
�"+�&�'�*�%�j�1�*0��C��'�%1��M�"�[
>��	�	�#���	�4�t�	�	���,�y�k�� <�=��	J��N�N�9�g��'2��TY�%/�:�
�
G�	
�	�	���*�Y�6�7��O�	H��!6�y�k��C�Q�G�G��	H��H�<�<�O�*�+M�N�N�O���|�|�H�&�);�G�9�A�'F�G�G�H��
�<�<�
H�"�%9�)��A�#F�G�G�
H��$�<�<�W
P��F�F�	��T��#�6�6�6�E�#�l�l�)4�Z�L��'B�#3�"4�+�6����<�<�E�*�3�I�;�a�@�!�E�E�E���3�x�1�}�*�3�I�;�a�@�!�E�E��q�6�:�:�&6�A�:�>�D��&2�4�&��$:�	�$&�	�&�/�	�{�;)�)2��5��Q�����2�G�H�H��C�8�8�8�I�#�l�l��14���2?�+�@���
�<�<�	I�I�"'�,�,�-=�i�[��+J�'4�#/�#5�C��
 #�|�|�I�".�"7�	�{�!� D�a�#I�I�I�� �	I���3�x�1�}�*�3�I�;�a�@�!�E�E� #�1�v�z�z�*:��z�B�H��")�(��1� 5�� .��%(��V�Z�Z��45�&0�&7�7=�v�g��#�!�^�3�*�3�I�;�n�$�g�U�3�q�6�9�9�+�6-�.�/�/��a�&�*�*�[�a�*�8�C��{�*�3�I�;�?%�%*�G�5��Q�����<-�.�/�/�)��)9�)9�3�?���*�,�".�"7�	�{�C2�27���c�!�f�i�i�[�I2�!3�#4�4�
#/�"7�	�{�C2�27���c�!�f�i�i�[�IH�!I�#J�J�'�)>�y�k��'K�Q�O�O��oW
P��B�	J��9�I�E�q�I�I��	J�s��6J/�K�K2�L�L>�7W+�/	K
�8K�K
�K/�2#L�#L;�>W(�"W#�5N�
W#�$N2�2A8W#�+$Q�W#�R(�$Q>�=R(�>$R"�"R(�%W#�'R(�(D;W#�#W(�+	X�4X�X)
NNNNNNNNNNNNF)�__name__�
__module__�__qualname__�__doc__�synopsis�options�SambaOptions�VersionOptions�CredentialsOptions�takes_optiongroupsr�str�int�
takes_options�
takes_argsr���r�r&r&:s����>-�H��)�)��-�-��.�.���	�t�W�#J�QT��3�	(��{�G��	�	��X�7X�?�	A��~�H�z�>�6R�:�	<���%:��E���&=�C�H��y�/�c�:��~�$E�C�P��~�$6�S�A��{�!A�,�`e�f��M�$��J�6:�@D�jn��Z8r�r&c��eZdZdZdZejejejd�Z	e
dddedd�	�gZd
gZ
d
d�Zy)�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.
r'r(r,r-r.r/r0r1r?Nc��|j�}|j|d��}t|t�||��}dt	j
|�z}		|j
|j�tj|	dg��}
|
dj}	|j|�|jjd
|z�y#t$rtd|z��wxYw#t$r}td	|z|��d}~wwxYw)NTrArC�)(&(sAMAccountName=%s)(objectClass=group))rN�r]r^rXrYr�Unable to find group "%s"zFailed to remove group "%s"zDeleted group %s
)rgrhrr
rr�
binary_encoderz�	domain_dn�
SCOPE_SUBTREErN�
IndexErrorr�deleterirvrw)
r�r?r+r)r*r0rGr�r��filterr�r�r�s
             r�r�zcmd_group_delete.runvs��
�
#�
#�
%���(�(��d�(�C���!�.�*:�"'�B�0��>��#�#�I�.�/��	J��,�,�E�O�O�$5�%(�%6�%6�*0�&*�V��-�C��1�v�y�y�H�	M��L�L��"�	
�	�	���,�y�8�9���	J��:�i�H�I�I�	J��
�	M��<�y�H�!�L�L��	M�s%�AC�C!�C�!	C>�*C9�9C>�NNNN�r�r�r�r�r�r�r�r�r�r�rr�r�r�r�r�r�r�r�r�Ssa���&-�H��)�)��-�-��.�.���	�t�W�#J�QT��3�	(��M�
��J�:r�r�c���eZdZdZdZejejejd�Z	e
dddedd�	�e
d
ded�
�e
ddde��e
dde��gZddgZ
								dd�Zy)�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/r0r1�--member-dnzRDN of the new group member to be added.
The --object-types option will be ignored.�append�r2r3r=�--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�r2r>r3�--member-base-dn�:Base DN for group member search.
Default is the domain DN.r6r?�listofmembers?Nc
	���|j�}
|j|
d��}|�|�|j�td��	t	|t�||
��}g}
|�|
|z
}
|�|
|j
d�z
}
|	j
d�}|�|j|�}|j||
d||��|jjd
|z�y#t$r}td
�d|�d	|����d}~wwxYw)NTrA�6Either listofmembers or --member-dn must be specified.rC�,��add_members_operation�member_types�member_base_dnzFailed to add members z to group "z" - zAdded members to group %s
�rgrh�usagerrr
�split�normalize_dn_in_domain�add_remove_group_membersrirvrw�r�r?�
listofmembersr+r)r*r0r��	member_dn�object_typesrGr�r��groupmembers�group_member_typesr�s                r�r�zcmd_group_add_members.run�s#���
#�
#�
%���(�(��d�(�C�����!6��J�J�L��H�J�
J�	-��a�n�.>�&+��4�E��L��$��	�)���(��
� 3� 3�C� 8�8��!-�!3�!3�C�!8���)�!&�!=�!=�n�!M���*�*�9�l�AE�8J�:H�
+�
J�	
�	�	���5�	�A�B��	�	-���i�� ,�-�
-��	-�s�A0C�	C5�C0�0C5�NNNNNNNr�r�r�r�r�r�r��s����&X�H��)�)��-�-��.�.���	�t�W�#J�QT��3�	(��}�B���		 �
	��4�-��	�	�!�1��	�#�M�.�/�0�J��������.�(Cr�r�c���eZdZdZdZejejejd�Z	e
dddedd�	�e
d
ded�
�e
ddde��e
dde��gZddgZ
								dd�Zy)�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/r0r1r�zPDN of the group member to be removed.
The --object-types option will be ignored.r�r�r�r�r�r�r�r�r6r?r�Nc
���|j�}
|j|
d��}|�|�|j�td��	t	|t�||
��}g}
|�|
|z
}
|�|
|j
d�z
}
|	j
d�}|�|j|�}|j||
d||��|jjd|z�y#t$r}td|�d	|�d
�|��d}~wwxYw)NTrAr�rCr�Fr�zFailed to remove members z
 from group "rHzRemoved members from group %s
r�r�s                r�r�zcmd_group_remove_members.run$s#���
#�
#�
%���(�(��d�(�C�����!6��J�J�L��H�J�
J�	n��a�n�.>�&+��4�E��L��$��	�)���(��
� 3� 3�C� 8�8��!-�!3�!3�C�!8���)�!&�!=�!=�n�!M���*�*�9�+7�AF�8J�:H�	
+�
J�	
�	�	���9�I�E�F���	n��P]�_h�i�kl�m�m��	n�s�A0C�	C4�C/�/C4r�r�r�r�r�r�r��s����"X�H��)�)��-�-��.�.���	�t�W�#J�QT��3�	(��}�B���		 �
	��4�-��	�	�!�1��	�#�M�.�/�0�J��������.�(Gr�r�c
���eZdZdZdZedddedd��ed	d
dd�
�eddde��eddddd��gZejejejd�Z							dd�Z
y)�cmd_group_listzList all groups.�%prog [options]r,r-r.r/r0r1z-vz	--verbosez3Verbose output, showing group type and group scope.r<�r2r=z-bz	--base-dnzSpecify base DN to use.r6�	--full-dn�full_dnF�)Display DN instead of the sAMAccountName.�r5r>r=r2�r)r+r*Nc	��|j�}|j|d��}	t|t�|	|��}
dg}|r|ddgz
}|
j	�}|r|
j|�}|
j
|tjd|��}
t|
�d	k(ry|�r�|jjd
�|jjd�|
D�]�}|jjd|jdd	�
�z�ttd|dz�dz�}|tttjd���k(r|jjd��n�|tttjd���k(r|jjd��nz|tttjd���k(r|jjd��n3|tttjd���k(r|jjd�n�|ttt jd���k(r|jjd�n�|ttt jd���k(r|jjd�na|ttt jd���k(r|jjd�n|jjd�t|jdg���}|jjd|z����y|
D]a}|r.|jjd|jd�z��3|jjd|jdd	�
�z��cy) NTrArC�samaccountnamer`�member�(objectClass=group)�r^rXrYrzQGroup Name                                  Group Type      Group Scope  Members
zQ--------------------------------------------------------------------------------
z%-44srZz%sl��r zSecurity         Builtin  r!zSecurity         Domain   r"zSecurity         Global   r#zSecurity         UniversalzDistribution     Global   zDistribution     Domain   zDistribution     Universalz                          �r>z    %6u
�%s
rN)rgrhrr
r�r�rzrrr�r{rvrwre�hexr�rdrf)r�r)r+r*r0�verbose�base_dnr�rGr�r�rYr�r�r��hgtype�num_memberss                 r�r�zcmd_group_list.runis����
#�
#�
%���(�(��d�(�C���!�.�*:�"'�B�0��� ����k�8�,�,�E��O�O�%�	���4�4�W�=�I��l�l�9�C�,=�,=�'<�!&��(��
��H��M����I�I�O�O�p�q��I�I�O�O�p�q��
;���	�	����#�'�'�2B��'�*J� J�K��S���K�(8�!8�9�<N�N�O���c�#�n�&8�&8��&C�"D�E�E��I�I�O�O�$@�A���C��(:�(:�8�(D�$E� F�F��I�I�O�O�$@�A���C��(:�(:�8�(D�$E� F�F��I�I�O�O�$@�A���C��(:�(:�;�(G�$H� I�I��I�I�O�O�$@�A���C�(:�(>�(>�x�(H�$I� J�J��I�I�O�O�$@�A���C�(:�(>�(>�x�(H�$I� J�J��I�I�O�O�$@�A���C�(:�(>�(>�{�(K�$L� M�M��I�I�O�O�$@�A��I�I�O�O�$@�A�!�#�'�'�(�B�'�"?�@���	�	����k� 9�:�)
;�,�
K����I�I�O�O�F�S�W�W�T�]�$:�;���	�	�������1A�q��)I� I�J�
Kr�)NNNNFNF)r�r�r�r�r�rr�r�r�r�r�r�r�r�r�r�r�r�r�Os���� �H�	�t�W�#J�QT��3�	(��t�[�I�"�	$�	�t�[�-��	�	�{���"�?�	A�
�M� �)�)��.�.��-�-����������9Kr�r�c
���eZdZdZdZedddedd��ed	d
dd�
�edddd��eddddd��gZejejejd�ZdgZ
							dd�Zy)�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
r'r,r-r.r/r0r1z--hide-expiredz!Do not list expired group membersFr<)r2r>r=z--hide-disabledz"Do not list disabled group members)r>r=r2r�r�r�r�r�r?Nc	�(�|j�}	|j|	d��}
	t|t�|
|	��}dt	j
|�z}	|j
|j�tj|dg��}
|
djdd��}ttj|�}|j�\}}d
|z}d}|dur|j!�}d|z}d}|durd
tj"t$fz}d|�d|�d|�|�d�}|j
|j�tj|ddg��}
t'|
�dk(ry|
D]x}|r.|j(j+d|jd�z��3|jdd��}|�|jdd��}|j(j+d|z��zy#t$rtd	|z��wxYw#t,$r}td|�d|����d}~wwxYw)NTrArCz)(&(objectClass=group)(sAMAccountName=%s))rRr�rrZr�z<SID=%s>r\z>(|(!(accountExpires=*))(accountExpires=0)(accountExpires>=%u))z(!(userAccountControl:%s:=%u))z(&(|(primaryGroupID=z)(memberOf=z))rW�samAccountName�cnr�rNzFailed to list members of "z
" group - )rgrhrr
rrr�rzr�r�rer�rrr	rnr��
get_nttime�OID_COMPARATOR_ANDrr{rvrwri)r�r?r+r)r*r0�hide_expired�
hide_disabledr�rGr�r��
search_filterr��group_sid_binary�	group_sid�
group_dom_sidr��group_sid_dn�filter_expires�current_nttime�filter_disabledr�r��member_namer�s                          r�r�zcmd_group_list_members.run�sC���
#�
#�
%���(�(��d�(�C��6	/��a�n�.>�&+��4�E�I� �.�.�y�9�:�M�
N��l�l�5�?�?�#4�C�<M�<M�/<�*5��#�8��$'�q�6�:�:�k�q�:�#A� �#�8�#3�#3�5E�F�I�#,�?�?�#4� �]�C�%��3�L��N��t�#�!&�!1�!1�!3��#&�*8�	#9��!�O���$�"B��*�*�,=�F?�#?����\�?�N�D�F��,�,�u���0��8I�8I�*0�&6��%=��?�C��C��A�
���
6����I�I�O�O�F�S�W�W�T�]�$:�;��!�g�g�&6�A�g�>���&�"%�'�'�$�A�'�"6�K��	�	����� 4�5�
6��?�
N�"�#>�)�#L�M�M�
N��R�	/�� )�1� .�/�
/��	/�s8�/G2�AG�B;G2�A=G2�G/�/G2�2	H�;H�H)NNNNFFF)r�r�r�r�r�rr�r�r�r�r�r�r�r�r�r�r�r�r�r��s����-�H�	�t�W�#J�QT��3�	(���7��"�	$�	� ��"�8�	:�	�{���"�?�	A��M�$�)�)��.�.��-�-�����J��������B/r�r�c��eZdZdZdZedddedd��gZd	d
gZe	je	je	jd�Z
		dd
�Zy)�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/r0r1r?�
new_parent_dnr�Nc�J�|j�}|j|d��}t|t�||��}	t	j
|	|	j
��}
dt	j|�z}	|	j|
|tj��}|dj}
	|	j|�}t	j
|	t!|
��}|j#t%|
�d
z
�|j'|�	|	j)|
|�|j*j-d|�d
|�d��y#t$rtd|z��wxYw#t$r }td|�d	|j����d}~wwxYw#t$r}td|z|��d}~wwxYw)NTrArCr��r]rXr^rr�zInvalid new_parent_dn "z": rzFailed to move group "%s"z
Moved group "z" into "z"
)rgrhrr
rr�Dnr�r�rzr�rNr�rr�ri�messager��remove_base_componentsr{�add_base�renamervrw)r�r?rr+r)r*r0rGr�r�r�r�r�r��full_new_parent_dnr��full_new_group_dns                 r�r�zcmd_group_move.run:s���
�
#�
#�
%���(�(��d�(�C���!�.�*:�"'�B�0���F�F�5�%�/�/�"3�4�	�=��#�#�I�.�/��	J��,�,�I�*0�%(�%6�%6��8�C��1�v�y�y�H�	;�!&�!=�!=�m�!L��
 �F�F�5�#�h�-�8���0�0��X���1B�C��"�"�#5�6�	K��L�L��#4�5�	
�	�	���"�$6�8�	9��#�	J��:�i�H�I�I�	J��
�	;�� -�q�y�y� :�;�
;��	;���	K��:�Y�F��J�J��	K�s<�81D>�*E�	F�>E�	F�"E=�=F�	F"�F�F"r��r�r�r�r�r�rr�r�r�r�r�r�r�r�r�r�r�r�rrsk���:=�H�	�t�W�#J���S�	2��M�
��/�J��)�)��.�.��-�-���FJ� $�!9r�rc��eZdZdZdZedddedd��ed	d
ed��gZd
gZe	je	je	jd�Z
		dd�Zy)�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/r0r1z--attributesz:Comma separated list of attributes, which will be printed.�group_attrs)r2r3r5r?r�Nc��|j�}|j|d��}t|t�||��}	d}
|r|j	d�}
dtj|�z}|	j�}	|	j||t
j|
��}
|
dj}|
D]3}tj|	|�}|jj!|��5y#t$rtd|z��wxYw)	NTrArCr�z,(&(objectCategory=group)(sAMAccountName=%s)))r]rXr^rYrr�)rgrhrr
r�rrr�r�rzr�rNr�rr�get_ldif_for_editorrvrw)r�r?r+r)r*r0rrGr�r�rYr��domaindnr��user_dnr��
group_ldifs                 r�r�zcmd_group_show.run�s
���
#�
#�
%���(�(��d�(�C���!�.�*:�"'�B�0������%�%�c�*�E�@��$�$�Y�/�0���?�?�$��	J��,�,�H��%(�%6�%6�e��E�C��!�f�i�i�G��	(�C��3�3�E�3�?�J��I�I�O�O�J�'�	(���	J��:�i�H�I�I�	J�s�92C$�$C<�NNNNNrr�r�r�rr^s|���>.�H�	�t�W�#J���S�	2��~�.��m�	-��M���J��)�)��.�.��-�-���IM� $�(r�rc��eZdZdZdZedddedd��gZejejejd	�Zd
�Z
d
d�Zy)�cmd_group_statsz+Summary statistics about group memberships.r�r,r-r.r/r0r1r�c�\�d}|j�D]\}}||ks�||ks�||z
}�|S)Nr)�items)r��	range_min�	range_max�group_freqs�total_count�members�counts       r��num_in_rangezcmd_group_stats.num_in_range�sD����)�/�/�1�	%�N�G�U��G�#��9�(<��u�$��	%��r�Nc��|j�}|j|d��}t|t�||��}|j	�}|j|tjdddg��}	i}
d}|	D]B}t|jd��}
t|jdg�	��}||
|
<||z
}�D|	j}|jjd
�|jjd�|jjdj|��|jjd
j|��|t|�z}|jjd|z�t!|
j#��}t!|
j%��}|j't)|��}||}|jjdj|||��|j+�|dz}||}|dzdk(r|||dz
zdz}|jjdj|��t-t.�}|
j1�D]\}}||xxdz
cc<�dddddddddddddd d!d"d#d$d%d&d'd(d)d*d+d,d-|fg}|jjd.�|jjd�|D]^}|d}|d}||kDrnM|j3|||�}|dk7s�-d/j||�}|jjd0||fz��`|jjd1�y)2NTrArCr�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
)rgrhrr
r�rzrrr�r�rer{r%rvrw�format�float�list�keys�values�index�max�sortrr�rr&)r�r)r+r*r0rGr�r�r�r��group_assignments�total_membershipsr�r�r��
num_groups�average�group_names�
group_membersr[�max_members�midpoint�medianr"rL�bands�band�
band_start�band_end�band_strs                              r�r�zcmd_group_stats.run�s[��
�
#�
#�
%���(�(��d�(�C���!�.�*:�"'�B�0���O�O�%�	��l�l�9�C�,=�,=�'<�"2�H�!=��?��
�����	-�C��s�w�w�/�0�1�D��c�g�g�h��g�;�<�K�&1��d�#���,��		-��Y�Y�
��	�	���8�9��	�	���M�N��	�	���-�4�4�Z�@�A��	�	���2�9�9�:K�L�M�#�e�J�&7�7���	�	���;�g�E�F��,�1�1�3�4���.�5�5�7�8�
��!�!�#�m�"4�5��#�C�(���	�	���2�9�9�+�:E�c�:J�L�	M�������?���x�(����>�Q���}�X��\�:�:�a�?�F��	�	���;�B�B�6�J�K�"�#�&��"3�"9�"9�";�	*��E�;���$��)�$�	*�
����8�X��8�X�x��8��8�Z��Z��Z��Z���|�\�<���%�'��	
�	�	���;�<��	�	���M�N��
	G�D��a��J��A�w�H��K�'���*�*�:�x��M�J��Q��$�+�+�J��A���	�	�����*�/E� E�F�
	G�	
�	�	���S�Tr�r�)r�r�r�r�r�rr�r�r�r�r�r�r�r&r�r�r�r�rr�s[��5� �H�	�t�W�#J�QT��3�	(��M��)�)��.�.��-�-����KUr�rc��eZdZdZdZedddedd��ed	d
e��gZdgZe	je	je	jd
�Z
		dd�Zy)�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.
    r'r,r-r.r/r0r1z--editorzQEditor to use instead of the system default, or 'vi' if no system default is set.r6r?r�Nc��|j�}|j|d��}t|t�||��}	dt	j
|�z}
|	j
�}	|	j||
tj��}|dj}
t|�dk7rtd	|t|�fz��|d}tj|	|�}|�#tj j#d
�}|�d}t%j&d�
�5}|j)t+|��|j-�	t/||j0g�t5|j0�5}|j7�}ddd�ddd�|	j9�}t;|�d}|	j=||�}t|�dk(r|j>j)d�y	|	jA|�|j>j)d|z�y#t$rtd|z��wxYw#t2$r}t3d|��d}~wwxYw#1swY��xYw#1swY��xYw#tB$r}td|z|��d}~wwxYw)NTrArCr�r
rr�rz'Invalid number of results: for "%s": %d�EDITOR�viz.tmp)�suffixzERROR: zNothing to do
zFailed to modify group '%s': z!Modified group '%s' successfully
)"rgrhrr
rrr�r�rzr�rNr�rr{rr�os�environre�tempfile�NamedTemporaryFilerwr�flushrr�r�open�read�
parse_ldif�next�msg_diffrv�modifyri)r�r?r+r)r*r0�editorrGr�r�r�rr�r�r��result_ldif�t_filer��edited_file�edited_message�msgs_edited�
msg_edited�res_msg_diffs                       r�r�zcmd_group_edit.runEsr��
�
#�
#�
%���(�(��d�(�C���!�.�*:�"'�B�0��>��#�#�I�.�/���?�?�$��	J��,�,�H�*0�%(�%6�%6��8�C��1�v�y�y�H��s�8�q�=��H�!*�S��X�6� 7�8�
8��!�f���0�0���<���>��Z�Z�^�^�H�-�F��~���
�
(�
(��
7�	4�6��L�L��;�/�0��L�L�N�
7��F�F�K�K�0�1��f�k�k�"�
4�k�!,�!1�!1�!3��
4�	4��&�&�~�6���+�&�q�)�
��~�~�c�:�6���|���!��I�I�O�O�-�.��	O��L�L��&�	
�	�	���<�y�H�I��M�	J��:�i�H�I�I�	J��(&�
7�(��A�6�6��
7��
4�
4��	4�	4��(�	O��>��J�A�N�N��	O�sl�$1H�+I�>H2�I�*I�;I�'I'�H/�2	I�;I�I�I�I	�I�I$�'	J�0I?�?Jrrr�r�r�r`r`s}�� �B-�H�	�t�W�#J���S�	2��z�!7�=@�	B��M���J��)�)��.�.��-�-���IM��7Jr�r`c��eZdZdZdZedddedd��gZd	d
gZe	je	je	jd�Z
		dd
�Zy)�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/r0r1r?rbr�Nc���|j�}|j|�}t|t�||��}	|	j	�}
djt
j|��}|	j|
tj|��}t|�dk(rtdj|���|dj}
d|dvrtdj|���dj|�}|	j|
tj|��}t|�dk7rtd	j|���|jd
�s|jjd�dj|
|�}	|	j!|�|jjdj|��y#tj"$r }td
j||���d}~wwxYw)NrCz(samaccountname={}))r^rXrzUnable 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
)rgrhrr
r�rIrrr�rzr�r{rrNrervrw�modify_ldifrs)r�r?rbr+r)r*r0rGr�r�rr�r�r��	group_modr�s                r�r�zcmd_group_add_unix_attrs.run�s����
#�
#�
%���(�(��,���!�.�*:�"'�B�0���?�?�$��'�-�-�c�.?�.?�	�.J�K���l�l�8�!$�!2�!2�&,��.��
��H��M��:�A�A�)�L�M�M��q�6�9�9���#�a�&� ��:�A�A�)�L�M�M�8�>�>�y�I���l�l�8�!$�!2�!2�&,��.��
��H��M��;�B�B�9�M�N�N��v�v�-�.��I�I�O�O�1�
2�
�
�F�8�Y��	�	6����i�(�
	
�	�	���<�C�C�I�N�O��	�|�|�	6��B� &��y�!� 4�6�
6��	6�s�F=�=G0�G+�+G0r�rr�r�r�ryrysn���29�H�	�t�W�#J���S�	2��M�
�{�+�J��)�)��.�.��-�-�
��BF� $�3Pr�ryc	���eZdZdZdZedddedd��ed	d
e��edd
d��edde��edde��gZdgZe	je	je	jd�Z
			dd�Zy)�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.
    r'r,r-r.r/r0r1z--force-new-cnz;Specify a new CN (RND) instead of using the sAMAccountName.r6z
--reset-cnzqSet the CN (RDN) to the sAMAccountName. Use this option to reset the changes made with the --force-new-cn option.r<r�r;zNew mail addressz--samaccountnamez,New account name (sAMAccountName/logon name)r?r�Nc
	���|r
|	rtd��|dk(rtd��|dk(rtd��|j�}
|j|
d��}t|t	�||
��}tj||j��}
dtj|�z}	|j|
t
j|gd	��
�}|d}|j}|j�}|d
d}|�|}n
|�|}n|d}|d}t|�t|�k7xr(t|�t|�k(xs|	xst|�}tj|d|z�}|j!|�tj"�}||_|j%||d|�|j%||d|�t'|�dkD}|j)�	|r|j+|�|r|j-||�|j3�|r%|j4j7d|�d|�d|�d��|re|j4j7d|z�|j9�D]3}|dk(r�	|j4j7|�d||r||nd�d���5yy#t$rtd|z��wxYw#t.$r$}|j1�td|z|��d}~wwxYw)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'TrArCz)(&(objectClass=group)(samaccountname=%s)))rOr��mailr�rr�r�rOzCN=%sr�zFailed to rename group "%s"zRenamed CN of group "z" from "z" to "z" successfully
zCFollowing attributes of group "%s" have been changed successfully:
rNz: z	[removed]rV)rrgrhrr
rrrr�r�rzr�rNr��parentr��boolr�Message�prepare_attr_replacer{�transaction_startrorri�transaction_cancel�transaction_commitrvrwrL)r�r?r+r)r*r0r�r��force_new_cn�reset_cnrGr�r�r�r�r��	old_groupr��group_parent_dn�old_cn�new_cn�expected_cn�must_change_cn�new_group_dnr�group_attributes_changedr��attrs                            r�r�zcmd_group_rename.runs7���H�� ;�<�
<��2��� 0�1�
1��R��� <�=�
=��
#�
#�
%���(�(��d�(�C���!�.�*:�"'�B�0���F�F�5�%�/�/�"3�4�	�=��#�#�I�.�/��	I��,�,�I�%(�%6�%6�*0�&.���C��A��I� �|�|�H�#�/�/�+���4���#���#�!�F�
�
'�#�F��/�0�F� � 0�1���V���F��3�:��f�+��[�)9�9�9�"�9�&*�<�&8�	��v�v�e�W�v�%5�6�����o�.��k�k�m��!���
�"�"�;�	�;K�#1�	3�
�"�"�;�	�6�<�P�#&�{�#3�a�#7� �	���!�	M�'����[�)�����X�|�4�	� � �"���I�I�O�O�09�6�6�K�
L�$��I�I�O�O�6�9B�D�
E�#�(�(�*�
D���4�<���	�	���d�*�4�0�5@��4E�6A�5B�!C�D�
D�$��c�	I��9�Y�G�H�H�	I��P�	M��$�$�&��<�y�H�!�L�L��	M�s$�'6J�'J7�J4�7	K$�K�K$)NNNNNNNNrr�r�r�rr�s���!�F-�H�	�t�W�8��e�#�	/�	��N��	�	�|�P�"�	$�	��#��	�	�!�?��	�
�M�&��J��)�)��.�.��-�-���IM�IM��XDr�rc��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<y)�	cmd_groupzGroup management.ru�creater��edit�
addmembers�
removemembersrK�listmembers�move�show�stats�addunixattrsrN)r�r�r�r��subcommandsr&r�r`r�r�r�r�rrrryrr�r�r�r�r�xs�����K�&��K���)�O�K���,�.�K���(�*�K��� 5� 7�K���#;�#=�K�� �(�*�K���!7�!9�K�
��(�*�K���(�*�K���*�,�K���":�"<�K���,�.�K��r�r�)<�samba.getopt�getoptr��samba.netcmdrrrrrr�	samba.ndrrr�samba.dcerpcr	�
samba.authr
�samba.samdbr�
samba.dsdbrr
rrrrrrrrrrr�collectionsr�
subprocessrr�samba.commonrrrergr\r�dictrdrfr&r�r�r�r�r�rrrr`ryrr�r�r�r��<module>r�sM��&�D�D�
�*�!�%������$�5�3�	����"D�!B�!<�$B�D�E���%J�%D�(J�L�M��
V8�G�V8�r;:�w�;:�|]C�G�]C�@[G�w�[G�|SK�W�SK�lf/�W�f/�RM9�W�M9�`L(�W�L(�^cU�g�cU�LiJ�W�iJ�X\P�w�\P�~XD�w�XD�t/��/r�

Zerion Mini Shell 1.0