%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python3/dist-packages/samba/netcmd/__pycache__/
Upload File :
Create Path :
Current File : //lib/python3/dist-packages/samba/netcmd/__pycache__/visualize.cpython-312.pyc

�

�I�dl����ddlZddlZddlmZddlZddlZddlmZddl	m
Z
ddl	mZddlm
Z
mZmZmZddlmZddlmZddlmZmZdd	lmZdd
lmZddlmZmZmZddlZddlZddl m!Z!m"Z"dd
l#m$Z$ddl%m&Z&m'Z'm(Z(m)Z)m*Z*m+Z+m,Z,m-Z-eddde.dd��eddde.dd��eddddd��ed d!d"�#�ed$d%e/ej`���&�ed'd(d)d"d*�+�ed,d-d.d"d*�+�ed/d0d1d2d3�4�gZ1ed5d6dd7d��ed8d9dd:d��gZ2d;Z3Gd<�d=e
�Z4d>�Z5d?�Z6d@�Z7GdA�dBe4�Z8GdC�dDe9�Z:GdE�dFe4�Z;GdG�dHe4�Z<GdI�dJe�Z=y)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--outputzwrite here (default stdout)�FILE)r r!r"�defaultz
--distancez&Distance matrix graph output (default)�format�distance�store_const)r r#�const�actionz--utf8zUse 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-remotezquery other DCs' databasesz--no-keyzomit the explanatory key�store_falseT�key)r r*r%r#z--dotzGraphviz dot output�dotz--xdotzattempt to call Graphviz xdot�xdot�__temp__c��eZdZdZdZejejejd�Z	e
ezZdZ
d�Zdd�Zd�Zd	�Zd
�Zy)�GraphCommandz Base class for graphing commandsz%prog [options])�	sambaopts�versionopts�credopts�c�h�|j�}|j|d��}t|||��}|S)NT��fallback_machine)�url�credentials�lp)�get_loadparm�get_credentialsr
)�selfrr4r6r=�creds�samdbs       �8/usr/lib/python3/dist-packages/samba/netcmd/visualize.py�get_dbzGraphCommand.get_db^s8��
�
#�
#�
%���(�(��d�(�C���!��2�6����Nc�&�|�|dk(rt||j��y|tur<tjd|��\}}t|d�}t
j|�nt|d�}|j|�|j�|S)a�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      rCrVzGraphCommand.writeds{���:��s���!�$�)�)�$��
��?��%�%�-C�-3�5�F�B���R��
�A��H�H�R�L��R��
�A�	����
�	���	��	rEc�\�|s#|r |j�jd�ryy|dk(ry|S)z5Heuristics to work out what output format was wanted.�.dotr/r'r0)�lower�endswith)r@r&�outputs   rC�calc_output_formatzGraphCommand.calc_output_format�s1����&�,�,�.�1�1�&�9��!��V����
rEc���|�|j|t�}n|j||�}tjj	dd�}tj||g�tj|�y)N�SAMBA_TOOL_XDOT_PATHz
/usr/bin/xdot)rVrPrT�environ�get�
subprocess�call�remove)r@rWr_rXr0s     rC�	call_xdotzGraphCommand.call_xdot�sW���>����A�y�)�B����A�v�&�B��z�z�~�~�4�o�F������r�
�#�
�	�	�"�
rEc��|�|S|dvr|j}t||j��}|sydtjjdd�vryy)	z�Heuristics to work out the colour scheme for distance matrices.
        Returning None means no colour, otherwise it should be a colour
        from graph.COLOUR_SETSN)rGN)�hint�256color�TERM�zxterm-256color-heatmap�ansi)rOr�requested_colourrTrcrd)r@�color_schemer_�want_colours    rC�calc_distance_color_schemez'GraphCommand.calc_distance_color_scheme�sX���#����[� ��Y�Y�F�&�v�D�4I�4I�J����
��������3�3�+�rE)Nr\)�__name__�
__module__�__qualname__�__doc__�synopsis�options�SambaOptions�VersionOptions�CredentialsOptions�takes_optiongroups�COMMON_OPTIONS�DOT_OPTIONS�
takes_options�
takes_argsrDrVr`rhrrr7rErCr3r3RsW��*� �H��)�)��-�-��.�.���
#�[�0�M��J���:��rEr3c�X�tjd|�}|r|jd�S|S)zFHelper function for sorting and grouping DNs by site, if
    possible.z$CN=Servers,CN=\s*([^,]+)\s*,CN=Sites�)�re�search�group)�dn�ms  rC�get_dnstr_siter��s+��	�	�	�9�2�>�A���w�w�q�z��
�IrEc��t|d�S)z\Helper function for sorting and grouping lists of (DN, ...) tuples
    by site, if possible.r)r�)�ts rC�get_dnstrlist_siter��s���!�A�$��rEc��ddlm}t|�}t|t�r|j	d�}t||�j
�ddd��dz}d	|zS)
zQGenerate a randomish but consistent darkish colour based on the
    given object.r)�md5�utf8N��)�baseiz#%06x)�hashlibr��str�
isinstance�encode�int�	hexdigest)�xr��tmp_str�cs    rC�colour_hashr��sW����!�f�G��'�3���.�.��(���C��L�"�"�$�R�a�(�r�2�X�=�A��Q�;�rEc�H�eZdZdZeezedddd��gzZ					dd�Zy)	�cmd_repszrepsFrom/repsTo from every DSA�-p�--partition�restrict to this partitionN�r r%c��|j�}|j|d��}t|||�\}}|j}t	|j
|
�}
t
d��}i}|D�]D}t|d��}|r�|j
j|tdg��}t|ddd�}td|�d	|�d
�tj��	|jd|z||�|j!|||�n(|j|||�|j!||||��t#|j%��}||k7r�tdtj��||z
D] }td|ztj���"td|ztj��||z
D] }td|ztj���"|D]�}|	dk(r||k(r�|	dk(r||k7r�|j'd|z�}|j)|�||t|j*�<|j-�\}} |j/�D]&\}!}"|
�|!|
k(s�||!dj1||"f��(| j/�D]&\}!}"|
�|!|
k(s�||!dj1||"f��(����Gggd�ggd�d�}#t3|j
�\}$}%|j/�D]�\}&}!|#j/�D]�\}'}(|!|'D]�\}}"|%j5|&|&�})|"j6D]/}*|(dj1||t|*j8�|)f��1|"j:D]/}*|(dj1|t|*j8�||)f��1������|j=|
|�dk(r�|j?||�}ddd�}+|#j/�D]�\}'}(|(j/�D]�\},}-t
t@�}.|-D]\}/}0}!|.|!j1|/|0f��|.j/�D];\}!}1tCd|1||||tD��}2d |+|,|!z�d |2��}2|jG|2|��=����yg}3g}4g}5t#�}6i}7t#�}8|#j/�D]�\}'}9|9j/�D]�\},}-|-D]�\}/}0}!|7jI|!tK|!|,f��}:|'dk(rd!nd"};|,dk(rd#nd$}<|6jM|/�|6jM|0�|5j1|/|0f�|3j1|:�d%|;�d&|<��}=|4j1|=�|8jM|!d'|,jO�z|:|=f�������g}>|rVtQ|8�D]&\}!},}:};|>j1d(d)|:�d*|;��|!�d+|,��f��(|>j1d,�|>j1d-�tS|6|5d|3|4||>�.�}2|
d/k(r|jU|2|�y|jG|2|�y#t$r-}td
|�d	|�d
�tj��Yd}~���d}~wwxYw)0NTr9c� �tt�S)N)r�listr7rErC�<lambda>zcmd_reps.run.<locals>.<lambda>�s��k�$�&7�rE)�readonly�dNSHostName��scope�attrsrzAttempting to contact ldap://� (�)rH�	ldap://%s�Could not contact ldap://)�forced_local_dsazfound extra DSAs:z   %sz(missing DSAs (known locally, not by %s):�othersr@�CN=NTDS Settings,�current�needed)�to�from)r�r�r�r�r'zRepsFrom objects for %szRepsTo objects for %s)r�r�)r��colour�
shorten_names�generate_key�grouping_function�
�dotted�solidrS�emptyzstyle="z
"; arrowhead=�repsFzcolor="z"; � )Fz style="dotted"; arrowhead="open"zrepsFromTo is needed)Fzstyle="solid"; arrowhead="open"zrepsFromTo currently exists)�directed�edge_colors�edge_stylesr��	key_itemsr0)+r>r?r�unix_nowrrBrrr�rr�rN�sys�stderr�
load_samdbr�run�set�	list_dsas�get_dsa�translate_ntdsconn�dsa_guid�get_rep_tables�items�appendrrd�rep_repsFrom�source_dsa_obj_guid�
rep_repsTor`rrr�rr�rV�
setdefaultr��add�title�sortedrrh)?r@rr_r�r.�talk_to_remoter4r6r5�mode�	partitionrpr�r&r0r=rA�	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?                                                               rCr�zcmd_reps.run�s����
#�
#�
%���(�(��d�(�C��*�1�b�%�8��	�4��%�%��!�)�/�/�9�=�	�
�7�8���
�
�1	F�F��h��.�C���o�o�,�,�V�3=�4A�?�-�D���s�1�v�m�4�Q�7�8�����)��:�:�'���N�N�;��#9�2�u�E�����2�u�%����q�"�e�,�����2�u�v��>� �����1�N��~�%��)��
�
�;�*�T�1�:�C��'�C�-�c�j�j�9�:��@�6�I��:�:�'� �>�1�:�C��'�C�-�c�j�j�9�:�,�
F�	��8�#�	�V�(;���V�^�	�V�(;�� �[�[�)<�y�)H�I�
��&�&�z�2�:C�
�c�*�"5�"5�6�7�"�0�0�2���1�!"����G�I�D�#� �(�D�I�,=���
�i�0�7�7���
�F�G�"#����F�I�D�#� �(�D�I�,=���
�h�/�6�6���}�E�F�
F�A1	F�f')�"�5�')�2� 6�8�	�-?�y���,O�)��/�%�m�m�o�
	*�N�H�d�$-�O�O�$5�
*� ��y�#'��;�*�K�F�C�!0�!4�!4�X�x�!H�J� �-�-�*��!�&�)�0�0�#�*�3�q�/D�/D�+E�F�'�)�*�*�
!�^�^�*��!�$��.�.�*�3�q�/D�/D�+E�F�#�'�)�*�*�*�
*�
	*�$�"�"�6�6�2�j�@��:�:�<�;A�C�L�2�-��N�%.�O�O�$5�
.� ��y�(1���(9�
.�$�I�u�!,�T�!2�J�+0�=���T�4�"�4�(�/�/��d��<�=�'1�'7�'7�'9�	.���e�+�D�%�15�3?�:G�9<�>L�N��+9��*C�d�*J�A�N���
�
�1�f�-�	.�	
.�
.�
������	��u�����%��(���0�	1�O�E�8�$,�N�N�$4�
1� �	�5�',�
1�O�C��t�)�4�4�d�5@�$�BK�BM�6N�O�F�-2�X�,=��7�I�&/�4�&7�F�W�E� �$�$�S�)� �$�$�T�*��$�$�c�4�[�1� �'�'��/�:C�U�K�E��&�&�u�-��K�K��v�	���0A�'A�!'��!0�1�
1�
1�	1�"�	��6<�W�o�
@�2��i���� � �%�6<�i�"H�-1�9�"=�"?�@�
@�
���6�
7�
���=�
>�
�l�I�#�".�"-�$1� )�
+���V���N�N�1�f�%��J�J�q�&�!��I ����!�L�"�z�z�+����s�X�	Y�""Y
�
Y)NNFTFNNNr@NNNNF)	rsrtrurvr}r~r	rr�r7rErCr�r��sB��$�"�[�0��t�]�)E��	�4��M�
6;�%*�7;�6:�).�	h"rEr�c��eZdZdZd�Zd�Zy)�NTDSConnzXCollects observation counts for NTDS connections, so we know
    whether all DSAs agree.c�J�d|_d|_d|_||_||_y)NrF)�observations�src_attests�dest_attestsr�r#)r@r�r#s   rC�__init__zNTDSConn.__init__�s(����� ���!��������	rEc��|xjdz
c_||jk(rd|_||jk(rd|_yy)Nr�T)rr�rr#r)r@�attesters  rC�attestzNTDSConn.attest�s@�����Q����t�x�x��#�D���t�y�y� � $�D��!rEN)rsrtrurvrr
r7rErCrr}s����%rErc�N�eZdZdZeezeddd��gzZd�Z						dd�Z	y)	�cmd_ntdsconnzDraw the NTDSConnection graphz--importldifz#graph from samba_kcc generated ldifNr�c��tjd��}tjj	|d�}||_t
j|||�}|S)NrJ)rKzimported.ldb)rQ�mkdtemprT�path�join�_tmp_fn_to_deleter�
ldif_to_samdb)r@�ldifr=�drXrBs      rC�import_ldif_dbzcmd_ntdsconn.import_ldif_db�sH�����$:�;��
�W�W�\�\�!�^�
,��!#���"�0�0��R��>���	rEc��|j�}|�|j|d��}nd}|j||�}t|||�\}}|jjdd�d}t
�}g}|D�]5}|rf|jj|tdg��}|ddd}	|jd|z||�}|j�}|j!�}n|j|||�}d
|z}|}|j|tdg��}|ddddk(}|j#||rdndf�|j|t$ddgdg��}|D]Q}t'|j(�}||j+d�dzd}|j-t'|dd�||f��S��8|rV||j.k(rGt1j2|�t1j4t0j6j9|��i} |D]2\}!}"}#|!|"f}$|$| vr| |$}n
t;|$�}|| |$<|j=|#��4t?tA|��\}}%|jC||�dk(�r�|jE|	|�}	tF|	}&|&jIdd�}'|&jIdd�}(g})d|%vr|)j-d�|s| jK�}*d|z}+�ng}*g},g}-g}.| jM�D]p\}}/|/jNr0|*j-|�|/jPr�0|,j-|��B|/jPr|-j-|��`|.j-|��rd}+|.r,|)j-d�|.D]}|)j-d|z��|-r,|)j-d�|-D]}|)j-d|z��|,r,|)j-d�|,D]}|)j-d|z��tS||*|
|	||tT|%� �}0djW|)�})|)rd!|'�d"|(�d!|)��})|jYd!|+�d#|0�d!|)��|�yg}1g}2g}3g}4t[|�}5tA| jM��D]�\}$}|1j-|$�|j\|5k(s|s#|2j-d$�|3j-d��K|jNrA|3j-d�|jPr|2j-d%���|2j-d&���|jPr#|2j-d'�|3j-d(���|2j-d'�|3j-d)���g}6|r]|6j-d*�d+D]!\}7}8|7|2vs�|6j-d,d-|7z|8f��#d.D]!\}9}8|9|3vs�|6j-d,d/|9z|8f��#|rd0}+nd|z}+t_tA|�|1d|+|2|4|3||6�1�	}0|d2k(r|ja|0|�y|jY|0|�y#t$r-}td	|�d
|�d�tj��Yd}~���d}~wwxYw)3NTr9�,r�r�r�rr�r�r�r�rHr�zmsDS-isRODC�TRUE�RODCrmz(objectClass=nTDSConnection)�
fromServerzsearch_options:0:2)r��
expressionr��controlsr'�header�resetz/No outbound connections are expected from RODCszNTDS 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=dotted)Fzcolor="#000000"zNTDS Connection))r"zmissing from some DCs)r#zmissing from source DCFz
color="%s"))r$zunknown to destination)r%z!unknown to source and destinationzcolor="#ff0000; %s"zNTDS Connections)r�r�r��edge_labelsr�r�r�r0)1r>r?rr�my_dsa_dnstr�splitr�rBr�rrDrrNr�r��get_dsServiceName�	domain_dnr�rr�r��indexr�rrTrg�rmdirr�dirnamerr
�zipr�r`rrr
rd�keysr�rrrr�rrV�lenrrrh):r@rr_r�r.r�r4r6r5rpr�r&�
importldifr0r=rAr�r��local_dsa_dn�vertices�attested_edgesr�r�r�rBr��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�connrWr�r�r�r&�	n_serversr�r��descrs:                                                          rCr�zcmd_ntdsconn.run�s����
#�
#�
%�����,�,�R�$�,�G�E��E��#�#�J��3�A�*�1�b�%�8��	�4� �-�-�3�3�C��;�A�>���5�����*	:�F���o�o�,�,�V�3=�4A�?�-�D���q�6�-�0��3��� �K�K��h�(>�	�(0�2�E� �1�1�3���_�_�&�����A�y�(�;��-��6�����,�,�w�%/�&3�_��6�C��!�f�]�+�A�.�&�8�G��L�L�'�W�6�"�=�>��,�,�r�%2�*H�&2�^�*>�(>�
�!�C��
:���C�F�F�������C� 0�1� 4� 5�6���%�%�s�3�|�+<�Q�+?�'@�'.��'9�:�
:�M*	:�X�!�t�5�5�5��I�I�a�L��H�H�R�W�W�_�_�Q�'�(���#1�	��C��x��d��A��E�z��!�H���a�L����a��
�H�H�X��	�!$�V�H�%5� 6���+��"�"�6�6�2�j�@��:�:�<�;A�C�L�!�,�/�G��{�{�8�R�0�H��k�k�'�2�.�G��F���$��
�
�O�P�!�$�j�j�l��6��E��!�� "�
� ���	�$�{�{�}�,�G�A�t��(�(�#�*�*�1�-�#�/�/�)�0�0��3��)�)�#�*�*�1�-�!�(�(��+�,�H����M�M�#3�4�'�:���
�
�n�q�&8�9�:���M�M�#<�=�)�:���
�
�n�q�&8�9�:� ��M�M�#F�G�+�:���
�
�n�q�&8�9�:� ��+�%)�'3�.;�-0�2D�-8�
:�A��W�W�V�_�F��.6�.5�.4�6��
�J�J�5�+,�+1�3�4:�
<�
��	���������I�	��5�;�;�=�)�	3�D�A�q����Q���~�~��*�.��#�#�I�.��"�"�2�&�����"�"�2�&��=�=� �'�'�	�2� �'�'�	�2�����#�#�I�.��"�"�>�2��#�#�I�.��"�"�>�2�!	3�$�	�����1�
2�!H�
K�����\�)��$�$�e�\�F�-B�D�%I�J�
K�
 G�
-���t��K�'��$�$�e�&;�e�&C�&*�&,�-�	
-��&�E�2�\�A�E��f�X�&�	�#�!�".�"-�"-�$1� )�
+���V���N�N�1�f�%��J�J�q�&�!��E ����!�L�"�z�z�+����s�-X
�
	Y�"X>�>Y)
NNFTFNNNNNNNF)
rsrtrurvr}r~r	rrr�r7rErCrr�sH��#�"�[�0��~�$I��	�4��M�
�6;�%*�7;��/3��]"rErc�Z�eZdZdZeedddd��edded	�
�gzZ						dd�Zy)
�cmd_uptodatenesszvisualize uptodateness vectorsr�r�r�Nr�z--max-digits�z,display this many digits of out-of-date-ness)r%r!r c
��|std|j��y|j�}|j|d��}t	|||�\}}|j
|_t
|j
|�}t|j
�\}}|j|	|�}	|j�D]�\}}||dfvr�
t|||||�}t||�}t|�}t|tt|���}|dkrd}d|z}t!||
|	||t"||dd�	�
}|j%d
|�d|��|���y)Nz>this won't work without talking to the remote servers (use -r)rHTr9r��
�DCzout-of-date-ness)	r�r�r�r�r��colour_scale�digits�ylabel�xlabelr�r!)rNrOr>r?rrBrrrrr�rrr�minr0r�rr�rV)r@rr_r�r.r�r4r6r5rpr�r&r1r0r��
max_digitsr=rAr�r�r�r��	part_name�part_dn�
utdv_edges�	distances�max_distancerN�c_scalerWs                              rCr�zcmd_uptodateness.run�sV�����#'�9�9�
.���
#�
#�
%���(�(��d�(�C��*�1�b�%�8��	�4��_�_��
�!�$�*�*�i�8�	�,>�t�z�z�,J�)��/��6�6�|�7=�?��#3�"8�"8�":�	>��I�w���$��/��'�	�4��"�e�L�J�*�:�t�<�I�0��;�L���S��\�):�%;�<�F���z����F�l�G��I�!%�#/�*7�),�.<�)0�#)�#'�#5�	7�A�
�J�J�y�!�4�f�=�5	>rE)NNFTFNNNNFNNFNrI)	rsrtrurvr}r	r�rr�r7rErCrHrH}sQ��(�"��t�]�)E��	��~�q�s�B�	D�&��M�6;�%*�7;��04�34�1>rErHc��eZdZdZiZe�j
�D]$\ZZejd�s�e�eedd<�&y)�
cmd_visualizez:Produces graphical representations of Samba network state.�cmd_�N)
rsrtrurv�subcommands�globalsr�r:�v�
startswithr7rErCrZrZ�sD��D��K��	���!�%���1��<�<���!"��K��!�"���%rErZ)>rTr��collectionsrrerQ�samba.getopt�getoptrx�sambarr�samba.netcmdrrrr	�samba.samdbr
�samba.graphrrr
r�samba.colourr�ldbrrr�timer��	samba.kccrr�samba.kcc.kcc_utilsr�samba.uptodatenessrrrrrrrrr�r�r/r}r~rPr3r�r�r�r��objectrrrHrZr7rErC�<module>ros���(
�
�#������D�D��!�4�#�)�3�3��	�-�(�	�	�	��4��F��U��.�
�4��"?��V�T�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

Zerion Mini Shell 1.0