
    n	d<                     
   d Z ddlmZ ddlmZ ddlmZ ddlmZ ddlm	Z	 ddl
mZmZ ddlmZmZmZ dd	lmZ dd
lmZ ddlZddlZddlZ G d de          Z G d de          Z G d de          Z G d de          ZdS )zTests for samba.dsdb.    )Credentials)SamDB)system_session)TestCase)delete_force)
ndr_unpackndr_pack)drsblobssecuritymisc)dsdb)werrorNc                        e Zd Z f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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d Zd Z	 d(dZd Z d  Z!d! Z"d" Z#d# Z$d$ Z%d% Z&d& Z'd' Z( xZ)S ))	DsdbTestsc                 $   t          t          |                                            t          j                                        | _        t                      | _        | j        	                    | j                   t                      | _        t          | j        | j        | j                  | _        dt          t          j                    j        dd                   z   }t          j        dd          }d}| j                                        }d|z   dz   |z   | _        | j                            |||	           |                     t.          | j        | j                   | j                            t3          j        | j        | j                                                  t2          j        d
g          }t3          j        | j        |d         d
         d                             d                    | _        | j                            | j        t2          j        dg          }|d         }|                     d|           |d         d                             d          }t3          j        | j        |          | _         d S )Nsession_infocredentialslpz
dsdb-user-r          zTest user for dsdb testCN=z
,CN=Users,)usernamepassworddescriptionserverReferencebasescopeattrszutf-8rIDSetReferences)!superr   setUpsambatestsenv_loadparmr   r   credsguessr   sessionr   samdbstruuiduuid4hexgenerate_random_password	domain_dn
account_dnnewuser
addCleanupr   searchldbDnget_serverName
SCOPE_BASEdecodeserver_ref_dnassertIn
rid_set_dn)	self	user_name	user_passuser_descriptionbase_dnresrid_set_refsrid_set_str	__class__s	           2/usr/lib/python3/dist-packages/samba/tests/dsdb.pyr#   zDsdbTests.setUp$   sA   i$$&&&+**,, ]]

!!!%'''+z"g' ' '

 !3tz||'7!'<#=#==	22r::	4*&&(()+l:WD
I$-'7 	 	9 	9 	9 	dj$/BBB jSVDJ,0J,E,E,G,G&I &I&)n'8&9   ; ;
 !VJA01!4;;GDDF F jT%7&)n'9&:   < < 1v(,777"#56q9@@II&[99    c                 d    | j                             |t          j        g d          }|d         S )N)rIDAllocationPoolrIDPreviousAllocationPoolrIDUsedPool
rIDNextRIDr   r   )r*   r4   r5   r8   )r=   r<   rB   s      rF   get_rid_setzDsdbTests.get_rid_setN   s?    jZ&)n'5 '5 '5   6 6 1vrG   c                    | j                                          	 |                     | j                  }|                     d|           |                     d|           |                     d|           |                     d|           t          |d         d                   }| j                                         }|                     |dz   |           | j                                         }|                     ||           |                     | j                  }|                     ||           | j                                          d S # | j                                          w xY w)NrI   rJ   rK   rL   r      )	r*   transaction_startrM   r<   r;   intnext_free_ridassertEqualtransaction_cancel)r=   orig_rid_setnext_ridrR   next_free_rid2rid_set2s         rF   test_ridalloc_next_free_ridz%DsdbTests.test_ridalloc_next_free_ridW   sX    	
$$&&&	,++DO<<LMM-|<<<MM5|DDDMM-666MM,555 <5a899H !J4466MX\=999 "Z5577N]N;;; ''88H\8444J))+++++DJ))++++s   DE E/c                    | j                                          	 d}d}d}d}t          j                    }| j        |_        t          j        g t          j        d          |d<   t          j        t          |dz  |z            t          j	        d          |d<   t          j        t          |dz  |z            t          j	        d          |d<   | j         
                    |           | j                                         }|                     ||           | j                                         }|                     ||           | j                                         }|                     |d	z   |           | j                                         \  }	}
|                     |d	z   |	           |                     ||
           | j                                          d S # | j                                          w xY w)
Ni  i  i  i  rL   r   rJ   rI   rO   )r*   rP   r5   Messager<   dnMessageElementFLAG_MOD_DELETEr+   FLAG_MOD_REPLACEmodifyrR   rS   allocate_ridfree_rid_boundsrT   )r=   prev_loprev_hinext_lonext_himsgnext_free_rid3ridnext_free_rid4free_lofree_his              rF   test_ridalloc_no_ridnextridz%DsdbTests.test_ridalloc_no_ridnextrids   s   
$$&&&'	, GGGG+--C_CF # 22363F3?!A !AC "32'@#A#A#&#7#>@ @ +,
 "32'@#A#A#&#7#68 8 #$ Jc""" "Z5577NWn555 *))++C^S111 "Z5577NS1Wn555  $z99;;GWS1Wg...Wg...J))+++++DJ))++++s   F+G! !G<c                 x   | j                                          	 d}d}t          j                    }| j        |_        t          j        t          |dz  |z            t          j        d          |d<   t          j        t          |dz  |z            t          j        d          |d<   t          j        t          |          t          j        d          |d<   | j         	                    |           | 
                    t          j                  5 }| j                                          d d d            n# 1 swxY w Y   |                     d|j        j        d                    | j                                          | j                                          d S # | j                                          w xY w)	N    r   rJ   rI   rL   RID pools out of RIDsrO   )r*   rP   r5   r[   r<   r\   r]   r+   r_   r`   assertRaisesLdbErrorrR   rS   	exceptionargsra   rT   )r=   pool_lopool_hirg   errs        rF   test_ridalloc_no_free_ridsz$DsdbTests.test_ridalloc_no_free_rids   s   
$$&&&	,GG+--C_CF"32'@#A#A#&#7#>@ @ +,
 "32'@#A#A#&#7#68 8 #$
 s7||#&#7#/1 1  Jc""" ""3<00 +C
((***+ + + + + + + + + + + + + + + 4cm6H6KLLL J##%%%J))+++++DJ))++++s1   C8F D9-F 9D==F  D=AF F9c                    | j                                          	 t          j                    }| j        |_        t          j        dt          j        d          |d<   t          j        dt          j        d          |d<   t          j        dt          j        d          |d<   | j                             |           | 	                    t          j
                  5 }| j                                          d d d            n# 1 swxY w Y   |                     d|j        j        d                    d}d}t          j                    }| j        |_        t          j        t          |d	z  |z            t          j        d          |d<   | j                             |           | j                                         }|                     ||           | j                                         \  }}|                     ||           |                     ||           | j                                          d S # | j                                          w xY w)
N0rJ   rI   rL   rq   rO   ro   rp   r   )r*   rP   r5   r[   r<   r\   r]   r_   r`   rr   rs   rR   rS   rt   ru   r+   rb   rT   )r=   rg   rx   rv   rw   next_free_rid5rk   rl   s           rF   test_ridalloc_new_ridsetz"DsdbTests.test_ridalloc_new_ridset   su   
$$&&&/	, +--C_CF"3#&#7#>@ @ +,
 "3#&#7#68 8 #$
 "3#&#7#/1 1  Jc""" ""3<00 +C
((***+ + + + + + + + + + + + + + + 4cm6H6KLLL GG+--C_CF"32'@#A#A#&#7#68 8 #$ Jc""" "Z5577NWn555  $z99;;GWWg...Wg...J))+++++DJ))++++s1   CH8 D6H8 DH8 	D
DH8 8Ic                     | j                                          	 d}d}d}d}t          j                    }| j        |_        t          j        t          |dz  |z            t          j        d          |d<   t          j        t          |dz  |z            t          j        d          |d<   t          j        t          |dz
            t          j        d	          |d	<   | j         	                    |           | j         
                                }|                     ||           | j                                         \  }}|                     ||           |                     ||           | j                                         }	|                     ||	           | j         
                                }
|                     ||
           | j                                         \  }}|                     ||           |                     ||           | j                                         }|                     |
|           | j                                          d S # | j                                          w xY w)
Nro   rp   i  i  r   rJ   rI   rO   rL   )r*   rP   r5   r[   r<   r\   r]   r+   r_   r`   rR   rS   rb   ra   rT   )r=   rv   rw   new_pool_lonew_pool_hirg   next_free_rid6rk   rl   rid2next_free_rid7free_lo2free_hi2rid3s                 rF   test_ridalloc_move_to_new_poolz(DsdbTests.test_ridalloc_move_to_new_pool   sm   
$$&&&0	,GGKK+--C_CF"32'@#A#A#&#7#>@ @ +,
 "3r(9['H#I#I#&#7#68 8 #$
 "3w{#3#3#&#7#/1 1  Jc""" "Z5577NWn555  $z99;;GWWg...Wg... :**,,D^T222 "Z5577N[.999 "&!;!;!=!=Hh[(333[(333 :**,,D^T222J))+++++DJ))++++s   H,I" "I=c                    | j                                          	 t          j                    }| j        |_        t          j        g t          j        d          |d<   | j                             |           | 	                    t          j
                  5 }| j                                          d d d            n# 1 swxY w Y   |j        j        \  }}|                     t          j        |           |                     d| j        z  |           | 	                    t          j
                  5 }| j                                          d d d            n# 1 swxY w Y   |j        j        \  }}|                     t          j        |           |                     d| j        d| j        d|           | j                                          d S # | j                                          w xY w)Nr!   zVNo RID Set DN - Cannot find attribute rIDSetReferences of %s to calculate reference dnz&No RID Set DN - Failed to add RID Set z	 - Entry z already exists)r*   rP   r5   r[   r:   r\   r]   r^   r`   rr   rs   rR   rt   ru   rS   ERR_NO_SUCH_ATTRIBUTEr;   ra   ERR_ENTRY_ALREADY_EXISTSr<   rT   )r=   rg   rx   enumestrs        rF   !test_ridalloc_no_ridsetreferencesz+DsdbTests.test_ridalloc_no_ridsetreferences&  sS   
$$&&&!	,+--C'CF"2#&#6#57 7 "# Jc""" ""3<00 +C
((***+ + + + + + + + + + + + + + + +JD$S6===MM 68<8JK       ""3<00 *C
'')))* * * * * * * * * * * * * * * +JD$S94@@@MMM  ???DOOO= 	      J))+++++DJ))++++sV   A;G B<0G <C  G C A/G 3EG EG  E!AG G0c                    | j                                          	 | j        }t          j                    }| j        |_        t          j        |t          j        d          |d<   | j         	                    |           | 
                    t          j                  5 }| j                                          d d d            n# 1 swxY w Y   |j        j        \  }}|                     t          j        |           |                     d|z   |           | 
                    t          j                  5 }| j                                          d d d            n# 1 swxY w Y   |j        j        \  }}|                     t          j        |           |                     d|z   |           | j                                          d S # | j                                          w xY w)Nr!   zBad RID Set )r*   rP   r1   r5   r[   r:   r\   r]   r_   r`   rr   rs   rR   rt   ru   rS   ERR_OPERATIONS_ERRORr;   ra   rT   )r=   fake_rid_set_strrg   rx   r   r   s         rF   test_ridalloc_no_rid_setz"DsdbTests.test_ridalloc_no_rid_setK  s-   
$$&&&	,#+--C'CF"#3#&#7#57 7 "# Jc""" ""3<00 +C
((***+ + + + + + + + + + + + + + + +JD$S5t<<<MM.+;;TBBB ""3<00 *C
'')))* * * * * * * * * * * * * * * +JD$S5t<<<MM.+;;dCCCJ))+++++DJ))++++sV   BG	 C7G	 CG	 
CA*G	 5EG	 EG	 "E#AG	 	G$c                 f    | j                             d          }|                     |d           d S )Ni	 z1.2.840.113556.1.4.1790)r*   get_oid_from_attidrS   )r=   oids     rF   test_get_oid_from_attridz"DsdbTests.test_get_oid_from_attridj  s4    j++F33788888rG   c                 $   | j                             t          j        | j        dg          }t          t          j        |d         d         d                   }|j        }|j	        D ]#}|j
        dk    r|j        }|j        dz   |_        $t          |          }t          j                    }|d         j        |_        t          j        |t          j        d          |d<   |                     t          j        | j         j        |dg           d S )NreplPropertyMetaDatar   r   r    r      rO   #local_oid:1.3.6.1.4.1.7165.4.3.14:0)r*   r4   r5   SCOPE_SUBTREEr1   r   r
   replPropertyMetaDataBlobctrarrayattidversionr	   r[   r\   r]   r_   rr   rs   r`   r=   rB   replr   oold_versionreplBlobrg   s           rF   test_error_replpropertymetadataz)DsdbTests.test_error_replpropertymetadatan  s    jc&7%)_'=&>   @ @ (;a&!78;= =h 	* 	*Aw"}}iIM	D>>kmmQ&)&83CWYo&p&p"##,
(93Af@ghhhhhrG   c                    | j                             t          j        | j        dg          }t          t          j        |d         d         d                   }t          |          }t          j	                    }|d         j
        |_
        t          j        |t          j        d          |d<   |                     t          j        | j         j        |dg           d S )Nr   r   r   r   )r*   r4   r5   r   r1   r   r
   r   r	   r[   r\   r]   r_   rr   rs   r`   r=   rB   r   r   rg   s        rF   (test_error_replpropertymetadata_nochangez2DsdbTests.test_error_replpropertymetadata_nochange  s    jc&7%)_'=&>   @ @ (;a&!78;= =D>>kmmQ&)&83CWYo&p&p"##,
(93Af@ghhhhhrG   c                    | j                             t          j        | j        dg          }t          t          j        |d         d         d                   }t          |          }t          j	                    }|d         j
        |_
        t          j        |t          j        d          |d<   | j                             |ddg           d S )Nr   r   r   r   z#local_oid:1.3.6.1.4.1.7165.4.3.25:0)r*   r4   r5   r   r1   r   r
   r   r	   r[   r\   r]   r_   r`   r   s        rF   *test_error_replpropertymetadata_allow_sortz4DsdbTests.test_error_replpropertymetadata_allow_sort  s    jc&7%)_'=&>   @ @ (;a&!78;= =D>>kmmQ&)&83CWYo&p&p"#
# EGlmnnnnnrG   c                    | j                             t          j        | j        ddg          }t          t          j        |d         d         d                   }|j        }|j	        D ]S}|j
        dk    rF|j        }|j        dz   |_        t          t          |d         d                             dz   |_        Tt          |          }t          j                    }|d         j        |_        t          j        |t          j        d          |d<   t          j        dt          j        d          |d<   |                     t          j        | j         j        |d	g           d S )
Nr   
uSNChangedr   r   r   rO   znew valr   r   )r*   r4   r5   r   r1   r   r
   r   r   r   r   r   rQ   r+   	local_usnr	   r[   r\   r]   r_   rr   rs   r`   r   s           rF    test_twoatt_replpropertymetadataz*DsdbTests.test_twoatt_replpropertymetadata  sB   jc&7%)_'=|&L   N N (;a&!78;= =h 	A 	AAw"}}iIM	!#c!f\&:";";<<q@D>>kmmQ&)&83CWYo&p&p"# /	3;OQ^__M#,
(93Af@ghhhhhrG   c                    | j                             t          j        | j        ddg          }t          t          j        |d         d         d                   }|j        }|j	        D ]}|j
        dk    rv|j        }|j        dz   |_        t          t          |d         d                             dz   |_        t          t          |d         d                             dz   |_        t!          |          }t          j                    }|d         j        |_        t          j        |t          j        d          |d<   | j                             |dg           d S )Nr   r   r   r   r   rO   r   )r*   r4   r5   r   r1   r   r
   r   r   r   r   r   rQ   r+   r   originating_usnr	   r[   r\   r]   r_   r`   r   s           rF   test_set_replpropertymetadataz'DsdbTests.test_set_replpropertymetadata  sB   jc&7%)_'=|&L   N N (;a&!78;= =h 	G 	GAw"}}iIM	!#c!f\&:";";<<q@$'CF<,@(A(A$B$BQ$F!D>>kmmQ&)&83CWYo&p&p"#
# EFGGGGGrG   c                 b    |                      | j                            d          d           d S )Nr   r   rS   r*   get_attribute_from_attidr=   s    rF    test_ok_get_attribute_from_attidz*DsdbTests.test_ok_get_attribute_from_attid  s.    <<R@@-PPPPPrG   c                 b    |                      | j                            d          d            d S )Ni.  r   r   s    rF    test_ko_get_attribute_from_attidz*DsdbTests.test_ko_get_attribute_from_attid  s.    <<UCCTJJJJJrG   c                 8   | j                             t          j        | j        dg          }|                     t          |          d           t          |d         j                  }|                     | j         	                    |d          d           d S )Nr\   r   rO   r   
unicodePwd   )
r*   r4   r5   r   r1   rS   lenr+   r\   "get_attribute_replmetadata_version)r=   rB   r\   s      rF   'test_get_attribute_replmetadata_versionz1DsdbTests.test_get_attribute_replmetadata_version  s    jc&7%)_'+f   . . 	S1%%%Q^^FFr<XXZ[\\\\\rG   c                    | j                             t          j        | j        dg          }|                     t          |          d           t          |d         j                  }| j         	                    |d          }| j         
                    |d|dz              |                     | j         	                    |d          |dz              d S )Nr\   r   rO   r   r   r   )r*   r4   r5   r   r1   rS   r   r+   r\   r   "set_attribute_replmetadata_version)r=   rB   r\   r   s       rF   'test_set_attribute_replmetadata_versionz1DsdbTests.test_set_attribute_replmetadata_version  s    jc&7%)_'+f   . . 	S1%%%Q^^*??MRR
55b-STUUUFFr=YY[bef[fgggggrG   c                     	 | j                             t          j        | j        dgdt
          j        z  g          }d S # t          j        $ r }|                     d           Y d }~d S d }~ww xY w)Nr   zlocal_oid:%s:0r   r   r    controls#Should have not raised an exception)	r*   r4   r5   r   r1   r   $DSDB_CONTROL_INVALID_NOT_IMPLEMENTEDrs   fail)r=   rB   es      rF    test_no_error_on_invalid_controlz*DsdbTests.test_no_error_on_invalid_control  s    	=*###*;)-+A*B.>040Y/Z .[ $ \ \CCC
 | 	= 	= 	=II;<<<<<<<<<	=s   <A   A/A**A/c                 6   	 | j                             t          j        | j        dgdt
          j        z  g          }d S # t          j        $ rI}|j        \  }}|t          j	        k    r$| 
                    d|d         z             Y d }~d S Y d }~d S d }~ww xY w)Nr   zlocal_oid:%s:1r   z9Got %s should have got ERR_UNSUPPORTED_CRITICAL_EXTENSIONrO   )r*   r4   r5   r   r1   r   r   rs   ru   "ERR_UNSUPPORTED_CRITICAL_EXTENSIONr   )r=   rB   r   errnor   s        rF   &test_error_on_invalid_critical_controlz0DsdbTests.test_error_on_invalid_critical_control  s    
	"*###*;)-+A*B.>040Y/Z .[ $ \ \CCC
 | 	" 	" 	"FMUD>>>		UaD! " " " " " " " " " ?>>>>>	"s   <A   B8BBc                     | j                                          	 | j                                         }n#  | j                                           xY w| j                                          t          |          S N)r*   rP   ra   rT   transaction_commitr+   )r=   ri   s     rF   ra   zDsdbTests.allocate_rid  so    
$$&&&	*))++CC	J))+++
%%'''3xxs	   5 Ac                 p   | j                                         }t          |                              d          rd}nd}t          |          d d         |z   dz   }t	          t          j        |                    }| j                                         }d|d|}	 | j                             |dd           | 	                    d	           n{# t          j        $ ri}|j        \  }}	|                     |t          j        t          |                     d
t          j        z  }
|                     |
|	v |	           Y d }~nd }~ww xY w	 | j                             |d|d           | 	                    d           n{# t          j        $ ri}|j        \  }}	|                     |t          j        t          |                     d
t          j        z  }
|                     |
|	v |	           Y d }~nd }~ww xY wdg}| j                             |dd|           | j                             |           	 | j                             |dd|           n@# t          j        $ r.}|j        \  }}	| 	                    d||	fz             Y d }~nd }~ww xY w| j                             |           d S )Nr{   9z-1000r   z,CN=ForeignSecurityPrincipals,foreignSecurityPrincipalr\   objectClassz2No exception should get ERR_OBJECT_CLASS_VIOLATION%08X)r\   r   	objectSidz0No exception should get ERR_UNWILLING_TO_PERFORMzprovision:0)r   !Got unexpected exception %d - %s )r*   get_domain_sidr+   endswithr	   r   dom_sidget_default_basednaddr   r5   rs   ru   rS   ERR_OBJECT_CLASS_VIOLATIONr   WERR_DS_MISSING_REQUIRED_ATT
assertTrueERR_UNWILLING_TO_PERFORMWERR_DS_ILLEGAL_MOD_OPERATIONdelete)r=   r   csid_strsidbasednr\   r   coderg   werrr   s               rF   @test_duplicate_objectSIDs_allowed_on_foreign_security_principalszJDsdbTests.test_duplicate_objectSIDs_allowed_on_foreign_security_principals  sB    *++--w<<  %% 	AAAg,,ss#a''18+G4455*//11=DWWffM		.JNN9; ; < < < IIJKKKK| 	. 	. 	.&KT3T3#A3q66JJJF??DOODCK--------		.
	.JNN9 " " # # # IIHIIII| 	. 	. 	.&KT3T3#?QHHHF@@DOODCK--------		. "?
57 7  	 	 	 	
 	
"	%JNN9; ; "  # # # # | 	% 	% 	%&KT3II9s$ % % % % % % % %	% 	
"sJ   !2C E#AEE3F G<AG77G<<I J+$JJc                 	   | j                                         }t          |          dz   }d}d}| j                                         }d}d|d|}	t	          j        | j         |	          }
| j                             t          j        |d|z  g           }|                     t          |          d	           | j                             t          j        |d|z  g           }|                     t          |          d	           | j                             t          j        |d|z  g           }|                     t          |          d	           | 
                    t          | j         |	           | j                             |	|d
           t	          j                    }|
|_        t	          j        d|z  t          j        |          ||<   	 | j                             |           |                     d           n{# t          j        $ ri}|j        \  }}|                     |t          j        t          |                     dt,          j        z  }|                     ||v |           Y d }~nd }~ww xY wt	          j                    }|
|_        t	          j        d|z  t          j        |          ||<   	 | j                             |           |                     d           n{# t          j        $ ri}|j        \  }}|                     |t          j        t          |                     dt,          j        z  }|                     ||v |           Y d }~nd }~ww xY wt	          j                    }|
|_        t	          j        d|z  t          j        |          ||<   	 | j                             |           n1# t          j        $ r}|                     d           Y d }~nd }~ww xY w| j                             t          j        |d|z  g           }|                     t          |          d           | j                             |d	         j                   | j                             |
           | j                             t          j        |d|z  g           }|                     t          |          d	           d S )N-4294967294S-1-5-32-4294967294S-1-5-4294967294dsdb_test_fpocn=
,cn=Users,(objectSid=%s)r   r   
expressionr    r   r   <SID=%s>z4No exception should get LDB_ERR_UNWILLING_TO_PERFORMr   z.No exception should get LDB_ERR_NO_SUCH_OBJECTr   rO   )r*   r   r+   r   r5   r6   r4   r   rS   r   r3   r   r   r[   r\   r]   FLAG_MOD_ADDr`   r   rs   ru   r   r   WERR_DS_INVALID_GROUP_TYPEr   ERR_NO_SUCH_OBJECTWERR_NO_SUCH_MEMBERr   )r=   	obj_classfpo_attrr   lsid_strbsid_strfsid_strr   cndn_strr\   rB   rg   r   r   r   s                   rF   _test_foreignSecurityPrincipalz(DsdbTests._test_foreignSecurityPrincipalD  s   *++--w<<-/(%:0022"*,""ff5VDJ''jc&7%++;h+F&(   * * 	S1%%%jc&7%++;h+F&(   * * 	S1%%%jc&7%++;h+F&(   * * 	S1%%%dj&999
$& & 	' 	' 	' kmm*:+@+.+;+35 5H	.Jc"""IILMMMM| 	. 	. 	.&KT3T3#?QHHHF==DOODCK--------		. kmm*:+@+.+;+35 5H	.Jc"""IIFGGGG| 	. 	. 	.&KT3T3#93q66BBBF66DOODCK--------		. kmm*:+@+.+;+35 5H	=Jc""""| 	= 	= 	=II;<<<<<<<<	= jc&7%++;h+F&(   * * 	S1%%%
#a&)$$$
"jc&7%++;h+F&(   * * 	S1%%%%%sJ   /H I>AI99I>/K2 2M*AM%%M*.O	 	O7O22O7c                 .    |                      dd          S )Ngroupmemberr  r   s    rF   $test_foreignSecurityPrincipal_memberz.DsdbTests.test_foreignSecurityPrincipal_member  s    22# # 	#rG   c                 .    |                      dd          S )NzmsDS-AzRolezmsDS-MembersForAzRoler  r   s    rF   .test_foreignSecurityPrincipal_MembersForAzRolez8DsdbTests.test_foreignSecurityPrincipal_MembersForAzRole  s     2268 8 	8rG   c                 .    |                      dd          S )NcomputerzmsDS-NeverRevealGroupr  r   s    rF   .test_foreignSecurityPrincipal_NeverRevealGroupz8DsdbTests.test_foreignSecurityPrincipal_NeverRevealGroup  s     2235 5 	5rG   c                 .    |                      dd          S )Nr  zmsDS-RevealOnDemandGroupr  r   s    rF   1test_foreignSecurityPrincipal_RevealOnDemandGroupz;DsdbTests.test_foreignSecurityPrincipal_RevealOnDemandGroup  s     2268 8 	8rG   Tc                 j   | j                                         }t          |          dz   }d}	d}
| j                                         }d}d|d|}t	          j        | j         |          }d}d|d|}t	          j        | j         |          }| j                             t          j        |d|z  g 	          }|                     t          |          d
           | j                             t          j        |d|	z  g 	          }|                     t          |          d
           | j                             t          j        |d|
z  g 	          }|                     t          |          d
           | 
                    t          | j         |           | 
                    t          | j         |           | j                             ||d           | j                             ||d           t	          j                    }||_        t	          j        d|z  t          j        |          ||<   	 | j                             |           |                     d|z             ng# t          j        $ rU}|j        \  }}|                     ||t          |                     d|z  }|                     ||v |           Y d }~nd }~ww xY wt	          j                    }||_        t	          j        d|	z  t          j        |          ||<   	 | j                             |           |                     d|z             ng# t          j        $ rU}|j        \  }}|                     ||t          |                     d|z  }|                     ||v |           Y d }~nd }~ww xY wt	          j                    }||_        t	          j        d|
z  t          j        |          ||<   	 | j                             |           |                     d|z             ng# t          j        $ rU}|j        \  }}|                     ||t          |                     d|z  }|                     ||v |           Y d }~nd }~ww xY wt	          j                    }||_        t	          j        d|z  t          j        |          ||<   	 | j                             |           |s|                     d|z             n# t          j        $ ro}|r|                     d|z             |j        \  }}|                     ||t          |                     d|z  }|                     ||v |           Y d }~nd }~ww xY w| j                             |           | j                             |           d S )Nr   r   r   dsdb_test_fpo1r   r   dsdb_test_fpo2r   r   r   r   r   zNo exception should get %sr   z%sz'Should have not raised an exception: %s)r*   r   r+   r   r5   r6   r4   r   rS   r   r3   r   r   r[   r\   r]   r   r`   r   rs   ru   r   r   )r=   r   r   msg_explerr_expwerr_expallow_referencer   r   r   r   r   cn1dn1_strdn1cn2dn2_strdn2rB   rg   r   r   r   s                          rF   #_test_fail_foreignSecurityPrincipalz-DsdbTests._test_fail_foreignSecurityPrincipal  s    *++--w<<-/(%:0022$+.337fTZ))$+.337fTZ))jc&7%++;h+F&(   * * 	S1%%%jc&7%++;h+F&(   * * 	S1%%%jc&7%++;h+F&(   * * 	S1%%%dj':::dj':::
$& & 	' 	' 	' 	
$& & 	' 	' 	' kmm*:+@+.+;+35 5H	.Jc"""II2W<====| 	. 	. 	.&KT3T8SVV444H$DOODCK--------		. kmm*:+@+.+;+35 5H	.Jc"""II2W<====| 	. 	. 	.&KT3T8SVV444H$DOODCK--------		. kmm*:+@+.+;+35 5H	.Jc"""II2S89999| 	. 	. 	.&KT3T8SVV444H$DOODCK--------		. kmm*4#:+.+;+35 5H
	.Jc"""" B		6@AAA| 	. 	. 	. I		CaGHHH&KT3T8SVV444H$DOODCK--------	. 	
#
#sd   82I+ +K:AK

K2M N*AN%%N*.2P! !R0AR  R	4S> >U<A%U77U<c                 `    |                      dddt          j        t          j        d          S )Nr  zmsDS-NonMembersz/LDB_ERR_UNWILLING_TO_PERFORM/WERR_NOT_SUPPORTEDF)r  )r  r5   r   r   WERR_NOT_SUPPORTEDr   s    rF   (test_foreignSecurityPrincipal_NonMembersz2DsdbTests.test_foreignSecurityPrincipal_NonMembers  s6    77*A,f.G %	 8 ' ' 	'rG   c                 \    |                      dddt          j        t          j                  S )Nr  zmsDS-HostServiceAccount;LDB_ERR_CONSTRAINT_VIOLATION/WERR_DS_NAME_REFERENCE_INVALIDr  r5   ERR_CONSTRAINT_VIOLATIONr   WERR_DS_NAME_REFERENCE_INVALIDr   s    rF   0test_foreignSecurityPrincipal_HostServiceAccountz:DsdbTests.test_foreignSecurityPrincipal_HostServiceAccount  s/    775M,5	7 7 	7rG   c                 \    |                      dddt          j        t          j                  S )Nusermanagerr"  r#  r   s    rF   %test_foreignSecurityPrincipal_managerz/DsdbTests.test_foreignSecurityPrincipal_manager  s.    77	M,5	7 7 	7rG   c                    | j                                         }|                                 }t          |          dz   |z   }t	          t          j        |                    }| j                                         }d}d|d|}| j                             |d|d           | j         	                    |           	 | j                             |d|d           | 
                    d           d S # t          j        $ rE}|j        \  }	}
|	t          j        k    r | 
                    d|	|
fz             Y d }~d S Y d }~d S d }~ww xY w)	N-dsdb_test_01r   r   r(  )r\   r   	objectSID4No exception should get LDB_ERR_CONSTRAINT_VIOLATIONz8Got %d - %s should have got LDB_ERR_CONSTRAINT_VIOLATION)r*   r   ra   r+   r	   r   r   r   r   r   r   r5   rs   ru   r$  )r=   r   ri   r   r   r   r  r\   r   r   rg   s              rF   6test_duplicate_objectSIDs_not_allowed_on_local_objectsz@DsdbTests.test_duplicate_objectSIDs_not_allowed_on_local_objects+  s   *++--##%%g,,$s*8+G4455*//11!)+VV4
!  	 	 	 	
"	)JNN% " " # # # IILMMMMM| 	) 	) 	)&KT3s333		 9!3K( ) ) ) ) ) ) ) ) ) 433333	)s    3C5 5E	4EE	c                    | j                                         }d|z  }d|z  }| j                                         }t          |          dz   }d}|                     t
          | j         |           |                     t
          | j         |           | j                             |dd           | j                             t          j	        |ddg	          }| 
                    t          |          d
           t          t          j        |d         d         d                   }t          t          j        |d         d         d                   }	|d         j        }
| j                             |dd           | j                             t          j	        |ddg	          }| 
                    t          |          d
           t          t          j        |d         d         d                   }t          t          j        |d         d         d                   }| j                             |           t          j                    }|
|_        t          j        d|z  t          j        d          |d<   	 | j                             |           |                     d           n{# t          j        $ ri}|j        \  }}| 
                    |t          j        t          |                     dt6          j        z  }|                     ||v |           Y d }~nd }~ww xY wt          j                    }|
|_        t          j        d|z  t          j        d          |d<   	 | j                             |           |                     d           n{# t          j        $ ri}|j        \  }}| 
                    |t          j        t          |                     dt6          j        z  }|                     ||v |           Y d }~nd }~ww xY wt          j                    }|
|_        t          j        d|z  t          j        d          |d<   | j                             |           t          j                    }|
|_        t          j        d|z  t          j        d          |d<   | j                             |           t          j                    }|
|_        t          j        d|z  t          j        d          |d<   | j                             |           t          j                    }|
|_        t          j        d|z  t          j        d          |d<   | j                             |           t          j                    }|
|_        t          j        d|z  t          j        d          |d<   	 | j                             |           |                     d           n{# t          j        $ ri}|j        \  }}| 
                    |t          j        t          |                     dt6          j        z  }|                     ||v |           Y d }~nd }~ww xY wt          j                    }|
|_        t          j        d|z  t          j        d          |d<   	 | j                             |           |                     d           n{# t          j        $ ri}|j        \  }}| 
                    |t          j        t          |                     dt6          j        z  }|                     ||v |           Y d }~nd }~ww xY wt          j                    }|
|_        t          j        d|z  t          j        d          |d<   	 | j                             |           |                     d           n{# t          j        $ ri}|j        \  }}| 
                    |t          j        t          |                     dt6          j        z  }|                     ||v |           Y d }~nd }~ww xY w| j                             |
           d S )Nzcn=reference_kept,cn=Users,%sz cn=reference_removed,cn=Users,%sr   z$afafafaf-fafa-afaf-fafa-afafafafafafr(  r   
objectGUIDr.  r   rO   r   r   r   r)  r/  r   z	<GUID=%s>	assistantzCN=NoneNone,%s)r*   r   r   r+   r3   r   r   r4   r5   r   rS   r   r   r   GUIDr   r   r\   r   r[   r]   r   r`   r   rs   ru   r$  r   r%  r   r^   )r=   r   kept_dn_strremoved_dn_strr   none_sid_strnone_guid_strrB   	kept_guidkept_sidkept_dnremoved_guidremoved_sidrg   r   r   r   s                    rF   #test_linked_vs_non_linked_referencez-DsdbTests.test_linked_vs_non_linked_referenceH  s   :002276B=H*++--7||m3>dj+>>>dj.AAA
!# # 	$ 	$ 	$ jc&7%0'3[&A   C C 	S1%%%ty#a&*>q*ABB	h.A{0CA0FGGa&)
 !# # 	$ 	$ 	$ jc&7%3'3[&A   C C 	S1%%%!$)SVL-A!-DEE !13q6+3Fq3IJJ
.))) kmm+J,D,/,<,57 7I	.Jc"""IILMMMM| 	. 	. 	.&KT3T3#?QHHHFAADOODCK--------		. kmm+K,,F,/,<,57 7I	.Jc"""IILMMMM| 	. 	. 	.&KT3T3#?QHHHFAADOODCK--------		. kmm-j;.F.1.>.9; ;K 	
#kmm-j;.F.1.A.9; ;K 	
#kmm-kL.H.1.>.9; ;K 	
#kmm-kL.H.1.A.9; ;K 	
# kmm-.>&.I.1.>.9; ;K	.Jc"""IILMMMM| 	. 	. 	.&KT3T3#?QHHHFAADOODCK--------		. kmm-j<.G.1.>.9; ;K	.Jc"""IILMMMM| 	. 	. 	.&KT3T3#?QHHHFAADOODCK--------		. kmm-kM.I.1.>.9; ;K	.Jc"""IILMMMM| 	. 	. 	.&KT3T3#?QHHHFAADOODCK--------		. 	
'"""""s}   =/J- -L%<AL  L%)/N P(APP=/W- -Y%<AY  Y%)/[ ](A]]/_ `=A`88`=c                    | j                                         }t          j        | j         d          }|}|                    |           t          |          }|                     || j                             |                     d S NCN=Users)r*   r0   r5   r6   add_baser+   rS   normalize_dn_in_domain)r=   r0   part_dnfull_dnfull_strs        rF    test_normalize_dn_in_domain_fullz*DsdbTests.test_normalize_dn_in_domain_full  s    J((**	&Z00###w<< 	::8DD	F 	F 	F 	F 	FrG   c                     | j                                         }d}t          j        | j         |          }|                    |           |                     || j                             |                     d S r@  r*   r0   r5   r6   rB  rS   rC  )r=   r0   part_strrE  s       rF    test_normalize_dn_in_domain_partz*DsdbTests.test_normalize_dn_in_domain_part  s    J((**	&X..### 	::8DD	F 	F 	F 	F 	FrG   c                     | j                                         }t          j        | j         d          }|}|                    |           |                     || j                             |                     d S r@  rI  )r=   r0   rD  rE  s       rF   #test_normalize_dn_in_domain_full_dnz-DsdbTests.test_normalize_dn_in_domain_full_dn  s    J((**	&Z00### 	::7CC	E 	E 	E 	E 	ErG   c           	      8   | j                                         }t          j        | j         d          }|                     t          j        | j         t          |          dz   t          |          z             | j                             |                     d S )NrA  ,)r*   r0   r5   r6   rS   r+   rC  )r=   r0   rD  s      rF   #test_normalize_dn_in_domain_part_dnz-DsdbTests.test_normalize_dn_in_domain_part_dn  s    J((**	&Z00 	
 #Gs 2S^^ CE E::7CC	E 	E 	E 	E 	ErG   )T)*__name__
__module____qualname__r#   rM   rY   rm   ry   r}   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   ra   r   r  r  r
  r  r  r  r   r&  r*  r0  r>  rG  rK  rM  rP  __classcell__rE   s   @rF   r   r   "   s       (: (: (: (: (:T  , , ,8), ), ),V, , ,B1, 1, 1,f2, 2, 2,h#, #, #,J, , ,>9 9 9i i i$
i 
i 
i
o 
o 
oi i i(H H H(Q Q QK K K] ] ]h h h= = =" " "  D D DLR& R& R&h# # #8 8 85 5 58 8 8 =Ag g g gR' ' '7 7 77 7 7) ) ):N# N# N#`F F F
F 
F 
F
E 
E 
EE E E E E E ErG   r   c                   N     e Zd Z fdZd Zd Zd Zd Zd Zd Z	d Z
d	 Z xZS )
DsdbNCRootTestsc                 r   t                                                       t          j                                        | _        t                      | _        | j                            | j                   t                      | _
        t          | j
        | j        | j                  | _        d| _        d S )Nr   F)r"   r#   r$   r%   r&   r   r   r'   r(   r   r)   r   r*   remoter=   rE   s    rF   r#   zDsdbNCRootTests.setUp
  s    +**,, ]]

!!!%'''+z"g' ' '
 rG   c                    | j                                         }t          j        | j         | j                                                   }t          j        | j         d| d          }	 | j                             |          }n@# t          j        $ r.}|j        \  }}|                     d||fz             Y d }~nd }~ww xY w| 	                    ||           d S )N<SID=>r   
r*   r   r5   r6   r0   get_nc_rootrs   ru   r   rS   r=   r   r0   r\   nc_rootr   r   rg   s           rF   test_dsdb_dn_nc_root_sidz(DsdbNCRootTests.test_dsdb_dn_nc_root_sid  s    *++--F4:tz';';'='=>>	VDJ 2 2 2 233	%j,,R00GG| 	% 	% 	%&KT3II9s$ % % % % % % % %	% 	G,,,,,   *B C$B==Cc                    | j                                         }t          j        | j         | j                                                   }t          j        | j         d| d          }	 | j                             |          }n@# t          j        $ r.}|j        \  }}|                     d||fz             Y d }~nd }~ww xY w| 	                    ||           d S )Nr\  z-500>r   r^  r`  s           rF   test_dsdb_dn_nc_root_admin_sidz.DsdbNCRootTests.test_dsdb_dn_nc_root_admin_sid#  s    *++--F4:tz';';'='=>>	VDJ 6 6 6 677	%j,,R00GG| 	% 	% 	%&KT3II9s$ % % % % % % % %	% 	G,,,,,rc  c                    | j                                         }t          j        | j         | j                                                   }t          j        | j         d|           }	 | j                             |          }n@# t          j        $ r.}|j        \  }}|                     d||fz             Y d }~nd }~ww xY w| 	                    ||           d S )Nz	CN=Users,r   r^  r`  s           rF   $test_dsdb_dn_nc_root_users_containerz4DsdbNCRootTests.test_dsdb_dn_nc_root_users_container/  s    *++--F4:tz';';'='=>>	VDJ 7I 7 788	%j,,R00GG| 	% 	% 	%&KT3II9s$ % % % % % % % %	% 	G,,,,,   )B C$B<<Cc                    | j                                         }t          j        | j         | j                                                   }t          j        | j         d|           }	 | j                             |          }n@# t          j        $ r.}|j        \  }}|                     d||fz             Y d }~nd }~ww xY w| 	                    ||           d S )NzCN=Xnotexisting,CN=Users,r   r^  r`  s           rF   test_dsdb_dn_nc_root_new_dnz+DsdbNCRootTests.test_dsdb_dn_nc_root_new_dn;  s    *++--F4:tz';';'='=>>	VDJ GI G GHH	%j,,R00GG| 	% 	% 	%&KT3II9s$ % % % % % % % %	% 	G,,,,,rh  c                    t          j        | j        | j                                                  }t          j        | j        d|           }	 | j                            |          }n@# t           j        $ r.}|j        \  }}|                     d||fz             Y d }~nd }~ww xY w|                     ||           d S )NzE<GUID=828e3baf-fa02-4d82-ba5d-6f647dab5fd8>;CN=Xnotexisting,CN=Users,r   )	r5   r6   r*   r0   r_  rs   ru   r   rS   )r=   r0   r\   ra  r   r   rg   s          rF   %test_dsdb_dn_nc_root_new_dn_with_guidz5DsdbNCRootTests.test_dsdb_dn_nc_root_new_dn_with_guidG  s    F4:tz';';'='=>>	VDJ shq s stt	%j,,R00GG| 	% 	% 	%&KT3II9s$ % % % % % % % %	% 	G,,,,,s   A+ +B(:$B##B(c                    | j                                         }| j                                         }t          j        | j         d| d          }	 | j                             |          }n@# t          j        $ r.}|j        \  }}|                     d||fz             Y d }~nd }~ww xY w| 	                    ||           d S )N<GUID=r]  r   )
r*   get_ntds_GUIDget_config_basednr5   r6   r_  rs   ru   r   rS   )r=   	ntds_guidconfiguration_dnr\   ra  r   r   rg   s           rF   test_dsdb_dn_nc_root_guidz)DsdbNCRootTests.test_dsdb_dn_nc_root_guidR  s    J,,..	:7799VDJ 5 5 5 566	%j,,R00GG| 	% 	% 	%&KT3II9s$ % % % % % % % %	% 	)733333s   A- -B*<$B%%B*c                    | j                                         }| j                                         }t          j        | j         | j                                                   }t          j        | j         d| d|           }	 | j                             |          }n@# t          j        $ r.}|j        \  }}| 	                    d||fz             Y d }~nd }~ww xY w| 
                    ||           d S )Nrn  z>;CN=Xnotexisting,CN=Users,r   r*   ro  rp  r5   r6   r0   r_  rs   ru   r   rS   	r=   rq  rr  r0   r\   ra  r   r   rg   s	            rF   2test_dsdb_dn_nc_root_misleading_to_noexisting_guidzBDsdbNCRootTests.test_dsdb_dn_nc_root_misleading_to_noexisting_guid^  s   J,,..	:7799F4:tz';';'='=>>	VDJ Z Z Zy Z Z[[	%j,,R00GG| 	% 	% 	%&KT3II9s$ % % % % % % % %	% 	)733333   B   C/$CCc                    | j                                         }| j                                         }t          j        | j         | j                                                   }t          j        | j         d| d|           }	 | j                             |          }n@# t          j        $ r.}|j        \  }}| 	                    d||fz             Y d }~nd }~ww xY w| 
                    ||           d S )Nrn  z>;r   ru  rv  s	            rF   0test_dsdb_dn_nc_root_misleading_to_existing_guidz@DsdbNCRootTests.test_dsdb_dn_nc_root_misleading_to_existing_guidk  s   J,,..	:7799F4:tz';';'='=>>	VDJ A A Ai A ABB	%j,,R00GG| 	% 	% 	%&KT3II9s$ % % % % % % % %	% 	)733333rx  )rQ  rR  rS  r#   rb  re  rg  rj  rl  rs  rw  rz  rT  rU  s   @rF   rW  rW    s        	 	 	 	 	
- 
- 
-
- 
- 
-
- 
- 
-
- 
- 
-	- 	- 	-
4 
4 
44 4 44 4 4 4 4 4 4rG   rW  c                        e Zd Z fdZ xZS )DsdbRemoteNCRootTestsc                     t                                                       t          dt          j                            d          z  | j        |                                 | j                  | _	        d| _
        d S )Nz	ldap://%sSERVER)urlr   r   r   T)r"   r#   r   r$   r%   env_get_var_valuer)   get_credentialsr   r*   rY  rZ  s    rF   r#   zDsdbRemoteNCRootTests.setUpy  sg    {U[-J-J8-T-TT(,'+';';'='="g' ' '
 rG   )rQ  rR  rS  r#   rT  rU  s   @rF   r|  r|  x  s8                rG   r|  c                   $     e Zd Z fdZd Z xZS )DsdbFullScanTestsc                 &   t          t          |                                            t          j                                        | _        t                      | _        | j        	                    | j                   t                      | _        d S r   )r"   r  r#   r$   r%   r&   r   r   r'   r(   r   r)   rZ  s    rF   r#   zDsdbFullScanTests.setUp  si    &&,,...+**,, ]]

!!!%''rG   c                     	 t          | j        | j        | j        dg          | _        d S # t
          j        $ r-}|j        d         }|                     d           Y d }~d S d }~ww xY w)Nz$disable_full_db_scan_for_self_test:1)r   r   r   optionsrO   z(sam.ldb required a full scan to start up)	r   r)   r'   r   r*   r5   rs   ru   r   )r=   rx   r   s      rF   test_sam_ldb_open_no_full_scanz0DsdbFullScanTests.test_sam_ldb_open_no_full_scan  s    	BDL+/:"&'(N'OQ Q QDJJJ | 	B 	B 	B8A;DII@AAAAAAAAA	Bs   (, A("A##A()rQ  rR  rS  r#   r  rT  rU  s   @rF   r  r    sN        ( ( ( ( (B B B B B B BrG   r  )__doc__samba.credentialsr   samba.samdbr   
samba.authr   samba.testsr   r   	samba.ndrr   r	   samba.dcerpcr
   r   r   r$   r   r   r5   r,   r   rW  r|  r   rG   rF   <module>r     s  $   ) ) ) ) ) )       % % % % % %             $ $ $ $ $ $ * * * * * * * * 1 1 1 1 1 1 1 1 1 1             



  dE dE dE dE dE dE dE dELn4 n4 n4 n4 n4h n4 n4 n4`    O   B B B B B B B B B BrG   