o
    jJ                     @   s  d dl mZ d dlmZmZmZmZmZmZm	Z	 d dl
mZmZmZmZmZ d dlmZ d dlmZmZ d dlmZ edZedZG d	d
 d
eZeZG dd deZdZdZdZdZdZ dZ!dZ"dZ#dZ$dZ%dZ&dZ'dZ(dZ)dZ*dZ+dZ,dZ-dZ.dZ/dZ0dZ1dZ2dZ3dZ4d Z5d!Z6dZ7d"Z8d#Z9d$Z:d%Z;d&Z<d'Z=dZ>dZ?d(Z@d)ZAd*ZBd+ZCd,ZDd-ZEd&ZFd$ZGd.ZHd/ZId'ZJd%ZKd0ZLd!ZMd"ZNdZOd1ZPd ZQd2ZRd3ZSd4ZTd5ZUd6ZVd7ZWdZXdZYd8ZZdZ[dZ\dZ]dZ^dZ_dZ`d9Zad:Zbd!ZcdZdd"Zed;Zfd5Zgd Zhd!ZidZjdZkdZldZmdZndZod<Zpd=Zqd:Zrd!ZsG d>d? d?eZtG d@dA dAeZuG dBdC dCeZvG dDdE dEeZwG dFdG dGeZxG dHdI dIeZyG dJdK dKeZzG dLdM dMeZ{G dNdO dOeZ|G dPdQ dQeZ}G dRdS dSeZ~G dTdU dUeZG dVdW dWeZG dXdY dYeZG dZd[ d[eZG d\d] d]eZG d^d_ d_eZG d`da daeZG dbdc dceZG ddde deeZG dfdg dgeZG dhdi dieZG djdk dkeZG dldm dmeZG dndo doeZG dpdq dqeZG drds dseZG dtdu dueZG dvdw dweZG dxdy dyeZG dzd{ d{eZG d|d} d}eZG d~d deZG dd deZeefeefeefeefeefdZdd Zdd Ze	e	e-e	fddZe	dfddZdd Zdd ZdS )    )system_errors)	ULONGLONGUINTUSHORTLPWSTRDWORDULONGNULL)NDRCALL	NDRSTRUCTNDRUNION
NDRPOINTERNDRUniConformantArray)DCERPCException)uuidtup_to_binstring_to_bin)DRIVER_INFO_2_ARRAY)z$76F03F96-CDFD-44FC-A22C-64950A001209z1.0z$9940CA8E-512F-4C58-88A9-61098D6896BDc                   @   s   e Zd ZdddZdd ZdS )DCERPCSessionErrorNc                 C   s   t | ||| d S )N)r   __init__)selferror_string
error_codepacket r   /root/aizidognhua/tmp/workspace/projects/ec89d86c-575f-41c9-af57-ac45cbdbf775/venv/lib/python3.10/site-packages/aiosmb/dcerpc/v5/par.pyr   "   s   zDCERPCSessionError.__init__c                 C   sF   | j }|tjv rtj| d }tj| d }d| j ||f S d| j  S )Nr      z'RPRN SessionError: code: 0x%x - %s - %sz+RPRN SessionError: unknown error code: 0x%x)r   r   ERROR_MESSAGES)r   keyerror_msg_shorterror_msg_verboser   r   r   __str__%   s   

zDCERPCSessionError.__str__)NNN)__name__
__module____qualname__r   r    r   r   r   r   r   !   s    
r   c                   @      e Zd ZdeffZdS )PSTRING_HANDLEDataN)r!   r"   r#   STRING_HANDLEreferentr   r   r   r   r%   3       r%          i  i   i0        @   i  i  r      i  i  i  i  i   i   i   i   i   i   i   l        i   @i    i         i   i   i   i   iwwiwi   pi   i    i  @ i  p i   i   i   i   i @  i   i   i   i    c                   @   s   e Zd ZdZdd ZdS )PRINTER_HANDLE))r&   z20s=b""c                 C   s   | j du rdS dS )NTr-   r,   )_isNDR64)r   r   r   r   getAlignment   s   
zPRINTER_HANDLE.getAlignmentN)r!   r"   r#   	structurer4   r   r   r   r   r2      s    r2   c                   @      e Zd ZdZdS )
BYTE_ARRAYcNr!   r"   r#   itemr   r   r   r   r7          r7   c                   @   r$   )PBYTE_ARRAYr&   N)r!   r"   r#   r7   r(   r   r   r   r   r<      r)   r<   c                   @      e Zd ZdefdeffZdS )DEVMODE_CONTAINERcbBufpDevModeN)r!   r"   r#   r   r<   r5   r   r   r   r   r>          r>   c                   @   s:   e Zd ZdefdefdefdefdefdefdeffZdS )	SPLCLIENT_INFO_1dwSizepMachineName	pUserName
dwBuildNumdwMajorVersiondwMinorVersionwProcessorArchitectureN)r!   r"   r#   r   r   r   r5   r   r   r   r   rB      s    rB   c                   @   r$   )PSPLCLIENT_INFO_1r&   N)r!   r"   r#   rB   r(   r   r   r   r   rJ      r)   rJ   c                   @   r$   )SPLCLIENT_INFO_2notUsedN)r!   r"   r#   r   r5   r   r   r   r   rK      r)   rK   c                   @   r$   )PSPLCLIENT_INFO_2r&   N)r!   r"   r#   rK   r(   r   r   r   r   rM      r)   rM   c                   @   sL   e Zd Zdefdefdefdefdefdefdefdefdefd	eff
Zd
S )SPLCLIENT_INFO_3cbSizedwFlagsrD   rE   rF   rG   rH   rI   hSplPrinterN)	r!   r"   r#   r   r   r   r   r   r5   r   r   r   r   rN      s    rN   c                   @   r$   )PSPLCLIENT_INFO_3r&   N)r!   r"   r#   rN   r(   r   r   r   r   rR      r)   rR   c                   @   r$   )DRIVER_INFO_1pNameN)r!   r"   r#   r'   r5   r   r   r   r   rS      r)   rS   c                   @   r$   )PDRIVER_INFO_1r&   N)r!   r"   r#   rS   r(   r   r   r   r   rU      r)   rU   c                   @   s4   e Zd ZdefdefdefdefdefdeffZdS )DRIVER_INFO_2cVersionrT   pEnvironmentpDriverPath	pDataFilepConfigFileN)r!   r"   r#   r   r   r5   r   r   r   r   rV          rV   c                   @   r$   )PDRIVER_INFO_2r&   N)r!   r"   r#   rV   r(   r   r   r   r   r]      r)   r]   c                   @   s(   e Zd ZdeffZdefdefdZdS )DRIVER_INFO_UNIONtagpNotUsedLevel2)r   r/   N)r!   r"   r#   r   	commonHdrrU   r]   unionr   r   r   r   r^     s    
r^   c                   @   r=   )DRIVER_CONTAINERLevel
DriverInfoN)r!   r"   r#   r   r^   r5   r   r   r   r   rd     rA   rd   c                   @   s.   e Zd ZdeffZdefdefdefdZdS )CLIENT_INFO_UNIONr_   pClientInfo1	pNotUsed1	pNotUsed2)r   r/      N)	r!   r"   r#   r   rb   rJ   rM   rR   rc   r   r   r   r   rg     s    
rg   c                   @   r=   )SPLCLIENT_CONTAINERre   
ClientInfoN)r!   r"   r#   r   rg   r5   r   r   r   r   rl     rA   rl   c                   @   r6   )USHORT_ARRAYz<HNr9   r   r   r   r   rn   %  r;   rn   c                   @   r$   )PUSHORT_ARRAYr&   N)r!   r"   r#   rn   r(   r   r   r   r   ro   (  r)   ro   c                   @   s4   e Zd ZdefdefdefdefdefdeffZdS )RpcAsync_V2_NOTIFY_OPTIONS_TYPEType	Reserved0	Reserved1	Reserved2CountpFieldsN)r!   r"   r#   r   r   ro   r5   r   r   r   r   rp   -  r\   rp   c                   @   r$   )!PRPC_V2_NOTIFY_OPTIONS_TYPE_ARRAYr&   N)r!   r"   r#   rp   r(   r   r   r   r   rw   7  r)   rw   c                   @   s(   e Zd ZdefdefdefdeffZdS )RpcAsync_V2_NOTIFY_OPTIONSVersionReservedru   pTypesN)r!   r"   r#   r   rw   r5   r   r   r   r   rx   =      rx   c                   @   r$   )PRPC_V2_NOTIFY_OPTIONSr&   N)r!   r"   r#   rx   r(   r   r   r   r   r}   E  r)   r}   c                   @   s2   e Zd ZdZdefdefdefdefdeffZdS )RpcAsyncEnumPrinters&   FlagsNamere   pPrinterEnumr?   N)r!   r"   r#   opnumr   r'   r<   r5   r   r   r   r   r~   O      r~   c                   @   (   e Zd ZdefdefdefdeffZdS )RpcAsyncEnumPrintersResponser   	pcbNeeded
pcReturned	ErrorCodeNr!   r"   r#   r<   r   r   r5   r   r   r   r   r   Y  r|   r   c                   @   s2   e Zd ZdZdefdefdefdefdeffZ	dS )RpcAsyncOpenPrinterr   pPrinterName	pDatatypepDevModeContainerAccessRequiredpClientInfoN)
r!   r"   r#   r   r'   r   r>   r   rl   r5   r   r   r   r   r   b  r   r   c                   @   r=   )RpcAsyncOpenPrinterResponsepHandler   Nr!   r"   r#   r2   r   r5   r   r   r   r   r   l  rA   r   c                   @   s   e Zd ZdZdeffZdS )RpcAsyncClosePrinter   	phPrinterN)r!   r"   r#   r   r2   r5   r   r   r   r   r   s  s    r   c                   @   r=   )RpcAsyncClosePrinterResponser   r   Nr   r   r   r   r   r   y  rA   r   c                   @   s2   e Zd ZdZdefdefdefdefdeffZdS )RpcAsyncEnumPrinterDrivers(   rT   rX   re   pDriversr?   N)	r!   r"   r#   r   r'   r   r   r<   r5   r   r   r   r   r     r   r   c                   @   r   )"RpcAsyncEnumPrinterDriversResponser   r   r   r   Nr   r   r   r   r   r     r|   r   c                   @   s&   e Zd ZdZdefdefdeffZdS )RpcAsyncAddPrinterDriver'   rT   pDriverContainerdwFileCopyFlagsN)r!   r"   r#   r   r'   rd   r   r5   r   r   r   r   r     s    r   c                   @   r$   ) RpcAsyncAddPrinterDriverResponser   N)r!   r"   r#   r   r5   r   r   r   r   r     r)   r   )r   r   r   r   r   c                 C   s(   | t kr| S | dd  dkr| d S | S )N )r	   )stringr   r   r   checkNullString  s
   r   c                    s"   t  }||d< | |tI dH S )a  
	RpcClosePrinter closes a handle to a printer object, server object, job object, or port object.
	Full Documentation: https://msdn.microsoft.com/en-us/library/cc244768.aspx

	:param DCERPC_v5 dce: a connected DCE instance.
	:param PRINTER_HANDLE phPrinter: A handle to a printer object, server object, job object, or port object.

	:return: a RpcClosePrinterResponse instance, raises DCERPCSessionError on error.
	r   N)r   requestMSRPC_UUID_WINSPOOL)dcer   r   r   r   r   hRpcAsyncClosePrinter  s   
r   c                    sl   t  }t||d< ||d< |tu rt|d d< n||d< ||d< |tu r)td||d< | |tI dH S )	a  
	RpcOpenPrinterEx retrieves a handle for a printer, port, port monitor, print job, or print server
	Full Documentation: https://msdn.microsoft.com/en-us/library/cc244809.aspx

	:param DCERPC_v5 dce: a connected DCE instance.
	:param string printerName: A string for a printer connection, printer object, server object, job object, port
	object, or port monitor object. This MUST be a Domain Name System (DNS), NetBIOS, Internet Protocol version 4
	(IPv4), Internet Protocol version 6 (IPv6), or Universal Naming Convention (UNC) name that remote procedure
	call (RpcAsync) binds to, and it MUST uniquely identify a print server on the network.
	:param string pDatatype: A string that specifies the data type to be associated with the printer handle.
	:param DEVMODE_CONTAINER pDevModeContainer: A DEVMODE_CONTAINER structure. This parameter MUST adhere to the specification in
	DEVMODE_CONTAINER Parameters (section 3.1.4.1.8.1).
	:param int accessRequired: The access level that the client requires for interacting with the object to which a
	handle is being opened.
	:param SPLCLIENT_CONTAINER pClientInfo: This parameter MUST adhere to the specification in SPLCLIENT_CONTAINER Parameters.

	:return: a RpcOpenPrinterExResponse instance, raises DCERPCSessionError on error.
	r   r   r   r@   r   zpClientInfo cannot be NULLr   N)r   r   r	   	Exceptionr   r   )r   printerNamer   r   accessRequiredr   r   r   r   r   hRpcAsyncOpenPrinter  s   r   c           	   
      s   t  }||d< ||d< t|d< ||d< d}z| |tI dH \}}|dur(|W n" tyK } zt|ddk r; | d }W Y d}~nd}~ww t  }||d< ||d< ||d< ||d	< d
| |d< | |tI dH S )a  
	RpcEnumPrinters enumerates available printers, print servers, domains, or print providers.
	Full Documentation: https://msdn.microsoft.com/en-us/library/cc244794.aspx

	:param DCERPC_v5 dce: a connected DCE instance.
	:param int flags: The types of print objects that this method enumerates. The value of this parameter is the
	result of a bitwise OR of one or more of the Printer Enumeration Flags (section 2.2.3.7).
	:param string name: NULL or a server name parameter as specified in Printer Server Name Parameters (section 3.1.4.1.4).
	:param level: The level of printer information structure.

	:return: a RpcEnumPrintersResponse instance, raises DCERPCSessionError on error.
	r   r   r   re   r   NERROR_INSUFFICIENT_BUFFERr   r?      a)r~   r	   r   r   r   strfind
get_packet)	r   flagsnamelevelr   bytesNeeded_errer   r   r   hRpcAsyncEnumPrinters  s2   r   c                    s6   t  }t||d< ||d< ||d< | |tI dH S )af  
	RpcAddPrinterDriverEx installs a printer driver on the print server
	Full Documentation: https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-rprn/b96cc497-59e5-4510-ab04-5484993b259b

	:param DCERPC_v5 dce: a connected DCE instance.
	:param pName
	:param pDriverContainer
	:param dwFileCopyFlags

	:return: raises DCERPCSessionError on error.
	rT   r   r   N)r   r   r   r   )r   rT   r   r   r   r   r   r   hRpcAsyncAddPrinterDriver  s   r   c              
      s   t  }t||d< ||d< ||d< t|d< d|d< z| |tI dH \}}|dur,|W n" tyO } zt|ddk r? | d	 }W Y d}~nd}~ww t  }t||d< ||d< ||d< d
| |d< ||d< | |tI dH \}	}|dur~d|fS t	
d|	d |	d }
|
j|fS )a  
	RpcEnumPrinterDrivers enumerates the printer drivers installed on a specified print server.
	Full Documentation: https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-rprn/857d00ac-3682-4a0d-86ca-3d3c372e5e4a

	:param DCERPC_v5 dce: a connected DCE instance.
	:param pName
	:param pEnvironment
	:param Level
	:param pDrivers
	:param cbBuf
	:param pcbNeeded
	:param pcReturned

	:return: raises DCERPCSessionError on error.
	rT   rX   re   r   r   r?   Nr   r   r       r   )r   r   r	   r   r   r   r   r   r   r   
from_bytesjoindrivers)r   rT   rX   re   r   r   r   r   r   data_rawdatar   r   r   hRpcAsyncEnumPrinterDrivers&  s:   
r   N)aiosmb.dcerpc.v5r   aiosmb.dcerpc.v5.dtypesr   r   r   r   r   r   r	   aiosmb.dcerpc.v5.ndrr
   r   r   r   r   aiosmb.dcerpc.v5.rpcrtr   aiosmb.dcerpc.v5.uuidr   r   aiosmb.dcerpc.v5.rprnr   MSRPC_UUID_PARr   r   r'   r%   JOB_ACCESS_ADMINISTERJOB_ACCESS_READJOB_EXECUTEJOB_READ	JOB_WRITEJOB_ALL_ACCESSPRINTER_ACCESS_ADMINISTERPRINTER_ACCESS_USEPRINTER_ACCESS_MANAGE_LIMITEDPRINTER_ALL_ACCESSPRINTER_EXECUTEPRINTER_READPRINTER_WRITESERVER_ACCESS_ADMINISTERSERVER_ACCESS_ENUMERATESERVER_ALL_ACCESSSERVER_EXECUTESERVER_READSERVER_WRITESPECIFIC_RIGHTS_ALLSTANDARD_RIGHTS_ALLSTANDARD_RIGHTS_EXECUTESTANDARD_RIGHTS_READSTANDARD_RIGHTS_REQUIREDSTANDARD_RIGHTS_WRITESYNCHRONIZEDELETEREAD_CONTROL	WRITE_DACWRITE_OWNERGENERIC_READGENERIC_WRITEGENERIC_EXECUTEGENERIC_ALLPRINTER_CHANGE_SET_PRINTERPRINTER_CHANGE_DELETE_PRINTERPRINTER_CHANGE_PRINTERPRINTER_CHANGE_ADD_JOBPRINTER_CHANGE_SET_JOBPRINTER_CHANGE_DELETE_JOBPRINTER_CHANGE_WRITE_JOBPRINTER_CHANGE_JOB!PRINTER_CHANGE_SET_PRINTER_DRIVERPRINTER_CHANGE_TIMEOUTPRINTER_CHANGE_ALLPRINTER_CHANGE_ALL_2!PRINTER_CHANGE_ADD_PRINTER_DRIVER$PRINTER_CHANGE_DELETE_PRINTER_DRIVERPRINTER_CHANGE_PRINTER_DRIVERPRINTER_CHANGE_ADD_FORMPRINTER_CHANGE_DELETE_FORMPRINTER_CHANGE_SET_FORMPRINTER_CHANGE_FORMPRINTER_CHANGE_ADD_PORTPRINTER_CHANGE_CONFIGURE_PORTPRINTER_CHANGE_DELETE_PORTPRINTER_CHANGE_PORT"PRINTER_CHANGE_ADD_PRINT_PROCESSOR%PRINTER_CHANGE_DELETE_PRINT_PROCESSORPRINTER_CHANGE_PRINT_PROCESSORPRINTER_CHANGE_ADD_PRINTER(PRINTER_CHANGE_FAILED_CONNECTION_PRINTERPRINTER_CHANGE_SERVERPRINTER_ENUM_LOCALPRINTER_ENUM_CONNECTIONSPRINTER_ENUM_NAMEPRINTER_ENUM_REMOTEPRINTER_ENUM_SHAREDPRINTER_ENUM_NETWORKPRINTER_ENUM_EXPANDPRINTER_ENUM_CONTAINERPRINTER_ENUM_ICON1PRINTER_ENUM_ICON2PRINTER_ENUM_ICON3PRINTER_ENUM_ICON8PRINTER_ENUM_HIDEPRINTER_NOTIFY_CATEGORY_2DPRINTER_NOTIFY_CATEGORY_ALLPRINTER_NOTIFY_CATEGORY_3DAPD_STRICT_UPGRADEAPD_STRICT_DOWNGRADEAPD_COPY_ALL_FILESAPD_COPY_NEW_FILESAPD_COPY_FROM_DIRECTORYAPD_DONT_COPY_FILES_TO_CLUSTERAPD_COPY_TO_ALL_SPOOLERSAPD_INSTALL_WARNED_DRIVERAPD_RETURN_BLOCKING_STATUS_CODEr2   r7   r<   r>   rB   rJ   rK   rM   rN   rR   rS   rU   rV   r]   r^   rd   rg   rl   rn   ro   rp   rw   rx   r}   r~   r   r   r   r   r   r   r   r   r   OPNUMSr   r   r   r   r   r   r   r   r   r   <module>   s&  $		



	

			
$&