%PDF- %PDF-
Mini Shell

Mini Shell

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

�

�I�dX����dZddlZddlZddlZddlZddlZddlZddlmZmZddl	m
Z
mZddlm
Z
mZddlmZddlmZmZddlmZdd	lmZddlZd
Zd�ZGd�d
e�ZGd�de�ZGd�dej6�ZGd�de�Zy)z(Convenience functions for using the SAM.�N)�dsdb�dsdb_dns)�
ndr_unpack�ndr_pack)�drsblobs�misc)�normalise_int32)�	get_bytes�cmp)�security)�is_ad_dc_built�restructuredTextc��y)N�tdb�r��-/usr/lib/python3/dist-packages/samba/samdb.py�get_default_backend_storer+s��rc��eZdZy)�
SamDBErrorN��__name__�
__module__�__qualname__rrrrr.���rrc��eZdZy)�SamDBNotFoundErrorNrrrrrr1rrrc
���eZdZdZiZiZGd�d�Zdddddejddddf
�fd�	Z	d[�fd�	Z
d�Zd	�Zd
�Z
d�Zd�Zd
�Z		d\d�Zd�Zd�Z			d]d�Zd�Zd�Z			d^d�Zd�Z		d_d�Z									d`d�Z															dad�Z			dbd�Zd�Z	dcd�Zddd�Zd�Z d�Z!e"e!e d� �Z#d!�Z$d"�Z%e"e%e$d#� �Z&d$�Z'	ddd%�Z(d&�Z)d'�Z*d(�Z+d)�Z,d*�Z-d+�Z.d,�Z/d-�Z0d.�Z1d/�Z2d0�Z3d1�Z4d2�Z5d3�Z6d4�Z7d5�Z8ded6�Z9ded7�Z:d8�Z;d9�Z<d:�Z=d;�Z>d<�Z?d=�Z@	ddd>�ZAd?�ZBd@�ZCdA�ZDdB�ZEdC�ZFdD�ZGdE�ZHdF�ZIdG�ZJdH�ZKdI�ZLdJ�ZMdK�ZNdL�ZOdfdM�ZP�fdN�ZQdO�ZRdP�ZSdgdQ�ZTdR�ZUdS�ZVdT�ZW	dgdU�ZXdV�ZYdW�ZZdX�Z[dY�Z\dZ�Z]�xZ^S)h�SamDBzThe SAM database.c��eZdZd�Zd�Zd�Zy)�SamDB._CleanUpOnErrorc� �||_||_y�N)�samdb�dn)�selfr$r%s   r�__init__zSamDB._CleanUpOnError.__init__;s���D�J��D�Grc��yr#r�r&s r�	__enter__zSamDB._CleanUpOnError.__enter__?s��rc�R�|�%|jj|j�y)NF)r$�deleter%)r&�exc_type�exc_val�exc_tbs    r�__exit__zSamDB._CleanUpOnError.__exit__Bs%���#��
�
�!�!�$�'�'�*�rN)rrrr'r*r0rrr�_CleanUpOnErrorr!:s��	�	�
	rr1NTc	����||_|	sd}n|�|�|j�}||_tt|�|||||||��|rt
j|�|
�t
j||
�yy)N)�url�lp�modules_dir�session_info�credentials�flags�options)	r4�	samdb_urlr3�superrr'r�_dsdb_set_global_schema�_dsdb_set_am_rodc)r&r3r4r5r6r7r8r9�
global_schema�auto_connect�am_rodc�	__class__s           �rr'zSamDB.__init__Ns���������C�
�[�R�^��,�,�.�C����
�e�T�#����1=�;�^c�,3�	$�	5���(�(��.����"�"�4��1�rc����|j�:tjj|�s|jj	|�}||_tt|�#|||��y)zconnect to the databaseN)r3r8r9)	r4�os�path�exists�private_pathr3r;r�connect)r&r3r8r9rAs    �rrGz
SamDB.connectdsR����7�7��r�w�w�~�~�c�':��'�'�&�&�s�+�C����
�e�T�"�s�%�+2�	#�	4rc�,�tj|�S)zreturn True if we are an RODC)r�_am_rodcr)s rr@z
SamDB.am_rodcms���}�}�T�"�"rc�,�tj|�S)z%return True if we are an PDC emulator)r�_am_pdcr)s r�am_pdczSamDB.am_pdcqs���|�|�D�!�!rc�4�t|j��S)zreturn the domain DN)�str�get_default_basednr)s r�	domain_dnzSamDB.domain_dnus���4�*�*�,�-�-rc�4�t|j��S)zreturn the schema partition dn)rN�get_schema_basednr)s r�	schema_dnzSamDB.schema_dnys���4�)�)�+�,�,rc�`�tjj}|j||d��y)z|Disables an account

        :param search_filter: LDAP filter to find the user (eg
            samccountname=name)
        T��onN)�sambar�UF_ACCOUNTDISABLE�toggle_userAccountFlags�r&�
search_filterr8s   r�disable_accountzSamDB.disable_account}s(���
�
�,�,���$�$�]�E�d�$�Crc��tjjtjjz}|j	||d��y)z{Enables an account

        :param search_filter: LDAP filter to find the user (eg
            samccountname=name)
        FrUN)rWrrX�UF_PASSWD_NOTREQDrYrZs   r�enable_accountzSamDB.enable_account�s7���
�
�,�,�u�z�z�/K�/K�K���$�$�]�E�e�$�Drc��|j|j�tj|dg��}t	|�dk(rtd|z��t	|�dk(sJ�|dj}t|ddd�}|r|r||zrd|z}	t|	��||z}
n|r||zsd|z}	t|	��||z}
||
k(ryd	|||
fz}|j|�y)
anToggle_userAccountFlags

        :param search_filter: LDAP filter to find the user (eg
            samccountname=name)
        :param flags: samba.dsdb.UF_* flags
        :param on: on=True (default) => set, on=False => unset
        :param strict: strict=False (default) ignore if no action is needed
                 strict=True raises an Exception if...
        �userAccountControl��base�scope�
expression�attrsrz!Unable to find account where '%s'�z Account flag(s) '%s' already setz"Account flag(s) '%s' already unsetNz|
dn: %s
changetype: modify
delete: userAccountControl
userAccountControl: %u
add: userAccountControl
userAccountControl: %u
)	�searchrP�ldb�
SCOPE_SUBTREE�len�	Exceptionr%�int�modify_ldif)r&r[r8�	flags_strrV�strict�res�
account_dn�old_uac�error�new_uac�mods            rrYzSamDB.toggle_userAccountFlags�s���k�k�t�~�~�/�s�7H�7H�%2�;O�:P��R���s�8�q�=�� C�m� S�T�T��3�x�1�}��}���V�Y�Y�
��c�!�f�1�2�1�5�6��
��7�U�?�:�Y�F����&�&���o�G��w���<�y�H����&�&����&�G��g�����7�G�$�%��	
����rc��|j|j�tj|g��}t	|�dk(rtd|z��t	|�dk(sJ�|dj}d|z}|j|�y)z�Forces a password change at next login

        :param search_filter: LDAP filter to find the user (eg
            samccountname=name)
        rbr�Unable to find user "%s"rgz=
dn: %s
changetype: modify
replace: pwdLastSet
pwdLastSet: 0
N)rhrPrirjrkrlr%rn�r&r[rq�user_dnrvs     r�#force_password_change_at_next_loginz)SamDB.force_password_change_at_next_login�s����k�k�t�~�~�/�s�7H�7H�%2�"��>���s�8�q�=�� :�]� J�K�K��3�x�1�}��}��a�&�)�)���
���	
����rc� �|j|j�tj|g��}t	|�dk(rtd|z��t	|�dk7rt
d|z��|dj}d|z}|j|�y)z�Unlock a user account by resetting lockoutTime to 0.
        This does also reset the badPwdCount to 0.

        :param search_filter: LDAP filter to find the user (e.g.
            sAMAccountName=username)
        rbrrxrgzUser "%s" is not uniquez?
dn: %s
changetype: modify
replace: lockoutTime
lockoutTime: 0
N)	rhrPrirjrkrrr%rnrys     r�unlock_accountzSamDB.unlock_account�s����k�k�t�~�~�/� #� 1� 1�%2� "��$���s�8�q�=�$�%?�-�%O�P�P��s�8�q�=��6��F�G�G��a�&�)�)���
���	
����rc
�t�|rd|�d|�d|j���}
n4d|�d|j|j�tj���}
|
|dd�}|�t|�|d<|�||d<|�||d<|�||d	<|�t|�|d
<|	�
||d<|	|d<|�t
|�|d
<|j|�y)a�Adds a new group with additional parameters

        :param groupname: Name of the new group
        :param grouptype: Type of the new group
        :param description: Description of the new group
        :param mailaddress: Email address of the new group
        :param notes: Notes of the new group
        :param gidnumber: GID Number of the new group
        :param nisdomain: NIS Domain Name of the new group
        :param sd: security descriptor of the object
        �CN=�,�group�r%�sAMAccountName�objectClassN�	groupType�description�mail�info�	gidNumber�msSFU30Name�msSFU30NisDomain�nTSecurityDescriptor)rP�get_wellknown_dnrOr�DS_GUID_USERS_CONTAINERr	r�add)r&�	groupname�groupou�	grouptyper��mailaddress�notes�sd�	gidnumber�	nisdomain�group_dn�
ldbmessages            r�newgroupzSamDB.newgroup�s����(1�7�D�N�N�<L�M�H��&/��0E�0E�(,�(?�(?�(A�(,�(D�(D�1F�G�H�%�(1�%,�.�
�� �&5�i�&@�J�{�#��"�(3�J�}�%��"�!,�J�v����!&�J�v��� �&5�i�&@�J�{�#�� �(1�J�}�%�-6�J�)�*�
�>�19�"��J�-�.�����rc���dtj|��dd�d|j��d�}|j�	|j	|j�tj
|g��}t
|�dk(rtd|z��t
|�d	k(sJ�|j|dj�|j�y
#|j��xYw)zLDeletes a group

        :param groupname: Name of the target group
        �(&(sAMAccountName=�)(objectCategory=�#CN=Group,CN=Schema,CN=Configurationr��))rbr�Unable to find group "%s"rgN�ri�
binary_encoderP�transaction_startrhrjrkrlr,r%�transaction_commit�transaction_cancel)r&r��groupfilter�targetgroups    r�deletegroupzSamDB.deletegroup s���IL�HY�HY�Zc�Hd�gL�NR�N\�N\�N^�_����� �	&��+�+�4�>�>�+;�3�CT�CT�1<�B�&�H�K��;��1�$�� ;�i� G�H�H��{�#�q�(�)�(��K�K��A��)�)�*�

�#�#�%��		��#�#�%����A;C�Cc	�R�d}gd�}d|vr|}|D]'}||vs�td|�ddj|��d���d|vr+|d	tj|�tj
fzz
}d
|vr|dtj|�zz
}d|vr:|}|d
dk7rd|z}|dtjtj|�fzz
}d|vr:|}|d
dk7rd|z}|dtjtj|�fzz
}d|vr|dtj|�zz
}d|z}|S)N�)�userr��computer�serviceaccount�contact�allzInvalid group member type "z". Valid types are z, z	 and all.r�z)(&(sAMAccountName=%s)(samAccountType=%d))r�zQ(&(sAMAccountName=%s)(objectClass=group)(!(groupType:1.2.840.113556.1.4.803:=1)))r�����$�%s$zW(&(samAccountType=%d)(!(objectCategory=msDS-ManagedServiceAccount))(sAMAccountName=%s))r�zT(&(samAccountType=%d)(objectCategory=msDS-ManagedServiceAccount)(sAMAccountName=%s))r�z3(&(objectCategory=Person)(!(objectSid=*))(name=%s))z(|%s))rl�joinrir�r�ATYPE_NORMAL_ACCOUNT�ATYPE_WORKSTATION_TRUST)r&�member�member_types�filter�all_member_types�member_type�samaccountnames       r�group_member_filterzSamDB.group_member_filter5s��������L� �+�L�'�	L�K��"2�2��!,�d�i�i�8H�.I�!K�L�L�	L��\�!��B��)�)�&�1�4�3L�3L�M�N�
O�F��l�"��C��(�(��0�1�
2�F���%�#�N��b�z�S� �!&�����.��4�4��)�)�.�9�;�;�
<�F�
�|�+�#�N��b�z�S� �!&�����.��4�4��)�)�.�9�;�;�
<�F�
��$��L��(�(��0�1�
2�F��6�!���
rc�(�|�gd�}dtj|��dd�d|j��d�}|j�	|j	|j�tj
|dg�	�}t
|�d
k(rtd|z��t
|�dk(sJ�d
}dt|d
j�z}	|D�]�}
d}|�|j�}	tj|
�}dt|�z}|�^	tj||
�}
|
j�|
jd�k(r|j!|
�}n|
}|jd�}|��|j#|
|�}|j	|tj
|g�	�}t
|�dkDr1d}|D]}|d|j%d�zz
}�td|
�d|����t
|�dk7rtd|
z��|d
jjd�}|durS|d
j%d��*t'|�|d
dD�cgc]
}t|���c}vrd}|	dt|�zz
}	���|d
us���|d
j%d�����t'|�|d
dvs���d}|	dt|�zz
}	���|dur|j)|	�|j+�y#t$rY���wxYw#t$r}Yd}~���d}~wwxYwcc}w#|j-��xYw)z�Adds or removes group members

        :param groupname: Name of the target group
        :param members: list of group members
        :param add_members_operation: Defines if its an add or remove
            operation
        N)r�r�r�r�r�r�r�r�r�rbrr�rgFz
dn: %s
changetype: modify
z<SID=%s>r�z%s
r%zFound multiple results for "z":
z)Unable to find "%s". Operation cancelled.Tzadd: member
member: %s
zdelete: member
member: %s
)rir�rPr�rhrjrkrlrNr%r�dom_sid�
ValueError�Dn�get_linearized�extended_str�normalize_dn_in_domainr��getr
rnr�r�)r&r��members�add_members_operationr��member_base_dnr�r��modified�addtargettogroupr��targetmember_dn�	membersid�	member_dn�full_member_dn�er��targetmember�targetmemberlist_str�msg�xs                     r�add_remove_group_memberszSamDB.add_remove_group_membersjs�����8�L��
���i�(�*O�QU�Q_�Q_�Qa�c��	
��� �H	&��+�+�4�>�>�+;�3�CT�CT�1<�X�J�&�P�K��;��1�$�� ;�i� G�H�H��{�#�q�(�)�(��H� ��;�q�>���� ��
"�1
��"&��!�)�%)�^�^�%5�N�� (� 0� 0�� 8�I�&0�3�y�>�&A�O�#�*��$'�F�F�4��$8�	�$�3�3�5��9O�9O�PQ�9R�R�-1�-H�-H��-S�N�-6�N�*8�*E�*E�a�*H��#�*�!�5�5�f�l�K�F�#'�;�;�N�58�5F�5F�:@�57�$/�$9�L�
�<�(�1�,�/1�,�#/�K�C�0�F�S�W�W�T�]�4J�J�0�K�'�)/�1E�)G�H�H��<�(�A�-�'�(S�V\�(\�]�]�&2�1�o�&8�&8�&E�&E�a�&H�O�(�D�0�k�!�n�6H�6H��6R�6Z�^g�hw�^x�R]�^_�R`�ai�Rj�Ak�MN�BE�FG�BH�Ak�_k�#�H�$�)�
�?��)��$�+�e�3��Q��9K�9K�H�9U�9a�fo�p�gA�EP�QR�ES�T\�E]�g]�#�H�$�)�
�?��)��$�_1
�f�4��� � �!1�2�
�#�#�%��e"�����&������(Ak��	��#�#�%��su�BK>�#K�>K>�AK"�CK>�:K9�K>�+K>�K>�+K>�	K�K>�K�K>�"	K6�+K>�1K6�6K>�>Lc�F�|�y||vrt|�t||�k(ryt|�dk(r;||vr6tjgtj|�}|j|�ytj|tj|�}|j|�y)aAChanges the MessageElement with the given attr_name of the
        given Message. If the value is "" set an empty value and the flag
        FLAG_MOD_DELETE, otherwise set the new value and FLAG_MOD_REPLACE.
        If the value is None or the Message contains the attr_name with this
        value, nothing will changed.Nr)rNrkri�MessageElement�FLAG_MOD_DELETEr��FLAG_MOD_REPLACE)r&r��old�	attr_name�value�els      r�prepare_attr_replacezSamDB.prepare_attr_replace�s����=������E�
�c�#�i�.�.A� A���u�:��?��C���'�'��C�,?�,?��K���������
�
��s�';�';�Y�
G������rc�>�|�i}|||d�}|j�D]\}}|��	||vs�t||�||<� |dr!|djd�s
|dxxdz
cc<tt	d|j���}	dj
|	�}
|
dk(r|S|
S)z�Prepares new combined fullname, using the name parts.
        Used for things like displayName or cn.
        Use the original name values, if no new one is specified.N)�	givenName�initials�snr��.� r�)�itemsrN�endswith�listr��valuesr�)r&�
given_namer��surname�	old_attrs�fallback_defaultrfr��
attr_value�attrs_values�fullnames           r�fullname_from_nameszSamDB.fullname_from_names�s���
���I�(�%�� ��
&+�[�[�]�	=�!�I�z��!�i�9�&<�#&�y��';�#<��i� �	=����U�:�%6�%?�%?��%D��*���$���F�4�����8�9���8�8�L�)���r�>�#�#��rc�n�|j|||��}|} |�|dk7r|} |rd| �d|�d|j���}!n4d| �d|j|j�tj
���}!t
j||j��j�jdd�}"|�d|"��}#|!||#dd	�}$|r/ttjtjz�|$d
<d}|�||$d<|�||$d
<|dk7r
||$d<||$d<|�d|z|$d<|	�|	|$d<|
�|
|$d<|�||$d<|�||$d<|
�|
|$d<|�||$d<|�||$d<|�||$d<|�||$d<|�||$d<|�||$d<|�||$d<|�t|�|$d<d}%ttd�|||||||f���r�t
j �}%t
j||!�|%_|�1t
j$t|�tj&d �|%d <|�1t
j$t|�tj&d!�|%d!<|�1t
j$t|�tj&d"�|%d"<|�1t
j$t|�tj&d#�|%d#<|�1t
j$t|�tj&d$�|%d$<|�1t
j$t|�tj&d%�|%d%<|��t
j$t|�tj&d&�|%d&<t
j$t|�tj&d'�|%d'<t
j$d(tj&d)�|%d)<|j)�	|j+|$�|j-||!�5|%r|j/|%�|r)|j1d*t
j2|!�z||�ddd�|j5�y#1swY�xYw#|j7��xYw)+alAdds a new user with additional parameters

        :param username: Name of the new user
        :param password: Password for the new user
        :param force_password_change_at_next_login_req: Force password change
        :param useusernameascn: Use username as cn rather that firstname +
            initials + lastname
        :param userou: Object container (without domainDN postfix) for new user
        :param surname: Surname of the new user
        :param givenname: First name of the new user
        :param initials: Initials of the new user
        :param profilepath: Profile path of the new user
        :param scriptpath: Logon script path of the new user
        :param homedrive: Home drive of the new user
        :param homedirectory: Home directory of the new user
        :param jobtitle: Job title of the new user
        :param department: Department of the new user
        :param company: Company of the new user
        :param description: of the new user
        :param mailaddress: Email address of the new user
        :param internetaddress: Home page of the new user
        :param telephonenumber: Phone number of the new user
        :param physicaldeliveryoffice: Office location of the new user
        :param sd: security descriptor of the object
        :param setpassword: optionally disable password reset
        :param uidnumber: RFC2307 Unix numeric UID of the new user
        :param gidnumber: RFC2307 Unix primary GID of the new user
        :param gecos: RFC2307 Unix GECOS field of the new user
        :param loginshell: RFC2307 Unix login shell of the new user
        :param uid: RFC2307 Unix username of the new user
        :param nisdomain: RFC2307 Unix NIS domain of the new user
        :param unixhome: RFC2307 Unix home directory of the new user
        :param smartcard_required: set the UF_SMARTCARD_REQUIRED bit of the new user
        �r�r�r�Nr�rr��/�@r�)r%r��userPrincipalNamer�raFr�r��displayName�name�%s.r��profilePath�
scriptPath�	homeDrive�
homeDirectory�title�
department�companyr�r��wWWHomePage�telephoneNumber�physicalDeliveryOfficeNamer�c�
�|duSr#r)�bs r�<lambda>zSamDB.newuser.<locals>.<lambda>|s
��Q�d�]�r�uid�	uidNumberr��gecos�
loginShell�unixHomeDirectoryr�r�zABCD!efgh12345$67890�unixUserPassword�(distinguishedName=%s))r�rPr�rOrr�rir��
canonical_str�replacerN�UF_NORMAL_ACCOUNT�UF_SMARTCARD_REQUIREDr�any�map�Messager%r�r�r�r�r1�modify�setpasswordr�r�r�)&r&�username�password�'force_password_change_at_next_login_req�useusernameascn�userour��	givennamer��profilepath�
scriptpath�	homedrive�
homedirectory�jobtitler�r�r�r��internetaddress�telephonenumber�physicaldeliveryofficer�r�	uidnumberr�r�
loginshellrr��unixhome�smartcard_required�displayname�cnrz�	dnsdomain�user_principal_namer��ldbmessage2s&                                      r�newuserz
SamDB.newuser�s���Z�.�.�)�8@�7>�/�@�����"�{�b�'8��B��')�6�4�>�>�3C�D�G��%'��(=�(=�(,�(?�(?�(A�(,�(D�(D�)F�G�G��F�F�4����!1�2�@�@�B�J�J�3�PR�S�	�)1�9�=��$�(0�+>�%+�-�
�
�/2�4�3I�3I�37�3M�3M�4N�0O�J�+�,��K���&�J�t��� �&/�J�{�#��"��(3�J�}�%�!,�J�v����%*�X�%5�J�z�"��"�(3�J�}�%��!�'1�J�|�$�� �&/�J�{�#��$�*7�J��'���"*�J�w���!�'1�J�|�$���$+�J�y�!��"�(3�J�}�%��"�!,�J�v���&�(7�J�}�%��&�,;�J�(�)�!�-�7M�J�3�4�
�>�19�"��J�-�.����s�*�S�)�Y��-7��H�-N�O�P��+�+�-�K� �V�V�D�'�2�K�N���%(�%7�%7��C��#�BV�BV�X]�%^��E�"��$�+.�+=�+=�c�)�n�c�Nb�Nb�do�+p��K�(��$�+.�+=�+=�c�)�n�c�Nb�Nb�do�+p��K�(�� �'*�'9�'9�#�e�*�c�FZ�FZ�\c�'d��G�$��%�,/�,>�,>�s�:��PS�Pd�Pd�fr�,s��L�)��#�36�3E�3E���M�3�#7�#7�9L�4N��/�0��$�25�2D�2D��	�N�C�$8�$8�:L�3N��.�/�-0�-?�-?���M�3�#7�#7��.H��M�*�25�2D�2D�*�C�,@�,@�&�3(��.�/�	
��� �	&��H�H�Z� ��%�%�d�G�4�	
N���K�K��,���$�$�&>�&)�&7�&7��&@�'A�%-�%L�N�
	
N�
�#�#�%�	
N�	
N��	��#�#�%��s$�#P!�=?P�<P!�P�P!�!P4c��|j|||��}|�|}|�|dk(rtd��|j�}|r|j|�}d|�d|��}|dd�}|�||d<|�||d	<|�||d
<|�d|z|d<|�||d
<|�||d<|	�|	|d<|
�|
|d<|�||d<|�||d<|
�|
|d<|�||d<|�||d<|j	|�|S)a�Adds a new contact with additional parameters

        :param fullcontactname: Optional full name of the new contact
        :param ou: Object container for new contact
        :param surname: Surname of the new contact
        :param givenname: First name of the new contact
        :param initials: Initials of the new contact
        :param displayname: displayName of the new contact
        :param jobtitle: Job title of the new contact
        :param department: Department of the new contact
        :param company: Company of the new contact
        :param description: Description of the new contact
        :param mailaddress: Email address of the new contact
        :param internetaddress: Home page of the new contact
        :param telephonenumber: Phone number of the new contact
        :param mobilenumber: Primary mobile number of the new contact
        :param physicaldeliveryoffice: Office location of the new contact
        r�r�zNo name for contact specifiedrr�r��r%r�r�r�r�r�r�r�r�r�r�r�r�r�mobiler)r�rlrPr�r�)r&�fullcontactname�our�rr�r'rr�r�r�r�r r!�mobilenumberr"r(�contactcontainer_dn�
contact_dnr�s                    r�
newcontactzSamDB.newcontact�sk��H�
%�
%��/7�.5�&�7���&� �B��"�r�R�x��;�<�<�"�n�n�.��
�"&�"=�"=�b�"A���#%�':�;�
�&�%.��
���&�J�t��� �&/�J�{�#��"�(3�J�}�%���%*�X�%5�J�z�"���"*�J�w���!�'1�J�|�$���$+�J�y�!��"�(3�J�}�%��"�!,�J�v���&�(7�J�}�%��&�,;�J�(�)��#�#/�J�x� �!�-�7M�J�3�4�������	rc�f�tjdd|�}|jd�rtd|z��d|z}|j	|j�tj�}	|r|j|�}	d|�d|	��}
|
|dd	�}|�||d<|r||d<ttjtjz�}|rttj�}||d
<|r#dj||j��|d<|j�	|j|�|rT|j!�}
|j#||
�5|j%dt'j(|
�z|
d�d
d
d
�|j+�y
#1swY�xYw#|j-��xYw)a�Adds a new user with additional parameters

        :param computername: Name of the new computer
        :param computerou: Object container for new computer
        :param description: Description of the new computer
        :param prepare_oldjoin: Preset computer password for oldjoin mechanism
        :param ip_address_list: ip address list for DNS A or AAAA record
        :param service_principal_name_list: string list of servicePincipalName
        z\$$r�r�zIllegal computername "%s"r�rr�r�r�Nr��servicePrincipalNameraz{}.{}�dNSHostNamerF)�re�sub�countrlr�rOr�DS_GUID_COMPUTERS_CONTAINERr�rN�UF_WORKSTATION_TRUST_ACCOUNTrX�format�domain_dns_namer�r��lowerr1rrir�r�r�)r&�computername�
computerour��prepare_oldjoin�ip_address_list�service_principal_name_listr(r��computercontainer_dn�computer_dnr��accountcontrolrs              r�newcomputerzSamDB.newcomputers����V�V�F�B��
-��
�8�8�C�=��7�,�F�G�G�����#�4�4�T�5L�5L�5N�.2�.N�.N� P���#'�#>�#>�z�#J� ��$&�(<�=��'�(6�%/��
�
�"�(3�J�}�%�&�1L�J�-�.��T�>�>�!�3�3�4�5��� ��!B�!B�C�N�+9�
�'�(��(/����D�(�(�*�),�J�}�%�	
��� �
	&��H�H�Z� ���8�8�:���)�)�$��<�6��$�$�&>�&)�&7�&7��&D�'E�%-�u�6�6�
�#�#�%�6�6��	��#�#�%��s$�5F�*F�8F�F�F�F0c���dtj|��dd�d|j��d�}|j�	|j	|j�tj
|g��}t
|�dk(rtd|z��t
|�d	k(sJ�|j|dj�|j�y
#|j��xYw)zIDeletes a user

        :param username: Name of the target user
        r�r�z$CN=Person,CN=Schema,CN=Configurationr�r�rbrrxrgNr�)r&rr��targets    r�
deleteuserzSamDB.deleteuserNs���DG�CT�CT�U]�C^�aG�IM�IW�IW�IY�Z����� �	&��[�[�d�n�n�&6�c�>O�>O�,2�"�!�>�F��6�{�a��� :�X� E�F�F��v�;�!�#�$�#��K�K��q�	���%�

�#�#�%��		��#�#�%��r�c���|j�	|j|j�tj|g��}t|�dk(rt
d|xs|z��t|�dkDrt
dt|�|fz��|dj}t|t�s|jd�}n|}d|zdzjd�}d	|�d
tj|�jd��d�}|j|�|r |jdt|�zd
z�|j!|�|j#�y#|j%��xYw)z�Sets the password for a user

        :param search_filter: LDAP filter to find the user (eg
            samccountname=name)
        :param password: Password for the user
        :param force_change_at_next_login: Force password change
        rbrrxrgz*Matched %u multiple users with filter "%s"�utf-8�"z	utf-16-lez
dn: z5
changetype: modify
replace: unicodePwd
unicodePwd:: �
z(distinguishedName=�)N)r�rhrPrirjrkrlr%�
isinstancerN�decode�encode�base64�	b64encodernr{r_r�r�)	r&r[r�force_change_at_next_loginrrqrz�pw�setpws	         rrzSamDB.setpasswordcsV��	
��� � 	&��+�+�4�>�>�#3�3�;L�;L�)6�b��B�C��3�x�1�}�� :�h�>W�-� X�Y�Y��3�x�!�|�� L�PS�TW�PX�Zg�Oh� h�i�i��!�f�i�i�G��h��,��_�_�W�-������(�S�.�(�(��5�B��� � ��$�+�+�G�4�6�E�
���U�#�)��8�8�)�C��L�8�3�>�@�
���
�.�

�#�#�%��		��#�#�%��s�D1E�E'c�,�|j�	|j|j�tj|ddg��}t|�dk(rt
d|z��t|�dk(sJ�|dj}t|ddd�}|r|dz}d}n8|dz}tj|ttj��z�}d	|||fz}|j|�|j�y
#|j��xYw)aSets the account expiry for a user

        :param search_filter: LDAP filter to find the user (eg
            samaccountname=name)
        :param expiry_seconds: expiry time from now in seconds
        :param no_expiry_req: if set, then don't expire password
        ra�accountExpiresrbrrxrgii����zy
dn: %s
changetype: modify
replace: userAccountControl
userAccountControl: %u
replace: accountExpires
accountExpires: %u
N)r�rhrPrirjrkrlr%rmrW�unix2nttime�timernr�r�)	r&r[�expiry_seconds�
no_expiry_reqrqrzrar[�setexps	         r�	setexpiryzSamDB.setexpiry�s&��	
��� �	&��+�+�4�>�>�#3�3�;L�;L�)6�%9�;K�$L��N�C��3�x�1�}�� :�]� J�K�K��s�8�q�=�!�=��!�f�i�i�G�!$�S��V�,@�%A�!�%D�!E���%7�'�%A�"�!"��%7�(�%B�"�!&�!2�!2�>�C��	�	��DT�3T�!U����"�N�3�4�F�
���V�$�

�#�#�%��		��#�#�%��s�CD�Dc�0�tj||�y)z`Change the domain SID used by this LDB.

        :param sid: The new domain sid to use.
        N)r�_samdb_set_domain_sid)r&�sids  r�set_domain_sidzSamDB.set_domain_sid�s��
	
�"�"�4��-rc�,�tj|�S)z&Read the domain SID used by this LDB. )r�_samdb_get_domain_sidr)s r�get_domain_sidzSamDB.get_domain_sid�s���)�)�$�/�/rzSID for the domain)�docc�0�tj||�y)zoSet the invocation id for this SamDB handle.

        :param invocation_id: GUID of the invocation id.
        N)r�_dsdb_set_ntds_invocation_id)r&�
invocation_ids  r�set_invocation_idzSamDB.set_invocation_id�s��
	
�)�)�$�
�>rc�,�tj|�S)zGet the invocation_id id)r�_samdb_ntds_invocation_idr)s r�get_invocation_idzSamDB.get_invocation_id�s���-�-�d�3�3rzInvocation ID GUIDc�.�tj||�Sr#)r�_dsdb_get_oid_from_attid�r&�attids  r�get_oid_from_attidzSamDB.get_oid_from_attid�s���,�,�T�5�9�9rc�0�tj|||�S)zNreturn the attribute ID for a LDAP attribute as an integer as found in DRSUAPI)r�$_dsdb_get_attid_from_lDAPDisplayName)r&�ldap_display_name�is_schema_ncs   r�get_attid_from_lDAPDisplayNamez$SamDB.get_attid_from_lDAPDisplayName�s ���8�8��9J�L�Z�	Zrc�.�tj||�S)z6return the syntax OID for a LDAP attribute as a string)r�)_dsdb_get_syntax_oid_from_lDAPDisplayName�r&rxs  r�#get_syntax_oid_from_lDAPDisplayNamez)SamDB.get_syntax_oid_from_lDAPDisplayName�s���=�=�d�DU�V�Vrc�.�tj||�S)z8return the systemFlags for a LDAP attribute as a integer)r�*_dsdb_get_systemFlags_from_lDAPDisplayNamer}s  r�$get_systemFlags_from_lDAPDisplayNamez*SamDB.get_systemFlags_from_lDAPDisplayName�s���>�>�t�EV�W�Wrc�.�tj||�S)z3return the linkID for a LDAP attribute as a integer)r�%_dsdb_get_linkId_from_lDAPDisplayNamer}s  r�get_linkId_from_lDAPDisplayNamez%SamDB.get_linkId_from_lDAPDisplayName�s���9�9�$�@Q�R�Rrc�.�tj||�S)z;return the lDAPDisplayName from an integer DRS attribute ID)r�"_dsdb_get_lDAPDisplayName_by_attidrss  r�get_lDAPDisplayName_by_attidz"SamDB.get_lDAPDisplayName_by_attid�s���6�6�t�U�C�Crc�.�tj||�S)z�return the attribute name of the corresponding backlink from the name
        of a forward link attribute. If there is no backlink return None)r�'_dsdb_get_backlink_from_lDAPDisplayNamer}s  r�!get_backlink_from_lDAPDisplayNamez'SamDB.get_backlink_from_lDAPDisplayName�s���;�;�D�BS�T�Trc�0�tj||�y)z�Set the NTDS Settings DN, as would be returned on the dsServiceName
        rootDSE attribute.

        This allows the DN to be set before the database fully exists

        :param ntds_settings_dn: The new DN to use
        N)r�_samdb_set_ntds_settings_dn)r&�ntds_settings_dns  r�set_ntds_settings_dnzSamDB.set_ntds_settings_dn�s��	
�(�(��/?�@rc�,�tj|�S)zGet the NTDS objectGUID)r�_samdb_ntds_objectGUIDr)s r�
get_ntds_GUIDzSamDB.get_ntds_GUID�s���*�*�4�0�0rc�p�|jdtjdg��}t|ddd�S)z/Get the current time as generalized time stringr��currentTime�rcrdrfr�rhri�
SCOPE_BASErN�r&rqs  r�get_timestrzSamDB.get_timestrs>���k�k�r� #���!.���1���3�q�6�-�(��+�,�,rc�H�tj|j��S)z!Get the current time as UNIX time)ri�string_to_timer�r)s r�get_timezSamDB.get_times���!�!�$�"2�"2�"4�5�5rc�H�tj|j��S)zGet the current time as NT time)rWr\r�r)s r�
get_nttimezSamDB.get_nttimes��� � �����1�1rc�,�tj|�S)zGet the server site name)r�_samdb_server_site_namer)s r�server_site_namezSamDB.server_site_names���+�+�D�1�1rc�p�|jdtjdg��}t|ddd�S)z return the DNS name of this hostr�r8r�rr�r�s  r�
host_dns_namezSamDB.host_dns_names5���k�k�r����
��k�O���3�q�6�-�(��+�,�,rc�f�|j�}|j�jd�dS)z&return the DNS name of the domain rootr�r)rOr�split)r&rPs  rr?zSamDB.domain_dns_names/���+�+�-�	��&�&�(�.�.�s�3�A�6�6rc��|j�}|j�}d|�d|�d�}|j�}|j|tj
|��}	|dddj
�}|S#t$rYywxYw)z*return the NetBIOS name of the domain rootz/(&(objectClass=crossRef)(nETBIOSName=*)(ncName=z
)(dnsroot=r�)rdrer�nETBIOSNameN)rOr?�get_partitions_dnrhri�SCOPE_ONELEVELrS�
IndexError)r&rP�dns_namer��
partitions_dnrq�netbios_domains       r�domain_netbios_namezSamDB.domain_netbios_names����+�+�-�	��'�'�)��V_�ai�j���.�.�0�
��k�k�-� #� 2� 2�%+��-��	� ��V�M�2�1�5�<�<�>�N�����	��	�s�A8�8	B�Bc�f�|j�}|j�jd�dS)z&return the DNS name of the forest rootr�r)�get_root_basednrr�)r&�	forest_dns  r�forest_dns_namezSamDB.forest_dns_name-s/���(�(�*�	��&�&�(�.�.�s�3�A�6�6rc�.�tj||�Sr#)r�_dsdb_load_partition_usn)r&�base_dns  r�load_partition_usnzSamDB.load_partition_usn2s���,�,�T�7�;�;rc�>�|j|j|��y)N)�write_indices_and_attributes)�set_schema_from_ldbri)r&�schemar�s   r�
set_schemazSamDB.set_schema5s��� � ����Jf� �grc�2�tj|||�yr#)r�_dsdb_set_schema_from_ldb)r&�ldb_connr�s   rr�zSamDB.set_schema_from_ldb8s���&�&�t�X�7S�Trc�*�d}|j|�y)Nz@
dn:
changetype: modify
add: schemaUpdateNow
schemaUpdateNow: 1
)rn)r&�ldifs  r�set_schema_update_nowzSamDB.set_schema_update_now;s����	
����rc�0�tj|||�S)zBconvert a list of attribute values to a DRSUAPI DsReplicaAttribute)r�_dsdb_DsReplicaAttribute�r&rirx�
ldif_elementss    r�dsdb_DsReplicaAttributezSamDB.dsdb_DsReplicaAttributeDs���,�,�S�2C�]�S�Src�0�tj|||�S)z$normalise a list of attribute values)r�_dsdb_normalise_attributesr�s    r�dsdb_normalise_attributeszSamDB.dsdb_normalise_attributesHs���.�.�s�4E�}�U�Urc���t|jj��dk(r|j�|j	|�|jvr|j|j	|�Sy)z� Get from an attid the associated attribute

        :param attid: The attribute id for searched attribute
        :return: The name of the attribute associated with this id
        rN)rk�
hash_oid_name�keys�_populate_oid_attidrurss  r�get_attribute_from_attidzSamDB.get_attribute_from_attidLsd���t�!�!�&�&�(�)�Q�.��$�$�&��"�"�5�)�T�-?�-?�?��%�%�d�&=�&=�e�&D�E�E�rc���i|_|jddgddg��}t|�dkDrI|D]C}t|j	d��}||jt|j	d��<�Eyy)z�Populate the hash hash_oid_name.

        This hash contains the oid of the attribute as a key and
        its display name as a value
        zobjectClass=attributeSchema�search_options:1:2�attributeID�lDAPDisplayName)re�controlsrfrN)r�rhrkrNr�)r&rqr��
strDisplays    rr�zSamDB._populate_oid_attidYs��� ����k�k�%B�$8�#9�!.�!2�!4��5���s�8�a�<��
K�� ����'8�!9�:�
�@J��"�"�3�q�u�u�]�';�#<�=�
K�rc�*�|jd|ztjdgdg��}t|�dk(ryt	t
j|ddd�}|j}t|jj��dk(r|j�|jD]h}|j|j�}||jvs�-|j�|j|j�k(s�\|jcSy)a[Get the version field trom the replPropertyMetaData for
        the given field

        :param dn: The on which we want to get the version
        :param att: The name of the attribute
        :return: The value of the version field in the replPropertyMetaData
            for the given attribute. None if the attribute is not replicated
        �distinguishedName=%sr��replPropertyMetaData�rerdr�rfrN)rhrirjrkrr�replPropertyMetaDataBlob�ctrr�r�r��arrayrurtr@�version)r&r%�attrq�replr��o�att_oids        r�"get_attribute_replmetadata_versionz(SamDB.get_attribute_replmetadata_versionis����k�k�%;�b�%@� #� 1� 1�$8�#9�!7� 8��:���s�8�q�=���(�;�;��a�&�!7�8��;�=���h�h���t�!�!�&�&�(�)�Q�.��$�$�&����	!�A��-�-�a�g�g�6�G��$�,�,�,��y�y�{�d�0�0��9�?�?�A�A��y�y� �	!�rc��|jd|ztjdgdg��}t|�dk(ryt	t
j|ddd�}|j}tjttj���}d}	t|jj��dk(r|j�|jD]�}
|j!|
j"�}||jvs�-|j%�|j|j%�k(s�\d}	|j'tj(�}||
_||
_t/j0|j3��|
_||
_||
_��|	s�|r�t|j�dkDr�tj:�}
d|
_|j!|
j"�}|j'tj(�}||
_||
_t/j0|j3��|
_||
_||
_d}	|j}|j=|
�|j>d	z|_||_|	rotA|�}tjB�}|djD|_"tjF|tjHd�|d<|jK|d
g�yy)Nr�r�r�r�rFTiZ	rgz#local_oid:1.3.6.1.4.1.7165.4.3.14:0)&rhrirjrkrrr�r�rWr\rmr]r�r�r�r�rurtr@�sequence_number�SEQ_NEXTr��originating_change_timer�GUIDrp�originating_invocation_id�originating_usn�	local_usn�replPropertyMetaData1�appendr;rrr%r�r�r)r&r%r�r��
addifnotexistrqr�r��now�foundr�r��seq�o2�tab�replBlobr�s                 r�"set_attribute_replmetadata_versionz(SamDB.set_attribute_replmetadata_version�s���k�k�%;�b�%@� #� 1� 1�$8�#9�!7� 8��:���s�8�q�=���(�;�;��a�&�!7�8��;�=���h�h������D�I�I�K� 0�1�����t�!�!�&�&�(�)�Q�.��$�$�&����	"�A��-�-�a�g�g�6�G��$�,�,�,��y�y�{�d�0�0��9�?�?�A�A����*�*�3�<�<�8��!��	�,/��)�.2�i�i��8N�8N�8P�.Q��+�$'��!�!���	"���3�s�y�y�>�A�+=��/�/�1�B��B�H��-�-�b�h�h�7�G��&�&�s�|�|�4�C��B�J�),�B�&�+/�9�9�T�5K�5K�5M�+N�B�(�!$�B���B�L��E��)�)�C��J�J�r�N��	�	�A�
�C�I��C�I����~�H��+�+�-�C���V�Y�Y�C�F��"�"�8�#&�#7�#7�#9�;�
�&�'�
�K�K��C�D�E�rc�.�tj|�yr#)r�'_dsdb_write_prefixes_from_schema_to_ldbr)s r�write_prefixes_from_schemaz SamDB.write_prefixes_from_schema�s���4�4�T�:rc�,�tj|�Sr#)r�_dsdb_get_partitions_dnr)s rr�zSamDB.get_partitions_dn�s���+�+�D�1�1rc�.�tj||�Sr#)r�_dsdb_get_nc_root)r&r%s  r�get_nc_rootzSamDB.get_nc_root�s���%�%�d�B�/�/rc� �|jjt|��}d}|�|j|�}|�Rtj|||�}|�|S|�0i|jt|�<|jt|�}|||<|Sr#)�hash_well_knownr�rNr�_dsdb_get_wellknown_dn)r&�nc_root�wkguid�h_ncr%s     rr�zSamDB.get_wellknown_dn�s����#�#�'�'��G��5��
�������&�!�B�
�:��,�,�T�7�F�C�B��z��	��|�57��$�$�S��\�2��+�+�C��L�9���D��L��	rc�D�t|t�st|�jd�}t	j
�}t	j||j��|_t	j|tjd�|d<|j|�y)N�utf8�	minPwdAge�rR�bytesrNrTrirr�rPr%r�r�r�r&r��ms   r�
set_minPwdAgezSamDB.set_minPwdAge��m���%��'���J�%�%�f�-�E��K�K�M���v�v�d�D�N�N�,�-����+�+�E�3�3G�3G��U��+�����A�rc��|j|j�tjdg��}t	|�dk(ryd|dvryt|ddd�S)Nr�rdrfr�rhrPrir�rkrmr�s  r�
get_minPwdAgezSamDB.get_minPwdAge��Y���k�k�$�.�.�*�#�.�.��
�k�V���s�8�q�=��
��A��
&���s�1�v�k�*�1�-�.�.rc�D�t|t�st|�jd�}t	j
�}t	j||j��|_t	j|tjd�|d<|j|�y)Nr�	maxPwdAgerrs   r�
set_maxPwdAgezSamDB.set_maxPwdAge�r	rc��|j|j�tjdg��}t	|�dk(ryd|dvryt|ddd�S)Nrrrrr�s  r�
get_maxPwdAgezSamDB.get_maxPwdAge�rrc�D�t|t�st|�jd�}t	j
�}t	j||j��|_t	j|tjd�|d<|j|�y)Nr�minPwdLengthrrs   r�set_minPwdLengthzSamDB.set_minPwdLength�sn���%��'���J�%�%�f�-�E��K�K�M���v�v�d�D�N�N�,�-����.�.�u�c�6J�6J�N�[��.�����A�rc��|j|j�tjdg��}t	|�dk(ryd|dvryt|ddd�S)Nrrrrr�s  r�get_minPwdLengthzSamDB.get_minPwdLengthsZ���k�k�$�.�.�*�#�.�.��HX�k�Y���s�8�q�=��
�3�q�6�
)���s�1�v�n�-�a�0�1�1rc�D�t|t�st|�jd�}t	j
�}t	j||j��|_t	j|tjd�|d<|j|�y)Nr�
pwdPropertiesrrs   r�set_pwdPropertieszSamDB.set_pwdProperties	sn���%��'���J�%�%�f�-�E��K�K�M���v�v�d�D�N�N�,�-��� �/�/��s�7K�7K�_�]��/�����A�rc��|j|j�tjdg��}t	|�dk(ryd|dvryt|ddd�S)Nrrrrr�s  r�get_pwdPropertieszSamDB.get_pwdPropertiessZ���k�k�$�.�.�*�#�.�.��HY�k�Z���s�8�q�=��
�C��F�
*���s�1�v�o�.�q�1�2�2rc�h�tj�}tj|d|j�j	�z�|_|�)tj|tjd�|d<n(tjgtjd�|d<|j|�y)N�1CN=Directory Service,CN=Windows NT,CN=Services,%s�dSHeuristics)
rirr��get_config_basednr�r%r�r�r�r)r&�dsheuristicsrs   r�set_dsheuristicszSamDB.set_dsheuristicss����K�K�M���v�v�d�O��.�.�0�?�?�A�B�C����#��"�"�<�#&�#7�#7�#1�3�
�n���"�"�2�s�':�':�#1�3�
�n��	
���A�rc���|jd|j�j�ztjdg��}t|�dk(rd}|Sd|dvr
|ddd}|Sd}|S)Nrr rr)rhr!r�rir�rk)r&rqr"s   r�get_dsheuristicszSamDB.get_dsheuristics)s����k�k�M� �2�2�4�C�C�E�F� #���~�6F��H���s�8�q�=��L����s�1�v�
%��q�6�.�1�!�4�L��� �L��rc�l�|dd�}|r||d<|r||d<|rt|�|d<|j|�y)aCreates an organizationalUnit object
        :param ou_dn: dn of the new object
        :param description: description attribute
        :param name: name attribute
        :param sd: security descriptor of the object, can be
        an SDDL string or security.descriptor type
        �organizationalUnitr.r�r�r�N)rr�)r&�ou_dnr�r�r�rs      r�	create_ouzSamDB.create_ou6sI���0�
2���*�A�m����A�f�I�
�(0���A�$�%�����rc���|j�	tt|�|�}|j	�|S#|j��xYw)z�Returns the value of the sequence number according to the requested type
        :param seq_type: type of sequence number
         )r�r;rr�r�r�)r&�seq_typer�rAs   �rr�zSamDB.sequence_numberJsP���	
��� �	&���t�4�X�>�C�

�#�#�%��
��	��#�#�%��s	�8�Ac�p�|jdtjdg��}t|ddd�S)z get the NTDS DN from the rootDSEr��
dsServiceNamer�rr�r�s  r�get_dsServiceNamezSamDB.get_dsServiceNameXs6���k�k�r�����?P�k�Q���3�q�6�/�*�1�-�.�.rc�p�|jdtjdg��}t|ddd�S)z"get the server DN from the rootDSEr��
serverNamer�rr�r�s  r�get_serverNamezSamDB.get_serverName]s5���k�k�r�����~�k�N���3�q�6�,�'��*�+�+rc�b�|�tj||�Stj|||��S)zDDo a DNS lookup in the database, returns the NDR database structures)�
dns_partition)r�lookup)r&r�r3s   r�
dns_lookupzSamDB.dns_lookupbs3��� ��?�?�4��2�2��?�?�4��1>�@�
@rc�.�tj||�S)z;Return the NDR database structures from a dnsRecord element)r�extract)r&r�s  r�dns_extractzSamDB.dns_extractjs������b�)�)rc�0�tj|||�S)zfDo a DNS modification on the database, sets the NDR database
        structures on a DNS name
        )rr
)r&r��new_recordss   r�dns_replacezSamDB.dns_replacens������h��<�<rc�0�tj|||�S)z�Do a DNS modification on the database, sets the NDR database
        structures on a LDB DN

        This routine is important because if the last record on the DN
        is removed, this routine will put a tombstone in the record.
        )r�
replace_by_dn)r&r%r:s   r�dns_replace_by_dnzSamDB.dns_replace_by_dnts���%�%�d�B��<�<rc��t�std��|�tj|||�Stj||||�S)z�garbage_collect_tombstones(lp, samdb, [dn], current_time, tombstone_lifetime)
        -> (num_objects_expunged, num_links_expunged)z6Cannot garbage collect tombstones: AD DC was not built)r
rr� _dsdb_garbage_collect_tombstones)r&r%�current_time�tombstone_lifetimes    r�garbage_collect_tombstonesz SamDB.garbage_collect_tombstones}sa��
���&�'�
'��%��8�8��r�9E�G�
G��8�8��r�9E�9K�M�
Mrc�,�tj|�S)zcreate a RID set for this DSA)r�_dsdb_create_own_rid_setr)s r�create_own_rid_setzSamDB.create_own_rid_set�s���,�,�T�2�2rc�,�tj|�S)z.return a new RID from the RID Pool on this DSA)r�_dsdb_allocate_ridr)s r�allocate_ridzSamDB.allocate_rid�s���&�&�t�,�,rc�,�|j�\}}|S)aEreturn the next free RID from the RID Pool on this DSA.

        :note: This function is not intended for general use, and care must be
            taken if it is used to generate objectSIDs. The returned RID is not
            formally reserved for use, creating the possibility of duplicate
            objectSIDs.
        )�free_rid_bounds)r&�rid�_s   r�
next_free_ridzSamDB.next_free_rid�s���%�%�'���Q��
rc�*�tj||j��}|j|tjdg��}	|dd}tj||djd��}|j|tjdg��}	|dd}tj||djd��}|j|tjgd	���}d
}d}	t|ddd�}	|	|k(r'tjtjd
|z��	t|ddd�}
	t|ddd�}|
|k(s||k(r|	}
|
|z}n|dz
}|
|z}|
dz	}
||
kDr7|	|
k(r$tjtjd��|	}
|
|z}|
dz	}
|}||ks||
kDr*tjtjd|||
fz��||
fS#t
$r)tjtjd|z�d�wxYw#t
$r)tjtjd|z�d�wxYw#t
$r|}	Y��cwxYw#t
$r|}
Y��4wxYw#t
$r|}Y��1wxYw)a�return the low and high bounds (inclusive) of RIDs that are
            available for use in this DSA's current RID pool.

        :note: This function is not intended for general use, and care must be
            taken if it is used to generate objectSIDs. The returned range of
            RIDs is not formally reserved for use, creating the possibility of
            duplicate objectSIDs.
        �serverReferencer�rzUNo RID Set DN - Cannot find attribute serverReference of %s to calculate reference dnNrN�rIDSetReferenceszVNo RID Set DN - Cannot find attribute rIDSetReferences of %s to calculate reference dn)�rIDAllocationPool�rIDPreviousAllocationPool�
rIDNextRIDl��l����rRzBad RID Set %srSrTrg� zRID pools out of RIDsz"Bad RID chosen %d from range %d-%d)rir�r1rhr��KeyError�LdbError�ERR_NO_SUCH_ATTRIBUTErSrm�ERR_OPERATIONS_ERROR)r&�server_name_dnrq�
server_ref�
server_ref_dn�rid_set_refs�
rid_set_dn�
uint32_max�
uint64_max�
alloc_pool�	prev_pool�next_rid�prev_pool_lo�prev_pool_his              rrKzSamDB.free_rid_bounds�s������d�&9�&9�&;�<���k�k�~� #���!2� 3��5��	H��Q�� 1�2�J����t�Z��]�%9�%9�'�%B�C�
��k�k�}� #���!3� 4��6��	G��q�6�"4�5�L��V�V�D�,�q�/�"8�"8��"A�B�
��k�k�z� #���!/��0���
��
�	$��S��V�$7�8��;�<�J���#��,�,�s�7�7�/�*�<�>�
>�	#��C��F�#>�?��B�C�I�	"��3�q�6�,�/��2�3�H�
�
�"�h�*�&<�"�I� �:�-�H���M�H�!�:�-�� �B����l�"��Y�&��l�l�3�#;�#;�#:�<�<�#�I�$�z�1�L�$��?�L�#�H��l�"�h��&=��,�,�s�7�7�C� (�,��E� F�G�
G���%�%��Y�	H��,�,��)�)�,�.<�=�>�DH�	
H�	H���	G��,�,��)�)�,�.;�<�=�CG�	
G�	G��(�	$�#�J�	$���	#�"�I�	#���	"�!�H�	"�sN�	G5�H*�6I�7I1�J�52H'�*2I�I.�-I.�1J�?J�J�Jc��tj||j��}t|tj�rt	|�}tj||�}|j|�s|j
|�|S)z�return a new DN expanded by adding the domain DN

        If the dn is already a child of the domain DN, just
        return it as-is.

        :param dn: relative dn
        )rir�rPrRrN�is_child_of�add_base)r&r%rP�full_dns    rr�zSamDB.normalize_dn_in_domain�sc���F�F�4����!1�2�	��b�#�&�&�!��R��B��&�&��r�"���"�"�9�-����Y�'��r)NrN)NTF)NNNNNNNN)TNN)NNNNr�)FFNNNNNNNNNNNNNNNNNTNNNNNNNF)NNNNNNNNNNNNNNN)NNFNN)FN)F)T)NNNr#)_rrr�__doc__r�r�r1ri�FLG_DONT_CREATE_DBr'rGr@rLrPrSr\r_rYr{r}r�r�r�r�r�r�r,r5rIrLrrarerh�property�
domain_sidrmrprlrurzr~r�r�r�r�r�r�r�r�r�r�r�r?r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rr
rrrrrrr#r%r)r�r.r1r5r8r;r>rCrFrIrNrKr��
__classcell__)rAs@rrr4s������M��O���( �D�d��!��)?�)?��T�"�D�2�,4�#�"�.�-�D�E�GK�05�+�Z�*�2;?�DH�+/�2�h&�*3�l8<�.2�04�Z&�x�.KO�=?��D9>�LP�LP�LP�DH�FJ�HL�DH�#(�j&�Z$(���!� �#� �"��#�#�#'�#'� $�*.�d�LFJ�;?�04�<&�|&�,@D�*&�X(&�T.�0��.�.�2�4�J�?�4��.�0A�!5�7�M�:�5:�Z�W�X�S�D�U�
A�1�-�6�2�2�-�
7�

�7�
<�h�U��T�V��K� �>:?�5F�n;�2�0�
��/��/��2��3�
���(�/�
,�
@�*�=�=�7;�M�"3�-�	�\&�|rrc�T�eZdZdZdd�Zd�Zd�Zd�Zd�Zd�Z	d	�Z
d
�Zd�Zd�Z
d
�Zy)�dsdb_Dnza class for binary DNNc�r�|�T|jd�rtj}n2|jd�rtj}ntj}|tjtjfvr�|jd�}t
|�dkrtd|z��dt
|d�zt|d�z}|d||_	|jd	t
|d�zd
|_
||d|_n||_d|_	d|_
tj||j�|_y)zcreate a dsdb_DnNzB:zS:�:�z
Invalid DN %srgr�r�r�)�
startswithr�DSDB_SYNTAX_BINARY_DN�DSDB_SYNTAX_STRING_DN�DSDB_SYNTAX_OR_NAMEr�rk�RuntimeErrorrm�prefix�binary�dnstringrir�r%)r&r$r|�
syntax_oid�colons�
prefix_lens      rr'zdsdb_Dn.__init__s�����"�"�4�(�!�7�7�
��$�$�T�*�!�7�7�
�!�5�5�
��$�4�4�d�6P�6P�Q�Q��^�^�C�(�F��6�{�Q��"�?�X�#=�>�>��S����^�+�c�&��)�n�<�J�"�1�Z�0�D�K��+�+�a�#�f�Q�i�.�&8��<�D�K�$�Z�[�1�D�M�$�D�M��D�K��D�K��&�&���
�
�.��rc�f�|jt|jjd���zS)Nrg)�mode)rzrNr%r�r)s r�__str__zdsdb_Dn.__str__-s(���{�{�S����!5�!5�1�!5�!=�>�>�>rc���|}|}|jjd�}|jjd�}t||�}|dk7r|St|j|j�}|S)z6 compare dsdb_Dn values similar to parsed_dn_compare()r�r)r%�get_extended_componentrr{)r&�other�dn1�dn2�guid1�guid2�vs       r�__cmp__zdsdb_Dn.__cmp__0se���������-�-�f�5�����-�-�f�5����u�����6��H���
�
�C�J�J�'���rc�*�|j|�dk(S�Nr�r��r&r�s  r�__eq__zdsdb_Dn.__eq__>����|�|�E�"�a�'�'rc�*�|j|�dk7Sr�r�r�s  r�__ne__zdsdb_Dn.__ne__Ar�rc�*�|j|�dkSr�r�r�s  r�__lt__zdsdb_Dn.__lt__D����|�|�E�"�Q�&�&rc�*�|j|�dkSr�r�r�s  r�__le__zdsdb_Dn.__le__Gr�rc�*�|j|�dkDSr�r�r�s  r�__gt__zdsdb_Dn.__gt__Jr�rc�*�|j|�dk\Sr�r�r�s  r�__ge__zdsdb_Dn.__ge__Mr�rc�N�|jdk(ryt|jd�S)z6return binary part of a dsdb_Dn as an integer, or Noner�N�)rzrmr{r)s r�get_binary_integerzdsdb_Dn.get_binary_integerPs"���;�;�"����4�;�;��#�#rc�@�tj|j�S)zreturn binary as a byte string)�binascii�	unhexlifyr{r)s rr
zdsdb_Dn.get_bytesVs���!�!�$�+�+�.�.rr#)rrrrjr'r�r�r�r�r�r�r�r�r�r
rrrrprps<���/�2?��(�(�'�(�'�(�$�/rrp)rjrWrir]rUrCr9rr�	samba.ndrrr�samba.dcerpcrr�samba.commonr	r
rrr
r��
__docformat__rrlrr�Ldbr�objectrprrr�<module>r�sw��./��
��
�	�	� �*�'�(�'�!� ��"�
��	��	�	��	�[�E�I�I�[�z.G/�f�G/r

Zerion Mini Shell 1.0