2010-06-24 08:33:58 +04:00
#!/usr/bin/env python
2007-12-24 04:19:41 +03:00
# Unix SMB/CIFS implementation.
2008-09-19 14:04:13 +04:00
# Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2005-2008
2007-12-24 04:19:41 +03:00
# Copyright (C) Martin Kuehl <mkhl@samba.org> 2006
#
# This is a Python port of the original in testprogs/ejs/samba3sam.js
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
2007-12-31 01:46:05 +03:00
""" Tests for the samba3sam LDB module, which maps Samba3 LDAP to AD LDAP. """
2007-12-24 04:19:41 +03:00
import os
import ldb
2010-06-13 18:38:24 +04:00
from ldb import SCOPE_DEFAULT , SCOPE_BASE
2007-12-24 04:19:41 +03:00
from samba import Ldb , substitute_var
2010-06-13 18:38:24 +04:00
from samba . tests import TestCaseInTempDir , env_loadparm
2008-12-18 19:50:54 +03:00
import samba . dcerpc . security
2008-09-30 18:02:21 +04:00
import samba . ndr
2010-01-08 01:31:23 +03:00
from samba . auth import system_session
2011-06-02 04:52:06 +04:00
from operator import attrgetter
2007-12-24 04:19:41 +03:00
2008-09-20 16:35:21 +04:00
def read_datafile ( filename ) :
2011-02-03 09:35:54 +03:00
paths = [ " ../../../../../testdata/samba3 " ,
" ../../../../testdata/samba3 " ]
for p in paths :
datadir = os . path . join ( os . path . dirname ( __file__ ) , p )
if os . path . exists ( datadir ) :
break
2008-09-20 16:35:21 +04:00
return open ( os . path . join ( datadir , filename ) , ' r ' ) . read ( )
2007-12-24 04:19:41 +03:00
2008-09-18 23:53:08 +04:00
def ldb_debug ( l , text ) :
print text
2008-09-19 14:04:13 +04:00
2007-12-31 01:46:05 +03:00
class MapBaseTestCase ( TestCaseInTempDir ) :
2008-09-19 01:46:58 +04:00
""" Base test case for mapping tests. """
2007-12-26 01:36:31 +03:00
def setup_modules ( self , ldb , s3 , s4 ) :
2007-12-31 01:46:05 +03:00
ldb . add ( { " dn " : " @MAP=samba3sam " ,
" @FROM " : s4 . basedn ,
" @TO " : " sambaDomainName=TESTS, " + s3 . basedn } )
2007-12-24 04:19:41 +03:00
2007-12-31 01:46:05 +03:00
ldb . add ( { " dn " : " @MODULES " ,
2010-01-08 04:15:01 +03:00
" @LIST " : " rootdse,paged_results,server_sort,asq,samldb,password_hash,operational,objectguid,rdn_name,samba3sam,samba3sid,partition " } )
2007-12-31 01:46:05 +03:00
ldb . add ( { " dn " : " @PARTITION " ,
2009-10-12 13:49:23 +04:00
" partition " : [ " %s " % ( s4 . basedn_casefold ) ,
" %s " % ( s3 . basedn_casefold ) ] ,
2009-10-22 02:22:18 +04:00
" replicateEntries " : [ " @ATTRIBUTES " , " @INDEXLIST " ] ,
" modules " : " *: " } )
2007-12-31 01:46:05 +03:00
def setUp ( self ) :
2010-06-13 18:38:24 +04:00
self . lp = env_loadparm ( )
self . lp . set ( " workgroup " , " TESTS " )
self . lp . set ( " netbios name " , " TESTS " )
2007-12-31 01:46:05 +03:00
super ( MapBaseTestCase , self ) . setUp ( )
def make_dn ( basedn , rdn ) :
2008-09-21 05:42:27 +04:00
return " %s ,sambaDomainName=TESTS, %s " % ( rdn , basedn )
2007-12-31 01:46:05 +03:00
def make_s4dn ( basedn , rdn ) :
2008-09-21 05:42:27 +04:00
return " %s , %s " % ( rdn , basedn )
2007-12-31 01:46:05 +03:00
self . ldbfile = os . path . join ( self . tempdir , " test.ldb " )
self . ldburl = " tdb:// " + self . ldbfile
2007-12-24 04:19:41 +03:00
2007-12-31 01:46:05 +03:00
tempdir = self . tempdir
class Target :
2008-09-19 14:44:00 +04:00
""" Simple helper class that contains data for a specific SAM
connection . """
2010-06-13 18:38:24 +04:00
def __init__ ( self , basedn , dn , lp ) :
self . db = Ldb ( lp = lp , session_info = system_session ( ) )
2011-06-02 12:56:10 +04:00
self . db . set_opaque ( " skip_allocate_sids " , " true " ) ;
2007-12-31 01:46:05 +03:00
self . basedn = basedn
2009-10-12 13:49:23 +04:00
self . basedn_casefold = ldb . Dn ( self . db , basedn ) . get_casefold ( )
2007-12-31 01:46:05 +03:00
self . substvars = { " BASEDN " : self . basedn }
2009-10-12 13:49:23 +04:00
self . file = os . path . join ( tempdir , " %s .ldb " % self . basedn_casefold )
self . url = " tdb:// " + self . file
2007-12-31 01:46:05 +03:00
self . _dn = dn
def dn ( self , rdn ) :
2008-09-21 05:42:27 +04:00
return self . _dn ( self . basedn , rdn )
2007-12-31 01:46:05 +03:00
def connect ( self ) :
return self . db . connect ( self . url )
2008-09-19 14:04:13 +04:00
def setup_data ( self , path ) :
2008-09-20 16:35:21 +04:00
self . add_ldif ( read_datafile ( path ) )
2008-09-19 14:04:13 +04:00
def subst ( self , text ) :
return substitute_var ( text , self . substvars )
def add_ldif ( self , ldif ) :
self . db . add_ldif ( self . subst ( ldif ) )
def modify_ldif ( self , ldif ) :
self . db . modify_ldif ( self . subst ( ldif ) )
2010-06-13 18:38:24 +04:00
self . samba4 = Target ( " dc=vernstok,dc=nl " , make_s4dn , self . lp )
self . samba3 = Target ( " cn=Samba3Sam " , make_dn , self . lp )
2007-12-31 01:46:05 +03:00
self . samba3 . connect ( )
self . samba4 . connect ( )
def tearDown ( self ) :
os . unlink ( self . ldbfile )
os . unlink ( self . samba3 . file )
os . unlink ( self . samba4 . file )
super ( MapBaseTestCase , self ) . tearDown ( )
2008-09-30 18:02:21 +04:00
def assertSidEquals ( self , text , ndr_sid ) :
2008-12-18 19:50:54 +03:00
sid_obj1 = samba . ndr . ndr_unpack ( samba . dcerpc . security . dom_sid ,
2008-09-30 18:02:21 +04:00
str ( ndr_sid [ 0 ] ) )
2008-12-22 01:05:35 +03:00
sid_obj2 = samba . dcerpc . security . dom_sid ( text )
self . assertEquals ( sid_obj1 , sid_obj2 )
2008-09-30 18:02:21 +04:00
2007-12-31 01:46:05 +03:00
class Samba3SamTestCase ( MapBaseTestCase ) :
2008-09-20 16:35:21 +04:00
2007-12-31 01:46:05 +03:00
def setUp ( self ) :
super ( Samba3SamTestCase , self ) . setUp ( )
2010-06-13 18:38:24 +04:00
ldb = Ldb ( self . ldburl , lp = self . lp , session_info = system_session ( ) )
2011-06-02 12:56:10 +04:00
ldb . set_opaque ( " skip_allocate_sids " , " true " ) ;
2008-09-19 14:04:13 +04:00
self . samba3 . setup_data ( " samba3.ldif " )
2008-09-20 16:35:21 +04:00
ldif = read_datafile ( " provision_samba3sam.ldif " )
2008-09-19 14:04:13 +04:00
ldb . add_ldif ( self . samba4 . subst ( ldif ) )
2007-12-31 01:46:05 +03:00
self . setup_modules ( ldb , self . samba3 , self . samba4 )
2008-09-20 16:35:21 +04:00
del ldb
2010-06-13 18:38:24 +04:00
self . ldb = Ldb ( self . ldburl , lp = self . lp , session_info = system_session ( ) )
2011-06-02 12:56:10 +04:00
self . ldb . set_opaque ( " skip_allocate_sids " , " true " ) ;
2007-12-31 01:46:05 +03:00
2008-09-19 00:56:58 +04:00
def test_search_non_mapped ( self ) :
""" Looking up by non-mapped attribute """
2008-01-02 10:52:31 +03:00
msg = self . ldb . search ( expression = " (cn=Administrator) " )
2007-12-24 04:19:41 +03:00
self . assertEquals ( len ( msg ) , 1 )
self . assertEquals ( msg [ 0 ] [ " cn " ] , " Administrator " )
2008-09-19 00:56:58 +04:00
def test_search_non_mapped ( self ) :
""" Looking up by mapped attribute """
2008-01-02 10:52:31 +03:00
msg = self . ldb . search ( expression = " (name=Backup Operators) " )
2007-12-24 04:19:41 +03:00
self . assertEquals ( len ( msg ) , 1 )
2008-12-21 09:34:27 +03:00
self . assertEquals ( str ( msg [ 0 ] [ " name " ] ) , " Backup Operators " )
2007-12-24 04:19:41 +03:00
2008-09-19 00:56:58 +04:00
def test_old_name_of_renamed ( self ) :
""" Looking up by old name of renamed attribute """
2008-01-02 10:52:31 +03:00
msg = self . ldb . search ( expression = " (displayName=Backup Operators) " )
2007-12-24 04:19:41 +03:00
self . assertEquals ( len ( msg ) , 0 )
2008-09-19 00:56:58 +04:00
def test_mapped_containing_sid ( self ) :
""" Looking up mapped entry containing SID """
2008-01-02 10:52:31 +03:00
msg = self . ldb . search ( expression = " (cn=Replicator) " )
2007-12-24 04:19:41 +03:00
self . assertEquals ( len ( msg ) , 1 )
2008-09-19 14:44:00 +04:00
self . assertEquals ( str ( msg [ 0 ] . dn ) ,
" cn=Replicator,ou=Groups,dc=vernstok,dc=nl " )
2008-09-19 03:43:04 +04:00
self . assertTrue ( " objectSid " in msg [ 0 ] )
2008-09-30 18:02:21 +04:00
self . assertSidEquals ( " S-1-5-21-4231626423-2410014848-2360679739-552 " ,
msg [ 0 ] [ " objectSid " ] )
2007-12-24 04:19:41 +03:00
oc = set ( msg [ 0 ] [ " objectClass " ] )
2008-09-19 03:43:04 +04:00
self . assertEquals ( oc , set ( [ " group " ] ) )
2007-12-24 04:19:41 +03:00
2008-09-19 00:56:58 +04:00
def test_search_by_objclass ( self ) :
""" Looking up by objectClass """
2008-01-02 10:52:31 +03:00
msg = self . ldb . search ( expression = " (|(objectClass=user)(cn=Administrator)) " )
2008-09-19 14:04:13 +04:00
self . assertEquals ( set ( [ str ( m . dn ) for m in msg ] ) ,
2008-09-19 14:44:00 +04:00
set ( [ " unixName=Administrator,ou=Users,dc=vernstok,dc=nl " ,
" unixName=nobody,ou=Users,dc=vernstok,dc=nl " ] ) )
2007-12-24 04:19:41 +03:00
2007-12-31 01:46:05 +03:00
def test_s3sam_modify ( self ) :
2008-09-19 14:04:13 +04:00
# Adding a record that will be fallbacked
2008-01-02 10:52:31 +03:00
self . ldb . add ( { " dn " : " cn=Foo " ,
2007-12-31 01:46:05 +03:00
" foo " : " bar " ,
" blah " : " Blie " ,
" cn " : " Foo " ,
" showInAdvancedViewOnly " : " TRUE " }
)
2007-12-24 04:19:41 +03:00
2008-09-19 14:04:13 +04:00
# Checking for existence of record (local)
2008-09-19 14:44:00 +04:00
# TODO: This record must be searched in the local database, which is
# currently only supported for base searches
2007-12-24 04:19:41 +03:00
# msg = ldb.search(expression="(cn=Foo)", ['foo','blah','cn','showInAdvancedViewOnly')]
# TODO: Actually, this version should work as well but doesn't...
#
#
2008-09-19 01:46:58 +04:00
msg = self . ldb . search ( expression = " (cn=Foo) " , base = " cn=Foo " ,
scope = SCOPE_BASE ,
attrs = [ ' foo ' , ' blah ' , ' cn ' , ' showInAdvancedViewOnly ' ] )
2007-12-24 04:19:41 +03:00
self . assertEquals ( len ( msg ) , 1 )
2008-12-21 09:34:27 +03:00
self . assertEquals ( str ( msg [ 0 ] [ " showInAdvancedViewOnly " ] ) , " TRUE " )
self . assertEquals ( str ( msg [ 0 ] [ " foo " ] ) , " bar " )
self . assertEquals ( str ( msg [ 0 ] [ " blah " ] ) , " Blie " )
2007-12-24 04:19:41 +03:00
2008-09-19 00:56:58 +04:00
# Adding record that will be mapped
2008-01-02 10:52:31 +03:00
self . ldb . add ( { " dn " : " cn=Niemand,cn=Users,dc=vernstok,dc=nl " ,
2007-12-31 01:46:05 +03:00
" objectClass " : " user " ,
" unixName " : " bin " ,
" sambaUnicodePwd " : " geheim " ,
" cn " : " Niemand " } )
2007-12-24 04:19:41 +03:00
2008-09-19 00:56:58 +04:00
# Checking for existence of record (remote)
2008-01-02 10:52:31 +03:00
msg = self . ldb . search ( expression = " (unixName=bin) " ,
attrs = [ ' unixName ' , ' cn ' , ' dn ' , ' sambaUnicodePwd ' ] )
2007-12-24 04:19:41 +03:00
self . assertEquals ( len ( msg ) , 1 )
2008-12-21 09:34:27 +03:00
self . assertEquals ( str ( msg [ 0 ] [ " cn " ] ) , " Niemand " )
self . assertEquals ( str ( msg [ 0 ] [ " sambaUnicodePwd " ] ) , " geheim " )
2007-12-24 04:19:41 +03:00
2008-09-19 00:56:58 +04:00
# Checking for existence of record (local && remote)
2008-01-02 10:52:31 +03:00
msg = self . ldb . search ( expression = " (&(unixName=bin)(sambaUnicodePwd=geheim)) " ,
2007-12-24 04:19:41 +03:00
attrs = [ ' unixName ' , ' cn ' , ' dn ' , ' sambaUnicodePwd ' ] )
self . assertEquals ( len ( msg ) , 1 ) # TODO: should check with more records
2008-12-21 09:34:27 +03:00
self . assertEquals ( str ( msg [ 0 ] [ " cn " ] ) , " Niemand " )
self . assertEquals ( str ( msg [ 0 ] [ " unixName " ] ) , " bin " )
self . assertEquals ( str ( msg [ 0 ] [ " sambaUnicodePwd " ] ) , " geheim " )
2007-12-24 04:19:41 +03:00
2008-09-19 00:56:58 +04:00
# Checking for existence of record (local || remote)
2008-01-02 10:52:31 +03:00
msg = self . ldb . search ( expression = " (|(unixName=bin)(sambaUnicodePwd=geheim)) " ,
2007-12-24 04:19:41 +03:00
attrs = [ ' unixName ' , ' cn ' , ' dn ' , ' sambaUnicodePwd ' ] )
2008-09-19 00:56:58 +04:00
#print "got %d replies" % len(msg)
2007-12-24 04:19:41 +03:00
self . assertEquals ( len ( msg ) , 1 ) # TODO: should check with more records
2008-12-21 09:34:27 +03:00
self . assertEquals ( str ( msg [ 0 ] [ " cn " ] ) , " Niemand " )
self . assertEquals ( str ( msg [ 0 ] [ " unixName " ] ) , " bin " )
self . assertEquals ( str ( msg [ 0 ] [ " sambaUnicodePwd " ] ) , " geheim " )
2007-12-24 04:19:41 +03:00
2008-09-19 00:56:58 +04:00
# Checking for data in destination database
2008-09-18 23:53:08 +04:00
msg = self . samba3 . db . search ( expression = " (cn=Niemand) " )
2007-12-24 04:19:41 +03:00
self . assertTrue ( len ( msg ) > = 1 )
2008-12-21 09:34:27 +03:00
self . assertEquals ( str ( msg [ 0 ] [ " sambaSID " ] ) ,
2008-09-19 01:46:58 +04:00
" S-1-5-21-4231626423-2410014848-2360679739-2001 " )
2008-12-21 09:34:27 +03:00
self . assertEquals ( str ( msg [ 0 ] [ " displayName " ] ) , " Niemand " )
2007-12-24 04:19:41 +03:00
2008-09-19 00:56:58 +04:00
# Adding attribute...
2008-01-02 10:52:31 +03:00
self . ldb . modify_ldif ( """
2007-12-24 04:19:41 +03:00
dn : cn = Niemand , cn = Users , dc = vernstok , dc = nl
changetype : modify
add : description
description : Blah
""" )
2008-09-19 00:56:58 +04:00
# Checking whether changes are still there...
2008-01-02 10:52:31 +03:00
msg = self . ldb . search ( expression = " (cn=Niemand) " )
2007-12-24 04:19:41 +03:00
self . assertTrue ( len ( msg ) > = 1 )
2008-12-21 09:34:27 +03:00
self . assertEquals ( str ( msg [ 0 ] [ " cn " ] ) , " Niemand " )
self . assertEquals ( str ( msg [ 0 ] [ " description " ] ) , " Blah " )
2007-12-24 04:19:41 +03:00
2008-09-19 00:56:58 +04:00
# Modifying attribute...
2008-01-02 10:52:31 +03:00
self . ldb . modify_ldif ( """
2007-12-24 04:19:41 +03:00
dn : cn = Niemand , cn = Users , dc = vernstok , dc = nl
changetype : modify
replace : description
description : Blie
""" )
2008-09-19 00:56:58 +04:00
# Checking whether changes are still there...
2008-01-02 10:52:31 +03:00
msg = self . ldb . search ( expression = " (cn=Niemand) " )
2007-12-24 04:19:41 +03:00
self . assertTrue ( len ( msg ) > = 1 )
2008-12-21 09:34:27 +03:00
self . assertEquals ( str ( msg [ 0 ] [ " description " ] ) , " Blie " )
2007-12-24 04:19:41 +03:00
2008-09-19 00:56:58 +04:00
# Deleting attribute...
2008-01-02 10:52:31 +03:00
self . ldb . modify_ldif ( """
2007-12-24 04:19:41 +03:00
dn : cn = Niemand , cn = Users , dc = vernstok , dc = nl
changetype : modify
delete : description
""" )
2008-09-19 00:56:58 +04:00
# Checking whether changes are no longer there...
2008-01-02 10:52:31 +03:00
msg = self . ldb . search ( expression = " (cn=Niemand) " )
2007-12-24 04:19:41 +03:00
self . assertTrue ( len ( msg ) > = 1 )
2008-09-18 23:53:08 +04:00
self . assertTrue ( not " description " in msg [ 0 ] )
2007-12-24 04:19:41 +03:00
2008-09-19 00:56:58 +04:00
# Renaming record...
2008-09-19 01:46:58 +04:00
self . ldb . rename ( " cn=Niemand,cn=Users,dc=vernstok,dc=nl " ,
" cn=Niemand2,cn=Users,dc=vernstok,dc=nl " )
2007-12-24 04:19:41 +03:00
2008-09-19 00:56:58 +04:00
# Checking whether DN has changed...
2008-01-02 10:52:31 +03:00
msg = self . ldb . search ( expression = " (cn=Niemand2) " )
2007-12-24 04:19:41 +03:00
self . assertEquals ( len ( msg ) , 1 )
2008-09-19 14:44:00 +04:00
self . assertEquals ( str ( msg [ 0 ] . dn ) ,
" cn=Niemand2,cn=Users,dc=vernstok,dc=nl " )
2007-12-24 04:19:41 +03:00
2008-09-19 00:56:58 +04:00
# Deleting record...
2008-01-02 10:52:31 +03:00
self . ldb . delete ( " cn=Niemand2,cn=Users,dc=vernstok,dc=nl " )
2007-12-24 04:19:41 +03:00
2008-09-19 00:56:58 +04:00
# Checking whether record is gone...
2008-01-02 10:52:31 +03:00
msg = self . ldb . search ( expression = " (cn=Niemand2) " )
2007-12-24 04:19:41 +03:00
self . assertEquals ( len ( msg ) , 0 )
2007-12-31 01:46:05 +03:00
class MapTestCase ( MapBaseTestCase ) :
2008-09-20 16:35:21 +04:00
2007-12-31 01:46:05 +03:00
def setUp ( self ) :
super ( MapTestCase , self ) . setUp ( )
2010-06-13 18:38:24 +04:00
ldb = Ldb ( self . ldburl , lp = self . lp , session_info = system_session ( ) )
2011-06-02 12:56:10 +04:00
ldb . set_opaque ( " skip_allocate_sids " , " true " ) ;
2008-09-20 16:35:21 +04:00
ldif = read_datafile ( " provision_samba3sam.ldif " )
2008-09-19 14:04:13 +04:00
ldb . add_ldif ( self . samba4 . subst ( ldif ) )
2007-12-31 01:46:05 +03:00
self . setup_modules ( ldb , self . samba3 , self . samba4 )
2008-09-20 16:35:21 +04:00
del ldb
2010-06-13 18:38:24 +04:00
self . ldb = Ldb ( self . ldburl , lp = self . lp , session_info = system_session ( ) )
2011-06-02 12:56:10 +04:00
self . ldb . set_opaque ( " skip_allocate_sids " , " true " ) ;
2007-12-31 01:46:05 +03:00
def test_map_search ( self ) :
2008-09-19 00:56:58 +04:00
""" Running search tests on mapped data. """
2008-09-21 05:42:27 +04:00
self . samba3 . db . add ( {
" dn " : " sambaDomainName=TESTS, " + self . samba3 . basedn ,
" objectclass " : [ " sambaDomain " , " top " ] ,
" sambaSID " : " S-1-5-21-4231626423-2410014848-2360679739 " ,
" sambaNextRid " : " 2000 " ,
" sambaDomainName " : " TESTS "
} )
2007-12-24 04:19:41 +03:00
2009-10-02 14:00:42 +04:00
# Add a set of split records
self . ldb . add_ldif ( """
dn : """ + self.samba4.dn( " cn=Domain Users " ) + """
objectClass : group
cn : Domain Users
objectSid : S - 1 - 5 - 21 - 4231626423 - 2410014848 - 2360679739 - 513
""" )
2008-09-21 05:42:27 +04:00
# Add a set of split records
2008-09-21 07:21:56 +04:00
self . ldb . add_ldif ( """
dn : """ + self.samba4.dn( " cn=X " ) + """
objectClass : user
cn : X
codePage : x
revision : x
dnsHostName : x
nextRid : y
lastLogon : x
description : x
objectSid : S - 1 - 5 - 21 - 4231626423 - 2410014848 - 2360679739 - 552
""" )
2008-09-21 05:42:27 +04:00
self . ldb . add ( {
" dn " : self . samba4 . dn ( " cn=Y " ) ,
" objectClass " : " top " ,
" cn " : " Y " ,
" codePage " : " x " ,
" revision " : " x " ,
" dnsHostName " : " y " ,
" nextRid " : " y " ,
" lastLogon " : " y " ,
" description " : " x " } )
self . ldb . add ( {
" dn " : self . samba4 . dn ( " cn=Z " ) ,
" objectClass " : " top " ,
" cn " : " Z " ,
" codePage " : " x " ,
" revision " : " y " ,
" dnsHostName " : " z " ,
" nextRid " : " y " ,
" lastLogon " : " z " ,
" description " : " y " } )
2007-12-24 04:19:41 +03:00
2008-09-19 00:56:58 +04:00
# Add a set of remote records
2007-12-24 04:19:41 +03:00
2008-09-21 05:42:27 +04:00
self . samba3 . db . add ( {
" dn " : self . samba3 . dn ( " cn=A " ) ,
" objectClass " : " posixAccount " ,
" cn " : " A " ,
" sambaNextRid " : " x " ,
" sambaBadPasswordCount " : " x " ,
" sambaLogonTime " : " x " ,
" description " : " x " ,
" sambaSID " : " S-1-5-21-4231626423-2410014848-2360679739-552 " ,
" sambaPrimaryGroupSID " : " S-1-5-21-4231626423-2410014848-2360679739-512 " } )
self . samba3 . db . add ( {
" dn " : self . samba3 . dn ( " cn=B " ) ,
" objectClass " : " top " ,
" cn " : " B " ,
" sambaNextRid " : " x " ,
" sambaBadPasswordCount " : " x " ,
" sambaLogonTime " : " y " ,
" description " : " x " } )
self . samba3 . db . add ( {
" dn " : self . samba3 . dn ( " cn=C " ) ,
" objectClass " : " top " ,
" cn " : " C " ,
" sambaNextRid " : " x " ,
" sambaBadPasswordCount " : " y " ,
" sambaLogonTime " : " z " ,
" description " : " y " } )
2007-12-24 04:19:41 +03:00
2008-09-19 00:56:58 +04:00
# Testing search by DN
2007-12-24 04:19:41 +03:00
# Search remote record by local DN
2008-01-02 10:52:31 +03:00
dn = self . samba4 . dn ( " cn=A " )
2008-09-19 01:46:58 +04:00
res = self . ldb . search ( dn , scope = SCOPE_BASE ,
attrs = [ " dnsHostName " , " lastLogon " ] )
2007-12-24 04:19:41 +03:00
self . assertEquals ( len ( res ) , 1 )
2008-09-20 16:35:21 +04:00
self . assertEquals ( str ( res [ 0 ] . dn ) , dn )
2008-01-02 10:52:31 +03:00
self . assertTrue ( not " dnsHostName " in res [ 0 ] )
2008-12-21 09:34:27 +03:00
self . assertEquals ( str ( res [ 0 ] [ " lastLogon " ] ) , " x " )
2007-12-24 04:19:41 +03:00
# Search remote record by remote DN
2008-01-02 10:52:31 +03:00
dn = self . samba3 . dn ( " cn=A " )
2008-09-19 01:46:58 +04:00
res = self . samba3 . db . search ( dn , scope = SCOPE_BASE ,
attrs = [ " dnsHostName " , " lastLogon " , " sambaLogonTime " ] )
2007-12-24 04:19:41 +03:00
self . assertEquals ( len ( res ) , 1 )
2008-09-20 16:35:21 +04:00
self . assertEquals ( str ( res [ 0 ] . dn ) , dn )
2008-01-02 10:52:31 +03:00
self . assertTrue ( not " dnsHostName " in res [ 0 ] )
self . assertTrue ( not " lastLogon " in res [ 0 ] )
2008-12-21 09:34:27 +03:00
self . assertEquals ( str ( res [ 0 ] [ " sambaLogonTime " ] ) , " x " )
2007-12-24 04:19:41 +03:00
# Search split record by local DN
2008-01-02 10:52:31 +03:00
dn = self . samba4 . dn ( " cn=X " )
2008-09-19 01:46:58 +04:00
res = self . ldb . search ( dn , scope = SCOPE_BASE ,
attrs = [ " dnsHostName " , " lastLogon " ] )
2007-12-24 04:19:41 +03:00
self . assertEquals ( len ( res ) , 1 )
2008-09-20 16:35:21 +04:00
self . assertEquals ( str ( res [ 0 ] . dn ) , dn )
2008-12-21 09:34:27 +03:00
self . assertEquals ( str ( res [ 0 ] [ " dnsHostName " ] ) , " x " )
self . assertEquals ( str ( res [ 0 ] [ " lastLogon " ] ) , " x " )
2007-12-24 04:19:41 +03:00
# Search split record by remote DN
2008-01-02 10:52:31 +03:00
dn = self . samba3 . dn ( " cn=X " )
2008-09-19 01:46:58 +04:00
res = self . samba3 . db . search ( dn , scope = SCOPE_BASE ,
attrs = [ " dnsHostName " , " lastLogon " , " sambaLogonTime " ] )
2007-12-24 04:19:41 +03:00
self . assertEquals ( len ( res ) , 1 )
2008-09-20 16:35:21 +04:00
self . assertEquals ( str ( res [ 0 ] . dn ) , dn )
2008-01-02 10:52:31 +03:00
self . assertTrue ( not " dnsHostName " in res [ 0 ] )
self . assertTrue ( not " lastLogon " in res [ 0 ] )
2008-12-21 09:34:27 +03:00
self . assertEquals ( str ( res [ 0 ] [ " sambaLogonTime " ] ) , " x " )
2007-12-24 04:19:41 +03:00
2008-09-19 00:56:58 +04:00
# Testing search by attribute
2007-12-24 04:19:41 +03:00
# Search by ignored attribute
2008-09-19 01:46:58 +04:00
res = self . ldb . search ( expression = " (revision=x) " , scope = SCOPE_DEFAULT ,
attrs = [ " dnsHostName " , " lastLogon " ] )
2007-12-24 04:19:41 +03:00
self . assertEquals ( len ( res ) , 2 )
2011-06-02 04:52:06 +04:00
res = sorted ( res , key = attrgetter ( ' dn ' ) )
self . assertEquals ( str ( res [ 0 ] . dn ) , self . samba4 . dn ( " cn=X " ) )
self . assertEquals ( str ( res [ 0 ] [ " dnsHostName " ] ) , " x " )
self . assertEquals ( str ( res [ 0 ] [ " lastLogon " ] ) , " x " )
self . assertEquals ( str ( res [ 1 ] . dn ) , self . samba4 . dn ( " cn=Y " ) )
self . assertEquals ( str ( res [ 1 ] [ " dnsHostName " ] ) , " y " )
self . assertEquals ( str ( res [ 1 ] [ " lastLogon " ] ) , " y " )
2007-12-24 04:19:41 +03:00
# Search by kept attribute
2008-09-19 01:46:58 +04:00
res = self . ldb . search ( expression = " (description=y) " ,
scope = SCOPE_DEFAULT , attrs = [ " dnsHostName " , " lastLogon " ] )
2007-12-24 04:19:41 +03:00
self . assertEquals ( len ( res ) , 2 )
2011-06-02 04:52:06 +04:00
res = sorted ( res , key = attrgetter ( ' dn ' ) )
self . assertEquals ( str ( res [ 0 ] . dn ) , self . samba4 . dn ( " cn=C " ) )
self . assertTrue ( not " dnsHostName " in res [ 0 ] )
2008-12-21 09:34:27 +03:00
self . assertEquals ( str ( res [ 0 ] [ " lastLogon " ] ) , " z " )
2011-06-02 04:52:06 +04:00
self . assertEquals ( str ( res [ 1 ] . dn ) , self . samba4 . dn ( " cn=Z " ) )
self . assertEquals ( str ( res [ 1 ] [ " dnsHostName " ] ) , " z " )
2008-12-21 09:34:27 +03:00
self . assertEquals ( str ( res [ 1 ] [ " lastLogon " ] ) , " z " )
2007-12-24 04:19:41 +03:00
# Search by renamed attribute
2008-09-19 14:44:00 +04:00
res = self . ldb . search ( expression = " (badPwdCount=x) " , scope = SCOPE_DEFAULT ,
attrs = [ " dnsHostName " , " lastLogon " ] )
2007-12-24 04:19:41 +03:00
self . assertEquals ( len ( res ) , 2 )
2011-06-02 04:52:06 +04:00
res = sorted ( res , key = attrgetter ( ' dn ' ) )
self . assertEquals ( str ( res [ 0 ] . dn ) , self . samba4 . dn ( " cn=A " ) )
2008-01-02 10:52:31 +03:00
self . assertTrue ( not " dnsHostName " in res [ 0 ] )
2011-06-02 04:52:06 +04:00
self . assertEquals ( str ( res [ 0 ] [ " lastLogon " ] ) , " x " )
self . assertEquals ( str ( res [ 1 ] . dn ) , self . samba4 . dn ( " cn=B " ) )
2008-01-02 10:52:31 +03:00
self . assertTrue ( not " dnsHostName " in res [ 1 ] )
2011-06-02 04:52:06 +04:00
self . assertEquals ( str ( res [ 1 ] [ " lastLogon " ] ) , " y " )
2007-12-24 04:19:41 +03:00
# Search by converted attribute
# TODO:
# Using the SID directly in the parse tree leads to conversion
# errors, letting the search fail with no results.
2008-01-02 10:52:31 +03:00
#res = self.ldb.search("(objectSid=S-1-5-21-4231626423-2410014848-2360679739-552)", scope=SCOPE_DEFAULT, attrs)
2008-09-21 07:21:56 +04:00
res = self . ldb . search ( expression = " (objectSid=*) " , base = None , scope = SCOPE_DEFAULT , attrs = [ " dnsHostName " , " lastLogon " , " objectSid " ] )
2009-10-02 14:00:42 +04:00
self . assertEquals ( len ( res ) , 4 )
2011-06-02 04:52:06 +04:00
res = sorted ( res , key = attrgetter ( ' dn ' ) )
self . assertEquals ( str ( res [ 1 ] . dn ) , self . samba4 . dn ( " cn=X " ) )
self . assertEquals ( str ( res [ 1 ] [ " dnsHostName " ] ) , " x " )
2008-12-21 09:34:27 +03:00
self . assertEquals ( str ( res [ 1 ] [ " lastLogon " ] ) , " x " )
2008-09-30 18:02:21 +04:00
self . assertSidEquals ( " S-1-5-21-4231626423-2410014848-2360679739-552 " ,
res [ 1 ] [ " objectSid " ] )
2008-09-21 07:21:56 +04:00
self . assertTrue ( " objectSid " in res [ 1 ] )
2011-06-02 04:52:06 +04:00
self . assertEquals ( str ( res [ 0 ] . dn ) , self . samba4 . dn ( " cn=A " ) )
self . assertTrue ( not " dnsHostName " in res [ 0 ] )
self . assertEquals ( str ( res [ 0 ] [ " lastLogon " ] ) , " x " )
self . assertSidEquals ( " S-1-5-21-4231626423-2410014848-2360679739-552 " ,
res [ 0 ] [ " objectSid " ] )
self . assertTrue ( " objectSid " in res [ 0 ] )
2007-12-24 04:19:41 +03:00
# Search by generated attribute
# In most cases, this even works when the mapping is missing
# a `convert_operator' by enumerating the remote db.
2008-09-19 14:44:00 +04:00
res = self . ldb . search ( expression = " (primaryGroupID=512) " ,
attrs = [ " dnsHostName " , " lastLogon " , " primaryGroupID " ] )
2007-12-24 04:19:41 +03:00
self . assertEquals ( len ( res ) , 1 )
2008-01-02 10:52:31 +03:00
self . assertEquals ( str ( res [ 0 ] . dn ) , self . samba4 . dn ( " cn=A " ) )
self . assertTrue ( not " dnsHostName " in res [ 0 ] )
2008-12-21 09:34:27 +03:00
self . assertEquals ( str ( res [ 0 ] [ " lastLogon " ] ) , " x " )
self . assertEquals ( str ( res [ 0 ] [ " primaryGroupID " ] ) , " 512 " )
2007-12-24 04:19:41 +03:00
2009-09-21 01:27:47 +04:00
# Note that Xs "objectSid" seems to be fine in the previous search for
# "objectSid"...
2007-12-24 04:19:41 +03:00
#res = ldb.search(expression="(primaryGroupID=*)", NULL, ldb. SCOPE_DEFAULT, attrs)
#print len(res) + " results found"
#for i in range(len(res)):
# for (obj in res[i]) {
# print obj + ": " + res[i][obj]
# }
# print "---"
#
# Search by remote name of renamed attribute */
2008-09-19 14:44:00 +04:00
res = self . ldb . search ( expression = " (sambaBadPasswordCount=*) " ,
attrs = [ " dnsHostName " , " lastLogon " ] )
2007-12-24 04:19:41 +03:00
self . assertEquals ( len ( res ) , 0 )
# Search by objectClass
attrs = [ " dnsHostName " , " lastLogon " , " objectClass " ]
2008-01-02 10:52:31 +03:00
res = self . ldb . search ( expression = " (objectClass=user) " , attrs = attrs )
2007-12-24 04:19:41 +03:00
self . assertEquals ( len ( res ) , 2 )
2011-06-02 04:52:06 +04:00
res = sorted ( res , key = attrgetter ( ' dn ' ) )
self . assertEquals ( str ( res [ 0 ] . dn ) , self . samba4 . dn ( " cn=A " ) )
self . assertTrue ( not " dnsHostName " in res [ 0 ] )
2008-12-21 09:34:27 +03:00
self . assertEquals ( str ( res [ 0 ] [ " lastLogon " ] ) , " x " )
self . assertEquals ( str ( res [ 0 ] [ " objectClass " ] [ 0 ] ) , " user " )
2011-06-02 04:52:06 +04:00
self . assertEquals ( str ( res [ 1 ] . dn ) , self . samba4 . dn ( " cn=X " ) )
self . assertEquals ( str ( res [ 1 ] [ " dnsHostName " ] ) , " x " )
2008-12-21 09:34:27 +03:00
self . assertEquals ( str ( res [ 1 ] [ " lastLogon " ] ) , " x " )
self . assertEquals ( str ( res [ 1 ] [ " objectClass " ] [ 0 ] ) , " user " )
2007-12-24 04:19:41 +03:00
# Prove that the objectClass is actually used for the search
2008-09-19 14:44:00 +04:00
res = self . ldb . search ( expression = " (|(objectClass=user)(badPwdCount=x)) " ,
attrs = attrs )
2007-12-24 04:19:41 +03:00
self . assertEquals ( len ( res ) , 3 )
2011-06-02 04:52:06 +04:00
res = sorted ( res , key = attrgetter ( ' dn ' ) )
self . assertEquals ( str ( res [ 0 ] . dn ) , self . samba4 . dn ( " cn=A " ) )
2008-01-02 10:52:31 +03:00
self . assertTrue ( not " dnsHostName " in res [ 0 ] )
2011-06-02 04:52:06 +04:00
self . assertEquals ( str ( res [ 0 ] [ " lastLogon " ] ) , " x " )
self . assertEquals ( res [ 0 ] [ " objectClass " ] [ 0 ] , " user " )
self . assertEquals ( str ( res [ 1 ] . dn ) , self . samba4 . dn ( " cn=B " ) )
self . assertTrue ( not " dnsHostName " in res [ 1 ] )
self . assertEquals ( str ( res [ 1 ] [ " lastLogon " ] ) , " y " )
self . assertEquals ( set ( res [ 1 ] [ " objectClass " ] ) , set ( [ " top " ] ) )
self . assertEquals ( str ( res [ 2 ] . dn ) , self . samba4 . dn ( " cn=X " ) )
self . assertEquals ( str ( res [ 2 ] [ " dnsHostName " ] ) , " x " )
2008-12-21 09:34:27 +03:00
self . assertEquals ( str ( res [ 2 ] [ " lastLogon " ] ) , " x " )
2011-06-02 04:52:06 +04:00
self . assertEquals ( str ( res [ 2 ] [ " objectClass " ] [ 0 ] ) , " user " )
2007-12-24 04:19:41 +03:00
2008-09-19 14:04:13 +04:00
# Testing search by parse tree
2007-12-24 04:19:41 +03:00
# Search by conjunction of local attributes
2008-09-19 14:44:00 +04:00
res = self . ldb . search ( expression = " (&(codePage=x)(revision=x)) " ,
attrs = [ " dnsHostName " , " lastLogon " ] )
2007-12-24 04:19:41 +03:00
self . assertEquals ( len ( res ) , 2 )
2011-06-02 04:52:06 +04:00
res = sorted ( res , key = attrgetter ( ' dn ' ) )
self . assertEquals ( str ( res [ 0 ] . dn ) , self . samba4 . dn ( " cn=X " ) )
self . assertEquals ( str ( res [ 0 ] [ " dnsHostName " ] ) , " x " )
self . assertEquals ( str ( res [ 0 ] [ " lastLogon " ] ) , " x " )
self . assertEquals ( str ( res [ 1 ] . dn ) , self . samba4 . dn ( " cn=Y " ) )
self . assertEquals ( str ( res [ 1 ] [ " dnsHostName " ] ) , " y " )
self . assertEquals ( str ( res [ 1 ] [ " lastLogon " ] ) , " y " )
2007-12-24 04:19:41 +03:00
# Search by conjunction of remote attributes
2008-09-19 14:44:00 +04:00
res = self . ldb . search ( expression = " (&(lastLogon=x)(description=x)) " ,
attrs = [ " dnsHostName " , " lastLogon " ] )
2007-12-24 04:19:41 +03:00
self . assertEquals ( len ( res ) , 2 )
2011-06-02 04:52:06 +04:00
res = sorted ( res , key = attrgetter ( ' dn ' ) )
self . assertEquals ( str ( res [ 0 ] . dn ) , self . samba4 . dn ( " cn=A " ) )
self . assertTrue ( not " dnsHostName " in res [ 0 ] )
2008-12-21 09:34:27 +03:00
self . assertEquals ( str ( res [ 0 ] [ " lastLogon " ] ) , " x " )
2011-06-02 04:52:06 +04:00
self . assertEquals ( str ( res [ 1 ] . dn ) , self . samba4 . dn ( " cn=X " ) )
self . assertEquals ( str ( res [ 1 ] [ " dnsHostName " ] ) , " x " )
2008-12-21 09:34:27 +03:00
self . assertEquals ( str ( res [ 1 ] [ " lastLogon " ] ) , " x " )
2007-12-24 04:19:41 +03:00
# Search by conjunction of local and remote attribute
2008-09-19 14:44:00 +04:00
res = self . ldb . search ( expression = " (&(codePage=x)(description=x)) " ,
attrs = [ " dnsHostName " , " lastLogon " ] )
2007-12-24 04:19:41 +03:00
self . assertEquals ( len ( res ) , 2 )
2011-06-02 04:52:06 +04:00
res = sorted ( res , key = attrgetter ( ' dn ' ) )
self . assertEquals ( str ( res [ 0 ] . dn ) , self . samba4 . dn ( " cn=X " ) )
self . assertEquals ( str ( res [ 0 ] [ " dnsHostName " ] ) , " x " )
self . assertEquals ( str ( res [ 0 ] [ " lastLogon " ] ) , " x " )
self . assertEquals ( str ( res [ 1 ] . dn ) , self . samba4 . dn ( " cn=Y " ) )
self . assertEquals ( str ( res [ 1 ] [ " dnsHostName " ] ) , " y " )
self . assertEquals ( str ( res [ 1 ] [ " lastLogon " ] ) , " y " )
2007-12-24 04:19:41 +03:00
# Search by conjunction of local and remote attribute w/o match
attrs = [ " dnsHostName " , " lastLogon " ]
2008-09-19 14:44:00 +04:00
res = self . ldb . search ( expression = " (&(codePage=x)(nextRid=x)) " ,
attrs = attrs )
2007-12-24 04:19:41 +03:00
self . assertEquals ( len ( res ) , 0 )
2008-09-19 14:44:00 +04:00
res = self . ldb . search ( expression = " (&(revision=x)(lastLogon=z)) " ,
attrs = attrs )
2007-12-24 04:19:41 +03:00
self . assertEquals ( len ( res ) , 0 )
# Search by disjunction of local attributes
2008-09-19 14:44:00 +04:00
res = self . ldb . search ( expression = " (|(revision=x)(dnsHostName=x)) " ,
attrs = [ " dnsHostName " , " lastLogon " ] )
2007-12-24 04:19:41 +03:00
self . assertEquals ( len ( res ) , 2 )
2011-06-02 04:52:06 +04:00
res = sorted ( res , key = attrgetter ( ' dn ' ) )
self . assertEquals ( str ( res [ 0 ] . dn ) , self . samba4 . dn ( " cn=X " ) )
self . assertEquals ( str ( res [ 0 ] [ " dnsHostName " ] ) , " x " )
self . assertEquals ( str ( res [ 0 ] [ " lastLogon " ] ) , " x " )
self . assertEquals ( str ( res [ 1 ] . dn ) , self . samba4 . dn ( " cn=Y " ) )
self . assertEquals ( str ( res [ 1 ] [ " dnsHostName " ] ) , " y " )
self . assertEquals ( str ( res [ 1 ] [ " lastLogon " ] ) , " y " )
2007-12-24 04:19:41 +03:00
# Search by disjunction of remote attributes
2008-09-19 14:44:00 +04:00
res = self . ldb . search ( expression = " (|(badPwdCount=x)(lastLogon=x)) " ,
attrs = [ " dnsHostName " , " lastLogon " ] )
2007-12-24 04:19:41 +03:00
self . assertEquals ( len ( res ) , 3 )
2011-06-02 04:52:06 +04:00
res = sorted ( res , key = attrgetter ( ' dn ' ) )
self . assertEquals ( str ( res [ 0 ] . dn ) , self . samba4 . dn ( " cn=A " ) )
2008-09-21 07:21:56 +04:00
self . assertFalse ( " dnsHostName " in res [ 0 ] )
2011-06-02 04:52:06 +04:00
self . assertEquals ( str ( res [ 0 ] [ " lastLogon " ] ) , " x " )
self . assertEquals ( str ( res [ 1 ] . dn ) , self . samba4 . dn ( " cn=B " ) )
self . assertFalse ( " dnsHostName " in res [ 1 ] )
self . assertEquals ( str ( res [ 1 ] [ " lastLogon " ] ) , " y " )
self . assertEquals ( str ( res [ 2 ] . dn ) , self . samba4 . dn ( " cn=X " ) )
self . assertEquals ( str ( res [ 2 ] [ " dnsHostName " ] ) , " x " )
2008-12-21 09:34:27 +03:00
self . assertEquals ( str ( res [ 2 ] [ " lastLogon " ] ) , " x " )
2007-12-24 04:19:41 +03:00
# Search by disjunction of local and remote attribute
2008-09-19 14:44:00 +04:00
res = self . ldb . search ( expression = " (|(revision=x)(lastLogon=y)) " ,
attrs = [ " dnsHostName " , " lastLogon " ] )
2007-12-24 04:19:41 +03:00
self . assertEquals ( len ( res ) , 3 )
2011-06-02 04:52:06 +04:00
res = sorted ( res , key = attrgetter ( ' dn ' ) )
self . assertEquals ( str ( res [ 0 ] . dn ) , self . samba4 . dn ( " cn=B " ) )
self . assertFalse ( " dnsHostName " in res [ 0 ] )
2008-12-21 09:34:27 +03:00
self . assertEquals ( str ( res [ 0 ] [ " lastLogon " ] ) , " y " )
2011-06-02 04:52:06 +04:00
self . assertEquals ( str ( res [ 1 ] . dn ) , self . samba4 . dn ( " cn=X " ) )
self . assertEquals ( str ( res [ 1 ] [ " dnsHostName " ] ) , " x " )
self . assertEquals ( str ( res [ 1 ] [ " lastLogon " ] ) , " x " )
self . assertEquals ( str ( res [ 2 ] . dn ) , self . samba4 . dn ( " cn=Y " ) )
self . assertEquals ( str ( res [ 2 ] [ " dnsHostName " ] ) , " y " )
self . assertEquals ( str ( res [ 2 ] [ " lastLogon " ] ) , " y " )
2007-12-24 04:19:41 +03:00
# Search by disjunction of local and remote attribute w/o match
2008-09-19 14:44:00 +04:00
res = self . ldb . search ( expression = " (|(codePage=y)(nextRid=z)) " ,
attrs = [ " dnsHostName " , " lastLogon " ] )
2007-12-24 04:19:41 +03:00
self . assertEquals ( len ( res ) , 0 )
# Search by negated local attribute
2008-09-19 14:44:00 +04:00
res = self . ldb . search ( expression = " (!(revision=x)) " ,
attrs = [ " dnsHostName " , " lastLogon " ] )
2009-10-02 14:00:42 +04:00
self . assertEquals ( len ( res ) , 6 )
2011-06-02 04:52:06 +04:00
res = sorted ( res , key = attrgetter ( ' dn ' ) )
self . assertEquals ( str ( res [ 0 ] . dn ) , self . samba4 . dn ( " cn=A " ) )
2008-01-02 10:52:31 +03:00
self . assertTrue ( not " dnsHostName " in res [ 0 ] )
2011-06-02 04:52:06 +04:00
self . assertEquals ( str ( res [ 0 ] [ " lastLogon " ] ) , " x " )
self . assertEquals ( str ( res [ 1 ] . dn ) , self . samba4 . dn ( " cn=B " ) )
2008-01-02 10:52:31 +03:00
self . assertTrue ( not " dnsHostName " in res [ 1 ] )
2011-06-02 04:52:06 +04:00
self . assertEquals ( str ( res [ 1 ] [ " lastLogon " ] ) , " y " )
self . assertEquals ( str ( res [ 2 ] . dn ) , self . samba4 . dn ( " cn=C " ) )
self . assertTrue ( not " dnsHostName " in res [ 2 ] )
2008-12-21 09:34:27 +03:00
self . assertEquals ( str ( res [ 2 ] [ " lastLogon " ] ) , " z " )
2011-06-02 04:52:06 +04:00
self . assertEquals ( str ( res [ 3 ] . dn ) , self . samba4 . dn ( " cn=Z " ) )
self . assertEquals ( str ( res [ 3 ] [ " dnsHostName " ] ) , " z " )
2008-12-21 09:34:27 +03:00
self . assertEquals ( str ( res [ 3 ] [ " lastLogon " ] ) , " z " )
2007-12-24 04:19:41 +03:00
# Search by negated remote attribute
2008-09-19 14:44:00 +04:00
res = self . ldb . search ( expression = " (!(description=x)) " ,
attrs = [ " dnsHostName " , " lastLogon " ] )
2009-10-02 14:00:42 +04:00
self . assertEquals ( len ( res ) , 4 )
2011-06-02 04:52:06 +04:00
res = sorted ( res , key = attrgetter ( ' dn ' ) )
self . assertEquals ( str ( res [ 0 ] . dn ) , self . samba4 . dn ( " cn=C " ) )
self . assertTrue ( not " dnsHostName " in res [ 0 ] )
2008-12-21 09:34:27 +03:00
self . assertEquals ( str ( res [ 0 ] [ " lastLogon " ] ) , " z " )
2011-06-02 04:52:06 +04:00
self . assertEquals ( str ( res [ 1 ] . dn ) , self . samba4 . dn ( " cn=Z " ) )
self . assertEquals ( str ( res [ 1 ] [ " dnsHostName " ] ) , " z " )
2008-12-21 09:34:27 +03:00
self . assertEquals ( str ( res [ 1 ] [ " lastLogon " ] ) , " z " )
2007-12-24 04:19:41 +03:00
# Search by negated conjunction of local attributes
2008-09-19 14:44:00 +04:00
res = self . ldb . search ( expression = " (!(&(codePage=x)(revision=x))) " ,
attrs = [ " dnsHostName " , " lastLogon " ] )
2009-10-02 14:00:42 +04:00
self . assertEquals ( len ( res ) , 6 )
2011-06-02 04:52:06 +04:00
res = sorted ( res , key = attrgetter ( ' dn ' ) )
self . assertEquals ( str ( res [ 0 ] . dn ) , self . samba4 . dn ( " cn=A " ) )
2008-01-02 10:52:31 +03:00
self . assertTrue ( not " dnsHostName " in res [ 0 ] )
2011-06-02 04:52:06 +04:00
self . assertEquals ( str ( res [ 0 ] [ " lastLogon " ] ) , " x " )
self . assertEquals ( str ( res [ 1 ] . dn ) , self . samba4 . dn ( " cn=B " ) )
2008-01-02 10:52:31 +03:00
self . assertTrue ( not " dnsHostName " in res [ 1 ] )
2011-06-02 04:52:06 +04:00
self . assertEquals ( str ( res [ 1 ] [ " lastLogon " ] ) , " y " )
self . assertEquals ( str ( res [ 2 ] . dn ) , self . samba4 . dn ( " cn=C " ) )
self . assertTrue ( not " dnsHostName " in res [ 2 ] )
2008-12-21 09:34:27 +03:00
self . assertEquals ( str ( res [ 2 ] [ " lastLogon " ] ) , " z " )
2011-06-02 04:52:06 +04:00
self . assertEquals ( str ( res [ 3 ] . dn ) , self . samba4 . dn ( " cn=Z " ) )
self . assertEquals ( str ( res [ 3 ] [ " dnsHostName " ] ) , " z " )
2008-12-21 09:34:27 +03:00
self . assertEquals ( str ( res [ 3 ] [ " lastLogon " ] ) , " z " )
2007-12-24 04:19:41 +03:00
# Search by negated conjunction of remote attributes
2008-09-19 14:44:00 +04:00
res = self . ldb . search ( expression = " (!(&(lastLogon=x)(description=x))) " ,
attrs = [ " dnsHostName " , " lastLogon " ] )
2009-10-02 14:00:42 +04:00
self . assertEquals ( len ( res ) , 6 )
2011-06-02 04:52:06 +04:00
res = sorted ( res , key = attrgetter ( ' dn ' ) )
self . assertEquals ( str ( res [ 0 ] . dn ) , self . samba4 . dn ( " cn=B " ) )
self . assertTrue ( not " dnsHostName " in res [ 0 ] )
2008-12-21 09:34:27 +03:00
self . assertEquals ( str ( res [ 0 ] [ " lastLogon " ] ) , " y " )
2011-06-02 04:52:06 +04:00
self . assertEquals ( str ( res [ 1 ] . dn ) , self . samba4 . dn ( " cn=C " ) )
2008-01-02 10:52:31 +03:00
self . assertTrue ( not " dnsHostName " in res [ 1 ] )
2011-06-02 04:52:06 +04:00
self . assertEquals ( str ( res [ 1 ] [ " lastLogon " ] ) , " z " )
self . assertEquals ( str ( res [ 2 ] . dn ) , self . samba4 . dn ( " cn=Y " ) )
self . assertEquals ( str ( res [ 2 ] [ " dnsHostName " ] ) , " y " )
self . assertEquals ( str ( res [ 2 ] [ " lastLogon " ] ) , " y " )
self . assertEquals ( str ( res [ 3 ] . dn ) , self . samba4 . dn ( " cn=Z " ) )
self . assertEquals ( str ( res [ 3 ] [ " dnsHostName " ] ) , " z " )
2008-12-21 09:34:27 +03:00
self . assertEquals ( str ( res [ 3 ] [ " lastLogon " ] ) , " z " )
2007-12-24 04:19:41 +03:00
# Search by negated conjunction of local and remote attribute
2008-09-19 14:44:00 +04:00
res = self . ldb . search ( expression = " (!(&(codePage=x)(description=x))) " ,
attrs = [ " dnsHostName " , " lastLogon " ] )
2009-10-02 14:00:42 +04:00
self . assertEquals ( len ( res ) , 6 )
2011-06-02 04:52:06 +04:00
res = sorted ( res , key = attrgetter ( ' dn ' ) )
self . assertEquals ( str ( res [ 0 ] . dn ) , self . samba4 . dn ( " cn=A " ) )
2008-01-02 10:52:31 +03:00
self . assertTrue ( not " dnsHostName " in res [ 0 ] )
2011-06-02 04:52:06 +04:00
self . assertEquals ( str ( res [ 0 ] [ " lastLogon " ] ) , " x " )
self . assertEquals ( str ( res [ 1 ] . dn ) , self . samba4 . dn ( " cn=B " ) )
2008-01-02 10:52:31 +03:00
self . assertTrue ( not " dnsHostName " in res [ 1 ] )
2011-06-02 04:52:06 +04:00
self . assertEquals ( str ( res [ 1 ] [ " lastLogon " ] ) , " y " )
self . assertEquals ( str ( res [ 2 ] . dn ) , self . samba4 . dn ( " cn=C " ) )
self . assertTrue ( not " dnsHostName " in res [ 2 ] )
2008-12-21 09:34:27 +03:00
self . assertEquals ( str ( res [ 2 ] [ " lastLogon " ] ) , " z " )
2011-06-02 04:52:06 +04:00
self . assertEquals ( str ( res [ 3 ] . dn ) , self . samba4 . dn ( " cn=Z " ) )
self . assertEquals ( str ( res [ 3 ] [ " dnsHostName " ] ) , " z " )
2008-12-21 09:34:27 +03:00
self . assertEquals ( str ( res [ 3 ] [ " lastLogon " ] ) , " z " )
2007-12-24 04:19:41 +03:00
# Search by negated disjunction of local attributes
2008-09-19 14:44:00 +04:00
res = self . ldb . search ( expression = " (!(|(revision=x)(dnsHostName=x))) " ,
attrs = [ " dnsHostName " , " lastLogon " ] )
2011-06-02 04:52:06 +04:00
res = sorted ( res , key = attrgetter ( ' dn ' ) )
self . assertEquals ( str ( res [ 0 ] . dn ) , self . samba4 . dn ( " cn=A " ) )
2008-01-02 10:52:31 +03:00
self . assertTrue ( not " dnsHostName " in res [ 0 ] )
2011-06-02 04:52:06 +04:00
self . assertEquals ( str ( res [ 0 ] [ " lastLogon " ] ) , " x " )
self . assertEquals ( str ( res [ 1 ] . dn ) , self . samba4 . dn ( " cn=B " ) )
2008-01-02 10:52:31 +03:00
self . assertTrue ( not " dnsHostName " in res [ 1 ] )
2011-06-02 04:52:06 +04:00
self . assertEquals ( str ( res [ 1 ] [ " lastLogon " ] ) , " y " )
self . assertEquals ( str ( res [ 2 ] . dn ) , self . samba4 . dn ( " cn=C " ) )
self . assertTrue ( not " dnsHostName " in res [ 2 ] )
2008-12-21 09:34:27 +03:00
self . assertEquals ( str ( res [ 2 ] [ " lastLogon " ] ) , " z " )
2011-06-02 04:52:06 +04:00
self . assertEquals ( str ( res [ 3 ] . dn ) , self . samba4 . dn ( " cn=Z " ) )
self . assertEquals ( str ( res [ 3 ] [ " dnsHostName " ] ) , " z " )
2008-12-21 09:34:27 +03:00
self . assertEquals ( str ( res [ 3 ] [ " lastLogon " ] ) , " z " )
2007-12-24 04:19:41 +03:00
# Search by negated disjunction of remote attributes
2008-09-19 14:44:00 +04:00
res = self . ldb . search ( expression = " (!(|(badPwdCount=x)(lastLogon=x))) " ,
attrs = [ " dnsHostName " , " lastLogon " ] )
2009-10-02 14:00:42 +04:00
self . assertEquals ( len ( res ) , 5 )
2011-06-02 04:52:06 +04:00
res = sorted ( res , key = attrgetter ( ' dn ' ) )
self . assertEquals ( str ( res [ 0 ] . dn ) , self . samba4 . dn ( " cn=C " ) )
self . assertTrue ( not " dnsHostName " in res [ 0 ] )
self . assertEquals ( str ( res [ 0 ] [ " lastLogon " ] ) , " z " )
self . assertEquals ( str ( res [ 1 ] . dn ) , self . samba4 . dn ( " cn=Y " ) )
self . assertEquals ( str ( res [ 1 ] [ " dnsHostName " ] ) , " y " )
self . assertEquals ( str ( res [ 1 ] [ " lastLogon " ] ) , " y " )
self . assertEquals ( str ( res [ 2 ] . dn ) , self . samba4 . dn ( " cn=Z " ) )
self . assertEquals ( str ( res [ 2 ] [ " dnsHostName " ] ) , " z " )
2008-12-21 09:34:27 +03:00
self . assertEquals ( str ( res [ 2 ] [ " lastLogon " ] ) , " z " )
2007-12-24 04:19:41 +03:00
# Search by negated disjunction of local and remote attribute
2008-09-19 01:46:58 +04:00
res = self . ldb . search ( expression = " (!(|(revision=x)(lastLogon=y))) " ,
attrs = [ " dnsHostName " , " lastLogon " ] )
2009-10-02 14:00:42 +04:00
self . assertEquals ( len ( res ) , 5 )
2011-06-02 04:52:06 +04:00
res = sorted ( res , key = attrgetter ( ' dn ' ) )
2008-01-02 10:52:31 +03:00
self . assertEquals ( str ( res [ 0 ] . dn ) , self . samba4 . dn ( " cn=A " ) )
self . assertTrue ( not " dnsHostName " in res [ 0 ] )
2008-12-21 09:34:27 +03:00
self . assertEquals ( str ( res [ 0 ] [ " lastLogon " ] ) , " x " )
2011-06-02 04:52:06 +04:00
self . assertEquals ( str ( res [ 1 ] . dn ) , self . samba4 . dn ( " cn=C " ) )
self . assertTrue ( not " dnsHostName " in res [ 1 ] )
2008-12-21 09:34:27 +03:00
self . assertEquals ( str ( res [ 1 ] [ " lastLogon " ] ) , " z " )
2011-06-02 04:52:06 +04:00
self . assertEquals ( str ( res [ 2 ] . dn ) , self . samba4 . dn ( " cn=Z " ) )
self . assertEquals ( str ( res [ 2 ] [ " dnsHostName " ] ) , " z " )
2008-12-21 09:34:27 +03:00
self . assertEquals ( str ( res [ 2 ] [ " lastLogon " ] ) , " z " )
2007-12-24 04:19:41 +03:00
2008-09-19 14:04:13 +04:00
# Search by complex parse tree
2008-09-19 01:46:58 +04:00
res = self . ldb . search ( expression = " (|(&(revision=x)(dnsHostName=x))(!(&(description=x)(nextRid=y)))(badPwdCount=y)) " , attrs = [ " dnsHostName " , " lastLogon " ] )
2009-10-02 14:00:42 +04:00
self . assertEquals ( len ( res ) , 7 )
2011-06-02 04:52:06 +04:00
res = sorted ( res , key = attrgetter ( ' dn ' ) )
self . assertEquals ( str ( res [ 0 ] . dn ) , self . samba4 . dn ( " cn=A " ) )
2008-01-02 10:52:31 +03:00
self . assertTrue ( not " dnsHostName " in res [ 0 ] )
2011-06-02 04:52:06 +04:00
self . assertEquals ( str ( res [ 0 ] [ " lastLogon " ] ) , " x " )
self . assertEquals ( str ( res [ 1 ] . dn ) , self . samba4 . dn ( " cn=B " ) )
self . assertTrue ( not " dnsHostName " in res [ 1 ] )
self . assertEquals ( str ( res [ 1 ] [ " lastLogon " ] ) , " y " )
self . assertEquals ( str ( res [ 2 ] . dn ) , self . samba4 . dn ( " cn=C " ) )
2008-01-02 10:52:31 +03:00
self . assertTrue ( not " dnsHostName " in res [ 2 ] )
2011-06-02 04:52:06 +04:00
self . assertEquals ( str ( res [ 2 ] [ " lastLogon " ] ) , " z " )
self . assertEquals ( str ( res [ 3 ] . dn ) , self . samba4 . dn ( " cn=X " ) )
self . assertEquals ( str ( res [ 3 ] [ " dnsHostName " ] ) , " x " )
self . assertEquals ( str ( res [ 3 ] [ " lastLogon " ] ) , " x " )
self . assertEquals ( str ( res [ 4 ] . dn ) , self . samba4 . dn ( " cn=Z " ) )
self . assertEquals ( str ( res [ 4 ] [ " dnsHostName " ] ) , " z " )
2008-12-21 09:34:27 +03:00
self . assertEquals ( str ( res [ 4 ] [ " lastLogon " ] ) , " z " )
2007-12-24 04:19:41 +03:00
# Clean up
2008-01-02 10:52:31 +03:00
dns = [ self . samba4 . dn ( " cn= %s " % n ) for n in [ " A " , " B " , " C " , " X " , " Y " , " Z " ] ]
2007-12-24 04:19:41 +03:00
for dn in dns :
2008-01-02 10:52:31 +03:00
self . ldb . delete ( dn )
2007-12-24 04:19:41 +03:00
2007-12-31 01:46:05 +03:00
def test_map_modify_local ( self ) :
""" Modification of local records. """
2007-12-24 04:19:41 +03:00
# Add local record
dn = " cn=test,dc=idealx,dc=org "
2008-01-02 10:52:31 +03:00
self . ldb . add ( { " dn " : dn ,
2007-12-31 01:46:05 +03:00
" cn " : " test " ,
" foo " : " bar " ,
" revision " : " 1 " ,
" description " : " test " } )
2007-12-24 04:19:41 +03:00
# Check it's there
attrs = [ " foo " , " revision " , " description " ]
2008-01-02 10:52:31 +03:00
res = self . ldb . search ( dn , scope = SCOPE_BASE , attrs = attrs )
2007-12-24 04:19:41 +03:00
self . assertEquals ( len ( res ) , 1 )
self . assertEquals ( str ( res [ 0 ] . dn ) , dn )
2008-12-21 09:34:27 +03:00
self . assertEquals ( str ( res [ 0 ] [ " foo " ] ) , " bar " )
self . assertEquals ( str ( res [ 0 ] [ " revision " ] ) , " 1 " )
self . assertEquals ( str ( res [ 0 ] [ " description " ] ) , " test " )
2007-12-24 04:19:41 +03:00
# Check it's not in the local db
2008-09-19 14:04:13 +04:00
res = self . samba4 . db . search ( expression = " (cn=test) " ,
scope = SCOPE_DEFAULT , attrs = attrs )
2007-12-24 04:19:41 +03:00
self . assertEquals ( len ( res ) , 0 )
# Check it's not in the remote db
2008-09-19 14:04:13 +04:00
res = self . samba3 . db . search ( expression = " (cn=test) " ,
scope = SCOPE_DEFAULT , attrs = attrs )
2007-12-24 04:19:41 +03:00
self . assertEquals ( len ( res ) , 0 )
# Modify local record
ldif = """
dn : """ + dn + """
replace : foo
foo : baz
replace : description
description : foo
"""
2008-01-02 10:52:31 +03:00
self . ldb . modify_ldif ( ldif )
2007-12-24 04:19:41 +03:00
# Check in local db
2008-01-02 10:52:31 +03:00
res = self . ldb . search ( dn , scope = SCOPE_BASE , attrs = attrs )
2007-12-24 04:19:41 +03:00
self . assertEquals ( len ( res ) , 1 )
self . assertEquals ( str ( res [ 0 ] . dn ) , dn )
2008-12-21 09:34:27 +03:00
self . assertEquals ( str ( res [ 0 ] [ " foo " ] ) , " baz " )
self . assertEquals ( str ( res [ 0 ] [ " revision " ] ) , " 1 " )
self . assertEquals ( str ( res [ 0 ] [ " description " ] ) , " foo " )
2007-12-24 04:19:41 +03:00
# Rename local record
dn2 = " cn=toast,dc=idealx,dc=org "
2008-01-02 10:52:31 +03:00
self . ldb . rename ( dn , dn2 )
2007-12-24 04:19:41 +03:00
# Check in local db
2008-01-02 10:52:31 +03:00
res = self . ldb . search ( dn2 , scope = SCOPE_BASE , attrs = attrs )
2007-12-24 04:19:41 +03:00
self . assertEquals ( len ( res ) , 1 )
self . assertEquals ( str ( res [ 0 ] . dn ) , dn2 )
2008-12-21 09:34:27 +03:00
self . assertEquals ( str ( res [ 0 ] [ " foo " ] ) , " baz " )
self . assertEquals ( str ( res [ 0 ] [ " revision " ] ) , " 1 " )
self . assertEquals ( str ( res [ 0 ] [ " description " ] ) , " foo " )
2007-12-24 04:19:41 +03:00
# Delete local record
2008-01-02 10:52:31 +03:00
self . ldb . delete ( dn2 )
2007-12-24 04:19:41 +03:00
# Check it's gone
2008-01-02 10:52:31 +03:00
res = self . ldb . search ( dn2 , scope = SCOPE_BASE )
2007-12-24 04:19:41 +03:00
self . assertEquals ( len ( res ) , 0 )
2007-12-31 01:46:05 +03:00
def test_map_modify_remote_remote ( self ) :
""" Modification of remote data of remote records """
2007-12-24 04:19:41 +03:00
# Add remote record
2008-01-02 10:52:31 +03:00
dn = self . samba4 . dn ( " cn=test " )
dn2 = self . samba3 . dn ( " cn=test " )
self . samba3 . db . add ( { " dn " : dn2 ,
2007-12-31 01:46:05 +03:00
" cn " : " test " ,
" description " : " foo " ,
" sambaBadPasswordCount " : " 3 " ,
" sambaNextRid " : " 1001 " } )
2007-12-24 04:19:41 +03:00
# Check it's there
2008-09-19 01:46:58 +04:00
res = self . samba3 . db . search ( dn2 , scope = SCOPE_BASE ,
attrs = [ " description " , " sambaBadPasswordCount " , " sambaNextRid " ] )
2007-12-24 04:19:41 +03:00
self . assertEquals ( len ( res ) , 1 )
self . assertEquals ( str ( res [ 0 ] . dn ) , dn2 )
2008-12-21 09:34:27 +03:00
self . assertEquals ( str ( res [ 0 ] [ " description " ] ) , " foo " )
self . assertEquals ( str ( res [ 0 ] [ " sambaBadPasswordCount " ] ) , " 3 " )
self . assertEquals ( str ( res [ 0 ] [ " sambaNextRid " ] ) , " 1001 " )
2007-12-24 04:19:41 +03:00
# Check in mapped db
attrs = [ " description " , " badPwdCount " , " nextRid " ]
2008-09-20 16:35:21 +04:00
res = self . ldb . search ( dn , scope = SCOPE_BASE , attrs = attrs , expression = " " )
2007-12-24 04:19:41 +03:00
self . assertEquals ( len ( res ) , 1 )
self . assertEquals ( str ( res [ 0 ] . dn ) , dn )
2008-12-21 09:34:27 +03:00
self . assertEquals ( str ( res [ 0 ] [ " description " ] ) , " foo " )
self . assertEquals ( str ( res [ 0 ] [ " badPwdCount " ] ) , " 3 " )
self . assertEquals ( str ( res [ 0 ] [ " nextRid " ] ) , " 1001 " )
2007-12-24 04:19:41 +03:00
# Check in local db
2008-01-02 10:52:31 +03:00
res = self . samba4 . db . search ( dn , scope = SCOPE_BASE , attrs = attrs )
2007-12-24 04:19:41 +03:00
self . assertEquals ( len ( res ) , 0 )
# Modify remote data of remote record
ldif = """
dn : """ + dn + """
replace : description
description : test
replace : badPwdCount
badPwdCount : 4
"""
2008-01-02 10:52:31 +03:00
self . ldb . modify_ldif ( ldif )
2007-12-24 04:19:41 +03:00
# Check in mapped db
2008-09-19 01:46:58 +04:00
res = self . ldb . search ( dn , scope = SCOPE_BASE ,
attrs = [ " description " , " badPwdCount " , " nextRid " ] )
2007-12-24 04:19:41 +03:00
self . assertEquals ( len ( res ) , 1 )
self . assertEquals ( str ( res [ 0 ] . dn ) , dn )
2008-12-21 09:34:27 +03:00
self . assertEquals ( str ( res [ 0 ] [ " description " ] ) , " test " )
self . assertEquals ( str ( res [ 0 ] [ " badPwdCount " ] ) , " 4 " )
self . assertEquals ( str ( res [ 0 ] [ " nextRid " ] ) , " 1001 " )
2007-12-24 04:19:41 +03:00
# Check in remote db
2008-09-19 01:46:58 +04:00
res = self . samba3 . db . search ( dn2 , scope = SCOPE_BASE ,
attrs = [ " description " , " sambaBadPasswordCount " , " sambaNextRid " ] )
2007-12-24 04:19:41 +03:00
self . assertEquals ( len ( res ) , 1 )
self . assertEquals ( str ( res [ 0 ] . dn ) , dn2 )
2008-12-21 09:34:27 +03:00
self . assertEquals ( str ( res [ 0 ] [ " description " ] ) , " test " )
self . assertEquals ( str ( res [ 0 ] [ " sambaBadPasswordCount " ] ) , " 4 " )
self . assertEquals ( str ( res [ 0 ] [ " sambaNextRid " ] ) , " 1001 " )
2007-12-24 04:19:41 +03:00
# Rename remote record
2008-01-02 10:52:31 +03:00
dn2 = self . samba4 . dn ( " cn=toast " )
self . ldb . rename ( dn , dn2 )
2007-12-24 04:19:41 +03:00
# Check in mapped db
dn = dn2
2008-09-19 01:46:58 +04:00
res = self . ldb . search ( dn , scope = SCOPE_BASE ,
attrs = [ " description " , " badPwdCount " , " nextRid " ] )
2007-12-24 04:19:41 +03:00
self . assertEquals ( len ( res ) , 1 )
self . assertEquals ( str ( res [ 0 ] . dn ) , dn )
2008-12-21 09:34:27 +03:00
self . assertEquals ( str ( res [ 0 ] [ " description " ] ) , " test " )
self . assertEquals ( str ( res [ 0 ] [ " badPwdCount " ] ) , " 4 " )
self . assertEquals ( str ( res [ 0 ] [ " nextRid " ] ) , " 1001 " )
2007-12-24 04:19:41 +03:00
# Check in remote db
2008-01-02 10:52:31 +03:00
dn2 = self . samba3 . dn ( " cn=toast " )
2008-09-19 01:46:58 +04:00
res = self . samba3 . db . search ( dn2 , scope = SCOPE_BASE ,
attrs = [ " description " , " sambaBadPasswordCount " , " sambaNextRid " ] )
2007-12-24 04:19:41 +03:00
self . assertEquals ( len ( res ) , 1 )
self . assertEquals ( str ( res [ 0 ] . dn ) , dn2 )
2008-12-21 09:34:27 +03:00
self . assertEquals ( str ( res [ 0 ] [ " description " ] ) , " test " )
self . assertEquals ( str ( res [ 0 ] [ " sambaBadPasswordCount " ] ) , " 4 " )
self . assertEquals ( str ( res [ 0 ] [ " sambaNextRid " ] ) , " 1001 " )
2007-12-24 04:19:41 +03:00
# Delete remote record
2008-01-02 10:52:31 +03:00
self . ldb . delete ( dn )
2008-09-19 00:56:58 +04:00
# Check in mapped db that it's removed
2008-01-02 10:52:31 +03:00
res = self . ldb . search ( dn , scope = SCOPE_BASE )
2007-12-24 04:19:41 +03:00
self . assertEquals ( len ( res ) , 0 )
# Check in remote db
2008-01-02 10:52:31 +03:00
res = self . samba3 . db . search ( dn2 , scope = SCOPE_BASE )
2007-12-24 04:19:41 +03:00
self . assertEquals ( len ( res ) , 0 )
2007-12-31 01:46:05 +03:00
def test_map_modify_remote_local ( self ) :
""" Modification of local data of remote records """
2007-12-24 04:19:41 +03:00
# Add remote record (same as before)
2008-01-02 10:52:31 +03:00
dn = self . samba4 . dn ( " cn=test " )
dn2 = self . samba3 . dn ( " cn=test " )
self . samba3 . db . add ( { " dn " : dn2 ,
2007-12-31 01:46:05 +03:00
" cn " : " test " ,
" description " : " foo " ,
" sambaBadPasswordCount " : " 3 " ,
" sambaNextRid " : " 1001 " } )
2007-12-24 04:19:41 +03:00
# Modify local data of remote record
ldif = """
dn : """ + dn + """
add : revision
revision : 1
replace : description
description : test
2008-09-19 00:56:58 +04:00
2007-12-24 04:19:41 +03:00
"""
2008-01-02 10:52:31 +03:00
self . ldb . modify_ldif ( ldif )
2007-12-24 04:19:41 +03:00
# Check in mapped db
attrs = [ " revision " , " description " ]
2008-01-02 10:52:31 +03:00
res = self . ldb . search ( dn , scope = SCOPE_BASE , attrs = attrs )
2007-12-24 04:19:41 +03:00
self . assertEquals ( len ( res ) , 1 )
self . assertEquals ( str ( res [ 0 ] . dn ) , dn )
2008-12-21 09:34:27 +03:00
self . assertEquals ( str ( res [ 0 ] [ " description " ] ) , " test " )
self . assertEquals ( str ( res [ 0 ] [ " revision " ] ) , " 1 " )
2007-12-24 04:19:41 +03:00
# Check in remote db
2008-01-02 10:52:31 +03:00
res = self . samba3 . db . search ( dn2 , scope = SCOPE_BASE , attrs = attrs )
2007-12-24 04:19:41 +03:00
self . assertEquals ( len ( res ) , 1 )
self . assertEquals ( str ( res [ 0 ] . dn ) , dn2 )
2008-12-21 09:34:27 +03:00
self . assertEquals ( str ( res [ 0 ] [ " description " ] ) , " test " )
2008-01-02 10:52:31 +03:00
self . assertTrue ( not " revision " in res [ 0 ] )
2007-12-24 04:19:41 +03:00
# Check in local db
2008-01-02 10:52:31 +03:00
res = self . samba4 . db . search ( dn , scope = SCOPE_BASE , attrs = attrs )
2007-12-24 04:19:41 +03:00
self . assertEquals ( len ( res ) , 1 )
self . assertEquals ( str ( res [ 0 ] . dn ) , dn )
2008-01-02 10:52:31 +03:00
self . assertTrue ( not " description " in res [ 0 ] )
2008-12-21 09:34:27 +03:00
self . assertEquals ( str ( res [ 0 ] [ " revision " ] ) , " 1 " )
2007-12-24 04:19:41 +03:00
# Delete (newly) split record
2008-01-02 10:52:31 +03:00
self . ldb . delete ( dn )
2007-12-24 04:19:41 +03:00
2007-12-31 01:46:05 +03:00
def test_map_modify_split ( self ) :
""" Testing modification of split records """
2007-12-24 04:19:41 +03:00
# Add split record
2008-01-02 10:52:31 +03:00
dn = self . samba4 . dn ( " cn=test " )
dn2 = self . samba3 . dn ( " cn=test " )
self . ldb . add ( {
2007-12-31 01:46:05 +03:00
" dn " : dn ,
" cn " : " test " ,
" description " : " foo " ,
" badPwdCount " : " 3 " ,
" nextRid " : " 1001 " ,
" revision " : " 1 " } )
2007-12-24 04:19:41 +03:00
# Check it's there
attrs = [ " description " , " badPwdCount " , " nextRid " , " revision " ]
2008-01-02 10:52:31 +03:00
res = self . ldb . search ( dn , scope = SCOPE_BASE , attrs = attrs )
2007-12-24 04:19:41 +03:00
self . assertEquals ( len ( res ) , 1 )
self . assertEquals ( str ( res [ 0 ] . dn ) , dn )
2008-12-21 09:34:27 +03:00
self . assertEquals ( str ( res [ 0 ] [ " description " ] ) , " foo " )
self . assertEquals ( str ( res [ 0 ] [ " badPwdCount " ] ) , " 3 " )
self . assertEquals ( str ( res [ 0 ] [ " nextRid " ] ) , " 1001 " )
self . assertEquals ( str ( res [ 0 ] [ " revision " ] ) , " 1 " )
2007-12-24 04:19:41 +03:00
# Check in local db
2008-01-02 10:52:31 +03:00
res = self . samba4 . db . search ( dn , scope = SCOPE_BASE , attrs = attrs )
2007-12-24 04:19:41 +03:00
self . assertEquals ( len ( res ) , 1 )
self . assertEquals ( str ( res [ 0 ] . dn ) , dn )
2008-01-02 10:52:31 +03:00
self . assertTrue ( not " description " in res [ 0 ] )
self . assertTrue ( not " badPwdCount " in res [ 0 ] )
self . assertTrue ( not " nextRid " in res [ 0 ] )
2008-12-21 09:34:27 +03:00
self . assertEquals ( str ( res [ 0 ] [ " revision " ] ) , " 1 " )
2007-12-24 04:19:41 +03:00
# Check in remote db
2008-09-19 14:44:00 +04:00
attrs = [ " description " , " sambaBadPasswordCount " , " sambaNextRid " ,
" revision " ]
2008-01-02 10:52:31 +03:00
res = self . samba3 . db . search ( dn2 , scope = SCOPE_BASE , attrs = attrs )
2007-12-24 04:19:41 +03:00
self . assertEquals ( len ( res ) , 1 )
self . assertEquals ( str ( res [ 0 ] . dn ) , dn2 )
2008-12-21 09:34:27 +03:00
self . assertEquals ( str ( res [ 0 ] [ " description " ] ) , " foo " )
self . assertEquals ( str ( res [ 0 ] [ " sambaBadPasswordCount " ] ) , " 3 " )
self . assertEquals ( str ( res [ 0 ] [ " sambaNextRid " ] ) , " 1001 " )
2008-01-02 10:52:31 +03:00
self . assertTrue ( not " revision " in res [ 0 ] )
2007-12-24 04:19:41 +03:00
# Modify of split record
ldif = """
dn : """ + dn + """
replace : description
description : test
replace : badPwdCount
badPwdCount : 4
replace : revision
revision : 2
"""
2008-01-02 10:52:31 +03:00
self . ldb . modify_ldif ( ldif )
2007-12-24 04:19:41 +03:00
# Check in mapped db
attrs = [ " description " , " badPwdCount " , " nextRid " , " revision " ]
2008-01-02 10:52:31 +03:00
res = self . ldb . search ( dn , scope = SCOPE_BASE , attrs = attrs )
2007-12-24 04:19:41 +03:00
self . assertEquals ( len ( res ) , 1 )
self . assertEquals ( str ( res [ 0 ] . dn ) , dn )
2008-12-21 09:34:27 +03:00
self . assertEquals ( str ( res [ 0 ] [ " description " ] ) , " test " )
self . assertEquals ( str ( res [ 0 ] [ " badPwdCount " ] ) , " 4 " )
self . assertEquals ( str ( res [ 0 ] [ " nextRid " ] ) , " 1001 " )
self . assertEquals ( str ( res [ 0 ] [ " revision " ] ) , " 2 " )
2007-12-24 04:19:41 +03:00
# Check in local db
2008-01-02 10:52:31 +03:00
res = self . samba4 . db . search ( dn , scope = SCOPE_BASE , attrs = attrs )
2007-12-24 04:19:41 +03:00
self . assertEquals ( len ( res ) , 1 )
self . assertEquals ( str ( res [ 0 ] . dn ) , dn )
2008-01-02 10:52:31 +03:00
self . assertTrue ( not " description " in res [ 0 ] )
self . assertTrue ( not " badPwdCount " in res [ 0 ] )
self . assertTrue ( not " nextRid " in res [ 0 ] )
2008-12-21 09:34:27 +03:00
self . assertEquals ( str ( res [ 0 ] [ " revision " ] ) , " 2 " )
2007-12-24 04:19:41 +03:00
# Check in remote db
2008-09-19 14:44:00 +04:00
attrs = [ " description " , " sambaBadPasswordCount " , " sambaNextRid " ,
" revision " ]
2008-01-02 10:52:31 +03:00
res = self . samba3 . db . search ( dn2 , scope = SCOPE_BASE , attrs = attrs )
2007-12-24 04:19:41 +03:00
self . assertEquals ( len ( res ) , 1 )
self . assertEquals ( str ( res [ 0 ] . dn ) , dn2 )
2008-12-21 09:34:27 +03:00
self . assertEquals ( str ( res [ 0 ] [ " description " ] ) , " test " )
self . assertEquals ( str ( res [ 0 ] [ " sambaBadPasswordCount " ] ) , " 4 " )
self . assertEquals ( str ( res [ 0 ] [ " sambaNextRid " ] ) , " 1001 " )
2008-01-02 10:52:31 +03:00
self . assertTrue ( not " revision " in res [ 0 ] )
2007-12-24 04:19:41 +03:00
# Rename split record
2008-01-02 10:52:31 +03:00
dn2 = self . samba4 . dn ( " cn=toast " )
self . ldb . rename ( dn , dn2 )
2007-12-24 04:19:41 +03:00
# Check in mapped db
dn = dn2
attrs = [ " description " , " badPwdCount " , " nextRid " , " revision " ]
2008-01-02 10:52:31 +03:00
res = self . ldb . search ( dn , scope = SCOPE_BASE , attrs = attrs )
2007-12-24 04:19:41 +03:00
self . assertEquals ( len ( res ) , 1 )
self . assertEquals ( str ( res [ 0 ] . dn ) , dn )
2008-12-21 09:34:27 +03:00
self . assertEquals ( str ( res [ 0 ] [ " description " ] ) , " test " )
self . assertEquals ( str ( res [ 0 ] [ " badPwdCount " ] ) , " 4 " )
self . assertEquals ( str ( res [ 0 ] [ " nextRid " ] ) , " 1001 " )
self . assertEquals ( str ( res [ 0 ] [ " revision " ] ) , " 2 " )
2007-12-24 04:19:41 +03:00
# Check in local db
2008-01-02 10:52:31 +03:00
res = self . samba4 . db . search ( dn , scope = SCOPE_BASE , attrs = attrs )
2007-12-24 04:19:41 +03:00
self . assertEquals ( len ( res ) , 1 )
self . assertEquals ( str ( res [ 0 ] . dn ) , dn )
2008-01-02 10:52:31 +03:00
self . assertTrue ( not " description " in res [ 0 ] )
self . assertTrue ( not " badPwdCount " in res [ 0 ] )
self . assertTrue ( not " nextRid " in res [ 0 ] )
2008-12-21 09:34:27 +03:00
self . assertEquals ( str ( res [ 0 ] [ " revision " ] ) , " 2 " )
2007-12-24 04:19:41 +03:00
# Check in remote db
2008-01-02 10:52:31 +03:00
dn2 = self . samba3 . dn ( " cn=toast " )
2008-09-19 14:44:00 +04:00
res = self . samba3 . db . search ( dn2 , scope = SCOPE_BASE ,
attrs = [ " description " , " sambaBadPasswordCount " , " sambaNextRid " ,
2008-09-20 16:35:21 +04:00
" revision " ] )
2007-12-24 04:19:41 +03:00
self . assertEquals ( len ( res ) , 1 )
self . assertEquals ( str ( res [ 0 ] . dn ) , dn2 )
2008-12-21 09:34:27 +03:00
self . assertEquals ( str ( res [ 0 ] [ " description " ] ) , " test " )
self . assertEquals ( str ( res [ 0 ] [ " sambaBadPasswordCount " ] ) , " 4 " )
self . assertEquals ( str ( res [ 0 ] [ " sambaNextRid " ] ) , " 1001 " )
2008-01-02 10:52:31 +03:00
self . assertTrue ( not " revision " in res [ 0 ] )
2007-12-24 04:19:41 +03:00
# Delete split record
2008-01-02 10:52:31 +03:00
self . ldb . delete ( dn )
2007-12-24 04:19:41 +03:00
# Check in mapped db
2008-01-02 10:52:31 +03:00
res = self . ldb . search ( dn , scope = SCOPE_BASE )
2007-12-24 04:19:41 +03:00
self . assertEquals ( len ( res ) , 0 )
# Check in local db
2008-01-02 10:52:31 +03:00
res = self . samba4 . db . search ( dn , scope = SCOPE_BASE )
2007-12-24 04:19:41 +03:00
self . assertEquals ( len ( res ) , 0 )
# Check in remote db
2008-01-02 10:52:31 +03:00
res = self . samba3 . db . search ( dn2 , scope = SCOPE_BASE )
2007-12-24 04:19:41 +03:00
self . assertEquals ( len ( res ) , 0 )