U vf+@sdZddlZddlZddlmZddZGdddejZdd Zd Z ej j j Z ej jejfe _ej je _ej j jZej jfe_ej je_ej j jZej jfe_ej je_ej j jZej jfe_eje_ej j jZej jejej jej jej jej jge_ej je_ej j jZej je_ej j jZej jfe_ej j j Z ejejejfe _ej j!fej j j"_Gd d d Z#d Z$dZ%e$Z&e$Z'e$Z(dZ)dZ*d Z+dZ,dZ-dZ.dZ/dZ0dZ1dZ2dZ3dZ4dZ5dZ6e%e*Be+Be,Be-Be.Be/Be0Be1Be2Be3Be4Be5BZ7e&e+Be,BZ8e'e-Be.Be/Be0Be1Be2Be3Be4BZ9e(e*Be5BZ:GdddZ;GdddZGd"d#d#ej=Z?Gd$d%d%ej=Z@eAe?ejej jfej jBjC_d&d'ZDd(d)ZEd*d+ZFd.d,d-ZGdS)/z Windows API functions implemented as ctypes functions and classes as found in jaraco.windows (3.4.1). If you encounter issues with this module, please consider reporting the issues in jaraco.windows and asking the author to port the fixes back here. N)uc Csnd}d}||B}d}|}d}tj}d}d} tjj||||t||| } t| |j} tjj || S)zf Call FormatMessage with a system error number to retrieve the descriptive error message. Nr) ctypeswintypesLPWSTRwindllkernel32ZFormatMessageWbyrefhandle_nonzero_successvalue LocalFree) errnoZALLOCATE_BUFFERZ FROM_SYSTEMflagssourceZ message_idZ language_idZ result_buffer buffer_size argumentsbytesmessagerA/opt/alt/python38/lib/python3.8/site-packages/paramiko/_winapi.pyformat_system_messages,  rcsJeZdZdZd fdd ZeddZeddZd d Zd d Z Z S) WindowsErrorzZmore info about errors at http://msdn.microsoft.com/en-us/library/ms681381(VS.85).aspxNcs8|dkrtjj}t|}d|d|f}tj|dSNr)rrr Z GetLastErrorrsuper__init__)selfr strerrorargs __class__rrr;s   zWindowsError.__init__cCs|jSN)rrrrrrBszWindowsError.messagecCs|jSr!)winerrorr"rrrcodeFszWindowsError.codecCs|jSr!)rr"rrr__str__JszWindowsError.__str__cCsdjftS)Nz*{self.__class__.__name__}({self.winerror}))formatvarsr"rrr__repr__MszWindowsError.__repr__)N) __name__ __module__ __qualname____doc__rpropertyrr$r%r( __classcell__rrrrr7s  rcCs|dkrtdSr)r)resultrrrr Qsr c@sBeZdZdZdddZddZddZd d Zd d Zd dZ dS) MemoryMapzL A memory map object which can have security attributes overridden. NcCs||_||_||_d|_dSr)namelengthsecurity_attributespos)rr2r3r4rrrrszMemoryMap.__init__c Csv|jrt|jnd}d}d}d}tjj|||d|jt|j}t |||krZt d||_ t ||ddd|_ |S)Nr0rzFailed to create file mapping)r4rr rr CreateFileMappingWr3rr2r Exceptionfilemap MapViewOfFileview)rZp_SAZINVALID_HANDLE_VALUEZPAGE_READWRITEZFILE_MAP_WRITEr:rrr __enter__s*zMemoryMap.__enter__cCs ||_dSr!)r5)rr5rrrseekszMemoryMap.seekcCspt|tstt|}|j||jkr6td|d|j|j}t |}tj j ||||j|7_dS)NzRefusing to write z bytes) isinstancerAssertionErrorlenr5r3 ValueErrorr<rc_size_trr RtlMoveMemory)rmsgndestr3rrrwrites  zMemoryMap.writecCsFt|}|j|j}t|}tjj||||j|7_|jS)z0 Read n bytes from mapped view. ) rcreate_string_bufferr<r5rCrr rDraw)rrFoutrr3rrrreads    zMemoryMap.readcCs$tjj|jtjj|jdSr!)rrr UnmapViewOfFiler<Z CloseHandler:)rexc_typeexc_valtbrrr__exit__szMemoryMap.__exit__)N) r)r*r+r,rr=r>rHrLrQrrrrr1s   r1iiir7 @riiirc@seZdZdZdS) TokenAccessrSN)r)r*r+ TOKEN_QUERYrrrrrX srXc@seZdZdZdS)TokenInformationClassrRN)r)r*r+Z TokenUserrrrrrZ srZc@s&eZdZdZdejfdejjfgZdS) TOKEN_USERrRSIDZ ATTRIBUTESN) r)r*r+numrc_void_prDWORD_fields_rrrrr[s r[c@sVeZdZdZejjZdZdej fdej fdefdej fdej fdej fd ej fgZ d S) SECURITY_DESCRIPTORz typedef struct _SECURITY_DESCRIPTOR { UCHAR Revision; UCHAR Sbz1; SECURITY_DESCRIPTOR_CONTROL Control; PSID Owner; PSID Group; PACL Sacl; PACL Dacl; } SECURITY_DESCRIPTOR; rRZRevisionZSbz1ControlZOwnerGroupZSaclZDaclN) r)r*r+r,rrZUSHORTZSECURITY_DESCRIPTOR_CONTROLREVISIONZc_ubyter^r`rrrrras racsZeZdZdZdejjfdejfdejjfgZ fddZ e ddZ e j d dZ ZS) SECURITY_ATTRIBUTESz typedef struct _SECURITY_ATTRIBUTES { DWORD nLength; LPVOID lpSecurityDescriptor; BOOL bInheritHandle; } SECURITY_ATTRIBUTES; nLengthlpSecurityDescriptorbInheritHandlecstj||tt|_dSr!)rrrsizeofrerf)rrkwargsrrrrDszSECURITY_ATTRIBUTES.__init__cCs|jSr!) _descriptorr"rrr descriptorHszSECURITY_ATTRIBUTES.descriptorcCs||_t||_dSr!)rkrZ addressofrg)rr rrrrlLs)r)r*r+r,rrr_r^BOOLr`rr-rlsetterr.rrrrre5s    rec Csvtj}tjj||jddt|t|j }t tjj||jt|t |t|t |t tjS)z: Given a token, get the token information for it. r)rrr_radvapi32GetTokenInformationr]r rIr r ricastPOINTERr[contents)tokenZinformation_class data_sizedatarrrrp\s&   rpcCs6tj}tj|}ttjj||t||Sr!)rrHANDLEr rroOpenProcessTokenr )Z proc_handleaccessr/rrrrxqs  rxcCsttjjtj}t|tS)z< Return a TOKEN_USER for the owner of this process. ) rxrrr ZGetCurrentProcessrXrYrpr[)processrrrget_current_user|s  r{cCsn|dkrt}t|ts tdt}t}||_d|_tj j t |tj tj j t ||jd|S)z Return a SECURITY_ATTRIBUTES structure with the SID set to the specified user (uses current user if none is specified). Nz user must be TOKEN_USER instancerRr)r{r?r[r@rarerlrhrrroZInitializeSecurityDescriptorr rdSetSecurityDescriptorOwnerr\)userZSDZSArrr get_security_attributes_for_users"r~)N)Hr,builtinsZctypes.wintypesrZ paramiko.utilrrrr Z GMEM_MOVEABLErr Z GlobalAllocrZUINTrCZargtypesrwrestypeZ GlobalLockZHGLOBALZLPVOIDZ GlobalUnlockrmZ GlobalSizer8ZCreateFileMappingr^r_rr;rMrDZHLOCALr r1Z READ_CONTROLZSTANDARD_RIGHTS_REQUIREDZSTANDARD_RIGHTS_READZSTANDARD_RIGHTS_WRITEZSTANDARD_RIGHTS_EXECUTEZSTANDARD_RIGHTS_ALLZPOLICY_VIEW_LOCAL_INFORMATIONZPOLICY_VIEW_AUDIT_INFORMATIONZPOLICY_GET_PRIVATE_INFORMATIONZPOLICY_TRUST_ADMINZPOLICY_CREATE_ACCOUNTZPOLICY_CREATE_SECRETZPOLICY_CREATE_PRIVILEGEZPOLICY_SET_DEFAULT_QUOTA_LIMITSZPOLICY_SET_AUDIT_REQUIREMENTSZPOLICY_AUDIT_LOG_ADMINZPOLICY_SERVER_ADMINZPOLICY_LOOKUP_NAMESZPOLICY_NOTIFICATIONZPOLICY_ALL_ACCESSZ POLICY_READZ POLICY_WRITEZPOLICY_EXECUTErXrZZ Structurer[rarerrror|rprxr{r~rrrrs $                 D