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: //usr/lib/python3/dist-packages/samba/__pycache__/subnets.cpython-310.pyc
o

�/a0!�@s�ddlZddlmZmZmZddlmZGdd�de�ZGdd�de�ZGd	d
�d
e�Z	Gdd�de�Z
Gd
d�de�Zdd�Zdd�Z
dd�Zdd�ZdS)�N)�FLAG_MOD_ADD�FLAG_MOD_REPLACE�LdbError�)�SiteNotFoundExceptionc@�eZdZdZdS)�SubnetExceptionzBase element for Subnet errorsN��__name__�
__module__�__qualname__�__doc__�rr�//usr/lib/python3/dist-packages/samba/subnets.pyr�rc@r)�SubnetNotFoundz$The subnet requested does not exist.Nr	rrrrr!rrc@r)�SubnetAlreadyExistsz&The subnet being added already exists.Nr	rrrrr&rrc@r)�
SubnetInvalidzThe subnet CIDR is invalid.Nr	rrrrr+rrc@r)�SiteNotFoundz2The site to be used for the subnet does not exist.Nr	rrrrr0rrc
Cs8|j|tjdt�|�d�}t|�dkrtd|��|dj}t|t�s*t	d|��t�
|d�}|�|�dkr;td	��|�
d
�dkrFtd��|�dd|�z#t��}||_t�d
td�|d<t�t|�td�|d<|�|�WdStjy�}z|j\}	}
|	tjkr�t	d||
f��|	tjkr�td|���d}~ww)ajCreate a subnet and associate it with a site.

    :param samdb: A samdb connection
    :param configDn: The DN of the configuration partition
    :param subnet_name: name of the subnet to create (a CIDR range)
    :return: None
    :raise SubnetAlreadyExists: if the subnet to be created already exists.
    :raise SiteNotFound: if the site does not exist.
    z(&(objectclass=Site)(cn=%s))��base�scope�
expressionrz&A site with the name %s does not existrz'%s is not a valid subnet (not a string)�CN=Subnets,CN=SitesF�dnsubnet.add_base() failed�CN=X�dnsubnet.add_child() failed�CN�subnet�objectclass�
siteObject�%s is not a valid subnet: %s�(A subnet with the CIDR %s already existsN)�search�ldb�
SCOPE_SUBTREE�
binary_encode�lenr�dn�
isinstance�strr�Dn�add_baser�	add_child�
set_component�Message�MessageElementr�addr�args�ERR_INVALID_DN_SYNTAX�ERR_ENTRY_ALREADY_EXISTSr)�samdb�configDn�subnet_name�	site_name�ret�dn_site�dnsubnet�m�e�enum�estrrrr�
create_subnet5sN

���

��


���r@c
Cs�t�|d�}|�|�dkrtd��|�d�dkrtd��|�dd|�z|j|tjdd	�}t|�d
kr9t	d|��Wn"t
y\}z|j\}}|tjkrRt	d|��WYd}~nd}~ww|�
|�dS)
aDelete a subnet.

    :param samdb: A samdb connection
    :param configDn: The DN of the configuration partition
    :param subnet_name: Name of the subnet to delete
    :return: None
    :raise SubnetNotFound: if the subnet to be deleted does not exist.
    rFrrrrr�objectClass=subnetrr�Subnet %s does not existN)r$r+r,rr-r.r#�
SCOPE_BASEr'rrr2�ERR_NO_SUCH_OBJECT�delete)r5r6r7r;r9�e1r>r?rrr�
delete_subnetis*	
��

���rGc	
Cs�t�|d�}|�|�dkrtd��|�d�dkrtd��|�dd|�t�|t|��}|�dd|�z	|�||�WdStyp}z)|j	\}}|tj
krStd|��|tjkr^t
d	|��|tjkrktd
||f���d}~ww)avRename a subnet.

    :param samdb: A samdb connection
    :param configDn: The DN of the configuration partition
    :param subnet_name: Name of the subnet to rename
    :param new_name: New name for the subnet
    :return: None
    :raise SubnetNotFound: if the subnet to be renamed does not exist.
    :raise SubnetExists: if the subnet to be created already exists.
    rFrrrrrrBr"r!N)r$r+r,rr-r.r*�renamerr2rDrr4rr3r)	r5r6r7�new_namer;�newdnsubnet�e2r>r?rrr�
rename_subnet�s2


�
���rLc
Cs�t�|d�}|�|�dkrtd��|�d�dkrtd��|�dd|�z|j|tjdd	�}t|�d
kr9t	d|��Wn"t
y\}z|j\}}|tjkrRt	d|��WYd}~nd}~wwt�|d
�}	|	�|�dkrntd��|	�d�dkrytd��|	�dd|�t�|d�}
|
�|	�z|j|	tjdd	�}t|�d
kr�t
d|��Wn"t
y�}z|j\}}|tjkr�t
d|��WYd}~nd}~wwt|dj�}t��}
||
_t�|td�|
d<|�|
�dS)a�Assign a subnet to a site.

    This dissociates the subnet from its previous site.

    :param samdb: A samdb connection
    :param configDn: The DN of the configuration partition
    :param subnet_name: Name of the subnet
    :param site_name: Name of the site
    :return: None
    :raise SubnetNotFound: if the subnet does not exist.
    :raise SiteNotFound: if the site does not exist.
    rFrrrrrrArrrBNzCN=Siteszdnsites.add_base() failedzdnsites.add_child() failedz
CN=ServerszobjectClass=sitezSite %s does not existr )r$r+r,rr-r.r#rCr'rrr2rDrr*r(r/r0r�modify)r5r6r7r8r;r9�e3r>r?�dnsite�	dnservers�e4�siteDnr<rrr�set_subnet_site�sb
��

���

��

����rS)r$rrr�sitesr�	Exceptionrrrrrr@rGrLrSrrrr�<module>s4$