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: //proc/1233/root/usr/lib/python3/dist-packages/samba/netcmd/__pycache__/ou.cpython-310.pyc
o

�/a�9�@s�ddlmZddlZddlmZddlmZmZm	Z	m
Z
ddlmZddl
mZddlmZGdd�de�ZGd	d
�d
e�ZGdd�de�ZGd
d�de�ZGdd�de�ZGdd�de�ZGdd�de
�ZdS)�N)�system_session)�Command�CommandError�Option�SuperCommand)�SamDB)�dsdb)�
attrgetterc@�ReZdZdZdZedddeddd�gZd	d
gZe	j
e	je	jd�Z
		dd
d�ZdS)�
cmd_renamea	Rename an organizational unit.

    The name of the organizational units can be specified as a full DN
    or without the domainDN component.

    Examples:
    samba-tool ou rename 'OU=OrgUnit,DC=samdom,DC=example,DC=com' \
        'OU=NewNameOfOrgUnit,DC=samdom,DC=example,DC=com'
    samba-tool ou rename 'OU=OrgUnit' 'OU=NewNameOfOrgUnit'

    The examples show how an administrator would rename an ou 'OrgUnit'
    to 'NewNameOfOrgUnit'. The new DN would be
    'OU=NewNameOfOrgUnit,DC=samdom,DC=example,DC=com'
    z'%prog <old_ou_dn> <new_ou_dn> [options]�-H�--URL�%LDB URL for database or target server�URL�H��help�type�metavar�dest�	old_ou_dn�	new_ou_dn��	sambaopts�credopts�versionoptsNc
Cs.|��}|j|dd�}t|t�||d�}	t�|	|	���}
z|	�|�}Wnty7}zt	d||f��d}~wwz|	�|�}
WntyS}zt	d||f��d}~wwz#|	j
|dtjgd�}t|�dkrp|j
�d	|�WdS|	�||
�Wnty�}zt	d
||��d}~ww|j
�d||
f�dS)NT��fallback_machine��url�session_info�credentials�lp�Invalid old_ou_dn "%s": %szInvalid new_ou_dn "%s": %s� (objectclass=organizationalUnit)��base�
expression�scope�attrsr�Unable to find ou "%s"
zFailed to rename ou "%s"zRenamed ou "%s" to "%s"
)�get_loadparm�get_credentialsrr�ldb�Dn�	domain_dn�normalize_dn_in_domain�	Exceptionr�search�
SCOPE_BASE�len�outf�write�rename)�selfrrrrrrr"�creds�samdbr/�full_old_ou_dn�e�full_new_ou_dn�res�r?�1/usr/lib/python3/dist-packages/samba/netcmd/ou.py�run@sL����������
�zcmd_rename.run�NNNN��__name__�
__module__�__qualname__�__doc__�synopsisr�str�
takes_options�
takes_args�options�SambaOptions�CredentialsOptions�VersionOptions�takes_optiongroupsrAr?r?r?r@r"s����rc@r
)�cmd_moveaiMove an organizational unit.

    The name of the organizational units can be specified as a full DN
    or without the domainDN component.

    Examples:
    samba-tool ou move 'OU=OrgUnit,DC=samdom,DC=example,DC=com' \
        'OU=NewParentOfOrgUnit,DC=samdom,DC=example,DC=com'
    samba-tool ou rename 'OU=OrgUnit' 'OU=NewParentOfOrgUnit'

    The examples show how an administrator would move an ou 'OrgUnit'
    into the ou 'NewParentOfOrgUnit'. The ou 'OrgUnit' would become
    a child of the 'NewParentOfOrgUnit' ou. The new DN would be
    'OU=OrgUnit,OU=NewParentOfOrgUnit,DC=samdom,DC=example,DC=com'
    z+%prog <old_ou_dn> <new_parent_dn> [options]rr
rrrrr�
new_parent_dnrNc
CsZ|��}|j|dd�}t|t�||d�}	t�|	|	���}
z|	�|�}Wnty7}zt	d||f��d}~wwz|	�|�}
WntyS}zt	d||f��d}~wwt�|	t
|��}|�t|�d�|�
|
�z#|	j|dtjgd�}t|�d	kr�|j�d
|�WdS|	�||�Wnty�}zt	d||��d}~ww|j�d||
f�dS)
NTrrr#zInvalid new_parent_dn "%s": %s�r$r%rr*zFailed to move ou "%s"zMoved ou "%s" into "%s"
)r+r,rrr-r.r/r0r1rrI�remove_base_componentsr4�add_baser2r3r5r6r7)r8rrRrrrrr"r9r:r/r;r<�full_new_parent_dnr=r>r?r?r@rA�sR�������
���
�zcmd_move.runrBrCr?r?r?r@rQbs����rQc@s^eZdZdZdZedddeddd�ed	d
edd�gZd
gZe	j
e	je	jd�Z
		ddd�ZdS)�cmd_adda�Add a new organizational unit.

    The name of the new ou can be specified as a full DN or without the
    domainDN component.

    Examples:
    samba-tool ou add 'OU=OrgUnit'
    samba-tool ou add 'OU=SubOU,OU=OrgUnit,DC=samdom,DC=example,DC=com'

    The examples show how an administrator would add a new ou 'OrgUnit'
    and a new ou 'SubOU' as a child of the ou 'OrgUnit'.
    �%prog <ou_dn> [options]rr
rrrrz
--descriptionzOU's description�description)rrr�ou_dnrNc
Cs�|��}|j|dd�}t|t�||d�}	z|	�|�}
Wnty/}ztd||f��d}~wwz	|	j|
|d�WntyL}ztd|
|��d}~ww|j�	d|
�dS)NTrr�Invalid ou_dn "%s": %s)rYzFailed to add ou "%s"zAdded ou "%s"
)
r+r,rrr0r1r�	create_our5r6)r8rZrrrrrYr"r9r:�
full_ou_dnr<r?r?r@rA�s$�����zcmd_add.run)NNNNNrCr?r?r?r@rW�s$
�����rWc
@sreZdZdZdZedddeddd�ed	d
ddd
d�eddddddd�gZdgZe	j
e	je	jd�Z
		ddd�ZdS)�cmd_listobjectsa�List all objects in an organizational unit.

    The name of the organizational unit can be specified as a full DN
    or without the domainDN component.

    Examples:
    samba-tool ou listobjects 'OU=OrgUnit,DC=samdom,DC=example,DC=com'
    samba-tool ou listobjects 'OU=OrgUnit'

    The examples show how an administrator would list all child objects
    of the ou 'OrgUnit'.
    rXrr
rrrr�	--full-dn�full_dnF�
store_true�"Display DNs including the base DN.�r�default�actionrz-rz--recursive�	recursivezList objects recursively.rZrNc
Cs2|��}|j|dd�}	t|t�|	|d�}
t�|
|
���}z|
�|�}Wnty7}
zt	d||
f��d}
~
wwd}tj
}|rDd}tj}zA|
j|d|gd�}t
|�|kr_|j�d	|�WdSt|td
�d�D]}|j|kroqg|sy|j�t
|��|j�d|j�qgWdSty�}
zt	d
||
��d}
~
ww)NTrrr[rrSz(objectclass=*)r%zou "%s" is empty
�dn��key�%s
z"Failed to list contents of ou "%s")r+r,rrr-r.r/r0r1r�SCOPE_ONELEVEL�
SCOPE_SUBTREEr2r4r5r6�sortedr	rgrT)r8rZrrrrr`rfr"r9r:r/r]r<�	minchildsr(�childs�childr?r?r@rA�sP����
�����zcmd_listobjects.run)NNNNFFrCr?r?r?r@r^�s*�
�
��	��r^c	@speZdZdZdZedddeddd�ed	d
ded�ed
ddddd�gZej	ej
ejd�Z						ddd�Z
dS)�cmd_listz�List all organizational units.

    Example:
    samba-tool ou listobjects

    The example shows how an administrator would list all organizational
    units.
    z%prog [options]rr
rrrrz-bz	--base-dnzSpecify base DN to use.)rrr_r`FrarbrcrNcCs�|��}|j|dd�}t|t�||d�}	t�|	|	���}
|r#|	�|�}
|	j|
tj	dgd�}t
|�dkr5dSt|td�d�D]}|sQt�|	|	���}
|j
�t
|
��|j�d	t|j
��q=dS)
NTrrz (objectClass=organizationalUnit))r(r'r)rrgrhrj)r+r,rrr-r.r/r0r2rlr4rmr	rgrTr5r6rI)r8rrrr�base_dnr`r"r9r:�	search_dnr>�msgr/r?r?r@rA:s*�
��zcmd_list.run)NNNNNF)rDrErFrGrHrrIrJrLrMrNrOrPrAr?r?r?r@rqs2	��
����rqc@s`eZdZdZdZedddeddd�ed	d
ddd
d�gZdgZe	j
e	je	jd�Z
		ddd�ZdS)�
cmd_deleteaSDelete an organizational unit.

    The name of the organizational unit can be specified as a full DN
    or without the domainDN component.

    Examples:
    samba-tool ou delete 'OU=OrgUnit,DC=samdom,DC=example,DC=com'
    samba-tool ou delete 'OU=OrgUnit'

    The examples show how an administrator would delete the ou 'OrgUnit'.
    rXrr
rrrrz--force-subtree-delete�force_subtree_deleteFraz7Delete organizational unit and all children reclusivelyrcrZrNc
Cs|��}|j|dd�}t|t�||d�}	t�|	|	���}
z|	�|�}Wnty7}zt	d||f��d}~wwg}
|r?dg}
z#|	j
|dtjgd�}t|�dkr[|j
�d	|�WdS|	�||
�Wntyu}zt	d
||��d}~ww|j
�d|�dS)NTrrr[z
tree_delete:1r$r%rr*zFailed to delete ou "%s"zDeleted ou "%s"
)r+r,rrr-r.r/r0r1rr2r3r4r5r6�delete)r8rZrrrrrvr"r9r:r/r]r<�controlsr>r?r?r@rAvs:������zcmd_delete.run)NNNNFrCr?r?r?r@ruXs&�����ruc@sZeZdZdZiZe�ed<e�ed<e�ed<e�ed<e�ed<e	�ed<e
�ed<d	S)
�cmd_ouz%Organizational Units (OU) management.�add�createrw�mover7�list�listobjectsN)rDrErFrG�subcommandsrWrurQrrqr^r?r?r?r@ry�s





ry)�samba.getopt�getoptrLr-�
samba.authr�samba.netcmdrrrr�samba.samdbr�sambar�operatorr	rrQrWr^rqruryr?r?r?r@�<module>s@D2F:=