a
    Wa|                     @   s  d dl mZ d dlmZmZmZmZ d dlZd dl	m
Z
 d dlmZ d dlmZ d dlmZ d dlmZmZmZmZmZmZmZmZ d dlmZ d d	lmZmZ d d
lm Z  d dl!Z!d dl"Z"ddl#m$Z$ e%eeeedZ&e%eeedZ'G dd deZ(G dd deZ)G dd deZ*G dd deZ+G dd deZ,G dd deZ-G dd deZ.G dd deZ/G dd  d eZ0G d!d" d"eZ1G d#d$ d$eZ2G d%d& d&eZ3dS )'    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)defaultdict)
check_callCalledProcessError)	get_bytes   )common)BuiltinDomainGlobal	Universalr   r   r   c                   @   s   e Zd ZdZdZejejejdZ	e
dddeddd	e
d
dede
ddg ddde
ddddgdde
ddede
ddede
ddede
ddede
ddedg	Zd gZd$d"d#Zd!S )%cmd_group_adda  Creates a new AD group.

This command creates 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 creates a 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-scopeZchoicer   z)Group scope (Domain | Global | Universal))r*   choicesr)   z--group-typeSecurityZDistributionz$Group type (Security | Distribution)z--descriptionzGroup's descriptionz--mail-addresszGroup's email addressz--noteszGroups's notesz--gid-numberzGroup's Unix/RFC2307 GID numberz--nis-domainzSFU30 NIS Domain	groupnameNc              
   C   s   |pddkrt |t}nt|t}|d u r6|d usF|d urN|d u rNtd| }|j|dd}z0t|t	 ||d}|j
||||	|
|||d W n2 ty } ztd| |W Y d }~n
d }~0 0 | jd|  d S )	Nr/   zcBoth --gid-number and --nis-domain have to be set for a RFC2307-enabled group. Operation cancelled.TZfallback_machineZurlZsession_infoZcredentialslp)groupou	grouptypedescriptionZmailaddressnotes	gidnumberZ	nisdomainzFailed to create group "%s"zAdded group %s
)security_groupgetr   distribution_groupr   r   get_loadparmget_credentialsr	   r   Znewgroup	Exceptionoutfwrite)selfr0   r"   r    r!   r'   r4   Zgroup_scopeZ
group_typer6   Zmail_addressr7   Z
gid_numberZ
nis_domainZgtyper3   credssamdbe rE   4/usr/lib/python3/dist-packages/samba/netcmd/group.pyrunp   s$     

$zcmd_group_add.run)NNNNNNNNNNNN)__name__
__module____qualname____doc__synopsisoptionsSambaOptionsVersionOptionsCredentialsOptionstakes_optiongroupsr   strinttakes_options
takes_argsrG   rE   rE   rE   rF   r   5   s<   
   r   c                   @   sL   e Zd ZdZdZejejejdZ	e
dddeddd	gZd
gZdddZdS )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&   r'   r(   r0   Nc              
   C   s   |  }|j|dd}t|t ||d}dt| }	z(|j| tj|	dgd}
|
d j	}W n t
y|   td| Y n0 z|| W n2 ty } ztd	| |W Y d }~n
d }~0 0 | jd
|  d S )NTr1   r2   )(&(sAMAccountName=%s)(objectClass=group))dn)basescope
expressionattrsr   Unable to find group "%s"zFailed to remove group "%s"zDeleted group %s
)r<   r=   r	   r   ldbbinary_encodesearch	domain_dnSCOPE_SUBTREErX   
IndexErrorr   deleter>   r?   r@   )rA   r0   r"   r    r!   r'   r3   rB   rC   filterresgroup_dnrD   rE   rE   rF   rG      s,    
$zcmd_group_delete.run)NNNNrH   rI   rJ   rK   rL   rM   rN   rO   rP   rQ   r   rR   rT   rU   rG   rE   rE   rE   rF   rV      s   
rV   c                   @   sv   e Zd ZdZdZejejejdZ	e
dddeddd	e
d
dedde
dddede
ddedgZddgZdddZdS )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-typesComma 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-   r0   listofmembers?Nc
              
   C   s   |  }
|j|
dd}|d u r6|d u r6|   tdzpt|t ||
d}g }|d ur^||7 }|d urt||d7 }|	d}|d ur||}|j||d||d W n6 t	y } ztd|||f W Y d }~n
d }~0 0 | j
d|  d S )	NTr1   6Either listofmembers or --member-dn must be specified.r2   ,Zadd_members_operationZmember_typesmember_base_dnz+Failed to add members %r to group "%s" - %szAdded members to group %s
r<   r=   Zusager   r	   r   splitnormalize_dn_in_domainZadd_remove_group_membersr>   r?   r@   rA   r0   Zlistofmembersr"   r    r!   r'   rz   Z	member_dnZobject_typesr3   rB   rC   ZgroupmembersZgroup_member_typesrD   rE   rE   rF   rG      s:    


zcmd_group_add_members.run)NNNNNNNrq   rh   rE   rE   rE   rF   ri      sD   
	        ri   c                   @   sv   e Zd ZdZdZejejejdZ	e
dddeddd	e
d
dedde
dddede
ddedgZddgZdddZdS )cmd_group_remove_membersa  Remove 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.
rj   r   r#   r$   r%   r&   r'   r(   rk   zPDN of the group member to be removed.
The --object-types option will be ignored.rl   rm   ro   rp   rq   rr   rt   ru   r-   r0   rv   Nc
              
   C   s   |  }
|j|
dd}|d u r6|d u r6|   tdzpt|t ||
d}g }|d ur^||7 }|d urt||d7 }|	d}|d ur||}|j||d||d W n6 t	y } ztd||f |W Y d }~n
d }~0 0 | j
d	|  d S )
NTr1   rw   r2   rx   Fry   z+Failed to remove members %r from group "%s"zRemoved members from group %s
r{   r~   rE   rE   rF   rG   \  s8    


(zcmd_group_remove_members.run)NNNNNNNrq   rh   rE   rE   rE   rF   r   )  sD   
	        r   c                
   @   sr   e Zd ZdZdZedddeddded	d
dddedddededdddddgZej	ej
ejdZdddZdS )cmd_group_listzList all groups.%prog [options]r#   r$   r%   r&   r'   r(   z-vz	--verbosez3Verbose output, showing group type and group scope.
store_true)r)   rn   z-bz	--base-dnzSpecify base DN to use.r-   	--full-dnfull_dnF)Display DN instead of the sAMAccountName.r,   rs   rn   r)   r    r"   r!   Nc                 C   sV  |  }|j|dd}	t|t |	|d}
dg}|r>|ddg7 }|
 }|rT|
|}|
j|tjd|d}t	|d	krxd S |r| j
d
 | j
d |D ]l}| j
d|jdd	d  ttd|d  d@ }|tttdkr| j
d n|tttdkr| j
d n|tttdkrB| j
d n|tttdkrh| j
d n~|tttdkr| j
d nX|tttdkr| j
d n2|tttdkr| j
d n| j
d t	|jdg d}| j
d|  qnF|D ]@}|r4| j
d|d  q| j
d|jdd	d  qd S ) NTr1   r2   samaccountnamer5   member(objectClass=group)rZ   r[   r\   r   zQGroup Name                                  Group Type      Group Scope  Members
zQ--------------------------------------------------------------------------------
z%-44sidxz%sl    r   zSecurity         Builtin  r   zSecurity         Domain   r   zSecurity         Global   r   zSecurity         UniversalzDistribution     Global   zDistribution     Domain   zDistribution     Universalz                          rs   z    %6u
%s
rX   )r<   r=   r	   r   ra   r}   r`   r^   rb   lenr?   r@   r:   hexrS   r9   r;   )rA   r    r"   r!   r'   verboseZbase_dnr   r3   rB   rC   r\   ra   rf   msgZhgtypenum_membersrE   rE   rF   rG     sZ    


zcmd_group_list.run)NNNNFNF)rH   rI   rJ   rK   rL   r   rR   rT   rM   rN   rP   rO   rQ   rG   rE   rE   rE   rF   r     s>   
       r   c                   @   s\   e Zd ZdZdZedddeddded	d
ddddgZej	ej
ejdZdgZdddZdS )cmd_group_list_memberszList 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&   r'   r(   r   r   Fr   r   r   r   r0   Nc              
   C   s  |  }|j|dd}z,t|t ||d}	dt| }
z0|	j|	 tj|
dgd}|d j	ddd}W n t
y   td	| Y n0 ttj|}| \}}d
| }d||f }
|	j|	 tj|
ddgd}t|dkrW d S |D ]X}|r
| jd|	d  q|j	ddd}|d u r0|j	ddd}| jd|  qW n6 tyz } ztd||f W Y d }~n
d }~0 0 d S )NTr1   r2   z)(&(objectClass=group)(sAMAccountName=%s))Z	objectSidr   r   r   r]   z<SID=%s>z#(|(primaryGroupID=%s)(memberOf=%s))ZsamAccountNameZcnr   rX   z)Failed to list members of "%s" group - %s)r<   r=   r	   r   r^   r_   r`   ra   rb   r:   rc   r   r   r   Zdom_sidr|   r   r?   r@   r>   )rA   r0   r"   r    r!   r'   r   r3   rB   rC   Zsearch_filterrf   Zgroup_sid_binaryZ	group_sidZgroup_dom_sidZridZgroup_sid_dnr   member_namerD   rE   rE   rF   rG     sR    
zcmd_group_list_members.run)NNNNF)rH   rI   rJ   rK   rL   r   rR   rT   rM   rN   rP   rO   rQ   rU   rG   rE   rE   rE   rF   r     s,   

     r   c                   @   sN   e Zd ZdZdZedddedddgZd	d
gZe	j
e	je	jdZdddZd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(   r0   new_parent_dnr   Nc              
   C   sV  |  }|j|dd}t|t ||d}	t|	|	 }
dt| }z |	j|
|tj	d}|d j
}W n ty   td| Y n0 z|	|}W n6 ty } ztd||jf W Y d }~n
d }~0 0 t|	t|}|t|d	  || z|	|| W n4 ty< } ztd
| |W Y d }~n
d }~0 0 | jd||f  d S )NTr1   r2   rW   rY   r[   rZ   r   r]   zInvalid new_parent_dn "%s": %sr   zFailed to move group "%s"zMoved group "%s" into "%s"
)r<   r=   r	   r   r^   ZDnra   r_   r`   rb   rX   rc   r   r}   r>   messagerR   Zremove_base_componentsr   Zadd_baserenamer?   r@   )rA   r0   r   r"   r    r!   r'   r3   rB   rC   ra   re   rf   rg   Zfull_new_parent_dnrD   Zfull_new_group_dnrE   rE   rF   rG   Y  sB    
$zcmd_group_move.run)NNNNrH   rI   rJ   rK   rL   r   rR   rT   rU   rM   rN   rP   rO   rQ   rG   rE   rE   rE   rF   r   -  s     r   c                   @   sZ   e Zd ZdZdZedddeddded	d
eddgZdgZe	j
e	je	jdZdddZdS )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,   r0   r   Nc                 C   s   |  }|j|dd}t|t ||d}	d }
|r:|d}
dt| }|	 }z"|	j||tj	|
d}|d j
}W n ty   td| Y n0 |D ]}t|	|}| j| qd S )	NTr1   r2   rx   z,(&(objectCategory=group)(sAMAccountName=%s)))rY   r[   rZ   r\   r   r]   )r<   r=   r	   r   r|   r^   r_   ra   r`   rb   rX   rc   r   r   get_ldif_for_editorr?   r@   )rA   r0   r"   r    r!   r'   r   r3   rB   rC   r\   re   domaindnrf   Zuser_dnr   Z
group_ldifrE   rE   rF   rG     s,    
zcmd_group_show.run)NNNNNr   rE   rE   rE   rF   r   }  s$   	  r   c                   @   sN   e Zd ZdZdZedddedddgZej	ej
ejd	Zd
d ZdddZdS )cmd_group_statsz+Summary statistics about group memberships.r   r#   r$   r%   r&   r'   r(   r   c                 C   s2   d}|  D ] \}}||kr||kr||7 }q|S )Nr   )items)rA   Z	range_minZ	range_maxgroup_freqsZtotal_countmemberscountrE   rE   rF   num_in_range  s
    
zcmd_group_stats.num_in_rangeNc                 C   sp  |  }|j|dd}t|t ||d}| }|j|tjdddgd}	i }
d}|	D ]4}t|	d}t
|j	dg d	}||
|< ||7 }qT|	j}| jd
 | jd | jd| | jd| |t| }| jd|  t|
 }t|
 }|t|}|| }| jd|||  |  |d }|| }|d dkrh|||d   d }| jd| tt}|
 D ]\}}||  d7  < qdddddddddddddd d!d"d#d$d%d&d'd(d)d*d+d,d-|fg}| jd. | jd |D ]^}|d }|d }||kr$ q`| |||}|dkr d/||}| jd0||f  q | jd1 d S )2NTr1   r2   r   r   r   r   r   r   zGroup membership statistics*
z2-------------------------------------------------
zTotal groups: {0}
zTotal memberships: {0}
z Average members per group: %.2f
zMax members: {0} ({1})
   r   zMedian members per group: {0}

)r   r   )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
)r<   r=   r	   r   ra   r`   r^   rb   rR   r:   r   r   r?   r@   formatfloatlistkeysvaluesindexmaxsortr   rS   r   r   )rA   r    r"   r!   r'   r3   rB   rC   ra   rf   Zgroup_assignmentsZtotal_membershipsr   namer   Z
num_groupsZaverageZgroup_namesZgroup_membersr   Zmax_membersZmidpointZmedianr   groupZbandsZbandZ
band_startZband_endZband_strrE   rE   rF   rG     sv    





zcmd_group_stats.run)NNNN)rH   rI   rJ   rK   rL   r   rR   rT   rM   rN   rP   rO   rQ   r   rG   rE   rE   rE   rF   r     s   
r   c                   @   sX   e Zd ZdZdZedddeddded	d
edgZdgZe	j
e	je	jdZdddZdS )cmd_group_edita  Modify 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&   r'   r(   z--editorzQEditor to use instead of the system default, or 'vi' if no system default is set.r-   r0   r   Nc                 C   s&  |  }|j|dd}t|t ||d}	dt| }
|	 }z |	j||
tjd}|d j	}W n t
y|   td| Y n0 t|dkrtd	|t|f |d }t|	|}|d u rtjd
}|d u rd}tjdd}|t| |  zt||jg W n0 ty8 } ztd|W Y d }~n
d }~0 0 t|j}| }W d    n1 sd0    Y  W d    n1 s0    Y  |	|}t|d }|	||}t|dkr| jd d S z|	 | W n4 t!y } ztd| |W Y d }~n
d }~0 0 | jd|  d S )NTr1   r2   rW   r   r   r]   r   z'Invalid number of results: for "%s": %dZEDITORZviz.tmp)suffixzERROR: zNothing to do
zFailed to modify group '%s': z!Modified group '%s' successfully
)"r<   r=   r	   r   r^   r_   ra   r`   rb   rX   rc   r   r   r   r   osenvironr:   tempfileZNamedTemporaryFiler@   r   flushr   r   r   openreadZ
parse_ldifnextZmsg_diffr?   Zmodifyr>   )rA   r0   r"   r    r!   r'   Zeditorr3   rB   rC   re   r   rf   rg   r   Zresult_ldifZt_filerD   Zedited_fileZedited_messageZmsgs_editedZ
msg_editedZres_msg_diffrE   rE   rF   rG   d  s^    
 H
$zcmd_group_edit.run)NNNNNr   rE   rE   rE   rF   r   2  s"   !  r   c                   @   sN   e Zd ZdZdZedddedddgZd	d
gZe	j
e	je	jdZdddZdS )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(   r0   r8   r   Nc              
   C   sB  |  }||}t|t ||d}	|	 }
dt|}|	j|
tj	|d}t
|dkrhtd||d j}d|d v rtd|d|}|	j|
tj	|d}t
|dkrtd	||d
s| jd d||}z|	| W n8 tjy* } ztd||W Y d }~n
d }~0 0 | jd| d S )Nr2   z(samaccountname={}))rZ   r[   r   zUnable to find group '{}'Z	gidNumberzGroup {} is a Unix group.z$(&(objectClass=group)(gidNumber={}))zgidNumber {} already used.zidmap_ldb:use rfc2307zYou 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
)r<   r=   r	   r   ra   r   r^   r_   r`   rb   r   r   rX   r:   r?   r@   Zmodify_ldifZLdbError)rA   r0   r8   r"   r    r!   r'   r3   rB   rC   r   re   rf   rg   Z	group_modrD   rE   rE   rF   rG     sF    



zcmd_group_add_unix_attrs.run)NNNNr   rE   rE   rE   rF   r     s     r   c                   @   s   e Zd ZdZi Ze ed< e ed< e ed< e ed< e	 ed< e
 ed< e ed< e ed	< e ed
< e ed< e ed< dS )	cmd_groupzGroup management.addrd   ZeditZ
addmembersZremovemembersr   ZlistmembersZmoveZshowZstatsZaddunixattrsN)rH   rI   rJ   rK   Zsubcommandsr   rV   r   ri   r   r   r   r   r   r   r   rE   rE   rE   rF   r     s   









r   )4Zsamba.getoptZgetoptrM   Zsamba.netcmdr   r   r   r   r^   Z	samba.ndrr   Zsamba.dcerpcr   Z
samba.authr   Zsamba.samdbr	   Z
samba.dsdbr
   r   r   r   r   r   r   r   collectionsr   
subprocessr   r   Zsamba.compatr   r   r    r   dictr9   r;   r   rV   ri   r   r   r   r   r   r   r   r   r   rE   rE   rE   rF   <module>   sD   (
V>`^VPPOfl_