a
    I_                     @   s   d dl mZmZmZmZ d dlmZ d dlm	Z	 d dl
mZ d dlZd dlmZmZ d dlmZ d dlZG dd deZG d	d
 d
eZG dd deZG dd deZG dd deZdS )    )CommandCommandErrorOptionSuperCommandN)SamDB)system_session)miscdrsuapi)drs_Replicatec                   @   s   e Zd Zdd Zdd ZdS )RODCExceptionc                 C   s
   || _ d S )N)value)selfr    r   3/usr/lib/python3/dist-packages/samba/netcmd/rodc.py__init__   s    zRODCException.__init__c                 C   s   d| j j| jf S )Nz%s: %s)	__class____name__r   )r   r   r   r   __str__!   s    zRODCException.__str__N)r   
__module____qualname__r   r   r   r   r   r   r      s   r   c                   @   s   e Zd ZdS )NamingErrorNr   r   r   r   r   r   r   r   %   s   r   c                   @   s   e Zd ZdS )ReplicationErrorNr   r   r   r   r   r   )   s   r   c                   @   sd   e Zd ZdZdZejejejdZ	e
ddede
ddede
d	d
ddgZdgZdd Zdd ZdS )cmd_rodc_preloadzBPreload accounts for an RODC.  Multiple accounts may be requested.z/%prog (<SID>|<DN>|<accountname>)+ ... [options])	sambaoptsZversionoptscredoptsz--serverz	DC to use)helptypez--filez<Read account list from a file, or - for stdin (one per line)z--ignore-errorsz<When preloading multiple accounts, skip any failing accounts
store_true)r   actionzaccount*c                 C   s   |dd dkr*|j d| dtjg d}n@|ddkrN|j |dtjg d}n|j dt| tjg d	}t|d
krtd| t|d d S )zwork out what DN they meantr      zS-z<SID=%s>zobjectclass=user)base
expressionscopeattrs=z((&(samAccountName=%s)(objectclass=user)))r"   r#   r$      zFailed to find account '%s'dn)	searchldb
SCOPE_BASEfindZbinary_encodeZSCOPE_SUBTREElenr   str)r   samdbaccountresr   r   r   get_dn@   s     
zcmd_rodc_preload.get_dnc                 O   s  | d}| d}| d}| d}| d}|d u rBtd|d urg }|dkrrtjD ]}||  q\nt|dD ]}||  q|| }	|j|	d	d
}
t	d| t
 |
|	d}t	d t
 |
|	d}t| }d}|	 dkr|d7 }td||f |	|
||}g }|D ]>}| }|j|tjdgd}t|d|d d d }z| ||}W nP ty } z6|stt||| W Y d }~qW Y d }~n
d }~0 0 | jd|  |  z|j|||tjd	d W n` tyH } zF|  |std| |t d|  W Y d }~qW Y d }~n
d }~0 0 |!  qt"|dkr| #d |D ]}| #d|  qrd S )Nr   r   serverfileignore_errorszYou must supply a server-rT)Zfallback_machinez	ldap://%s)ZurlZsession_infoZcredentialslpZseal	   z,printzncacn_ip_tcp:%s[%s]ZinvocationId)r!   r#   r$   Z
objectGUIDr   zReplicating DN %s
)ZexopZrodczError replicating DN %sz'
Preload encountered problematic users:z    %s)$get	ExceptionsysstdinappendstripopenZget_loadparmZget_credentialsr   r   r   ZGUIDZget_ntds_GUIDZ	log_levelr
   Zget_dsServiceNamer(   r)   r*   Zschema_format_valuer1   r   r   r-   ZoutfwriteZtransaction_startZ	replicater	   ZDRSUAPI_EXOP_REPL_SECRETZtransaction_cancelr   Ztransaction_commitr,   message)r   Zaccountskwargsr   r   r2   Zaccounts_filer4   liner7   Zcredsr.   Zlocal_samdbZdestination_dsa_guidZbinding_optionsreplerrorsr/   Z
dc_ntds_dnr0   Zsource_dsa_invocation_idr'   eerrorr   r   r   runS   sx    







$

$
zcmd_rodc_preload.runN)r   r   r   __doc__ZsynopsisoptionsZSambaOptionsZVersionOptionsZCredentialsOptionsZtakes_optiongroupsr   r-   Ztakes_optionsZ
takes_argsr1   rH   r   r   r   r   r   -   s   r   c                   @   s   e Zd ZdZi Ze ed< dS )cmd_rodcz.Read-Only Domain Controller (RODC) management.ZpreloadN)r   r   r   rI   Zsubcommandsr   r   r   r   r   rK      s   rK   )Zsamba.netcmdr   r   r   r   Zsamba.getoptZgetoptrJ   Zsamba.samdbr   Z
samba.authr   r)   Zsamba.dcerpcr   r	   Zsamba.drs_utilsr
   r;   r:   r   r   r   r   rK   r   r   r   r   <module>   s   r