관리-도구
편집 파일: decorators.cpython-39.pyc
a �������g�����������������������@���s����d�Z�g�d�ZddlZddlZddlZddlZddlZddlmZ�ddl m Z �ddlmZ�ddl mZ�ddlmZmZ�dd lmZ�d d��Zdd ��Zdd��ZG�dd��d�ZG�dd��de�ZG�dd��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_senderc��������������������s���t�������fdd��}|S�)zTDecorator to handle exceptions and log them. Used if not conneced to D-Bus. c��������������� ������sj���z��|�i�|��W�S��t�yL�}�z$t�t�����t�|��W�Y�d�}~n"d�}~0��tyd���t����Y�n0�d�S��N)r���r����debug1� traceback� format_exc�error� Exception� exception)�args�kwargsr�����func���>/usr/lib/python3.9/site-packages/firewall/server/decorators.py�_impl0���s����z handle_exceptions.<locals>._impl)� functools�wraps�r���r���r���r���r���r���,���s����r���c��������������������s&���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�|��W�S��t�y��}�zjt��t|��}|tjtjtjtjfv�rVt� t|���nt� t�����t� t|���tt|���W�Y�d�}~nfd�}~0��ty��}�z|�W�Y�d�}~n@d�}~0��ty��}�z t����tt|���W�Y�d�}~n d�}~0�0�d�S�r���)r����get_code�strr���ZALREADY_ENABLEDZNOT_ENABLEDZZONE_ALREADY_SETZALREADY_SETr���Zwarningr ���r���r���r���r ���r���r���r���)r���r���r����code�exr���r���r���r���@���s ���� � z%dbus_handle_exceptions.<locals>._impl)r���r����inspectZ signatureZ __signature__r���r���r���r���r���;���s����r���c������������������O���s���|��dd��tjj|�i�|��S�)zAdd sender argument for D-BusZsender_keyword�sender)� setdefault�dbusZservice�method�r���r���r���r���r���r���`���s����r���c�������������������@���s&���e�Zd�ZdZi�Zddd�Zdd��ZdS�)�dbus_service_method_deprecatedzRDecorator that maintains a list of deprecated methods in dbus interfaces. Nc�����������������C���s*���||�_�|�j�r&|�j�|�jvr&t��|�j|�j�<�d�S�r���)� interface� deprecated�set)�selfr(���r���r���r����__init__k���s����z'dbus_service_method_deprecated.__init__c��������������������s4���|�j�r|�j|�j�����j��t������fdd��}|S�)Nc���������������������s�����|�i�|��S�r���r���r&���r���r���r���r���u���s����z6dbus_service_method_deprecated.__call__.<locals>._impl)r(���r)����add�__name__r���r����r+���r���r���r���r���r����__call__q���s ����z'dbus_service_method_deprecated.__call__)N)r.���� __module__�__qualname__�__doc__r)���r,���r0���r���r���r���r���r'���e���s��� r'���c�������������������@���s���e�Zd�ZdZdS�)�dbus_service_signal_deprecatedzRDecorator that maintains a list of deprecated signals in dbus interfaces. N)r.���r1���r2���r3���r���r���r���r���r4���z���s���r4���c�������������������@���sD���e�Zd�ZdZdZdZdZdZdZdZ dd��Z edd ���Zd 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.AuthorityNc�����������������C���s ���||�_�d�S�r���)�_polkit_auth_required)r+���Zpolkit_auth_requiredr���r���r���r,�������s����z!dbus_polkit_require_auth.__init__c�����������������C���s���|�j��|�j��d�|�_d�|�_d�S�r���)�_busZremove_signal_receiver�_bus_signal_receiver�_interface_polkit)�cls�nameZ old_ownerZ new_ownerr���r���r����_polkit_name_owner_changed����s����z3dbus_polkit_require_auth._polkit_name_owner_changedc��������������������s$���t��������fdd��}�j|_|S�)Nc���������������������s8��t���jst���t���_t���jsHt���jjt���jdd�jd�t���_t���js�z6t� t���j� t���jt���j�t���j�t���_W�n�tj y����Y�n0��j}|s�t� d��|�d�}|�r*t���j�rt���j�dd|if|i�dd �\}}}|�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)�typer7���r$���Z SystemBusr8���Zadd_signal_receiverr<����_polkit_namer9���Z InterfaceZ get_object�_polkit_path�_polkit_interfacer���r6����getZCheckAuthorizationr ���r���)r���r���Z action_idr"����result�_r?����r���r+���r���r���r�������sF���� � �� � z0dbus_polkit_require_auth.__call__.<locals>._impl)r���r���r6���r/���r���rG���r���r0�������s����+z!dbus_polkit_require_auth.__call__)r.���r1���r2���r3���rA���rB���rC���r7���r8���r9���r,����classmethodr<���r0���r���r���r���r���r5�������s��� r5���)r3����__all__r$���Zdbus.servicer���r���r!���Zdbus.exceptionsr���Zfirewall.errorsr���Zfirewallr���Zfirewall.core.loggerr���Zfirewall.server.dbusr ���r ���Zfirewall.dbus_utilsr���r���r���r���r'���r4���r5���r���r���r���r����<module>���s$���%