grthtrhthjhtyjytjytkergtrhtrjytjerhrfh4:24 29/09/2026a q©j]0ã@snddlZddlZddlZddlZddlZddlZddlZddlZddlZddl m Z ddl m Z ddl mZddlmZddlmZddlmZmZmZdd lmZdd lmZmZdd lmZdd lmZm Z m!Z!dd l"m#Z#ddl$m%Z%m&Z&m'Z'e (e)¡Z*e+e,dœdd„Z-ee,dœdd„Z.Gdd„deƒZ/Gdd„dej0ƒZ1Gdd„de1ƒZ2Gdd„de'e1ej3dd�Z4dS)éN)Úbasename)ÚTemporaryDirectory)ÚSequence)Úferny)Úmake_bootloader)ÚBusÚVariantÚbusé)ÚBridgeBeibootHelper)Ú JsonObjectÚget_str)Ú BridgeConfig)ÚConfiguredPeerÚPeerÚ PeerError)Ú PolkitAgent)ÚRouterÚ RoutingErrorÚ RoutingRule)Ú sudo_pathÚreturnc CsFz&tj|ddgtjtjtjdd�WdStjtfy@YdS0dS)Nz-Az--helpT)ÚstdinÚstdoutÚstderrÚcheckF)Ú subprocessÚrunZDEVNULLZCalledProcessErrorÚOSError)r©rú5/usr/lib/python3.9/site-packages/cockpit/superuser.pyÚsudo_supports_askpass!sûr!)ÚconfigrcCsB|js dSt |jd¡}|dur&dSt|ƒdkr>t|ƒs>dSdS)NFrZsudoT)Ú privilegedÚshutilÚwhichÚspawnrr!)r"Úcommandrrr Úis_valid_superuser_config0sr(csVeZdZUejed<eeejdœ‡fdd„ Zde e j dœdd„Z d d œd d „Z ‡ZS) Ú SuperuserPeerÚ responder)Úrouterr"r*cstƒ ||¡||_dS©N)ÚsuperÚ__init__r*)Úselfr+r"r*©Ú __class__rr r.>szSuperuserPeer.__init__z Sequence[str])Úargsrrc ƒsþt tjtj¡\}}t ¡}dt ¡›d�}t  ¡}|  ddddd|dd d d d œfd d dd œfdd dd œfdd|d œfdd|d œfdd|d œfddt   |d¡|dfgd œfgg¡ }|  d¡| |¡IdH|j‡fdd„|d�IdH\} } | ˆusúJ‚| S)Nzcockpit-superuser-z.servicezorg.freedesktop.systemd1z/org/freedesktop/systemd1z org.freedesktop.systemd1.ManagerÚStartTransientUnitzssa(sv)a(sa(sv))ZfailZ DescriptionÚszCockpit privileged bridge)ÚtÚvÚTypeÚexecZUserÚrootZStandardInputFileDescriptorÚhZStandardOutputFileDescriptorZStandardErrorFileDescriptorZ ExecStartza(sasb)rFTcsˆSr,rr©r/rr Úhóz4SuperuserPeer.start_transient_unit..)Úsock)ÚsocketZ socketpairZAF_UNIXZ SOCK_STREAMÚasyncioÚget_running_loopÚosÚgetpidrZdefault_systemZmessage_new_method_callr$r%Z#set_allow_interactive_authorizationZ call_asyncZcreate_connection) r/r2rZoursZtheirsZloopZ unit_nameÚsystemÚmsgÚ transportZprotocolrr;r Ústart_transient_unitBs6      ù ï   z"SuperuserPeer.start_transient_unitN©rc Ãs²t ¡4IdH�š„}|jjrBt d|j¡| t|j ƒ¡IdHnt d|j¡|j g}d|jvrœt d|j¡t |dgƒ}|  |¡t |j tjd� ¡}nd}t |¡}d|jvrØ| tƒ¡}t |¡}d|›�g}n|j}|jjd k�r|j|j|d �IdH} n|j|j||d d �IdH} |du�r2|  |¡z| ¡IdHWn:tj�y~} ztd t| ƒd�| ‚WYd} ~ n d} ~ 00WdƒIdH�q®1IdH�s¤0YdS)Nz-connecting polkit superuser peer transport %rz1connecting non-polkit superuser peer transport %rz# cockpit-bridgez$going to beiboot superuser bridge %rz --privileged)ZgadgetszSUDO_ASKPASS=ferny-askpassz SUDO_ASKPASS=r3)rT)rZstart_new_sessionzauthentication-failed)Úmessage)Ú contextlibÚAsyncExitStackr"ÚpolkitÚloggerÚdebugr2Úenter_async_contextrr*r ÚappendrZstepsrZBEIBOOT_GADGETSÚencodeZInteractionAgentÚenvÚ enter_contextrZwrite_askpass_to_tmpdirÚmethodrGr&ÚwriteZ communicateZInteractionErrorrÚstr) r/ÚcontextZ respondersÚhelperZstage1ZagentZtmpdirZ ferny_askpassrRrFÚexcrrr Údo_connect_transportls6         z"SuperuserPeer.do_connect_transport)Ú__name__Ú __module__Ú __qualname__rÚAskpassHandlerÚ__annotations__rrr.Úobjectr@Z TransportrGrZÚ __classcell__rrr0r r);s  *r)c@s&eZdZdZeddeddœdd„ZdS)ÚCockpitResponder)z ferny.askpassúcockpit.send-stderrztuple[object, ...]z list[int]N)r'r2Úfdsrrc Ãsj|dkrftj|dd��>}| d¡| dgtjtjt ddg¡fg¡Wdƒn1s\0YdS)Nrcr)ÚfilenoóÚié)r?ÚpopZsendmsgZ SOL_SOCKETZ SCM_RIGHTSÚarray)r/r'r2rdrr>rrr Údo_custom_command˜s z"CockpitResponder.do_custom_command)r[r\r]ZcommandsrVrkrrrr rb•sþrbc@s.eZdZedœdd„Zeeeddœdd„ZdS) ÚAuthorizeResponder)r+cCs||_d|_dS)NF)r+Úauthorize_attempted)r/r+rrr r.£szAuthorizeResponder.__init__ú str | None©ÚmessagesÚpromptÚhintrcÃs`|jrt d¡dSd|_d dd„t ¡ d¡Dƒ¡}|j d|›�¡IdH}|dkr\dS|S)NzAnoninteractive authorize during init already attempted, rejectingTÚcss|]}|d›VqdS)Z02xNr©Ú.0Úcrrr Ú ­r=z0AuthorizeResponder.do_askpass..Úasciizplain1:) rmrMÚinfoÚjoinÚgetpassZgetuserrQr+Zrequest_authorization)r/rprqrrZhexuserÚpasswordrrr Ú do_askpass§s zAuthorizeResponder.do_askpassN)r[r\r]rr.rVr}rrrr rl¢srlcs~eZdZUdZeeed<ded<ded<ej  ddddd¡Z ejj d gd �Z ejj dd d �Z ejj d id �Zed dœdd„Zeeeddœdd„Zddœeedœ‡fdd„Zddœdd„Zeejddœdd „Zeedd!œd"d#„Zddœd$d%„Zddœd&d'„Zedd(œd)d*„Zd+dd,œd-d.„Zejjdgd/�edd0œd1d2„ƒZ ej ¡ddœd3d4„ƒZ!ejjdgd/�edd5œd6d7„ƒZ"‡Z#S)8ÚSuperuserRoutingRulerÚsuperuser_configszasyncio.Future[str] | NoneÚpending_promptzSuperuserPeer | NoneÚpeerr4ÚbÚas)ÚvalueÚnoneúa{sv}z Peer | None)ÚoptionsrcCs<| d¡}|r|jdkrdS|js*|dkr0|jStdƒ‚dS)NÚ superuserr9Útryz access-denied)ÚgetÚcurrentr�r)r/r‡rˆrrr Ú apply_ruleÁs  zSuperuserRoutingRule.apply_rulernrocÃsd|jdusJ‚|dk}t ¡ ¡|_z2t d|¡| d|d||¡|jIdHWd|_Sd|_0dS)NZconfirmzprompting for %srs)r€r@rAZ create_futurerMrNrq)r/rprqrrZechorrr r}Ðs  þzSuperuserRoutingRule.do_askpassF)r#)r+r#cs8tƒ |¡d|_d|_d|_|s.t ¡dkr4d|_dS)Nrr9)r-r.r€r�ÚstartuprBÚgetuidr‹)r/r+r#r0rr r.Ýs  zSuperuserRoutingRule.__init__NrHcCsd|_d|_dS)Nr…)r‹r�r;rrr Ú peer_doneçszSuperuserRoutingRule.peer_done)Únamer*rc Ã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) Nr…zcockpit.Superuser.Errorz Superuser bridge already runningÚanyzUnknown superuser bridge type "ú"Úinit)Ú init_hostz!cockpit.Superuser.Error.CancelledzOperation aborted)r‹r ZBusErrorr�r�rr�r)r+Úadd_done_callbackr�Ústartr”r@ZCancelledErrorrrrVr")r/r�r*r"rYrrr Úgoës$   (zSuperuserRoutingRule.go)ÚconfigsrcCsŽt dt|ƒ¡dd„|Dƒ}t|ƒ|_dd„|jDƒ|_dd„|Dƒ|_t d|j¡|jdurŠ|jj|jvrŠt d|jjj ¡|  ¡dS) Nzset_configs() with %d itemscSsg|]}t|ƒr|‘qSr)r(©rur"rrr Ú r=z4SuperuserRoutingRule.set_configs..cSsg|] }|j‘qSr)r�r™rrr rš r=cSs*i|]"}|jr|jtdt|jƒidƒ“qS)Úlabelr†)r›rrtrrr Ú r=z4SuperuserRoutingRule.set_configs..z bridges are now %sz= stopping superuser bridge '%s': it disappeared from configs) rMrNÚlenÚtuplerÚbridgesÚmethodsr�r"r�Úshutdown)r/r˜rrr Ú set_configss  z SuperuserRoutingRule.set_configscCs|jdur|j ¡d|_dSr,)r€Úcancelr;rrr Ú cancel_prompts  z"SuperuserRoutingRule.cancel_promptcCs.| ¡|jdur|j ¡|jdus*J‚dSr,)r¤r�Úcloser;rrr r¡s  zSuperuserRoutingRule.shutdown)ÚparamsrcCs<t|ddƒ}t|jƒ}t | ||¡¡|_|j |j¡dS)NÚidr‘) r rlr+r@Z create_taskr—Ú _init_taskr•Ú _init_done)r/r¦r�r*rrr r“#s  zSuperuserRoutingRule.initzasyncio.Task[None])ÚtaskrcCs&t d| ¡¡|jjdd�|`dS)Nzsuperuser init done! %szsuperuser-init-done)r')rMrNÚ exceptionr+Z write_controlr¨)r/rªrrr r©)szSuperuserRoutingRule._init_done)Zin_types)r�rcÃs| ||¡IdHdSr,)r—)r/r�rrr r–/szSuperuserRoutingRule.startcCs | ¡dSr,)r¡r;rrr Ústop3szSuperuserRoutingRule.stop)ÚreplyrcCs0|jdur"t d¡|j |¡n t d¡dS)Nzresponding to pending promptz!got Answer, but no prompt pending)r€rMrNZ set_result)r/r­rrr Úanswer7s  zSuperuserRoutingRule.answer)$r[r\r]rrrr_r Z InterfaceZSignalrqZPropertyrŸr‹r r rŒrVr}rÚboolr.r�rr^r—r¢r¤r¡r“r©ZMethodr–r¬r®rarrr0r r~³s.    r~zcockpit.Superuser)Z interface)5rjr@rJr{ZloggingrBr$r?rZos.pathrZtempfilerÚtypingrZcockpit._vendorrZcockpit._vendor.bei.bootloaderrZcockpit._vendor.systemd_ctypesrrr Zbeipackr Zjsonutilr r Zpackagesrr�rrrrLrr+rrrZ getLoggerr[rMrVr¯r!r(r)r^rbrlZObjectr~rrrr Ús6          Z