HEX
Server: LiteSpeed
System: Linux s1049.use1.mysecurecloudhost.com 4.18.0-477.27.2.lve.el8.x86_64 #1 SMP Wed Oct 11 12:32:56 UTC 2023 x86_64
User: xedaptot (3356)
PHP: 8.3.31
Disabled: NONE
Upload Files
File: //proc/thread-self/root/lib/python3.6/site-packages/sssd/modules/__pycache__/request.cpython-36.pyc
3

Yd�i�*�@sBddlZddlZddlmZddlmZej�ZGdd�d�ZdS)�N)�SubparsersAction)�Optionc@s�eZdZdZdZgZedded�edde�gZedd	e	�ed
de�edd
e�edde�gZ
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zdd �Zd!d"�ZdS)#�RequestAnalyzerz�
    A request analyzer module, handles request tracking logic
    and analysis. Parses input generated from a source Reader.
    Nz	--verbosezVerbose outputz-vz--pamzFilter only PAM requests�cidzTrack request with this IDz--childzInclude child process logsz--mergez'Merge logs together sorted by timestampzTrack only PAM requestscCs|jj�dS)z|
        Print the module parser help output

        Args:
            args (Namespace): argparse parsed arguments
        N)�
module_parserZ
print_help)�self�args�r	�/usr/lib/python3.6/request.py�print_module_helpsz!RequestAnalyzer.print_module_helpcCsvd}|jd|dd�|_|jjddtdd�}|jd	�}|j|d
d|j|j�|j|dd
|j|j	�|jj
|jd�|jS)z�
        Setup module parser, subcommands, and options

        Args:
            parser_grp (argparse.Action): Parser group to nest
               module and subcommands under
        zAnalyze request tracking moduleZrequestzRequest tracking)�description�helpN�	subparserZCOMMANDS)�title�dest�action�metavarzOperation Modes�listzList recent requestsZshowzTrack individual request ID)�func)Z
add_parserrZadd_subparsersrZadd_parser_groupZadd_subcommand�
list_requests�	list_opts�
track_request�	show_optsZset_defaultsr)rZ
parser_grpZcliZdescrZ
subcmd_grpr	r	r
�
setup_args&s



zRequestAnalyzer.setup_argscCs8|jdkrddlm}|�}nddlm}||j�}|S)z�
        Load the appropriate source reader.

        Args:
            args (Namespace): argparse parsed arguments

        Returns:
            Instantiated source object
        Zjournaldr)�Journald)�Files)�sourceZsssd.source_journaldrZsssd.source_filesrZlogdir)rrrrrr	r	r
�loadBs


zRequestAnalyzer.loadccsFx@|D]8}x2|D]*}tj|�}|j|�r|jd�r4q|VqWqWdS)z�
        Yield lines which match any number of patterns (OR) in
        provided patterns list.

        Args:
            source (Reader): source Reader object
        Yields:
            lines matching the provided pattern(s)
        z   *  N)�re�compile�search�
startswith)rr�patterns�line�patternZre_objr	r	r
�matched_lineTs





zRequestAnalyzer.matched_linecCsJg}x@|j||�D]0}tj|�}|j|�}|r|jd�}|j|�qW|S)a�
        Retrieve list of associated REQ_TRACE ids. Filter
        only source lines by pattern, then parse out the
        linked id with the provided regex.

        Args:
            source (Reader): source Reader object
            pattern (list of str): regex pattern(s) used for finding
                 linked ids
            regex (str): regular expression used to extract linked id

        Returns:
            List of linked ids discovered
        r)r%rrr �group�append)rrr$ZregexZ
linked_ids�matchZid_re�foundr	r	r
�get_linked_idsfs


zRequestAnalyzer.get_linked_idscCsHd}|r |jj|j|d��n$t|�jdkr<t|dd�nt|�|S)a�
        Print or consume a line, if merge cli option is provided then consume
        boolean is set to True

        Args:
            line (str): line to process
            source (Reader): source Reader object
            consume (bool): If True, line is added to consume_logs
               list, otherwise print line

        Returns:
            True if line was processed, otherwise False
        T�r�)�end���)�
consumed_logsr'�rstrip�type�__name__�print)rr#rZconsumeZ
found_resultsr	r	r
�consume_line~szRequestAnalyzer.consume_linecCs$i}x||D]t}d|krq
|jd�}|ddd�}tjd|d�}|jd�}||f|j�krr|||f|7<q
||||f<q
W�x�|j�D�]�\}}	g}
g}�xx|	j�D�]j}d}
d}d}|jd�}|dd	d�}|jd
�ddd�}tjd|��r|j|�tjd
|��r\|jd�d}
|j�|jd�}|dd	d�}|jd
�ddd�}n8tjd|��rz|j	d�d}ntjd|��r�|j	�d}|
�r�t
d|
�|�r�||
k�r�t
d|dd��|
j|�|r�d|k�s�d|kr�||kr�ttjd|��r�t
d|�|j|�q�Wq�WdS)z�
        Parse log file and print formatted verbose list_requests output

        Args:
            source (Reader): source Reader object
        zCID#�[rN�z
CID#[0-9]*�r,��:�z\[cmdZcache_req_send�'r+Zcache_req_process_inputZcache_req_search_sendz   - z	       - ZUIDZGIDz\dr.r.r.)
�splitrr r&�keys�items�
splitlines�print_formatted�clear�rsplitr3r'�bool)rr�datar#�fields�ts�resultr�k�vZcr_doneZid_doneZcidlineZplugin�name�idZcr_fieldZcrr	r	r
�print_formatted_verbose�sV







z'RequestAnalyzer.print_formatted_verbosecCs�|jd�rdSd|krdS|jd�d}|dd�}|jd�}|dd	d�}|d	d	d�}|dd	d�}|j�s�|dd	d�}t|�d
|�d|�d|���|S)z�
        Parse line and print formatted list_requests output

        Args:
            line (str): line to parse
        Returns:
            Client ID from printed line, 0 otherwise
        z   *  rZ	refreshed�)r+Nr5r7r:�	��z: [uid z] CID #z: i����r.r.r.)r!r<�	isnumericr3)rr#rFrEr�cmdZuidr	r	r
r@�s


zRequestAnalyzer.print_formattedcCs�|j|�}|jj}d}dg}|jr.|jj}d}tjd|�d��|j|d�|jr^|j	|�n8x6|j
||�D]&}t|�jdkr�t
|�ql|j|�qlWdS)	z�
        List component (default: NSS) responder requests

        Args:
            args (Namespace):  populated argparse namespace
        �nssz\[cmd�pamz******** Listing z client requests ********FrN)r�	Component�NSSrT�PAM�logger�info�
set_component�verboserLr%r1r2r3r@)rrr�	component�respr"r#r	r	r
r�s

zRequestAnalyzer.list_requestsc
st|j|�}|j}d}d}|jj}d}d|�d�g�|jrD|jj}d}tjd|�d|�d��|j||j	�x$|j
|��D]}|j|||j�}qxWtjd	|�d
��d|�d|�d�g�|j|jj
|j	�d
}	|j|�|	�}
�j��fdd�|
D�x&|j
|��D]}|j|||j�}�qW|j�rNt|jdd�d�}x|D]}t|��q<W|�rp|�rptjd|�d��dS)z�
        Print Logs pertaining to individual SSSD client request

        Args:
            args (Namespace):  populated argparse namespace
        FrSz\[CID#z\]rTz******** Checking z responder for Client ID z *******z)********* Checking Backend for Client ID z	 ********zREQ_TRACE.*\[sssd.z CID #z\[RID#[0-9]+\]csg|]}�jd|����qS)�\)r')�.0rK)r$r	r
�
<listcomp>4sz1RequestAnalyzer.track_request.<locals>.<listcomp>cSs|jd�dS)NrMr)r<)�sr	r	r
�<lambda><sz/RequestAnalyzer.track_request.<locals>.<lambda>)�keyzID z not found in logs!N)rrrUrVrTrWrXrYrZZchildr%r4�mergeZBEr*rA�sortedr/r3�warn)
rrrrZresp_resultsZ
be_resultsr\r]r(Zbe_id_regexZbe_idsZsorted_list�entryr	)r$r
rs<

zRequestAnalyzer.track_request)r2�
__module__�__qualname__�__doc__rr/rrCr�intrrrrr%r*r4rLr@rrr	r	r	r
r
s&


	Fr)rZloggingZsssd.parserrrZ	getLoggerrXrr	r	r	r
�<module>s