
    kc~                        d Z ddlZddlZddlZddlmZmZ ddlmZmZ ddlm	Z	 ddlm
Z
 ddlmc mZ ddlmc mZ ej                   Zddlmc mZ  G d d      Z G d	 d
      Z ej*                  dej,                        Zy)z>$Id: auth_handler.py,v 1.6 2002/11/25 19:40:23 akuchling Exp $    N)	as_stringas_bytes)encodestringdecodestring)long)md5c                   8    e Zd Zd	dZd Zd Zd Zd Zd Zd Z	y)
auth_handlerc                     t        |      | _        || _        || _        t	        j                         | _        t	        j                         | _        y N)dictionary_authorizer
authorizerhandlerrealmcounter
pass_count
fail_count)selfdictr   r   s       @/usr/lib/python3/dist-packages/supervisor/medusa/auth_handler.py__init__zauth_handler.__init__#   s8    /6
!//+!//+    c                 8    | j                   j                  |      S r   )r   matchr   requests     r   r   zauth_handler.match*   s    ||!!7++r   c                    t        t        |j                        }|r|j                         }|dk(  rt        t        |j                  d      }	 t	        t        t        |                  }|j                  dd      }| j                  j                  |      r=| j                  j                          ||_        | j"                  j%                  |       y | j'                  |       y t        j                  j                  d|z         | j'                  |       y | j'                  |       y #  t        j                  j                  d|z         |j                  d       Y y xY w)Nbasic   z"malformed authorization info <%s>
i  :   z$unknown/unsupported auth method: %s
)
get_headerAUTHORIZATIONheaderlowerr   r   r   sysstderrwriteerrorsplitr   	authorizer   	increment	auth_infor   handle_requesthandle_unauthorized)r   r   schemecookiedecodedr-   s         r   r.   zauth_handler.handle_request.   s   ]GNN;\\^F #]GNNAF'Xf5E(FGG
 $MM#q1	??,,i8OO--/(1G%LL//9,,g6 

  !H6!QR((1 $$g.1JJ$$%JV%STMM3's   D- -5E$c                     | j                   j                          |j                  j                  d        d|d<   d| j                  z  |d<   |j                  d       y )Nclose
ConnectionzBasic realm="%s"zWWW-Authenticatei  )r   r,   channelset_terminatorr   r)   r   s     r   r/   z auth_handler.handle_unauthorizedR   sP     	!!#&&- '&84::&E"#sr   c                    |j                   j                  j                  }t        t	        t        j
                                     }|dd dk(  r|dd }t        t        |             }dj                  |||g      }| j                  |      S )zEA digest-authentication <nonce>, constructed as suggested in RFC 2069NLr    )	r6   serveripstrr   timeidjoin
apply_hash)r   r   r<   nowprivate_keynonces         r   
make_noncezauth_handler.make_nonce[   su    __##&&$tyy{#$rs8s?cr(C2t9o"c;/0&&r   c                 t    t               }|j                  |       |j                         }t        |      dd S )z;Apply MD5 to a string <s>, then wrap it in base64 encoding.Nr9   )r   updatedigestr   )r   smds       r   rA   zauth_handler.apply_hashe   s1    E	!HHJQ$$r   c                 8   t        j                  d| j                  z        g}t        | j                  d      r)|j                  | j                  j                                |j                  t        j                  d             t        j                  |      S )NzB<li>Authorization Extension : <b>Unauthorized requests:</b> %s<ul>statusz</ul>)	producerssimple_producerr   hasattrr   appendrM   composite_producer)r   rs     r   rM   zauth_handler.statusm   s     ))?AEQ DLL(+HHdll))+,	))73	 ++A..r   N)default)
__name__
__module____qualname__r   r   r.   r/   rE   rA   rM    r   r   r
   r
   "   s&    ,,"/H'%/r   r
   c                       e Zd Zd Zd Zy)r   c                     || _         y r   r   )r   r   s     r   r   zdictionary_authorizer.__init__}   s	    	r   c                 P    |\  }}|| j                   v r| j                   |   |k(  ryy)Nr!   r   r[   )r   r-   usernamepasswords       r   r+   zdictionary_authorizer.authorize   s.    (8tyy TYYx%8H%Dr   N)rU   rV   rW   r   r+   rX   r   r   r   r   |   s    r   r   zAuthorization: ([^ ]+) (.*))RCS_IDrer&   r>   supervisor.compatr   r   r   r   r   r   supervisor.medusa.countermedusar   !supervisor.medusa.default_handlerdefault_handlerr"   supervisor.medusa.producersrN   r
   r   compile
IGNORECASEr#   rX   r   r   <module>ri      st    K 
 
  1 8 " ! + + ; ;''
 / /X/ X/t	 	 

%

r   