
uUc           @   s   d  Z  d d l Z d d l Z d d l Z d d l Z d d l Z d d l m Z d d l m Z m	 Z	 d d l
 m Z m Z d d l m Z d Z d e j f d	     YZ d S(
   s(   Convenience functions for using the SAM.iN(   t   dsdb(   t
   ndr_unpackt   ndr_pack(   t   drsblobst   misc(   t   normalise_int32t   restructuredTextt   SamDBc           B   s  e  Z d  Z i  Z i  Z d> d> d> d> d> d d> e e d> d 
 Z d> d d> d  Z d   Z	 d   Z
 d   Z d   Z d   Z d> e e d	  Z d
   Z d> d> d> d> d> d> d> d> d  Z d   Z e d  Z e e d> d> d> d> d> d> d> d> d> d> d> d> d> d> d> d> d> e d> d> d> d> d> d> d> d  Z d   Z e d> d  Z e d  Z d   Z d   Z e e e d  Z d   Z d   Z e e e d  Z d   Z e d  Z  d   Z! d   Z" d   Z# d   Z$ d   Z% d   Z& d    Z' d!   Z( d"   Z) d#   Z* d$   Z+ d%   Z, e d&  Z- e d'  Z. d(   Z/ d)   Z0 d*   Z1 d+   Z2 d,   Z3 e d-  Z4 d.   Z5 d/   Z6 d0   Z7 d1   Z8 d2   Z9 d3   Z: d4   Z; d5   Z< d6   Z= d7   Z> d8   Z? d9   Z@ d> d> d> d:  ZA d;   ZB d<   ZC d=   ZD RS(?   s   The SAM database.i    c         C   s   | |  _  |	 s d  } n' | d  k r? | d  k	 r? | j   } n  | |  _ t t |   j d | d | d | d | d | d | d |  | r t j |   n  |
 d  k	 r t j	 |  |
  n  d  S(   Nt   urlt   lpt   modules_dirt   session_infot   credentialst   flagst   options(
   R	   t   Nonet	   samdb_urlR   t   superR   t   __init__R    t   _dsdb_set_global_schemat   _dsdb_set_am_rodc(   t   selfR   R	   R
   R   R   R   R   t   global_schemat   auto_connectt   am_rodc(    (    s/   /usr/lib/python2.7/dist-packages/samba/samdb.pyR   ,   s    			$c         C   si   |  j  d k	 r7 t j j |  r7 |  j  j |  } n  | |  _ t t |   j	 d | d | d |  d S(   s   connect to the databaseR   R   R   N(
   R	   R   t   ost   patht   existst   private_pathR   R   R   t   connect(   R   R   R   R   (    (    s/   /usr/lib/python2.7/dist-packages/samba/samdb.pyR   A   s
    "	c         C   s   t  j |   S(   s   return True if we are an RODC(   R    t   _am_rodc(   R   (    (    s/   /usr/lib/python2.7/dist-packages/samba/samdb.pyR   J   s    c         C   s   t  j |   S(   s%   return True if we are an PDC emulator(   R    t   _am_pdc(   R   (    (    s/   /usr/lib/python2.7/dist-packages/samba/samdb.pyt   am_pdcN   s    c         C   s   t  |  j    S(   s   return the domain DN(   t   strt   get_default_basedn(   R   (    (    s/   /usr/lib/python2.7/dist-packages/samba/samdb.pyt	   domain_dnR   s    c         C   s&   t  j j } |  j | | d t d S(   s|   Disables an account

        :param search_filter: LDAP filter to find the user (eg
            samccountname=name)
        t   onN(   t   sambaR    t   UF_ACCOUNTDISABLEt   toggle_userAccountFlagst   True(   R   t   search_filterR   (    (    s/   /usr/lib/python2.7/dist-packages/samba/samdb.pyt   disable_accountV   s    c         C   s0   t  j j t  j j B} |  j | | d t d S(   s{   Enables an account

        :param search_filter: LDAP filter to find the user (eg
            samccountname=name)
        R$   N(   R%   R    R&   t   UF_PASSWD_NOTREQDR'   t   False(   R   R)   R   (    (    s/   /usr/lib/python2.7/dist-packages/samba/samdb.pyt   enable_account`   s    c      	   C   s7  |  j  d |  j   d t j d | d d g  } t |  d k rU t d |   n  t |  d k sm t  | d j } t | d d d  } | r | r | | @r d	 | }	 t |	   n  | | B}
 n5 | r | | @r d
 | }	 t |	   n  | | @}
 | |
 k rd Sd | | |
 f } |  j	 |  d S(   sn  Toggle_userAccountFlags

        :param search_filter: LDAP filter to find the user (eg
            samccountname=name)
        :param flags: samba.dsdb.UF_* flags
        :param on: on=True (default) => set, on=False => unset
        :param strict: strict=False (default) ignore if no action is needed
                 strict=True raises an Exception if...
        t   baset   scopet
   expressiont   attrst   userAccountControli    s!   Unable to find account where '%s'i   s    Account flag(s) '%s' already sets"   Account flag(s) '%s' already unsetNs|   
dn: %s
changetype: modify
delete: userAccountControl
userAccountControl: %u
add: userAccountControl
userAccountControl: %u
(
   t   searchR#   t   ldbt   SCOPE_SUBTREEt   lent	   Exceptiont   AssertionErrort   dnt   intt   modify_ldif(   R   R)   R   t	   flags_strR$   t   strictt   rest
   account_dnt   old_uact   errort   new_uact   mod(    (    s/   /usr/lib/python2.7/dist-packages/samba/samdb.pyR'   j   s(    

	c      	   C   s   |  j  d |  j   d t j d | d g   } t |  d k rR t d |   n  t |  d k sj t  | d j } d | } |  j |  d	 S(
   s   Forces a password change at next login

        :param search_filter: LDAP filter to find the user (eg
            samccountname=name)
        R.   R/   R0   R1   i    s   Unable to find user "%s"i   s=   
dn: %s
changetype: modify
replace: pwdLastSet
pwdLastSet: 0
N(	   R3   R#   R4   R5   R6   R7   R8   R9   R;   (   R   R)   R>   t   user_dnRC   (    (    s/   /usr/lib/python2.7/dist-packages/samba/samdb.pyt#   force_password_change_at_next_login   s    
c
         C   s  d | | p d |  j    f }
 i |
 d 6| d 6d d 6} | d k	 rY t |  | d <n  | d k	 rr | | d <n  | d k	 r | | d	 <n  | d k	 r | | d
 <n  | d k	 r t |  | d <n  |	 d k	 r | | d <|	 | d <n  | d k	 rt |  | d <n  |  j |  d S(   s  Adds a new group with additional parameters

        :param groupname: Name of the new group
        :param grouptype: Type of the new group
        :param description: Description of the new group
        :param mailaddress: Email address of the new group
        :param notes: Notes of the new group
        :param gidnumber: GID Number of the new group
        :param nisdomain: NIS Domain Name of the new group
        :param sd: security descriptor of the object
        s   CN=%s,%s,%ss   CN=UsersR9   t   sAMAccountNamet   groupt   objectClasst	   groupTypet   descriptiont   mailt   infot	   gidNumbert   msSFU30Namet   msSFU30NisDomaint   nTSecurityDescriptorN(   R#   R   R   R   t   add(   R   t	   groupnamet   groupout	   grouptypeRJ   t   mailaddresst   notest   sdt	   gidnumbert	   nisdomaint   group_dnt
   ldbmessage(    (    s/   /usr/lib/python2.7/dist-packages/samba/samdb.pyt   newgroup   s(    


c      	   C   s   d t  j |  d |  j   f } |  j   y |  j d |  j   d t  j d | d g   } t |  d k r t d |   n  t |  d	 k s t  |  j	 | d j
  Wn |  j     n X|  j   d
 S(   sL   Deletes a group

        :param groupname: Name of the target group
        s,   (&(sAMAccountName=%s)(objectCategory=%s,%s))s#   CN=Group,CN=Schema,CN=ConfigurationR.   R/   R0   R1   i    s   Unable to find group "%s"i   N(   R4   t   binary_encodeR#   t   transaction_startR3   R5   R6   R7   R8   t   deleteR9   t   transaction_cancelt   transaction_commit(   R   RR   t   groupfiltert   targetgroup(    (    s/   /usr/lib/python2.7/dist-packages/samba/samdb.pyt   deletegroup   s    "

c   
      C   sN  d t  j |  d |  j   f } |  j   y|  j d |  j   d t  j d | d d g  } t |  d k r t d	 |   n  t |  d
 k s t  t	 } d t
 | d j  } xP| D]H} |  j d |  j   d t  j d d t  j |  t  j |  f d g   }	 t |	  d
 k r4t d |   n  | t k r| d j d  d k szt
 |	 d j  | d d k rt } | d t
 |	 d j  7} q | t	 k r | d j d  d k	 r t
 |	 d j  | d d k r t } | d t
 |	 d j  7} q q W| t k r(|  j |  n  Wn |  j     n X|  j   d S(   s   Adds or removes group members

        :param groupname: Name of the target group
        :param members: list of group members
        :param add_members_operation: Defines if its an add or remove
            operation
        s,   (&(sAMAccountName=%s)(objectCategory=%s,%s))s#   CN=Group,CN=Schema,CN=ConfigurationR.   R/   R0   R1   t   memberi    s   Unable to find group "%s"i   s   
dn: %s
changetype: modify
s   (|(sAMAccountName=%s)(CN=%s))s)   Unable to find "%s". Operation cancelled.s   add: member
member: %s
s   delete: member
member: %s
N(   R4   R]   R#   R^   R3   R5   R6   R7   R8   R,   R!   R9   R(   t   getR   R;   R`   Ra   (
   R   RR   t   memberst   add_members_operationRb   Rc   t   modifiedt   addtargettogroupRe   t   targetmember(    (    s/   /usr/lib/python2.7/dist-packages/samba/samdb.pyt   add_remove_group_members   s>    

(FF
c   %      C   s?  d } | d- k	 r | | 7} n  | d- k	 r< | d | 7} n  | d- k	 rY | d | 7} n  | } | d- k r | d k	 r | } n  d | | p d |  j   f }  t j |  |  j    j   j d d  }! d | |! f }" i |  d 6| d	 6|" d
 6d d 6}# | d- k	 r| |# d <n  | d- k	 r-| |# d <n  | d k	 rP| |# d <| |# d <n  | d- k	 rmd | |# d <n  |	 d- k	 r|	 |# d <n  |
 d- k	 r|
 |# d <n  | d- k	 r| |# d <n  | d- k	 r| |# d <n  | d- k	 r| |# d <n  | d- k	 r| |# d <n  | d- k	 r| |# d <n  | d- k	 r5| |# d <n  | d- k	 rN| |# d <n  | d- k	 rg| |# d <n  | d- k	 r| |# d <n  | d- k	 r| |# d <n  | d- k	 rt |  |# d <n  d- }$ t t d    | | | | | | | f   rt j	   }$ t j |  |   |$ _
 t j d! t j d  |$ d <| d- k	 rYt j t |  t j d"  |$ d" <n  | d- k	 rt j t |  t j d#  |$ d# <n  | d- k	 rt j t |  t j d$  |$ d$ <n  | d- k	 rt j t |  t j d%  |$ d% <n  | d- k	 rt j t |  t j d&  |$ d& <n  | d- k	 rNt j t |  t j d'  |$ d' <n  | d- k	 rt j t |  t j d(  |$ d( <t j t |  t j d)  |$ d) <t j d* t j d+  |$ d+ <qn  |  j   yP |  j |#  |$ r|  j |$  n  | r|  j d, t j |  | |  n  Wn |  j     n X|  j   d- S(.   s  Adds a new user with additional parameters

        :param username: Name of the new user
        :param password: Password for the new user
        :param force_password_change_at_next_login_req: Force password change
        :param useusernameascn: Use username as cn rather that firstname +
            initials + lastname
        :param userou: Object container (without domainDN postfix) for new user
        :param surname: Surname of the new user
        :param givenname: First name of the new user
        :param initials: Initials of the new user
        :param profilepath: Profile path of the new user
        :param scriptpath: Logon script path of the new user
        :param homedrive: Home drive of the new user
        :param homedirectory: Home directory of the new user
        :param jobtitle: Job title of the new user
        :param department: Department of the new user
        :param company: Company of the new user
        :param description: of the new user
        :param mailaddress: Email address of the new user
        :param internetaddress: Home page of the new user
        :param telephonenumber: Phone number of the new user
        :param physicaldeliveryoffice: Office location of the new user
        :param sd: security descriptor of the object
        :param setpassword: optionally disable password reset
        :param uidnumber: RFC2307 Unix numeric UID of the new user
        :param gidnumber: RFC2307 Unix primary GID of the new user
        :param gecos: RFC2307 Unix GECOS field of the new user
        :param loginshell: RFC2307 Unix login shell of the new user
        :param uid: RFC2307 Unix username of the new user
        :param nisdomain: RFC2307 Unix NIS domain of the new user
        :param unixhome: RFC2307 Unix home directory of the new user
        t    s    %s.s    %ss   CN=%s,%s,%ss   CN=Userst   /s   %s@%sR9   RF   t   userPrincipalNamet   userRH   t   snt	   givenNamet   displayNamet   names   %s.t   initialst   profilePatht
   scriptPatht	   homeDrivet   homeDirectoryt   titlet
   departmentt   companyRJ   RK   t   wWWHomePaget   telephoneNumbert   physicalDeliveryOfficeNameRP   c         S   s
   |  d  k	 S(   N(   R   (   t   b(    (    s/   /usr/lib/python2.7/dist-packages/samba/samdb.pyt   <lambda>  s    t   posixAccountt   uidt	   uidNumberRM   t   gecost
   loginShellt   unixHomeDirectoryRO   RN   s   ABCD!efgh12345$67890t   unixUserPasswords   (samAccountName=%s)N(   R   R#   R4   t   Dnt   canonical_strt   replaceR   t   anyt   mapt   MessageR9   t   MessageElementt   FLAG_MOD_ADDR!   t   FLAG_MOD_REPLACER^   RQ   t   modifyt   setpasswordR]   R`   Ra   (%   R   t   usernamet   passwordt'   force_password_change_at_next_login_reqt   useusernameascnt   userout   surnamet	   givennameRu   t   profilepatht
   scriptpatht	   homedrivet   homedirectoryt   jobtitleR{   R|   RJ   RU   t   internetaddresst   telephonenumbert   physicaldeliveryofficeRW   R   t	   uidnumberRX   R   t
   loginshellR   RY   t   unixhomet   displaynamet   cnRD   t	   dnsdomaint   user_principal_nameR[   t   ldbmessage2(    (    s/   /usr/lib/python2.7/dist-packages/samba/samdb.pyt   newuser)  s    +	*


%%%%%	

c      	   C   s   d t  j |  d |  j   f } |  j   y |  j d |  j   d t  j d | d g   } t |  d k r t d |   n  t |  d	 k s t  |  j	 | d j
  Wn |  j     n X|  j   d
 S(   sI   Deletes a user

        :param username: Name of the target user
        s,   (&(sAMAccountName=%s)(objectCategory=%s,%s))s$   CN=Person,CN=Schema,CN=ConfigurationR.   R/   R0   R1   i    s   Unable to find user "%s"i   N(   R4   R]   R#   R^   R3   R5   R6   R7   R8   R_   R9   R`   Ra   (   R   R   t   filtert   target(    (    s/   /usr/lib/python2.7/dist-packages/samba/samdb.pyt
   deleteuser  s    "

c   	   	   C   s@  |  j    y|  j d |  j   d t j d | d g   } t |  d k re t d | p[ |   n  t |  d k r t d t |  | f   n  | d j } t d	 | d	 d
  j	 d  } d | t
 j |  f } |  j |  | r|  j d t |  d  n  |  j |  Wn |  j     n X|  j   d S(   s   Sets the password for a user

        :param search_filter: LDAP filter to find the user (eg
            samccountname=name)
        :param password: Password for the user
        :param force_change_at_next_login: Force password change
        R.   R/   R0   R1   i    s   Unable to find user "%s"i   s*   Matched %u multiple users with filter "%s"t   "s   utf-8s	   utf-16-les?   
dn: %s
changetype: modify
replace: unicodePwd
unicodePwd:: %s
s   (distinguishedName=t   )N(   R^   R3   R#   R4   R5   R6   R7   R9   t   unicodet   encodet   base64t	   b64encodeR;   RE   R!   R-   R`   Ra   (	   R   R)   R   t   force_change_at_next_loginR   R>   RD   t   pwt   setpw(    (    s/   /usr/lib/python2.7/dist-packages/samba/samdb.pyR     s(    	
 
c   	   
   C   sB  |  j    y|  j d |  j   d t j d | d d d g  } t |  d k re t d |   n  t |  d	 k s} t  | d j } t	 | d d d  } t	 | d d d  } | r | d
 B} d } n) | d @} t
 j | t	 t j     } d | | | f } |  j |  Wn |  j     n X|  j   d S(   s  Sets the account expiry for a user

        :param search_filter: LDAP filter to find the user (eg
            samaccountname=name)
        :param expiry_seconds: expiry time from now in seconds
        :param no_expiry_req: if set, then don't expire password
        R.   R/   R0   R1   R2   t   accountExpiresi    s   Unable to find user "%s"i   i   sy   
dn: %s
changetype: modify
replace: userAccountControl
userAccountControl: %u
replace: accountExpires
accountExpires: %u
Ni(   R^   R3   R#   R4   R5   R6   R7   R8   R9   R:   R%   t   unix2nttimet   timeR;   R`   Ra   (	   R   R)   t   expiry_secondst   no_expiry_reqR>   RD   R2   R   t   setexp(    (    s/   /usr/lib/python2.7/dist-packages/samba/samdb.pyt	   setexpiry  s,    

	
	
c         C   s   t  j |  |  d S(   s`   Change the domain SID used by this LDB.

        :param sid: The new domain sid to use.
        N(   R    t   _samdb_set_domain_sid(   R   t   sid(    (    s/   /usr/lib/python2.7/dist-packages/samba/samdb.pyt   set_domain_sid6  s    c         C   s   t  j |   S(   s&   Read the domain SID used by this LDB. (   R    t   _samdb_get_domain_sid(   R   (    (    s/   /usr/lib/python2.7/dist-packages/samba/samdb.pyt   get_domain_sid=  s    s   SID for the domainc         C   s   t  j |  |  d S(   so   Set the invocation id for this SamDB handle.

        :param invocation_id: GUID of the invocation id.
        N(   R    t   _dsdb_set_ntds_invocation_id(   R   t   invocation_id(    (    s/   /usr/lib/python2.7/dist-packages/samba/samdb.pyt   set_invocation_idD  s    c         C   s   t  j |   S(   s   Get the invocation_id id(   R    t   _samdb_ntds_invocation_id(   R   (    (    s/   /usr/lib/python2.7/dist-packages/samba/samdb.pyt   get_invocation_idK  s    s   Invocation ID GUIDc         C   s   t  j |  |  S(   N(   R    t   _dsdb_get_oid_from_attid(   R   t   attid(    (    s/   /usr/lib/python2.7/dist-packages/samba/samdb.pyt   get_oid_from_attidR  s    c         C   s   t  j |  | |  S(   sN   return the attribute ID for a LDAP attribute as an integer as found in DRSUAPI(   R    t$   _dsdb_get_attid_from_lDAPDisplayName(   R   t   ldap_display_namet   is_schema_nc(    (    s/   /usr/lib/python2.7/dist-packages/samba/samdb.pyt   get_attid_from_lDAPDisplayNameU  s    	c         C   s   t  j |  |  S(   s6   return the syntax OID for a LDAP attribute as a string(   R    t)   _dsdb_get_syntax_oid_from_lDAPDisplayName(   R   R   (    (    s/   /usr/lib/python2.7/dist-packages/samba/samdb.pyt#   get_syntax_oid_from_lDAPDisplayName[  s    c         C   s   t  j |  |  S(   s8   return the systemFlags for a LDAP attribute as a integer(   R    t*   _dsdb_get_systemFlags_from_lDAPDisplayName(   R   R   (    (    s/   /usr/lib/python2.7/dist-packages/samba/samdb.pyt$   get_systemFlags_from_lDAPDisplayName_  s    c         C   s   t  j |  |  S(   s3   return the linkID for a LDAP attribute as a integer(   R    t%   _dsdb_get_linkId_from_lDAPDisplayName(   R   R   (    (    s/   /usr/lib/python2.7/dist-packages/samba/samdb.pyt   get_linkId_from_lDAPDisplayNamec  s    c         C   s   t  j |  |  S(   s;   return the lDAPDisplayName from an integer DRS attribute ID(   R    t"   _dsdb_get_lDAPDisplayName_by_attid(   R   R   (    (    s/   /usr/lib/python2.7/dist-packages/samba/samdb.pyt   get_lDAPDisplayName_by_attidg  s    c         C   s   t  j |  |  S(   s   return the attribute name of the corresponding backlink from the name
        of a forward link attribute. If there is no backlink return None(   R    t'   _dsdb_get_backlink_from_lDAPDisplayName(   R   R   (    (    s/   /usr/lib/python2.7/dist-packages/samba/samdb.pyt!   get_backlink_from_lDAPDisplayNamek  s    c         C   s   t  j |  |  d S(   s   Set the NTDS Settings DN, as would be returned on the dsServiceName
        rootDSE attribute.

        This allows the DN to be set before the database fully exists

        :param ntds_settings_dn: The new DN to use
        N(   R    t   _samdb_set_ntds_settings_dn(   R   t   ntds_settings_dn(    (    s/   /usr/lib/python2.7/dist-packages/samba/samdb.pyt   set_ntds_settings_dnp  s    c         C   s   t  j |   S(   s   Get the NTDS objectGUID(   R    t   _samdb_ntds_objectGUID(   R   (    (    s/   /usr/lib/python2.7/dist-packages/samba/samdb.pyt   get_ntds_GUIDz  s    c         C   s   t  j |   S(   s   Get the server site name(   R    t   _samdb_server_site_name(   R   (    (    s/   /usr/lib/python2.7/dist-packages/samba/samdb.pyt   server_site_name~  s    c         C   s4   |  j  d d d t j d d g  } | d d d S(   s    return the DNS name of this hostR.   Rm   R/   R1   t   dNSHostNamei    (   R3   R4   t
   SCOPE_BASE(   R   R>   (    (    s/   /usr/lib/python2.7/dist-packages/samba/samdb.pyt   host_dns_name  s    $c         C   s#   |  j    } | j   j d  d S(   s&   return the DNS name of the domain rootRn   i    (   R"   R   t   split(   R   R#   (    (    s/   /usr/lib/python2.7/dist-packages/samba/samdb.pyt   domain_dns_name  s    c         C   s#   |  j    } | j   j d  d S(   s&   return the DNS name of the forest rootRn   i    (   t   get_root_basednR   R   (   R   t	   forest_dn(    (    s/   /usr/lib/python2.7/dist-packages/samba/samdb.pyt   forest_dns_name  s    c         C   s   t  j |  |  S(   N(   R    t   _dsdb_load_partition_usn(   R   t   base_dn(    (    s/   /usr/lib/python2.7/dist-packages/samba/samdb.pyt   load_partition_usn  s    c         C   s   |  j  | j d | d  S(   Nt   write_indices_and_attributes(   t   set_schema_from_ldbR4   (   R   t   schemaR   (    (    s/   /usr/lib/python2.7/dist-packages/samba/samdb.pyt
   set_schema  s    c         C   s   t  j |  | |  d  S(   N(   R    t   _dsdb_set_schema_from_ldb(   R   t   ldb_connR   (    (    s/   /usr/lib/python2.7/dist-packages/samba/samdb.pyR     s    c         C   s   t  j | | |  S(   sB   convert a list of attribute values to a DRSUAPI DsReplicaAttribute(   R    t   _dsdb_DsReplicaAttribute(   R   R4   R   t   ldif_elements(    (    s/   /usr/lib/python2.7/dist-packages/samba/samdb.pyt   dsdb_DsReplicaAttribute  s    c         C   s   t  j | | |  S(   s$   normalise a list of attribute values(   R    t   _dsdb_normalise_attributes(   R   R4   R   R   (    (    s/   /usr/lib/python2.7/dist-packages/samba/samdb.pyt   dsdb_normalise_attributes  s    c         C   s_   t  |  j j    d k r( |  j   n  |  j j |  j |   rW |  j |  j |  Sd Sd S(   s    Get from an attid the associated attribute

        :param attid: The attribute id for searched attribute
        :return: The name of the attribute associated with this id
        i    N(   R6   t   hash_oid_namet   keyst   _populate_oid_attidt   has_keyR   R   (   R   R   (    (    s/   /usr/lib/python2.7/dist-packages/samba/samdb.pyt   get_attribute_from_attid  s
    c         C   s   i  |  _  |  j d d d d g d d d g  } t |  d k r xB | D]7 } t | j d   } | |  j  t | j d   <qI Wn  d	 S(
   s   Populate the hash hash_oid_name.

        This hash contains the oid of the attribute as a key and
        its display name as a value
        R0   s   objectClass=attributeSchemat   controlss   search_options:1:2R1   t   attributeIDt   lDAPDisplayNamei    N(   R   R3   R6   R!   Rf   (   R   R>   t   et
   strDisplay(    (    s/   /usr/lib/python2.7/dist-packages/samba/samdb.pyR     s    		c      	   C   s   |  j  d d | d t j d d g d d g  } t |  d k rG d	 St t j t | d d   } | j	 } t |  j
 j    d k r |  j   n  x[ | j D]P } |  j | j  } |  j
 j |  r | j   |  j
 | j   k r | j Sq Wd	 S(
   s[  Get the version field trom the replPropertyMetaData for
        the given field

        :param dn: The on which we want to get the version
        :param att: The name of the attribute
        :return: The value of the version field in the replPropertyMetaData
            for the given attribute. None if the attribute is not replicated
        R0   s   distinguishedName=%sR/   R   s   search_options:1:2R1   t   replPropertyMetaDatai    N(   R3   R4   R5   R6   R   R   R   t   replPropertyMetaDataBlobR!   t   ctrR   R   R   t   arrayR   R   R   t   lowert   version(   R   R9   t   attR>   t   replR  t   ot   att_oid(    (    s/   /usr/lib/python2.7/dist-packages/samba/samdb.pyt"   get_attribute_replmetadata_version  s"    
				c      	   C   s  |  j  d d | d t j d d g d d g  } t |  d k rG d  St t j t | d d   } | j	 } t
 j t t j     } t }	 t |  j j    d k r |  j   n  x | j D] }
 |  j |
 j  } |  j j |  r | j   |  j | j   k r t }	 |  j t j  } | |
 _ | |
 _ t j |  j    |
 _ | |
 _  | |
 _! q q W|	 r6| r6t | j  d k r6t j"   } d	 | _ |  j | j  } |  j t j  } | | _ | | _ t j |  j    | _ | | _  | | _! t }	 | j } | j# |  | j$ d
 | _$ | | _ n  |	 rt% |  } t j&   } | d j' | _' t j( | t j) d  | d <|  j* | d g  n  d  S(   NR0   s   distinguishedName=%sR/   R   s   search_options:1:2R1   R  i    iZ 	 i   s#   local_oid:1.3.6.1.4.1.7165.4.3.14:0(+   R3   R4   R5   R6   R   R   R   R  R!   R  R%   R   R:   R   R,   R   R   R   R  R   R   R   R  R(   t   sequence_numbert   SEQ_NEXTR  t   originating_change_timeR   t   GUIDR   t   originating_invocation_idt   originating_usnt	   local_usnt   replPropertyMetaData1t   appendt   countR   R   R9   R   R   R   (   R   R9   R  t   valuet   addifnotexistR>   R  R  t   nowt   foundR	  R
  t   seqt   o2t   tabt   replBlobt   msg(    (    s/   /usr/lib/python2.7/dist-packages/samba/samdb.pyt"   set_attribute_replmetadata_version  s^    							"							c         C   s   t  j |   d  S(   N(   R    t'   _dsdb_write_prefixes_from_schema_to_ldb(   R   (    (    s/   /usr/lib/python2.7/dist-packages/samba/samdb.pyt   write_prefixes_from_schema  s    c         C   s   t  j |   S(   N(   R    t   _dsdb_get_partitions_dn(   R   (    (    s/   /usr/lib/python2.7/dist-packages/samba/samdb.pyt   get_partitions_dn  s    c         C   s   t  j |  |  S(   N(   R    t   _dsdb_get_nc_root(   R   R9   (    (    s/   /usr/lib/python2.7/dist-packages/samba/samdb.pyt   get_nc_root  s    c         C   s   |  j  j t |   } d  } | d  k	 r< | j |  } n  | d  k r t j |  | |  } | d  k rm | S| d  k r i  |  j  t |  <|  j  t |  } n  | | | <n  | S(   N(   t   hash_well_knownRf   R!   R   R    t   _dsdb_get_wellknown_dn(   R   t   nc_roott   wkguidt   h_ncR9   (    (    s/   /usr/lib/python2.7/dist-packages/samba/samdb.pyt   get_wellknown_dn  s    c         C   sT   t  j   } t  j |  |  j    | _ t  j | t  j d  | d <|  j |  d  S(   Nt	   minPwdAge(   R4   R   R   R#   R9   R   R   R   (   R   R  t   m(    (    s/   /usr/lib/python2.7/dist-packages/samba/samdb.pyt   set_minPwdAge+  s    c         C   se   |  j  |  j   d t j d d g } t |  d k r= d  Sd | d k rQ d  S| d d d Sd  S(   NR/   R1   R,  i    (   R3   R#   R4   R   R6   R   (   R   R>   (    (    s/   /usr/lib/python2.7/dist-packages/samba/samdb.pyt   get_minPwdAge1  s    'c         C   sT   t  j   } t  j |  |  j    | _ t  j | t  j d  | d <|  j |  d  S(   Nt   minPwdLength(   R4   R   R   R#   R9   R   R   R   (   R   R  R-  (    (    s/   /usr/lib/python2.7/dist-packages/samba/samdb.pyt   set_minPwdLength:  s    c         C   se   |  j  |  j   d t j d d g } t |  d k r= d  Sd | d k rQ d  S| d d d Sd  S(   NR/   R1   R0  i    (   R3   R#   R4   R   R6   R   (   R   R>   (    (    s/   /usr/lib/python2.7/dist-packages/samba/samdb.pyt   get_minPwdLength@  s    'c         C   sT   t  j   } t  j |  |  j    | _ t  j | t  j d  | d <|  j |  d  S(   Nt   pwdProperties(   R4   R   R   R#   R9   R   R   R   (   R   R  R-  (    (    s/   /usr/lib/python2.7/dist-packages/samba/samdb.pyt   set_pwdPropertiesI  s    c         C   se   |  j  |  j   d t j d d g } t |  d k r= d  Sd | d k rQ d  S| d d d Sd  S(   NR/   R1   R3  i    (   R3   R#   R4   R   R6   R   (   R   R>   (    (    s/   /usr/lib/python2.7/dist-packages/samba/samdb.pyt   get_pwdPropertiesO  s    'c         C   s   t  j   } t  j |  d |  j   j    | _ | d  k	 r\ t  j | t  j d  | d <n t  j g  t  j	 d  | d <|  j
 |  d  S(   Ns1   CN=Directory Service,CN=Windows NT,CN=Services,%st   dSHeuristics(   R4   R   R   t   get_config_basednt   get_linearizedR9   R   R   R   t   FLAG_MOD_DELETER   (   R   t   dsheuristicsR-  (    (    s/   /usr/lib/python2.7/dist-packages/samba/samdb.pyt   set_dsheuristicsX  s    	c         C   s{   |  j  d |  j   j   d t j d d g } t |  d k rL d  } n+ d | d k rq | d d d } n d  } | S(   Ns1   CN=Directory Service,CN=Windows NT,CN=Services,%sR/   R1   R6  i    (   R3   R7  R8  R4   R   R6   R   (   R   R>   R:  (    (    s/   /usr/lib/python2.7/dist-packages/samba/samdb.pyt   get_dsheuristicsd  s    		c         C   sd   i | d 6d d 6} | r' | | d <n  | r: | | d <n  | rS t  |  | d <n  |  j |  d S(   s  Creates an organizationalUnit object
        :param ou_dn: dn of the new object
        :param description: description attribute
        :param name: name atttribute
        :param sd: security descriptor of the object, can be
        an SDDL string or security.descriptor type
        R9   t   organizationalUnitRH   RJ   Rt   RP   N(   R   RQ   (   R   t   ou_dnRJ   Rt   RW   R-  (    (    s/   /usr/lib/python2.7/dist-packages/samba/samdb.pyt	   create_ouq  s    

c         C   sK   |  j    y t t |   j |  } Wn |  j     n X|  j   | S(   s   Returns the value of the sequence number according to the requested type
        :param seq_type: type of sequence number
         (   R^   R   R   R  R`   Ra   (   R   t   seq_typeR  (    (    s/   /usr/lib/python2.7/dist-packages/samba/samdb.pyR    s    


c         C   s4   |  j  d d d t j d d g  } | d d d S(   s    get the NTDS DN from the rootDSER.   Rm   R/   R1   t   dsServiceNamei    (   R3   R4   R   (   R   R>   (    (    s/   /usr/lib/python2.7/dist-packages/samba/samdb.pyt   get_dsServiceName  s    $c         C   s4   |  j  d d d t j d d g  } | d d d S(   s"   get the server DN from the rootDSER.   Rm   R/   R1   t
   serverNamei    (   R3   R4   R   (   R   R>   (    (    s/   /usr/lib/python2.7/dist-packages/samba/samdb.pyt   get_serverName  s    $N(E   t   __name__t
   __module__t   __doc__R   R&  R   R(   R   R   R   R    R#   R*   R-   R,   R'   RE   R\   Rd   Rl   R   R   R   R   R   R   t   propertyt
   domain_sidR   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R  R  R!  R#  R%  R+  R.  R/  R1  R2  R4  R5  R;  R<  R?  R  RB  RD  (    (    (    s/   /usr/lib/python2.7/dist-packages/samba/samdb.pyR   &   s   					
	
,	-	9			'+															
											5																	(   RG  R%   R4   R   R   R   R    t	   samba.ndrR   R   t   samba.dcerpcR   R   t   samba.commonR   t   __docformat__t   LdbR   (    (    (    s/   /usr/lib/python2.7/dist-packages/samba/samdb.pyt   <module>   s   