2004-05-02 10:06:45 +00:00
/*
ldb database library
Copyright ( C ) Andrew Tridgell 2004
* * NOTE ! The following LGPL license applies to the ldb
* * library . This does NOT imply that all of Samba is released
* * under the LGPL
This library is free software ; you can redistribute it and / or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation ; either
2007-07-10 02:46:15 +00:00
version 3 of the License , or ( at your option ) any later version .
2004-05-02 10:06:45 +00:00
This library 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
Lesser General Public License for more details .
You should have received a copy of the GNU Lesser General Public
2007-07-10 03:42:26 +00:00
License along with this library ; if not , see < http : //www.gnu.org/licenses/>.
2004-05-02 10:06:45 +00:00
*/
/*
* Name : ldb
*
* Component : ldbtest
*
* Description : utility to test ldb
*
* Author : Andrew Tridgell
*/
2010-11-01 23:36:42 +11:00
# include "replace.h"
# include "system/filesys.h"
# include "system/time.h"
2009-01-29 18:39:30 -05:00
# include "ldb.h"
2007-05-05 18:50:56 +00:00
# include "tools/cmdline.h"
2004-05-02 10:06:45 +00:00
2010-08-30 18:54:42 +02:00
static struct timespec tp1 , tp2 ;
2005-06-18 07:42:21 +00:00
static struct ldb_cmdline * options ;
2004-05-02 10:06:45 +00:00
2004-10-20 19:21:10 +00:00
static void _start_timer ( void )
2004-05-02 10:06:45 +00:00
{
2010-09-01 11:22:09 +02:00
if ( clock_gettime ( CUSTOM_CLOCK_MONOTONIC , & tp1 ) ! = 0 ) {
clock_gettime ( CLOCK_REALTIME , & tp1 ) ;
}
2004-05-02 10:06:45 +00:00
}
2004-10-20 19:21:10 +00:00
static double _end_timer ( void )
2004-05-02 10:06:45 +00:00
{
2010-09-01 11:22:09 +02:00
if ( clock_gettime ( CUSTOM_CLOCK_MONOTONIC , & tp2 ) ! = 0 ) {
clock_gettime ( CLOCK_REALTIME , & tp2 ) ;
}
2004-05-02 10:06:45 +00:00
return ( ( tp2 . tv_sec - tp1 . tv_sec ) +
2010-08-30 18:54:42 +02:00
( tp2 . tv_nsec - tp1 . tv_nsec ) * 1.0e-9 ) ;
2004-05-02 10:06:45 +00:00
}
static void add_records ( struct ldb_context * ldb ,
2006-11-22 00:59:34 +00:00
struct ldb_dn * basedn ,
2009-11-06 18:35:17 +01:00
unsigned int count )
2004-05-02 10:06:45 +00:00
{
struct ldb_message msg ;
2009-11-06 18:35:17 +01:00
unsigned int i ;
2004-05-02 10:06:45 +00:00
2005-09-17 19:25:50 +00:00
#if 0
2005-06-22 02:39:07 +00:00
if ( ldb_lock ( ldb , " transaction " ) ! = 0 ) {
printf ( " transaction lock failed \n " ) ;
2011-03-02 22:28:27 +01:00
exit ( LDB_ERR_OPERATIONS_ERROR ) ;
2005-06-22 02:39:07 +00:00
}
2005-09-17 19:25:50 +00:00
# endif
2004-05-02 10:06:45 +00:00
for ( i = 0 ; i < count ; i + + ) {
struct ldb_message_element el [ 6 ] ;
struct ldb_val vals [ 6 ] [ 1 ] ;
char * name ;
2005-06-18 07:42:21 +00:00
TALLOC_CTX * tmp_ctx = talloc_new ( ldb ) ;
2004-05-07 23:54:41 +00:00
2006-08-23 10:55:20 +00:00
name = talloc_asprintf ( tmp_ctx , " Test%d " , i ) ;
2004-05-02 10:06:45 +00:00
2006-11-22 00:59:34 +00:00
msg . dn = ldb_dn_copy ( tmp_ctx , basedn ) ;
ldb_dn_add_child_fmt ( msg . dn , " cn=%s " , name ) ;
2004-05-02 10:06:45 +00:00
msg . num_elements = 6 ;
msg . elements = el ;
el [ 0 ] . flags = 0 ;
2005-06-18 07:42:21 +00:00
el [ 0 ] . name = talloc_strdup ( tmp_ctx , " cn " ) ;
2004-05-02 10:06:45 +00:00
el [ 0 ] . num_values = 1 ;
el [ 0 ] . values = vals [ 0 ] ;
2005-10-12 06:10:23 +00:00
vals [ 0 ] [ 0 ] . data = ( uint8_t * ) name ;
2004-05-02 10:06:45 +00:00
vals [ 0 ] [ 0 ] . length = strlen ( name ) ;
el [ 1 ] . flags = 0 ;
2005-10-12 06:10:23 +00:00
el [ 1 ] . name = " title " ;
2004-05-02 10:06:45 +00:00
el [ 1 ] . num_values = 1 ;
el [ 1 ] . values = vals [ 1 ] ;
2005-10-12 06:10:23 +00:00
vals [ 1 ] [ 0 ] . data = ( uint8_t * ) talloc_asprintf ( tmp_ctx , " The title of %s " , name ) ;
vals [ 1 ] [ 0 ] . length = strlen ( ( char * ) vals [ 1 ] [ 0 ] . data ) ;
2004-05-02 10:06:45 +00:00
el [ 2 ] . flags = 0 ;
2005-06-18 07:42:21 +00:00
el [ 2 ] . name = talloc_strdup ( tmp_ctx , " uid " ) ;
2004-05-02 10:06:45 +00:00
el [ 2 ] . num_values = 1 ;
el [ 2 ] . values = vals [ 2 ] ;
2008-08-22 17:36:56 +10:00
vals [ 2 ] [ 0 ] . data = ( uint8_t * ) ldb_casefold ( ldb , tmp_ctx , name , strlen ( name ) ) ;
2005-10-12 06:10:23 +00:00
vals [ 2 ] [ 0 ] . length = strlen ( ( char * ) vals [ 2 ] [ 0 ] . data ) ;
2004-05-02 10:06:45 +00:00
el [ 3 ] . flags = 0 ;
2005-06-18 07:42:21 +00:00
el [ 3 ] . name = talloc_strdup ( tmp_ctx , " mail " ) ;
2004-05-02 10:06:45 +00:00
el [ 3 ] . num_values = 1 ;
el [ 3 ] . values = vals [ 3 ] ;
2005-10-12 06:10:23 +00:00
vals [ 3 ] [ 0 ] . data = ( uint8_t * ) talloc_asprintf ( tmp_ctx , " %s@example.com " , name ) ;
vals [ 3 ] [ 0 ] . length = strlen ( ( char * ) vals [ 3 ] [ 0 ] . data ) ;
2004-05-02 10:06:45 +00:00
el [ 4 ] . flags = 0 ;
2005-06-18 07:42:21 +00:00
el [ 4 ] . name = talloc_strdup ( tmp_ctx , " objectClass " ) ;
2004-05-02 10:06:45 +00:00
el [ 4 ] . num_values = 1 ;
el [ 4 ] . values = vals [ 4 ] ;
2005-10-12 06:10:23 +00:00
vals [ 4 ] [ 0 ] . data = ( uint8_t * ) talloc_strdup ( tmp_ctx , " OpenLDAPperson " ) ;
vals [ 4 ] [ 0 ] . length = strlen ( ( char * ) vals [ 4 ] [ 0 ] . data ) ;
2004-05-02 10:06:45 +00:00
el [ 5 ] . flags = 0 ;
2005-06-18 07:42:21 +00:00
el [ 5 ] . name = talloc_strdup ( tmp_ctx , " sn " ) ;
2004-05-02 10:06:45 +00:00
el [ 5 ] . num_values = 1 ;
el [ 5 ] . values = vals [ 5 ] ;
2005-10-12 06:10:23 +00:00
vals [ 5 ] [ 0 ] . data = ( uint8_t * ) name ;
vals [ 5 ] [ 0 ] . length = strlen ( ( char * ) vals [ 5 ] [ 0 ] . data ) ;
2004-05-02 10:06:45 +00:00
2004-05-05 04:27:29 +00:00
ldb_delete ( ldb , msg . dn ) ;
2011-05-11 14:25:11 +02:00
if ( ldb_add ( ldb , & msg ) ! = LDB_SUCCESS ) {
2004-05-02 10:06:45 +00:00
printf ( " Add of %s failed - %s \n " , name , ldb_errstring ( ldb ) ) ;
2011-03-02 22:28:27 +01:00
exit ( LDB_ERR_OPERATIONS_ERROR ) ;
2004-05-02 10:06:45 +00:00
}
printf ( " adding uid %s \r " , name ) ;
fflush ( stdout ) ;
2005-06-18 07:42:21 +00:00
talloc_free ( tmp_ctx ) ;
2004-05-02 10:06:45 +00:00
}
2005-09-17 19:25:50 +00:00
#if 0
2005-06-22 02:39:07 +00:00
if ( ldb_unlock ( ldb , " transaction " ) ! = 0 ) {
printf ( " transaction unlock failed \n " ) ;
2011-03-02 22:28:27 +01:00
exit ( LDB_ERR_OPERATIONS_ERROR ) ;
2005-06-22 02:39:07 +00:00
}
2005-09-17 19:25:50 +00:00
# endif
2004-05-02 10:06:45 +00:00
printf ( " \n " ) ;
}
2004-05-05 04:27:29 +00:00
static void modify_records ( struct ldb_context * ldb ,
2006-11-22 00:59:34 +00:00
struct ldb_dn * basedn ,
2009-11-06 18:35:17 +01:00
unsigned int count )
2004-05-05 04:27:29 +00:00
{
struct ldb_message msg ;
2009-11-06 18:35:17 +01:00
unsigned int i ;
2004-05-05 04:27:29 +00:00
for ( i = 0 ; i < count ; i + + ) {
struct ldb_message_element el [ 3 ] ;
struct ldb_val vals [ 3 ] ;
char * name ;
2005-06-18 07:42:21 +00:00
TALLOC_CTX * tmp_ctx = talloc_new ( ldb ) ;
2004-05-05 04:27:29 +00:00
2005-06-18 07:42:21 +00:00
name = talloc_asprintf ( tmp_ctx , " Test%d " , i ) ;
2006-11-22 00:59:34 +00:00
msg . dn = ldb_dn_copy ( tmp_ctx , basedn ) ;
ldb_dn_add_child_fmt ( msg . dn , " cn=%s " , name ) ;
2004-05-05 04:27:29 +00:00
msg . num_elements = 3 ;
msg . elements = el ;
el [ 0 ] . flags = LDB_FLAG_MOD_DELETE ;
2005-06-18 07:42:21 +00:00
el [ 0 ] . name = talloc_strdup ( tmp_ctx , " mail " ) ;
2004-05-05 04:27:29 +00:00
el [ 0 ] . num_values = 0 ;
el [ 1 ] . flags = LDB_FLAG_MOD_ADD ;
2005-06-18 07:42:21 +00:00
el [ 1 ] . name = talloc_strdup ( tmp_ctx , " mail " ) ;
2004-05-05 04:27:29 +00:00
el [ 1 ] . num_values = 1 ;
el [ 1 ] . values = & vals [ 1 ] ;
2005-10-12 06:10:23 +00:00
vals [ 1 ] . data = ( uint8_t * ) talloc_asprintf ( tmp_ctx , " %s@other.example.com " , name ) ;
vals [ 1 ] . length = strlen ( ( char * ) vals [ 1 ] . data ) ;
2004-05-05 04:27:29 +00:00
el [ 2 ] . flags = LDB_FLAG_MOD_REPLACE ;
2005-06-18 07:42:21 +00:00
el [ 2 ] . name = talloc_strdup ( tmp_ctx , " mail " ) ;
2004-05-05 04:27:29 +00:00
el [ 2 ] . num_values = 1 ;
el [ 2 ] . values = & vals [ 2 ] ;
2005-10-12 06:10:23 +00:00
vals [ 2 ] . data = ( uint8_t * ) talloc_asprintf ( tmp_ctx , " %s@other2.example.com " , name ) ;
vals [ 2 ] . length = strlen ( ( char * ) vals [ 2 ] . data ) ;
2004-05-05 04:27:29 +00:00
2011-05-11 14:25:11 +02:00
if ( ldb_modify ( ldb , & msg ) ! = LDB_SUCCESS ) {
2004-05-05 04:27:29 +00:00
printf ( " Modify of %s failed - %s \n " , name , ldb_errstring ( ldb ) ) ;
2011-03-02 22:28:27 +01:00
exit ( LDB_ERR_OPERATIONS_ERROR ) ;
2004-05-05 04:27:29 +00:00
}
printf ( " Modifying uid %s \r " , name ) ;
fflush ( stdout ) ;
2005-06-18 07:42:21 +00:00
talloc_free ( tmp_ctx ) ;
2004-05-05 04:27:29 +00:00
}
printf ( " \n " ) ;
}
static void delete_records ( struct ldb_context * ldb ,
2006-11-22 00:59:34 +00:00
struct ldb_dn * basedn ,
2009-11-06 18:35:17 +01:00
unsigned int count )
2004-05-05 04:27:29 +00:00
{
2009-11-06 18:35:17 +01:00
unsigned int i ;
2004-05-05 04:27:29 +00:00
for ( i = 0 ; i < count ; i + + ) {
2005-08-18 15:02:01 +00:00
struct ldb_dn * dn ;
char * name = talloc_asprintf ( ldb , " Test%d " , i ) ;
2006-11-22 00:59:34 +00:00
dn = ldb_dn_copy ( name , basedn ) ;
ldb_dn_add_child_fmt ( dn , " cn=%s " , name ) ;
2004-05-05 04:27:29 +00:00
printf ( " Deleting uid Test%d \r " , i ) ;
fflush ( stdout ) ;
2011-05-11 14:25:11 +02:00
if ( ldb_delete ( ldb , dn ) ! = LDB_SUCCESS ) {
2006-11-22 00:59:34 +00:00
printf ( " Delete of %s failed - %s \n " , ldb_dn_get_linearized ( dn ) , ldb_errstring ( ldb ) ) ;
2011-03-02 22:28:27 +01:00
exit ( LDB_ERR_OPERATIONS_ERROR ) ;
2004-05-05 04:27:29 +00:00
}
2005-08-18 15:02:01 +00:00
talloc_free ( name ) ;
2004-05-05 04:27:29 +00:00
}
printf ( " \n " ) ;
}
2009-11-06 18:35:17 +01:00
static void search_uid ( struct ldb_context * ldb , struct ldb_dn * basedn ,
unsigned int nrecords , unsigned int nsearches )
2004-05-02 10:06:45 +00:00
{
2009-11-06 18:35:17 +01:00
unsigned int i ;
2004-05-02 10:06:45 +00:00
for ( i = 0 ; i < nsearches ; i + + ) {
int uid = ( i * 700 + 17 ) % ( nrecords * 2 ) ;
char * expr ;
2005-11-08 00:11:45 +00:00
struct ldb_result * res = NULL ;
2004-05-02 10:06:45 +00:00
int ret ;
2006-08-23 05:08:55 +00:00
expr = talloc_asprintf ( ldb , " (uid=TEST%d) " , uid ) ;
2008-09-23 14:30:06 -04:00
ret = ldb_search ( ldb , ldb , & res , basedn , LDB_SCOPE_SUBTREE , NULL , " %s " , expr ) ;
2004-05-02 10:06:45 +00:00
2005-11-08 00:11:45 +00:00
if ( ret ! = LDB_SUCCESS | | ( uid < nrecords & & res - > count ! = 1 ) ) {
2004-05-02 10:06:45 +00:00
printf ( " Failed to find %s - %s \n " , expr , ldb_errstring ( ldb ) ) ;
2011-03-02 22:28:27 +01:00
exit ( LDB_ERR_OPERATIONS_ERROR ) ;
2004-05-02 10:06:45 +00:00
}
2005-11-08 00:11:45 +00:00
if ( uid > = nrecords & & res - > count > 0 ) {
2004-05-02 10:06:45 +00:00
printf ( " Found %s !? - %d \n " , expr , ret ) ;
2011-03-02 22:28:27 +01:00
exit ( LDB_ERR_OPERATIONS_ERROR ) ;
2004-05-02 10:06:45 +00:00
}
2010-04-11 01:39:06 +02:00
printf ( " Testing uid %d/%d - %d \r " , i , uid , res - > count ) ;
2004-05-02 10:06:45 +00:00
fflush ( stdout ) ;
2005-11-08 00:11:45 +00:00
talloc_free ( res ) ;
2006-08-23 05:08:55 +00:00
talloc_free ( expr ) ;
2004-05-02 10:06:45 +00:00
}
printf ( " \n " ) ;
}
2009-11-06 18:35:17 +01:00
static void start_test ( struct ldb_context * ldb , unsigned int nrecords ,
unsigned int nsearches )
2004-05-02 10:06:45 +00:00
{
2005-08-18 15:02:01 +00:00
struct ldb_dn * basedn ;
2006-11-22 00:59:34 +00:00
basedn = ldb_dn_new ( ldb , ldb , options - > basedn ) ;
if ( ! ldb_dn_validate ( basedn ) ) {
2011-03-02 22:40:13 +01:00
printf ( " Invalid base DN format \n " ) ;
exit ( LDB_ERR_INVALID_DN_SYNTAX ) ;
2006-11-22 00:59:34 +00:00
}
2005-08-18 15:02:01 +00:00
2004-05-05 04:27:29 +00:00
printf ( " Adding %d records \n " , nrecords ) ;
2005-08-18 15:02:01 +00:00
add_records ( ldb , basedn , nrecords ) ;
2004-05-02 10:06:45 +00:00
printf ( " Starting search on uid \n " ) ;
2004-10-20 19:21:10 +00:00
_start_timer ( ) ;
2005-08-18 15:02:01 +00:00
search_uid ( ldb , basedn , nrecords , nsearches ) ;
2004-10-20 19:21:10 +00:00
printf ( " uid search took %.2f seconds \n " , _end_timer ( ) ) ;
2004-05-05 04:27:29 +00:00
printf ( " Modifying records \n " ) ;
2005-08-18 15:02:01 +00:00
modify_records ( ldb , basedn , nrecords ) ;
2004-05-05 04:27:29 +00:00
printf ( " Deleting records \n " ) ;
2005-08-18 15:02:01 +00:00
delete_records ( ldb , basedn , nrecords ) ;
2004-05-02 10:06:45 +00:00
}
2004-09-22 02:05:02 +00:00
/*
2 ) Store an @ indexlist record
3 ) Store a record that contains fields that should be index according
to @ index
4 ) disconnection from database
5 ) connect to same database
6 ) search for record added in step 3 using a search key that should
be indexed
*/
static void start_test_index ( struct ldb_context * * ldb )
{
2005-01-02 07:49:29 +00:00
struct ldb_message * msg ;
2005-11-08 00:11:45 +00:00
struct ldb_result * res = NULL ;
2005-08-18 15:02:01 +00:00
struct ldb_dn * indexlist ;
struct ldb_dn * basedn ;
2004-09-22 02:05:02 +00:00
int ret ;
2011-04-10 19:44:53 +02:00
unsigned int flags = 0 ;
2006-08-22 01:32:29 +00:00
const char * specials ;
specials = getenv ( " LDB_SPECIALS " ) ;
if ( specials & & atoi ( specials ) = = 0 ) {
printf ( " LDB_SPECIALS disabled - skipping index test \n " ) ;
return ;
}
2005-09-22 04:16:46 +00:00
if ( options - > nosync ) {
flags | = LDB_FLG_NOSYNC ;
}
2004-09-22 02:05:02 +00:00
printf ( " Starting index test \n " ) ;
2006-11-22 00:59:34 +00:00
indexlist = ldb_dn_new ( * ldb , * ldb , " @INDEXLIST " ) ;
2005-08-18 15:02:01 +00:00
ldb_delete ( * ldb , indexlist ) ;
2004-09-28 08:17:20 +00:00
2005-01-02 07:49:29 +00:00
msg = ldb_msg_new ( NULL ) ;
2013-08-18 19:49:24 +00:00
if ( msg = = NULL ) {
printf ( " ldb_msg_new failed \n " ) ;
exit ( LDB_ERR_OPERATIONS_ERROR ) ;
}
2005-01-02 07:49:29 +00:00
2005-08-18 15:02:01 +00:00
msg - > dn = indexlist ;
2005-10-12 06:10:23 +00:00
ldb_msg_add_string ( msg , " @IDXATTR " , strdup ( " uid " ) ) ;
2004-09-22 02:05:02 +00:00
2005-01-02 07:49:29 +00:00
if ( ldb_add ( * ldb , msg ) ! = 0 ) {
2006-11-22 02:05:19 +00:00
printf ( " Add of %s failed - %s \n " , ldb_dn_get_linearized ( msg - > dn ) , ldb_errstring ( * ldb ) ) ;
2011-03-02 22:28:27 +01:00
exit ( LDB_ERR_OPERATIONS_ERROR ) ;
2004-09-22 02:05:02 +00:00
}
2006-11-22 00:59:34 +00:00
basedn = ldb_dn_new ( * ldb , * ldb , options - > basedn ) ;
2005-08-18 15:02:01 +00:00
2005-01-02 07:49:29 +00:00
memset ( msg , 0 , sizeof ( * msg ) ) ;
2006-11-22 00:59:34 +00:00
msg - > dn = ldb_dn_copy ( msg , basedn ) ;
ldb_dn_add_child_fmt ( msg - > dn , " cn=test " ) ;
2005-10-12 06:10:23 +00:00
ldb_msg_add_string ( msg , " cn " , strdup ( " test " ) ) ;
ldb_msg_add_string ( msg , " sn " , strdup ( " test " ) ) ;
ldb_msg_add_string ( msg , " uid " , strdup ( " test " ) ) ;
ldb_msg_add_string ( msg , " objectClass " , strdup ( " OpenLDAPperson " ) ) ;
2004-09-22 02:05:02 +00:00
2011-05-11 14:25:11 +02:00
if ( ldb_add ( * ldb , msg ) ! = LDB_SUCCESS ) {
2006-11-22 02:05:19 +00:00
printf ( " Add of %s failed - %s \n " , ldb_dn_get_linearized ( msg - > dn ) , ldb_errstring ( * ldb ) ) ;
2011-03-02 22:28:27 +01:00
exit ( LDB_ERR_OPERATIONS_ERROR ) ;
2004-09-22 02:05:02 +00:00
}
2005-02-27 11:35:47 +00:00
if ( talloc_free ( * ldb ) ! = 0 ) {
printf ( " failed to free/close ldb database " ) ;
2011-03-02 22:28:27 +01:00
exit ( LDB_ERR_OPERATIONS_ERROR ) ;
2004-09-22 02:05:02 +00:00
}
2008-06-14 11:24:17 -04:00
( * ldb ) = ldb_init ( options , NULL ) ;
2006-11-22 00:59:34 +00:00
2005-09-22 04:16:46 +00:00
ret = ldb_connect ( * ldb , options - > url , flags , NULL ) ;
2011-04-10 19:35:22 +02:00
if ( ret ! = LDB_SUCCESS ) {
2005-06-18 07:42:21 +00:00
printf ( " failed to connect to %s \n " , options - > url ) ;
2011-03-02 22:28:27 +01:00
exit ( LDB_ERR_OPERATIONS_ERROR ) ;
2004-09-22 02:05:02 +00:00
}
2006-11-22 00:59:34 +00:00
basedn = ldb_dn_new ( * ldb , * ldb , options - > basedn ) ;
2009-12-18 13:07:48 +11:00
msg - > dn = basedn ;
ldb_dn_add_child_fmt ( msg - > dn , " cn=test " ) ;
2006-11-22 00:59:34 +00:00
2008-09-23 14:30:06 -04:00
ret = ldb_search ( * ldb , * ldb , & res , basedn , LDB_SCOPE_SUBTREE , NULL , " uid=test " ) ;
2005-11-08 00:11:45 +00:00
if ( ret ! = LDB_SUCCESS ) {
printf ( " Search with (uid=test) filter failed! \n " ) ;
2011-03-02 22:28:27 +01:00
exit ( LDB_ERR_OPERATIONS_ERROR ) ;
2005-11-08 00:11:45 +00:00
}
if ( res - > count ! = 1 ) {
printf ( " Should have found 1 record - found %d \n " , res - > count ) ;
2011-03-02 22:28:27 +01:00
exit ( LDB_ERR_OPERATIONS_ERROR ) ;
2004-09-22 02:05:02 +00:00
}
2006-11-22 00:59:34 +00:00
indexlist = ldb_dn_new ( * ldb , * ldb , " @INDEXLIST " ) ;
2005-01-02 07:49:29 +00:00
if ( ldb_delete ( * ldb , msg - > dn ) ! = 0 | |
2005-08-18 15:02:01 +00:00
ldb_delete ( * ldb , indexlist ) ! = 0 ) {
2004-09-22 02:05:02 +00:00
printf ( " cleanup failed - %s \n " , ldb_errstring ( * ldb ) ) ;
2011-03-02 22:28:27 +01:00
exit ( LDB_ERR_OPERATIONS_ERROR ) ;
2004-09-22 02:05:02 +00:00
}
printf ( " Finished index test \n " ) ;
}
2010-11-01 11:03:38 +01:00
static void usage ( struct ldb_context * ldb )
2004-05-02 10:06:45 +00:00
{
printf ( " Usage: ldbtest <options> \n " ) ;
printf ( " Options: \n " ) ;
printf ( " -H ldb_url choose the database (or $LDB_URL) \n " ) ;
2005-08-30 02:11:56 +00:00
printf ( " --num-records nrecords database size to use \n " ) ;
printf ( " --num-searches nsearches number of searches to do \n " ) ;
2004-05-02 10:06:45 +00:00
printf ( " \n " ) ;
printf ( " tests ldb API \n \n " ) ;
2011-02-01 20:34:44 +01:00
exit ( LDB_ERR_OPERATIONS_ERROR ) ;
2004-05-02 10:06:45 +00:00
}
2006-05-01 01:34:04 +00:00
int main ( int argc , const char * * argv )
2004-05-02 10:06:45 +00:00
{
2005-06-18 07:42:21 +00:00
TALLOC_CTX * mem_ctx = talloc_new ( NULL ) ;
2004-05-02 10:06:45 +00:00
struct ldb_context * ldb ;
2008-06-14 11:24:17 -04:00
ldb = ldb_init ( mem_ctx , NULL ) ;
2011-02-01 20:26:12 +01:00
if ( ldb = = NULL ) {
return LDB_ERR_OPERATIONS_ERROR ;
}
2004-05-02 10:06:45 +00:00
2005-06-18 07:42:21 +00:00
options = ldb_cmdline_process ( ldb , argc , argv , usage ) ;
2004-05-02 10:06:45 +00:00
2005-06-18 07:42:21 +00:00
talloc_steal ( mem_ctx , options ) ;
2004-05-02 10:06:45 +00:00
2005-06-18 07:42:21 +00:00
if ( options - > basedn = = NULL ) {
2005-09-22 03:51:50 +00:00
options - > basedn = " ou=Ldb Test,ou=People,o=University of Michigan,c=TEST " ;
2004-05-02 10:06:45 +00:00
}
srandom ( 1 ) ;
2005-09-22 03:51:50 +00:00
printf ( " Testing with num-records=%d and num-searches=%d \n " ,
options - > num_records , options - > num_searches ) ;
2009-11-06 18:35:17 +01:00
start_test ( ldb ,
( unsigned int ) options - > num_records ,
( unsigned int ) options - > num_searches ) ;
2004-05-02 10:06:45 +00:00
2004-09-28 08:17:20 +00:00
start_test_index ( & ldb ) ;
2005-06-18 07:42:21 +00:00
talloc_free ( mem_ctx ) ;
2004-05-02 10:06:45 +00:00
2011-02-01 20:34:44 +01:00
return LDB_SUCCESS ;
2004-05-02 10:06:45 +00:00
}