Your IP : 18.190.253.224


Current Path : /usr/lib/python3.6/site-packages/firewall/__pycache__/
Upload File :
Current File : //usr/lib/python3.6/site-packages/firewall/__pycache__/dbus_utils.cpython-36.pyc

3

@)�fJ�@s�dddddddddd	d
gZddlZddlZddlZdd
lmZddlmZejdkZ	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zddd�Zdd�Zddd	�Zdd
�ZdS)�command_of_pid�
pid_of_sender�
uid_of_sender�user_of_uid�context_of_sender�command_of_sender�user_of_sender�dbus_to_python�dbus_signature�%dbus_introspection_prepare_properties�!dbus_introspection_add_properties�N)�minidom)�log�3cCsPy6td|d��}|j�djdd�j�}WdQRXWntk
rJdSX|S)z  Get command for pid from /proc z/proc/%d/cmdline�rr�� N)�open�	readlines�replace�strip�	Exception)�pid�f�cmd�r� /usr/lib/python3.6/dbus_utils.pyr%s&cCsD|jdd�}tj|d�}yt|j|��}Wntk
r>dSX|S)zW Get pid from sender string using 
    org.freedesktop.DBus.GetConnectionUnixProcessID zorg.freedesktop.DBusz/org/freedesktop/DBusN)�
get_object�dbus�	Interface�intZGetConnectionUnixProcessID�
ValueError)�bus�sender�dbus_obj�
dbus_ifacerrrrr.scCsD|jdd�}tj|d�}yt|j|��}Wntk
r>dSX|S)zV Get user id from sender string using 
    org.freedesktop.DBus.GetConnectionUnixUser zorg.freedesktop.DBusz/org/freedesktop/DBusN)rrrr ZGetConnectionUnixUserr!)r"r#r$r%�uidrrrr;scCs,ytj|�}Wntk
r"dSX|dS)z Get user for uid from pwd Nr)�pwd�getpwuidr)r&ZpwsrrrrHs
c
CsP|jdd�}tj|d�}y|j|�}Wntk
r:dSXdjttt|���S)zl Get SELinux context from sender string using 
    org.freedesktop.DBus.GetConnectionSELinuxSecurityContext zorg.freedesktop.DBusz/org/freedesktop/DBusN�)	rrrZ#GetConnectionSELinuxSecurityContextr�join�map�chrr)r"r#r$r%�contextrrrrQscCstt||��S)z  Return command of D-Bus sender )rr)r"r#rrrr_scCstt||��S)N)rr)r"r#rrrrdscCs�|dkr|}�n�t|tj�r(t|�}�n�t|tj�rNtrB|jd�nt|�}�n�trjt|tj�rjt|�}�ndt|tj	�r�t|�}�nLt|tj
�s�t|tj�s�t|tj�s�t|tj
�s�t|tj�s�t|tj�s�t|tj�r�t|�}n�t|tj�r�t|�}n�t|tj��rdd�|D�}n�t|tj��r6tdd�|D��}n�t|tj��rXdd�|j�D�}nvt|t��s�t|t��s�t|t��s�t|t��s�t|t��s�t|t��s�t|t��s�t|t��r�|}ntdt|���|dk	�r�|tk�r�t|t��s�|tk�rt|t��s�|tk�r t|t��s�|tk�r8t|t��s�|tk�rPt|t��s�|tk�rht|t��s�|tk�r�t|t��r�td|t|�|f��|S)	Nzutf-8cSsg|]}t|��qSr)r)�.0�xrrr�
<listcomp>}sz"dbus_to_python.<locals>.<listcomp>cSsg|]}t|��qSr)r)r.r/rrrr0scSsi|]\}}t|�t|��qSr)r)r.�k�vrrr�
<dictcomp>�sz"dbus_to_python.<locals>.<dictcomp>zUnhandled %sz%s is %s, expected %s)�
isinstancer�Boolean�bool�String�PY2�encode�str�
UTF8String�
ObjectPath�Byte�Int16�Int32�Int64�UInt16�UInt32�UInt64r �Double�float�Array�Struct�tuple�
Dictionary�items�bytes�list�dict�	TypeError�repr�type)�objZ
expected_typeZ
python_objrrrrgsV


cCs>t|tj�rdSt|tj�r dSt|tj�r0dSt|tj�r@dSt|tj�rPdSt|tj�r`dSt|tj�rpdSt|tj	�r�dSt|tj
�r�d	St|tj�r�d
St|tj�r�dSt|tj
��r�t|j�dkr�d
|jSd|jSnXt|tj��r�d|jSt|tj��rd|jSt�r*t|tj��r*dStdt|���dS)N�b�s�o�y�n�ir/�q�u�t�d�za(%s)za%sz(%s)za{%s}zUnhandled %s)r4rr5r7r<r=r>r?r@rArBrCrDrF�lenZ	signaturerGrIr8r;rNrO)rQrrrr	�sB


cCs�|dkri}t|d�s"t|di�t|d�}i||<y|j|�}Wntk
rZi}YnXxV|j�D]J\}}dt|�i|||<||kr�|||||d<qfd|||d<qfWdS)N�_fw_dbus_propertiesrP�access�read)�hasattr�setattr�getattrZGetAllrrJr	)rQ�	interfacer_�dipZ_dict�key�valuerrrr
�s


c
Cs�tj|�}t|d�r�x�|jd�D]�}|jd�r |jd�|kr i}t|d�rTt|d�}||kr xX||j�D]H\}}|jd�}|j	d|�|j	d|d�|j	d|d�|j
|�qjWq Wtj|j
��|j
�}	|j�|	S)Nr^rd�name�propertyrPr_)r
ZparseStringraZgetElementsByTagNameZhasAttributeZgetAttributercrJZ
createElementZsetAttributeZappendChildrZdebug10Ztoxml�unlink)
rQ�datard�docZnodererfrgZpropZnew_datarrrr�s&





)N)N)�__all__rr'�sysZxml.domr
Zfirewall.core.loggerr�versionr8rrrrrrrrr	r
rrrrr�<module>s*
	

	
0%


?>