HEX
Server: Apache
System: Linux server2.voipitup.com.au 4.18.0-553.109.1.lve.el8.x86_64 #1 SMP Thu Mar 5 20:23:46 UTC 2026 x86_64
User: posscale (1027)
PHP: 8.2.30
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //opt/saltstack/salt/lib/python3.10/site-packages/salt/tokens/__pycache__/localfs.cpython-310.pyc
o

�N�gy�@szdZddlZddlZddlZddlZddlZddlZddlZddl	m
Z
e�e�Z
dZdd�Zdd�Zd	d
�Zdd�ZdS)
zu
Stores eauth tokens in the filesystem of the master. Location is configured by the master config option 'token_dir'
�N)�DEFAULT_HASH_TYPEZlocalfsc	Cs2tt|�dt��}t|t�d�����}tj�	|d|�}|�d�}tj�
|�rBt|t�d�����}tj�	|d|�}tj�
|�s(||d<zAtjj
�d��)tjj
�|d��}|�tj�|��Wd�n1skwYWd�n1szwYt�||�W|Sty�t�d	|�iYSw)
a�
    Mint a new token using the config option hash_type and store tdata with 'token' attribute set
    to the token.
    This module uses the hash of random 512 bytes as a token.

    :param opts: Salt master config options
    :param tdata: Token data to be stored with 'token' attribute of this dict set to the token.
    :returns: tdata with token if successful. Empty dict if failed.
    �	hash_typei�	token_dirz.tmp�token�zw+bNz6Authentication failure: can not write token file "%s".)�getattr�hashlib�getr�str�os�urandom�	hexdigest�path�join�isfile�salt�utils�filesZ	set_umask�fopen�write�payload�dumps�rename�OSError�log�warning)�opts�tdatar�tok�t_pathZtemp_t_path�fp_�r!�G/opt/saltstack/salt/lib/python3.10/site-packages/salt/tokens/localfs.py�mk_tokens,

������r#cCs�tj�|d|�}tjj�|d|�siStj�|�siSz&tjj�	|d��}tj
�|���}|Wd�WS1s<wYWdSt
yTt�d|�iYSw)z�
    Fetch the token data from the store.

    :param opts: Salt master config options
    :param tok: Token value to get
    :returns: Token data if successful. Empty dict if failed.
    r�rbNz5Authentication failure: can not read token file "%s".)rrrrrZverifyZ
clean_pathrrrr�loads�readrrr)rrrr rr!r!r"�	get_token1s(��r'cCsDtj�|d|�}zt�|�iWSty!t�d|�YdSw)z�
    Remove token from the store.

    :param opts: Salt master config options
    :param tok: Token to remove
    :returns: Empty dict if successful. None if failed.
    rzCould not remove token %sN)rrr�removerrr)rrrr!r!r"�rm_tokenGs
�r)cCs:g}tjj�|d�D]\}}}|D]}|�|�qq|S)zy
    List all tokens in the store.

    :param opts: Salt master config options
    :returns: List of dicts (tokens)
    r)rrrZos_walk�append)r�ret�dirpath�dirnames�	filenamesrr!r!r"�list_tokensWs�r/)�__doc__r�loggingrZsalt.payloadrZsalt.utils.filesZsalt.utils.pathZsalt.utils.verifyZsalt.configr�	getLogger�__name__rZ__virtualname__r#r'r)r/r!r!r!r"�<module>s