ó
@´_Wc           @   s  d  d l  Z  d  d l j Z d  d l Z d  d l m Z d  d l m Z m Z d  d l	 m
 Z
 d  d l m Z m Z m Z m Z d  d l m Z d „  Z d „  Z d	 „  Z d
 e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d S(   iÿÿÿÿN(   t   LdbError(   t   drsuapit   misc(   t   system_session(   t   Commandt   CommandErrort   SuperCommandt   Option(   t   SamDBc         C   s“   y% |  j  | d t j d d g ƒ} Wn3 t k
 rZ \ } } | t j k rT d | S‚  n Xd | d k r | d d d } | Sd | } | Sd S(   sn   Gets the owner of an FSMO role

    :param roledn: The DN of the FSMO role
    :param role: The FSMO role
    t   scopet   attrst   fSMORoleOwners-   * The '%s' role is not present in this domaini    s/   * The '%s' role does not have an FSMO roleownerN(   t   searcht   ldbt
   SCOPE_BASER    t   ERR_NO_SUCH_OBJECT(   t   samdbt   rolednt   rolet   rest   numt   msgt   master_owner(    (    s5   /usr/lib/python2.7/dist-packages/samba/netcmd/fsmo.pyt   get_fsmo_roleowner"   s    
c      	   C   s  | d k r% | j  ƒ  } d | } n. | d k rS t j | j ƒ  ƒ } d | } n  | j | d d g d t j d d	 g ƒ} d | d
 k r,y^ t t j	 t j
 | | d
 d d
 ƒ j d ƒ ƒ ƒ }	 t t j
 | | d
 d d
 ƒ ƒ }
 WqAt k
 r(\ } } t d | d
 d d
 | f ƒ ‚ qAXn |  j d | ƒ t S| d k r‚d |	 | j ƒ  f } d | j ƒ  | j ƒ  f } nA | d k rÃd |	 | j ƒ  f } d | j ƒ  | j ƒ  f } n  | j ƒ  } | | k rø| j ƒ  } | j | d t ƒ} t d d | d t ƒ  d | d | ƒ } t j ƒ  } t j
 | | ƒ | _ t j |
 t j d ƒ | d <y | j | ƒ Wn/ t k
 r£\ } } t d | | f ƒ ‚ n Xt j ƒ  } t j
 | | ƒ | _ t j | t j d ƒ | d <y | j | ƒ Wn/ t k
 r#\ } } t d | | f ƒ ‚ n Xy" t j j | j  ƒ  | | ƒ } Wn( t j j! k
 rp} t d | ƒ ‚ n XyG | d
 } | d } t" j# } | d } t j j$ | | |	 | | ƒ Wn( t j j! k
 râ} t d | ƒ ‚ n X|  j d | ƒ t S|  j d | ƒ t Sd S(   s   Transfer dns FSMO role. t	   domaindnss$   CN=Infrastructure,DC=DomainDnsZones,t	   forestdnss$   CN=Infrastructure,DC=ForestDnsZones,R
   R   R	   t   controlss   extended_dn:1:1i    t   GUIDs+   No GUID found in naming master DN %s : %s 
s0   * The '%s' role does not have an FSMO roleowner
s   %s._msdcs.%st   fallback_machinet   urls	   ldap://%st   session_infot   credentialst   lps   Failed to delete role '%s': %ss   Failed to add role '%s': %ss   Drsuapi Connect failedi   i   s   Replication faileds&   FSMO transfer of '%s' role successful
s'   This DC already has the '%s' FSMO role
N(%   t	   domain_dnt   sambat   dn_from_dns_namet   forest_dns_nameR   R   R   t   strR   R   t   Dnt   get_extended_componentR    R   t   writet   Falset   domain_dns_namet   get_ntds_GUIDt   get_dsServiceNamet   get_loadparmt   get_credentialst   TrueR   R   t   Messaget   dnt   MessageElementt   FLAG_MOD_DELETEt   modifyt   FLAG_MOD_ADDt	   drs_utilst   drsuapi_connectt   host_dns_namet   drsExceptionR   t   DRSUAPI_DRS_WRIT_REPt   sendDsReplicaSync(   t   outft	   sambaoptst   credoptsR   R   R!   t   role_objectt	   forest_dnR   t   master_guidR   R   R   t   master_dns_namet   new_dns_namet	   new_ownerR    t   credst   mt
   connectiont   et   drsuapi_connectiont   drsuapi_handlet   req_optionst   NCt   estr(    (    s5   /usr/lib/python2.7/dist-packages/samba/netcmd/fsmo.pyt   transfer_dns_role8   sš    		(#			

	
c         C   s˜  | j  ƒ  } d | } d | j ƒ  } d | } t | j ƒ  ƒ } | j ƒ  } t j ƒ  }	 t j | d ƒ |	 _ | d k r¬ t	 | | | ƒ }
 t j
 d t j d ƒ |	 d <nK| d k r4t	 | | | ƒ }
 | j | d	 t j d
 d g ƒ} t | ƒ d k st ‚ | d d d } t j
 | t j d ƒ |	 d <nÃ | d k rqt	 | | | ƒ }
 t j
 d t j d ƒ |	 d <n† | d k r®t	 | | | ƒ }
 t j
 d t j d ƒ |	 d <nI | d k rët	 | | | ƒ }
 t j
 d t j d ƒ |	 d <n t d ƒ ‚ d |
 k r|
 | k rgy | j |	 ƒ Wn/ t k
 rQ\ } } t d | | f ƒ ‚ n X|  j d | ƒ t S|  j d | ƒ t Sn |  j d |
 ƒ t Sd S(   s   Transfer standard FSMO role. s   CN=RID Manager$,CN=System,s   CN=Partitions,%ss   CN=Infrastructure,t    t   ridt   1t   becomeRidMastert   pdcR	   R
   t	   objectSidi   i    t	   becomePdct   namingt   becomeDomainMastert   infrastructuret   becomeInfrastructureMastert   schemat   becomeSchemaMasters   Invalid FSMO role.t   *s    Transfer of '%s' role failed: %ss&   FSMO transfer of '%s' role successful
s'   This DC already has the '%s' FSMO role
s   %s
N(   R!   t   get_config_basednR%   t   get_schema_basednR,   R   R0   R&   R1   R   R2   t   FLAG_MOD_REPLACER   R   t   lent   AssertionErrorR   R4   R    R(   R/   R)   (   R<   R   R   R!   t   rid_dnt	   naming_dnt   infrastructure_dnt	   schema_dnRD   RF   R   R   t   sidR   R   (    (    s5   /usr/lib/python2.7/dist-packages/samba/netcmd/fsmo.pyt   transfer_role–   sf    

					t   cmd_fsmo_seizec           B   sÝ   e  Z d  Z d Z i e j d 6e j d 6e j d 6Z e	 d d d d d	 e
 d
 d d d ƒe	 d d d d d ƒe	 d d	 d d d d d d d d d d g d d ƒg Z g  Z d „  Z d „  Z d! d! d! d! d! d! d  „ Z RS("   s   Seize the role.s   %prog [options]R=   R>   t   versionoptss   -Hs   --URLt   helps%   LDB URL for database or target servert   typet   metavart   URLt   destt   Hs   --forces5   Force seizing of role without attempting to transfer.t   actiont
   store_trues   --rolet   choicet   choicesRP   RS   RX   RZ   RV   R   R   t   allsI  The FSMO role to seize or transfer.

rid=RidAllocationMasterRole

schema=SchemaMasterRole

pdc=PdcEmulationMasterRole

naming=DomainNamingMasterRole

infrastructure=InfrastructureMasterRole

domaindns=DomainDnsZonesMasterRole

forestdns=ForestDnsZonesMasterRole

all=all of the above

You must provide an Admin user and password.c         C   sŽ  | j  ƒ  } | j ƒ  } d | |  _ d | j ƒ  |  _ t | j ƒ  ƒ |  _ d | |  _ t	 j
 ƒ  } | d k r t	 j | |  j ƒ | _ n¥ | d k r± t	 j | | ƒ | _ n | d k rØ t	 j | |  j ƒ | _ nZ | d k rÿ t	 j | |  j ƒ | _ n3 | d k r&t	 j | |  j ƒ | _ n t d	 ƒ ‚ t } t | | j | ƒ } d
 | k rä| | k rÉ| d k rá|  j d ƒ y t |  j | | ƒ Wn t } |  j d ƒ qÆX|  j d ƒ t Sqáqê|  j j d | ƒ t Sn t } | d k	 s| t k rŠ|  j d | ƒ t	 j | t	 j d ƒ | d <y | j | ƒ Wn/ t k
 rq\ }	 }
 t d | |
 f ƒ ‚ n X|  j j d | ƒ t Sd S(   s   Seize standard fsmo role. s   CN=Infrastructure,s   CN=Partitions,%ss   CN=RID Manager$,CN=System,RP   RS   RV   RX   RZ   s   Invalid FSMO role.R\   s   Attempting transfer...s!   Transfer unsuccessful, seizing...s%   Transfer successful, not seizing roles'   This DC already has the '%s' FSMO role
s   Seizing %s FSMO role...R   s   Failed to seize '%s' role: %ss#   FSMO seize of '%s' role successful
N(   R,   R!   Rd   R]   Rc   R%   R^   Re   Rb   R   R0   R&   R1   R   R)   R   t   Nonet   messageRg   R<   R/   R(   R2   R_   R4   R    (   t   selfR   R   t   forcet   serviceNameR!   RF   t   seizeR   R   R   (    (    s5   /usr/lib/python2.7/dist-packages/samba/netcmd/fsmo.pyt
   seize_roleô   s^    
	c         C   s  | j  ƒ  } | j ƒ  } t j | j ƒ  ƒ }	 d | |  _ d |	 |  _ t j ƒ  }
 | d k rz t j	 | |  j ƒ |
 _
 n3 | d k r¡ t j	 | |  j ƒ |
 _
 n t d ƒ ‚ t } t | |
 j
 | ƒ } d | k re| | k rJ| d k rb|  j d ƒ y t |  j | | | | ƒ Wn t } |  j d ƒ qGX|  j d	 ƒ t Sqbqk|  j j d
 | ƒ t Sn t } | d k	 sƒ| t k r|  j d | ƒ t j | t j d ƒ |
 d <y | j |
 ƒ Wn/ t k
 rò\ } } t d | | f ƒ ‚ n X|  j j d | ƒ t Sd S(   s   Seize DNS FSMO role. s$   CN=Infrastructure,DC=DomainDnsZones,s$   CN=Infrastructure,DC=ForestDnsZones,R   R   s   Invalid FSMO role.R\   s   Attempting transfer...s!   Transfer unsuccessful, seizing...s&   Transfer successful, not seizing role
s'   This DC already has the '%s' FSMO role
s   Seizing %s FSMO role...R   s   Failed to seize '%s' role: %ss#   FSMO seize of '%s' role successful
N(   R,   R!   R"   R#   R$   t   domaindns_dnt   forestdns_dnR   R0   R&   R1   R   R)   R   Ru   Rv   RN   R<   R/   R(   R2   R_   R4   R    (   Rw   R   R   R>   R=   Ri   Rx   Ry   R!   R@   RF   Rz   R   R   R   (    (    s5   /usr/lib/python2.7/dist-packages/samba/netcmd/fsmo.pyt   seize_dns_role1  sR    
	c   
   	   C   s9  | j  ƒ  } | j | d t ƒ} t d | d t ƒ  d | d | ƒ }	 | d k rë |  j d |	 | ƒ |  j d |	 | ƒ |  j d	 |	 | ƒ |  j d
 |	 | ƒ |  j d |	 | ƒ |  j d |	 | | | | ƒ |  j d |	 | | | | ƒ nJ | d k s| d k r"|  j | |	 | | | | ƒ n |  j | |	 | ƒ d  S(   NR   R   R   R   R    Rt   RP   RS   RV   RX   RZ   R   R   (   R-   R.   R/   R   R   R{   R~   (
   Rw   Rx   Ro   R   R>   R=   Ri   R    RE   R   (    (    s5   /usr/lib/python2.7/dist-packages/samba/netcmd/fsmo.pyt   runj  s$    
N(   t   __name__t
   __module__t   __doc__t   synopsist   optionst   SambaOptionst   CredentialsOptionst   VersionOptionst   takes_optiongroupsR   R%   t   takes_optionst
   takes_argsR{   R~   Ru   R   (    (    (    s5   /usr/lib/python2.7/dist-packages/samba/netcmd/fsmo.pyRh   Ó   s&   

	
	=	9	t   cmd_fsmo_showc           B   s}   e  Z d  Z d Z i e j d 6e j d 6e j d 6Z e	 d d d d d	 e
 d
 d d d ƒg Z g  Z d d d d d „ Z RS(   s   Show the roles.s   %prog [options]R=   R>   Ri   s   -Hs   --URLRj   s%   LDB URL for database or target serverRk   Rl   Rm   Rn   Ro   c      	   C   s£  | j  ƒ  } | j | d t ƒ} t d | d t ƒ  d | d | ƒ } | j ƒ  } t j | j ƒ  ƒ }	 d | }
 d | j	 ƒ  } | j
 ƒ  } d | } d	 | } d
 |	 } t | |
 d ƒ } t | | d ƒ } t | | d ƒ } t | | d ƒ } t | | d ƒ } t | | d ƒ } t | | d ƒ } |  j d | ƒ |  j d | ƒ |  j d | ƒ |  j d | ƒ |  j d | ƒ |  j d | ƒ |  j d | ƒ d  S(   NR   R   R   R   R    s   CN=Infrastructure,s   CN=Partitions,%ss   CN=RID Manager$,CN=System,s$   CN=Infrastructure,DC=DomainDnsZones,s$   CN=Infrastructure,DC=ForestDnsZones,RX   RS   RV   RZ   RP   R   R   s   SchemaMasterRole owner: s    InfrastructureMasterRole owner: s   RidAllocationMasterRole owner: s   PdcEmulationMasterRole owner: s   DomainNamingMasterRole owner: s    DomainDnsZonesMasterRole owner: s    ForestDnsZonesMasterRole owner: (   R-   R.   R/   R   R   R!   R"   R#   R$   R]   R^   R   Rv   (   Rw   Ro   R>   R=   Ri   R    RE   R   R!   R@   Rd   Rc   Re   Rb   R|   R}   t   infrastructureMastert   pdcEmulatort   namingMastert   schemaMastert	   ridMastert   domaindnszonesMastert   forestdnszonesMaster(    (    s5   /usr/lib/python2.7/dist-packages/samba/netcmd/fsmo.pyR   —  s:    



						N(   R€   R   R‚   Rƒ   R„   R…   R†   R‡   Rˆ   R   R%   R‰   RŠ   Ru   R   (    (    (    s5   /usr/lib/python2.7/dist-packages/samba/netcmd/fsmo.pyR‹   …  s   

t   cmd_fsmo_transferc           B   s¶   e  Z d  Z d Z i e j d 6e j d 6e j d 6Z e	 d d d d d	 e
 d
 d d d ƒe	 d d	 d d d d d d d d d d g d d ƒg Z g  Z d d d d d d d „ Z RS(   s   Transfer the role.s   %prog [options]R=   R>   Ri   s   -Hs   --URLRj   s%   LDB URL for database or target serverRk   Rl   Rm   Rn   Ro   s   --roleRr   Rs   RP   RS   RX   RZ   RV   R   R   Rt   sI  The FSMO role to seize or transfer.

rid=RidAllocationMasterRole

schema=SchemaMasterRole

pdc=PdcEmulationMasterRole

naming=DomainNamingMasterRole

infrastructure=InfrastructureMasterRole

domaindns=DomainDnsZonesMasterRole

forestdns=ForestDnsZonesMasterRole

all=all of the above

You must provide an Admin user and password.c   
   	   C   s0  | j  ƒ  } | j | d t ƒ} t d | d t ƒ  d | d | ƒ }	 | d k rå t |  j d |	 ƒ t |  j d |	 ƒ t |  j d	 |	 ƒ t |  j d
 |	 ƒ t |  j d |	 ƒ t |  j | | d |	 ƒ t |  j | | d |	 ƒ nG | d k sý | d k rt |  j | | | |	 ƒ n t |  j | |	 ƒ d  S(   NR   R   R   R   R    Rt   RP   RS   RV   RX   RZ   R   R   (   R-   R.   R/   R   R   Rg   R<   RN   (
   Rw   Rx   Ro   R   R>   R=   Ri   R    RE   R   (    (    s5   /usr/lib/python2.7/dist-packages/samba/netcmd/fsmo.pyR   Ø  s"    

N(   R€   R   R‚   Rƒ   R„   R…   R†   R‡   Rˆ   R   R%   R‰   RŠ   Ru   R   (    (    (    s5   /usr/lib/python2.7/dist-packages/samba/netcmd/fsmo.pyR“   º  s   


	t   cmd_fsmoc           B   s;   e  Z d  Z i  Z e ƒ  e d <e ƒ  e d <e ƒ  e d <RS(   s:   Flexible Single Master Operations (FSMO) roles management.Rz   t   showt   transfer(   R€   R   R‚   t   subcommandsRh   R‹   R“   (    (    (    s5   /usr/lib/python2.7/dist-packages/samba/netcmd/fsmo.pyR”   ò  s
   (   R"   t   samba.getoptt   getoptR„   R   R    t   samba.dcerpcR   R   t
   samba.authR   t   samba.netcmdR   R   R   R   t   samba.samdbR   R   RN   Rg   Rh   R‹   R“   R”   (    (    (    s5   /usr/lib/python2.7/dist-packages/samba/netcmd/fsmo.pyt   <module>   s   "		^	=²58