
    g("                         S SK r S SK JrJrJr  SSKJr   " S S\5      r " S S\5      r " S	 S
\5      r	 " S S\5      r
 " S S\5      rS rS rS rS rg)    N)FLAG_MOD_ADDFLAG_MOD_REPLACELdbError   )SiteNotFoundExceptionc                       \ rS rSrSrSrg)SubnetException   zBase element for Subnet errors N__name__
__module____qualname____firstlineno____doc____static_attributes__r       //usr/lib/python3/dist-packages/samba/subnets.pyr	   r	      s    (r   r	   c                       \ rS rSrSrSrg)SubnetNotFound!   z$The subnet requested does not exist.r   Nr   r   r   r   r   r   !   s    .r   r   c                       \ rS rSrSrSrg)SubnetAlreadyExists&   z&The subnet being added already exists.r   Nr   r   r   r   r   r   &   s    0r   r   c                       \ rS rSrSrSrg)SubnetInvalid+   zThe subnet CIDR is invalid.r   Nr   r   r   r   r   r   +   s    %r   r   c                       \ rS rSrSrSrg)SiteNotFound0   z2The site to be used for the subnet does not exist.r   Nr   r   r   r   r   r   0   s    <r   r   c                    U R                  U[        R                  S[        R                  " U5      -  S9n[	        U5      S:w  a  [        SU-  5      eUS   R                  n[        U[        5      (       d  [        SU-  5      e[        R                  " U S5      n UR                  U5         UR                  S	5        UR                  SSU5         [        R                   " 5       nXgl        [        R"                  " S[$        S5      US'   [        R"                  " [        U5      [$        S5      US'   U R'                  U5        g! [        R                   a    [        S5      ef = f! [        R                   a    [        S
5      ef = f! [        R                   a\  nUR(                  u  pU	[        R*                  :X  a  [        U< SU
< 35      eU	[        R,                  :X  a  [/        SU-  5      ee SnAff = f)aN  Create 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
expressionr   z&A site with the name %s does not existr   z'%s is not a valid subnet (not a string)CN=Subnets,CN=Sitesdnsubnet.add_base() failedCN=Xdnsubnet.add_child() failedCNsubnetobjectclass
siteObject is not a valid subnet: (A subnet with the CIDR %s already existsN)searchldbSCOPE_SUBTREEbinary_encodelenr   dn
isinstancestrr   Dnadd_baser   r	   	add_childset_componentMessageMessageElementr   addargsERR_INVALID_DN_SYNTAXERR_ENTRY_ALREADY_EXISTSr   )samdbconfigDnsubnet_name	site_nameretdn_sitednsubnetmeenumestrs              r   create_subnetrM   5   s    ,,HC,=,="@((3#4  5C 3x1}C$% & 	&!fiiGk3''ESTTvve23H<(#=6" 1dK0KKM--h.;=-,,S\<-9;,		! << <:;;< << =;<<= << vv3,,,+t TUUS111 &&P(3'4 5 5 s2   E	 0E, A3F 	 E), FG?#AG::G?c                 X   [         R                  " U S5      n UR                  U5         UR                  S5        UR                  SSU5         U R                  U[         R                  SS9n[        U5      S	:w  a  [        S
U-  5      e U R                  U5        g! [         R                   a    [	        S5      ef = f! [         R                   a    [	        S5      ef = f! [         a:  nUR                  u  pgU[         R                  :X  a  [        S
U-  5      e SnANSnAff = f)zDelete 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.
r&   r'   r(   r)   r   r*   objectClass=subnetr"   r   Subnet %s does not existN)r1   r8   r9   r   r	   r:   r;   r0   
SCOPE_BASEr4   r   r?   ERR_NO_SUCH_OBJECTdelete)rB   rC   rD   rH   rF   e1rK   rL   s           r   delete_subnetrU   m   s%    vve23H<(#=6" 1dK0Kll&:  <s8q= !;k!IJJ  
LL% << <:;;< << =;<<=  Kww3))) !;k!IJJ *Ks.   B C <C%  B? C"%
D)/0D$$D)c                    [         R                  " U S5      n UR                  U5         UR                  S5        UR                  SSU5        [         R                  " U [        U5      5      nUR                  SSU5         U R                  XE5        g
! [         R                   a    [	        S5      ef = f! [         R                   a    [	        S5      ef = f! [         a~  nUR                  u  pxU[         R                  :X  a  [        SU-  5      eU[         R                  :X  a  [        SU-  5      eU[         R                  :X  a  [        U< S	U< 35      ee S
nAff = f)aV  Rename 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.
r&   r'   r(   r)   r   r*   rP   r/   r.   N)r1   r8   r9   r   r	   r:   r;   r7   renamer?   rR   r   rA   r   r@   r   )	rB   rC   rD   new_namerH   newdnsubnete2rK   rL   s	            r   rename_subnetr[      sU    vve23H<(#=6" 1dK0&&H.Kax0X+ << <:;;< << =;<<=  ww3))) !;h!FGGS111%&P(0'1 2 2S...(BF!H I I s/   B B8 C  B58 C
E#%A9EE#c                    [         R                  " U S5      n UR                  U5         UR                  S5        UR                  SSU5         U R                  U[         R                  SS9n[        U5      S	:w  a  [        S
U-  5      e [         R                  " U S5      n	 U	R                  U5         U	R                  S5        U	R                  SSU5        [         R                  " U S5      n
U
R                  U	5         U R                  U	[         R                  SS9n[        U5      S	:w  a  [        SU-  5      e [        WS   R                  5      n[         R                   " 5       nXMl        [         R"                  " U[$        S5      US'   U R'                  U5        g! [         R                   a    [	        S5      ef = f! [         R                   a    [	        S5      ef = f! [         a;  nUR                  u  pxU[         R                  :X  a  [        S
U-  5      e SnAGNSnAff = f! [         R                   a    [	        S5      ef = f! [         R                   a    [	        S5      ef = f! [         a;  nUR                  u  pxU[         R                  :X  a  [        SU-  5      e SnAGNxSnAff = f)ag  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.
r&   r'   r(   r)   r   r*   rO   r"   r   rP   NzCN=Siteszdnsite.add_base() failedzdnsite.add_child() failedz
CN=ServerszobjectClass=sitezSite %s does not existr-   )r1   r8   r9   r   r	   r:   r;   r0   rQ   r4   r   r?   rR   r   r7   r5   r<   r=   r   modify)rB   rC   rD   rE   rH   rF   e3rK   rL   dnsite	dnserverse4siteDnrI   s                 r   set_subnet_siterc      s    vve23H<(#=6" 1dK0Kll&:  <s8q= !;k!IJJ  VVE:&F:!;  D),ul+IvNllcnn&8  :s8q='(@9(LMM  Q^FAD((1A)57AlO	LLOa << <:;;< << =;<<=  Kww3))) !;k!IJJ *K << :899: << ;9::;  Nww3)))'(@9(LMM *Ns^   F% G <G+ %H3 7I <I9 % G G(+
H050H++H03 I I69
J>0J99J>)r1   r   r   r   sitesr   	Exceptionr	   r   r   r   r   rM   rU   r[   rc   r   r   r   <module>rf      sg   .  8 8 )	i 	
	_ 	
	/ 	
	O 	
	? 	
5pB%PAr   