Sindbad~EG File Manager
3
Kl�f�U � @ s� d dl Z d dlZddlmZ ddlmZ ddlmZ dd� Zdd � Zd
d� ZG dd
� d
�Z G dd� de �Z
G dd� de �Zd dlj
Z
i ZG dd� de �ZG dd� de �ZG dd� de �ZG dd� de �ZG dd� d�ZG dd� d�ZG dd� d�ZdS ) � N� )� refpolicy)�access)�utilc C s� ddl } ddl}tdd�}t|j� j� d �}|j |j|j� | �}|jd|�}|jd|�}| j ddd d
||g| j
d�j� d }tj
r�tj|�}|S )a
Obtain all of the avc and policy load messages from the audit
log. This function uses ausearch and requires that the current
process have sufficient rights to run ausearch.
Returns:
string contain all of the audit messages returned by ausearch.
r Nz/proc/uptime�rz%xz%Xz/sbin/ausearchz-mz5AVC,USER_AVC,MAC_POLICY_LOAD,DAEMON_START,SELINUX_ERRz-ts)�stdout)�
subprocess�time�open�float�read�split�closeZ localtimeZstrftime�Popen�PIPE�communicater �PY3�decode_input)r r �fdZoff�sZbootdateZboottime�output� r �/usr/lib/python3.6/audit.py�get_audit_boot_msgs s
r c C s: ddl } | jdddg| jd�j� d }tjr6tj|�}|S )a
Obtain all of the avc and policy load messages from the audit
log. This function uses ausearch and requires that the current
process have sufficient rights to run ausearch.
Returns:
string contain all of the audit messages returned by ausearch.
r Nz/sbin/ausearchz-mz5AVC,USER_AVC,MAC_POLICY_LOAD,DAEMON_START,SELINUX_ERR)r )r r r r r r r )r r r r r �get_audit_msgs2 s
r c C s6 ddl } | jdg| jd�j� d }tjr2tj|�}|S )z�Obtain all of the avc and policy load messages from /bin/dmesg.
Returns:
string contain all of the audit messages returned by dmesg.
r Nz
/bin/dmesg)r )r r r r r r r )r r r r r �get_dmesg_msgsA s
r c @ s e Zd ZdZdd� Zdd� ZdS )�AuditMessagez�Base class for all objects representing audit messages.
AuditMessage is a base class for all audit messages and only
provides storage for the raw message (as a string) and a
parsing function that does nothing.
c C s || _ d| _d S )N� )�message�header)�selfr r r r �__init__W s zAuditMessage.__init__c C s^ xX|D ]P}|j d�}t|�dkr<|dd� dkr|| _dS q|d dkr|d | _dS qW dS ) z�Parse a string that has been split into records by space into
an audit message.
This method should be overridden by subclasses. Error reporting
should be done by raise ValueError exceptions.
�=� N� zaudit(r �msgr )r
�lenr )r �recsr% �fieldsr r r �from_split_string[ s
zAuditMessage.from_split_stringN)�__name__�
__module__�__qualname__�__doc__r! r) r r r r r P s r c @ s e Zd ZdZdd� ZdS )�InvalidMessagez�Class representing invalid audit messages. This is used to differentiate
between audit messages that aren't recognized (that should return None from
the audit message parser) and a message that is recognized but is malformed
in some way.
c C s t j| |� d S )N)r r! )r r r r r r! v s zInvalidMessage.__init__N)r* r+ r, r- r! r r r r r. p s r. c @ s e Zd ZdZdd� Zdd� ZdS )�PathMessagez!Class representing a path messagec C s t j| |� d| _d S )Nr )r r! �path)r r r r r r! { s zPathMessage.__init__c C sX t j| |� xF|D ]>}|jd�}t|�dkr.q|d dkr|d dd� | _d S qW d S )Nr"