³ņ
OÉcIc        
   @   s  d  Z  y d d k Z d d k Z Wn e j
 o n Xd d k Z d d k Z d a d a h  Z	 h  Z
 h  Z d   Z h  Z d   Z d d d     YZ d e f d     YZ d	 d d
     YZ d   Z d   Z d d d  Z d d d  Z d   Z d   Z d   Z d S(   s·  This module deal with users and groups

On each connection we may need to map unames and gnames to uids and
gids, and possibly vice-versa.  So maintain a separate dictionary for
this.

On the destination connection only, if necessary have a separate
dictionary of mappings, which specify how to map users/groups on one
connection to the users/groups on the other.  The UserMap and GroupMap
objects should only be used on the destination.

i’’’’Nc         C   sm   y t  |  SWnZ t j
 oN y t i |   d } Wn t t f j
 o d } n X| t  |  <| Sn Xd S(   s.   Given uname, return uid or None if cannot findi   N(   t   uname2uid_dictt   KeyErrort   pwdt   getpwnamt	   NameErrort   None(   t   unamet   uid(    (    s<   /var/lib/python-support/python2.5/rdiff_backup/user_group.pyt	   uname2uid6   s       
c         C   sm   y t  |  SWnZ t j
 oN y t i |   d } Wn t t f j
 o d } n X| t  |  <| Sn Xd S(   s.   Given gname, return gid or None if cannot findi   N(   t   gname2gid_dictR   t   grpt   getgrnamR   R   (   t   gnamet   gid(    (    s<   /var/lib/python-support/python2.5/rdiff_backup/user_group.pyt	   gname2gid@   s       
t   Mapc           B   s/   e  Z d  Z d   Z d d  Z d d  Z RS(   s9   Used for mapping names and id on source side to dest sidec         C   s   | o t  p t |  _ d S(   s4   Initialize, user is true for users, false for groupsN(   R   R   t   name2id(   t   selft   is_user(    (    s<   /var/lib/python-support/python2.5/rdiff_backup/user_group.pyt   __init__L   s    c         C   s;   | p | Sn |  i  |  } | d j o | Sn | Sd S(   s0   Return mapped id from id and, if available, nameN(   R   R   (   R   t   idt   namet   newid(    (    s<   /var/lib/python-support/python2.5/rdiff_backup/user_group.pyt   __call__P   s      c         C   s   | p | Sn |  i  |  S(   sæ   Like get_id, but use this for ACLs.  Return id or None

		Unlike ordinary user/group ownership, ACLs are not required
		and can be dropped.  If we cannot map the name over, return
		None.

		(   R   (   R   R   R   (    (    s<   /var/lib/python-support/python2.5/rdiff_backup/user_group.pyt   map_aclW   s     N(   t   __name__t
   __module__t   __doc__R   R   R   R   (    (    (    s<   /var/lib/python-support/python2.5/rdiff_backup/user_group.pyR   J   s   	t
   DefinedMapc           B   s8   e  Z d  Z d   Z d   Z d d  Z d d  Z RS(   s   Map names and ids on source side to appropriate ids on dest side

	Like map, but initialize with user-defined mapping string, which
	supersedes Map.

	c         C   sģ   t  i |  |  h  |  _ h  |  _ xĆ | i d  D]² } | i   } | p q2 n | i d  } t |  d j p t i i	 d |  n | \ } } y  |  i
 |  |  i t |  <Wq2 t j
 o |  i
 |  |  i | <q2 Xq2 Wd S(   sé   Initialize object with given mapping string

		The mapping_string should consist of a number of lines, each which
		should have the form "source_id_or_name:dest_id_or_name".  Do user
		mapping unless user is false, then do group.

		s   
t   :i   s&   Error parsing mapping file, bad line: N(   R   R   t   name_mapping_dictt   id_mapping_dictt   splitt   stript   lent   logt   Logt
   FatalErrort   init_get_new_idt   intt
   ValueError(   R   R   t   mapping_stringt   linet   compst   oldt   new(    (    s<   /var/lib/python-support/python2.5/rdiff_backup/user_group.pyR   j   s"    	 	    c         C   sc   y t  |  SWnN t j
 oB y |  i |  SWq_ t j
 o t i i d |  q_ Xn Xd S(   s=   Return id of id_or_name, failing if cannot.  Used in __init__s%   Cannot get id for user or group name N(   R'   R(   R   R   R#   R$   R%   (   R   t
   id_or_name(    (    s<   /var/lib/python-support/python2.5/rdiff_backup/user_group.pyR&      s      c         C   s/   |  i  | |  } | d j o | Sn | Sd S(   s#   Return new id given old id and nameN(   R   R   (   R   R   R   R   (    (    s<   /var/lib/python-support/python2.5/rdiff_backup/user_group.pyR      s     c         C   s   | oM y |  i  | SWn t j
 o n X|  i |  } | d j	 o | SqT n y |  i | SWn t j
 o d Sn Xd S(   s8   Return new id or None given old and name (used for ACLs)N(   R   R   R   R   R   (   R   R   R   R   (    (    s<   /var/lib/python-support/python2.5/rdiff_backup/user_group.pyR      s         N(   R   R   R   R   R&   R   R   R   (    (    (    s<   /var/lib/python-support/python2.5/rdiff_backup/user_group.pyR   c   s
   			t   NumericalMapc           B   s&   e  Z d  Z d d  Z d d  Z RS(   s;   Simple Map replacement that just keeps numerical uid or gidc         C   s   | S(   N(    (   R   R   R   (    (    s<   /var/lib/python-support/python2.5/rdiff_backup/user_group.pyR      s    c         C   s   | S(   N(    (   R   R   R   (    (    s<   /var/lib/python-support/python2.5/rdiff_backup/user_group.pyR      s    N(   R   R   R   R   R   R   (    (    (    s<   /var/lib/python-support/python2.5/rdiff_backup/user_group.pyR/      s   c         C   sr   y t  |  SWn_ t j
 oS y t i |   d } Wn$ t t t f j
 o } d } n X| t  |  <| Sn Xd S(   s@   Given uid, return uname from passwd file, or None if cannot findi    N(   t   uid2uname_dictR   R   t   getpwuidt   OverflowErrorR   R   (   R   R   t   e(    (    s<   /var/lib/python-support/python2.5/rdiff_backup/user_group.pyt	   uid2uname„   s       
c         C   sr   y t  |  SWn_ t j
 oS y t i |   d } Wn$ t t t f j
 o } d } n X| t  |  <| Sn Xd S(   sC   Given gid, return group name from group file or None if cannot findi    N(   t   gid2gname_dictR   R
   t   getgrgidR2   R   R   (   R   R   R3   (    (    s<   /var/lib/python-support/python2.5/rdiff_backup/user_group.pyt	   gid2gname®   s       
c         C   s>   | o t    a n' |  o t d |   a n t d  a d S(   s±   Initialize user mapping with given mapping string

	If numerical_ids is set, just keep the same uid.  If either
	argument is None, default to preserving uname where possible.

	i   N(   R/   t   UserMapR   R   (   R)   t   numerical_ids(    (    s<   /var/lib/python-support/python2.5/rdiff_backup/user_group.pyt   init_user_mappingø   s
      c         C   s>   | o t    a n' |  o t d |   a n t d  a d S(   s²   Initialize group mapping with given mapping string

	If numerical_ids is set, just keep the same gid.  If either
	argument is None, default to preserving gname where possible.

	i    N(   R/   t   GroupMapR   R   (   R)   R9   (    (    s<   /var/lib/python-support/python2.5/rdiff_backup/user_group.pyt   init_group_mappingÄ   s
      c         C   sG   |  i    \ } } |  i   |  i   } } t | |  t | |  f S(   s”   Return mapped (newuid, newgid) from rpath's initial info

	This is the main function exported by the user_group module.  Note
	that it is connection specific.

	(   t	   getuidgidt   getunamet   getgnameR8   R;   (   t   rpR   R   R   R   (    (    s<   /var/lib/python-support/python2.5/rdiff_backup/user_group.pyt	   map_rpathŃ   s    c         C   s   t  i |  |  S(   N(   R8   R   (   R   R   (    (    s<   /var/lib/python-support/python2.5/rdiff_backup/user_group.pyt   acl_user_mapÜ   s    c         C   s   t  i |  |  S(   N(   R;   R   (   R   R   (    (    s<   /var/lib/python-support/python2.5/rdiff_backup/user_group.pyt   acl_group_mapŻ   s    (    (    (   R   R
   R   t   ImportErrorR#   t   GlobalsR   R8   R;   R0   R5   R    R   R	   R   R   R   R/   R4   R7   R:   R<   RA   RB   RC   (    (    (    s<   /var/lib/python-support/python2.5/rdiff_backup/user_group.pys   <module>   s.    			
9				
		