HEX
Server: LiteSpeed
System: Linux kapuas.iixcp.rumahweb.net 5.14.0-427.42.1.el9_4.x86_64 #1 SMP PREEMPT_DYNAMIC Fri Nov 1 14:58:02 EDT 2024 x86_64
User: mirz4654 (1666)
PHP: 8.1.33
Disabled: system,exec,escapeshellarg,escapeshellcmd,passthru,proc_close,proc_get_status,proc_nice,proc_open,proc_terminate,shell_exec,popen,pclose,dl,pfsockopen,leak,apache_child_terminate,posix_kill,posix_mkfifo,posix_setsid,posix_setuid,posix_setpgid,ini_alter,show_source,define_syslog_variables,symlink,syslog,openlog,openlog,closelog,ocinumcols,listen,chgrp,apache_note,apache_setenv,debugger_on,debugger_off,ftp_exec,dll,ftp,myshellexec,socket_bind,mail,posix_getwpuid
Upload Files
File: //lib/python3.9/site-packages/ansible/plugins/connection/__pycache__/psrp.cpython-39.pyc
a

�)gɌ�
@svddlmZmZmZeZdZddlZddlZddl	Z	ddl
Z
ddlmZ
ddlmZmZddlmZddlmZddlmZmZmZdd	lmZdd
lmZddlmZddlmZd
Z dZ!zpddl"Z"ddl#m$Z$m%Z%m&Z&ddl'm(Z(m)Z)ddl*m+Z+m,Z,ddl-m.Z.m/Z/ddl0m1Z1m2Z2ddl3m4Z4m5Z5Wn.e6�yZZ7zdZ e7Z!WYdZ7[7n
dZ7[700e�Z8Gdd�de�Z9dS)�)�absolute_import�division�print_functiona^$
author: Ansible Core Team
name: psrp
short_description: Run tasks over Microsoft PowerShell Remoting Protocol
description:
- Run commands or put/fetch on a target via PSRP (WinRM plugin)
- This is similar to the I(winrm) connection plugin which uses the same
  underlying transport but instead runs in a PowerShell interpreter.
version_added: "2.7"
requirements:
- pypsrp>=0.4.0 (Python library)
extends_documentation_fragment:
    - connection_pipelining
options:
  # transport options
  remote_addr:
    description:
    - The hostname or IP address of the remote host.
    default: inventory_hostname
    type: str
    vars:
    - name: inventory_hostname
    - name: ansible_host
    - name: ansible_psrp_host
  remote_user:
    description:
    - The user to log in as.
    type: str
    vars:
    - name: ansible_user
    - name: ansible_psrp_user
    keyword:
    - name: remote_user
  remote_password:
    description: Authentication password for the C(remote_user). Can be supplied as CLI option.
    type: str
    vars:
    - name: ansible_password
    - name: ansible_winrm_pass
    - name: ansible_winrm_password
    aliases:
    - password  # Needed for --ask-pass to come through on delegation
  port:
    description:
    - The port for PSRP to connect on the remote target.
    - Default is C(5986) if I(protocol) is not defined or is C(https),
      otherwise the port is C(5985).
    type: int
    vars:
    - name: ansible_port
    - name: ansible_psrp_port
    keyword:
    - name: port
  protocol:
    description:
    - Set the protocol to use for the connection.
    - Default is C(https) if I(port) is not defined or I(port) is not C(5985).
    choices:
    - http
    - https
    type: str
    vars:
    - name: ansible_psrp_protocol
  path:
    description:
    - The URI path to connect to.
    type: str
    vars:
    - name: ansible_psrp_path
    default: 'wsman'
  auth:
    description:
    - The authentication protocol to use when authenticating the remote user.
    - The default, C(negotiate), will attempt to use C(Kerberos) if it is
      available and fall back to C(NTLM) if it isn't.
    type: str
    vars:
    - name: ansible_psrp_auth
    choices:
    - basic
    - certificate
    - negotiate
    - kerberos
    - ntlm
    - credssp
    default: negotiate
  cert_validation:
    description:
    - Whether to validate the remote server's certificate or not.
    - Set to C(ignore) to not validate any certificates.
    - I(ca_cert) can be set to the path of a PEM certificate chain to
      use in the validation.
    choices:
    - validate
    - ignore
    default: validate
    type: str
    vars:
    - name: ansible_psrp_cert_validation
  ca_cert:
    description:
    - The path to a PEM certificate chain to use when validating the server's
      certificate.
    - This value is ignored if I(cert_validation) is set to C(ignore).
    type: path
    vars:
    - name: ansible_psrp_cert_trust_path
    - name: ansible_psrp_ca_cert
    aliases: [ cert_trust_path ]
  connection_timeout:
    description:
    - The connection timeout for making the request to the remote host.
    - This is measured in seconds.
    type: int
    vars:
    - name: ansible_psrp_connection_timeout
    default: 30
  read_timeout:
    description:
    - The read timeout for receiving data from the remote host.
    - This value must always be greater than I(operation_timeout).
    - This option requires pypsrp >= 0.3.
    - This is measured in seconds.
    type: int
    vars:
    - name: ansible_psrp_read_timeout
    default: 30
    version_added: '2.8'
  reconnection_retries:
    description:
    - The number of retries on connection errors.
    type: int
    vars:
    - name: ansible_psrp_reconnection_retries
    default: 0
    version_added: '2.8'
  reconnection_backoff:
    description:
    - The backoff time to use in between reconnection attempts.
      (First sleeps X, then sleeps 2*X, then sleeps 4*X, ...)
    - This is measured in seconds.
    - The C(ansible_psrp_reconnection_backoff) variable was added in Ansible
      2.9.
    type: int
    vars:
    - name: ansible_psrp_connection_backoff
    - name: ansible_psrp_reconnection_backoff
    default: 2
    version_added: '2.8'
  message_encryption:
    description:
    - Controls the message encryption settings, this is different from TLS
      encryption when I(ansible_psrp_protocol) is C(https).
    - Only the auth protocols C(negotiate), C(kerberos), C(ntlm), and
      C(credssp) can do message encryption. The other authentication protocols
      only support encryption when C(protocol) is set to C(https).
    - C(auto) means means message encryption is only used when not using
      TLS/HTTPS.
    - C(always) is the same as C(auto) but message encryption is always used
      even when running over TLS/HTTPS.
    - C(never) disables any encryption checks that are in place when running
      over HTTP and disables any authentication encryption processes.
    type: str
    vars:
    - name: ansible_psrp_message_encryption
    choices:
    - auto
    - always
    - never
    default: auto
  proxy:
    description:
    - Set the proxy URL to use when connecting to the remote host.
    vars:
    - name: ansible_psrp_proxy
    type: str
  ignore_proxy:
    description:
    - Will disable any environment proxy settings and connect directly to the
      remote host.
    - This option is ignored if C(proxy) is set.
    vars:
    - name: ansible_psrp_ignore_proxy
    type: bool
    default: 'no'

  # auth options
  certificate_key_pem:
    description:
    - The local path to an X509 certificate key to use with certificate auth.
    type: path
    vars:
    - name: ansible_psrp_certificate_key_pem
  certificate_pem:
    description:
    - The local path to an X509 certificate to use with certificate auth.
    type: path
    vars:
    - name: ansible_psrp_certificate_pem
  credssp_auth_mechanism:
    description:
    - The sub authentication mechanism to use with CredSSP auth.
    - When C(auto), both Kerberos and NTLM is attempted with kerberos being
      preferred.
    type: str
    choices:
    - auto
    - kerberos
    - ntlm
    default: auto
    vars:
    - name: ansible_psrp_credssp_auth_mechanism
  credssp_disable_tlsv1_2:
    description:
    - Disables the use of TLSv1.2 on the CredSSP authentication channel.
    - This should not be set to C(yes) unless dealing with a host that does not
      have TLSv1.2.
    default: no
    type: bool
    vars:
    - name: ansible_psrp_credssp_disable_tlsv1_2
  credssp_minimum_version:
    description:
    - The minimum CredSSP server authentication version that will be accepted.
    - Set to C(5) to ensure the server has been patched and is not vulnerable
      to CVE 2018-0886.
    default: 2
    type: int
    vars:
    - name: ansible_psrp_credssp_minimum_version
  negotiate_delegate:
    description:
    - Allow the remote user the ability to delegate it's credentials to another
      server, i.e. credential delegation.
    - Only valid when Kerberos was the negotiated auth or was explicitly set as
      the authentication.
    - Ignored when NTLM was the negotiated auth.
    type: bool
    vars:
    - name: ansible_psrp_negotiate_delegate
  negotiate_hostname_override:
    description:
    - Override the remote hostname when searching for the host in the Kerberos
      lookup.
    - This allows Ansible to connect over IP but authenticate with the remote
      server using it's DNS name.
    - Only valid when Kerberos was the negotiated auth or was explicitly set as
      the authentication.
    - Ignored when NTLM was the negotiated auth.
    type: str
    vars:
    - name: ansible_psrp_negotiate_hostname_override
  negotiate_send_cbt:
    description:
    - Send the Channel Binding Token (CBT) structure when authenticating.
    - CBT is used to provide extra protection against Man in the Middle C(MitM)
      attacks by binding the outer transport channel to the auth channel.
    - CBT is not used when using just C(HTTP), only C(HTTPS).
    default: yes
    type: bool
    vars:
    - name: ansible_psrp_negotiate_send_cbt
  negotiate_service:
    description:
    - Override the service part of the SPN used during Kerberos authentication.
    - Only valid when Kerberos was the negotiated auth or was explicitly set as
      the authentication.
    - Ignored when NTLM was the negotiated auth.
    default: WSMAN
    type: str
    vars:
    - name: ansible_psrp_negotiate_service

  # protocol options
  operation_timeout:
    description:
    - Sets the WSMan timeout for each operation.
    - This is measured in seconds.
    - This should not exceed the value for C(connection_timeout).
    type: int
    vars:
    - name: ansible_psrp_operation_timeout
    default: 20
  max_envelope_size:
    description:
    - Sets the maximum size of each WSMan message sent to the remote host.
    - This is measured in bytes.
    - Defaults to C(150KiB) for compatibility with older hosts.
    type: int
    vars:
    - name: ansible_psrp_max_envelope_size
    default: 153600
  configuration_name:
    description:
    - The name of the PowerShell configuration endpoint to connect to.
    type: str
    vars:
    - name: ansible_psrp_configuration_name
    default: Microsoft.PowerShell
N)�	constants)�AnsibleConnectionFailure�AnsibleError)�AnsibleFileNotFound)�boolean)�to_bytes�	to_native�to_text)�ConnectionBase)�_common_args)�Display)�sha1T)�GenericComplexObject�PSInvocationState�RunspacePoolState)�AuthenticationError�
WinRMError)�PSHost�PSHostUserInterface)�
PowerShell�RunspacePool)�WSMan�AUTH_KWARGS)�ConnectionError�ConnectTimeoutFcs�eZdZdZdZdZdZdZ�fdd�Z�fdd�Z	d	d
�Z
d�fdd
�	Z�fdd�Z�fdd�Z
dd�Zdd�Zddd�Zdd�Z�ZS)�
ConnectionZpsrp)z.ps1z.exe�FTcszd|_d|_d|_d|_d|_d|_tt|�j|i|��t	j
svt�d��
tj�t�d��
tj�t�d��
tj�dS)NTFZ
powershell�pypsrpZrequests_credsspZurllib3)Zalways_pipeline_modulesZhas_native_async�runspace�host�_last_pipelineZ_shell_type�superr�__init__�CZ
DEFAULT_DEBUG�loggingZ	getLoggerZsetLevelZWARNING�INFO)�self�args�kwargs��	__class__��C/usr/lib/python3.9/site-packages/ansible/plugins/connection/psrp.pyr%\szConnection.__init__c
sttstdtt���tt|���|��tj	d|j
|j|jf|jd�|j
�sptfi|j��}t�}tddddd|d�|_t||j|jd�|_
tjd|j|j|jjf|jd�z|j
��Wn�ty�}ztdt|���WYd}~nvd}~0t�y*}ztd	t|���WYd}~nBd}~0ttf�yb}ztd
t|���WYd}~n
d}~00d|_d|_ |S)Nz,pypsrp or dependencies are not installed: %sz7ESTABLISH PSRP CONNECTION FOR USER: %s ON PORT %s TO %s�r"FzAnsible PSRP Host)r"�configuration_namez8PSRP OPEN RUNSPACE: auth=%s configuration=%s endpoint=%sz*failed to authenticate with the server: %sz0psrp connection failure during runspace open: %sz*Failed to connect to the host via PSRP: %sT)!�
HAS_PYPSRPrr�PYPSRP_IMP_ERRr$r�_connect�
_build_kwargs�display�vvv�
_psrp_user�
_psrp_port�
_psrp_hostr!r�_psrp_conn_kwargsrrr"r�_psrp_configuration_name�vvvvv�
_psrp_auth�	transportZendpoint�openrrrrr�
_connectedr#)r)�
connectionZhost_ui�er,r.r/r4lsd�������������zConnection._connectc
Csv|jsd|_dSz|��Wn6tyR}zt�dt|��WYd}~n
d}~00tjd|jd�d|_|�	�dS)Nz*PSRP reset - failed to closed runspace: %szPSRP: Reset Connectionr0)
rAr!�close�	Exceptionr6�debugrr=r:r4)r)rCr.r.r/�reset�s(zConnection.resetNcs�tt|�j|||d�|�d�t�d�r�t�|�d�d�}t	|d�}t	|ddd�}|r�|�d	�r�t
|��d
dd��}td|��|j
�d
d
d
�}||kr�t�d�q�tjd||jd�n t	d|�}tjd||jd�|�||�\}}	}
||	|
fS)N)�in_data�sudoable� z -EncodedCommand���z	utf-16-le�surrogate_or_strictZpassthru)�errors�	nonstringz#!r�z=cannot run the interpreter '%s' on the psrp connection pluginrz!PSRP: EXEC (via pipeline wrapper)z
PSRP: EXEC %sr0z%s
exit $LASTEXITCODE)r$r�exec_command�
startswith�joinr�base64�	b64decode�splitrr�
splitlinesr�_shellZbuild_module_commandr6r7r:�_exec_psrp_script)r)�cmdrHrIZ	b_command�scriptZinterpreterZbootstrap_wrapper�rc�stdout�stderrr,r.r/rP�s(�
�zConnection.exec_commandcs*tt�������j����tjd��f�jd�d}t�j	j
jddd��t��t
�dd��tj���s�td	t����������fd
d�}�j||��gd�\}}}|d
kr�tt|���t�t|��}���}	|�d�}
|
�stdt|�t|�f��|
|	k�s&tdt|
�t|	�f��dS)NzPUT %s TO %sr0a�begin {
    $ErrorActionPreference = "Stop"
    $WarningPreference = "Continue"
    $path = $MyInvocation.UnboundArguments[0]
    $fd = [System.IO.File]::Create($path)
    $algo = [System.Security.Cryptography.SHA1CryptoServiceProvider]::Create()
    $bytes = @()

    $bindingFlags = [System.Reflection.BindingFlags]'NonPublic, Instance'
    Function Get-Property {
        <#
        .SYNOPSIS
        Gets the private/internal property specified of the object passed in.
        #>
        Param (
            [Parameter(Mandatory=$true, ValueFromPipeline=$true)]
            [System.Object]
            $Object,

            [Parameter(Mandatory=$true, Position=1)]
            [System.String]
            $Name
        )

        $Object.GetType().GetProperty($Name, $bindingFlags).GetValue($Object, $null)
    }

    Function Set-Property {
        <#
        .SYNOPSIS
        Sets the private/internal property specified on the object passed in.
        #>
        Param (
            [Parameter(Mandatory=$true, ValueFromPipeline=$true)]
            [System.Object]
            $Object,

            [Parameter(Mandatory=$true, Position=1)]
            [System.String]
            $Name,

            [Parameter(Mandatory=$true, Position=2)]
            [AllowNull()]
            [System.Object]
            $Value
        )

        $Object.GetType().GetProperty($Name, $bindingFlags).SetValue($Object, $Value, $null)
    }

    Function Get-Field {
        <#
        .SYNOPSIS
        Gets the private/internal field specified of the object passed in.
        #>
        Param (
            [Parameter(Mandatory=$true, ValueFromPipeline=$true)]
            [System.Object]
            $Object,

            [Parameter(Mandatory=$true, Position=1)]
            [System.String]
            $Name
        )

        $Object.GetType().GetField($Name, $bindingFlags).GetValue($Object)
    }

    # MaximumAllowedMemory is required to be set to so we can send input data that exceeds the limit on a PS
    # Runspace. We use reflection to access/set this property as it is not accessible publicly. This is not ideal
    # but works on all PowerShell versions I've tested with. We originally used WinRS to send the raw bytes to the
    # host but this falls flat if someone is using a custom PS configuration name so this is a workaround. This
    # isn't required for smaller files so if it fails we ignore the error and hope it wasn't needed.
    # https://github.com/PowerShell/PowerShell/blob/c8e72d1e664b1ee04a14f226adf655cced24e5f0/src/System.Management.Automation/engine/serialization.cs#L325
    try {
        $Host | Get-Property 'ExternalHost' | `
            Get-Field '_transportManager' | `
            Get-Property 'Fragmentor' | `
            Get-Property 'DeserializationContext' | `
            Set-Property 'MaximumAllowedMemory' $null
    } catch {}
}
process {
    $bytes = [System.Convert]::FromBase64String($input)
    $algo.TransformBlock($bytes, 0, $bytes.Length, $bytes, 0) > $null
    $fd.Write($bytes, 0, $bytes.Length)
}
end {
    $fd.Close()

    $algo.TransformFinalBlock($bytes, 0, 0) > $null
    $hash = [System.BitConverter]::ToString($algo.Hash).Replace('-', '').ToLowerInvariant()
    Write-Output -InputObject "{`"sha1`":`"$hash`"}"
}
�R��rL�rMz#file or module does not exist: "%s"c3s�d}t�d����t��fdd�d�D]P}t|�}||7}��|�tjd��||f�jd�t�|�}t	|�gVq$|dkr�dgVWd�n1s�0YdS)	Nr�rbcs
����S)N)�readr.)�buffer_size�src_fdr.r/�<lambda>F�z7Connection.put_file.<locals>.read_gen.<locals>.<lambda>rgz%PSRP PUT %s to %s (offset=%d, size=%dr0r)
r@�iter�len�updater6r=r:rSZ	b64encoder)�offsetZb_dataZdata_lenZb64_data�Z	b_in_pathrd�in_path�out_pathr)Z	sha1_hash)rer/�read_genBs
�
z%Connection.put_file.<locals>.read_gen)�	argumentsrrz8Remote sha1 was not returned, stdout: '%s', stderr: '%s'z0Remote sha1 hash %s does not match local hash %s)r$r�put_filerW�_unquoter6r7r:�intr!rB�max_payload_sizerr
�os�path�existsrrrXr�json�loadsrZ	hexdigest�get)r)rmrnZcopy_scriptror[r\r]Z
put_outputZ
local_sha1Zremote_sha1r,rlr/rq�s0b
�
�zConnection.put_filecs�tt|��||�tjd||f|jd�|j�|�}|�dd�}t	|j
jj|j
jjdd�}||d}d|j�
|�|f}d	}|j|d
d�\}}}	|dkr�td
|t|	�f��n|��dkr�dSt|dd�}
d}t|
d���}tjd|||f|jd�|�||�\}}}	|dk�r0td|t|	�f��t�|���}
|�|
�t|
�|k�rZ�qh|t|
�7}q�|�d�\}}}	|dk�r�t�d|t|	�f�Wd�n1�s�0YdS)NzFETCH %s TO %sr0�\�/r_r`ia�$ErrorActionPreference = "Stop"
$path = '%s'

if (Test-Path -Path $path -PathType Leaf) {
    $fs = New-Object -TypeName System.IO.FileStream -ArgumentList @(
        $path,
        [System.IO.FileMode]::Open,
        [System.IO.FileAccess]::Read,
        [System.IO.FileShare]::Read
    )
    $buffer_size = %d
} elseif (Test-Path -Path $path -PathType Container) {
    Write-Output -InputObject "[DIR]"
} else {
    Write-Error -Message "$path does not exist"
    $host.SetShouldExit(1)
}aU$ErrorActionPreference = "Stop"
$fs.Seek(%d, [System.IO.SeekOrigin]::Begin) > $null
$buffer = New-Object -TypeName byte[] -ArgumentList $buffer_size
$bytes_read = $fs.Read($buffer, 0, $buffer_size)

if ($bytes_read -gt 0) {
    $bytes = $buffer[0..($bytes_read - 1)]
    Write-Output -InputObject ([System.Convert]::ToBase64String($bytes))
}F��use_local_scoperz.failed to setup file stream for fetch '%s': %sz[DIR]rLra�wbzPSRP FETCH %s to %s (offset=%dz#failed to transfer file to '%s': %sz$fs.Close()z3failed to close remote file stream of file '%s': %s)r$r�
fetch_filer6r7r:rWrr�replacersr!rBrt�_escaperXrr�stripr
r@r=rSrT�writeri�warning)r)rmrnZmax_b64_sizerdZsetup_scriptZread_scriptr[r\r]Z
b_out_pathrkZout_file�datar,r.r/r�fs\�
���
���

�


�zConnection.fetch_filecCsL|jr6|jjtjkr6tjd|jj|jd�|j��d|_d|_	d|_
dS)NzPSRP CLOSE RUNSPACE: %sr0F)r!�staterZOPENEDr6r=�idr:rDrAr#)r)r.r.r/rD�s�
zConnection.closecCsn|�d�|_|�d�|_|�d�|_|�d�}|�d�}|durR|durRd}d}n6|durpt|�dkrjdnd	}n|dur�|dkr�dnd}||_t|�|_|�d
�|_|�d�|_|�d�}|�d
�}|dkr�d|_	n|dur�||_	nd|_	|�d�|_
|�d�|_|�d�|_|�d�|_
t|�d��|_t|�d��|_t|�d��|_|�d�|_t|�d��|_t|�d��|_|�d�|_|�d�|_|�d�|_|�d�|_|�d�|_|�d �|_|�d!�|_|�d"�|_|�d#�|_g}t� �D]}|�!|��q�d$d%�|�d&�D�}|�"|�}|D]}	t#�$d'|	��q"t%|j|j|j|j|jdk|j|j|j	|j
|j|j
|j|j|j|j|j|j|j|j|j|j|j|jd(�|_&t't(d)��r�d*t(j)v�r�|j|j&d<n|jdu�r�t#�$d+�t't(d)��rd,t(j)v�r|j|j&d<|j|j&d<n,|jdu�r&t#�$d-�|jdu�r<t#�$d.�|�*|�D]"}	|�d&�d/|	}
|
|j&|	<�qFdS)0NZremote_addrZremote_userZremote_password�protocol�port�httpsibia�httprv�auth�cert_validationZca_cert�ignoreFT�connection_timeoutZread_timeoutZmessage_encryption�proxyZignore_proxy�operation_timeout�max_envelope_sizer1Zreconnection_retriesZreconnection_backoff�certificate_key_pem�certificate_pem�credssp_auth_mechanism�credssp_disable_tlsv1_2�credssp_minimum_version�negotiate_send_cbt�negotiate_delegate�negotiate_hostname_override�negotiate_servicecSsh|]}|�dd��qS)Z
ansible_psrp_r)r�)�.0�vr.r.r/�	<setcomp>�rgz+Connection._build_kwargs.<locals>.<setcomp>Z_extraszDansible_psrp_%s is unsupported by the current psrp version installed)Zserverr��username�passwordZsslrvr�r�r�Z
encryptionr�Zno_proxyr�r�r�r�r�r�r�r�r�r�r��FEATURESZwsman_read_timeoutz�ansible_psrp_read_timeout is unsupported by the current psrp version installed, using ansible_psrp_connection_timeout value for read_timeout instead.Zwsman_reconnectionszWansible_psrp_reconnection_retries is unsupported by the current psrp version installed.zWansible_psrp_reconnection_backoff is unsupported by the current psrp version installed.zansible_psrp_%s)+Z
get_optionr:r8Z
_psrp_passrsZ_psrp_protocolr9Z
_psrp_pathr>Z_psrp_cert_validationZ_psrp_connection_timeoutZ_psrp_read_timeoutZ_psrp_message_encryptionZ_psrp_proxyr	Z_psrp_ignore_proxyZ_psrp_operation_timeoutZ_psrp_max_envelope_sizer<Z_psrp_reconnection_retries�floatZ_psrp_reconnection_backoffZ_psrp_certificate_key_pemZ_psrp_certificate_pemZ_psrp_credssp_auth_mechanismZ_psrp_credssp_disable_tlsv1_2Z_psrp_credssp_minimum_versionZ_psrp_negotiate_send_cbtZ_psrp_negotiate_delegateZ!_psrp_negotiate_hostname_overrideZ_psrp_negotiate_servicer�values�extend�
differencer6r��dictr;�hasattrr r��intersection)r)r�r�r�Zcert_trust_pathZsupported_argsZ
auth_kwarg�
extra_argsZunsupported_args�arg�optionr.r.r/r5�s�





�
�


zConnection._build_kwargsc
Cs||jr tj|j_|j��d|_t|j�}|j||d�|rP|D]}|�|�q@|j	|d�|�
|�\}}}	||_|||	fS)Nr})�input)r#rZRUNNINGr��stoprr!Z
add_script�add_argumentZinvoke�_parse_pipeline_result)
r)rZZ
input_datar~rpZpsr�r[r\r]r.r.r/rX%s


zConnection._exec_psrp_scriptcCs|jjp|jrdnd}g}|jD]�}t|t�r�|jdur�|j}|j�	�D]\}}|�
d||f�qH|j�	�D]\}}|�
d||f�qnd�|�}nt
|dd�}|�
|�q t|jjj�dkr�||jjj7}d�|�}	g}
|jjD]z}|jr�d	|jnd
}|j�rd|jnd
}
d|t|�|
|j|jf}|j}tjd
k�rT|du�rT|d|7}|
�
|�q�t|jjj�dk�r�|
|jjj7}
d�dd�|
D��}tjd||jd�tjd|	|jd�tjd||jd�d|j_g|jj_g|jj_|t|	dd�t|dd�fS)a}
        PSRP doesn't have the same concept as other protocols with its output.
        We need some extra logic to convert the pipeline streams and host
        output into the format that Ansible understands.

        :param pipeline: The finished PowerShell pipeline that invoked our
            commands
        :return: rc, stdout, stderr based on the pipeline output
        �rNz%s: %s�
Z
simplerepr)rNz
z%s : rz%s
zJ%s%s
%s    + CategoryInfo          : %s
    + FullyQualifiedErrorId : %sr`z
StackTrace:
%scSsg|]}t|��qSr.)r)r��or.r.r/�
<listcomp>vrgz5Connection._parse_pipeline_result.<locals>.<listcomp>zPSRP RC: %dr0zPSRP STDOUT: %szPSRP STDERR: %szutf-8)�encoding)r"r[Z
had_errors�output�
isinstancerZ	to_stringZ
property_setsZadapted_properties�items�appendZextended_propertiesrRrriZuir\Zstreams�error�command_nameZinvocation_position_message�str�messageZfq_errorZscript_stacktracer6�	verbosityr]r=r:r
)r)Zpipeliner[Zstdout_listr�Z	obj_lines�key�valueZ
output_msgr\Zstderr_listr�r�ZpositionZ	error_msgZ
stacktracer]r.r.r/r�?sL



��

z!Connection._parse_pipeline_result)NT)NTN)�__name__�
__module__�__qualname__r?Z!module_implementation_preferencesZallow_executableZhas_pipeliningZallow_extrasr%r4rGrPrqr�rDr5rXr��
__classcell__r.r.r,r/rTs /'N	h
r):Z
__future__rrr�typeZ
__metaclass__Z
DOCUMENTATIONrSrxr'ruZansiblerr&Zansible.errorsrrrZ)ansible.module_utils.parsing.convert_boolr	Zansible.module_utils._textr
rrZansible.plugins.connectionr
Z ansible.plugins.shell.powershellrZansible.utils.displayrZansible.utils.hashingrr2r3r Zpypsrp.complex_objectsrrrZpypsrp.exceptionsrrZpypsrp.hostrrZpypsrp.powershellrrZpypsrp.wsmanrrZrequests.exceptionsrr�ImportError�errr6rr.r.r.r/�<module>s@/