HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: //lib/python3/dist-packages/samba/__pycache__/drs_utils.cpython-310.pyc
o

eF�c�H�@s�ddlmZmZmZddlmZddlmZddlm	Z	ddlm
Z
ddlmZddlZddlZddl
mZmZmZddlZGd	d
�d
e�Zddd�Zd
d�Zdd�Zdd�Zdd�ZGdd�de�ZGdd�de�ZdS)�)�drsuapi�misc�drsblobs)�Net)�
ndr_unpack)�dsdb)�werror)�WERRORErrorN)�DRSUAPI_ATTID_name�(DRSUAPI_SUPPORTED_EXTENSION_GETCHGREQ_V8�)DRSUAPI_SUPPORTED_EXTENSION_GETCHGREQ_V10c@s eZdZdZdd�Zdd�ZdS)�drsExceptionzBase element for drs errorscCs
||_dS�N��value)�selfr�r�1/usr/lib/python3/dist-packages/samba/drs_utils.py�__init__%�
zdrsException.__init__cCs
d|jS)NzdrsException: r)rrrr�__str__(rzdrsException.__str__N)�__name__�
__module__�__qualname__�__doc__rrrrrrr
"sr
c

Cs�d}|��dkr|d7}|dur!|d|��7}d|�d|�d�}nd	||f}zt�|||�}t|�\}}WntyJ}	ztd
||	f��d}	~	ww|||fS)a�Make a DRSUAPI connection to the server.

    :param server: the name of the server to connect to
    :param lp: a samba line parameter object
    :param creds: credential used for the connection
    :param ip: Forced target server name
    :return: A tuple with the drsuapi bind object, the drsuapi handle
                and the supported extensions.
    :raise drsException: if the connection fails
    �seal�	z,printNz,target_hostname=z
ncacn_ip_tcp:�[�]zncacn_ip_tcp:%s[%s]zDRS connection to %s failed: %s)�	log_levelr�
drs_DsBind�	Exceptionr
)
�server�lp�creds�ip�binding_options�binding_string�drsuapiBind�
drsuapiHandle�bindSupportedExtensions�errr�drsuapi_connect,s��
r,c
Csht��}||_t��}||_||_t�|�|_z
|�	|d|�WdSt
y3}ztd|��d}~ww)a�Send DS replica sync request.

    :param drsuapiBind: a drsuapi Bind object
    :param drsuapi_handle: a drsuapi handle on the drsuapi connection
    :param source_dsa_guid: the guid of the source dsa for the replication
    :param naming_context: the DN of the naming context to replicate
    :param req_options: replication options for the DsReplicaSync call
    :raise drsException: if any error occur while sending and receiving the
        reply for the dsReplicaSync
    �zDsReplicaSync failed %sN)r�DsReplicaObjectIdentifier�dn�DsReplicaSyncRequest1�naming_context�optionsr�GUID�source_dsa_guid�
DsReplicaSyncr!r
)r(�drsuapi_handler4r1�
req_option�nc�req1�estrrrr�sendDsReplicaSyncLs
��r;cCs4t��}d|_t��|_|jjtjO_|jjtjO_|jjtjO_|jjtj	O_|jjtj
O_|jjtjO_|jjtjO_|jjtj
O_|jjtjO_|jjtjO_|jjtjO_|jjtjO_|jjtjO_|jjtjO_|jjtjO_|jjtjO_|jjtjO_|jjtjO_|jjtjO_|jjtjO_|jjtjO_|jjtjO_|jjtjO_|jjtjO_|jjtjO_|jjtjO_|jjtj O_|jjtj!O_|�"t#�$tj%�|�\}}||jjfS)z0make a DsBind call, returning the binding handle�)&r�
DsBindInfoCtr�length�DsBindInfo28�info�supported_extensions� DRSUAPI_SUPPORTED_EXTENSION_BASE�-DRSUAPI_SUPPORTED_EXTENSION_ASYNC_REPLICATION�%DRSUAPI_SUPPORTED_EXTENSION_REMOVEAPI�&DRSUAPI_SUPPORTED_EXTENSION_MOVEREQ_V2�+DRSUAPI_SUPPORTED_EXTENSION_GETCHG_COMPRESS�%DRSUAPI_SUPPORTED_EXTENSION_DCINFO_V1�4DRSUAPI_SUPPORTED_EXTENSION_RESTORE_USN_OPTIMIZATION�'DRSUAPI_SUPPORTED_EXTENSION_KCC_EXECUTE�'DRSUAPI_SUPPORTED_EXTENSION_ADDENTRY_V2�4DRSUAPI_SUPPORTED_EXTENSION_LINKED_VALUE_REPLICATION�%DRSUAPI_SUPPORTED_EXTENSION_DCINFO_V2�8DRSUAPI_SUPPORTED_EXTENSION_INSTANCE_TYPE_NOT_REQ_ON_MOD�'DRSUAPI_SUPPORTED_EXTENSION_CRYPTO_BIND�)DRSUAPI_SUPPORTED_EXTENSION_GET_REPL_INFO�-DRSUAPI_SUPPORTED_EXTENSION_STRONG_ENCRYPTION�&DRSUAPI_SUPPORTED_EXTENSION_DCINFO_V01�1DRSUAPI_SUPPORTED_EXTENSION_TRANSITIVE_MEMBERSHIP�+DRSUAPI_SUPPORTED_EXTENSION_ADD_SID_HISTORY�&DRSUAPI_SUPPORTED_EXTENSION_POST_BETA3�,DRSUAPI_SUPPORTED_EXTENSION_GET_MEMBERSHIPS2�(DRSUAPI_SUPPORTED_EXTENSION_GETCHGREQ_V6�)DRSUAPI_SUPPORTED_EXTENSION_NONDOMAIN_NCSr�*DRSUAPI_SUPPORTED_EXTENSION_GETCHGREPLY_V5�*DRSUAPI_SUPPORTED_EXTENSION_GETCHGREPLY_V6�,DRSUAPI_SUPPORTED_EXTENSION_ADDENTRYREPLY_V3�*DRSUAPI_SUPPORTED_EXTENSION_GETCHGREPLY_V7�)DRSUAPI_SUPPORTED_EXTENSION_VERIFY_OBJECT�DsBindrr3�DRSUAPI_DS_BIND_GUID)�drs�	bind_infor@�handlerrrr gsB
r c
Cs�t��}d|_g}|��}|j|tjdgd�d�}|D]@}t|dd�}d|vr<|dd}t|�t	j
jt	j
jB@r<qd|vrO|dd}t|�t	j
j
@rOq|�|�}	|�t|	��q|��||_t|�|_|S)	z-get a list of attributes for RODC replicationr-zobjectClass=attributeSchema)�lDAPDisplayName�systemFlags�searchFlags)�base�scope�
expression�attrsrbrrcrd)r�DsPartialAttributeSet�version�get_schema_basedn�search�ldb�
SCOPE_SUBTREE�str�int�sambar�DS_FLAG_ATTR_NOT_REPLICATED�DS_FLAG_ATTR_IS_CONSTRUCTED�SEARCH_FLAG_RODC_ATTRIBUTE�get_attid_from_lDAPDisplayName�append�sort�attids�len�
num_attids)
�samdb�partial_attribute_setrx�	schema_dn�res�r�ldap_display_name�system_flags�search_flags�attidrrr�"drs_get_rodc_partial_attribute_set�s4
��

r�cCs|j|_|j|_|j|_dS)z�
    Copies the highwater mark by value, rather than by object reference. (This
    avoids lingering talloc references to old GetNCChanges reply messages).
    N)�tmp_highest_usn�reserved_usn�highest_usn)�hwm�new_hwmrrr�drs_copy_highwater_mark�sr�c@sBeZdZdZdd�Zdd�Zdd�Zdejdd	d
ddfdd
�Z	d	S)�
drs_ReplicatezDRS replication callscCs�t�|||�|_t|j�\|_|_t||d�|_||_t|t	j
�s%td��|t	�
d�kr0td��|j�|j||j|�|_
d|_dS)N)r$r#z"Must supply GUID for invocation_idz$00000000-0000-0000-0000-000000000000zGMust not set GUID 00000000-0000-0000-0000-000000000000 as invocation_idr)rr_r �
drs_handle�supports_extr�netr{�
isinstancerr3�RuntimeError�replicate_init�replication_state�
more_flags)rr'r#r$r{�
invocation_idrrrr�s
zdrs_Replicate.__init__cCs&|j}|dko|t@o|jtj@dkS)Ni�!r)r�rr�r�DRSUAPI_DRS_GET_TGT)r�
error_code�reqr�rrr�_should_retry_with_get_tgt�s��z(drs_Replicate._should_retry_with_get_tgtcCs|jj|j|||||d�dS)�5Processes a single chunk of received replication data)�schema�	req_levelr�N)r��replicate_chunkr��r�level�ctrr�r�r��first_chunkrrr�
process_chunk�s
�zdrs_Replicate.process_chunkFNTrc
Csl|jt@rt��}|
|jB|_d}nd}t��}||_||_t��|_	||j	_
d}
t��}d|_d|_
d|_|s�|jj|tjdgd�}d|dvrb|ddD]}ttj|�}|jj|kra|jj}qOt��}
d|
_d|
_d|
_g}t�|j|j���}|D]}t��}|j|_|j|_|� |�q}||
_!t"|�|
_#||_|
|_$|dur�||_%n,|tj&kr�d|_%n#tj'tj(Btj)Btj*Btj+B|_%|r�|j%tj,O_%n|j%tj-O_%|	r�|j%tj.O_%d|_/d	|_0||_1d|_2d|_3d|_4d|j5_6d|j5_7|�s|�rt8|j�|_3|jt9@�s)d
}t�:�}t;|�D]}|ddk�r%t<||t=||���q|}d}d}d}	|j>�?|j@||�\}}|jAdu�rN|jBdk�rNtCd
|jB��z|�D||||||�Wn.tE�y�}z!|�F|jGd|��r�tHd�|jtjIO_d}WYd}~�q/|�d}~wwd}||jB7}z||jJ7}Wn
tK�y�Ynw|jLdk�r�	||fStM|j|jN��q0)zreplicate a single DN�
�Nr�repsFrom)rerfrhr-i�i�"��_Tz6DsGetNCChanges: NULL first_object with object_count=%uz1Missing target object - retrying with DRS_GET_TGTF)Or�rr�DsGetNCChangesRequest10r��DsGetNCChangesRequest8�destination_dsa_guid�source_dsa_invocation_idr.r1r/�DsReplicaHighWaterMarkr�r�r�r{rlrm�
SCOPE_BASErr�repsFromToBlobr��
highwatermark�DsReplicaCursorCtrExrj�	reserved1�	reserved2r�_dsdb_load_udv_v2�get_default_basedn�DsReplicaCursorrv�cursorsry�count�uptodateness_vector�
replica_flags�DRSUAPI_EXOP_REPL_SECRET�DRSUAPI_DRS_INIT_SYNC�DRSUAPI_DRS_PER_SYNC�DRSUAPI_DRS_GET_ANC�DRSUAPI_DRS_NEVER_SYNCED�$DRSUAPI_DRS_GET_ALL_GROUP_MEMBERSHIP�%DRSUAPI_DRS_SPECIAL_SECRET_PROCESSING�DRSUAPI_DRS_WRIT_REP�DRSUAPI_DRS_SYNC_FORCED�max_object_count�max_ndr_size�extended_op�	fsmo_infor|�partial_attribute_set_ex�mapping_ctr�num_mappings�mappingsr�r�DsGetNCChangesRequest5�dir�setattr�getattrr_�DsGetNCChangesr��first_object�object_countr�r�r	r��args�printr��linked_attributes_count�AttributeError�	more_datar��new_highwatermark)rr/r�r�r��exop�rodcr��	full_sync�sync_forcedr�r�r��udvr�r~�reps_from_packed�
reps_from_obj�
cursors_v1�
cursors_v2�	cursor_v2�	cursor_v1�req5�a�num_objects�	num_linksr�r�r�r+rrr�	replicate�s�

���

��������
���zdrs_Replicate.replicate)
rrrrrr�r�r�DRSUAPI_EXOP_NONEr�rrrrr��s�r�csDeZdZdZ�fdd�Zdd�Zdd�Zdd	�Z�fd
d�Z�Z	S)�drs_ReplicateRenamerz,Uses DRS replication to rename the entire DBcs0tt|��|||||�||_||_tj|_dSr)�superr�r�old_base_dn�new_base_dnrr�r�)rr'r#r$r{r�r�r���	__class__rrrns�zdrs_ReplicateRenamer.__init__cCst�d|j|j|�S)z/Uses string substitution to replace the base DNz%s$)�re�subr�r�)r�dn_strrrr�	rename_dn{szdrs_ReplicateRenamer.rename_dncCsJ|jjD]}|jtkr"t�|j|jj�}|�	�}|�
d�|jjd_
qdS)z3Updates the 'name' attribute for the base DN objectz	utf-16-lerN)�
attribute_ctr�
attributesr�r
rm�Dnr{�
identifierr/�
get_rdn_value�encode�	value_ctr�values�blob)r�base_obj�attr�base_dn�new_namerrr�update_name_attrs
��z%drs_ReplicateRenamer.update_name_attrcCsN|jj}|�|jj�|j_td||jjf�|jj|jkr%|�|�dSdS)z1Renames the first/top-level object in a partitionzRenaming partition %s --> %sN)r�r/r�r�r�r�)r�	first_obj�old_dnrrr�rename_top_level_object�s��z,drs_ReplicateRenamer.rename_top_level_objectcsR|jr|�|jj�|j_|r|jdkr|�|jj�tt|��	||||||�dS)r�rN)
r1r�r/r�rr��objectr�r�r�r�r�rrr��s�z"drs_ReplicateRenamer.process_chunk)
rrrrrr�r�rr��
__classcell__rrr�rr�ks
r�r)�samba.dcerpcrrr�	samba.netr�	samba.ndrrrqrrr	rm�samba.dcerpc.drsuapir
rrr�r!r
r,r;r r�r�rr�r�rrrr�<module>s&

 &&
/