
    RSi؆                     $   d Z ddlZddlZddlmZ ddlmZ dgZ G d d          Zd Z G d	 d
          Z		  ej
                    5   ej        d           ddlZddlZddlZddd           n# 1 swxY w Y   eddgz  Z ej                    Z ej                    Z G d d          Z G d de	e          Zn# e$ r Y nw xY w	 ddlZddlZddlZddlZddlZddlZeddgz  Z G d d          Z G d de	e          ZdS # e$ r Y dS w xY w)a  An "authorizer" is a class handling authentications and permissions
of the FTP server. It is used by pyftpdlib.handlers.FTPHandler
class for:

- verifying user password
- getting user home directory
- checking user permissions when a filesystem read/write event occurs
- changing user when accessing the filesystem

DummyAuthorizer is the main class which handles virtual users.

UnixAuthorizer and WindowsAuthorizer are platform specific and
interact with UNIX and Windows password database.
    N   )AuthenticationFailed)AuthorizerErrorDummyAuthorizerc                       e Zd ZdZdZdZd Z	 	 	 ddZd Zd	 Z	ddZ
d Zd Zd Zd Zd ZddZd Zd Zd Zd Zd ZdS )r   a  Basic "dummy" authorizer class, suitable for subclassing to
    create your own custom authorizers.

    An "authorizer" is a class handling authentications and permissions
    of the FTP server.  It is used inside FTPHandler class for verifying
    user's password, getting users home directory, checking user
    permissions when a file read/write event occurs and changing user
    before accessing the filesystem.

    DummyAuthorizer is the base authorizer, providing a platform
    independent interface for managing "virtual" FTP users. System
    dependent authorizers can by written by subclassing this base
    class and overriding appropriate methods as necessary.
    elradfmwMTc                     i | _         d S N
user_table)selfs    I/home/jrussi/.local/lib/python3.11/site-packages/pyftpdlib/authorizers.py__init__zDummyAuthorizer.__init__9   s        Login successful.Goodbye.c                    |                      |          rt          d|d          t          j                            |          st          d|          t          j                            |          }|                     ||           t          |          ||i t          |          t          |          d}|| j        |<   dS )aT  Add a user to the virtual users table.

        AuthorizerError exceptions raised on error conditions such as
        invalid permissions, missing home directory or duplicate usernames.

        Optional perm argument is a string referencing the user's
        permissions explained below:

        Read permissions:
         - "e" = change directory (CWD command)
         - "l" = list files (LIST, NLST, STAT, MLSD, MLST, SIZE, MDTM commands)
         - "r" = retrieve file from the server (RETR command)

        Write permissions:
         - "a" = append data to an existing file (APPE command)
         - "d" = delete file or directory (DELE, RMD commands)
         - "f" = rename file or directory (RNFR, RNTO commands)
         - "m" = create directory (MKD command)
         - "w" = store a file to the server (STOR, STOU commands)
         - "M" = change file mode (SITE CHMOD command)
         - "T" = update file last modified time (MFMT command)

        Optional msg_login and msg_quit arguments can be specified to
        provide customized response strings when user log-in and quit.
        user z already existsno such directory: )pwdhomepermoperms	msg_loginmsg_quitN)	has_user
ValueErrorospathisdirrealpath_check_permissionsstrr   )r   usernamepasswordhomedirr   r   r   dics           r   add_userzDummyAuthorizer.add_user<   s    D =="" 	B@X@@@AAAw}}W%% 	@>7>>???'""7++$///x==YH
 
 %(!!!r   c                 0    t          j        | dd|fi | dS )a=  Add an anonymous user to the virtual users table.

        AuthorizerError exception raised on error conditions such as
        invalid permissions, missing home directory, or duplicate
        anonymous users.

        The keyword arguments in kwargs are the same expected by
        add_user method: "perm", "msg_login" and "msg_quit".

        The optional "perm" keyword argument is a string defaulting to
        "elr" referencing "read-only" anonymous user's permissions.

        Using write permission values ("adfmwM") results in a
        RuntimeWarning.
        	anonymous N)r   r)   )r   r'   kwargss      r   add_anonymouszDummyAuthorizer.add_anonymousn   s)      	 {BJJ6JJJJJr   c                     | j         |= dS )z+Remove a user from the virtual users table.Nr   r   r%   s     r   remove_userzDummyAuthorizer.remove_user   s    OH%%%r   Fc                    |                      ||           t          j                            |          st	          d|          t          j                            t          j                            |                    }t          j                            |                     |                    }||k    rt	          d          |                     ||          st	          d          ||f| j	        |         d         |<   dS )z+Override permissions for a given directory.r   z)can't override home directory permissionsz path escapes user home directoryr   N)
r#   r   r    r!   r   normcaser"   get_home_dir
_issubpathr   )r   r%   	directoryr   	recursiver   s         r   override_permzDummyAuthorizer.override_perm   s    $///w}}Y'' 	B@9@@AAAG$$RW%5%5i%@%@AA	w 1 1( ; ;<<HIIIy$// 	A?@@@9=y!(+I666r   c                     d}|                      |          s|dk    rd}t          |          |dk    r&| j        |         d         |k    rt          |          dS dS )zRaises AuthenticationFailed if supplied username and
        password don't match the stored credentials, else return
        None.
        Authentication failed.r+   Anonymous access not allowed.r   N)r   r   r   )r   r%   r&   handlermsgs        r   validate_authenticationz'DummyAuthorizer.validate_authentication   sy    
 '}}X&& 	,;&&5&s+++{""x(/8;;*3/// #";;r   c                 (    | j         |         d         S )zReturn the user's home directory.
        Since this is called during authentication (PASS),
        AuthenticationFailed can be freely raised by subclasses in case
        the provided username no longer exists.
        r   r   r0   s     r   r4   zDummyAuthorizer.get_home_dir   s     x(00r   c                     dS )zImpersonate another user (noop).

        It is always called before accessing the filesystem.
        By default it does nothing.  The subclass overriding this
        method is expected to provide a mechanism to change the
        current user.
        N r   r%   r&   s      r   impersonate_userz DummyAuthorizer.impersonate_user         r   c                     dS )a  Terminate impersonation (noop).

        It is always called after having accessed the filesystem.
        By default it does nothing.  The subclass overriding this
        method is expected to provide a mechanism to switch back
        to the original user.
        NrA   r0   s     r   terminate_impersonationz'DummyAuthorizer.terminate_impersonation   rD   r   c                     || j         v S )z7Whether the username exists in the virtual users table.r   r0   s     r   r   zDummyAuthorizer.has_user   s    4?**r   Nc                    ||| j         |         d         v S t          j                            |          }| j         |         d         D ]}| j         |         d         |         \  }}|                     ||          rV|r||v c S ||k    sBt          j                            |          |k    r%t          j                            |          s||v c S || j         |         d         v S )zWhether the user has permission over path (an absolute
        pathname of a file or a directory).

        Expected perm argument is one of the following letters:
        "elradfmwMT".
        Nr   r   )r   r   r    r3   r5   dirnamer!   )r   r%   r   r    diropermr7   s          r   has_permzDummyAuthorizer.has_perm   s     <4?84V<<<w%%?8,X6 	) 	)C#x8B3GE9tS)) ) )5=(((3;;GOOD))S00t9L9L05=(((tx0888r   c                 (    | j         |         d         S )z Return current user permissions.r   r   r0   s     r   	get_permszDummyAuthorizer.get_perms   s    x(00r   c                 (    | j         |         d         S )z Return the user's login message.r   r   r0   s     r   get_msg_loginzDummyAuthorizer.get_msg_login   s    x(55r   c                 L    	 | j         |         d         S # t          $ r Y dS w xY w)z#Return the user's quitting message.r   r   )r   KeyErrorr0   s     r   get_msg_quitzDummyAuthorizer.get_msg_quit   s;    	?8,Z88 	 	 	::	s    
##c                     d}|D ]T}|| j         | j        z   vrt          d|          |dk    r)|| j        v r |st          j        dt
          d           d}Ud S )Nr   zno such permission r+   z-write permissions assigned to anonymous user.   )
stacklevelr   )
read_permswrite_permsr   warningswarnRuntimeWarning)r   r%   r   warnedps        r   r#   z"DummyAuthorizer._check_permissions   s     	 	A$*:::: !<q!<!<===K''))) * C"    
 	 	r   c                 (   |                     t          j                                      t          j                  }|                     t          j                                      t          j                  }|dt	          |                   |k    S )z>Return True if a is a sub-path of b or if the paths are equal.N)rstripr   sepsplitlen)r   abp1p2s        r   r5   zDummyAuthorizer._issubpath   sa    XXbf##BF++XXbf##BF++)CGG)}""r   )r   r   r   )Fr   )__name__
__module____qualname____doc__rW   rX   r   r)   r.   r1   r8   r>   r4   rC   rF   r   rL   rN   rP   rS   r#   r5   rA   r   r   r   r   &   s<         JK   %0( 0( 0( 0(dK K K$& & &I I I I0 0 01 1 1    + + +9 9 9 9.1 1 16 6 6    "# # # # #r   c                       fd}|S )zA decorator to replace anonymous user string passed to authorizer
    methods as first argument with the actual user used to handle
    anonymous sessions.
    c                 <    |dk    r	| j         p|} | |g|R i |S Nr+   )anonymous_user)r   r%   argsr-   callables       r   wrapperz"replace_anonymous.<locals>.wrapper  s=    {""*6hHxh8888888r   rA   )rp   rq   s   ` r   replace_anonymousrr      s#    9 9 9 9 9
 Nr   c                   d    e Zd ZdZdZdZdZdZdZd Z		 	 	 	 	 ddZ
d	 Zd
 Zd ZddZd Zd ZdS )_Basez_Methods common to both Unix and Windows authorizers.
    Not supposed to be used directly.
    r:   r;   z#User %s doesn't have a valid shell.z User %s is not allowed to login.c                    | j         r| j        rt          d          |                                 }| j        p| j         D ]-}|dk    rt          d          ||vrt          d|           .| j        |                     | j                  st          d| j                   |                     | j                  }t          j        	                    |          st          d| j                   dS dS )z$Check for errors in the constructor.z?rejected_users and allowed_users options are mutually exclusiver+   zinvalid username "anonymous"zunknown user Nno such user zno valid home set for user )
rejected_usersallowed_usersr   _get_system_usersrn   r   r4   r   r    r!   )r   usersuserr   s       r   r   z_Base.__init__  s7    	4#5 	!)  
 &&((&=$*= 	> 	>D{""%&DEEE5  %&<d&<&<=== ! *==!455 M%&Kd6I&K&KLLL$$T%899D7==&& %G$2EGG   +* r   Nc                    |s|s|s|s|st          d          | j        r|| j        vrt          | d          | j        r|| j        v rt          | d          |dk    r|rt          d          |                     |          st          d|           || j        j        v r| j        j        |= | j                            ||pd|pt          j                    |pd|pd|pd           |d| j        j        |         d<   dS dS )	z^Overrides the options specified in the class constructor
        for a specific user.
        z/at least one keyword argument must be specifiedz is not an allowed userr+   z'can't assign password to anonymous userrv   r,   Nr   )	r   rx   rw   r   _dummy_authorizerr   r)   r   getcwdr   r%   r&   r'   r   r   r   s          r   override_userz_Base.override_user1  s    				 		 			
 		 "A    	H($2D"D"D!X"F"F"FGGG 	H8t/B#B#B!X"F"F"FGGG{""x"!"KLLL}}X&& 	>!"<("<"<===t-888&1(;''N"ry{{JBON	
 	
 	
 ?BDD"-h7??? ?r   c                 <    |                      |d          p| j        S )Nr   )_get_keyr   r0   s     r   rP   z_Base.get_msg_login^  s    }}X{33Et~Er   c                 <    |                      |d          p| j        S )Nr   )r   r   r0   s     r   rS   z_Base.get_msg_quita  s    }}Xz22CdmCr   c                 T    |                      |d          }|r|S |dk    rdS | j        S )Nr   r+   r   )r   global_perm)r   r%   overridden_permss      r   rN   z_Base.get_permsd  s=    ==6:: 	$##{""5r   c                 0    ||                      |          v S r   rN   r   r%   r   r    s       r   rL   z_Base.has_perml  s    t~~h////r   c                 j    | j                             |          r| j         j        |         |         S d S r   )r}   r   r   )r   r%   keys      r   r   z_Base._get_keyo  s>    !**844 	D)4X>sCC	D 	Dr   c                 `    | j         r|| j         vrdS t          | j        o|| j        v           S )zkReturn True if the user has been black listed via
        allowed_users or rejected_users options.
        T)rx   boolrw   r0   s     r   _is_rejected_userz_Base._is_rejected_users  s?      	($2D"D"D4D'KH8K,KLLLr   NNNNNr   )rg   rh   ri   rj   msg_no_such_usermsg_wrong_passwordmsg_anon_not_allowedmsg_invalid_shellmsg_rejected_userr   r   rP   rS   rN   rL   r   r   rA   r   r   rt   rt     s          01:=:  6 +E +E +E +EZF F FD D D     0 0 0 0D D DM M M M Mr   rt   ignoreBaseUnixAuthorizerUnixAuthorizerc                       e Zd ZdZddZd Zed             Zd Zed             Z	ed             Z
ed	             Zd
 Zd Zd ZddZdS )r   zAn authorizer compatible with Unix user account and password
        database.
        This class should not be used directly unless for subclassing.
        Use higher-level UnixAuthorizer class instead.
        Nc                     t          j                    dk    st          j                    st	          d          || _        | j        F	 t          j        | j                  j         d S # t          $ r}t	          d|           |d }~ww xY wd S )Nr   z"super user privileges are requiredrv   )
r   geteuidspwdgetspallr   rn   r   getpwnampw_dirrR   )r   rn   errs      r   r   zBaseUnixAuthorizer.__init__  s    z||q   %&JKKK"0D".L!455<<<<   )888  /.s   	A) )
B3BBc                 ,   |dk    r| j         t          | j                  dS 	 t          j        |          j        }t          j        ||          }||k    rt          | j                  dS # t          $ r}t          | j	                  |d}~ww xY w)zAuthenticates against shadow password db; raises
            AuthenticationFailed in case of failed authentication.
            r+   N)
rn   r   r   r   getspnamsp_pwdcryptr   rR   r   )r   r%   r&   r<   pw1pw2r   s          r   r>   z*BaseUnixAuthorizer.validate_authentication  s     ;&&&..t/HIII /.L-118C+h44C czz243JKKK "z   O O O.t/DEE3NOs   .A/ /
B9BBc                     	 t          j        |          }t          j        |j                   t          j        |j                   dS # t          $ r}t          | j	                  |d}~ww xY w)z[Change process effective user/group ids to reflect
            logged in user.
            N)
r   r   r   setegidpw_gidseteuidpw_uidrR   r   r   )r   r%   r&   	pwdstructr   s        r   rC   z#BaseUnixAuthorizer.impersonate_user  s|    
-L22	 
9+,,,
9+,,,,,	  F F F%d&;<<#EFs   A
 

A.A))A.c                 j    t          j        t                     t          j        t                     dS )z(Revert process effective user/group IDs.N)r   r   PROCESS_GIDr   PROCESS_UIDr0   s     r   rF   z*BaseUnixAuthorizer.terminate_impersonation  s(    J{###J{#####r   c                 .    ||                                  v S )zReturn True if user exists on the Unix system.
            If the user has been black listed via allowed_users or
            rejected_users options always return False.
            ry   r0   s     r   r   zBaseUnixAuthorizer.has_user  s     t557777r   c                     	 t          j        |          j        S # t          $ r}t	          | j                  |d}~ww xY w)zReturn user home directory.N)r   r   r   rR   r   r   )r   r%   r   s      r   r4   zBaseUnixAuthorizer.get_home_dir  sQ    F|H--44 F F F%d&;<<#EFs    
?:?c                  <    d t          j                    D             S )z,Return all users defined on the UNIX system.c                     g | ]	}|j         
S rA   )pw_name.0entrys     r   
<listcomp>z8BaseUnixAuthorizer._get_system_users.<locals>.<listcomp>  s    >>>eEM>>>r   )r   getpwallrA   r   r   ry   z$BaseUnixAuthorizer._get_system_users  s     ?>s|~~>>>>r   c                     dS Nr   rA   r0   s     r   rP   z BaseUnixAuthorizer.get_msg_login      &&r   c                     dS Nr   rA   r0   s     r   rS   zBaseUnixAuthorizer.get_msg_quit      :r   c                     dS N
elradfmwMTrA   r0   s     r   rN   zBaseUnixAuthorizer.get_perms      <r   c                 0    ||                      |          v S r   r   r   s       r   rL   zBaseUnixAuthorizer.has_perm      4>>(3333r   r   )rg   rh   ri   rj   r   r>   rr   rC   rF   r   r4   staticmethodry   rP   rS   rN   rL   rA   r   r   r   r     s       	 		 	 	 		L 	L 	L" 

	- 
	- 
	
	-	$ 	$ 	$
 
	8 	8 
		8 
	F 	F 
		F 
	? 	? 
	?	' 	' 	'	 	 		  	  	 	4 	4 	4 	4 	4 	4r   c                       e Zd ZdZ	 	 	 	 	 	 	 ddZ	 	 	 	 	 ddZd	 Zed
             Zed             Z	e
d             ZdS )r   a  A wrapper on top of BaseUnixAuthorizer providing options
        to specify what users should be allowed to login, per-user
        options, etc.

        Example usages:

         >>> from pyftpdlib.authorizers import UnixAuthorizer
         >>> # accept all except root
         >>> auth = UnixAuthorizer(rejected_users=["root"])
         >>>
         >>> # accept some users only
         >>> auth = UnixAuthorizer(allowed_users=["matt", "jay"])
         >>>
         >>> # accept everybody and don't care if they have not a valid shell
         >>> auth = UnixAuthorizer(require_valid_shell=False)
         >>>
         >>> # set specific options for a user
         >>> auth.override_user("matt", password="foo", perm="elr")
        r   NTr   r   c                    t                               | |           |g }|g }|| _        || _        || _        || _        || _        || _        || _        t                      | _
        | j
                            d|           t                              |            |r2| j        D ],}|                     |          st          d| d          +dS dS )a  Parameters:

            - (string) global_perm:
               a series of letters referencing the users permissions;
               defaults to "elradfmwMT" which means full read and write
               access for everybody (except anonymous).

            - (list) allowed_users:
               a list of users which are accepted for authenticating
               against the FTP server; defaults to [] (no restrictions).

            - (list) rejected_users:
               a list of users which are not accepted for authenticating
               against the FTP server; defaults to [] (no restrictions).

            - (bool) require_valid_shell:
               Deny access for those users which do not have a valid shell
               binary listed in /etc/shells.
               If /etc/shells cannot be found this is a no-op.
               Anonymous user is not subject to this option, and is free
               to not have a valid shell defined.
               Defaults to True (a valid shell is required for login).

            - (string) anonymous_user:
               specify it if you intend to provide anonymous access.
               The value expected is a string representing the system user
               to use for managing anonymous sessions;  defaults to None
               (anonymous access disabled).

            - (string) msg_login:
               the string sent when client logs in.

            - (string) msg_quit:
               the string sent when client quits.
            Nr,   r   z has not a valid shell)r   r   r   rx   rw   rn   require_valid_shellr   r   r   r}   r#   rt   _has_valid_shellr   )	r   r   rx   rw   r   rn   r   r   r%   s	            r   r   zUnixAuthorizer.__init__   s	   Z ''n===$ "%!#*D!.D"0D"0D':D$&DN$DM%4%6%6D""55b+FFFNN4   "  $ 2  H00:: -DHDDD    r   c           	          | j         r2|dk    r,|                     |          st          | j        |z            t                              | ||||||           dS )fOverrides the options specified in the class constructor
            for a specific user.
            r+   N)r   r   r   r   rt   r   r   s          r   r   zUnixAuthorizer.override_userD  sx     ' MH,C,C,,X66 M)$*@8*KLLLh'4H    r   c                    |dk    r| j         t          | j                  d S |                     |          rt          | j        |z            |                     |d          }|r||k    rt          | j                  nt                              | |||           | j	        r2|dk    r.| 
                    |          st          | j        |z            d S d S d S )Nr+   r   )rn   r   r   r   r   r   r   r   r>   r   r   r   r   r%   r&   r<   overridden_passwords        r   r>   z&UnixAuthorizer.validate_authenticationY  s   ;&&&..t/HIII%%h// N*4+AH+LMMM"&--%"@"@" &(22.t/FGGG 3 #::(Hg   ' H,C,C,,X66 ..9   ,C,C r   c                 \    |                      |          rdS ||                                 v S NFr   ry   r0   s     r   r   zUnixAuthorizer.has_usern  4    %%h// ut557777r   c                 l    |                      |d          }|r|S t                              | |          S Nr   )r   r   r4   )r   r%   overridden_homes      r   r4   zUnixAuthorizer.get_home_dirt  s9    "mmHf==O '&&%224BBBr   c                 t   	 t          d          }|5  	 t          j        |           j        }n# t          $ r Y ddd           dS w xY w|D ]@}|                    d          r|                                }||k    r ddd           dS A	 ddd           dS # 1 swxY w Y   dS # t          $ r Y dS w xY w)zReturn True if the user has a valid shell binary listed
            in /etc/shells. If /etc/shells can't be found return True.
            z/etc/shellsNF#T)openr   r   pw_shellrR   
startswithstripFileNotFoundError)r%   fileshelllines       r   r   zUnixAuthorizer._has_valid_shell{  sr   
!M**  ! !% #X 6 6 ?# % % %$	! ! ! ! ! ! ! !% $ ( (??3// %$#zz||5==#'! ! ! ! ! ! ! ! ) ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! %   ttsG   B) B/B
ABA8BBB #B )
B76B7)r   NNTNr   r   r   )rg   rh   ri   rj   r   r   r>   rr   r   r4   r   r   rA   r   r   r   r     s        	 	0 % $)B	 B	 B	 B	N 	 	 	 	*	 	 	* 
	8 	8 
		8
 
	C 	C 
		C 
	! 	! 
	! 	! 	!r   BaseWindowsAuthorizerWindowsAuthorizerc                       e Zd ZdZddZd Zed             Zd Zed             Z	ed             Z
ed	             Zd
 Zd Zd ZddZdS )r   zAn authorizer compatible with Windows user account and
        password database.
        This class should not be used directly unless for subclassing.
        Use higher-level WinowsAuthorizer class instead.
        Nc                     || _         || _        | j         7|                     | j         | j                   |                     d            d S d S r   )rn   anonymous_passwordrC   rF   )r   rn   r   s      r   r   zBaseWindowsAuthorizer.__init__  sb    "0D&8D#".%%')@   ,,T22222	 /.r   c                     |dk    r| j         t          | j                  d S 	 t          j        |d |t
          j        t
          j                   d S # t          j	        $ r}t          | j
                  |d }~ww xY wrm   )rn   r   r   win32security	LogonUserwin32conLOGON32_LOGON_INTERACTIVELOGON32_PROVIDER_DEFAULT
pywintypeserrorr   )r   r%   r&   r<   r   s        r   r>   z-BaseWindowsAuthorizer.validate_authentication  s    ;&&&..t/HIII	M'65     # M M M*4+BCCLMs   ,A A<"A77A<c                     t          j        |d|t          j        t          j                  }t          j        |           |                                 dS )1Impersonate the security context of another user.N)r   r   r   r   r   ImpersonateLoggedOnUserClose)r   r%   r&   r<   s       r   rC   z&BaseWindowsAuthorizer.impersonate_user  sO     $-21 G 1':::MMOOOOOr   c                 ,    t          j                     dS )z,Terminate the impersonation of another user.N)r   RevertToSelfr0   s     r   rF   z-BaseWindowsAuthorizer.terminate_impersonation  s    &(((((r   c                 .    ||                                  v S r   r   r0   s     r   r   zBaseWindowsAuthorizer.has_user  s    t557777r   c                    	 t          j        t          j        d|          d                   }n'# t          j        $ r}t          |          |d}~ww xY wd}|d|z   z  }	 t          j        t          j        |          }n%# t          $ r}t          d|           |d}~ww xY wt          j
        |d          d         }t          j        |          }|S )z|Return the user's profile directory, the closest thing
            to a user home directory we have on Windows.
            Nr   zSOFTWARE\Microsoft\Windows NTz\CurrentVersion\ProfileList\z&No profile directory defined for user ProfileImagePath)r   ConvertSidToStringSidLookupAccountNamer   r   r   winregOpenKeyHKEY_LOCAL_MACHINEOSErrorQueryValueExwin32apiExpandEnvironmentStrings)r   r%   sidr   r    r   valuer   s           r   r4   z"BaseWindowsAuthorizer.get_home_dir  s   
4#9!3D(CCAF  # 4 4 4%c**343D9C??DnV%>EE   %GXGG  '-?@@CE4U;;DKs,   -0 AAA"B 
B$BB$c                 L    d t          j        dd          d         D             S )z/Return all users defined on the Windows system.c                     g | ]
}|d          S )namerA   r   s     r   r   z;BaseWindowsAuthorizer._get_system_users.<locals>.<listcomp>  s)       "'f  r   Nr   )win32netNetUserEnum)clss    r   ry   z'BaseWindowsAuthorizer._get_system_users  s5    
 +3+?a+H+H+K   r   c                     dS r   rA   r0   s     r   rP   z#BaseWindowsAuthorizer.get_msg_login  r   r   c                     dS r   rA   r0   s     r   rS   z"BaseWindowsAuthorizer.get_msg_quit  r   r   c                     dS r   rA   r0   s     r   rN   zBaseWindowsAuthorizer.get_perms  r   r   c                 0    ||                      |          v S r   r   r   s       r   rL   zBaseWindowsAuthorizer.has_perm  r   r   )NNr   )rg   rh   ri   rj   r   r>   rr   rC   rF   r   r4   classmethodry   rP   rS   rN   rL   rA   r   r   r   r     s       	 		3 	3 	3 	3	M 	M 	M  

	 
	 
	
		) 	) 	) 
	8 	8 
		8 
	 	 
		, 
	 	 
		' 	' 	'	 	 		  	  	 	4 	4 	4 	4 	4 	4r   c                   r    e Zd ZdZ	 	 	 	 	 	 	 ddZ	 	 	 	 	 ddZd Zd	 Zed
             Z	ed             Z
dS )r   ag  A wrapper on top of BaseWindowsAuthorizer providing options
        to specify what users should be allowed to login, per-user
        options, etc.

        Example usages:

         >>> from pyftpdlib.authorizers import WindowsAuthorizer
         >>> # accept all except Administrator
         >>> auth = WindowsAuthorizer(rejected_users=["Administrator"])
         >>>
         >>> # accept some users only
         >>> auth = WindowsAuthorizer(allowed_users=["matt", "jay"])
         >>>
         >>> # set specific options for a user
         >>> auth.override_user("matt", password="foo", perm="elr")
        r   Nr   r   c                    |g }|g }|| _         || _        || _        || _        || _        || _        || _        t                      | _        | j        	                    d|           t                              |            | j        7|                     | j        | j                   |                     d           dS dS )a  Parameters:

            - (string) global_perm:
               a series of letters referencing the users permissions;
               defaults to "elradfmwMT" which means full read and write
               access for everybody (except anonymous).

            - (list) allowed_users:
               a list of users which are accepted for authenticating
               against the FTP server; defaults to [] (no restrictions).

            - (list) rejected_users:
               a list of users which are not accepted for authenticating
               against the FTP server; defaults to [] (no restrictions).

            - (string) anonymous_user:
               specify it if you intend to provide anonymous access.
               The value expected is a string representing the system user
               to use for managing anonymous sessions.
               As for IIS, it is recommended to use Guest account.
               The common practice is to first enable the Guest user, which
               is disabled by default and then assign an empty password.
               Defaults to None (anonymous access disabled).

            - (string) anonymous_password:
               the password of the user who has been chosen to manage the
               anonymous sessions.  Defaults to None (empty password).

            - (string) msg_login:
               the string sent when client logs in.

            - (string) msg_quit:
               the string sent when client quits.
            Nr,   )r   rx   rw   rn   r   r   r   r   r}   r#   rt   r   rC   rF   )r   r   rx   rw   rn   r   r   r   s           r   r   zWindowsAuthorizer.__init__  s    X $ "%!#*D!.D"0D"0D&8D#&DN$DM%4%6%6D""55b+FFFNN4   ".%%')@   ,,T22222	 /.r   c           	      F    t                               | ||||||           dS )r   N)rt   r   r   s          r   r   zWindowsAuthorizer.override_user\  s5     h'4H    r   c                    |dk    r| j         t          | j                  dS | j        r || j        vrt          | j        |z            | j        r || j        v rt          | j        |z            |                     |d          }|r||k    rt          | j                  dS t          	                    | |||           dS )z]Authenticates against Windows user database; return
            True on success.
            r+   Nr   )
rn   r   r   rx   r   rw   r   r   r   r>   r   s        r   r>   z)WindowsAuthorizer.validate_authenticationn  s     ;&&&..t/HIII! Nhd6H&H&H*4+AH+LMMM" Nx43F'F'F*4+AH+LMMM"&--%"@"@" &(22.t/FGGG 32 &==(Hg    r   c                 n    |dk    r| j         pd}| j        pd}t                              | ||           dS )r   r+   r,   N)rn   r   r   rC   rB   s      r   rC   z"WindowsAuthorizer.impersonate_user  sE    ;&&.4"28b!2248LLLLLr   c                 \    |                      |          rdS ||                                 v S r   r   r0   s     r   r   zWindowsAuthorizer.has_user  r   r   c                 r    |                      |d          }|r|}nt                              | |          }|S r   )r   r   r4   )r   r%   r   r   s       r   r4   zWindowsAuthorizer.get_home_dir  s?    "mmHf==O J&,99$IIKr   )r   NNNNr   r   r   )rg   rh   ri   rj   r   r   r>   rC   rr   r   r4   rA   r   r   r   r     s        	 	* %#)?	3 ?	3 ?	3 ?	3H 	 	 	 	$	 	 	,	M 	M 	M 
	8 	8 
		8
 
	 	 
		 	 	r   )rj   r   rY   
exceptionsr   r   __all__r   rr   rt   catch_warningssimplefilterr   r   r   getuidr   getgidr   r   r   ImportErrorr   r   r   r  r   r   r   r   rA   r   r   <module>r     s  
  
			  , , , , , , ' ' ' ' ' ' R# R# R# R# R# R# R# R#j  &kM kM kM kM kM kM kM kMdP!	 	 	"	"  h'''


	               $&677G ")++K")++KX4 X4 X4 X4 X4 X4 X4 X4tg! g! g! g! g! 2 g! g! g! g!G  	 	 	D	d@OOOOOOOOO MMM')<==G`4 `4 `4 `4 `4 `4 `4 `4DQ Q Q Q QE#8 Q Q Q Q QS  	 	 	DD	sG   B= A0$B= 0A44B= 7A48B= =CC	D DD