+
    4SsiI                         ^ RI t ^ RIt^ RIHt ^ RIHt ^ RIHt ^ RIHtH	t	 ^ RI
HtHtHtHtHtHt  ! R R]4      tR	 tRR
 ltR tRR ltRR ltR tR tR# )    N)LdbError)werror)
ndr_unpack)miscdnsp)DNS_TYPE_NS
DNS_TYPE_ADNS_TYPE_AAAADNS_TYPE_CNAMEDNS_TYPE_SRVDNS_TYPE_PTRc                   0   a  ] tR t^t o RtR tR tRtV tR# )DemoteExceptionzBase element for demote errorsc                    Wn         R # Nvalue)selfr   s   &&1/usr/lib/python3/dist-packages/samba/remove_dc.py__init__DemoteException.__init__    s    
    c                (    R V P                   ,           # )zDemoteException: r   )r   s   &r   __str__DemoteException.__str__#   s    "TZZ//r   r   N)	__name__
__module____qualname____firstlineno____doc__r   r   __static_attributes____classdictcell__)__classdict__s   @r   r   r      s     (0 0r   r   c           	      (   V P                  4       pR RV,          3 F  p\        P                  ! W4      p VP                  V P	                  4       4        TP                  R4       TP                  ^ RT4        TP                  RT,          4       T P                  T4       K  	  R F  p\        P                  ! W4      p VP                  V P                  4       4        TP                  R4       TP                  ^ RT4        TP                  RT,          4       T P                  T4       K  	  R#   \        P
                   d#    \        RT: RT P	                  4       : 24      hi ; i  \        P
                   d    \        RT,          4      hi ; i  \        P
                   d1   pTP                  w  rxT\        P                  8X  d    Rp?EK  h Rp?ii ; i  \        P
                   d#    \        RT: RT P                  4       : 24      hi ; i  \        P
                   d    \        RT: R	T: R
24      hi ; i  \        P
                   d1   p	T	P                  w  rxT\        P                  8X  d    Rp	?	EK  h Rp	?	ii ; i)z3CN=Enterprise,CN=Microsoft System Volumes,CN=Systemz+CN=%s,CN=Microsoft System Volumes,CN=SystemzFailed constructing DN z by adding base zCN=Xz.Failed constructing DN %s by adding child CN=XCNzRemoving Sysvol reference: %sNz% by adding child CN=X (soon to be CN=))zMCN=Domain System Volumes (SYSVOL share),CN=File Replication Service,CN=SystemzDCN=Topology,CN=Domain System Volume,CN=DFSR-GlobalSettings,CN=System)domain_dns_nameldbDnadd_baseget_config_basednr   r   	add_childset_componentinfodeleteargsERR_NO_SUCH_OBJECTget_default_basedn)
samdbloggerdc_namerealmsdneenumestre1s
   &&&       r   remove_sysvol_referencesr=   '   sS   !!#EC;eCEVVE	EKK//12	*LL  	D'*	KK7"<=LL'E8V VVE	FKK0023	MLL  	D'*	KK7"<=LL'V) || 	E!%')@)@)B#D E E	E
 || 	*!"R%'#) * *	* || 	66LTs---	 || 	F!%')A)A)C#E F F	F
 || 	M!?A7#L M M	M || 	77LTs---	sk   D8E2;)FG%$H	)I87E/2(FG"2#GGG"%7H*I	J!#JJJc           
        a aa S P                  R \        P                  R. R.R7      p\        V4      ^ 8X  d   R# VP	                  4       p S P                  V4      w  poS P                  T. 4       S P                  R \        P                  R.R7      p
\        T
4      ^8X  g   Q hT
^ ,          R,          pT 3R	 lo\        T3R
 lT 4       4      pT3R lpT F  p TP!                  RT,          4       S P                  T4      w  pp\        T4      pT Uu. uF  pT! T4      '       d   K  TNK  	  pp\        T4      T8w  g   Kn  TP#                  RT\        T4      T\        T4      ,
          3,          4       S P                  TT4       K  	  \        S YT4       R#   \         dm   pTP                  w  rT\        P                  8X  g   T\        P                  8X  d   T'       d   \        S TTT4        Rp?R# \        RT: RT	: 24      hRp?ii ; i  \         dC   pTP                  w  rT\        P                  8X  d    Rp? R# \        RT: RT	: 24      hRp?ii ; iu upi ) z.(&(objectClass=dnsZone)(!(dc=RootDNSServers)))search_options:0:2)basescope
expressionattrscontrolsNz
lookup of z	 failed: namingContextsrB   rD   c                 |   < \         P                  ! SV 4      P                  4       P                  R ^4      ^ ,          # )/)r(   r)   canonical_strsplit)r8   r3   s   &r   dns_name_from_dn/remove_dns_references.<locals>.dns_name_from_dn   s1     vveR ..066sA>qAAr   c              3   F   <"   T F  pS! \        V4      4      x  K  	  R # 5ir   )str).0r8   rL   s   & r   	<genexpr>(remove_dns_references.<locals>.<genexpr>   s     6#Bs2w''#s   !c                    < V P                   \        8X  g   V P                   \        8X  dE   S F>  pVP                   V P                   8X  g   K   VP                  V P                  8X  g   K=   R # 	  R# TF)wTyper	   r
   data)	dnsRecordrecprimary_recss   & r   a_rec_to_remove.remove_dns_references.<locals>.a_rec_to_remove   sK    ??j(IOO},L#99	/CHH	4N $ r   z(checking for DNS records to remove on %s1updating %s keeping %d values, removing %s values)searchr(   SCOPE_SUBTREElenupper
dns_lookupRuntimeErrorr0   r   "WERR_DNS_ERROR_NAME_DOES_NOT_EXISTWERR_DNS_ERROR_RCODE_NAME_ERRORremove_hanging_dns_referencesr   dns_replace
SCOPE_BASEsetdebugr.   )r3   r4   dnsHostNameignore_no_namezonesdnsHostNameUpperr8   e4r:   r;   resncsa_names_to_remove_fromrZ   a_namea_rec_dna_recse2orig_num_recsrrL   rY   s   f&&&                @@r   remove_dns_referencesrx   b   s>    LLb(9(9$T!#7"8  :E 5zQ"((*O"--k:\ 
k2&
,,r ^^4D3E  GCs8q==
a&!
"CB 6#6
6  )	NLLCfLM!&!1!1&!9Xv F#>V?1+=!!V>v;-'KKKVmc&k.IJK Lff-! )$ "%5I  	OwwF===F:::-eV.>.35 ;MNN	Ob  	N77LTv@@@!vt"LMM		N ?sN   F! ,HI+.I+!H,?H,H HHI(&#I#I##I(c                   a V3R  lpV EF  pVP                  RVP                  ,          4       V P                  VP                  \        P                  RR.R7      pV F  p VR,          pT U	u. uF,  q! T	4      '       d   K  \        \        P                  T	4      NK.  	  p
p	\        T
4      \        T4      8w  g   K`  TP                  RTP                  \        T
4      \        T4      \        T
4      ,
          3,          4       T P                  TP                  T
4       K  	  EK   	  R#   \
         d     K  i ; iu up	i )c                   < \        \        P                  V 4      pVP                  \        8X  g+   VP                  \
        8X  g   VP                  \        8X  d%   VP                  P                  4       S8X  d   R #  R# VP                  \        8X  d,   VP                  P                  P                  4       S8X  d   R # R# rT   )r   r   DnssrvRpcRecordrU   r   r   r   rV   r`   r   
nameTarget)r   rW   rm   s   & r   	to_remove0remove_hanging_dns_references.<locals>.to_remove   s    t33U;	??k)oo/oo-~~##%)99 :
  __,~~((..04DDr   zchecking %sz/(&(objectClass=dnsNode)(!(dNSTombstoned=TRUE)))rW   )rA   rB   rC   rD   r\   N)ri   r8   r]   r(   r^   KeyErrorr   r   r{   r_   r.   dns_replace_by_dn)r3   r4   rm   rl   r}   zonerecordsrecordorig_valuesvvaluess   &&f&       r   re   re      s"   

 ]TWW,-,,DGG33D3D+:&1]  4 F$[1  +@*!)A, :j!5!5q9*  @ 6{c+..O%yy#f+";/#f+=?? @ ''		6:#    @s   $	D.1E E .D=<D=c                 b   V P                  R \        P                  R.R7      p\        V4      ^8X  g   Q hV^ ,          R,          ^ ,          p	V P                  V. RO\        P                  RR7      p
V
^ ,          p\	        VR,          ^ ,          4      p \        P
                  ! WR,          ^ ,          P                  R4      4      p \	        VR,          ^ ,          4      pV'       d   V P                  VR
.4       VEe'   V P                  VR. RO\        P                  R7      pRV^ ,          9   dJ   \	        V^ ,          R,          ^ ,          4      pVP                  RV,          4       V P                  V4       RV^ ,          9   dJ   \	        V^ ,          R,          ^ ,          4      pVP                  RV,          4       V P                  V4       V'       d,   VP                  RV,          4       V P                  VR
.4       RV9   d   \	        VR,          ^ ,          4      pV'       d   V P                  R\        P                  ! V4      : RV: R2. \        P                  V P                  4       R7      p\        V4      ^8X  dL   VP                  RV^ ,          P                  ,          4       V P                  V^ ,          P                  4       Ve   V'       d   \        WV4       V'       d   \        WV4       R	# R	#   \         d    R	p ELQi ; i  \         d    R	p ELKi ; i)r?   dsServiceNamerG   serverReferencecnrj   z(objectClass=server)rA   rD   rB   rC   utf8Ntree_delete:0zobjectclass=computermsDS-KrbTgtLinkrIDSetReferencesrA   rC   rD   rB   zRemoving RID Set: %szRemoving RODC KDC account: %sz5Removing computer account: %s (and any child objects)z(&(objectclass=user)(cn=dns-z)(servicePrincipalName=DNS/z)))rC   rD   rB   rA   z/Removing Samba-specific DNS service account: %s)r   r   rj   )r   r   r   )r]   r(   rg   r_   rO   r)   decoder   r/   r.   binary_encoder^   r2   r8   rx   r=   )r3   r4   	server_dnremove_computer_objremove_server_objremove_sysvol_objremove_dns_namesremove_dns_accountro   my_serviceNamemsgsmsgr5   computer_dnrj   computer_msgs
rid_set_dnkrbtgt_link_dns   &&&&&&&&          r   offline_remove_serverr      s    ,,r ^^O3D  FCs8q==VO,Q/N <<Y.!nn#9	  ;D
 q'C#d)A,GffU(9$:1$=$D$DV$LM#m,Q/0  	Y 12+0F,2 ,/>> % ; q!11]1-.@A!DEJKK.;<LL$a 00 q!12C!DQ!GHNKK7.HILL(KKOR]]^LL&78Cc-034Kll--g6'E!#3+<+< % 8 8 :  < s8q=KKICPQFIIUVLLQ##3e[9 8 c  
  s$   3L	 	L 	LLL.-L.c
                    V P                  R \        P                  R.R7      p
\        V
4      ^8X  g   Q h\        P                  ! W
^ ,          R,          ^ ,          P                  R4      4      pVP                  4       pW8X  d   \        RV,          4      h V P                  VRR.\        P                  R7      p\        T4      ^ 8X  d!   \        T: R
T P                  4       : 24      hT^ ,          pTP                  P                  4       R8w  g    TP                  P                  4       R8w  d   \        RT,          4      h\        \         P"                  TR,          ^ ,          4      pT'       do   T P                  T P%                  4       RT,          R7      pT F@  pTP'                  RTP                  ,          4       T P)                  TP                  4       KB  	  T'       d   T P                  R \        P*                  RT,          R.R7      pT F  p\-        T4      p\        P.                  ! 4       pTP                  Tn        \        P0                  ! T\        P2                  R4      TR&   TP5                  RTP                  : RT: R24       T P7                  T4       K  	   TP'                  RT,          4       T P)                  TR.4       \9        YTTTTTT	R7       R	#   \         d=   pTP                  w  ppT\        P                  8X  d   \        RT,          4      hh R	p?ii ; i  \         d'   pTP                  w  pp\        RT,          4      hR	p?ii ; i)r?   r   rG   r   z#Refusing to demote our own DSA: %s zobjectClass=ntdsDSA
objectGUIDr   zGiven DN %s doesn't existNz is not an ntdsda in r%   zNTDS Settingsz)Given DN (%s) wasn't the NTDS Settings DNz5(&(objectclass=nTDSConnection)(fromServer=<GUID=%s>)))rA   rC   zRemoving nTDSConnection: %sz(fsmoRoleOwner=<GUID=%s>))r@   )rA   rB   rC   rE   fsmoRoleOwnerr   zSeizing FSMO role on: z (now owned by r&   z'Removing nTDSDSA: %s (and any children)r   z,Failed to remove the DCs NTDS DSA object: %sr   r   r   r   r   )r]   r(   rg   r_   r)   r   parentr   r   r0   r1   r'   r8   get_rdn_nameget_rdn_valuer   r   GUIDr+   r.   r/   r^   rO   MessageMessageElementFLAG_MOD_REPLACEwarningmodifyr   )r3   r4   ntds_dnr   r   remove_connection_objseize_stale_fsmor   r   r   ro   r   r   r   e5r:   r;   r   	ntds_guidstale_connectionsconnstale_fsmo_rolesrolevalme6s   &&&&&&&&&&                r   offline_remove_ntds_dcr   )  s    ,,r ^^O3D  FCs8q==VVEq6/#:1#=#D#DV#LMN I CnTUU||5J#/.  H 	D	Q!(%*?*?*AC D 	D q'C%/1I%& ' 	' 499c,&7&:;I "LLe.E.E.G5CEN5O ) P &DKK5?@LL! &  <<Rs7H7H3O*3442F1G ( I %Dn%CA77AD++C1E1E,;=AgJNN"gg~7 8LLO %&=GHW/0 %.A,=,=+;-?Ao  wwt3)))!"="GHHd  &wwtL $% & 	&&s0   $K/ 0+L9 /L6:7L11L69M*!M%%M*c                    V P                  4        R p \        P                  ! VR7      pRV,          p T P	                  T. \        P"                  R
R7      p
\        T
4      ^ 8X  dH   Tf1   T P                  4        \        T: RT P                  4       : 24      h\'        YTRRRRRR7       M%\)        YT
^ ,          P                  RRRRRRRR7
       T P+                  4        R #   \         Ed     T P	                  T P                  4       . R\        P                  ! T4      ,          R7      pMF  \         d9   pTP                  w  r\        RT: RT P                  4       : RT	: 24      hR p?ii ; i\        T4      ^ 8X  d1   T P                  4        \        T: RT P                  4       : 24      hT^ ,          P                  p\        P                  ! T R	4      pTP!                  T4        ELi ; i  \         df   pTP                  w  rT\        P$                  8X  d	   . p
 R p?ELT P                  4        \        RT: RT P                  4       : RT	: 24      hR p?ii ; i)N)hexz	<GUID=%s>z(&(objectClass=server)(cn=%s)))rA   rD   rC   zFailure checking if z is an server object in z: z is not an AD DC in zCN=NTDS Settingsz(objectClass=ntdsdsa)r   z is an NTDS DSA in Tr   )r   r   r   r   r   r   r   )transaction_startuuidUUID
ValueErrorr]   r+   r(   r   r   r0   r   r'   r_   transaction_cancelr8   r)   r*   rg   r1   r   r   transaction_commit)r3   r4   r5   r   r   r   server_msgse3r:   r;   	ntds_msgse7s   &&&         r   	remove_dcr   ~  sS   
 
I$II'*		)0:LLgRs~~,C ! E	 	I!$$&!%,e.C.C.E#G H H 	e'260404/315	7 	u(|37155904150426	8 
}  $
	N,,E,C,C,E-/32),):):7)C3D ' EK
  	N77LT!%,e.C.C.Et#M N N	N !$$&!%,e.C.C.E#G H HN%%	&& 23#)$4  :ww3)))I$$&!%//149: ::sS    C& #G9 &G63=D10G61E4<3E//E44A>G65G69I)%I$/5I$$I)c                 ^    V P                  4        \        WR 4       V P                  4        R # r   )start_transactionr   commit_transaction)r3   r   s   &&r    offline_remove_dc_RemoveDsServerr     s$    	540	r   )F)FFFFF)FFFFFFF)r   r(   r   sambar   	samba.ndrr   samba.dcerpcr   r   samba.dcerpc.dnspr   r	   r
   r   r   r   	Exceptionr   r=   rx   re   r   r   r   r    r   r   <module>r      s^   &  
     #/ /0i 08vMJ`(;VI9XRAjK\r   