HEX
Server: Apache
System: Linux a16-asgard6.hospedagemuolhost.com.br 5.14.0-570.52.1.el9_6.x86_64 #1 SMP PREEMPT_DYNAMIC Wed Oct 15 06:39:08 EDT 2025 x86_64
User: maoristu4c3dbd03 (1436)
PHP: 8.1.33
Disabled: NONE
Upload Files
File: //usr/lib64/python3.9/site-packages/rhsmlib/dbus/__pycache__/server.cpython-39.opt-1.pyc
a

X�Zh>�@s2ddlZddlmZmZmZmZmZmZddlZ	ddl
Z	ddlZ	ddlZddl
mZddlmZddlmZddlmZddlmZddlmZdd	lmZdd
lmZmZddlmZmZm Z m!Z!m"Z"ddl#m$Z%dd
l&m'Z'er�ddl(Z	ddl)m*Z*e�+e,�Z-e�Z.e�/e.�Z0Gdd�d�Z1Gdd�d�Z2dS)�N)�Any�Dict�List�Optional�
TYPE_CHECKING�Type)�	constants)�
connection)�GLib)�partial)�config)�
pid_of_sender)�get_config_parser)�create_filesystem_watcher�DirectoryWatch)�CONSUMER_WATCHER�ENTITLEMENT_WATCHER�CONFIG_WATCHER�PRODUCT_WATCHER�SYSPURPOSE_WATCHER)�	injection)�init_logger)�
BaseObjectc@s�eZdZdZdZdd�Zdedeeee	dee
d�dd	�Zdd
d�Ze
dd
��Zdd�Zededd�dd��Zededd�dd��ZdS)�Serverz9
    Class used for rhsm.service providing D-Bus API
    NcOst�|�|_|jS)zK
        Function called, when new instance of Server is requested
        )�object�__new__�INSTANCE)�cls�args�kwargs�r �9/usr/lib64/python3.9/site-packages/rhsmlib/dbus/server.pyr=szServer.__new__zdbus._dbus.Busr)�	bus_class�bus_name�object_classes�
bus_kwargscCs�dt_tt�tjj��|p"tj	|_
|p.tj}|p6i}|p>g}g|_i|_
z|fi|��|_Wn"tjjy�t�d��Yn0t�tj�|_d}tdd}tdd}d}tj�|j
|j�|_t��|_|D]l}	z|	d|	d	}
}Wnt�y
|	}
i}Yn0|
f|
j|jd
�|��}|j�|�||j
t |
j!�<q�g}
g}g}g}g}d|j
v�r�|�|j
dj"�|
�|j
dj"�|�|j
dj"�|�|j
dj"�|�|j
dj#�d|j
v�r�|
�|j
dj$�d
|j
v�r|�|j
d
j%j"�|�|j
d
j&�d|j
v�r*|�|j
dj'�d|j
v�rH|�|j
dj(�t)|jj*|
�}t)||�}t)||�}t)||�}t)||�}t+t,|t-|t.|t/|t0|i�|_1t2j3|j1j4dd�|_5|j5�6�dS)a�
        Create a connection to a bus defined by bus_class and bus_kwargs; instantiate objects in
        object_classes; expose them under bus_name and enter a GLib mainloop.  bus_kwargs are generally
        only necessary if you're using dbus.bus.BusConnection

        The object_classes argument is a list.  The list can contain either a class or a tuple consisting
        of a class and a dictionary of arguments to send that class's constructor.
        FzCould not create bus classz/etc/rhsm/rhsm.conf�rhsmZproductCertDirZentitlementCertDirz$/etc/rhsm/syspurpose/syspurpose.jsonr�)Zobject_pathr#ZEntitlementDBusObjectZConsumerDBusObjectZConfigDBusObjectZProductsDBusObjectZSyspurposeDBusObjectzThread-FileSystemWatcher)�target�nameN)7r	ZREUSE_CONNECTIONr�parser�dbus�mainloopZglibZthreads_initrZBUS_NAMEr#�	SystemBus�objectsZ
object_map�bus�
exceptionsZ
DBusException�log�	exception�injZrequireZIDENTITY�identity�confZserviceZBusNameZconnection_namer
ZMainLoop�	TypeErrorZdefault_dbus_path�append�str�__name__�reloadZEntitlementChangedZConsumerChanged�implZ
ConfigChangedZInstalledProductsChangedZSyspurposeChangedrZ
cert_dir_pathrrrrrr�filesystem_watcher�	threading�ThreadZloop�_thread�start)�selfr"r#r$r%Zconfig_cert_dir_pathZproducts_cert_dir_pathZentitlement_cert_dir_pathZsyspurpose_cert_dir_path�item�clazzrZclazz_instanceZconsumer_dir_listZentitlement_dir_listZconfig_dir_listZproducts_dir_listZsyspurpose_dir_listZconsumer_dir_watchZentitlement_dir_watchZconfig_dir_watchZproducts_dir_watchZsyspurpose_dir_watchr r r!�__init__Ds�



��



��	�zServer.__init__c
Cs�z�zt�|j|�|j��Wn�tyL}zt�|�WYd}~nbd}~0tyx}zt�|�WYd}~n6d}~0t	y�}zt�|�WYd}~n
d}~00W|j
��|r�|��n|j
��|r�|��0dS)z�
        The two arguments, started_event and stopped_event, should be instances of threading.
        Event that will be set when the mainloop has finished starting and stopping.
        N)
r
Zidle_add�notify_startedr,�run�KeyboardInterruptr1r2�
SystemExit�	Exceptionr<�stop�set)rA�
started_eventZ
stopped_event�er r r!rF�s"

�
z
Server.runcCs|r|��dS)z�
        This callback will be run once the mainloop is up and running. It's only purpose is to alert
        other blocked threads that the mainloop is ready.
        F)rK)rLr r r!rE�szServer.notify_startedcCsX|j��|j��|j�d�|jD]}|��q&t�	d|j
���|j�|j
�dS)z�
        This method is primarily intended for uses of Server in a thread such as during testing since
        in a single-threaded program, the execution would be blocked on the mainloop and therefore
        preclude even calling this method.
        �zReleasing Bus name: N)
r,�quitr<rJr?�joinr.�remove_from_connectionr1�debugr#r/Zrelease_name)rA�objr r r!�shutdown�s



zServer.shutdown)�watcher_set�returncCsV|j}|durdS|jj��D]2\}}|dur8||vr8qt�d|���|��qdS)z�
        This function temporary disables file system directory watchers
        :param watcher_set: Set of watchers. If the watcher is None, then all watchers are disabled
        :return: None
        NzDisabling directory watcher: )rr<�dir_watches�itemsr1rRZtemporary_disable�rrUZserver_instanceZdir_watcher_idZdir_watcherr r r!�temporary_disable_dir_watchers�sz%Server.temporary_disable_dir_watcherscCsV|j}|durdS|jj��D]2\}}|dur8||vr8qt�d|���|��qdS)z�
        This function enables file system directory watchers
        :param watcher_set: Set of watcher. If the watcher is None, then all watchers are enabled
        :return: None
        NzEnabling directory watcher: )rr<rWrXr1rR�enablerYr r r!�enable_dir_watchers�szServer.enable_dir_watchers)NNNN)NN)N)N)r9�
__module__�__qualname__�__doc__rrrr8rr�dictrDrF�staticmethodrErT�classmethodrKrZr\r r r r!r6s*	�
�i


rc@s�eZdZUdZdZeed<dZeed<edd��Z	e
dd	��Ze
d
d��Zedd
��Z
ddd�Zedd�dd�Zeed�dd�Zed�dd�Zdd�Zdd�ZdS)�DomainSocketServera�This class sets up a DBus server on a domain socket. That server can then be used to perform
    registration. The issue is that we can't send registration credentials over the regular system or
    session bus since those aren't really locked down. The work-around is the client asks our service
    to open another server on a domain socket, gets socket information back, and then connects and sends
    the register command (with the credentials) to the server on the domain socket.zunix:tmpdir=�_server_socket_ifacez/run�_server_socket_pathcCs|j|jS�N)rdre�rAr r r!�_server_socketsz!DomainSocketServer._server_socketcCsr|||j|jd�}t�d||f�|�|�|j�|jd7_Wd�n1sX0Yt�d|�dS)N)�conn�sender�cmd_linezInstance: %s of %s createdr'zNew connection: %s)rjrkr1rRr7�lock�connection_count)�domain_socket_serverZ
service_classZobject_listrirSr r r!�connection_addeds�
,z#DomainSocketServer.connection_addedcCs�t�d|�|j�Z|jd8_|jdkr8t�d�n&|jdkrNt�d�nt�d|j�Wd�n1sr0YdS)NzClosed connection: %sr'rzNo connections remainzServer still has one connectionzServer still has %d connections)r1rRrlrm)rnrir r r!�connection_removed(s

z%DomainSocketServer.connection_removedcCs|jr|jjSdSdSrf)�_server�addressrgr r r!rr5szDomainSocketServer.addressNcCs�|pg|_g|_d|_||_t�|_t�d|�d��|j�|�||_	t
��|_|j�d|_
Wd�n1st0YdS)a�Create a connection to a bus defined by bus_class and bus_kwargs; instantiate objects in
        object_classes; expose them under bus_name and enter a GLib mainloop.  bus_kwargs are generally
        only necessary if you're using dbus.bus.BusConnection

        The object_classes argument is a list.  The list can contain either a class or a tuple consisting
        of a class and a dictionary of arguments to send that class's constructor.
        NzAdding sender z to the set of sendersr)r$r.rqrjrK�_sendersr1rR�addrkr=�Lockrlrm)rAr$rjrkr r r!rD<s

zDomainSocketServer.__init__)rjrVcCs|j�|�dS)z3
        Add sender to the list of senders
        N)rsrt�rArjr r r!�
add_senderQszDomainSocketServer.add_sendercCsRz|j�|�Wn&ty6t�d|�d��YdS0t�d|�d��dSdS)z=
        Try to remove sender from the set of sender
        zSender z? wasn't removed from the set of senders (not member of the set)Fz  removed from the set of sendersTN)rs�remove�KeyErrorr1rRrvr r r!�
remove_senderWsz DomainSocketServer.remove_sender)rVcCsRd}t�}t��}|jD]&}t||�}|dur:|�|�qd}q|j�|�|_|S)z�
        Check if other users are still running. It sender in the set is not
        running, then remove sender from the set, because sender could
        crash, or it was terminated since it called Start() method.
        FNT)rKr+r-rsr
rt�
difference)rAZis_one_sender_runningZnot_runningr/rj�pidr r r!�are_other_senders_still_runningds

z2DomainSocketServer.are_other_senders_still_runningcCs:|jD]}|��q|j��d|_d|_d|_d|_dSrf)r.rQrqZ
disconnectrjrk)rA�or r r!rTvs


zDomainSocketServer.shutdowncCsTtj�|j�|_|jD] }|jj�tt	j
|||j��q|jj�tt	j
|��|jSrf)r+Zserverrrhrqr$Zon_connection_addedr7rrcror.Zon_connection_removedrprr)rArCr r r!rF�s
�zDomainSocketServer.run)NNN)r9r]r^r_rdr8�__annotations__re�propertyrhrarorprrrDrw�boolrzr}rTrFr r r r!rc	s"







rc)3Zlogging�typingrrrrrrZdbus.servicer+Zdbus.serverZdbus.mainloop.glibr=Zrhsmlib.dbusrr&r	Z
gi.repositoryr
�	functoolsrZrhsmlib.servicesrZrhsmlib.dbus.dbus_utilsr
Zrhsm.configrZrhsmlib.file_monitorrrrrrrrZsubscription_managerrr3Zrhsm.logutilrZ
dbus._dbusZrhsmlib.dbus.base_objectrZ	getLoggerr9r1r*ZConfigr5rrcr r r r!�<module>s2 

T