+
    4Ssi l                        ^ RI t ^ RIt^ RIHt ^ RIt^ RIt^ RIHt ^ RI	H
t
 ^ RI	Ht ^ RIHtHtHtHt ^ RIHt ^ RIHt ^ RIHtHt ^ R	IHt ^ R
IHt ^ RIHtHtHt ^ RIt^ RIt^ RI H!t!H"t" ^ RI#H$t$ ^ RI%H&t&H't'H(t(H)t)H*t*H+t+H,t,H-t- ]! RRR].RRR7      ]! RRR].RRR7      ]! RRRRRR7      ]! R R!R"R#7      ]! R$R%]/! ]P`                  ! 4       4      R&7      ]! R'R(R)R"R*R+7      ]! R,R-R.R"R*R+7      ]! R/R0R1R2R3R47      .t1]! R5R6RR7RR7      ]! R8R9RR:RR7      .t2R;t3 ! R< R=]4      t4R> t5R? t6R@ t7 ! RA RB]44      t8 ! RC RD]94      t: ! RE RF]44      t; ! RG RH]44      t< ! RI RJ]4      t=R# )K    N)defaultdict)dsdb)nttime2unix)CommandSuperCommandCommandErrorOption)SamDB)	dot_graph)distance_matrixCOLOUR_SETS)full_matrix)is_colour_wanted)
SCOPE_BASESCOPE_SUBTREELdbError)KCCldif_import_export)KCCError)get_partition_mapsget_partitionget_own_cursorget_utdvget_utdv_edgesget_utdv_distancesget_utdv_max_distanceget_kcc_and_dsasz-Hz--URLz%LDB URL for database or target serverURLH)helptypemetavardestz-oz--outputzwrite here (default stdout)FILE)r    r!   r"   defaultz
--distancez&Distance matrix graph output (default)formatdistancestore_const)r    r#   constactionz--utf8zUse utf-8 Unicode characters
store_true)r    r*   z--color-schemez,use this colour scheme (implies --color=yes))r    choicesz-Sz--shorten-namesz don't print long common suffixesF)r    r*   r%   z-rz--talk-to-remotezquery other DCs' databasesz--no-keyzomit the explanatory keystore_falseTkey)r    r*   r%   r#   z--dotzGraphviz dot outputdotz--xdotzattempt to call Graphviz xdotxdot__temp__c                      a  ] tR t^Rt o RtRtR]P                  R]P                  R]P                  /t
]],           tRtR tRR ltR	 tR
 tR tRtV tR# )GraphCommandz Base class for graphing commandsz%prog [options]	sambaoptsversionoptscredoptsc                f    VP                  4       pVP                  VR R7      p\        WVR7      pV# )Tfallback_machine)urlcredentialslp)get_loadparmget_credentialsr
   )selfr   r4   r6   r<   credssamdbs   &&&&   8/usr/lib/python3/dist-packages/samba/netcmd/visualize.pyget_dbGraphCommand.get_db^   s6    ##%((d(C!26    Nc                4   Ve   VR8X  d   \        WP                  R7       R# V\        J d>   \        P                  ! RVR7      w  rB\        VR4      p\        P                  ! V4       M\        VR4      pVP                  V4       VP                  4        V# )aW  Decide whether we're dealing with a filename, a tempfile, or
stdout, and write accordingly.

:param s: the string to write
:param fn: a destination
:param suffix: suffix, if destination is a tempfile

If fn is None or "-", write to stdout.
If fn is visualize.TEMP_FILE, write to a temporary file
Otherwise fn should be a filename to write to.
N-filesamba-tool-visualise)prefixsuffixw)	printoutf	TEMP_FILEtempfilemkstempopenosclosewrite)r?   sfnrL   fdfs   &&&&  rB   rV   GraphCommand.writed   sw     :s!))$?%%-C-35FBRAHHRLRA	
			rE   c                    V'       g2   V'       d(   VP                  4       P                  R4      '       d   R# R# VR8X  d   R# V# )z5Heuristics to work out what output format was wanted..dotr/   r'   r0   )lowerendswith)r?   r&   outputs   &&&rB   calc_output_formatGraphCommand.calc_output_format   s4    &,,.11&99!VrE   c                    Vf   V P                  V\        4      pMV P                  W4      p\        P                  P	                  RR4      p\
        P                  ! WC.4       \        P                  ! V4       R # )NSAMBA_TOOL_XDOT_PATHz/usr/bin/xdot)rV   rP   rT   environget
subprocesscallremove)r?   rW   r`   rX   r0   s   &&&  rB   	call_xdotGraphCommand.call_xdot   sS    >Ay)BA&Bzz~~4oF
#
		"rE   c                    Ve   V# VR9   d   V P                   p\        W P                  R7      pV'       g   R# R\        P                  P                  RR4      9   d   R# R# )	zHeuristics to work out the colour scheme for distance matrices.
Returning None means no colour, otherwise it should be a colour
from graph.COLOUR_SETSN)hint256colorTERM zxterm-256color-heatmapansi)rG   N)rO   r   requested_colourrT   re   rf   )r?   color_schemer`   want_colours   &&& rB   calc_distance_color_scheme'GraphCommand.calc_distance_color_scheme   sV     #[ YYF&v4I4IJ
 33+rE    )Nr]   )__name__
__module____qualname____firstlineno____doc__synopsisoptionsSambaOptionsVersionOptionsCredentialsOptionstakes_optiongroupsCOMMON_OPTIONSDOT_OPTIONStakes_options
takes_argsrC   rV   ra   rj   ru   __static_attributes____classdictcell____classdict__s   @rB   r3   r3   R   se     * HW))w--G..
 #[0MJ: rE   r3   c                f    \         P                  ! RV 4      pV'       d   VP                  ^4      # V # )zBHelper function for sorting and grouping DNs by site, if
possible.z$CN=Servers,CN=\s*([^,]+)\s*,CN=Sites)researchgroup)dnms   & rB   get_dnstr_siter      s+     			92>AwwqzIrE   c                &    \        V ^ ,          4      # )zXHelper function for sorting and grouping lists of (DN, ...) tuples
by site, if possible.)r   )ts   &rB   get_dnstrlist_siter      s     !A$rE   c                    ^ RI Hp \        V 4      p\        V\        4      '       d   VP	                  R4      p\        V! V4      P                  4       R,          ^R7      R,          pRV,          # )zMGenerate a randomish but consistent darkish colour based on the
given object.)md5utf8:N   N)basei z#%06x)hashlibr   str
isinstanceencodeint	hexdigest)xr   tmp_strcs   &   rB   colour_hashr      sX     !fG'3..(CL""$R(r2X=AQ;rE   c                   d   a  ] tR t^t o Rt]],           ]! RRRRR7      .,           tR	R lt	Rt
V tR# )
cmd_repszrepsFrom/repsTo from every DSA-p--partitionrestrict to this partitionNr    r%   c                "   VP                  4       pVP                  VR R7      p\        WV4      w  ppVP                  p\	        VP
                  V
4      p
\        R 4      p/ pV EF  p\        VR R7      pV'       d   VP
                  P                  V\        R.R7      p\        V^ ,          R,          ^ ,          4      p\        RV: RV: R2\        P                  R	7        VP                  R
V,          VV4       TP!                  YT4       M&VP                  WV4       VP!                  WVVR7       \#        VP%                  4       4      pVV8w  d   \        R\        P                  R	7       VV,
           F%  p\        RV,          \        P                  R	7       K'  	  \        RV,          \        P                  R	7       VV,
           F%  p\        RV,          \        P                  R	7       K'  	  V EF  pV	R8X  d
   VV8X  d   K  V	R8X  d
   VV8w  d   K$  VP'                  RV,           4      pVP)                  V4       VV\        VP*                  4      &   VP-                  4       w  pp VP/                  4        F4  w  p!p"V
e
   V!V
8X  g   K  VV!,          R,          P1                  VV"34       K6  	  V P/                  4        F4  w  p!p"V
e
   V!V
8X  g   K  VV!,          R,          P1                  VV"34       K6  	  EK  	  EK  	  RR. R. /RR. R. //p#\3        VP
                  4      w  p$p%VP/                  4        F  w  p&p!V#P/                  4        F  w  p'p(V!V',           F  w  pp"V%P5                  V&V&4      p)V"P6                   F8  p*V(R,          P1                  VV\        V*P8                  4      ,          V)34       K:  	  V"P:                   F8  p*V(R,          P1                  V\        V*P8                  4      ,          VV)34       K:  	  K  	  K  	  K  	  V P=                  W4      R8X  d   V P?                  VV4      pRRRR/p+V#P/                  4        F  w  p'p(V(P/                  4        F  w  p,p-\        \@        4      p.V- F!  w  p/p0p!V.V!,          P1                  V/V034       K#  	  V.P/                  4        FF  w  p!p1\C        RV1VVVV\D        R7      p2RV+V,,          V!,          : RV2: 2p2V PG                  V2V4       KH  	  K  	  K  	  R# . p3. p4. p5\#        4       p6/ p7\#        4       p8V#P/                  4        F  w  p'p9V9P/                  4        F  w  p,p-V- F  w  p/p0p!V7PI                  V!\K        V!V,34      4      p:V'R8X  d   RMRp;V,R8X  d   RMR p<V6PM                  V/4       V6PM                  V04       V5P1                  V/V034       V3P1                  V:4       R!V;: R"V<: 2p=V4P1                  V=4       V8PM                  V!R#V,PO                  4       ,           V:V=34       K  	  K  	  K  	  . p>V'       d]   \Q        V84       F+  w  p!p,p:p;V>P1                  R$R%V:: R&V;: 2V!: R'V,: 234       K-  	  V>P1                  R*4       V>P1                  R+4       \S        V6V5R V3V4VV>R(7      p2VR)8X  d   V PU                  V2V4       R# V PG                  V2V4       R#   \         d1   p\        RT: RT: R2\        P                  R	7        Rp?EK  Rp?ii ; i),Tr8   c                       \        \        4      # )N)r   listrw   rE   rB   <lambda>cmd_reps.run.<locals>.<lambda>   s	    k$&7rE   )readonlydNSHostNamescopeattrszAttempting to contact ldap:// ()rH   	ldap://%sCould not contact ldap://N)forced_local_dsazfound extra DSAs:z   %sz(missing DSAs (known locally, not by %s):othersr?   CN=NTDS Settings,currentneededtofromr'   zRepsFrom objects for %szRepsTo objects for %s)r   colourshorten_namesgenerate_keygrouping_function
dottedsolidrS   emptyzstyle="z"; arrowhead=repsFzcolor="z";  )directededge_colorsedge_stylesr   	key_itemsr0   )Fz style="dotted"; arrowhead="open"zrepsFromTo is needed)Fzstyle="solid"; arrowhead="open"zrepsFromTo currently exists)+r=   r>   r   unix_nowr   rA   r   r   r   r   r   rN   sysstderr
load_samdbr   runset	list_dsasget_dsatranslate_ntdsconndsa_guidget_rep_tablesitemsappendr   rf   rep_repsFromsource_dsa_obj_guid
rep_repsTora   ru   r   r   r   rV   
setdefaultr   addtitlesortedr   rj   )?r?   r   r`   r   r.   talk_to_remoter4   r6   r5   mode	partitionrs   r   r&   r0   r<   r@   	local_kccdsasr   nc_repsguid_to_dnstrdsa_dnkccresdns_nameedsas_from_heredsa	remote_dn
remote_dsar   npartrep	all_edgesshort_partitionslong_partitionspartnamestate	edgelists
short_namerheader_strings	directionr   
part_edgessrcr#   edgesrW   edge_coloursr   	dot_edgesdot_verticesused_colourskey_setedgelistr   	linestylearrowstyler   s?   &&&&&&&&&&&&&&&                                                rB   r   cmd_reps.run   s    ##%((d(C*1%8	4%%!)//9=	
 78
 Fh.Coo,,V3=4A? - D s1vm4Q78)::'NN;#92uE u%qe,uv> 1N~%)

;*T11C'C-cjj9 2@6I::' >11C'C-cjj9 2 ,	8#	V(;V^	V(; [[)<y)HI
&&z2:Cc*"5"567 "0021!"ID# (DI,=i077F "+ "#ID# (DI,=h/66}E "+ ,A f b&"5r62 68	 -?y,O)/%mmoNHd$-OO$5 y#';;KFC!0!4!4Xx!HJ --!&)00#*3q/D/D+EF')* .
 !^^!$..*3q/D/D+EF#')* , $/ %6 .$ ""62j@::<;ACL 1-N %.OO$5 y(1(9$Iu!,T!2J+0T4"4(//d< ,1'1'7'7'9e+D%153?:G9<>LN +9*Cd*J*JAN

1f- (:	 ): %6 	u%(0OE8$,NN$4 	5',OCt)44d5@$BKBM 6NOF -2X,=7I&/4&7FWE $$S) $$T*$$c4[1 ''/:CUKE&&u-KKv	0A'A!'!0 1 (- %5  1" 	6<Wo2i  %6<i"H-19"="? @ 7F  6 7  = > lI#"."-$1 )+ VNN1f%JJq&!I   !L"zz+s   &[\$\		\rw   )NNFTFNNNr?   NNNNF)rx   ry   rz   r{   r|   r   r   r	   r   r   r   r   r   s   @rB   r   r      s:     $"[0t])E	4 M
h" h"rE   r   c                   0   a  ] tR tRt o RtR tR tRtV tR# )NTDSConni}  zTCollects observation counts for NTDS connections, so we know
whether all DSAs agree.c                H    ^ V n         RV n        RV n        Wn        W n        R# )r   FN)observationssrc_attestsdest_attestsr   r#   )r?   r   r#   s   &&&rB   __init__NTDSConn.__init__  s$     !	rE   c                    V ;P                   ^,          un         WP                  8X  d   RV n        WP                  8X  d
   RV n        R# R# )   TN)r  r   r  r#   r  )r?   attesters   &&rB   attestNTDSConn.attest  s<    Qxx#Dyy  $D !rE   )r#   r  r  r   r  N)	rx   ry   rz   r{   r|   r  r  r   r   r   s   @rB   r  r  }  s     % %rE   r  c                   h   a  ] tR tRt o Rt]],           ]! RRRR7      .,           tR t	R
R lt
R	tV tR# )cmd_ntdsconni  zDraw the NTDSConnection graphz--importldifz#graph from samba_kcc generated ldifNr   c                    \         P                  ! R R7      p\        P                  P	                  VR4      pW@n        \        P                  ! WBV4      pV# )rJ   )rK   zimported.ldb)rQ   mkdtemprT   pathjoin_tmp_fn_to_deleter   ldif_to_samdb)r?   ldifr<   drX   rA   s   &&&   rB   import_ldif_dbcmd_ntdsconn.import_ldif_db  sD    $:;WW\\!^,!#"00>	rE   c                   VP                  4       pVf   VP                  VRR7      pMR pV P                  W4      p\        WV4      w  ppVP                  P                  R^4      ^,          p\        4       p. pV EFo  pV'       dw   VP                  P                  V\        R.R7      pV^ ,          R,          ^ ,          p V P                  RV,          VV4      pTP                  4       pTP!                  4       pMV P                  WV4      pRV,           pTpVP                  V\        R.R7      pV^ ,          R,          ^ ,          R8H  pTP#                  TV'       d   RMR34       VP                  V\$        RR.R.R7      pV F^  p\'        VP(                  4      pVVP+                  R4      ^,           R  pVP-                  \'        VR,          ^ ,          4      VV34       K`  	  EKr  	  V'       dZ   WP.                  8X  dJ   \0        P2                  ! V4       \0        P4                  ! \0        P6                  P9                  V4      4       / p V F;  w  p!p"p#V!V"3p$V$V 9   d   V V$,          pM\;        V$!  pVV V$&   VP=                  V#4       K=  	  \?        \A        V4      !  w  pp%V PC                  W4      R8X  Ed1   V PE                  V	V4      p	\F        V	,          p&V&PI                  RR4      p'V&PI                  RR4      p(. p)RV%9   d   V)P-                  R4       V'       g   V PK                  4       p*RV,          p+EMR. p*. p,. p-. p.V PM                  4        F  w  pp/V/PN                  '       d9   V*P-                  V4       V/PP                  '       g   V,P-                  V4       KN  KP  V/PP                  '       d   V-P-                  V4       Ku  V.P-                  V4       K  	  Rp+V.'       d3   V)P-                  R4       V. F  pV)P-                  RV,          4       K  	  V-'       d3   V)P-                  R4       V- F  pV)P-                  RV,          4       K  	  V,'       d3   V)P-                  R4       V, F  pV)P-                  RV,          4       K  	  \S        VV*V
V	VV\T        V%R7      p0RPW                  V)4      p)V)'       d   RV': R V(: RV): 2p)V PY                  RV+: R!V0: RV): 2V4       R # . p1. p2. p3. p4\[        V4      p5\A        V PM                  4       4       EF  w  p$pV1P-                  V$4       VP\                  V58X  g	   V'       g%   V2P-                  R"4       V3P-                  R4       KU  VPN                  '       dJ   V3P-                  R4       VPP                  '       d   V2P-                  R#4       K  V2P-                  R$4       K  VPP                  '       d%   V2P-                  R%4       V3P-                  R&4       K  V2P-                  R%4       V3P-                  R'4       EK  	  . p6V'       dr   V6P-                  R.4       R/ F*  w  p7p8V7V29   g   K  V6P-                  R(R)V7,          V834       K,  	  R0 F*  w  p9p8V9V39   g   K  V6P-                  R(R*V9,          V834       K,  	  V'       d   R+p+M	RV,          p+\_        \A        V4      V1RV+V2V4V3VV6R,7	      p0VR-8X  d   V Pa                  V0V4       R # V PY                  V0V4       R #   \         d1   p\        RT: RT: R	2\        P                  R
7        R p?EK  R p?ii ; i)1NTr8   ,r   r   r   r   r   r   rH   r   zmsDS-isRODCTRUERODCrp   z(objectClass=nTDSConnection)
fromServerzsearch_options:0:2)r   
expressionr   controlsr'   headerresetz/No outbound connections are expected from RODCszNTDS Connections known to %sz-NTDS Connections known to each destination DCzTThe following connections are alleged by DCs other than the source and destination:
z  %s -> %s
zbThe following connections are alleged by DCs other than the destination but including the source:
zRThe following connections (included in the chart) are not known to the source DC:
)r   r   r   r   r   row_commentsr   NOTES

z#000000#0000ff#cc00ffz#ff0000style=dashedstyle=dottedFz
color="%s"zcolor="#ff0000; %s"zNTDS Connections)r   r   r   edge_labelsr   r   r   r0   )Fzcolor="#000000"zNTDS Connection))r0  zmissing from some DCs)r1  zmissing from source DC))r2  zunknown to destination)r3  z!unknown to source and destination)1r=   r>   r"  r   my_dsa_dnstrsplitr   rA   r   r   rC   r   rN   r   r   get_dsServiceName	domain_dnr   r   r   r   indexr   r  rT   ri   rmdirr  dirnamer  r  zipr   ra   ru   r   rf   keysr   r  r  r   r   r  rV   lenr  r   rj   ):r?   r   r`   r   r.   r   r4   r6   r5   rs   r   r&   
importldifr0   r<   r@   r   r   local_dsa_dnverticesattested_edgesr   r   r   rA   r   ntds_dnr   is_rodcmsgmsgdndest_dnr   r   r#   r  krodc_statuscoloursc_headerc_resetepiloggraph_edgesr   source_deniesdest_denies	both_denyconnrW   r  r  r   r4  	n_serversr   r   descr	  s:   &&&&&&&&&&&&&&                                            rB   r   cmd_ntdsconn.run  s    ##%,,R$,GEE##J3A*1%8	4 --33C;A>5Foo,,V3=4A? - D q6-03 KKh(>	(02E  113__&A(;-6,,w%/&3_  6C !f]+A.&8GLL'W6"=>,,r%2*H&2^ *>(>  !C CFFC 01 4 56%%s3|+<Q+?'@'.'9 : M X !555IIaLHHRWW__Q'( #1CxdAEz!HaLaHHX $2 !$VH%5 6+""62j@::<;ACL!,/G{{8R0Hkk'2.GF$OP! $jjl6E ! " 	${{}GAt(((#**1-#///)003  0)))#**1-!((+  - HMM #3 4 'nq&89 'MM #< = )nq&89 ) MM #F G +nq&89 +  +%)'3.;-02D-8:A WWV_Fv.6.5.46 JJ5+,+134:< 	I	5;;=)DAqQ~~*.##I.""2&""2&=== ''	2 ''	2##I."">2##I."">2! *$ 	 1 2!H\)$$e\F-BD%IJ!H
 Gt K'$$e&;e&C&*&, -	 G &E2\AEfX&	#!"."-"-$1 )+ VNN1f%JJq&!E   !L"zz+s   \\?$\::\?)r  )NNFTFNNNNNNNF)rx   ry   rz   r{   r|   r   r   r	   r   r"  r   r   r   r   s   @rB   r  r    s=     #"[0~$I	4 M
]" ]"rE   r  c            	       l   a  ] tR tRt o Rt]]! RRRRR7      ]! R^]R	R
7      .,           tRR lt	Rt
V tR# )cmd_uptodatenessi}  zvisualize uptodateness vectorsr   r   r   Nr   z--max-digitsz,display this many digits of out-of-date-ness)r%   r!   r    c                   V'       g   \        R V P                  R7       R# VP                  4       pVP                  VRR7      p\	        VVV4      w  ppVP
                  V n        \        V P
                  V4      p\        V P
                  4      w  ppV P                  V	V4      p	VP                  4        F  w  ppVVR39  d   K  \        VVVVV4      p\        VV4      p\        V4      p\        V\        \        V4      4      4      pV^8  d   ^p^
V,          p\!        VV
V	VV\"        VVRRR7
      pV P%                  RV: R	V: 2V4       K  	  R# )
z>this won't work without talking to the remote servers (use -r)rH   NTr8   DCzout-of-date-ness)	r   r   r   r   r   colour_scaledigitsylabelxlabelr   r/  )rN   rO   r=   r>   r   rA   r   r   ru   r   r   r   r   minr>  r   r   r   rV   )r?   r   r`   r   r.   r   r4   r6   r5   rs   r   r&   r?  r0   r   
max_digitsr<   r@   r   r   r   r   	part_namepart_dn
utdv_edges	distancesmax_distancer[  c_scalerW   s   &&&&&&&&&&&&&&&&              rB   r   cmd_uptodateness.run  sQ     #'99. ##%((d(C*1b%8	4__
!$**i8	,>tzz,J)/66|7=? #3"8"8":Iw$/'	4"eLJ*:t<I0;LS\):%;<FzFlGI!%#/*7),.<)0#)#'#5	7A JJy!4f=5 #;rE   )rA   )NNFTFNNNNFNNFN   )rx   ry   rz   r{   r|   r   r	   r   r   r   r   r   r   s   @rB   rW  rW  }  sE     ("t])E	~qsB	D& M1> 1>rE   rW  c                       ] tR tRtRt/ t]! 4       P                  4        F0  w  tt	]P                  R4      '       g   K  ]	! 4       ]]R,          &   K2  	  RtR# )cmd_visualizei  z:Produces graphical representations of Samba network state.cmd_:   NNrw   N)rx   ry   rz   r{   r|   subcommandsglobalsr   rH  v
startswithr   rw   rE   rB   ri  ri    s@    DK	!1<<!"K" "rE   ri  )>rT   r   collectionsr   rg   rQ   samba.getoptgetoptr~   sambar   r   samba.netcmdr   r   r   r	   samba.samdbr
   samba.graphr   r   r   r   samba.colourr   ldbr   r   r   timer   	samba.kccr   r   samba.kcc.kcc_utilsr   samba.uptodatenessr   r   r   r   r   r   r   r   r   r   r=  r   r   rP   r3   r   r   r   r   objectr  r  rW  ri  rw   rE   rB   <module>r~     s  ( 
 
 #      D D  ! 4 # ) 3 3  	 - (	 	 	 4FU.
4"?VT3
<F
=B
88 
 $;((*+- 4"2/ 4#*F/
:6E;#, 7.X}.
89/ 	Z7 Zz p"| p"f%v %$k"< k"\;>| ;>|%L %rE   