a
    %0É_c  ã                   @   sà   d Z ddlmZ ddlZddlmZ ddlmZ ddlm	Z	 ddl
mZmZmZmZmZ ejZejZdZd a aai Ze e¡Zed	d
dd ed	ddd ed	ddd dd„ Zdd„ Zdd„ Zeeƒdd„ ƒZdd„ ZdS )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  ¡ st tdƒ¡‚d|vr(d| }d| }t t dt	|f ¡¡ d S )Ns   factotum not interactives   user=s   %s user?s   %s !password?s
   %s -g '%s')
ÚuiÚinteractiver   ÚAbortr   ÚosÚsystemr   ZtonativestrÚ_executable)ÚselfÚparams© r   ú0/usr/lib/python3/dist-packages/hgext/factotum.pyÚauth_getkeyS   s    
r   c              	   C   s  d| }t  dt t j¡}zàz¬t  |d| ¡ t  |t¡ ¡ }|d dkrÆt  |d¡ t  |t¡ d d¡\}}}|dkrÆ| d¡r°| 	d¡r¢|d	d
…  
dd¡}nt tdƒ¡‚||fW W t  |¡ S W n$ ttfyì   t tdƒ¡‚Y n0 W t  |¡ nt  |¡ 0 || |ƒ qd S )Ns   proto=pass %ss   %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   Zgetkeyr   ÚfdÚlZstatusÚuserÚpasswdr   r   r   Úauth_getuserpasswd\   s(    



ür1   c                    s   ‡ fdd„}|S )Nc                    s   t ˆ | j| ƒ | S )N)r   Ú__name__)Úfunc©Úclsr   r   Ú	decoratoru   s    z%monkeypatch_method.<locals>.decoratorr   )r5   r6   r   r4   r   Úmonkeypatch_methodt   s    r7   c           
      C   sÜ   | j  ||¡\}}|r.|r.|  ||¡ ||fS d}t | j||¡}|rn|\}}| d¡}| d¡| d¡ }}|rv|s¸|sŒ| d¡d  ¡ }dt	|f }	|r¨d|	|f }	t
| t|	ƒ\}}|  ||||¡ |  ||¡ ||fS )	Nó    s   prefixs   usernames   passwordó    r   s   service=%s prefix=%ss
   %s user=%s)ZpasswddbÚfind_user_passwordZ_writedebugr   Zreadauthforurir   Úgetr&   ÚlowerÚ_servicer1   r   Zadd_password)
r   ZrealmZauthurir/   r0   ÚprefixÚresr   Zauthr   r   r   r   r:   |   s(    
r:   c                 C   s(   |   dd¡a|   dd¡a|   dd¡ad S )Nr   r   r   r   )Zconfigr   r!   r=   )r   r   r   r   Úuisetup–   s    r@   )Ú__doc__Z
__future__r   r   Zmercurial.i18nr   Zmercurial.pycompatr   Zmercurial.utilsr   Z	mercurialr   r   r   r	   r
   ZurlreqZpasswordmgrr%   r   r!   r=   ZconfigtableZ
configitemr   r1   r7   r:   r@   r   r   r   r   Ú<module>   s6   
ÿÿÿ	
