<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet"
        integrity="sha384-GLhlTQ8iRABdZLl6O3oVMWSktQOp6b7In1Zl3/Jr59b6EGGoI1aFkw7cmDA6j6gD" crossorigin="anonymous">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.3.0/css/all.min.css"
        integrity="sha512-SzlrxWUlpfuzQ+pcUCosxcglQRNAq/DZjVsC0lE40xsADsfeQoEypE+enwcOiGjk/bSuGGKHEyjSoQ1zVisanQ=="
        crossorigin="anonymous" referrerpolicy="no-referrer" />
</head>
</html>
3
uAcI$                 @   s   d Z ddlmZ ddlZddlZddlmZ ddlmZ ddlm	Z	 dd	d
dddgZ
dd ZdZG dd
 d
eZdeddfdd	ZG dd dejZG dd deZe Zdd Zdi fddZdS )zmThis module contains convenience decorators and functions for using
PolicyKit with dbus services and clients.    )absolute_importN)	decorator)reduce   )method_call_no_timeoutrequire_authenable_proxyAUTHFAIL_DONTCATCHNotAuthorizedExceptionAreAuthorizationsObtainableIsSystemBusNameAuthorizedAsyncc                s    fdd}|S )u   Decorator for DBus service methods.

    Specify that a user needs a specific PolicyKit authorization `polkit_auth´
    to execute it.c                s   t | d  | S )NZ_slip_polkit_auth_required)setattr)method)polkit_auth /usr/lib/python3.6/polkit.pyrequire_auth_decorator/   s    z,require_auth.<locals>.require_auth_decoratorr   )r   r   r   )r   r   r   )   s    zBorg.fedoraproject.slip.dbus.service.PolKit.NotAuthorizedException.c               @   s   e Zd ZdS )r	   N)__name__
__module____qualname__r   r   r   r   r	   <   s   c                s6   fdd | dk	r"t  | S  fdd}|S dS )u  Decorator for DBus proxy methods.

    Let's you (optionally) specify either a result value or an exception type
    and a callback which is returned, thrown or called respectively if a
    PolicyKit authorization doesn't exist or can't be obtained in the DBus
    mechanism, i.e. an appropriate DBus exception is thrown.

    An exception constructor may and a callback must accept an `action_id´
    parameter which will be set to the id of the PolicyKit action for which
    authorization could not be obtained.

    Examples:

    1) Return `False´ in the event of an authorization problem, and call
    `error_handler´:

        def error_handler(action_id=None):
            print "Authorization problem:", action_id

        class MyProxy(object):
            @polkit.enable_proxy(authfail_result=False,
                                 authfail_callback=error_handler)
            def some_method(self, ...):
                ...

    2) Throw a `MyAuthError´ instance in the event of an authorization problem:

        class MyAuthError(Exception):
            def __init__(self, *args, **kwargs):
                action_id = kwargs.pop("action_id")
                super(MyAuthError, self).__init__(*args, **kwargs)
                self.action_id = action_id

        class MyProxy(object):
            @polkit.enable_proxy(authfail_exception=MyAuthError)
            def some_method(self, ...):
                ...c                s   y
| ||S  t jk
r } zr|j }|jts2 |ttd  } d k	rT |d d k	ry|d}W n    }Y nX |tkr S d }~X nX d S )N)	action_id)dbusDBusExceptionZget_dbus_name
startswithAUTH_EXC_PREFIXlenr	   )funcpkeZexc_namer   Zaf_exc)authfail_callbackauthfail_exceptionauthfail_resultr   r   _enable_proxyv   s$    


z#enable_proxy.<locals>._enable_proxyNc                s
   t  | S )N)r   )r   )r#   r   r   decorate   s    zenable_proxy.<locals>.decorate)r   )r   r"   r!   r    r$   r   )r#   r    r!   r"   r   r   @   s
    6
c                   s$   e Zd ZdZdZ fddZ  ZS )r
   zqException which a DBus service method throws if an authorization
    required for executing it can't be obtained.zAorg.fedoraproject.slip.dbus.service.PolKit.NotAuthorizedExceptionc                s(   | j jd | | _tt| j|| d S )N.)	__class___dbus_error_namesuperr
   __init__)selfr   r   r   )r&   r   r   r)      s    
zNotAuthorizedException.__init__)r   r   r   __doc__r'   r)   __classcell__r   r   )r&   r   r
      s   c               @   s   e Zd ZdZdZdZdZdZdZdZ	dZ
edd Zedd	 Zed
d Zedd Zedd Zdd Zdd Zdd Zdi fddZdS )PolKitz"Convenience wrapper around polkit.zorg.freedesktop.PolicyKit1z%/org/freedesktop/PolicyKit1/Authorityz$org.freedesktop.PolicyKit1.AuthorityNc             C   s4   || j kr0tjr0tjjtj d t_d t_d t_d S )N)
_dbus_namer-   _PolKit__busZremove_signal_receiver_PolKit__signal_receiver_PolKit__interface)clsnameZ	old_ownerZ	new_ownerr   r   r   _on_name_owner_changed   s
    zPolKit._on_name_owner_changedc             C   s0   t js*tj t _t jj| jdd| jdt _t jS )NZNameOwnerChangedzorg.freedesktop.DBus)Zhandler_functionZsignal_nameZdbus_interfaceZarg0)r-   r/   r   Z	SystemBusZadd_signal_receiverr4   r.   r0   )r*   r   r   r   _bus   s    
zPolKit._busc             C   s   t js| jj t _t jS )N)r-   _PolKit__bus_namer5   Zget_unique_name)r*   r   r   r   	_bus_name   s    zPolKit._bus_namec             C   sF   t js@y"tj| jj| j| j| jt _W n tj	k
r>   Y nX t jS )N)
r-   r1   r   	Interfacer5   
get_objectr.   
_dbus_path_dbus_interfacer   )r*   r   r   r   
_interface   s    

zPolKit._interfacec             C   s
   t | jS )N)boolr<   )r*   r   r   r   _polkit_present   s    zPolKit._polkit_presentc          	   C   s>   | j jdd}tj|d}y|j|}W n   d }Y nX |S )Nzorg.freedesktop.DBusz/org/freedesktop/DBus)r5   r9   r   r8   ZGetConnectionUnixUser)r*   system_bus_nameZ
bus_objectZbus_interfaceZuidr   r   r   Z__dbus_system_bus_name_uid   s    
z!PolKit.__dbus_system_bus_name_uidc             C   s6   | j s
dS | jjdd| jif|i dd\}}}|p4|S )NTzsystem-bus-namer3   r    )r>   r<   CheckAuthorizationr7   )r*   Zauthorizationis_authorizedis_challengedetailsr   r   r   Z__authorization_is_obtainable   s    z$PolKit.__authorization_is_obtainablec                s8    j s
dS t|tttfs |f}t fdd|d}|S )NTc                s   | o j |S )N)$_PolKit__authorization_is_obtainable)xy)r*   r   r   <lambda>   s    z4PolKit.AreAuthorizationsObtainable.<locals>.<lambda>)r>   
isinstancetuplelistsetr   )r*   authorizationsZ
obtainabler   )r*   r   r      s    
z"PolKit.AreAuthorizationsObtainableTc       	   
      sd   | j s  |d kp| j|dkS d}|r0|dO } fdd}| jjdd|if|||d||td d S )	Nr   r   c                s   | \}}} | d S )Nr   )argsrB   rC   rD   )reply_handlerr   r   reply_cb  s    
z7PolKit.IsSystemBusNameAuthorizedAsync.<locals>.reply_cbzsystem-bus-namer3   r@   )rO   error_handlerZtimeout)r>   !_PolKit__dbus_system_bus_name_uidr<   rA   r   )	r*   r?   r   rO   rQ   	challengerD   flagsrP   r   )rO   r   r      s    

z%PolKit.IsSystemBusNameAuthorizedAsync)r   r   r   r+   r.   r:   r;   r1   r/   r6   r0   classmethodr4   propertyr5   r7   r<   r>   rR   rE   r   r   r   r   r   r   r-      s"   
r-   c             C   s
   t j| S )N)__polkitr   )rM   r   r   r   r     s    Tc             C   s   t j| |||||S )N)rW   r   )r?   r   rO   rQ   rS   rD   r   r   r   r     s    
)r+   Z
__future__r   collectionsr   r   	functoolsr   Z	constantsr   __all__r   r   objectr	   r   r   r
   r-   rW   r   r   r   r   r   r   <module>   s(   Wo