ó
E®Uc           @   sA   d  Z  d Z d d l Z d d l Z d e j f d „  ƒ  YZ d S(   s3   Convenience functions for using the idmap database.t   restructuredTextiÿÿÿÿNt   IDmapDBc           B   se   e  Z d  Z d Z d Z d Z d	 d	 d	 d	 d	 d d	 d „ Z d	 d d	 d „ Z d „  Z	 d	 d „ Z
 RS(
   s   The IDmap database.i   i   i   i    c         C   sh   | |  _  | d	 k r' | j d ƒ } n  t t |  ƒ j d | d | d | d | d | d | d | ƒ d	 S(
   sb   Opens the IDMap Database.

        For parameter meanings see the super class (samba.Ldb)
        s	   idmap.ldbt   urlt   lpt   modules_dirt   session_infot   credentialst   flagst   optionsN(   R   t   Nonet   private_patht   superR   t   __init__(   t   selfR   R   R   R   R   R   R   (    (    s/   /usr/lib/python2.7/dist-packages/samba/idmap.pyR   "   s    	$c         C   s5   t  t |  ƒ j d |  j j | ƒ d | d | ƒ d  S(   NR   R   R   (   R   R   t   connectR   R
   (   R   R   R   R   (    (    s/   /usr/lib/python2.7/dist-packages/samba/idmap.pyR   0   s    *c         C   sÏ   |  j  d d d d d t j ƒ } | d j d ƒ } t j } | d k rh | d j d ƒ } t j } n  t t | ƒ ƒ d	 } t j	 ƒ  } t j
 |  d
 ƒ | _ t j t | ƒ | d ƒ | d <|  j | ƒ | S(   s“   Increment xidNumber, if not present it create and assign it to the lowerBound

        :return xid can that be used for SID/unixid mapping
        t
   expressions   distinguishedName=CN=CONFIGt   baset    t   scopei    t	   xidNumbert
   lowerBoundi   s	   CN=CONFIGN(   t   searcht   ldbt   SCOPE_SUBTREEt   gett   FLAG_MOD_REPLACER	   t   FLAG_MOD_ADDt   intt   strt   Messaget   Dnt   dnt   MessageElementt   modify(   R   t   rest   idt   flagt   newidt   msg(    (    s/   /usr/lib/python2.7/dist-packages/samba/idmap.pyt   increment_xid4   s    	c         C   sª   | d k r |  j ƒ  } n  d } | |  j k r9 d } n4 | |  j k rQ d } n | |  j k ri d } n d Sd | | | | | f } |  j |  j | ƒ j ƒ  d ƒ d S(   sÏ   Setup a mapping between a sam name and a unix name.

        :param sid: SID of the NT-side of the mapping.
        :param unixname: Unix id to map to, if none supplied the next one will be selected
        R   t   ID_TYPE_UIDt   ID_TYPE_GIDt   ID_TYPE_BOTHNsL   
dn: CN=%s
xidNumber: %s
objectSid: %s
objectClass: sidMap
type: %s
cn: %s

i   (   R	   R'   t   TYPE_UIDt   TYPE_GIDt	   TYPE_BOTHt   addt
   parse_ldift   next(   R   t   sidt   typet   unixidt   type_stringt   mod(    (    s/   /usr/lib/python2.7/dist-packages/samba/idmap.pyt   setup_name_mappingG   s    			
N(   t   __name__t
   __module__t   __doc__R+   R,   R-   R	   R   R   R'   R6   (    (    (    s/   /usr/lib/python2.7/dist-packages/samba/idmap.pyR      s   	(   R9   t   __docformat__R   t   sambat   LdbR   (    (    (    s/   /usr/lib/python2.7/dist-packages/samba/idmap.pyt   <module>   s   