Current File : //lib/python3.9/site-packages/firewall/server/__pycache__/decorators.cpython-39.pyc
a

���g��@s�dZgd�ZddlZddlZddlZddlZddlZddlmZddl	m
Z
ddlmZddl
mZddlmZmZdd	lmZd
d�Zdd
�Zdd�ZGdd�d�ZGdd�de�ZGdd�d�ZdS)z>This module contains decorators for use with and without D-Bus)�handle_exceptions�dbus_handle_exceptions�dbus_service_method�N)�
DBusException)�
FirewallError)�errors)�log)�FirewallDBusException�NotAuthorizedException)�
uid_of_sendercst����fdd��}|S)zTDecorator to handle exceptions and log them. Used if not conneced
    to D-Bus.
    c
sjz�|i|��WStyL}z$t�t���t�|�WYd}~n"d}~0tydt��Yn0dS�N)rr�debug1�	traceback�
format_exc�error�	Exception�	exception)�args�kwargsr��func��>/usr/lib/python3.9/site-packages/firewall/server/decorators.py�_impl0sz handle_exceptions.<locals>._impl)�	functools�wraps�rrrrrr,srcs&t����fdd��}t���|_|S)z�Decorator to handle exceptions, log and report them into D-Bus

    :Raises DBusException: on a firewall error code problems.
    c
s�z�|i|��WSty�}zjt�t|��}|tjtjtjtjfvrVt�	t|��nt�
t���t�
t|��tt|���WYd}~nfd}~0ty�}z|�WYd}~n@d}~0ty�}z t��tt|���WYd}~n
d}~00dSr)r�get_code�strrZALREADY_ENABLEDZNOT_ENABLEDZZONE_ALREADY_SETZALREADY_SETrZwarningr
rrrr	rrr)rrr�code�exrrrr@s 
� z%dbus_handle_exceptions.<locals>._impl)rr�inspectZ	signatureZ
__signature__rrrrr;srcOs|�dd�tjj|i|��S)zAdd sender argument for D-BusZsender_keyword�sender)�
setdefault�dbusZservice�method�rrrrrr`src@s&eZdZdZiZddd�Zdd�ZdS)�dbus_service_method_deprecatedzRDecorator that maintains a list of deprecated methods in dbus
    interfaces.
    NcCs*||_|jr&|j|jvr&t�|j|j<dSr)�	interface�
deprecated�set)�selfr(rrr�__init__ksz'dbus_service_method_deprecated.__init__cs4|jr|j|j��j�t����fdd��}|S)Ncs�|i|��Srrr&rrrrusz6dbus_service_method_deprecated.__call__.<locals>._impl)r(r)�add�__name__rr�r+rrrrr�__call__qs
z'dbus_service_method_deprecated.__call__)N)r.�
__module__�__qualname__�__doc__r)r,r0rrrrr'es
r'c@seZdZdZdS)�dbus_service_signal_deprecatedzRDecorator that maintains a list of deprecated signals in dbus
    interfaces.
    N)r.r1r2r3rrrrr4zsr4c@sDeZdZdZdZdZdZdZdZdZ	dd�Z
edd	��Zd
d�Z
dS)�dbus_polkit_require_authz�Decorator factory that checks if the interface/method can be used by the
    sender/user. Assumes wrapped function is a method inside a class derived
    from DbusServiceObject.
    zorg.freedesktop.PolicyKit1z%/org/freedesktop/PolicyKit1/Authorityz$org.freedesktop.PolicyKit1.AuthorityNcCs
||_dSr)�_polkit_auth_required)r+Zpolkit_auth_requiredrrrr,�sz!dbus_polkit_require_auth.__init__cCs|j�|j�d|_d|_dSr)�_busZremove_signal_receiver�_bus_signal_receiver�_interface_polkit)�cls�nameZ	old_ownerZ	new_ownerrrr�_polkit_name_owner_changed�sz3dbus_polkit_require_auth._polkit_name_owner_changedcs$t�����fdd��}�j|_|S)Ncs8t��jst��t��_t��jsHt��jjt��jdd�jd�t��_t��js�z6t�	t��j�
t��jt��j�t��j�t��_Wntj
y�Yn0�j}|s�t�
d��|�d�}|�r*t��j�rt��j�dd|if|idd	�\}}}|�s*t|d
��n$tt��j|�}|dk�r*t|d���|i|��S)
NZNameOwnerChangedzorg.freedesktop.DBus)Zhandler_functionZsignal_nameZdbus_interfaceZarg0z'Not Authorized: No action_id specified.r"zsystem-bus-namer;��Zpolkitr�uid)�typer7r$Z	SystemBusr8Zadd_signal_receiverr<�_polkit_namer9Z	InterfaceZ
get_object�_polkit_path�_polkit_interfacerr6�getZCheckAuthorizationr
r)rrZ	action_idr"�result�_r?�rr+rrr�sF


�
��



�


z0dbus_polkit_require_auth.__call__.<locals>._impl)rrr6r/rrGrr0�s+z!dbus_polkit_require_auth.__call__)r.r1r2r3rArBrCr7r8r9r,�classmethodr<r0rrrrr5�s
r5)r3�__all__r$Zdbus.servicerrr!Zdbus.exceptionsrZfirewall.errorsrZfirewallrZfirewall.core.loggerrZfirewall.server.dbusr	r
Zfirewall.dbus_utilsrrrrr'r4r5rrrr�<module>s$%