ó
[³XMc           @   s¾   d  Z  d d l m Z d d l m Z d d l m Z d d l m Z d d l	 m
 Z
 d d l m Z d d l m Z d	 „  Z d
 e f d „  ƒ  YZ d Z d e f d „  ƒ  YZ e ƒ  Z d S(   s%   
Cred plugin for UNIX user accounts.
iÿÿÿÿ(   t
   implements(   t   plugin(   t   ICheckerFactory(   t   ICredentialsChecker(   t   IUsernamePassword(   t   UnauthorizedLogin(   t   deferc         C   s   |  d d k r* d |  j  d ƒ d } n
 |  d  } y d d  l } Wn t k
 r] d  } n X| d  k ry t d ƒ ‚ n  | j | | ƒ |  k S(   Ni    t   $s   $1$i   iÿÿÿÿs(   cred_unix not supported on this platform(   t   splitt   cryptt   ImportErrort   Nonet   NotImplementedError(   t   cryptedt   pwt   saltR	   (    (    s=   /usr/lib/python2.7/dist-packages/twisted/plugins/cred_unix.pyt   verifyCryptedPassword   s    

t   UNIXCheckerc           B   s<   e  Z d  Z e e ƒ e f Z d „  Z d „  Z d „  Z	 RS(   s  
    A credentials checker for a UNIX server. This will check that
    an authenticating username/password is a valid user on the system.

    Does not work on Windows.

    Right now this supports Python's pwd and spwd modules, if they are
    installed. It does not support PAM.
    c         C   sh   y | j  | ƒ d } Wn t k
 r7 t j t ƒ  ƒ SX| d k rH d  St | | ƒ rd t j | ƒ Sd  S(   Ni   t   *t   x(   R   R   (   t   getpwnamt   KeyErrorR   t   failR   R   R   t   succeed(   t   selft   pwdt   usernamet   passwordt   cryptedPass(    (    s=   /usr/lib/python2.7/dist-packages/twisted/plugins/cred_unix.pyt   checkPwd3   s    c         C   sX   y | j  | ƒ d } Wn t k
 r7 t j t ƒ  ƒ SXt | | ƒ rT t j | ƒ Sd  S(   Ni   (   t   getspnamR   R   R   R   R   R   (   R   t   spwdR   R   R   (    (    s=   /usr/lib/python2.7/dist-packages/twisted/plugins/cred_unix.pyt	   checkSpwd@   s    c         C   sß   | j  | j } } y d d  l } Wn t k
 r< d  } n X| d  k	 rq |  j | | | ƒ } | d  k	 rq | Sn  y d d  l } Wn t k
 rš d  } n X| d  k	 rÏ |  j | | | ƒ } | d  k	 rÏ | Sn  t j	 t
 ƒ  ƒ S(   Niÿÿÿÿ(   R   R   R   R
   R   R   R   R    R   R   R   (   R   t   credentialsR   R   R   t   checkedR   (    (    s=   /usr/lib/python2.7/dist-packages/twisted/plugins/cred_unix.pyt   requestAvatarIdJ   s$    

(
   t   __name__t
   __module__t   __doc__R    R   R   t   credentialInterfacesR   R    R#   (    (    (    s=   /usr/lib/python2.7/dist-packages/twisted/plugins/cred_unix.pyR   %   s   	
			
s  
This checker will attempt to use every resource available to
authenticate against the list of users on the local UNIX system.
(This does not support Windows servers for very obvious reasons.)

Right now, this includes support for:

  * Python's pwd module (which checks /etc/passwd)
  * Python's spwd module (which checks /etc/shadow)

Future versions may include support for PAM authentication.
t   UNIXCheckerFactoryc           B   sB   e  Z d  Z e e e j ƒ d Z e Z	 d Z
 e j Z d „  Z RS(   s'   
    A factory for L{UNIXChecker}.
    t   unixs   No argstring required.c         C   s   t  ƒ  S(   s®   
        This checker factory ignores the argument string. Everything
        needed to generate a user database is pulled out of the local
        UNIX environment.
        (   R   (   R   t	   argstring(    (    s=   /usr/lib/python2.7/dist-packages/twisted/plugins/cred_unix.pyt   generateChecker   s    (   R$   R%   R&   R    R   R   t   IPlugint   authTypet   unixCheckerFactoryHelpt   authHelpt   argStringFormatR   R'   R+   (    (    (    s=   /usr/lib/python2.7/dist-packages/twisted/plugins/cred_unix.pyR(   u   s   	N(   R&   t   zope.interfaceR    t   twistedR   t   twisted.cred.strcredR   t   twisted.cred.checkersR   t   twisted.cred.credentialsR   t   twisted.cred.errorR   t   twisted.internetR   R   t   objectR   R.   R(   t   theUnixCheckerFactory(    (    (    s=   /usr/lib/python2.7/dist-packages/twisted/plugins/cred_unix.pyt   <module>   s   	L