/*
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
version 3 of the License, or (at your option) any later version.
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
License along with this library; if not, see .
*/
/*
* Name: ldb
*
* Component: ldbtest
*
* Description: utility to test ldb
*
* Author: Andrew Tridgell
*/
#include "includes.h"
#include "ldb/include/includes.h"
#include "ldb/tools/cmdline.h"
static struct timeval tp1,tp2;
static struct ldb_cmdline *options;
static void _start_timer(void)
{
gettimeofday(&tp1,NULL);
}
static double _end_timer(void)
{
gettimeofday(&tp2,NULL);
return((tp2.tv_sec - tp1.tv_sec) +
(tp2.tv_usec - tp1.tv_usec)*1.0e-6);
}
static void add_records(struct ldb_context *ldb,
const struct ldb_dn *basedn,
int count)
{
struct ldb_message msg;
int i;
#if 0
if (ldb_lock(ldb, "transaction") != 0) {
printf("transaction lock failed\n");
exit(1);
}
#endif
for (i=0;icount != 1)) {
printf("Failed to find %s - %s\n", expr, ldb_errstring(ldb));
exit(1);
}
if (uid >= nrecords && res->count > 0) {
printf("Found %s !? - %d\n", expr, ret);
exit(1);
}
printf("testing uid %d/%d - %d \r", i, uid, res->count);
fflush(stdout);
talloc_free(res);
talloc_free(expr);
}
printf("\n");
}
static void start_test(struct ldb_context *ldb, int nrecords, int nsearches)
{
struct ldb_dn *basedn;
basedn = ldb_dn_explode(ldb, options->basedn);
printf("Adding %d records\n", nrecords);
add_records(ldb, basedn, nrecords);
printf("Starting search on uid\n");
_start_timer();
search_uid(ldb, basedn, nrecords, nsearches);
printf("uid search took %.2f seconds\n", _end_timer());
printf("Modifying records\n");
modify_records(ldb, basedn, nrecords);
printf("Deleting records\n");
delete_records(ldb, basedn, nrecords);
}
/*
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)
{
struct ldb_message *msg;
struct ldb_result *res = NULL;
struct ldb_dn *indexlist;
struct ldb_dn *basedn;
int ret;
int flags = 0;
const char *specials;
specials = getenv("LDB_SPECIALS");
if (specials && atoi(specials) == 0) {
printf("LDB_SPECIALS disabled - skipping index test\n");
return;
}
if (options->nosync) {
flags |= LDB_FLG_NOSYNC;
}
printf("Starting index test\n");
indexlist = ldb_dn_explode(NULL, "@INDEXLIST");
ldb_delete(*ldb, indexlist);
msg = ldb_msg_new(NULL);
msg->dn = indexlist;
ldb_msg_add_string(msg, "@IDXATTR", strdup("uid"));
if (ldb_add(*ldb, msg) != 0) {
printf("Add of %s failed - %s\n", ldb_dn_linearize(*ldb, msg->dn), ldb_errstring(*ldb));
exit(1);
}
basedn = ldb_dn_explode(NULL, options->basedn);
memset(msg, 0, sizeof(*msg));
msg->dn = ldb_dn_build_child(msg, "cn", "test", basedn);
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"));
if (ldb_add(*ldb, msg) != 0) {
printf("Add of %s failed - %s\n", ldb_dn_linearize(*ldb, msg->dn), ldb_errstring(*ldb));
exit(1);
}
if (talloc_free(*ldb) != 0) {
printf("failed to free/close ldb database");
exit(1);
}
(*ldb) = ldb_init(options);
ret = ldb_connect(*ldb, options->url, flags, NULL);
if (ret != 0) {
printf("failed to connect to %s\n", options->url);
exit(1);
}
ret = ldb_search(*ldb, basedn, LDB_SCOPE_SUBTREE, "uid=test", NULL, &res);
if (ret != LDB_SUCCESS) {
printf("Search with (uid=test) filter failed!\n");
exit(1);
}
if(res->count != 1) {
printf("Should have found 1 record - found %d\n", res->count);
exit(1);
}
if (ldb_delete(*ldb, msg->dn) != 0 ||
ldb_delete(*ldb, indexlist) != 0) {
printf("cleanup failed - %s\n", ldb_errstring(*ldb));
exit(1);
}
printf("Finished index test\n");
}
static void usage(void)
{
printf("Usage: ldbtest \n");
printf("Options:\n");
printf(" -H ldb_url choose the database (or $LDB_URL)\n");
printf(" --num-records nrecords database size to use\n");
printf(" --num-searches nsearches number of searches to do\n");
printf("\n");
printf("tests ldb API\n\n");
exit(1);
}
int main(int argc, const char **argv)
{
TALLOC_CTX *mem_ctx = talloc_new(NULL);
struct ldb_context *ldb;
ldb_global_init();
ldb = ldb_init(mem_ctx);
options = ldb_cmdline_process(ldb, argc, argv, usage);
talloc_steal(mem_ctx, options);
if (options->basedn == NULL) {
options->basedn = "ou=Ldb Test,ou=People,o=University of Michigan,c=TEST";
}
srandom(1);
printf("Testing with num-records=%d and num-searches=%d\n",
options->num_records, options->num_searches);
start_test(ldb, options->num_records, options->num_searches);
start_test_index(&ldb);
talloc_free(mem_ctx);
return 0;
}
(@_/n?-4i(RyW,dhe{
Յ(ן1c)3[BYO2!y)7VoWEʸCZȽB단A[HYeĨ=mS9}PLD@||fQhHqO
Gi$
an'11Q\d jbtu^ǣS+EŐ _4mkGkJ彍1
o%C椷ԋݘ.3
yq+X]x )f҉|YԮ#y^6^F~bWs=ڕ,ml zU&]c8_bҌc(JHփ$^.vjٓ'pKk6˃K",_c!E[rwY"?1>[zR%^)ŏզ
P%ưc?B$1bST9rhOȭC+MNN5"'&'%(OPԋ߈_iiݿU68ejuWѬB7 [$ƀE+5q/k)b$&x1jTaz6" .?i4(dټق0Xރ\S5&at4(L;7LfjТL}PdMX::"i$
;14P;n@Vcl0z`_? iJ_ۛ=XzéA&GpGkqv{Dl8> 6X k㑸Ԯn%3Xw;в!! fH>\/QO~ Yb z_dc)`~PFq8Z<~Jqj%3^^
nk@
um7,x,+/k0n
okaXwjݠk̋䚾>ru7pe:G
Qv$ъw8op/Z
d'H@e nQ*qn
m&§A!U 7X$jaWK>Ʉq#%" ]Kb^\XD>ZN+TK\,^Rړivԛ:-kZjp2 l?swݲe[ΐW,5^ F:D.;qd㇠Rˉ]xJIO[gg^33U5)I?V094
oO] yS33ԷA">"ý=^5w
v!<&6&ok
3S͑]FQnۿ"!n#gSft5JZi!ϳoCX-!knTe%ˏ( Gΐ[jv'teu n!((kSI~J3 ]sDcqx }#$K0"`*5cspSӪHnm@#&'[F';lƍ7*`&J\*MHؗ8\fq~''LgR0kNgUbh}rteN.м8왑2߬nv`
BH0o!7x#:ka#,s]W^gl`$ϰM+]l`z|ʫ(̱Sm&̨rx `Չ [V7!߯G}* sxYѪp)am9%lմ-zәjӀ{s/cw
*TNR^Ze1O
-
}-p^OlSBK]<@ RbFCd~l+0V .#'%J=R}]oY)*rZ}[EdH|]Uy1=b@QDW`-3 v{{j);J9 @FkM