File: //usr/lib/python3/dist-packages/hgext/__pycache__/factotum.cpython-310.pyc
o
    �]Lb{  �                   @   s�   d Z ddlmZ ddlZddlmZ ddlmZ ddlm	Z	 ddl
mZmZm
Z
mZmZ ejZejZdZd a aai Ze
�e�Zed	d
dd� ed	d
dd� ed	ddd� dd� Zdd� Zdd� Zee�dd� �Zdd� ZdS )a�  http authentication with factotum
This extension allows the factotum(4) facility on Plan 9 from Bell Labs
platforms to provide authentication information for HTTP access. Configuration
entries specified in the auth section as well as authentication information
provided in the repository URL are fully supported. If no prefix is specified,
a value of "*" will be assumed.
By default, keys are specified as::
  proto=pass service=hg prefix=<prefix> user=<username> !password=<password>
If the factotum extension is unable to read the required key, one will be
requested interactively.
A configuration section is available to customize runtime behavior. By
default, these entries are::
  [factotum]
  executable = /bin/auth/factotum
  mountpoint = /mnt/factotum
  service = hg
The executable entry defines the full path to the factotum binary. The
mountpoint entry defines the path to the factotum file service. Lastly, the
service entry controls the service name used when reading keys.
�    )�absolute_importN)�_)�setattr)�procutil)�error�httpconnection�	registrar�url�util�   �   factotum�
   executables   /bin/auth/factotum)�default�
   mountpoints
   /mnt/factotum�   services   hgc                 C   sL   | j �� st�td���d|vrd| }d| }t�t�dt	|f �� d S )Ns   factotum not interactives   user=s   %s user?s
   %s !password?s
   %s -g '%s')
�ui�interactiver   �Abortr   �os�systemr   �tonativestr�_executable)�self�params� r   �0/usr/lib/python3/dist-packages/hgext/factotum.py�auth_getkeyY   s   
r   c              	   C   s  d| }	 t �dt t j�}znzVt �|d| � t �|t��� }|d dkrdt �|d� t �|t��d d�\}}}|dkrd|�d	�rY|�	d	�rR|d
d� �
dd	�}nt�t
d
���||fW W t �|� S W n ttfyu   t�t
d���w W t �|� nt �|� w || |� q)Ns
   proto=pass %sTs   %s/rpcs   start %sr   s   oks   read�   �   '�   ���s   ''s   malformed password strings   factotum not responding)r   �open�_mountpoint�O_RDWR�write�read�ERRMAX�split�
startswith�endswith�replacer   r   r   �close�OSError�IOError)r   �getkeyr   �fd�l�status�user�passwdr   r   r   �auth_getuserpasswdb   s0   
����
�r4   c                    s   � fdd�}|S )Nc                    s   t � | j| � | S )N)r   �__name__)�func��clsr   r   �	decorator{   s   z%monkeypatch_method.<locals>.decoratorr   )r8   r9   r   r7   r   �monkeypatch_methodz   s   r:   c           
      C   s�   | j �||�\}}|r|r| �||� ||fS d}t�| j||�}|r7|\}}|�d�}|�d�|�d�}}|r;|s\|sF|�d�d �� }dt	|f }	|rTd|	|f }	t
| t|	�\}}| �||||� | �||� ||fS )	N�    s   prefixs   usernames   password�    r   s   service=%s prefix=%ss
   %s user=%s)
�passwddb�find_user_password�_writedebugr   �readauthforurir   �getr'