File: //lib/python3/dist-packages/samba/netcmd/__pycache__/domain_backup.cpython-310.pyc
o
��9a�� � @ s� d dl Z d dlZd dlZd dlZd dlZd dlZd dlZd dlZd dlZd dl m
Z d dlm
Z
mZ d dlZd dlmZ d dlmZ d dlmZ d dlmZmZmZ d dlmZ d dlmZmZmZ d d l m!Z! d d
l"m#Z#m$Z$ d dl%m&Z&m'Z'm(Z( d dlm)Z) d
dl*m+Z+ d dl,m-Z-m.Z. d dl/m0Z0 d dl1m2Z2 d dl,m3Z3 d dl4m5Z5 d dl6Z6d dl,m7Z7m8Z8m9Z9 d dl:m;Z;m<Z<m=Z= d dl>m?Z? d dl@mAZA d dlBZBd dlCmDZD d dlmEZE d dlFmGZG d dlHmIZI d dlJmKZK dd� ZLdd � ZMd!d"� ZNd#d$� ZOd%d&� ZP d9d'd(�ZQd)d*� ZRd+d,� ZSd-d.� ZTG d/d0� d0ejUjV�ZWG d1d2� d2e+�ZXG d3d4� d4ejUjV�ZYG d5d6� d6ejUjV�ZZG d7d8� d8ejUj[�Z\dS ):� N)�SamDB�get_default_backend_store)�LdbError)�libsmb_samba_internal)�param)�
backup_online�backup_restore�backup_offline)�system_session)�
DCJoinContext�
join_clone�DCCloneAndRenameContext)�dom_sid)�Option�CommandError)�misc�security�drsblobs)�Ldb� )�cmd_fsmo_seize)�make_smbconf�DEFAULTSITE)�update_krbtgt_account_password)� remove_dc)�secretsdb_self_join)�dbcheck)�guess_names�determine_host_ip�determine_host_ip6)�fill_dns_data_partitions�get_dnsadmins_sid�get_domainguid)�tdb_copy)�mdb_copy)�CalledProcessError)�sites)�_dsdb_load_udv_v2)�ndr_pack)�SMB_SIGNING_REQUIREDc
C s z| � � }W n ty! } z|�d� |�d� td|��d }~ww t| �� �}t|�d t|� }z%| jtj d| g ddgd�}t
|�d krMtd
| ��td||d jf �� tjyu } z|j\}} |tj
krk� W Y d }~nd }~ww t|�d t|� S )
Nz}A SID could not be allocated for restoring the domain. Either no RID Set was found on this DC, or the RID Set was not usable.z�To initialise this DC's RID pools, obtain a RID Set from this domain's RID master, or run samba-tool dbcheck to fix the existing RID Set.zCannot create backup�-�<SID=%s>�show_deleted:1zshow_recycled:1)�scope�base�attrs�controlsr z]Cannot create backup - this DC's RID pool is corrupt, the next SID (%s) appears to be in use.z�Cannot create backup - this DC's RID pool is corrupt, the next SID %s points to existing object %s. Please run samba-tool dbcheck on the source DC.r )�
next_free_ridr �infor r �get_domain_sid�str�search�ldb�
SCOPE_BASE�len�dn�args�ERR_NO_SUCH_OBJECT)
�samdb�logger�rid�err�sid�sid_for_restore�res�e�enum�emsg� rF �</usr/lib/python3/dist-packages/samba/netcmd/domain_backup.py�get_sid_for_restore@ sB
��
����
���rH c C sF t �� }|�|j� |�� }|�t� tj| d||d�}|�|� |S )z7Returns an SMB connection to the sysvol share on the DC�sysvol)�lp�creds) �s3param�get_context�load�
configfile�get_smb_signing�set_smb_signingr) �libsmb�Conn)�serverrJ rK �s3_lp�saved_signing_state�connrF rF rG �smb_sysvol_connp s
rX c C s t j �� �� �dd�S )N�:r* )�datetime�now� isoformat�replacerF rF rF rG �
get_timestamp s r^ c C s d||f }t j�| |�S )Nzsamba-backup-%s-%s.tar.bz2)�os�path�join)� targetdir�name�time_str�filenamerF rF rG �backup_filepath� s rf c C s4 | � d| � t�|d�}|j|dd� |�� d S )NzCreating backup file %s...�w:bz2z./��arcname)r2 �tarfile�open�add�close)r= �tmpdirrf �tfrF rF rG �create_backup_tar� s rp c C s� t tj�| d�d�}zStj�� �d�}|�d| � |�d|�d� � |�d||f � |�d|�d �|�d
�� � f � |�dt
|� � |rW|�d| � W |�� d S W |�� d S |�� w )
N�
backup.txt�wz%Y-%b-%d %H:%M:%SzBackup created %s
zUsing samba-tool version: %s
z
server stringz Domain %s backup, using DC '%s'
z/Backup for domain %s (NetBIOS), %s (DNS realm)
� workgroup�realmz#Backup contains domain secrets: %s
z%s
)rk r_ r` ra rZ r[ �strftime�write�get�lowerr4 rm )rb rJ �backup_typerT �include_secrets�
extra_info�frd rF rF rG �create_log_file� s ��r} c C s8 t �� }t �| d�|_t �|t j|�||<