a i@sdZgdZddlZddlZddlZddlZddlZddlmZddl m Z ddl m Z ddl mZddlmZmZdd lmZd d Zd d ZddZGdddZGdddeZGdddZdS)z>This module contains decorators for use with and without D-Bus)handle_exceptionsdbus_handle_exceptionsdbus_service_methodN) DBusException) FirewallError)errors)log)FirewallDBusExceptionNotAuthorizedException) uid_of_sendercstfdd}|S)zTDecorator to handle exceptions and log them. Used if not conneced to D-Bus. c sjz|i|WStyL}z$ttt|WYd}~n"d}~0tydtYn0dSN)rrdebug1 traceback format_excerror Exception exception)argskwargsrfunc>/usr/lib/python3.9/site-packages/firewall/server/decorators.py_impl0s z handle_exceptions.._impl) functoolswrapsrrrrrr,srcs&tfdd}t|_|S)zDecorator to handle exceptions, log and report them into D-Bus :Raises DBusException: on a firewall error code problems. c sz|i|WSty}zjtt|}|tjtjtjtjfvrVt t|nt t t t|tt|WYd}~nfd}~0ty}z|WYd}~n@d}~0ty}z ttt|WYd}~n d}~00dSr )rget_codestrrZALREADY_ENABLEDZ NOT_ENABLEDZZONE_ALREADY_SETZ ALREADY_SETrZwarningr rrrr rrr)rrrcodeexrrrr@s   z%dbus_handle_exceptions.._impl)rrinspectZ signatureZ __signature__rrrrr;s rcOs|ddtjj|i|S)zAdd sender argument for D-BusZsender_keywordsender) setdefaultdbusZservicemethodrrrrrr`s rc@s&eZdZdZiZdddZddZdS)dbus_service_method_deprecatedzRDecorator that maintains a list of deprecated methods in dbus interfaces. NcCs*||_|jr&|j|jvr&t|j|j<dSr ) interface deprecatedset)selfr(rrr__init__ks z'dbus_service_method_deprecated.__init__cs4|jr|j|jjtfdd}|S)Ncs|i|Sr rr&rrrrusz6dbus_service_method_deprecated.__call__.._impl)r(r)add__name__rrr+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 ddZ e dd Z d d Z dS) dbus_polkit_require_authzDecorator 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|jd|_d|_dSr )_busZremove_signal_receiver_bus_signal_receiver_interface_polkit)clsnameZ old_ownerZ new_ownerrrr_polkit_name_owner_changedsz3dbus_polkit_require_auth._polkit_name_owner_changedcs$tfdd}j|_|S)Ncs8tjstt_tjsHtjjtjddjdt_tjsz6t tj tjtj tj t_Wntj yYn0j}|st d|d}|r*tjrtjdd|if|idd \}}}|s*t|d n$ttj|}|d kr*t|d |i|S) NZNameOwnerChangedzorg.freedesktop.DBus)Zhandler_functionZ signal_nameZdbus_interfaceZarg0z'Not Authorized: No action_id specified.r"zsystem-bus-namer;Zpolkitruid)typer7r$Z SystemBusr8Zadd_signal_receiverr< _polkit_namer9Z InterfaceZ get_object _polkit_path_polkit_interfacerr6getZCheckAuthorizationr r )rrZ action_idr"result_r?rr+rrrsF              z0dbus_polkit_require_auth.__call__.._impl)rrr6r/rrGrr0s+z!dbus_polkit_require_auth.__call__)r.r1r2r3rArBrCr7r8r9r, classmethodr<r0rrrrr5s r5)r3__all__r$Z dbus.servicerrr!Zdbus.exceptionsrZfirewall.errorsrZfirewallrZfirewall.core.loggerrZfirewall.server.dbusr r Zfirewall.dbus_utilsr rrrr'r4r5rrrrs$     %