
    bZ2                        d Z 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 d Zd Z G d d	e          Z
d
 Zd Zd ZddZdZd Zd Zd Zd Zd Zd Zd Zej        Zej        Zej        Zej        Zej        Zej        Zej         Z ej!        Z!ej"        Z"ej#        Z#ej$        Z$ej%        Z%ej&        Z&ej'        Z'ej(        Z(ej)        Z)ej*        Z*ej+        Z+ej,        Z,ej-        Z-ej.        Z.ej/        Z/ej0        Z0ej1        Z1dS )zSamba 4.restructuredText    N)_glue)Ldbc                  r   ddg} | D ]}t           j                            t           j                            t           j                            t
                    |                    }t           j                            t           j                            |d                    r|c S t          d          )z&Return the top level source directory.z../../..z../../../..source4z)unable to find top level source directory)ospathnormpathjoindirname__file__existsRuntimeError)pathsptopdirs      0/usr/lib/python3/dist-packages/samba/__init__.pysource_tree_topdirr   "   s    'E  !!"',,rwx/H/H!"L"LMM7>>"',,vy99:: 	MMM	
B
C
CC    c                  H    	 t                      } n# t          $ r Y dS w xY wdS )z?Return True if we are running from within the samba source treeFT)r   r   )r   s    r   in_source_treer   ,   s;    #%%   uu4s    
c                   ^    e Zd ZdZ	 	 ddZddej        fdZd Zd Z	d Z
d	 Zdd
ZddZdS )r   a  Simple Samba-specific LDB subclass that takes care
    of setting up the modules dir, credentials pointers, etc.

    Please note that this is intended to be for all Samba LDB files,
    not necessarily the Sam database. For Sam-specific helper
    functions see samdb.py.
    Nr   c                 h   ||                      |           nO|                      t          j                            t          j                                        d                     ||                     |           ||                     |           || 	                    |           | 
                                 d }|                                  |(|                    d          }	|	|	r|t          j        z  }|                     d           ||                     |||           dS dS )ah  Opens a Samba Ldb file.

        :param url: Optional LDB URL to open
        :param lp: Optional loadparm object
        :param modules_dir: Optional modules directory
        :param session_info: Optional session information
        :param credentials: Optional credentials, defaults to anonymous.
        :param flags: Optional LDB flags
        :param options: Additional options (optional)

        This is different from a regular Ldb file in that the Samba-specific
        modules-dir is used by default and that credentials and session_info
        can be passed through (required by some modules).
        Nldbc                 $    t          |           d S N)print)ltexts     r   msgzLdb.__init__.<locals>.msgc   s    $KKKKKr   z
ldb:nosynci  )set_modules_dirr   r	   r   sambaparammodules_dirset_session_infoset_credentialsset_loadparmregister_samba_handlersset_utf8_casefoldgetr   
FLG_NOSYNCset_create_permsconnect)
selfurllpr$   session_infocredentialsflagsoptionsr    nosync_ps
             r   __init__zLdb.__init__>   sB   " "  ----  ek.E.E.G.G!O!OPPP#!!,///"  --->b!!!
 	$$&&&	 	 	 	    >vvl++H##'e$$$?LLeW----- ?r   c                 *   |                      ||||g          }t          |          dk    s|d         |         dS t          |d         |                   }t          |          dk    sJ |                     ||                                          S )aG  Search for one attribute as a string.

        :param basedn: BaseDN for the search.
        :param attribute: Name of the attribute
        :param expression: Optional search expression.
        :param scope: Search scope (defaults to base).
        :return: Value of attribute as a string or None if it wasn't found.
           r   N)searchlensetschema_format_valuepop)r.   	attributebasedn
expressionscoperesvaluess          r   	searchonezLdb.searchonet   s     kk&%i[AAs88q==CF9-54SVI&''6{{a''	6::<<@@@r   c                 t   	 |                      |t          j        g d          }n8# t          j        $ r&}|j        \  }}|t          j        k    rY d}~dS  d}~ww xY w	 |D ]}|                     |j        dg           dS # t          j        $ r&}|j        \  }}|t          j        k    r Y d}~dS d}~ww xY w)zErases user and computer objects from our AD.

        This is needed since the 'samldb' module denies the deletion of primary
        groups. Therefore all groups shouldn't be primary somewhere anymore.
        z+(|(objectclass=user)(objectclass=computer)))baserA   attrsr@   Nrelax:0)r9   r   SCOPE_SUBTREELdbErrorargsERR_NO_SUCH_OBJECTdeletedn)r.   rN   rB   errorerrnoestrr    s          r   erase_users_computerszLdb.erase_users_computers   s   		++2S->b)V  X XCC| 	 	 	!JMUD...		 1 1CFYK00001 1| 	 	 	!JMUD... /.....	s2   #& AAAA!B B7B22B7c                 L   d}|                      |           |                     |t          j        dg ddg          D ]V}	 |                     |j        dg            # t          j        $ r%}|j        \  }}|t          j        k    r Y d}~Od}~ww xY w|                     |t          j        dg ddg          }t          |          dk    sJ d	D ]Q}	 |                     |dg           # t          j        $ r%}|j        \  }}|t          j        k    r Y d}~Jd}~ww xY wdS )
z~Erase this ldb.

        :note: Removes all records, except those that are controlled by
            Samba4's schema.
         zJ(&(|(objectclass=*)(distinguishedName=*))(!(distinguishedName=@BASEINFO)))zshow_deleted:0zshow_recycled:0)controlsrH   Nr   )z@SUBCLASSESz@MODULESz@OPTIONSz
@PARTITIONz
@KLUDGEACL)
rR   r9   r   rI   rM   rN   rJ   rK   rL   r:   )r.   r?   r    rO   rP   rQ   rB   attrs           r   erase_except_schema_controlledz"Ldb.erase_except_schema_controlled   s     	""6*** ;;vs'8k!-=?P,Q  S S 		 		CCFYK0000<    %
C222 32222 kk&#"3f(8:K'L  N N 3xx1}}}}= 	 	DD9+....<    %
C222 32222		 	s0   AB-BBC--D!<DD!c                     |                                   dD ]Q}	 |                     |dg           # t          j        $ r%}|j        \  }}|t          j        k    r Y d}~Jd}~ww xY wdS )z%Erase this ldb, removing all records.)z
@INDEXLISTz@ATTRIBUTESrH   N)rW   rM   r   rJ   rK   rL   )r.   rV   rO   rP   rQ   s        r   erasez	Ldb.erase   s    ++--- 2 	 	DD9+....<    %
C222 32222	 	s   2A&A!!A&c                     t          |d          5 }|                     |                                           ddd           dS # 1 swxY w Y   dS )zHLoad a LDIF file.

        :param ldif_path: Path to LDIF file.
        rN)openadd_ldifread)r.   	ldif_path	ldif_files      r   load_ldif_file_addzLdb.load_ldif_file_add   s    
 )S!! 	,YMM)..**+++	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	,s   (AA
A
c                     |                      |          D ]-\  }}|t          j        k    sJ |                     ||           .dS )zJAdd data based on a LDIF string.

        :param ldif: LDIF text.
        N)
parse_ldifr   CHANGETYPE_NONEaddr.   ldifrU   
changetyper    s        r   r]   zLdb.add_ldif   sX    
  $t44 	$ 	$OJ!44444HHS(####	$ 	$r   c                     |                      |          D ]B\  }}|t          j        k    r|                     ||           ,|                     ||           CdS )zQModify database based on a LDIF string.

        :param ldif: LDIF text.
        N)rc   r   CHANGETYPE_ADDre   modifyrf   s        r   modify_ldifzLdb.modify_ldif   si    
  $t44 	+ 	+OJS///h''''C****		+ 	+r   )NNNNNr   Nr   )__name__
__module____qualname____doc__r6   r   
SCOPE_BASErD   rR   rW   rY   ra   r]   rl    r   r   r   r   5   s          JN484. 4. 4. 4.l +/4A A A A"  6' ' 'R  , , ,$ $ $ $	+ 	+ 	+ 	+ 	+ 	+r   r   c                     |                                 D ]f\  }}t          |t                    sJ d|z              t          |t                    sJ d|d|d            |                     d|z  |          } g| S )zSubstitute strings of the form ${NAME} in str, replacing
    with substitutions from values.

    :param text: Text in which to subsitute.
    :param values: Dictionary with keys and values.
    z%r is not a stringzValue z for z is not a stringz${%s})items
isinstancestrreplace)r   rC   namevalues       r   substitute_varrz      s       3 3u$$$AA&:T&AAAA%%%XXXEEESWSWSW'XXXX||GdNE22Kr   c                     d| vrdS |                      d          }|                      d|          }t          d| ||dz            z            )zCheck that all substitution variables in a string have been replaced.

    If not, raise an exception.

    :param text: The text to search for substitution variables
    z${N}z!Not all variables substituted: %sr8   )find	Exception)r   	var_startvar_ends      r   check_all_substitutedr     sa     4		$IiiY''G
77Q;./0 1 1 1r   c                     t          | dd          5 }|                                }|t          ||          }t          |           ddd           n# 1 swxY w Y   |S )zRead a file and sub in variables found in it

    :param file_name: File to be read (typically from setup directory)
     param subst_vars: Optional variables to subsitute in the file.
    r[   zutf-8)encodingN)r\   r^   rz   r   )	file_name
subst_vars	data_filedatas       r   read_and_sub_filer     s     
iw	/	/	/ (9~~!!$
33D!$'''	( ( ( ( ( ( ( ( ( ( ( ( ( ( (
 Ks   6AAAc                 2   t           j                            |          rt          j        |           t	          | |          }t          |d          }	 |                    |           |                                 dS # |                                 w xY w)zSetup a file in the private dir.

    :param template: Path of the template file.
    :param fname: Path of the file to create.
    :param subst_vars: Substitution variables.
    wN)r   r	   r   unlinkr   r\   writeclose)templatefnamer   r   fs        r   
setup_filer   #  s     
w~~e 
	%Xz22DUCA											s   B   B   c                 2    |                                  p| dv S )Nz !#$%&'()-.@^_{}~)isalnum)cs    r   is_valid_netbios_charr   8  s    IIKK31 334r   c                 h    t          |           t          k    rdS | D ]}t          |          s dS dS )z1Check whether a name is valid as a NetBIOS name. FT)r:   MAX_NETBIOS_NAME_LENr   )rx   xs     r   valid_netbios_namer   <  sK     4yy'''u  $Q'' 	55	4r   c                 X    dd                     |                     d                    z   S )z.return a DN from a DNS name domain/forest rootzDC=z,DC=.)r   split)	dnsdomains    r   dn_from_dns_namer   G  s%    6;;ys334444r   c                  B    t          t          j                              S r   )inttimerr   r   r   current_unix_timer   L  s    ty{{r   c                     dgt          |           z  }t          t          |                     D ]=}t          | |         t                    r| |         nt	          | |                   ||<   >|S )Nr   )r:   rangeru   r   ord)stringblobis      r   string_to_byte_arrayr   P  sh    3VD3v;; N N)&)S99M&))s6!9~~QKr   c                 &    ddl m}  |||           S )Nr   )arcfour_crypt_blob)samba.cryptor   )keyr   r   s      r   arcfour_encryptr   Y  s'    //////dC(((r   c                      ddl m}  ddl m} dS )zXThis function modifies the samba.net.Net class to contain
    an export_keytab() method.r   )net)dckeytabN)r"   r   r   )r   r   s     r   enable_net_export_keytabr   ^  s.     r   r   )2rp   __docformat__r   sysr   r   samba.paramr"   r   
samba._ldbr   _Ldbr   r   rz   r   r   r   r   r   r   r   r   r   r   r   versioninterface_ipsfault_setupset_debug_levelget_debug_levelfloat2nttimenttime2floatnttime2stringnttime2unixunix2nttimegenerate_random_password generate_random_machine_passwordcheck_password_qualitygenerate_random_bytesstrcasecmp_mstrstr_mis_ntvfs_fileserver_builtis_heimdal_builtis_ad_dc_builtis_selftest_enabledNTSTATUSErrorHRESULTErrorWERRORErrorDsExtendedErrorrr   r   r   <module>r      s6  * " 				 



  



           " " " " " "D D D  |+ |+ |+ |+ |+$ |+ |+ |+~   1 1 1"     $  5 5 5  5 5 5
    ) ) )
  " -#''!!# 9 #(#I  5 3 !>!; ) %/ #!'r   