
    Id                         d Z ddlZddlmZmZ  G d de      Z G d de      Z G d d	e      Z G d
 de      Zd Z	d Z
y)zManipulating sites.    N)FLAG_MOD_ADDLdbErrorc                       e Zd ZdZd Zd Zy)SiteExceptionzBase element for Sites errorsc                     || _         y )N)value)selfr   s     -/usr/lib/python3/dist-packages/samba/sites.py__init__zSiteException.__init__   s	    
    c                 L    | j                   j                  d| j                  S )Nz: )	__class____name__r   )r	   s    r
   __str__zSiteException.__str__   s    >>22DJJ??r   N)r   
__module____qualname____doc__r   r    r   r
   r   r      s    '@r   r   c                       e Zd ZdZy)SiteNotFoundExceptionz>Raised when the site is not found and it's expected to exists.Nr   r   r   r   r   r   r
   r   r   "   s    Hr   r   c                       e Zd ZdZy)SiteAlreadyExistsExceptionzBRaised when the site is not found and it's expected not to exists.Nr   r   r   r
   r   r   &   s    Lr   r   c                       e Zd ZdZy)SiteServerNotEmptyExceptionz0Raised when the site still has servers attached.Nr   r   r   r
   r   r   *   s    :r   r   c           	      0   | j                  |t        j                  d|z        }t        |      dk7  rt	        d|z        t        j
                         }t        j                  | d|dt        |            |_        t        j                  dt        d      |d<   | j                  |       t        j
                         }t        j                  | d	t        |j                        z        |_        t        j                  d
t        d      |d<   | j                  |       t        j
                         }t        j                  | dt        |j                        z        |_        t        j                  dt        d      |d<   | j                  |       y)a  
    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_siter6   .   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                 "   t        j                  | d      }	 |j                  |       	 |j                  d       |j                  dd|       t        j                  | d      }|j                  |       	 | j                  |t         j                  d	      }t        |      d
k7  rt        d|z        	 | j                  |t         j                  d	      }t        |      dk7  rt        d|z        | j                  |dg       y# t         j                  $ r t	        d      w xY w# t         j                  $ r t	        d      w xY w# t        $ r:}|j                  \  }}|t         j                  k(  rt        d|z        Y d}~d}~ww xY w)aV  
    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&   r*   add_baser   r   	add_childset_componentr%   
SCOPE_BASEr(   r   argsERR_NO_SUCH_OBJECTSCOPE_ONELEVELr   delete)	r/   r0   r1   dnsite	dnserversr2   eenumestrs	            r
   delete_siterG   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t3)))'(@8(KLL *Ms.   D D) 6>E D&)E	F0F		F)r   r&   r   r   	Exceptionr   r   r   r   r6   rG   r   r   r
   <module>rI      sQ   $  
 &@I @IM IM M;- ;"J+r   