
    h=                        S SK r S SKrS SKrS SKrS SKrS SKrS SKrS SKrS SKrS SK	J
r
JrJrJrJr  SSKJr  \R"                  " \5      r\R(                  " S5      rSrS\< S3S	S
.r " S S\5      r \R4                  rS\R:                  4S jr " S S5      r " S S\5      r  " S S5      r!S\"S\"4S jr#\RH                  S\
S\\"SS4   4S j5       r%g! \ a     SS\R                  S\S\S\SS4
S jjr N|f = f)     N)AnyCallableClassVar	GeneratorSequence   )interaction_clients    ferny ([^
]*)  
z ferny {(command, args)!r}  
zW
        import sys
        def command(command, *args):
            sys.stderr.write(fz%)
            sys.stderr.flush()
    z9
        def end():
            command('ferny.end')
    )commandendc                       \ rS rSrSrg)InteractionError3    N)__name__
__module____qualname____firstlineno____static_attributes__r       I/usr/lib/python3/dist-packages/cockpit/_vendor/ferny/interaction_agent.pyr   r   3   s    r   r   sockbufsizemaxfdsflagsreturnz"tuple[bytes, list[int], int, None]c           	         [         R                   " S5      nU R                  U[        R                  " X$R                  -  5      5      u  pVp7U Hh  u  pn
U[        R
                  :X  d  M  U	[        R                  :X  d  M2  UR                  U
S [        U
5      [        U
5      UR                  -  -
   5        Mj     U[        U5      X74$ )Ni)
arrayrecvmsgsocketCMSG_LENitemsize
SOL_SOCKET
SCM_RIGHTS	frombyteslenlist)r   r   r   r   fdsmsgancdataaddr
cmsg_level	cmsg_type	cmsg_datas              r   recv_fdsr/   <   s     kk#$(LL&//&S_S_J_:`$a!e07,J9f///IARAR4Ri(YY3y>CLL;X)YZ[ 18 DIu**r   c                  x     [         R                  " 5       $ ! [         a    [         R                  " 5       s $ f = fN)asyncioget_running_loopAttributeErrorget_event_loopr   r   r   r3   r3   G   s4    ('')) (%%''(s    99c            
       J    \ rS rSr% \\\      \S'   S\SSSSS\S	S
4
S jrSr	g
)InteractionHandlerO   commandsr
   argstuple[object, ...]r(   	list[int]stderrr   Nc                    #    [         e7fr1   )NotImplementedErrorselfr
   r:   r(   r=   s        r   run_commandInteractionHandler.run_commandR   s     !!s   	r   )
r   r   r   r   r   r   str__annotations__rB   r   r   r   r   r7   r7   O   s<    x}%%" "4H "{ "dg "lp "r   r7   c                       \ rS rSr% Sr\\\      \S'   S\S\S\SS4S	 jr	S
\S\S\S\S\S\
4S jrS\SSSSS\SS4
S jrSSSSS\SS4S jrS\SSSSS\SS4
S jrSrg)AskpassHandlerV   )ferny.askpassr9   messagesprompthintr   z
str | Nonec                    #    g7f)a  Prompt the user for an authentication or confirmation interaction.

'messages' is data that was sent to stderr before the interaction was requested.
'prompt' is the interaction prompt.

The expected response type depends on hint:

    - "confirm": ask for permission, returning "yes" if accepted
        - example: authorizing agent operation

    - "none": show a request without need for a response
        - example: please touch your authentication token

    - otherwise: return a password or other form of text token
        - examples: enter password, unlock private key

In any case, the function should properly handle cancellation.  For the
"none" case, this will be the normal way to dismiss the dialog.
Nr   )rA   rJ   rK   rL   s       r   
do_askpassAskpassHandler.do_askpassY   s
     (    reasonhost	algorithmkeyfingerprintc                    #    g7f)aA  Prompt the user for a decision regarding acceptance of a host key.

The "reason" will be either "HOSTNAME" or "ADDRESS" (if `CheckHostIP` is enabled).

The host, algorithm, and key parameters are the values in the form that
they would appear one a single line in the known hosts file.  The
fingerprint is the key fingerprint in the format that ssh would
normally present it to the user.

In case the host key should be accepted, this function needs to return
True.  Returning False means that ssh implements its default logic.  To
interrupt the connection, raise an exception.
Fr   )rA   rQ   rR   rS   rT   rU   s         r   
do_hostkeyAskpassHandler.do_hostkeyo   s
      rP   r
   r:   r;   r(   r<   r=   Nc                    #    g7f)zHandle a custom command.

The command name, its arguments, the passed fds, and the stderr leading
up to the command invocation are all provided.

See doc/interaction-protocol.md
Nr   r@   s        r   do_custom_command AskpassHandler.do_custom_command   s     rP   c           
        #    [         R                  SXU5         Uu  pE[        U[        5      (       d   e[	        S U 5       5      (       d   e[        U[
        5      (       d   e[	        S UR                  5        5       5      (       d   e[        U5      S:X  d   e [        UR                  S5      S5       n[        UR                  S5      S5       n [        5       n	 [        R                   " 5       n
U
c   eU	R'                  XzR(                  5        [        U5      S:X  au  US   nUR+                  S	S
5      n[         R                  SX;U5        U R-                  X;U5      I S h  vN n[         R                  SU5        Ub  [/        XS9  [/        SUS9  O[        U5      S:X  ax  Uu  pnnnnUS;   aI  [         R                  SUUUUU5        U R1                  UUUUU5      I S h  vN (       a  [/        UUUUS9  O[         R                  SU5        [/        SUS9  O[         R                  SU5        U	R3                  U5         S S S 5        S S S 5        g ! [        [        [        4 a!  n[         R                  SXU5         S nAg S nAff = f! ["         a"    [        R$                  R!                  5       n
 GNf = f GNZ N! W	R3                  U5        f = f! , (       d  f       N= f! , (       d  f       g = f7f)Nz_askpass_command(%s, %s, %s)c              3   B   #    U  H  n[        U[        5      v   M     g 7fr1   
isinstancerD   ).0args     r   	<genexpr>2AskpassHandler._askpass_command.<locals>.<genexpr>   s     <tz#s++ts   c              3   t   #    U  H.  u  p[        U[        5      =(       a    [        U[        5      v   M0     g 7fr1   r^   )r`   rT   vals      r   rb   rc      s*     aU`z#s+D
30DDU`s   68   z4Invalid arguments to askpass interaction: %s, %s: %sr   wr   SSH_ASKPASS_PROMPT zdo_askpass(%r, %r, %r)zdo_askpass answer %r)file   )ADDRESSHOSTNAMEzdo_hostkey(%r, %r, %r, %r, %r)z$ignoring KnownHostsCommand reason %rz?Incorrect number of command-line arguments to ferny-askpass: %s)loggerdebugr_   r'   alldictitemsr&   
ValueError	TypeErrorAssertionErrorerroropenpopr3   r2   current_taskr4   Task
add_readercancelgetrN   printrW   remove_reader)rA   r:   r(   r=   argvenvexcstatusstdoutlooptaskrK   rL   answerargv0rQ   rR   rS   rT   rU   s                       r   _askpass_commandAskpassHandler._askpass_command   s    3TG		IDdD))))<t<<<<<c4((((aUXU^U^U`aaaaas8q= =
 #''!*c"fd3771:s.Cv#+')7"//1D '''4t9>!!WF77#7<DLL!964P#'??64#HHFLL!7@)f2af-Y!^GKDE4C!88%EvtU^`cepq!%y#{![[[!$	3VD%KVT!&) LL!bdhi""6*I /D""	 I~6 	LLOQU\_`	 & 7"<<446D7 I \ ""6*I /D.C""s   LBI L:K0K
K	#J8A2K	*K+B K	+K,AK	9KK0	LJ1JLJL(K=K	 KK	K		KK
K-	)K00
K>:Lc                    #    [         R                  SXX45        US:X  a  U R                  X#U5      I S h  vN   g U R                  XX45      I S h  vN   g  N  N7f)Nzrun_command(%s, %s, %s, %s)rI   )rn   ro   r   rZ   r@   s        r   rB   AskpassHandler.run_command   sR     2G3Oo%''6:::((DDD ;Ds!   3AAAAAAr   )r   r   r   r   r9   r   r   rD   rE   rN   boolrW   rZ   r   rB   r   r   r   r   rG   rG   V   s    (:Hhx}%: c   ,s # # C ^a fj  		"6	=H	RU			1++? 1+k 1+[^ 1+cg 1+fE E4H E{ Edg Elp Er   rG   c            	       V   \ rS rSr% S\S'   \R                  \S'   S\S'   \\S'   \R                  \S'   \R                  \S	'   S
\S'   Sr	S\S'   Sr
\\S'   S'S jrS(S jrS\S\SSSS4S jrS\SSSS4S jrS'S jr  S)S\\   SSSS SS4S! jjrS\4S" jrS'S# jrS'S$ jrS'S% jrS&rg)*InteractionAgent   zdict[str, InteractionHandler]	_handlers_loopzset[asyncio.Task]_tasks_buffer_ours_theirszasyncio.Future[str]_completion_futureNzNone | str | Exception_pending_resultF_endr   c                 @   [         R                  SU 5        U R                  b  U R                  (       a  [         R                  S5        g U R                  R                  5       (       a  [         R                  S5        g [        U R                  [        5      (       aF  [         R                  SU R                  5        U R                  R                  U R                  5        g [         R                  S5        U R                  R                  U R                  5        g )Nz_consider_completion(%r)z  but not ready yetz  but already completez-  submitting stderr (%r) to completion_futurez0  submitting exception (%r) to completion_future)
rn   ro   r   r   r   doner_   rD   
set_resultset_exceptionrA   s    r   _consider_completion%InteractionAgent._consider_completion   s    /6'4;;LL./$$))++LL12,,c22LLH$J^J^_##..t/C/CD LLKL##11$2F2FGr   c                 \   [         R                  SX5        U R                  c  Xl        U R                  R	                  5       S:w  aS  [         R                  SU R                  5        U R
                  R                  U R                  R	                  5       5        U R                   H)  n[         R                  SU5        UR                  5         M+     [         R                  S5        U R                  R                  5         U R                  R                  5         U R                  5         g )Nz_result(%r, %r)z  remove_reader(%r)z    cancel(%r)z  closing sockets)rn   ro   r   r   filenor   r   r   r|   r   closer   )rA   resultr   s      r   _resultInteractionAgent._result   s    &5'#) ::"$LL.

;JJ$$TZZ%6%6%89KKDLL)40KKM   	()

!!#r   r=   command_blobr(   r<   c           	      l  ^ ^^	^
 [         R                  SXU5         [        R                  " UR	                  5       5      u  pE[        U[        5      (       a  [        U[        5      (       d  [        S5      e US:X  a0  ST l        T R                  T R                  R	                  SS95        g  T R                   U   m[%        U5      m
T R&                  R)                  TR+                  XET
UR	                  5       5      5      m	S	[,        R.                  S
S 4UU U	U
4S jjnT	R1                  U5        T R2                  R5                  T	5        / US S & g ! [        [        [        [        4 a   n[         R                  SX&5         S nAg S nAff = f! ["         a    [         R                  SU5         g f = f)Nz_invoke_command(%r, %r, %r)zInvalid argument typesz&Received invalid ferny command: %s: %sz	ferny.endTreplaceerrorsz$Received unhandled ferny command: %scompleted_taskr   c                   > U TL d   eT(       a-  [         R                  " TR                  5       5        T(       a  M-  TR                  R	                  T5         TR                  5         [        R                  ST5        TR                  5         g ! [        R                   a    [        R                  ST5         N=[         a2  n[        R                  STU5        TR                  U5         S nANsS nAff = f)Nz%r completed cleanlyz%r was cancelledz%r raised %r)osr   rx   r   remover   rn   ro   r2   CancelledError	Exceptionr   r   )r   r   handlerrA   r   task_fdss     r   bottom_half5InteractionAgent._invoke_command.<locals>.bottom_half  s    !T)))( (KKt$"3W= %%' )) :/9 "^Wc:S!!"s   &B *C7<	C7(C22C7)rn   ro   astliteral_evaldecoder_   rD   tuplert   UnicodeDecodeErrorSyntaxErrorrs   rv   r   r   r   r   KeyErrorr'   r   create_taskrB   r2   rz   add_done_callbackr   add)rA   r=   r   r(   r
   r:   r   r   r   r   r   s   `       @@@r   _invoke_command InteractionAgent._invoke_command   sq   2F#N	,,\-@-@-BCMGgs++:dE3J3J 899 4K k!DILL,,I,>?	nnW-G 9zz%%g&9&9'SYS`S`Sb&cd	( 	( 	( 	($ 	{+AQ #KYG 	LLA<U	  	LL?I	s*   AE 0F F-FF F32F3datac                    [         R                  SX5        US:X  a)  U R                  U R                  R	                  SS95        g U R                  R                  U5        [        R                  U R                  5      n[        UR                  5       5      U l        [        U5      S:  a/  U R                  US   US   / 5        USS  n[        U5      S:  a  M/  U(       a  U R                  R                  S5      (       d   U R                  5       eU R                  S S	 n[        S5      U l        [        UR                  S5      S
5       nUR                  5       nS S S 5        U R                  UWU5        g g ! , (       d  f       N#= f)Nz_got_data(%r, %r)r   r   r   r   r   rf       r   rb)rn   ro   r   r   r   extend
COMMAND_REsplit	bytearrayrx   r&   r   endswithrw   read)rA   r   r(   chunksr=   command_channelr
   s          r   	_got_dataInteractionAgent._got_data)  s;   ($43;LL,,I,>?D! !!$,,/ .&kAo  F1Ir:ABZF &kAo
 <<((//==/\\#2&F$S>DLcggaj$'?)..0 (  #6  ('s   E<<
F
c                 $    [        U R                  SS[        R                  S9u  pp4U R	                  X5        W(       a.  [        R                  " UR                  5       5        U(       a  M-  g g ! [
         a8     W(       a.  [        R                  " UR                  5       5        U(       a  M-  g g [         a  nU R                  U5         S nANS nAff = f! W(       a.  [        R                  " UR                  5       5        U(       a  M-  f f = f)N   
   )r   )r/   r   r    MSG_DONTWAITr   BlockingIOErrorr   r   rx   OSErrorr   )rA   r   r(   _flags_addrr   s         r   _read_readyInteractionAgent._read_readyB  s    
	$'/

D"FL_L_'`$Dv NN4%# #  	 # #  	LL	
 # #s@   'A0 C 0
C:C 1	C:CC CC 3DDhandlersr   z asyncio.AbstractEventLoop | Nonedone_callbackz,Callable[[asyncio.Future[str]], None] | Nonec                    U=(       d
    [        5       U l        U R                  R                  5       U l        [	        5       U l        0 U l        U H$  nUR                   H  nX@R                  U'   M     M&     Ub  U R                  R                  U5        [        R                  " [        R                  [        R                  5      u  U l        U l        [        5       U l        g r1   )r3   r   create_futurer   setr   r   r9   r   r    
socketpairAF_UNIXSOCK_STREAMr   r   r   r   )rA   r   r   r   r   r
   s         r   __init__InteractionAgent.__init__O  s     /-/
"&**":":"<eG"++*1w' ,   $##55mD#)#4#4V^^VEWEW#X dj {r   c                 6    U R                   R                  5       $ r1   )r   r   r   s    r   r   InteractionAgent.filenod  s    ||""$$r   c                    [         R                  SU 5        U R                  R                  5       S:w  a_  [         R                  SU R                  5        U R                  R                  U R                  R                  5       U R                  5        O[         R                  S5        [         R                  SU R                  5        U R                  R                  5         g )Nz	start(%r)r   z  add_reader(%r)z#  ...but agent is already finished.z  close(%r))	rn   ro   r   r   r   r{   r   r   r   r   s    r   startInteractionAgent.startg  s    [$'::"$LL+TZZ8JJ!!$**"3"3"5t7G7GHLL>?]DLL1r   c                 ~   [         R                  SU 5         U R                  R                  5       S:w  a  [         R                  S5        [        R
                  " [        5          U R                  R                  S[        R                  5      n[         R                  S[        U5      5        U(       d  OU R                  R                  U5        Mn  S S S 5        U R                  U R                  R                  SS95        g ! , (       d  f       N7= f! [         a  nU R                  U5         S nAg S nAff = f)Nzforce_completion(%r)r   z-  draining pending stderr data (non-blocking)r   z    got %d bytesr   r   )rn   ro   r   r   
contextlibsuppressr   recvr    r   r&   r   r   r   r   r   )rA   r   r   s      r   force_completion!InteractionAgent.force_completionr  s    +T2	@zz  "b(LM((9#zztV5H5HI%7TC#!++D1  : LL,,I,>? :9  	LL	s1   AD %A0DD 
DD 
D<!D77D<c                   #    [         R                  SU 5         U R                  5         [        R                  " U R
                  5      I S h  vN n[         R                  SX5        [         R                  S5        U R                  5         U R                  (       d.  [         R                  S5        [        UR                  5       5      eg  N! [         R                  S5        U R                  5         f = f7f)Nz_communicate(%r)z$_communicate(%r) stderr result is %rz,_communicate finished.  Ensuring completion.z<_communicate never saw ferny.end.  raising InteractionError.)
rn   ro   r   r2   shieldr   r   r   r   strip)rA   r=   s     r   communicateInteractionAgent.communicate  s     '.
	$JJL
 #>>$*A*ABBFLL?NLLGH!!#yyLLWX"6<<>22  C LLGH!!#s/   C93C CC (A%C9C 'C66C9)	r   r   r   r   r   r   r   r   r   )r   N)r   zstr | Exceptionr   N)NN)r   r   r   r   rE   r2   AbstractEventLoopr   r    r   r   r   r   r   bytesr   r   r   r   r7   r   intr   r   r   r   r   r   r   r   r   r      s    ..$$$==]]--04O-4D$H"$(.e .5 .{ .W[ .`7e 7+ 7$ 72$  48HL	#-.# 1# F	#
 
#*% %	@(3r   r   tmpdirc                    [         R                  R                  U S5      n[         R                  " U[         R                  [         R
                  -  [         R                  -  [         R                  -  [         R                  -  S5      n [         R                  " U[        R                  [        R                  5      5        [         R                  " U5        U$ ! [         R                  " U5        f = f)Nzferny-askpassi  )r   pathjoinrw   O_CREATO_WRONLY	O_CLOEXECO_EXCL
O_NOFOLLOWwrite
__loader__get_datar	   __file__r   )r   askpass_pathfds      r   write_askpass_to_tmpdirr    s    77<<8L	rzzBKK7",,FRUWUbUbbdi	jB
Z(();)D)DEF
 	s   8C C4kwargsc               +      #    [         R                  " S0 U D6 n[        U5      v   S S S 5        g ! , (       d  f       g = f7f)Nr   )tempfileTemporaryDirectoryr  )r  	directorys     r   temporary_askpassr    s.     		$	$	.v	.)%i00 
/	.	.s   A0	A
>A)r   )&r   r   r2   r   loggingr   rer    r
  typingr   r   r   r   r   ri   r	   	getLoggerr   rn   compiler   COMMAND_TEMPLATEBEIBOOT_GADGETSr   r   r/   r4   r   r   r3   r7   rG   r   rD   r  contextmanagerr  r   r   r   <module>r     sZ  $  
    	 	   ? ?  			8	$ ZZ23
7   02 3	y 	+H('33 (" "lE' lE^P3 P3fC C  1 1	#tT/(B 1 1U  + FG+mm+&)+36+?B+	-++s   5C "C>=C>