
    g                         S r SSKrSSKJrJr   " S S\5      r " S S\5      r " S S	\5      r " S
 S\5      rS r	S r
g)zManipulating sites.    N)FLAG_MOD_ADDLdbErrorc                   $    \ rS rSrSrS rS rSrg)SiteException   zBase element for Sites errorsc                     Xl         g )Nvalue)selfr
   s     -/usr/lib/python3/dist-packages/samba/sites.py__init__SiteException.__init__   s    
    c                 P    U R                   R                  < SU R                  < 3$ )Nz: )	__class____name__r
   )r   s    r   __str__SiteException.__str__   s    >>22DJJ??r   r	   N)r   
__module____qualname____firstlineno____doc__r   r   __static_attributes__ r   r   r   r      s    '@r   r   c                       \ rS rSrSrSrg)SiteNotFoundException"   z>Raised when the site is not found and it's expected to exists.r   Nr   r   r   r   r   r   r   r   r   r   r   "   s    Hr   r   c                       \ rS rSrSrSrg)SiteAlreadyExistsException&   zBRaised when the site is not found and it's expected not to exists.r   Nr   r   r   r   r    r    &   s    Lr   r    c                       \ rS rSrSrSrg)SiteServerNotEmptyException*   z0Raised when the site still has servers attached.r   Nr   r   r   r   r#   r#   *   s    :r   r#   c           	      B   U R                  U[        R                  SU-  S9n[        U5      S:w  a  [	        SU-  5      e[        R
                  " 5       n[        R                  " U SU< S[        U5      < 35      Ul        [        R                  " S[        S5      US'   U R                  U5        [        R
                  " 5       n[        R                  " U S	[        UR                  5      -  5      Ul        [        R                  " S
[        S5      US'   U R                  U5        [        R
                  " 5       n[        R                  " U S[        UR                  5      -  5      Ul        [        R                  " S[        S5      US'   U R                  U5        g)z
Create a site

:param samdb: A samdb connection
:param configDn: The DN of the configuration partition
:param siteName: Name of the site to create
:return: True upon success
:raise SiteAlreadyExists: if the site to be created already exists.
z(&(objectclass=Site)(cn=%s))basescope
expressionr   z&A site with the name %s already existszCn=z
,CN=Sites,siteobjectclasszCn=NTDS Site Settings,%snTDSSiteSettingszCn=Servers,%sserversContainerT)searchldbSCOPE_SUBTREElenr    MessageDnstrdnMessageElementr   add)samdbconfigDnsiteNameretmm2m3s          r   create_siter?   .   s3    ,,HC,=,="@8"K  MC
3x1}()QT\)\]]A66%#h-HIAD))&,NAm	IIaL	BFF54s144y@ABE**+=|][B}	IIbM	BFF5/CI56BE**+=|][B}	IIbMr   c                 $   [         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 U R                  U[         R                  SS	9n[        U5      S:w  a  [        SU-  5      eU R                  US/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NSnAff = f)a6  
Delete a site

:param samdb: A samdb connection
:param configDn: The DN of the configuration partition
:param siteName: Name of the site to delete
:return: True upon success
:raise SiteNotFoundException: if the site to be deleted do not exists.
:raise SiteServerNotEmpty: if the site has still servers in it.
zCN=Siteszdnsite.add_base() failedzCN=Xzdnsite.add_child() failedr   CNz
CN=ServerszobjectClass=siter&      zSite %s does not existNz(objectclass=server)z9Site %s still has servers in it, move them before removalztree_delete:0T)r/   r3   add_baser   r   	add_childset_componentr.   
SCOPE_BASEr1   r   argsERR_NO_SUCH_OBJECTSCOPE_ONELEVELr#   delete)	r8   r9   r:   dnsite	dnserversr;   eenumestrs	            r   delete_siterP   S   s    VVE:&F8!9  D(+ul+IvMllcnn&8  :s8q='(@8(KLL  ,,IS-?-?"8  :C
3x1})*ehp*pqq	LL/*+9 << 86778 << 97889  Mvv3)))'(@8(KLL *Ms.   D D( 8<E  D%( E
F0F

F)r   r/   r   r   	Exceptionr   r   r    r#   r?   rP   r   r   r   <module>rR      sQ   $  
 &@I @IM IM M;- ;"J+r   