HEX
Server: Apache
System: Linux insrv.serversdaddy.com 5.14.0-362.24.2.el9_3.x86_64 #1 SMP PREEMPT_DYNAMIC Sat Mar 30 14:11:54 EDT 2024 x86_64
User: jsaha (1066)
PHP: 8.3.6
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //proc/self/root/usr/lib/python3.9/site-packages/cockpit/__pycache__/superuser.cpython-39.pyc
a

���e�$�@s:ddlZddlZddlZddlZddlZddlZddlZddlmZddl	m
Z
mZmZm
Z
ddlmZddlmZddlmZmZddlmZdd	lmZmZdd
lmZddlmZmZmZddl m!Z!dd
l"m#Z#m$Z$m%Z%e�&e'�Z(Gdd�de�Z)Gdd�dej*�Z+Gdd�de+�Z,Gdd�de%e+ej-dd�Z.dS)�N)�TemporaryDirectory)�List�Optional�Sequence�Tuple)�ferny)�make_bootloader)�Variant�bus�)�BridgeBeibootHelper)�
JsonObject�get_str)�BridgeConfig)�ConfiguredPeer�Peer�	PeerError)�PolkitAgent)�Router�RoutingError�RoutingRulecsBeZdZUejed<eeejd��fdd�Zdd�dd�Z	�Z
S)	�
SuperuserPeer�	responder)�router�configrcst��||�||_dS�N)�super�__init__r)�selfrrr��	__class__��5/usr/lib/python3.9/site-packages/cockpit/superuser.pyr-szSuperuserPeer.__init__N��returnc	�stt��4IdH��F}d|jvrDt�d|j�|�t|j��IdHnt�d|j�t�	|j�}d|j
vr�|�t��}t�
|�}d|��g}n|j
}|j|j||dd�IdH}d|jvr�t�d	|j�t|d
g�}|�|�|�t|jtjd����z|��IdHWn:tj�y@}ztdt|�d
�|�WYd}~n
d}~00Wd�IdH�qp1IdH�sf0YdS)NZpkexecz-connecting polkit superuser peer transport %rz1connecting non-polkit superuser peer transport %rzSUDO_ASKPASS=ferny-askpassz
SUDO_ASKPASS=T)�stderrZstart_new_sessionz# cockpit-bridgez$going to beiboot superuser bridge %rz--privileged)Zgadgetszauthentication-failed)�message)�
contextlib�AsyncExitStack�args�logger�debug�enter_async_contextrrrZInteractionAgent�env�
enter_contextrZwrite_askpass_to_tmpdirZspawnrZadd_handler�writerZstepsZBEIBOOT_GADGETS�encodeZcommunicateZInteractionErrorr�str)	r�contextZagentZtmpdirZ
ferny_askpassr-Z	transport�helper�excr!r!r"�do_connect_transport1s*




z"SuperuserPeer.do_connect_transport)�__name__�
__module__�__qualname__r�InteractionResponder�__annotations__rrrr5�
__classcell__r!r!rr"r*s

rc@s*eZdZdZeeeeedd�dd�ZdS)�CockpitResponder)z
ferny.askpass�cockpit.send-stderrN)�commandr)�fdsr%r$c
�sj|dkrftj|dd��>}|�d�|�dgtjtjt�ddg�fg�Wd�n1s\0YdS)Nr=r)�fileno��i�)�socket�popZsendmsgZ
SOL_SOCKETZ
SCM_RIGHTS�array)rr>r)r?r%Zsockr!r!r"�do_custom_commandSs
z"CockpitResponder.do_custom_command)	r6r7r8Zcommandsr1rr�intrGr!r!r!r"r<Psr<c@s.eZdZed�dd�Zeeeed�dd�ZdS)�AuthorizeResponder�rcCs
||_dSrrJ)rrr!r!r"r\szAuthorizeResponder.__init__��messages�prompt�hintr$c�s6d�dd�t���d�D��}|j�d|���IdHS)N�css|]}|d�VqdS)Z02xNr!��.0�cr!r!r"�	<genexpr>`�z0AuthorizeResponder.do_askpass.<locals>.<genexpr>�asciizplain1:)�join�getpassZgetuserr0rZrequest_authorization)rrLrMrNZhexuserr!r!r"�
do_askpass_szAuthorizeResponder.do_askpassN)r6r7r8rrr1rXr!r!r!r"rI[srIcsteZdZUdZeeed<eej	ed<ee
ed<ej�
ddddd�Zejjdgd�Zejjdd	d�Zejjd
id�Zeeed�dd
�Zeeeeed�dd�Zdd�eed��fdd�Zdd�Zeejdd�dd�Zeed�dd�Zdd �Z d!d"�Z!edd#�d$d%�Z"d&d'�Z#ejj$dgd(�edd)�d*d+��Z%ej�$�dd,�d-d.��Z&ejj$dgd(�edd/�d0d1��Z'�Z(S)2�SuperuserRoutingRuler!�superuser_configs�pending_prompt�peer�s�b�as)�value�none�a{sv})�optionsr$cCs<|�d�}|r|jdkrdS|js*|dkr0|jStd��dS)N�	superuser�root�tryz
access-denied)�get�currentr\r)rrcrdr!r!r"�
apply_rulers
zSuperuserRoutingRule.apply_rulerKc�sd|jdusJ�|dk}t����|_z2t�d|�|�d|d||�|jIdHWd|_Sd|_0dS)NZconfirmzprompting for %srO)r[�asyncioZget_running_loopZ
create_futurer*r+rM)rrLrMrNZechor!r!r"rX�s�zSuperuserRoutingRule.do_askpassF��
privileged)rrlcs8t��|�d|_d|_d|_|s.t��dkr4d|_dS)Nrre)rrr[r\�startup�os�getuidrh)rrrlrr!r"r�szSuperuserRoutingRule.__init__cCsd|_d|_dS)Nra)rhr\�rr!r!r"�	peer_done�szSuperuserRoutingRule.peer_doneN)�namerr$c
�s|jdkrt�dd��|jdus$J�|jdus2J�|jD]}||jdfvr8qdq8t�dd|�d���d|_t|j||�|_|j�	|j
�z|jj|jjd�IdHWnZt
jy�t�d	d
�d�Yn:ttfy�}zt�dt|��|�WYd}~n
d}~00|jjj|_dS)Nrazcockpit.Superuser.Errorz Superuser bridge already running�anyzUnknown superuser bridge type "�"�init)�	init_hostz!cockpit.Superuser.Error.CancelledzOperation aborted)rhr
ZBusErrorr\rmrZrrrr�add_done_callbackrq�startrvrjZCancelledError�OSErrorrr1r)rrrrrr4r!r!r"�go�s$

(zSuperuserRoutingRule.go)�configscCs�t�dt|��dd�|D�}t|�|_dd�|jD�|_dd�|D�|_t�d|j�|jdur�|jj|jvr�t�d|jjj	�|�
�dS)	Nzset_configs() with %d itemscSsg|]}|jr|�qSr!rk�rQrr!r!r"�
<listcomp>�rTz4SuperuserRoutingRule.set_configs.<locals>.<listcomp>cSsg|]
}|j�qSr!)rrr|r!r!r"r}�rTcSs*i|]"}|jr|jtdt|j�id��qS)�labelrb)r~r	rPr!r!r"�
<dictcomp>�rTz4SuperuserRoutingRule.set_configs.<locals>.<dictcomp>z  bridges are now %sz=  stopping superuser bridge '%s': it disappeared from configs)r*r+�len�tuplerZ�bridges�methodsr\rrr�stop)rr{r!r!r"�set_configs�s

z SuperuserRoutingRule.set_configscCs|jdur|j��d|_dSr)r[�cancelrpr!r!r"�
cancel_prompt�s

z"SuperuserRoutingRule.cancel_promptcCs.|��|jdur|j��|jdus*J�dSr)r�r\�closerpr!r!r"�shutdown�s

zSuperuserRoutingRule.shutdown)�paramsr$cCs<t|dd�}t|j�}t�|�||��|_|j�|j�dS)N�idrs)	rrIrrjZcreate_taskrz�
_init_taskrw�
_init_done)rr�rrrr!r!r"ru�s
zSuperuserRoutingRule.initcCs&t�d|���|jjdd�|`dS)Nzsuperuser init done! %szsuperuser-init-done)r>)r*r+�	exceptionrZ
write_controlr�)rZtaskr!r!r"r��szSuperuserRoutingRule._init_done)Zin_types)rrr$c�s|�||�IdHdSr)rz)rrrr!r!r"rx�szSuperuserRoutingRule.startr#cCs|��dSr)r�rpr!r!r"r��szSuperuserRoutingRule.stop)�replyr$cCs0|jdur"t�d�|j�|�n
t�d�dS)Nzresponding to pending promptz!got Answer, but no prompt pending)r[r*r+Z
set_result)rr�r!r!r"�answer�s

zSuperuserRoutingRule.answer))r6r7r8rZrrr:rrjZFuturerr
Z	InterfaceZSignalrMZPropertyr�rhr�r
rrir1rXr�boolrrqrr9rzr�r�r�rur�ZMethodrxr�r�r;r!r!rr"rYds.



rYzcockpit.Superuser)Z	interface)/rFrjr'rWZloggingrnrDZtempfiler�typingrrrrZcockpit._vendorrZcockpit._vendor.bei.bootloaderrZcockpit._vendor.systemd_ctypesr	r
ZbeipackrZjsonutilr
rZpackagesrr\rrrZpolkitrrrrrZ	getLoggerr6r*rr9r<rIZObjectrYr!r!r!r"�<module>s,
&