From: Kurt Zeilenga Date: Tue, 17 Aug 1999 19:00:59 +0000 (+0000) Subject: New dn2id format with base/one/subtree indices (ldbm/bdb2) X-Git-Tag: TWEB_OL_BASE~193 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=e4f6d548773d1a79d9ca6fa82b6c486fbdc0c47b;p=openldap New dn2id format with base/one/subtree indices (ldbm/bdb2) New id2entry (id-less) format (ldbm/bdb2) Removed id2children (ldbm/bdb2) Added nextid database (ldbm) Broke ldbmtest Removed ldif2* tools (ldbm/bdb2) Added slap tools (slapadd, slapcat, slapindex) --- diff --git a/build/main.dsw b/build/main.dsw index 2b8c9582c2..bfe89b0ef0 100644 --- a/build/main.dsw +++ b/build/main.dsw @@ -87,34 +87,46 @@ Package=<4> Project_Dep_Name ldapsearch End Project Dependency Begin Project Dependency - Project_Dep_Name ldbmcat - End Project Dependency - Begin Project Dependency Project_Dep_Name ldbmtest End Project Dependency Begin Project Dependency Project_Dep_Name ldif End Project Dependency Begin Project Dependency - Project_Dep_Name ldif2id2children + Project_Dep_Name testavl End Project Dependency Begin Project Dependency - Project_Dep_Name ldif2id2entry + Project_Dep_Name ud End Project Dependency Begin Project Dependency - Project_Dep_Name ldif2index + Project_Dep_Name slapcat End Project Dependency Begin Project Dependency - Project_Dep_Name ldif2ldbm + Project_Dep_Name slapadd + End Project Dependency + Begin Project Dependency + Project_Dep_Name slapindex End Project Dependency Begin Project Dependency Project_Dep_Name slapd End Project Dependency Begin Project Dependency - Project_Dep_Name testavl + Project_Dep_Name ldbmcat End Project Dependency Begin Project Dependency - Project_Dep_Name ud + Project_Dep_Name ldif2ldbm + End Project Dependency + Begin Project Dependency + Project_Dep_Name ldbmindex + End Project Dependency + Begin Project Dependency + Project_Dep_Name ldbmentry + End Project Dependency + Begin Project Dependency + Project_Dep_Name ltest + End Project Dependency + Begin Project Dependency + Project_Dep_Name ltest_r End Project Dependency }}} @@ -291,7 +303,7 @@ Package=<4> ############################################################################### -Project: "ldbmtest"=..\servers\slapd\tools\ldbmtest.dsp - Package Owner=<4> +Project: "ldbmentry"=..\servers\slapd\tools\ldbmentry.dsp - Package Owner=<4> Package=<5> {{{ @@ -303,6 +315,9 @@ Package=<4> Project_Dep_Name backldbm End Project Dependency Begin Project Dependency + Project_Dep_Name libavl + End Project Dependency + Begin Project Dependency Project_Dep_Name liblber End Project Dependency Begin Project Dependency @@ -312,46 +327,19 @@ Package=<4> Project_Dep_Name libldbm End Project Dependency Begin Project Dependency - Project_Dep_Name liblutil - End Project Dependency - Begin Project Dependency - Project_Dep_Name libslapd - End Project Dependency - Begin Project Dependency - Project_Dep_Name libavl - End Project Dependency - Begin Project Dependency - Project_Dep_Name libldif - End Project Dependency -}}} - -############################################################################### - -Project: "ldif"=..\servers\slapd\tools\ldif.dsp - Package Owner=<4> - -Package=<5> -{{{ -}}} - -Package=<4> -{{{ - Begin Project Dependency - Project_Dep_Name liblber - End Project Dependency - Begin Project Dependency Project_Dep_Name libldif End Project Dependency Begin Project Dependency - Project_Dep_Name libldap + Project_Dep_Name liblutil End Project Dependency Begin Project Dependency - Project_Dep_Name liblutil + Project_Dep_Name libslapd End Project Dependency }}} ############################################################################### -Project: "ldif2id2children"=..\servers\slapd\tools\ldif2id2children.dsp - Package Owner=<4> +Project: "ldbmindex"=..\servers\slapd\tools\ldbmindex.dsp - Package Owner=<4> Package=<5> {{{ @@ -363,22 +351,22 @@ Package=<4> Project_Dep_Name backldbm End Project Dependency Begin Project Dependency - Project_Dep_Name libldap_r + Project_Dep_Name libavl End Project Dependency Begin Project Dependency - Project_Dep_Name libldif + Project_Dep_Name liblber End Project Dependency Begin Project Dependency - Project_Dep_Name libavl + Project_Dep_Name libldap_r End Project Dependency Begin Project Dependency - Project_Dep_Name liblutil + Project_Dep_Name libldbm End Project Dependency Begin Project Dependency - Project_Dep_Name liblber + Project_Dep_Name libldif End Project Dependency Begin Project Dependency - Project_Dep_Name libldbm + Project_Dep_Name liblutil End Project Dependency Begin Project Dependency Project_Dep_Name libslapd @@ -387,7 +375,7 @@ Package=<4> ############################################################################### -Project: "ldif2id2entry"=..\servers\slapd\tools\ldif2id2entry.dsp - Package Owner=<4> +Project: "ldbmtest"=..\servers\slapd\tools\ldbmtest.dsp - Package Owner=<4> Package=<5> {{{ @@ -399,31 +387,31 @@ Package=<4> Project_Dep_Name backldbm End Project Dependency Begin Project Dependency - Project_Dep_Name libavl + Project_Dep_Name liblber End Project Dependency Begin Project Dependency Project_Dep_Name libldap_r End Project Dependency Begin Project Dependency - Project_Dep_Name libldif + Project_Dep_Name libldbm End Project Dependency Begin Project Dependency Project_Dep_Name liblutil End Project Dependency Begin Project Dependency - Project_Dep_Name liblber + Project_Dep_Name libslapd End Project Dependency Begin Project Dependency - Project_Dep_Name libldbm + Project_Dep_Name libavl End Project Dependency Begin Project Dependency - Project_Dep_Name libslapd + Project_Dep_Name libldif End Project Dependency }}} ############################################################################### -Project: "ldif2index"=..\servers\slapd\tools\ldif2index.dsp - Package Owner=<4> +Project: "ldif"=..\servers\slapd\tools\ldif.dsp - Package Owner=<4> Package=<5> {{{ @@ -432,28 +420,16 @@ Package=<5> Package=<4> {{{ Begin Project Dependency - Project_Dep_Name backldbm - End Project Dependency - Begin Project Dependency - Project_Dep_Name libldap_r - End Project Dependency - Begin Project Dependency - Project_Dep_Name libavl - End Project Dependency - Begin Project Dependency - Project_Dep_Name liblutil + Project_Dep_Name liblber End Project Dependency Begin Project Dependency Project_Dep_Name libldif End Project Dependency Begin Project Dependency - Project_Dep_Name liblber - End Project Dependency - Begin Project Dependency - Project_Dep_Name libldbm + Project_Dep_Name libldap End Project Dependency Begin Project Dependency - Project_Dep_Name libslapd + Project_Dep_Name liblutil End Project Dependency }}} @@ -645,6 +621,78 @@ Package=<4> ############################################################################### +Project: "slapadd"=..\servers\slapd\tools\slapadd.dsp - Package Owner=<4> + +Package=<5> +{{{ +}}} + +Package=<4> +{{{ + Begin Project Dependency + Project_Dep_Name backldbm + End Project Dependency + Begin Project Dependency + Project_Dep_Name libavl + End Project Dependency + Begin Project Dependency + Project_Dep_Name liblber + End Project Dependency + Begin Project Dependency + Project_Dep_Name libldap_r + End Project Dependency + Begin Project Dependency + Project_Dep_Name libldbm + End Project Dependency + Begin Project Dependency + Project_Dep_Name libldif + End Project Dependency + Begin Project Dependency + Project_Dep_Name liblutil + End Project Dependency + Begin Project Dependency + Project_Dep_Name libslapd + End Project Dependency +}}} + +############################################################################### + +Project: "slapcat"=..\servers\slapd\tools\slapcat.dsp - Package Owner=<4> + +Package=<5> +{{{ +}}} + +Package=<4> +{{{ + Begin Project Dependency + Project_Dep_Name libavl + End Project Dependency + Begin Project Dependency + Project_Dep_Name liblber + End Project Dependency + Begin Project Dependency + Project_Dep_Name libldap_r + End Project Dependency + Begin Project Dependency + Project_Dep_Name libldbm + End Project Dependency + Begin Project Dependency + Project_Dep_Name libldif + End Project Dependency + Begin Project Dependency + Project_Dep_Name liblutil + End Project Dependency + Begin Project Dependency + Project_Dep_Name libslapd + End Project Dependency + Begin Project Dependency + Project_Dep_Name backldbm + End Project Dependency +}}} + +############################################################################### + Project: "slapd"=..\servers\slapd\slapd.dsp - Package Owner=<4> Package=<5> @@ -684,6 +732,42 @@ Package=<4> ############################################################################### +Project: "slapindex"=..\servers\slapd\tools\slapindex.dsp - Package Owner=<4> + +Package=<5> +{{{ +}}} + +Package=<4> +{{{ + Begin Project Dependency + Project_Dep_Name backldbm + End Project Dependency + Begin Project Dependency + Project_Dep_Name libavl + End Project Dependency + Begin Project Dependency + Project_Dep_Name liblber + End Project Dependency + Begin Project Dependency + Project_Dep_Name libldap_r + End Project Dependency + Begin Project Dependency + Project_Dep_Name libldbm + End Project Dependency + Begin Project Dependency + Project_Dep_Name libldif + End Project Dependency + Begin Project Dependency + Project_Dep_Name liblutil + End Project Dependency + Begin Project Dependency + Project_Dep_Name libslapd + End Project Dependency +}}} + +############################################################################### + Project: "testavl"=..\libraries\libavl\testavl.dsp - Package Owner=<4> Package=<5> diff --git a/include/ldbm.h b/include/ldbm.h index 876b7c60ef..10f9b3b44d 100644 --- a/include/ldbm.h +++ b/include/ldbm.h @@ -49,23 +49,26 @@ typedef DBT Datum; typedef DB *LDBM; -LDAP_END_DECL #define DB_TYPE DB_BTREE /* for ldbm_open */ #ifdef HAVE_BERKELEY_DB2 +typedef DBC LDBMCursor; # define LDBM_READER DB_RDONLY # define LDBM_WRITER 0x00000 /* hopefully */ # define LDBM_WRCREAT (DB_NOMMAP|DB_CREATE|DB_THREAD) # define LDBM_NEWDB (DB_TRUNCATE|DB_CREATE|DB_THREAD) #else +typedef int LDBMCursor; # define LDBM_READER O_RDONLY # define LDBM_WRITER O_RDWR # define LDBM_WRCREAT (O_RDWR|O_CREAT) # define LDBM_NEWDB (O_RDWR|O_TRUNC|O_CREAT) #endif +LDAP_END_DECL + # define LDBM_FAST 0 #define LDBM_SUFFIX ".dbb" @@ -110,17 +113,17 @@ typedef DBT Datum; typedef DB *LDBM; -LDAP_END_DECL - #define DB_TYPE DB_HASH /* for ldbm_open */ #ifdef LDBM_USE_DB2 +typedef DBC LDBMCursor; # define LDBM_READER DB_RDONLY # define LDBM_WRITER 0x00000 /* hopefully */ # define LDBM_WRCREAT (DB_NOMMAP|DB_CREATE|DB_THREAD) # define LDBM_NEWDB (DB_TRUNCATE|DB_CREATE|DB_THREAD) #else +typedef int LDBMCursor; # define LDBM_READER O_RDONLY # define LDBM_WRITER O_RDWR # define LDBM_WRCREAT (O_RDWR|O_CREAT) @@ -128,6 +131,8 @@ LDAP_END_DECL # define LDBM_FAST 0 #endif +LDAP_END_DECL + #define LDBM_SUFFIX ".dbh" /* for ldbm_insert */ @@ -148,7 +153,7 @@ LDAP_END_DECL LDAP_BEGIN_DECL typedef datum Datum; - +typedef int LDBMCursor; typedef GDBM_FILE LDBM; extern gdbm_error gdbm_errno; @@ -182,6 +187,7 @@ LDAP_END_DECL LDAP_BEGIN_DECL typedef datum Datum; +typedef int LDBMCursor; typedef MDBM *LDBM; LDAP_END_DECL @@ -222,7 +228,7 @@ LDAP_END_DECL LDAP_BEGIN_DECL typedef datum Datum; - +typedef int LDBMCursor; typedef DBM *LDBM; LDAP_END_DECL @@ -258,18 +264,12 @@ Datum ldbm_fetch( LDBM ldbm, Datum key ); int ldbm_store( LDBM ldbm, Datum key, Datum data, int flags ); int ldbm_delete( LDBM ldbm, Datum key ); -#if HAVE_BERKELEY_DB2 - void *ldbm_malloc( size_t size ); - Datum ldbm_firstkey( LDBM ldbm, DBC **dbch ); - Datum ldbm_nextkey( LDBM ldbm, Datum key, DBC *dbcp ); -#else - Datum ldbm_firstkey( LDBM ldbm ); - Datum ldbm_nextkey( LDBM ldbm, Datum key ); -#endif - +Datum ldbm_firstkey( LDBM ldbm, LDBMCursor **cursor ); +Datum ldbm_nextkey( LDBM ldbm, Datum key, LDBMCursor *cursor ); /* initialization of Datum structures */ #ifdef HAVE_BERKELEY_DB2 + void *ldbm_malloc( size_t size ); # define ldbm_datum_init(d) ((void)memset(&(d), 0, sizeof(Datum))) #else # define ldbm_datum_init(d) ((void)0) diff --git a/include/ldif.h b/include/ldif.h index a28dd3044f..901fb58e70 100644 --- a/include/ldif.h +++ b/include/ldif.h @@ -64,6 +64,14 @@ ldif_fetch_url LDAP_P(( LDAP_F( char * ) ldif_getline LDAP_P(( char **next )); +LDAP_F( int ) +ldif_read_record LDAP_P(( + FILE *fp, + int *lineno, + char **bufp, + int *buflen )); + + #define LDIF_PUT_NOVALUE 0x0000 /* no value */ #define LDIF_PUT_VALUE 0x0001 /* value w/ auto detection */ #define LDIF_PUT_TEXT 0x0002 /* assume text */ diff --git a/include/lutil.h b/include/lutil.h index 7a607b11ba..d7eb530fcd 100644 --- a/include/lutil.h +++ b/include/lutil.h @@ -47,6 +47,14 @@ lutil_passwd LDAP_P(( const char *passwd, const char **methods )); +/* utils.c */ +LDAP_F( char* ) +lutil_progname LDAP_P(( + const char* name, + int argc, + char *argv[] )); + + LDAP_END_DECL #endif /* _LUTIL_H */ diff --git a/libraries/libldbm/ldbm.c b/libraries/libldbm/ldbm.c index 3cfebe7912..e9091a9a10 100644 --- a/libraries/libldbm/ldbm.c +++ b/libraries/libldbm/ldbm.c @@ -314,16 +314,12 @@ ldbm_delete( LDBM ldbm, Datum key ) } Datum -#ifdef HAVE_BERKELEY_DB2 -ldbm_firstkey( LDBM ldbm, DBC **dbch ) -#else -ldbm_firstkey( LDBM ldbm ) -#endif +ldbm_firstkey( LDBM ldbm, LDBMCursor **dbch ) { Datum key, data; #ifdef HAVE_BERKELEY_DB2 - DBC *dbci; + LDBMCursor *dbci; ldbm_datum_init( key ); ldbm_datum_init( data ); @@ -375,11 +371,7 @@ ldbm_firstkey( LDBM ldbm ) } Datum -#ifdef HAVE_BERKELEY_DB2 -ldbm_nextkey( LDBM ldbm, Datum key, DBC *dbcp ) -#else -ldbm_nextkey( LDBM ldbm, Datum key ) -#endif +ldbm_nextkey( LDBM ldbm, Datum key, LDBMCursor *dbcp ) { Datum data; @@ -518,7 +510,7 @@ ldbm_delete( LDBM ldbm, Datum key ) } Datum -ldbm_firstkey( LDBM ldbm ) +ldbm_firstkey( LDBM ldbm, LDBMCursor **dbcp ) { Datum d; @@ -530,7 +522,7 @@ ldbm_firstkey( LDBM ldbm ) } Datum -ldbm_nextkey( LDBM ldbm, Datum key ) +ldbm_nextkey( LDBM ldbm, Datum key, LDBMCursor *dbcp ) { Datum d; @@ -629,7 +621,7 @@ ldbm_open( char *name, int rw, int mode, int dbcachesize ) return( db ); -}/* LDBM ldbm_open() */ +} @@ -655,7 +647,7 @@ ldbm_close( LDBM ldbm ) fflush( stdout ); #endif -}/* void ldbm_close() */ +} @@ -672,7 +664,7 @@ ldbm_sync( LDBM ldbm ) mdbm_sync( ldbm ); LDBM_UNLOCK; -}/* void ldbm_sync() */ +} #define MAX_MDBM_RETRY 5 @@ -739,7 +731,7 @@ ldbm_fetch( LDBM ldbm, Datum key ) return d; -}/* Datum ldbm_fetch() */ +} @@ -786,8 +778,7 @@ ldbm_store( LDBM ldbm, Datum key, Datum data, int flags ) return( rc ); -}/* int ldbm_store() */ - +} @@ -817,7 +808,7 @@ ldbm_delete( LDBM ldbm, Datum key ) return( rc ); -}/* int ldbm_delete() */ +} @@ -872,24 +863,24 @@ ldbm_get_next( LDBM ldbm, kvpair (*fptr)(MDBM *, kvpair) ) return ret; -}/* static Datum ldbm_get_next() */ +} Datum -ldbm_firstkey( LDBM ldbm ) +ldbm_firstkey( LDBM ldbm, LDBMCursor **dbcp ) { return ldbm_get_next( ldbm, mdbm_first ); -}/* Datum ldbm_firstkey() */ +} Datum -ldbm_nextkey( LDBM ldbm, Datum key ) +ldbm_nextkey( LDBM ldbm, Datum key, LDBMCursor *dbcp ) { /* XXX: @@ -899,7 +890,7 @@ ldbm_nextkey( LDBM ldbm, Datum key ) return ldbm_get_next( ldbm, mdbm_next ); -}/* Datum ldbm_nextkey() */ +} int ldbm_errno( LDBM ldbm ) @@ -907,7 +898,7 @@ ldbm_errno( LDBM ldbm ) /* XXX: best we can do with current mdbm interface */ return( errno ); -}/* int ldbm_errno() */ +} @@ -985,7 +976,7 @@ ldbm_delete( LDBM ldbm, Datum key ) } Datum -ldbm_firstkey( LDBM ldbm ) +ldbm_firstkey( LDBM ldbm, LDBMCursor **dbcp ) { Datum d; @@ -997,7 +988,7 @@ ldbm_firstkey( LDBM ldbm ) } Datum -ldbm_nextkey( LDBM ldbm, Datum key ) +ldbm_nextkey( LDBM ldbm, Datum key, LDBMCursor *dbcp ) { Datum d; diff --git a/libraries/libldif/line64.c b/libraries/libldif/line64.c index aef935b755..fa39ce6ae5 100644 --- a/libraries/libldif/line64.c +++ b/libraries/libldif/line64.c @@ -534,3 +534,62 @@ int ldif_is_not_printable( return 1; } + +/* + * slap_read_ldif - read an ldif record. Return 1 for success, 0 for EOF. + */ +int +ldif_read_record( + FILE *fp, + int *lno, /* ptr to line number counter */ + char **bufp, /* ptr to malloced output buffer */ + int *buflenp ) /* ptr to length of *bufp */ +{ + char linebuf[BUFSIZ], *line; + ber_len_t lcur = 0, len, linesize; + int last_ch = '\n', found_entry = 0, stop; + + line = linebuf; + linesize = sizeof( linebuf ); + + for ( stop = feof( fp ); !stop; last_ch = line[len-1] ) { + if ( fgets( line, linesize, fp ) == NULL ) { + stop = 1; + /* Add \n in case the file does not end with newline */ + line = "\n"; + } + len = strlen( line ); + + if ( last_ch == '\n' ) { + (*lno)++; + + if ( line[0] == '\n' ) { + if ( !found_entry ) + continue; + break; + } + + if ( !found_entry ) { + /* Found a new entry */ + found_entry = 1; + + if ( isdigit( (unsigned char) line[0] ) ) { + /* skip index */ + continue; + } + } + } + + if ( *buflenp - lcur <= len ) { + char *nbufp = ber_memrealloc( *bufp, *buflenp += len + BUFSIZ ); + if( nbufp == NULL ) { + return 0; + } + *bufp = nbufp; + } + strcpy( *bufp + lcur, line ); + lcur += len; + } + + return( found_entry ); +} \ No newline at end of file diff --git a/libraries/liblutil/Makefile.in b/libraries/liblutil/Makefile.in index b5932cc985..189f2f6623 100644 --- a/libraries/liblutil/Makefile.in +++ b/libraries/liblutil/Makefile.in @@ -3,8 +3,10 @@ ## LIBRARY = liblutil.a -SRCS = base64.c debug.c detach.c md5.c passwd.c sha1.c getpass.c lockf.c -OBJS = base64.o debug.o detach.o md5.o passwd.o sha1.o getpass.o lockf.o \ +SRCS = base64.c debug.c detach.c \ + md5.c passwd.c sha1.c getpass.c lockf.c utils.c +OBJS = base64.o debug.o detach.o \ + md5.o passwd.o sha1.o getpass.o lockf.o utils.o \ @LIBOBJS@ LDAP_INCDIR= ../../include diff --git a/libraries/liblutil/base64.c b/libraries/liblutil/base64.c index 2a29a1dea0..e837088347 100644 --- a/libraries/liblutil/base64.c +++ b/libraries/liblutil/base64.c @@ -1,3 +1,7 @@ +/* + * Copyright 1998-1999 The OpenLDAP Foundation, All Rights Reserved. + * COPYING RESTRICTIONS APPLY, see COPYRIGHT file + */ /* * Modified by Kurt D. Zeilenga for inclusion into OpenLDAP */ diff --git a/libraries/liblutil/debug.c b/libraries/liblutil/debug.c index d6bb4f836f..f6b9979060 100644 --- a/libraries/liblutil/debug.c +++ b/libraries/liblutil/debug.c @@ -1,3 +1,7 @@ +/* + * Copyright 1998-1999 The OpenLDAP Foundation, All Rights Reserved. + * COPYING RESTRICTIONS APPLY, see COPYRIGHT file + */ /* * Copyright (c) 1996, 1998 by Internet Software Consortium. * diff --git a/libraries/liblutil/getopt.c b/libraries/liblutil/getopt.c index c69bd17aa1..2294dcf519 100644 --- a/libraries/liblutil/getopt.c +++ b/libraries/liblutil/getopt.c @@ -1,3 +1,7 @@ +/* + * Copyright 1998-1999 The OpenLDAP Foundation, All Rights Reserved. + * COPYING RESTRICTIONS APPLY, see COPYRIGHT file + */ /* getopt.c diff --git a/libraries/liblutil/getpass.c b/libraries/liblutil/getpass.c index 30c632d562..6efd3f00d4 100644 --- a/libraries/liblutil/getpass.c +++ b/libraries/liblutil/getpass.c @@ -1,3 +1,7 @@ +/* + * Copyright 1998-1999 The OpenLDAP Foundation, All Rights Reserved. + * COPYING RESTRICTIONS APPLY, see COPYRIGHT file + */ /* * Copyright (c) 1992, 1993 Regents of the University of Michigan. * All rights reserved. diff --git a/libraries/liblutil/liblutil.dsp b/libraries/liblutil/liblutil.dsp index 4ccd716d13..539fc479c0 100644 --- a/libraries/liblutil/liblutil.dsp +++ b/libraries/liblutil/liblutil.dsp @@ -252,6 +252,10 @@ InputPath=.\slapdmsg.mc !ENDIF +# End Source File +# Begin Source File + +SOURCE=.\utils.c # End Source File # End Target # End Project diff --git a/libraries/liblutil/md5.c b/libraries/liblutil/md5.c index 9fbf7e2755..0109b1c652 100644 --- a/libraries/liblutil/md5.c +++ b/libraries/liblutil/md5.c @@ -1,3 +1,7 @@ +/* + * Copyright 1998-1999 The OpenLDAP Foundation, All Rights Reserved. + * COPYING RESTRICTIONS APPLY, see COPYRIGHT file + */ /* * Modified by Kurt D. Zeilenga for inclusion into OpenLDAP * I hereby disclaim copyright in any changes I have made; this diff --git a/libraries/liblutil/ntservice.c b/libraries/liblutil/ntservice.c index bf6d114b05..57ab8c89f9 100644 --- a/libraries/liblutil/ntservice.c +++ b/libraries/liblutil/ntservice.c @@ -1,3 +1,7 @@ +/* + * Copyright 1998-1999 The OpenLDAP Foundation, All Rights Reserved. + * COPYING RESTRICTIONS APPLY, see COPYRIGHT file + */ /* ntservice.c */ #include "portable.h" diff --git a/libraries/liblutil/passwd.c b/libraries/liblutil/passwd.c index cbe5e6fb13..8fc16c2a01 100644 --- a/libraries/liblutil/passwd.c +++ b/libraries/liblutil/passwd.c @@ -1,3 +1,7 @@ +/* + * Copyright 1998-1999 The OpenLDAP Foundation, All Rights Reserved. + * COPYING RESTRICTIONS APPLY, see COPYRIGHT file + */ /* * lutil_password(credentials, password) * diff --git a/libraries/liblutil/sha1.c b/libraries/liblutil/sha1.c index 7b0d9c4aa6..bdaafda162 100644 --- a/libraries/liblutil/sha1.c +++ b/libraries/liblutil/sha1.c @@ -1,3 +1,7 @@ +/* + * Copyright 1998-1999 The OpenLDAP Foundation, All Rights Reserved. + * COPYING RESTRICTIONS APPLY, see COPYRIGHT file + */ /* Acquired from: * $OpenBSD: sha1.c,v 1.9 1997/07/23 21:12:32 kstailey Exp $ */ diff --git a/libraries/liblutil/utils.c b/libraries/liblutil/utils.c new file mode 100644 index 0000000000..8bd298facf --- /dev/null +++ b/libraries/liblutil/utils.c @@ -0,0 +1,26 @@ +/* + * Copyright 1998-1999 The OpenLDAP Foundation, All Rights Reserved. + * COPYING RESTRICTIONS APPLY, see COPYRIGHT file + */ + +#include "portable.h" + +#include +#include + +#include +#include + +char* lutil_progname( const char* name, int argc, char *argv[] ) +{ + char *progname; + + if(argc == 0) { + return strdup( name ); + } + + progname = strrchr ( argv[0], *LDAP_DIRSEP ); + progname = strdup( progname ? &progname[1] : argv[0] ); + + return progname; +} diff --git a/servers/slapd/back-bdb2/Makefile.in b/servers/slapd/back-bdb2/Makefile.in index 97ce09b7ae..08e30bea34 100644 --- a/servers/slapd/back-bdb2/Makefile.in +++ b/servers/slapd/back-bdb2/Makefile.in @@ -2,12 +2,12 @@ SRCS = idl.c add.c search.c cache.c dbcache.c dn2id.c entry.c id2entry.c \ index.c id2children.c nextid.c abandon.c compare.c group.c \ modify.c modrdn.c delete.c init.c config.c bind.c attr.c \ filterindex.c unbind.c kerberos.c close.c alias.c startup.c \ - timing.c porter.c txn.c + timing.c porter.c txn.c tools.c OBJS = idl.lo add.lo search.lo cache.lo dbcache.lo dn2id.lo entry.lo id2entry.lo \ index.lo id2children.lo nextid.lo abandon.lo compare.lo group.lo \ modify.lo modrdn.lo delete.lo init.lo config.lo bind.lo attr.lo \ filterindex.lo unbind.lo kerberos.lo close.lo alias.lo startup.lo \ - timing.lo porter.lo txn.lo + timing.lo porter.lo txn.lo tools.lo LDAP_INCDIR= ../../../include LDAP_LIBDIR= ../../../libraries diff --git a/servers/slapd/back-bdb2/add.c b/servers/slapd/back-bdb2/add.c index bb495be727..7324cc2e13 100644 --- a/servers/slapd/back-bdb2/add.c +++ b/servers/slapd/back-bdb2/add.c @@ -188,9 +188,6 @@ bdb2i_back_add_internal( Debug( LDAP_DEBUG_ANY, "cache_add_entry_lock failed\n", 0, 0, 0 ); - /* return the id */ - bdb2i_next_id_return( be, e->e_id ); - /* free the entry */ entry_free( e ); @@ -203,28 +200,9 @@ bdb2i_back_add_internal( rc = -1; - /* - * add it to the id2children index for the parent - */ - - bdb2i_start_timing( be->bd_info, &time1 ); - - if ( bdb2i_id2children_add( be, p, e ) != 0 ) { - Debug( LDAP_DEBUG_TRACE, "bdb2i_id2children_add failed\n", 0, - 0, 0 ); - send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, - NULL, NULL, NULL, NULL ); - - bdb2i_stop_timing( be->bd_info, time1, "ADD-ID2CHILDREN", conn, op ); - - goto return_results; - } - - bdb2i_stop_timing( be->bd_info, time1, "ADD-ID2CHILDREN", conn, op ); - /* * Add the entry to the attribute indexes, then add it to - * the id2children index, dn2id index, and the id2entry index. + * the id2entry and dn2id index. */ bdb2i_start_timing( be->bd_info, &time1 ); @@ -317,11 +295,9 @@ bdb2_back_add( /* check, if a new default attribute index will be created, in which case we have to open the index file BEFORE TP */ - switch ( slapMode ) { + switch ( slapMode & SLAP_MODE ) { case SLAP_SERVER_MODE: - case SLAP_TIMEDSERVER_MODE: case SLAP_TOOL_MODE: - case SLAP_TOOLID_MODE: bdb2i_check_default_attr_index_add( li, e ); break; } diff --git a/servers/slapd/back-bdb2/back-bdb2.h b/servers/slapd/back-bdb2/back-bdb2.h index cfcc492425..758318c080 100644 --- a/servers/slapd/back-bdb2/back-bdb2.h +++ b/servers/slapd/back-bdb2/back-bdb2.h @@ -20,11 +20,19 @@ LDAP_BEGIN_DECL #define SUBLEN 3 +#define DN_BASE_PREFIX '=' +#define DN_ONE_PREFIX '@' +#define DN_SUBTREE_PREFIX '?' + +#define SLAPD_FILTER_DN_ONE ((ber_tag_t) -2) +#define SLAPD_FILTER_DN_SUBTREE ((ber_tag_t) -3) + + #define BDB2_SUFFIX ".bdb2" /* - * there is a single index for each attribute. these prefixes insure + * there is a single index for each attribute. these prefixes ensure * that there is no collision among keys. */ #define EQ_PREFIX '=' /* prefix for equality keys */ @@ -32,6 +40,10 @@ LDAP_BEGIN_DECL #define SUB_PREFIX '*' /* prefix for substring keys */ #define CONT_PREFIX '\\' /* prefix for continuation keys */ +/* allow 3 characters per byte + PREFIX + EOS */ +#define CONT_SIZE ( sizeof(long)*3 + 1 + 1 ) + + #define UNKNOWN_PREFIX '?' /* prefix for unknown keys */ #define DEFAULT_BLOCKSIZE 8192 @@ -98,18 +110,19 @@ struct dbcache { }; typedef struct dbcache BDB2_TXN_FILES; +typedef struct dbcache DBCache; /* for the cache of attribute information (which are indexed, etc.) */ struct attrinfo { char *ai_type; /* type name (cn, sn, ...) */ int ai_indexmask; /* how the attr is indexed */ -#define INDEX_PRESENCE 0x01 -#define INDEX_EQUALITY 0x02 -#define INDEX_APPROX 0x04 -#define INDEX_SUB 0x08 -#define INDEX_UNKNOWN 0x10 -#define INDEX_FROMINIT 0x20 +#define INDEX_PRESENCE 0x0001 +#define INDEX_EQUALITY 0x0002 +#define INDEX_APPROX 0x0004 +#define INDEX_SUB 0x0008 +#define INDEX_UNKNOWN 0x0010 +#define INDEX_FROMINIT 0x1000 int ai_syntaxmask; /* what kind of syntax */ /* ...from slap.h... #define SYNTAX_CIS 0x01 @@ -119,12 +132,6 @@ struct attrinfo { */ }; -/* this could be made an option */ -#ifndef SLAPD_NEXTID_CHUNK -#define SLAPD_NEXTID_CHUNK 32 -#endif - - /* TP stuff */ typedef struct _bdb2_txn_head { @@ -178,9 +185,6 @@ extern DB_ENV bdb2i_dbEnv; /* the private description of a database */ struct ldbminfo { ID li_nextid; -#if SLAPD_NEXTID_CHUNK > 1 - ID li_nextid_wrote; -#endif char *li_nextid_file; int li_mode; char *li_directory; diff --git a/servers/slapd/back-bdb2/close.c b/servers/slapd/back-bdb2/close.c index eafdf164f4..894e4dfadc 100644 --- a/servers/slapd/back-bdb2/close.c +++ b/servers/slapd/back-bdb2/close.c @@ -12,6 +12,7 @@ static int bdb2i_back_db_close_internal( BackendDB *be ) { + struct ldbminfo *li = (struct ldbminfo *) be->be_private; DB_LOCK lock; /* since close will probably write the NEXTID file, @@ -20,8 +21,7 @@ bdb2i_back_db_close_internal( BackendDB *be ) return( -1 ); } - if ( slapMode != SLAP_TOOL_MODE ) { - + if ( li->li_nextid != NOID ) { Debug( LDAP_DEBUG_TRACE, "bdb2 backend saving nextid\n", 0, 0, 0 ); if ( bdb2i_next_id_save( be ) < 0 ) { Debug( LDAP_DEBUG_ANY, "bdb2 backend nextid save failed!\n", diff --git a/servers/slapd/back-bdb2/dbcache.c b/servers/slapd/back-bdb2/dbcache.c index e220c91dad..d77e1e772e 100644 --- a/servers/slapd/back-bdb2/dbcache.c +++ b/servers/slapd/back-bdb2/dbcache.c @@ -28,12 +28,10 @@ bdb2i_cache_open( ) { /* all files are open, so return handle from file cache */ - switch ( slapMode ) { + switch ( slapMode & SLAP_MODE ) { case SLAP_SERVER_MODE: - case SLAP_TIMEDSERVER_MODE: case SLAP_TOOL_MODE: - case SLAP_TOOLID_MODE: { struct ldbminfo *li = (struct ldbminfo *) be->be_private; char buf[MAXPATHLEN]; @@ -60,12 +58,9 @@ void bdb2i_cache_close( BackendDB *be, struct dbcache *db ) { /* all files stay open until SERVER or TOOL shut down */ - switch ( slapMode ) { - + switch ( slapMode & SLAP_MODE ) { case SLAP_SERVER_MODE: - case SLAP_TIMEDSERVER_MODE: case SLAP_TOOL_MODE: - case SLAP_TOOLID_MODE: return; default: @@ -81,12 +76,9 @@ void bdb2i_cache_really_close( BackendDB *be, struct dbcache *db ) { /* all files stay open until SERVER or TOOL shut down */ - switch ( slapMode ) { - + switch ( slapMode & SLAP_MODE ) { case SLAP_SERVER_MODE: - case SLAP_TIMEDSERVER_MODE: case SLAP_TOOL_MODE: - case SLAP_TOOLID_MODE: return; default: @@ -102,12 +94,10 @@ void bdb2i_cache_flush_all( BackendDB *be ) { /* if SERVER or TOOL, syncing is done by TP, or during shutdown */ - switch ( slapMode ) { + switch ( slapMode & SLAP_MODE ) { case SLAP_SERVER_MODE: - case SLAP_TIMEDSERVER_MODE: case SLAP_TOOL_MODE: - case SLAP_TOOLID_MODE: return; default: @@ -163,12 +153,12 @@ bdb2i_cache_store( flags, 0, 0, 0, 0 ); #endif /* LDBM_DEBUG */ - if ( slapMode == SLAP_TIMEDSERVER_MODE ) + if ( slapMode & SLAP_TIMED_MODE ) bdb2i_uncond_start_timing( &time1 ); rc = bdb2i_db_store( db->dbc_db, key, data, flags ); - if ( slapMode == SLAP_TIMEDSERVER_MODE ) { + if ( slapMode & SLAP_TIMED_MODE ) { char buf[BUFSIZ]; char buf2[BUFSIZ]; diff --git a/servers/slapd/back-bdb2/delete.c b/servers/slapd/back-bdb2/delete.c index ca36c2bacf..d80d2dceb2 100644 --- a/servers/slapd/back-bdb2/delete.c +++ b/servers/slapd/back-bdb2/delete.c @@ -93,7 +93,7 @@ bdb2i_back_delete_internal( } #endif - /* delete from parent's id2children entry */ + /* find parent's entry */ if( (pdn = dn_parent( be, e->e_ndn )) != NULL ) { if( (p = bdb2i_dn2entry_w( be, pdn, &matched )) == NULL) { Debug( LDAP_DEBUG_TRACE, @@ -125,15 +125,6 @@ bdb2i_back_delete_internal( } } - if ( bdb2i_id2children_remove( be, p, e ) != 0 ) { - Debug(LDAP_DEBUG_ARGS, - "<=- bdb2i_back_delete: operations error %s\n", - dn, 0, 0); - send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, - NULL, NULL, NULL, NULL ); - goto return_results; - } - /* delete from dn2id mapping */ if ( bdb2i_dn2id_delete( be, e->e_ndn ) != 0 ) { Debug(LDAP_DEBUG_ARGS, diff --git a/servers/slapd/back-bdb2/dn2id.c b/servers/slapd/back-bdb2/dn2id.c index 35b1081d2b..b4c17be8fb 100644 --- a/servers/slapd/back-bdb2/dn2id.c +++ b/servers/slapd/back-bdb2/dn2id.c @@ -23,9 +23,6 @@ bdb2i_dn2id_add( Datum key, data; struct ldbminfo *li = (struct ldbminfo *) be->be_private; - ldbm_datum_init( key ); - ldbm_datum_init( data ); - Debug( LDAP_DEBUG_TRACE, "=> bdb2i_dn2id_add( \"%s\", %ld )\n", dn, id, 0 ); if ( (db = bdb2i_cache_open( be, "dn2id", BDB2_SUFFIX, LDBM_WRCREAT )) @@ -35,11 +32,12 @@ bdb2i_dn2id_add( return( -1 ); } - dn = ch_strdup( dn ); - (void) dn_normalize_case( dn ); + ldbm_datum_init( key ); + key.dsize = strlen( dn ) + 2; + key.dptr = ch_malloc( key.dsize ); + sprintf( key.dptr, "%c%s", DN_BASE_PREFIX, dn ); - key.dptr = dn; - key.dsize = strlen( dn ) + 1; + ldbm_datum_init( data ); data.dptr = (char *) &id; data.dsize = sizeof(ID); @@ -48,7 +46,41 @@ bdb2i_dn2id_add( rc = bdb2i_cache_store( db, key, data, flags ); - free( dn ); + free( key.dptr ); + + if ( rc != -1 ) { + char *pdn = dn_parent( NULL, dn ); + + if( pdn != NULL ) { + ldbm_datum_init( key ); + key.dsize = strlen( pdn ) + 2; + key.dptr = ch_malloc( key.dsize ); + sprintf( key.dptr, "%c%s", DN_ONE_PREFIX, pdn ); + rc = bdb2i_idl_insert_key( be, db, key, id ); + free( key.dptr ); + } + } + + if ( rc != -1 ) { + char **subtree = dn_subtree( NULL, dn ); + + if( subtree != NULL ) { + int i; + for( i=0; subtree[i] != NULL; i++ ) { + ldbm_datum_init( key ); + key.dsize = strlen( subtree[i] ) + 2; + key.dptr = ch_malloc( key.dsize ); + sprintf( key.dptr, "%c%s", DN_SUBTREE_PREFIX, subtree[i] ); + + rc = bdb2i_idl_insert_key( be, db, key, id ); + + free( key.dptr ); + } + + charray_free( subtree ); + } + } + bdb2i_cache_close( be, db ); Debug( LDAP_DEBUG_TRACE, "<= bdb2i_dn2id_add %d\n", rc, 0, 0 ); @@ -66,16 +98,10 @@ bdb2i_dn2id( ID id; Datum key, data; - ldbm_datum_init( key ); - ldbm_datum_init( data ); - - dn = ch_strdup( dn ); Debug( LDAP_DEBUG_TRACE, "=> bdb2i_dn2id( \"%s\" )\n", dn, 0, 0 ); - (void) dn_normalize_case( dn ); /* first check the cache */ if ( (id = bdb2i_cache_find_entry_dn2id( be, &li->li_cache, dn )) != NOID ) { - free( dn ); Debug( LDAP_DEBUG_TRACE, "<= bdb2i_dn2id %ld (in cache)\n", id, 0, 0 ); return( id ); @@ -83,19 +109,22 @@ bdb2i_dn2id( if ( (db = bdb2i_cache_open( be, "dn2id", BDB2_SUFFIX, LDBM_WRCREAT )) == NULL ) { - free( dn ); Debug( LDAP_DEBUG_ANY, "<= bdb2i_dn2id could not open dn2id%s\n", BDB2_SUFFIX, 0, 0 ); return( NOID ); } - key.dptr = dn; - key.dsize = strlen( dn ) + 1; + ldbm_datum_init( key ); + + key.dsize = strlen( dn ) + 2; + key.dptr = ch_malloc( key.dsize ); + sprintf( key.dptr, "%c%s", DN_BASE_PREFIX, dn ); data = bdb2i_cache_fetch( db, key ); bdb2i_cache_close( be, db ); - free( dn ); + + free( key.dptr ); if ( data.dptr == NULL ) { Debug( LDAP_DEBUG_TRACE, "<= bdb2i_dn2id NOID\n", 0, 0, 0 ); @@ -110,6 +139,41 @@ bdb2i_dn2id( return( id ); } +ID_BLOCK * +bdb2i_dn2idl( + BackendDB *be, + char *dn, + int prefix ) +{ + struct dbcache *db; + Datum key; + ID_BLOCK *idl; + + Debug( LDAP_DEBUG_TRACE, "=> bdb2i_dn2idl( \"%c%s\" )\n", prefix, dn, 0 ); + + if ( (db = bdb2i_cache_open( be, "dn2id", BDB2_SUFFIX, LDBM_WRCREAT )) + == NULL ) { + Debug( LDAP_DEBUG_ANY, + "<= bdb2i_dn2idl could not open dn2id%s\n", BDB2_SUFFIX, + 0, 0 ); + return( NULL ); + } + + ldbm_datum_init( key ); + + key.dsize = strlen( dn ) + 2; + key.dptr = ch_malloc( key.dsize ); + sprintf( key.dptr, "%c%s", prefix, dn ); + + idl = bdb2i_idl_fetch( be, db, key ); + + free( key.dptr ); + + bdb2i_cache_close( be, db ); + + return( idl ); +} + int bdb2i_dn2id_delete( BackendDB *be, @@ -120,8 +184,6 @@ bdb2i_dn2id_delete( Datum key; int rc; - ldbm_datum_init( key ); - Debug( LDAP_DEBUG_TRACE, "=> bdb2i_dn2id_delete( \"%s\" )\n", dn, 0, 0 ); if ( (db = bdb2i_cache_open( be, "dn2id", BDB2_SUFFIX, LDBM_WRCREAT )) @@ -132,14 +194,15 @@ bdb2i_dn2id_delete( return( -1 ); } - dn = ch_strdup( dn ); - (void) dn_normalize_case( dn ); - key.dptr = dn; - key.dsize = strlen( dn ) + 1; + ldbm_datum_init( key ); + + key.dsize = strlen( dn ) + 2; + key.dptr = ch_malloc( key.dsize ); + sprintf( key.dptr, "%c%s", DN_BASE_PREFIX, dn ); rc = bdb2i_cache_delete( db, key ); - free( dn ); + free( key.dptr ); bdb2i_cache_close( be, db ); diff --git a/servers/slapd/back-bdb2/external.h b/servers/slapd/back-bdb2/external.h index 31d2279601..58da13d224 100644 --- a/servers/slapd/back-bdb2/external.h +++ b/servers/slapd/back-bdb2/external.h @@ -58,6 +58,18 @@ extern int bdb2_back_group LDAP_P(( BackendDB *bd, Entry *target, char* gr_ndn, char* op_ndn, char* objectclassValue, char* groupattrName)); +/* hooks for slap tools */ +extern int bdb2_tool_entry_open LDAP_P(( BackendDB *be, int mode )); +extern int bdb2_tool_entry_close LDAP_P(( BackendDB *be )); +extern ID bdb2_tool_entry_first LDAP_P(( BackendDB *be )); +extern ID bdb2_tool_entry_next LDAP_P(( BackendDB *be )); +extern Entry* bdb2_tool_entry_get LDAP_P(( BackendDB *be, ID id )); +extern ID bdb2_tool_entry_put LDAP_P(( BackendDB *be, Entry *e )); +extern int bdb2_tool_index_attr LDAP_P(( BackendDB *be, char* type )); +extern int bdb2_tool_index_change LDAP_P(( BackendDB *be, char* type, + struct berval **bv, ID id, int op )); +extern int bdb2_tool_sync LDAP_P(( BackendDB *be )); + LDAP_END_DECL #endif /* _BDB2_EXTERNAL_H */ diff --git a/servers/slapd/back-bdb2/filterindex.c b/servers/slapd/back-bdb2/filterindex.c index 32da1d85e7..ad546caa48 100644 --- a/servers/slapd/back-bdb2/filterindex.c +++ b/servers/slapd/back-bdb2/filterindex.c @@ -36,6 +36,16 @@ bdb2i_filter_candidates( result = NULL; switch ( f->f_choice ) { + case SLAPD_FILTER_DN_ONE: + Debug( LDAP_DEBUG_FILTER, "\tDN ONE\n", 0, 0, 0 ); + result = bdb2i_dn2idl( be, f->f_dn, DN_SUBTREE_PREFIX ); + break; + + case SLAPD_FILTER_DN_SUBTREE: + Debug( LDAP_DEBUG_FILTER, "\tDN SUBTREE\n", 0, 0, 0 ); + result = bdb2i_dn2idl( be, f->f_dn, DN_SUBTREE_PREFIX ); + break; + case LDAP_FILTER_EQUALITY: Debug( LDAP_DEBUG_FILTER, "\tEQUALITY\n", 0, 0, 0 ); result = ava_candidates( be, &f->f_ava, LDAP_FILTER_EQUALITY ); diff --git a/servers/slapd/back-bdb2/id2children.c b/servers/slapd/back-bdb2/id2children.c index d4784d5bd8..903418daa6 100644 --- a/servers/slapd/back-bdb2/id2children.c +++ b/servers/slapd/back-bdb2/id2children.c @@ -10,88 +10,6 @@ #include "slap.h" #include "back-bdb2.h" -int -bdb2i_id2children_add( - BackendDB *be, - Entry *p, - Entry *e -) -{ - struct dbcache *db; - Datum key; - char buf[20]; - - ldbm_datum_init( key ); - - Debug( LDAP_DEBUG_TRACE, "=> bdb2i_id2children_add( %ld, %ld )\n", - p ? p->e_id : 0, e->e_id, 0 ); - - if ( (db = bdb2i_cache_open( be, "id2children", BDB2_SUFFIX, - LDBM_WRCREAT )) == NULL ) { - Debug( LDAP_DEBUG_ANY, - "<= bdb2i_id2children_add -1 could not open \"id2children%s\"\n", - BDB2_SUFFIX, 0, 0 ); - return( -1 ); - } - - sprintf( buf, "%c%ld", EQ_PREFIX, p ? p->e_id : 0 ); - key.dptr = buf; - key.dsize = strlen( buf ) + 1; - - if ( bdb2i_idl_insert_key( be, db, key, e->e_id ) != 0 ) { - Debug( LDAP_DEBUG_TRACE, "<= bdb2i_id2children_add -1 (idl_insert)\n", - 0, 0, 0 ); - bdb2i_cache_close( be, db ); - return( -1 ); - } - - bdb2i_cache_close( be, db ); - - Debug( LDAP_DEBUG_TRACE, "<= bdb2i_id2children_add 0\n", 0, 0, 0 ); - return( 0 ); -} - - -int -bdb2i_id2children_remove( - BackendDB *be, - Entry *p, - Entry *e -) -{ - struct dbcache *db; - Datum key; - char buf[20]; - - Debug( LDAP_DEBUG_TRACE, "=> bdb2i_id2children_remove( %ld, %ld )\n", - p ? p->e_id : 0, e->e_id, 0 ); - - if ( (db = bdb2i_cache_open( be, "id2children", BDB2_SUFFIX, - LDBM_WRCREAT )) == NULL ) { - Debug( LDAP_DEBUG_ANY, - "<= bdb2i_id2children_remove -1 could not open \"id2children%s\"\n", - BDB2_SUFFIX, 0, 0 ); - return( -1 ); - } - - ldbm_datum_init( key ); - sprintf( buf, "%c%ld", EQ_PREFIX, p ? p->e_id : 0 ); - key.dptr = buf; - key.dsize = strlen( buf ) + 1; - - if ( bdb2i_idl_delete_key( be, db, key, e->e_id ) != 0 ) { - Debug( LDAP_DEBUG_TRACE, "<= bdb2i_id2children_remove -1 (idl_delete)\n", - 0, 0, 0 ); - bdb2i_cache_close( be, db ); - return( -1 ); - } - - bdb2i_cache_close( be, db ); - - Debug( LDAP_DEBUG_TRACE, "<= bdb2i_id2children_remove 0\n", 0, 0, 0 ); - return( 0 ); -} - int bdb2i_has_children( BackendDB *be, @@ -102,26 +20,27 @@ bdb2i_has_children( Datum key; int rc = 0; ID_BLOCK *idl; - char buf[20]; ldbm_datum_init( key ); Debug( LDAP_DEBUG_TRACE, "=> bdb2i_has_children( %ld )\n", p->e_id , 0, 0 ); - if ( (db = bdb2i_cache_open( be, "id2children", BDB2_SUFFIX, + if ( (db = bdb2i_cache_open( be, "dn2id", BDB2_SUFFIX, LDBM_WRCREAT )) == NULL ) { Debug( LDAP_DEBUG_ANY, - "<= bdb2i_has_children -1 could not open \"id2children%s\"\n", - BDB2_SUFFIX, 0, 0 ); + "<= bdb2i_has_children: could not open \"dn2id" BDB2_SUFFIX "\"\n", + 0, 0, 0 ); return( 0 ); } - sprintf( buf, "%c%ld", EQ_PREFIX, p->e_id ); - key.dptr = buf; - key.dsize = strlen( buf ) + 1; + key.dsize = strlen( p->e_ndn ) + 2; + key.dptr = ch_malloc( key.dsize ); + sprintf( key.dptr, "%c%s", DN_ONE_PREFIX, p->e_ndn ); idl = bdb2i_idl_fetch( be, db, key ); + free( key.dptr ); + bdb2i_cache_close( be, db ); if( idl != NULL ) { diff --git a/servers/slapd/back-bdb2/id2entry.c b/servers/slapd/back-bdb2/id2entry.c index a2cc63690c..c7bf18e5c0 100644 --- a/servers/slapd/back-bdb2/id2entry.c +++ b/servers/slapd/back-bdb2/id2entry.c @@ -39,7 +39,7 @@ bdb2i_id2entry_add( BackendDB *be, Entry *e ) key.dsize = sizeof(ID); ldap_pvt_thread_mutex_lock( &entry2str_mutex ); - data.dptr = entry2str( e, &len, 1 ); + data.dptr = entry2str( e, &len ); data.dsize = len + 1; /* store it */ @@ -150,13 +150,7 @@ bdb2i_id2entry_rw( BackendDB *be, ID id, int rw ) return( NULL ); } - if ( e->e_id != id ) { - Debug( LDAP_DEBUG_TRACE, - "<= bdb2i_id2entry_%s( %ld ) (wrong id %ld on disk)\n", - rw ? "w" : "r", id, e->e_id ); - entry_free( e ); - return( NULL ); - } + e->e_id = id; if ( bdb2i_cache_add_entry_rw( &li->li_cache, e, rw ) != 0 ) { entry_free( e ); diff --git a/servers/slapd/back-bdb2/idl.c b/servers/slapd/back-bdb2/idl.c index 5b000f308e..f6718dc4b4 100644 --- a/servers/slapd/back-bdb2/idl.c +++ b/servers/slapd/back-bdb2/idl.c @@ -139,12 +139,13 @@ bdb2i_idl_fetch( tmp = (ID_BLOCK **) ch_malloc( (i + 1) * sizeof(ID_BLOCK *) ); /* read in all the blocks */ - kstr = (char *) ch_malloc( key.dsize + 20 ); + kstr = (char *) ch_malloc( key.dsize + CONT_SIZE ); nids = 0; for ( i = 0; !ID_BLOCK_NOID(idl, i); i++ ) { ldbm_datum_init( data ); - sprintf( kstr, "%c%s%ld", CONT_PREFIX, key.dptr, ID_BLOCK_ID(idl, i) ); + sprintf( kstr, "%c%ld%s", CONT_PREFIX, + ID_BLOCK_ID(idl, i), key.dptr ); data.dptr = kstr; data.dsize = strlen( kstr ) + 1; @@ -298,7 +299,8 @@ idl_change_first( } /* write block with new key */ - sprintf( bkey.dptr, "%c%s%ld", CONT_PREFIX, hkey.dptr, ID_BLOCK_ID(b, 0) ); + sprintf( bkey.dptr, "%c%ld%s", CONT_PREFIX, + ID_BLOCK_ID(b, 0), hkey.dptr ); bkey.dsize = strlen( bkey.dptr ) + 1; if ( (rc = idl_store( be, db, bkey, b )) != 0 ) { Debug( LDAP_DEBUG_ANY, @@ -389,16 +391,16 @@ bdb2i_idl_insert_key( rc = idl_store( be, db, key, idl ); /* store the first id block */ - kstr = (char *) ch_malloc( key.dsize + 20 ); - sprintf( kstr, "%c%s%ld", CONT_PREFIX, key.dptr, - ID_BLOCK_ID(tmp, 0) ); + kstr = (char *) ch_malloc( key.dsize + CONT_SIZE ); + sprintf( kstr, "%c%ld%s", CONT_PREFIX, + ID_BLOCK_ID(tmp, 0), key.dptr ); k2.dptr = kstr; k2.dsize = strlen( kstr ) + 1; rc = idl_store( be, db, k2, tmp ); /* store the second id block */ - sprintf( kstr, "%c%s%ld", CONT_PREFIX, key.dptr, - ID_BLOCK_ID(tmp2, 0) ); + sprintf( kstr, "%c%ld%s", CONT_PREFIX, + ID_BLOCK_ID(tmp2, 0), key.dptr ); k2.dptr = kstr; k2.dsize = strlen( kstr ) + 1; rc = idl_store( be, db, k2, tmp2 ); @@ -432,8 +434,9 @@ bdb2i_idl_insert_key( } /* get the block */ - kstr = (char *) ch_malloc( key.dsize + 20 ); - sprintf( kstr, "%c%s%ld", CONT_PREFIX, key.dptr, ID_BLOCK_ID(idl, i) ); + kstr = (char *) ch_malloc( key.dsize + CONT_SIZE ); + sprintf( kstr, "%c%ld%s", CONT_PREFIX, + ID_BLOCK_ID(idl, i), key.dptr ); k2.dptr = kstr; k2.dsize = strlen( kstr ) + 1; if ( (tmp = idl_fetch_one( be, db, k2 )) == NULL ) { @@ -477,8 +480,8 @@ bdb2i_idl_insert_key( /* is there a next block? */ if ( !first && !ID_BLOCK_NOID(idl, i + 1) ) { /* read it in */ - sprintf( kstr, "%c%s%ld", CONT_PREFIX, key.dptr, - ID_BLOCK_ID(idl, i + 1) ); + sprintf( kstr, "%c%ld%s", CONT_PREFIX, + ID_BLOCK_ID(idl, i + 1), key.dptr ); k2.dptr = kstr; k2.dsize = strlen( kstr ) + 1; if ( (tmp2 = idl_fetch_one( be, db, k2 )) == NULL ) { @@ -535,8 +538,8 @@ bdb2i_idl_insert_key( /* delete all indirect blocks */ for ( j = 0; !ID_BLOCK_NOID(idl, j); j++ ) { - sprintf( kstr, "%c%s%ld", CONT_PREFIX, key.dptr, - ID_BLOCK_ID(idl, j) ); + sprintf( kstr, "%c%ld%s", CONT_PREFIX, + ID_BLOCK_ID(idl, j), key.dptr ); k2.dptr = kstr; k2.dsize = strlen( kstr ) + 1; @@ -578,15 +581,15 @@ bdb2i_idl_insert_key( rc = idl_store( be, db, key, tmp ); /* store the first id block */ - sprintf( kstr, "%c%s%ld", CONT_PREFIX, key.dptr, - ID_BLOCK_ID(tmp2, 0) ); + sprintf( kstr, "%c%ld%s", CONT_PREFIX, + ID_BLOCK_ID(tmp2, 0), key.dptr ); k2.dptr = kstr; k2.dsize = strlen( kstr ) + 1; rc = idl_store( be, db, k2, tmp2 ); /* store the second id block */ - sprintf( kstr, "%c%s%ld", CONT_PREFIX, key.dptr, - ID_BLOCK_ID(tmp3, 0) ); + sprintf( kstr, "%c%ld%s", CONT_PREFIX, + ID_BLOCK_ID(tmp3, 0), key.dptr ); k2.dptr = kstr; k2.dsize = strlen( kstr ) + 1; rc = idl_store( be, db, k2, tmp3 ); @@ -715,11 +718,11 @@ bdb2i_idl_delete_key ( */ for ( nids = 0; !ID_BLOCK_NOID(idl, nids); nids++ ) ; /* NULL */ - kstr = (char *) ch_malloc( key.dsize + 20 ); + kstr = (char *) ch_malloc( key.dsize + CONT_SIZE ); for ( j = 0; !ID_BLOCK_NOID(idl, j); j++ ) { ldbm_datum_init( data ); - sprintf( kstr, "%c%s%ld", CONT_PREFIX, key.dptr, ID_BLOCK_ID(idl, j) ); + sprintf( kstr, "%c%ld%s", CONT_PREFIX, ID_BLOCK_ID(idl, j), key.dptr ); data.dptr = kstr; data.dsize = strlen( kstr ) + 1; diff --git a/servers/slapd/back-bdb2/index.c b/servers/slapd/back-bdb2/index.c index 5e2a97ad32..0338712c70 100644 --- a/servers/slapd/back-bdb2/index.c +++ b/servers/slapd/back-bdb2/index.c @@ -108,8 +108,8 @@ bdb2i_index_read( ldbm_datum_init( key ); prefix = index2prefix( indextype ); - Debug( LDAP_DEBUG_TRACE, "=> bdb2i_index_read( \"%s\" \"%c\" \"%s\" )\n", - type, prefix, val ); + Debug( LDAP_DEBUG_TRACE, "=> bdb2i_index_read( \"%c%s\" -> \"%s\" )\n", + prefix, type, val ); bdb2i_attr_masks( be->be_private, type, &indexmask, &syntax ); if ( ! (indextype & indexmask) ) { @@ -143,6 +143,7 @@ bdb2i_index_read( tmpval = (char *) ch_malloc( len + 2 ); realval = tmpval; } + realval[0] = prefix; strcpy( &realval[1], val ); } @@ -238,8 +239,8 @@ bdb2i_index_add_values( return 0; } - Debug( LDAP_DEBUG_TRACE, "=> bdb2i_index_add_values( \"%s\", %ld )\n", type, - id, 0 ); + Debug( LDAP_DEBUG_TRACE, "=> bdb2i_index_add_values( \"%s\", %ld )\n", + type, id, 0 ); attr_normalize( type ); bdb2i_attr_masks( be->be_private, type, &indexmask, &syntax ); if ( indexmask == 0 ) { diff --git a/servers/slapd/back-bdb2/init.c b/servers/slapd/back-bdb2/init.c index 231994a595..3977fc5e20 100644 --- a/servers/slapd/back-bdb2/init.c +++ b/servers/slapd/back-bdb2/init.c @@ -38,7 +38,7 @@ bdb2i_back_init_private( bt->lty_dbhome = DEFAULT_DB_HOME; bt->lty_mpsize = DEFAULT_DBCACHE_SIZE; - if ( slapMode == SLAP_TIMEDSERVER_MODE ) + if ( slapMode & SLAP_TIMED_MODE ) bt->lty_betiming = 1; bi->bi_private = bt; @@ -78,6 +78,19 @@ bdb2_back_initialize( bi->bi_entry_release_rw = bdb2_back_entry_release_rw; bi->bi_acl_group = bdb2_back_group; + /* + * hooks for slap tools + */ + bi->bi_tool_entry_open = bdb2_tool_entry_open; + bi->bi_tool_entry_close = bdb2_tool_entry_close; + bi->bi_tool_entry_first = bdb2_tool_entry_first; + bi->bi_tool_entry_next = bdb2_tool_entry_next; + bi->bi_tool_entry_get = bdb2_tool_entry_get; + bi->bi_tool_entry_put = bdb2_tool_entry_put; + bi->bi_tool_index_attr = bdb2_tool_index_attr; + bi->bi_tool_index_change = bdb2_tool_index_change; + bi->bi_tool_sync = bdb2_tool_sync; + bi->bi_connection_init = 0; bi->bi_connection_destroy = 0; @@ -164,27 +177,11 @@ bdb2i_back_db_init_internal( /* default database directory */ li->li_directory = DEFAULT_DB_DIRECTORY; - /* always index dn, id2children, objectclass (used in some searches) */ - if ( !at_find( "dn" ) ) { - argv[ 0 ] = "dn"; - argv[ 1 ] = "dn"; - argv[ 2 ] = NULL; - attr_syntax_config( "ldbm dn initialization", 0, 2, argv ); - } - argv[ 0 ] = "dn"; - argv[ 1 ] = "eq,sub"; - argv[ 2 ] = NULL; - bdb2i_attr_index_config( li, "ldbm dn initialization", 0, 2, argv, 1 ); - argv[ 0 ] = "id2children"; - argv[ 1 ] = "eq"; - argv[ 2 ] = NULL; - bdb2i_attr_index_config( li, "ldbm id2children initialization", 0, 2, argv, - 1 ); argv[ 0 ] = "objectclass"; argv[ 1 ] = "pres,eq"; argv[ 2 ] = NULL; - bdb2i_attr_index_config( li, "ldbm objectclass initialization", 0, 2, argv, - 1 ); + bdb2i_attr_index_config( li, "ldbm objectclass initialization", + 0, 2, argv, 1 ); /* initialize the cache mutex */ ldap_pvt_thread_mutex_init( &li->li_cache.c_mutex ); diff --git a/servers/slapd/back-bdb2/modify.c b/servers/slapd/back-bdb2/modify.c index ef263e7ed6..1e4a62d9a3 100644 --- a/servers/slapd/back-bdb2/modify.c +++ b/servers/slapd/back-bdb2/modify.c @@ -145,11 +145,9 @@ bdb2_back_modify( /* check, if a new default attribute index will be created, in which case we have to open the index file BEFORE TP */ - switch ( slapMode ) { + switch ( slapMode & SLAP_MODE ) { case SLAP_SERVER_MODE: - case SLAP_TIMEDSERVER_MODE: case SLAP_TOOL_MODE: - case SLAP_TOOLID_MODE: bdb2i_check_default_attr_index_mod( li, modlist ); break; } @@ -314,7 +312,7 @@ bdb2i_replace_values( { (void) attr_delete( &e->e_attrs, mod->mod_type ); - if ( mod->bvalues != NULL && + if ( mod->mod_bvalues != NULL && attr_merge( e, mod->mod_type, mod->mod_bvalues ) != 0 ) { return( LDAP_CONSTRAINT_VIOLATION ); diff --git a/servers/slapd/back-bdb2/nextid.c b/servers/slapd/back-bdb2/nextid.c index 0218cfd784..91cb5e360a 100644 --- a/servers/slapd/back-bdb2/nextid.c +++ b/servers/slapd/back-bdb2/nextid.c @@ -26,9 +26,6 @@ bdb2i_next_id_save( BackendDB *be ) int rc; rc = next_id_write( be, id ); - if (rc == 0) { - li->li_nextid_wrote = id; - } return rc; } @@ -46,44 +43,15 @@ bdb2i_next_id( BackendDB *be ) if ( li->li_nextid == NOID ) { li->li_nextid = 1; } - -#if SLAPD_NEXTID_CHUNK > 1 - li->li_nextid_wrote = li->li_nextid; -#endif } id = li->li_nextid++; -#if SLAPD_NEXTID_CHUNK > 1 - if ( li->li_nextid > li->li_nextid_wrote ) { - li->li_nextid_wrote += SLAPD_NEXTID_CHUNK; - (void) next_id_write( be, li->li_nextid_wrote ); - } -#else (void) next_id_write( be, li->li_nextid ); -#endif return( id ); } -void -bdb2i_next_id_return( BackendDB *be, ID id ) -{ -#ifdef SLAPD_NEXTID_RETURN - struct ldbminfo *li = (struct ldbminfo *) be->be_private; - - if ( id != li->li_nextid - 1 ) { - return; - } - - li->li_nextid--; - -#if !( SLAPD_NEXTID_CHUNK > 1 ) - (void) next_id_write( be, li->li_nextid ); -#endif -#endif -} - ID bdb2i_next_id_get( BackendDB *be ) { @@ -97,10 +65,6 @@ bdb2i_next_id_get( BackendDB *be ) if ( li->li_nextid == NOID ) { li->li_nextid = 1; } - -#if SLAPD_NEXTID_CHUNK > 1 - li->li_nextid_wrote = li->li_nextid; -#endif } id = li->li_nextid; diff --git a/servers/slapd/back-bdb2/porter.c b/servers/slapd/back-bdb2/porter.c index 26e3610773..8dba543e7c 100644 --- a/servers/slapd/back-bdb2/porter.c +++ b/servers/slapd/back-bdb2/porter.c @@ -21,12 +21,10 @@ bdb2i_enter_backend_rw( DB_LOCK *lock, int writer ) DBT lock_dbt; int ret = 0; - switch ( slapMode ) { + switch ( slapMode & SLAP_MODE ) { case SLAP_SERVER_MODE: - case SLAP_TIMEDSERVER_MODE: case SLAP_TOOL_MODE: - case SLAP_TOOLID_MODE: if ( ( ret = lock_id( bdb2i_dbEnv.lk_info, &locker )) != 0 ) { Debug( LDAP_DEBUG_ANY, @@ -103,12 +101,10 @@ bdb2i_leave_backend_rw( DB_LOCK lock, int writer ) ret_transaction |= bdb2i_set_txn_checkpoint( bdb2i_dbEnv.tx_info, 0 ); /* now release the lock */ - switch ( slapMode ) { + switch ( slapMode & SLAP_MODE ) { case SLAP_SERVER_MODE: - case SLAP_TIMEDSERVER_MODE: case SLAP_TOOL_MODE: - case SLAP_TOOLID_MODE: switch( ( ret_lock = lock_put( bdb2i_dbEnv.lk_info, lock ))) { case 0: diff --git a/servers/slapd/back-bdb2/proto-back-bdb2.h b/servers/slapd/back-bdb2/proto-back-bdb2.h index f0583e1f14..7f1042202d 100644 --- a/servers/slapd/back-bdb2/proto-back-bdb2.h +++ b/servers/slapd/back-bdb2/proto-back-bdb2.h @@ -77,6 +77,12 @@ int bdb2i_dn2id_add LDAP_P(( BackendDB *be, char *dn, ID id )); ID bdb2i_dn2id LDAP_P(( BackendDB *be, char *dn )); int bdb2i_dn2id_delete LDAP_P(( BackendDB *be, char *dn )); +ID_BLOCK * +bdb2i_dn2idl LDAP_P(( + BackendDB *be, + char *dn, + int prefix )); + Entry * bdb2i_dn2entry_rw LDAP_P(( BackendDB *be, char *dn, @@ -101,8 +107,6 @@ ID_BLOCK * bdb2i_filter_candidates LDAP_P(( BackendDB *be, Filter *f )); * id2children.c */ -int bdb2i_id2children_add LDAP_P(( BackendDB *be, Entry *p, Entry *e )); -int bdb2i_id2children_remove LDAP_P(( BackendDB *be, Entry *p, Entry *e )); int bdb2i_has_children LDAP_P(( BackendDB *be, Entry *p )); /* diff --git a/servers/slapd/back-bdb2/search.c b/servers/slapd/back-bdb2/search.c index 9117aeafb9..9b5dc6d3de 100644 --- a/servers/slapd/back-bdb2/search.c +++ b/servers/slapd/back-bdb2/search.c @@ -437,28 +437,20 @@ search_candidates( lf->f_choice = LDAP_FILTER_AND; lf->f_and = (Filter *) ch_malloc( sizeof(Filter) ); - lf->f_and->f_choice = LDAP_FILTER_SUBSTRINGS; - lf->f_and->f_sub_type = ch_strdup( "dn" ); - lf->f_and->f_sub_initial = NULL; - lf->f_and->f_sub_any = NULL; - lf->f_and->f_sub_final = ch_strdup( e->e_ndn ); + lf->f_and->f_choice = SLAPD_FILTER_DN_SUBTREE; + lf->f_and->f_dn = e->e_ndn; lf->f_and->f_next = f; f = lf; } else if ( scope == LDAP_SCOPE_ONELEVEL ) { - char buf[16]; - lf = (Filter *) ch_malloc( sizeof(Filter) ); lf->f_next = NULL; lf->f_choice = LDAP_FILTER_AND; lf->f_and = (Filter *) ch_malloc( sizeof(Filter) ); - lf->f_and->f_choice = LDAP_FILTER_EQUALITY; - lf->f_and->f_ava.ava_type = ch_strdup( "id2children" ); - sprintf( buf, "%ld", e != NULL ? e->e_id : 0 ); - lf->f_and->f_ava.ava_value.bv_val = ch_strdup( buf ); - lf->f_and->f_ava.ava_value.bv_len = strlen( buf ); + lf->f_and->f_choice = SLAPD_FILTER_DN_ONE; + lf->f_and->f_dn = e->e_ndn; lf->f_and->f_next = f; f = lf; @@ -471,8 +463,8 @@ search_candidates( /* free up filter additions we allocated above */ if( lf != NULL ) { - lf->f_and->f_next = NULL; - filter_free( lf ); + free( lf->f_and ); + free( lf ); } if( af != NULL ) { diff --git a/servers/slapd/back-bdb2/tools.c b/servers/slapd/back-bdb2/tools.c new file mode 100644 index 0000000000..5d92b1a6e8 --- /dev/null +++ b/servers/slapd/back-bdb2/tools.c @@ -0,0 +1,248 @@ +/* tools.c - tools for slap tools */ +/* + * Copyright 1998-1999 The OpenLDAP Foundation, All Rights Reserved. + * COPYING RESTRICTIONS APPLY, see COPYRIGHT file + */ + +#include "portable.h" + +#include + +#include + +#include "slap.h" +#include "back-bdb2.h" + +static LDBMCursor *cursorp = NULL; +static DBCache *id2entry = NULL; + +int bdb2_tool_entry_open( + BackendDB *be, int mode ) +{ + struct ldbminfo *li = (struct ldbminfo *) be->be_private; + int flags; + + assert( slapMode & SLAP_TOOL_MODE ); + assert( id2entry == NULL ); + + switch( mode ) { + case 1: + flags = LDBM_WRCREAT; + break; + case 2: +#ifdef TRUNCATE_MODE + flags = LDBM_NEWDB; +#else + flags = LDBM_WRCREAT; +#endif + break; + default: + flags = LDBM_READER; + } + + li->li_dbcachewsync = 0; + + if ( (id2entry = bdb2i_cache_open( be, "id2entry", BDB2_SUFFIX, flags )) + == NULL ) { + Debug( LDAP_DEBUG_ANY, "Could not open/create id2entry" BDB2_SUFFIX "\n", + 0, 0, 0 ); + return( -1 ); + } + + return 0; +} + +int bdb2_tool_entry_close( + BackendDB *be ) +{ + struct ldbminfo *li = (struct ldbminfo *) be->be_private; + + assert( slapMode & SLAP_TOOL_MODE ); + assert( id2entry != NULL ); + + bdb2i_cache_close( be, id2entry ); + li->li_dbcachewsync = 1; + id2entry = NULL; + + return 0; +} + +ID bdb2_tool_entry_first( + BackendDB *be ) +{ + Datum key; + ID id; + + assert( slapMode & SLAP_TOOL_MODE ); + assert( id2entry != NULL ); + + key = ldbm_firstkey( id2entry->dbc_db, &cursorp ); + + if( key.dptr == NULL ) { + return NOID; + } + + memcpy( &id, key.dptr, key.dsize ); + + ldbm_datum_free( id2entry->dbc_db, key ); + + return id; +} + +ID bdb2_tool_entry_next( + BackendDB *be ) +{ + Datum key; + ID id; + int count; + + assert( slapMode & SLAP_TOOL_MODE ); + assert( id2entry != NULL ); + + /* allow for NEXTID */ + ldbm_datum_init( key ); + + key = ldbm_nextkey( id2entry->dbc_db, key, cursorp ); + + if( key.dptr == NULL ) { + return NOID; + } + + memcpy( &id, key.dptr, key.dsize ); + + ldbm_datum_free( id2entry->dbc_db, key ); + + return id; +} + +Entry* bdb2_tool_entry_get( BackendDB *be, ID id ) +{ + Entry *e; + Datum key, data; + assert( slapMode & SLAP_TOOL_MODE ); + assert( id2entry != NULL ); + + ldbm_datum_init( key ); + + key.dptr = (char *) &id; + key.dsize = sizeof(ID); + + data = bdb2i_cache_fetch( id2entry, key ); + + if ( data.dptr == NULL ) { + return NULL; + } + + e = str2entry( data.dptr ); + ldbm_datum_free( id2entry->dbc_db, data ); + + return e; +} + +ID bdb2_tool_entry_put( + BackendDB *be, + Entry *e ) +{ + struct ldbminfo *li = (struct ldbminfo *) be->be_private; + Datum key, data; + int rc, len; + + assert( slapMode & SLAP_TOOL_MODE ); + assert( id2entry != NULL ); + + if( bdb2i_next_id_get( be ) == NOID ) { + return NOID; + } + + e->e_id = li->li_nextid++; + + Debug( LDAP_DEBUG_TRACE, "=> bdb2_tool_entry_put( %ld, \"%s\" )\n", + e->e_id, e->e_dn, 0 ); + + rc = bdb2i_index_add_entry( be, e ); + + if( rc != 0 ) { + return NOID; + } + + rc = bdb2i_dn2id_add( be, e->e_ndn, e->e_id ); + + if( rc != 0 ) { + return NOID; + } + + ldbm_datum_init( key ); + ldbm_datum_init( data ); + + key.dptr = (char *) &e->e_id; + key.dsize = sizeof(ID); + + data.dptr = entry2str( e, &len ); + data.dsize = len + 1; + + /* store it */ + rc = bdb2i_cache_store( id2entry, key, data, LDBM_REPLACE ); + + if( rc != 0 ) { + (void) bdb2i_dn2id_delete( be, e->e_ndn ); + return NOID; + } + + return e->e_id; +} + +int bdb2_tool_index_attr( + BackendDB *be, + char* type ) +{ + static DBCache *db = NULL; + int indexmask, syntaxmask; + char * at_cn; + + assert( slapMode & SLAP_TOOL_MODE ); + + bdb2i_attr_masks( be->be_private, type, &indexmask, &syntaxmask ); + + attr_normalize( type ); + at_cn = at_canonical_name( type ); + + if ( (db = bdb2i_cache_open( be, at_cn, LDBM_SUFFIX, LDBM_NEWDB )) + == NULL ) { + Debug( LDAP_DEBUG_ANY, + "<= index_read NULL (could not open %s%s)\n", at_cn, + BDB2_SUFFIX, 0 ); + return( NULL ); + } + + bdb2i_cache_close( be, db ); + + return indexmask != 0; +} + +int bdb2_tool_index_change( + BackendDB *be, + char* type, + struct berval **bv, + ID id, + int op ) +{ + assert( slapMode & SLAP_TOOL_MODE ); + + bdb2i_index_add_values( be, + type, bv, id ); + + return 0; +} + +int bdb2_tool_sync( BackendDB *be ) +{ + struct ldbminfo *li = (struct ldbminfo *) be->be_private; + + assert( slapMode & SLAP_TOOL_MODE ); + + if ( li->li_nextid != NOID ) { + bdb2i_next_id_save( be ); + } + + return 0; +} diff --git a/servers/slapd/back-bdb2/txn.c b/servers/slapd/back-bdb2/txn.c index 4cf75de346..747a754cce 100644 --- a/servers/slapd/back-bdb2/txn.c +++ b/servers/slapd/back-bdb2/txn.c @@ -7,6 +7,14 @@ #endif #include "txn.h" +/* default DB files */ +char *bdb2i_fixed_filenames[] = { + "id2entry", + "dn2id", + "objectclass", + NULL +}; + int bdb2i_txn_head_init( BDB2_TXN_HEAD *head ) @@ -17,20 +25,19 @@ bdb2i_txn_head_init( BDB2_TXN_HEAD *head ) /* for each fixed DB file allocate a file descriptor node and initialize the file's name */ fileNodeH = &head->dbFiles; - for ( dbFile = BDB2_DB_DN_FILE; dbFile <= BDB2_DB_OC_IDX_FILE; dbFile++ ) { + for ( dbFile = 0; bdb2i_fixed_filenames[dbFile] != NULL; dbFile++ ) { char fileName[MAXPATHLEN]; *fileNodeH = (BDB2_TXN_FILES *) ch_calloc( 1, sizeof( BDB2_TXN_FILES )); - if ( *fileNodeH == NULL ) { + if ( *fileNodeH == NULL ) { Debug( LDAP_DEBUG_ANY, "bdb2i_txn_head_init(): out of memory!\n", 0, 0, 0 ); return( 1 ); - } - sprintf( fileName, "%s%s", bdb2i_fixed_filenames[dbFile], BDB2_SUFFIX ); + sprintf( fileName, "%s" BDB2_SUFFIX, bdb2i_fixed_filenames[dbFile] ); (*fileNodeH)->dbc_name = ch_strdup( fileName ); fileNodeH = &(*fileNodeH)->next; diff --git a/servers/slapd/back-bdb2/txn.h b/servers/slapd/back-bdb2/txn.h index b8ebc3aa7b..93a43ebc21 100644 --- a/servers/slapd/back-bdb2/txn.h +++ b/servers/slapd/back-bdb2/txn.h @@ -46,13 +46,6 @@ ldap_pvt_thread_mutex_t txn_dirty_mutex; #define NEXTID_RECNO (db_recno_t) 1 -/* default DB files */ -char *bdb2i_fixed_filenames[] = { - - "dn", "dn2id", "id2entry", "id2children", "objectclass" - - }; - #endif /* _BDB2_TXN_H_ */ diff --git a/servers/slapd/back-ldbm/Makefile.in b/servers/slapd/back-ldbm/Makefile.in index 80c2fad6f8..3a88ae1c3b 100644 --- a/servers/slapd/back-ldbm/Makefile.in +++ b/servers/slapd/back-ldbm/Makefile.in @@ -1,11 +1,11 @@ -SRCS = idl.c add.c search.c cache.c dbcache.c dn2id.c entry.c id2entry.c \ +SRCS = idl.c add.c search.c cache.c dbcache.c dn2id.c entry.c id2entry.c \ index.c id2children.c nextid.c abandon.c compare.c group.c \ modify.c modrdn.c delete.c init.c config.c bind.c attr.c \ - filterindex.c unbind.c kerberos.c close.c alias.c -OBJS = idl.lo add.lo search.lo cache.lo dbcache.lo dn2id.lo entry.lo id2entry.lo \ + filterindex.c unbind.c kerberos.c close.c alias.c tools.c +OBJS = idl.lo add.lo search.lo cache.lo dbcache.lo dn2id.lo entry.lo id2entry.lo \ index.lo id2children.lo nextid.lo abandon.lo compare.lo group.lo \ modify.lo modrdn.lo delete.lo init.lo config.lo bind.lo attr.lo \ - filterindex.lo unbind.lo kerberos.lo close.lo alias.lo + filterindex.lo unbind.lo kerberos.lo close.lo alias.lo tools.lo LDAP_INCDIR= ../../../include LDAP_LIBDIR= ../../../libraries diff --git a/servers/slapd/back-ldbm/add.c b/servers/slapd/back-ldbm/add.c index a3ff1feca5..8775e29514 100644 --- a/servers/slapd/back-ldbm/add.c +++ b/servers/slapd/back-ldbm/add.c @@ -211,9 +211,6 @@ ldbm_back_add( Debug( LDAP_DEBUG_ANY, "cache_add_entry_lock failed\n", 0, 0, 0 ); - /* return the id */ - next_id_return( be, e->e_id ); - /* free the entry */ entry_free( e ); @@ -226,20 +223,6 @@ ldbm_back_add( rc = -1; -#ifndef DN_INDICES - /* - * add it to the id2children index for the parent - */ - if ( id2children_add( be, p, e ) != 0 ) { - Debug( LDAP_DEBUG_TRACE, "id2children_add failed\n", 0, - 0, 0 ); - send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, - NULL, NULL, NULL, NULL ); - - goto return_results; - } -#endif - /* * Add the entry to the attribute indexes, then add it to * the id2children index, dn2id index, and the id2entry index. diff --git a/servers/slapd/back-ldbm/back-ldbm.h b/servers/slapd/back-ldbm/back-ldbm.h index 2b699eba9f..9a68e0e2d1 100644 --- a/servers/slapd/back-ldbm/back-ldbm.h +++ b/servers/slapd/back-ldbm/back-ldbm.h @@ -24,7 +24,6 @@ LDAP_BEGIN_DECL #define SUBLEN 3 -/* #undef DN_INDICES *//* generate dn eq, subtree, and parent indices */ #define DN_BASE_PREFIX '=' #define DN_ONE_PREFIX '@' #define DN_SUBTREE_PREFIX '?' @@ -44,8 +43,6 @@ LDAP_BEGIN_DECL /* allow 3 characters per byte + PREFIX + EOS */ #define CONT_SIZE ( sizeof(long)*3 + 1 + 1 ) -/* #undef CONT_POSTFIX *//* postfix original key */ - #define UNKNOWN_PREFIX '?' /* prefix for unknown keys */ #define DEFAULT_BLOCKSIZE 8192 @@ -131,20 +128,11 @@ typedef struct ldbm_attrinfo { #define MAXDBCACHE 16 -/* this could be made an option */ -#ifndef SLAPD_NEXTID_CHUNK -#define SLAPD_NEXTID_CHUNK 32 -#endif - struct ldbminfo { ID li_nextid; -#if SLAPD_NEXTID_CHUNK > 1 - ID li_nextid_wrote; -#endif - char *li_nextid_file; + ldap_pvt_thread_mutex_t li_nextid_mutex; ldap_pvt_thread_mutex_t li_root_mutex; ldap_pvt_thread_mutex_t li_add_mutex; - ldap_pvt_thread_mutex_t li_nextid_mutex; int li_mode; char *li_directory; Cache li_cache; diff --git a/servers/slapd/back-ldbm/backldbm.dsp b/servers/slapd/back-ldbm/backldbm.dsp index c9d2a5faf7..377cc8ad3c 100644 --- a/servers/slapd/back-ldbm/backldbm.dsp +++ b/servers/slapd/back-ldbm/backldbm.dsp @@ -240,6 +240,10 @@ SOURCE=.\startup.c # End Source File # Begin Source File +SOURCE=.\tools.c +# End Source File +# Begin Source File + SOURCE=.\unbind.c # End Source File # End Target diff --git a/servers/slapd/back-ldbm/close.c b/servers/slapd/back-ldbm/close.c index f5e5442aa5..fe03f78404 100644 --- a/servers/slapd/back-ldbm/close.c +++ b/servers/slapd/back-ldbm/close.c @@ -16,11 +16,6 @@ int ldbm_back_db_close( Backend *be ) { - Debug( LDAP_DEBUG_TRACE, "ldbm backend saving nextid\n", 0, 0, 0 ); - if ( next_id_save( be ) < 0 ) { - Debug( LDAP_DEBUG_ANY, "ldbm backend nextid save failed!\n", 0, 0, 0 ); - } - Debug( LDAP_DEBUG_TRACE, "ldbm backend syncing\n", 0, 0, 0 ); ldbm_cache_flush_all( be ); Debug( LDAP_DEBUG_TRACE, "ldbm backend done syncing\n", 0, 0, 0 ); diff --git a/servers/slapd/back-ldbm/config.c b/servers/slapd/back-ldbm/config.c index 8df6e46fa1..80cabd6a47 100644 --- a/servers/slapd/back-ldbm/config.c +++ b/servers/slapd/back-ldbm/config.c @@ -44,14 +44,6 @@ ldbm_back_db_config( free( li->li_directory ); li->li_directory = ch_strdup( argv[1] ); - if ( li->li_nextid_file ) - free( li->li_nextid_file ); - li->li_nextid_file = - ch_malloc( strlen(li->li_directory) + sizeof("/NEXTID") + 1 ); - - strcpy(li->li_nextid_file, li->li_directory); - strcat(li->li_nextid_file, "/NEXTID"); - /* mode with which to create new database files */ } else if ( strcasecmp( argv[0], "mode" ) == 0 ) { if ( argc < 2 ) { diff --git a/servers/slapd/back-ldbm/dbcache.c b/servers/slapd/back-ldbm/dbcache.c index 1163605314..3a0287122e 100644 --- a/servers/slapd/back-ldbm/dbcache.c +++ b/servers/slapd/back-ldbm/dbcache.c @@ -121,11 +121,6 @@ ldbm_cache_open( li->li_dbcache[i].dbc_maxindirect = (SLAPD_LDBM_MIN_MAXIDS / li->li_dbcache[i].dbc_maxids) + 1; -#ifndef CONT_POSTFIX - /* don't let maxindirect exceed 9 */ - li->li_dbcache[i].dbc_maxindirect %= 10; -#endif - Debug( LDAP_DEBUG_ARGS, "ldbm_cache_open (blksize %ld) (maxids %d) (maxindirect %d)\n", li->li_dbcache[i].dbc_blksize, li->li_dbcache[i].dbc_maxids, @@ -203,9 +198,7 @@ ldbm_cache_fetch( { Datum data; - ldbm_datum_init( data ); - - data = ldbm_fetch( db->dbc_db, key ); + return ldbm_fetch( db->dbc_db, key ); return( data ); } diff --git a/servers/slapd/back-ldbm/delete.c b/servers/slapd/back-ldbm/delete.c index ac6b7d6343..7db49948bb 100644 --- a/servers/slapd/back-ldbm/delete.c +++ b/servers/slapd/back-ldbm/delete.c @@ -140,17 +140,6 @@ ldbm_back_delete( rootlock = 1; } -#ifndef DN_INDICES - if ( id2children_remove( be, p, e ) != 0 ) { - Debug(LDAP_DEBUG_ARGS, - "<=- ldbm_back_delete: operations error %s\n", - dn, 0, 0); - send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, - NULL, NULL, NULL, NULL ); - goto return_results; - } -#endif - /* delete from dn2id mapping */ if ( dn2id_delete( be, e->e_ndn ) != 0 ) { Debug(LDAP_DEBUG_ARGS, diff --git a/servers/slapd/back-ldbm/dn2id.c b/servers/slapd/back-ldbm/dn2id.c index 1353146f4a..0b3dbece36 100644 --- a/servers/slapd/back-ldbm/dn2id.c +++ b/servers/slapd/back-ldbm/dn2id.c @@ -27,9 +27,6 @@ dn2id_add( Datum key, data; struct ldbminfo *li = (struct ldbminfo *) be->be_private; - ldbm_datum_init( key ); - ldbm_datum_init( data ); - Debug( LDAP_DEBUG_TRACE, "=> dn2id_add( \"%s\", %ld )\n", dn, id, 0 ); if ( (db = ldbm_cache_open( be, "dn2id", LDBM_SUFFIX, LDBM_WRCREAT )) @@ -39,15 +36,12 @@ dn2id_add( return( -1 ); } -#ifndef DN_INDICES - key.dptr = dn; - key.dsize = strlen( key.dptr ) + 1; -#else + ldbm_datum_init( key ); key.dsize = strlen( dn ) + 2; key.dptr = ch_malloc( key.dsize ); sprintf( key.dptr, "%c%s", DN_BASE_PREFIX, dn ); -#endif + ldbm_datum_init( data ); data.dptr = (char *) &id; data.dsize = sizeof(ID); @@ -56,13 +50,13 @@ dn2id_add( rc = ldbm_cache_store( db, key, data, flags ); -#ifdef DN_INDICES free( key.dptr ); if ( rc != -1 ) { char *pdn = dn_parent( NULL, dn ); if( pdn != NULL ) { + ldbm_datum_init( key ); key.dsize = strlen( pdn ) + 2; key.dptr = ch_malloc( key.dsize ); sprintf( key.dptr, "%c%s", DN_ONE_PREFIX, pdn ); @@ -77,6 +71,7 @@ dn2id_add( if( subtree != NULL ) { int i; for( i=0; subtree[i] != NULL; i++ ) { + ldbm_datum_init( key ); key.dsize = strlen( subtree[i] ) + 2; key.dptr = ch_malloc( key.dsize ); sprintf( key.dptr, "%c%s", @@ -93,7 +88,6 @@ dn2id_add( } } -#endif ldbm_cache_close( be, db ); @@ -112,9 +106,6 @@ dn2id( ID id; Datum key, data; - ldbm_datum_init( key ); - ldbm_datum_init( data ); - Debug( LDAP_DEBUG_TRACE, "=> dn2id( \"%s\" )\n", dn, 0, 0 ); /* first check the cache */ @@ -131,22 +122,17 @@ dn2id( return( NOID ); } -#ifndef DN_INDICES - key.dptr = dn; - key.dsize = strlen( key.dptr ) + 1; -#else + ldbm_datum_init( key ); + key.dsize = strlen( dn ) + 2; key.dptr = ch_malloc( key.dsize ); sprintf( key.dptr, "%c%s", DN_BASE_PREFIX, dn ); -#endif data = ldbm_cache_fetch( db, key ); ldbm_cache_close( be, db ); -#ifdef DN_INDICES free( key.dptr ); -#endif if ( data.dptr == NULL ) { Debug( LDAP_DEBUG_TRACE, "<= dn2id NOID\n", 0, 0, 0 ); @@ -161,7 +147,6 @@ dn2id( return( id ); } -#ifdef DN_INDICES ID_BLOCK * dn2idl( Backend *be, @@ -173,8 +158,6 @@ dn2idl( Datum key; ID_BLOCK *idl; - ldbm_datum_init( key ); - Debug( LDAP_DEBUG_TRACE, "=> dn2idl( \"%c%s\" )\n", prefix, dn, 0 ); if ( (db = ldbm_cache_open( be, "dn2id", LDBM_SUFFIX, LDBM_WRCREAT )) @@ -184,6 +167,8 @@ dn2idl( return NULL; } + ldbm_datum_init( key ); + key.dsize = strlen( dn ) + 2; key.dptr = ch_malloc( key.dsize ); sprintf( key.dptr, "%c%s", prefix, dn ); @@ -196,7 +181,7 @@ dn2idl( return( idl ); } -#endif + int dn2id_delete( @@ -208,8 +193,6 @@ dn2id_delete( Datum key; int rc; - ldbm_datum_init( key ); - Debug( LDAP_DEBUG_TRACE, "=> dn2id_delete( \"%s\" )\n", dn, 0, 0 ); if ( (db = ldbm_cache_open( be, "dn2id", LDBM_SUFFIX, LDBM_WRCREAT )) @@ -220,20 +203,15 @@ dn2id_delete( return( -1 ); } -#ifndef DN_INDICES - key.dptr = dn; - key.dsize = strlen( key.dptr ) + 1; -#else + ldbm_datum_init( key ); + key.dsize = strlen( dn ) + 2; key.dptr = ch_malloc( key.dsize ); sprintf( key.dptr, "%c%s", DN_BASE_PREFIX, dn ); -#endif rc = ldbm_cache_delete( db, key ); -#ifdef DN_INDICES free( key.dptr ); -#endif ldbm_cache_close( be, db ); diff --git a/servers/slapd/back-ldbm/external.h b/servers/slapd/back-ldbm/external.h index e48f588623..c35e612d11 100644 --- a/servers/slapd/back-ldbm/external.h +++ b/servers/slapd/back-ldbm/external.h @@ -60,6 +60,20 @@ extern int ldbm_back_group LDAP_P(( BackendDB *bd, Entry *target, char* gr_ndn, char* op_ndn, char* objectclassValue, char* groupattrName)); + +/* hooks for slap tools */ +extern int ldbm_tool_entry_open LDAP_P(( BackendDB *be, int mode )); +extern int ldbm_tool_entry_close LDAP_P(( BackendDB *be )); +extern ID ldbm_tool_entry_first LDAP_P(( BackendDB *be )); +extern ID ldbm_tool_entry_next LDAP_P(( BackendDB *be )); +extern Entry* ldbm_tool_entry_get LDAP_P(( BackendDB *be, ID id )); +extern ID ldbm_tool_entry_put LDAP_P(( BackendDB *be, Entry *e )); +extern int ldbm_tool_index_attr LDAP_P(( BackendDB *be, char* type )); +extern int ldbm_tool_index_change LDAP_P(( BackendDB *be, char* type, + struct berval **bv, ID id, int op )); +extern int ldbm_tool_sync LDAP_P(( BackendDB *be )); + + LDAP_END_DECL #endif /* _LDBM_EXTERNAL_H */ diff --git a/servers/slapd/back-ldbm/filterindex.c b/servers/slapd/back-ldbm/filterindex.c index 370dc230ab..1db64e4480 100644 --- a/servers/slapd/back-ldbm/filterindex.c +++ b/servers/slapd/back-ldbm/filterindex.c @@ -40,7 +40,6 @@ filter_candidates( result = NULL; switch ( f->f_choice ) { -#ifdef DN_INDICES case SLAPD_FILTER_DN_ONE: Debug( LDAP_DEBUG_FILTER, "\tDN ONE\n", 0, 0, 0 ); result = dn2idl( be, f->f_dn, DN_ONE_PREFIX ); @@ -50,7 +49,7 @@ filter_candidates( Debug( LDAP_DEBUG_FILTER, "\tDN SUBTREE\n", 0, 0, 0 ); result = dn2idl( be, f->f_dn, DN_SUBTREE_PREFIX ); break; -#endif + case LDAP_FILTER_EQUALITY: Debug( LDAP_DEBUG_FILTER, "\tEQUALITY\n", 0, 0, 0 ); result = ava_candidates( be, &f->f_ava, LDAP_FILTER_EQUALITY ); diff --git a/servers/slapd/back-ldbm/id2children.c b/servers/slapd/back-ldbm/id2children.c index c5bc3f0524..00d5bf6988 100644 --- a/servers/slapd/back-ldbm/id2children.c +++ b/servers/slapd/back-ldbm/id2children.c @@ -14,96 +14,6 @@ #include "slap.h" #include "back-ldbm.h" -#ifndef DN_INDICES -int -id2children_add( - Backend *be, - Entry *p, - Entry *e -) -{ - DBCache *db; - Datum key; - char buf[20]; - - ldbm_datum_init( key ); - - Debug( LDAP_DEBUG_TRACE, "=> id2children_add( %ld, %ld )\n", - p ? p->e_id : 0, e->e_id, 0 ); - - if ( (db = ldbm_cache_open( be, "id2children", LDBM_SUFFIX, - LDBM_WRCREAT )) == NULL ) { - Debug( LDAP_DEBUG_ANY, - "<= id2children_add -1 could not open \"id2children%s\"\n", - LDBM_SUFFIX, 0, 0 ); - return( -1 ); - } - - sprintf( buf, "%c%ld", EQ_PREFIX, p ? p->e_id : 0 ); - key.dptr = buf; - key.dsize = strlen( buf ) + 1; - - if ( idl_insert_key( be, db, key, e->e_id ) != 0 ) { - Debug( LDAP_DEBUG_TRACE, "<= id2children_add -1 (idl_insert)\n", - 0, 0, 0 ); - ldbm_cache_close( be, db ); - return( -1 ); - } - - ldbm_cache_close( be, db ); - - Debug( LDAP_DEBUG_TRACE, "<= id2children_add 0\n", 0, 0, 0 ); - return( 0 ); -} - - -int -id2children_remove( - Backend *be, - Entry *p, - Entry *e -) -{ - DBCache *db; - Datum key; - char buf[20]; - - Debug( LDAP_DEBUG_TRACE, "=> id2children_remove( %ld, %ld )\n", p ? p->e_id - : 0, e->e_id, 0 ); - - if ( (db = ldbm_cache_open( be, "id2children", LDBM_SUFFIX, - LDBM_WRCREAT )) == NULL ) { - Debug( LDAP_DEBUG_ANY, - "<= id2children_remove -1 could not open \"id2children%s\"\n", - LDBM_SUFFIX, 0, 0 ); - return( -1 ); - } - - ldbm_datum_init( key ); - sprintf( buf, "%c%ld", EQ_PREFIX, p ? p->e_id : 0 ); - key.dptr = buf; - key.dsize = strlen( buf ) + 1; - - if ( idl_delete_key( be, db, key, e->e_id ) != 0 ) { -#if 0 - Debug( LDAP_DEBUG_ANY, - "<= id2children_remove: idl_delete_key failure\n", - 0, 0, 0 ); - ldbm_cache_close( be, db ); - return( -1 ); -#else - Debug( LDAP_DEBUG_ANY, - "<= id2children_remove: ignoring idl_delete_key failure\n", - 0, 0, 0 ); -#endif - } - - ldbm_cache_close( be, db ); - - Debug( LDAP_DEBUG_TRACE, "<= id2children_remove 0\n", 0, 0, 0 ); - return( 0 ); -} -#endif int has_children( @@ -115,28 +25,11 @@ has_children( Datum key; int rc = 0; ID_BLOCK *idl; -#ifndef DN_INDICES - char buf[20]; -#endif ldbm_datum_init( key ); Debug( LDAP_DEBUG_TRACE, "=> has_children( %ld )\n", p->e_id , 0, 0 ); -#ifndef DN_INDICES - if ( (db = ldbm_cache_open( be, "id2children", LDBM_SUFFIX, - LDBM_WRCREAT )) == NULL ) { - Debug( LDAP_DEBUG_ANY, - "<= has_children -1 could not open \"id2children%s\"\n", - LDBM_SUFFIX, 0, 0 ); - return( 0 ); - } - - sprintf( buf, "%c%ld", EQ_PREFIX, p->e_id ); - key.dptr = buf; - key.dsize = strlen( buf ) + 1; - -#else if ( (db = ldbm_cache_open( be, "dn2id", LDBM_SUFFIX, LDBM_WRCREAT )) == NULL ) { Debug( LDAP_DEBUG_ANY, @@ -148,10 +41,11 @@ has_children( key.dsize = strlen( p->e_ndn ) + 2; key.dptr = ch_malloc( key.dsize ); sprintf( key.dptr, "%c%s", DN_ONE_PREFIX, p->e_ndn ); -#endif idl = idl_fetch( be, db, key ); + free( key.dptr ); + ldbm_cache_close( be, db ); if( idl != NULL ) { diff --git a/servers/slapd/back-ldbm/id2entry.c b/servers/slapd/back-ldbm/id2entry.c index f33630e9cd..982e816d6b 100644 --- a/servers/slapd/back-ldbm/id2entry.c +++ b/servers/slapd/back-ldbm/id2entry.c @@ -43,7 +43,7 @@ id2entry_add( Backend *be, Entry *e ) key.dsize = sizeof(ID); ldap_pvt_thread_mutex_lock( &entry2str_mutex ); - data.dptr = entry2str( e, &len, 1 ); + data.dptr = entry2str( e, &len ); data.dsize = len + 1; /* store it */ @@ -144,7 +144,6 @@ id2entry_rw( Backend *be, ID id, int rw ) } e = str2entry( data.dptr ); - ldbm_datum_free( db->dbc_db, data ); ldbm_cache_close( be, db ); @@ -154,12 +153,7 @@ id2entry_rw( Backend *be, ID id, int rw ) return( NULL ); } - if ( e->e_id != id ) { - Debug( LDAP_DEBUG_TRACE, "<= id2entry_%s( %ld ) (wrong id %ld on disk)\n", - rw ? "w" : "r", id, e->e_id ); - entry_free( e ); - return( NULL ); - } + e->e_id = id; if( cache_add_entry_rw( &li->li_cache, e, rw ) != 0 ) { entry_free( e ); diff --git a/servers/slapd/back-ldbm/idl.c b/servers/slapd/back-ldbm/idl.c index eb68a95c7f..47c8a305cc 100644 --- a/servers/slapd/back-ldbm/idl.c +++ b/servers/slapd/back-ldbm/idl.c @@ -45,7 +45,6 @@ idl_allids( Backend *be ) return( idl ); } - /* Free an ID_BLOCK */ void idl_free( ID_BLOCK *idl ) @@ -72,8 +71,6 @@ idl_fetch_one( Datum data; ID_BLOCK *idl; - ldbm_datum_init( data ); - /* Debug( LDAP_DEBUG_TRACE, "=> idl_fetch_one\n", 0, 0, 0 ); */ data = ldbm_cache_fetch( db, key ); @@ -148,13 +145,9 @@ idl_fetch( for ( i = 0; !ID_BLOCK_NOID(idl, i); i++ ) { ldbm_datum_init( data ); -#ifndef CONT_POSTFIX - sprintf( kstr, "%c%s%ld", CONT_PREFIX, - key.dptr, ID_BLOCK_ID(idl, i) ); -#else sprintf( kstr, "%c%ld%s", CONT_PREFIX, ID_BLOCK_ID(idl, i), key.dptr ); -#endif + data.dptr = kstr; data.dsize = strlen( kstr ) + 1; @@ -307,13 +300,9 @@ idl_change_first( } /* write block with new key */ -#ifdef CONT_POSTFIX - sprintf( bkey.dptr, "%c%s%ld", CONT_PREFIX, - hkey.dptr, ID_BLOCK_ID(b, 0) ); -#else sprintf( bkey.dptr, "%c%ld%s", CONT_PREFIX, ID_BLOCK_ID(b, 0), hkey.dptr ); -#endif + bkey.dsize = strlen( bkey.dptr ) + 1; if ( (rc = idl_store( be, db, bkey, b )) != 0 ) { Debug( LDAP_DEBUG_ANY, @@ -405,25 +394,16 @@ idl_insert_key( /* store the first id block */ kstr = (char *) ch_malloc( key.dsize + CONT_SIZE ); -#ifdef CONT_POSTFIX - sprintf( kstr, "%c%s%ld", CONT_PREFIX, - key.dptr, ID_BLOCK_ID(tmp, 0) ); -#else sprintf( kstr, "%c%ld%s", CONT_PREFIX, ID_BLOCK_ID(tmp, 0), key.dptr ); -#endif + k2.dptr = kstr; k2.dsize = strlen( kstr ) + 1; rc = idl_store( be, db, k2, tmp ); /* store the second id block */ -#ifdef CONT_POSTFIX - sprintf( kstr, "%c%s%ld", CONT_PREFIX, - key.dptr, ID_BLOCK_ID(tmp2, 0) ); -#else sprintf( kstr, "%c%ld%s", CONT_PREFIX, ID_BLOCK_ID(tmp2, 0), key.dptr ); -#endif k2.dptr = kstr; k2.dsize = strlen( kstr ) + 1; rc = idl_store( be, db, k2, tmp2 ); @@ -458,13 +438,8 @@ idl_insert_key( /* get the block */ kstr = (char *) ch_malloc( key.dsize + CONT_SIZE ); -#ifdef CONT_POSTFIX - sprintf( kstr, "%c%s%ld", CONT_PREFIX, - key.dptr, ID_BLOCK_ID(idl, i) ); -#else sprintf( kstr, "%c%ld%s", CONT_PREFIX, ID_BLOCK_ID(idl, i), key.dptr ); -#endif k2.dptr = kstr; k2.dsize = strlen( kstr ) + 1; if ( (tmp = idl_fetch_one( be, db, k2 )) == NULL ) { @@ -508,13 +483,8 @@ idl_insert_key( /* is there a next block? */ if ( !first && !ID_BLOCK_NOID(idl, i + 1) ) { /* read it in */ -#ifdef CONT_POSTFIX - sprintf( kstr, "%c%s%ld", CONT_PREFIX, - key.dptr, ID_BLOCK_ID(idl, i + 1) ); -#else sprintf( kstr, "%c%ld%s", CONT_PREFIX, ID_BLOCK_ID(idl, i + 1), key.dptr ); -#endif k2.dptr = kstr; k2.dsize = strlen( kstr ) + 1; if ( (tmp2 = idl_fetch_one( be, db, k2 )) == NULL ) { @@ -571,13 +541,8 @@ idl_insert_key( /* delete all indirect blocks */ for ( j = 0; !ID_BLOCK_NOID(idl, j); j++ ) { -#ifdef CONT_POSTFIX - sprintf( kstr, "%c%s%ld", CONT_PREFIX, - key.dptr, ID_BLOCK_ID(idl, j) ); -#else sprintf( kstr, "%c%ld%s", CONT_PREFIX, ID_BLOCK_ID(idl, j), key.dptr ); -#endif k2.dptr = kstr; k2.dsize = strlen( kstr ) + 1; @@ -619,25 +584,15 @@ idl_insert_key( rc = idl_store( be, db, key, tmp ); /* store the first id block */ -#ifdef CONT_POSTFIX - sprintf( kstr, "%c%s%ld", CONT_PREFIX, - key.dptr, ID_BLOCK_ID(tmp2, 0) ); -#else sprintf( kstr, "%c%ld%s", CONT_PREFIX, ID_BLOCK_ID(tmp2, 0), key.dptr ); -#endif k2.dptr = kstr; k2.dsize = strlen( kstr ) + 1; rc = idl_store( be, db, k2, tmp2 ); /* store the second id block */ -#ifdef CONT_POSTFIX - sprintf( kstr, "%c%s%ld", CONT_PREFIX, - key.dptr, ID_BLOCK_ID(tmp3, 0) ); -#else sprintf( kstr, "%c%ld%s", CONT_PREFIX, ID_BLOCK_ID(tmp3, 0), key.dptr ); -#endif k2.dptr = kstr; k2.dsize = strlen( kstr ) + 1; rc = idl_store( be, db, k2, tmp3 ); @@ -771,13 +726,8 @@ idl_delete_key ( for ( j = 0; !ID_BLOCK_NOID(idl, j); j++ ) { ldbm_datum_init( data ); -#ifdef CONT_POSTFIX - sprintf( kstr, "%c%s%ld", CONT_PREFIX, - key.dptr, ID_BLOCK_ID(idl, j) ); -#else sprintf( kstr, "%c%ld%s", CONT_PREFIX, ID_BLOCK_ID(idl, j), key.dptr ); -#endif data.dptr = kstr; data.dsize = strlen( kstr ) + 1; diff --git a/servers/slapd/back-ldbm/index.c b/servers/slapd/back-ldbm/index.c index f10a5906fd..b44ffab756 100644 --- a/servers/slapd/back-ldbm/index.c +++ b/servers/slapd/back-ldbm/index.c @@ -50,7 +50,7 @@ index_add_entry( /* add the dn to the indexes */ { char *dn = ch_strdup("dn"); - index_change_values( be, dn, bvals, e->e_id, __INDEX_ADD_OP ); + index_change_values( be, dn, bvals, e->e_id, SLAP_INDEX_ADD_OP ); free( dn ); } @@ -58,9 +58,8 @@ index_add_entry( /* add each attribute to the indexes */ for ( ap = e->e_attrs; ap != NULL; ap = ap->a_next ) { - index_change_values( be, ap->a_type, ap->a_vals, e->e_id, - __INDEX_ADD_OP ); + SLAP_INDEX_ADD_OP ); } Debug( LDAP_DEBUG_TRACE, "<= index_add( %ld, \"%s\" ) 0\n", e->e_id, @@ -90,14 +89,14 @@ index_add_mods( mod->mod_type, mod->mod_bvalues, id, - __INDEX_ADD_OP); + SLAP_INDEX_ADD_OP ); break; case LDAP_MOD_DELETE: rc = index_change_values( be, mod->mod_type, mod->mod_bvalues, id, - __INDEX_DELETE_OP ); + SLAP_INDEX_DELETE_OP ); break; case LDAP_MOD_SOFTADD: /* SOFTADD means index was there */ rc = 0; @@ -159,17 +158,18 @@ index_read( realval = val; tmpval = NULL; if ( prefix != UNKNOWN_PREFIX ) { - unsigned int len = strlen( val ); + unsigned int len = strlen( val ); - if ( (len + 2) < sizeof(buf) ) { + if ( (len + 2) < sizeof(buf) ) { realval = buf; } else { /* value + prefix + null */ tmpval = (char *) ch_malloc( len + 2 ); realval = tmpval; } - realval[0] = prefix; - strcpy( &realval[1], val ); + + realval[0] = prefix; + strcpy( &realval[1], val ); } key.dptr = realval; @@ -272,16 +272,16 @@ index_change_values( if( vals == NULL ) { Debug( LDAP_DEBUG_TRACE, "=> index_change_values( %s, NULL, %ld, op=%s )\n", - type, id, ((op == __INDEX_ADD_OP) ? "ADD" : "DELETE" ) ); + type, id, ((op == SLAP_INDEX_ADD_OP) ? "ADD" : "DELETE" ) ); return 0; } Debug( LDAP_DEBUG_TRACE, "=> index_change_values( \"%s\", %ld, op=%s )\n", - type, id, ((op == __INDEX_ADD_OP) ? "ADD" : "DELETE" ) ); + type, id, ((op == SLAP_INDEX_ADD_OP) ? "ADD" : "DELETE" ) ); - if (op == __INDEX_ADD_OP) { + if (op == SLAP_INDEX_ADD_OP) { /* Add values */ @@ -433,7 +433,7 @@ index_change_values( return( 0 ); -}/* int index_change_values() */ +} static int index2prefix( int indextype ) diff --git a/servers/slapd/back-ldbm/init.c b/servers/slapd/back-ldbm/init.c index abfc3ec5cb..770f5883ed 100644 --- a/servers/slapd/back-ldbm/init.c +++ b/servers/slapd/back-ldbm/init.c @@ -58,6 +58,19 @@ ldbm_back_initialize( bi->bi_entry_release_rw = ldbm_back_entry_release_rw; bi->bi_acl_group = ldbm_back_group; + /* + * hooks for slap tools + */ + bi->bi_tool_entry_open = ldbm_tool_entry_open; + bi->bi_tool_entry_close = ldbm_tool_entry_close; + bi->bi_tool_entry_first = ldbm_tool_entry_first; + bi->bi_tool_entry_next = ldbm_tool_entry_next; + bi->bi_tool_entry_get = ldbm_tool_entry_get; + bi->bi_tool_entry_put = ldbm_tool_entry_put; + bi->bi_tool_index_attr = ldbm_tool_index_attr; + bi->bi_tool_index_change = ldbm_tool_index_change; + bi->bi_tool_sync = ldbm_tool_sync; + bi->bi_connection_init = 0; bi->bi_connection_destroy = 0; @@ -110,10 +123,6 @@ ldbm_back_db_init( /* arrange to read nextid later (on first request for it) */ li->li_nextid = NOID; -#if SLAPD_NEXTID_CHUNK > 1 - li->li_nextid_wrote = NOID; -#endif - /* default cache size */ li->li_cache.c_maxsize = DEFAULT_CACHE_SIZE; @@ -129,29 +138,11 @@ ldbm_back_db_init( /* default database directory */ li->li_directory = ch_strdup( DEFAULT_DB_DIRECTORY ); -#ifndef DN_INDICES - /* always index dn, id2children, objectclass (used in some searches) */ - if ( !at_find( "dn" ) ) { - argv[ 0 ] = "dn"; - argv[ 1 ] = "dn"; - argv[ 2 ] = NULL; - attr_syntax_config( "ldbm dn initialization", 0, 2, argv ); - } - argv[ 0 ] = "dn"; - argv[ 1 ] = "eq,sub"; - argv[ 2 ] = NULL; - attr_index_config( li, "ldbm dn initialization", 0, 2, argv, 1 ); - argv[ 0 ] = "id2children"; - argv[ 1 ] = "eq"; - argv[ 2 ] = NULL; - attr_index_config( li, "ldbm id2children initialization", 0, 2, argv, - 1 ); -#endif argv[ 0 ] = "objectclass"; argv[ 1 ] = "pres,eq"; argv[ 2 ] = NULL; - attr_index_config( li, "ldbm objectclass initialization", 0, 2, argv, - 1 ); + attr_index_config( li, "ldbm objectclass initialization", + 0, 2, argv, 1 ); /* initialize various mutex locks & condition variables */ ldap_pvt_thread_mutex_init( &li->li_root_mutex ); diff --git a/servers/slapd/back-ldbm/modify.c b/servers/slapd/back-ldbm/modify.c index 6f58b94767..267222b01c 100644 --- a/servers/slapd/back-ldbm/modify.c +++ b/servers/slapd/back-ldbm/modify.c @@ -134,7 +134,7 @@ int ldbm_modify_internal( mod->mod_type, a->a_vals, e->e_id, - __INDEX_DELETE_OP); + SLAP_INDEX_DELETE_OP); } } } diff --git a/servers/slapd/back-ldbm/nextid.c b/servers/slapd/back-ldbm/nextid.c index 0e45fced41..af718a10dc 100644 --- a/servers/slapd/back-ldbm/nextid.c +++ b/servers/slapd/back-ldbm/nextid.c @@ -1,4 +1,4 @@ -/* id.c - keep track of the next id to be given out */ +/* nextid.c - keep track of the next id to be given out */ /* * Copyright 1998-1999 The OpenLDAP Foundation, All Rights Reserved. * COPYING RESTRICTIONS APPLY, see COPYRIGHT file @@ -17,188 +17,112 @@ #include "slap.h" #include "back-ldbm.h" -/* All functions except put_nextid() obey slapMode == SLAP_TOOL_MODE. */ - -static ID next_id_read( Backend *be ); -static ID next_id_get_save( Backend *be, int do_save ); - -#define next_id_write( be, id ) \ - (slapMode == SLAP_TOOL_MODE ? (be, id, 0) : put_nextid( be, id )) - static ID next_id_read( Backend *be ) { struct ldbminfo *li = (struct ldbminfo *) be->be_private; - ID id; - char buf[20]; - char* file = li->li_nextid_file; - FILE* fp; - - if ( slapMode == SLAP_TOOL_MODE ) - return NOID; - - if ( (fp = fopen( file, "r" )) == NULL ) { - Debug( LDAP_DEBUG_ANY, - "next_id_read: could not open \"%s\"\n", - file, 0, 0 ); - return NOID; + ID id = NOID; + Datum key, data; + DBCache *db; + + if ( (db = ldbm_cache_open( be, "nextid", LDBM_SUFFIX, LDBM_WRCREAT )) + == NULL ) { + Debug( LDAP_DEBUG_ANY, "Could not open/create nextid" LDBM_SUFFIX "\n", + 0, 0, 0 ); + return( NOID ); } - if ( fgets( buf, sizeof(buf), fp ) == NULL ) { - Debug( LDAP_DEBUG_ANY, - "next_id_read: could not fgets nextid from \"%s\"\n", - file, 0, 0 ); - fclose( fp ); - return NOID; - } + ldbm_datum_init( key ); + key.dptr = (char *) &id; + key.dsize = sizeof(ID); + + data = ldbm_cache_fetch( db, key ); - id = atol( buf ); - fclose( fp ); + if( data.dptr != NULL ) { + memcpy( &id, data.dptr, sizeof( ID ) ); + ldbm_datum_free( db->dbc_db, data ); - if(id < 1) { - Debug( LDAP_DEBUG_ANY, - "next_id_read %ld: atol(%s) return non-positive integer\n", - id, buf, 0 ); - return NOID; + } else { + id = 1; } + ldbm_cache_close( be, db ); return id; } -int -put_nextid( Backend *be, ID id ) +ID +next_id_write( Backend *be, ID id ) { struct ldbminfo *li = (struct ldbminfo *) be->be_private; - char* file = li->li_nextid_file; - FILE* fp; - int rc; - - if ( (fp = fopen( file, "w" )) == NULL ) { - Debug( LDAP_DEBUG_ANY, "put_nextid(%ld): could not open \"%s\"\n", - id, file, 0 ); - return -1; - } - - rc = 0; - - if ( fprintf( fp, "%ld\n", id ) == EOF ) { - Debug( LDAP_DEBUG_ANY, "put_nextid(%ld): cannot fprintf\n", - id, 0, 0 ); - rc = -1; + Datum key, data; + DBCache *db; + ID noid = NOID; + int flags; + + if ( (db = ldbm_cache_open( be, "nextid", LDBM_SUFFIX, LDBM_WRCREAT )) + == NULL ) { + Debug( LDAP_DEBUG_ANY, "Could not open/create nextid" LDBM_SUFFIX "\n", + 0, 0, 0 ); + return( NOID ); } - if( fclose( fp ) != 0 ) { - Debug( LDAP_DEBUG_ANY, "put_nextid %ld: cannot fclose\n", - id, 0, 0 ); - rc = -1; - } - - return rc; -} - -int -next_id_save( Backend *be ) -{ - return( next_id_get_save( be, 1 ) == NOID ? -1 : 0 ); -} - -ID -next_id( Backend *be ) -{ - struct ldbminfo *li = (struct ldbminfo *) be->be_private; - ID id; + ldbm_datum_init( key ); + ldbm_datum_init( data ); - ldap_pvt_thread_mutex_lock( &li->li_nextid_mutex ); + key.dptr = (char *) &noid; + key.dsize = sizeof(ID); - /* first time in here since startup - try to read the nexid */ - if ( li->li_nextid == NOID ) { - li->li_nextid = next_id_read( be ); + data.dptr = (char *) &id; + data.dsize = sizeof(ID); - if ( li->li_nextid == NOID ) { - li->li_nextid = 1; - } + flags = LDBM_REPLACE; + if( li->li_dbcachewsync ) flags |= LDBM_SYNC; -#if SLAPD_NEXTID_CHUNK > 1 - li->li_nextid_wrote = li->li_nextid; -#endif + if ( ldbm_cache_store( db, key, data, flags ) != 0 ) { + id = NOID; } - id = li->li_nextid++; - -#if SLAPD_NEXTID_CHUNK > 1 - if ( li->li_nextid > li->li_nextid_wrote ) { - li->li_nextid_wrote += SLAPD_NEXTID_CHUNK; - (void) next_id_write( be, li->li_nextid_wrote ); - } -#else - (void) next_id_write( be, li->li_nextid ); -#endif - - ldap_pvt_thread_mutex_unlock( &li->li_nextid_mutex ); - return( id ); + ldbm_cache_close( be, db ); + return id; } -void -next_id_return( Backend *be, ID id ) +ID +next_id_get( Backend *be ) { -#ifdef SLAPD_NEXTID_RETURN struct ldbminfo *li = (struct ldbminfo *) be->be_private; + ID id = NOID; ldap_pvt_thread_mutex_lock( &li->li_nextid_mutex ); - if ( id != li->li_nextid - 1 ) { - ldap_pvt_thread_mutex_unlock( &li->li_nextid_mutex ); - return; + if ( li->li_nextid == NOID ) { + li->li_nextid = next_id_read( be ); } - li->li_nextid--; - -#if !( SLAPD_NEXTID_CHUNK > 1 ) - (void) next_id_write( be, li->li_nextid ); -#endif + id = li->li_nextid; ldap_pvt_thread_mutex_unlock( &li->li_nextid_mutex ); -#endif + return id; } ID -next_id_get( Backend *be ) -{ - return next_id_get_save( be, 0 ); -} - -static ID -next_id_get_save( Backend *be, int do_save ) +next_id( Backend *be ) { struct ldbminfo *li = (struct ldbminfo *) be->be_private; - ID id; + ID id = NOID; ldap_pvt_thread_mutex_lock( &li->li_nextid_mutex ); - /* first time in here since startup - try to read the nexid */ if ( li->li_nextid == NOID ) { li->li_nextid = next_id_read( be ); - - if ( li->li_nextid == NOID ) { - li->li_nextid = 1; - } - -#if SLAPD_NEXTID_CHUNK > 1 - li->li_nextid_wrote = li->li_nextid; -#endif } - id = li->li_nextid; + if ( li->li_nextid != NOID ) { + id = li->li_nextid++; - if ( do_save ) { - if ( next_id_write( be, id ) == 0 ) { - li->li_nextid_wrote = id; - } else { - id = NOID; - } + (void) next_id_write( be, li->li_nextid ); } ldap_pvt_thread_mutex_unlock( &li->li_nextid_mutex ); + return id; - return( id ); } diff --git a/servers/slapd/back-ldbm/proto-back-ldbm.h b/servers/slapd/back-ldbm/proto-back-ldbm.h index 341a09ead2..9e14f239d1 100644 --- a/servers/slapd/back-ldbm/proto-back-ldbm.h +++ b/servers/slapd/back-ldbm/proto-back-ldbm.h @@ -139,15 +139,12 @@ int index_add_mods LDAP_P(( Backend *be, LDAPModList *ml, ID id )); ID_BLOCK * index_read LDAP_P(( Backend *be, char *type, int indextype, char *val )); /* Possible operations supported (op) by index_change_values() */ -#define __INDEX_ADD_OP 0x0001 -#define __INDEX_DELETE_OP 0x0002 int index_change_values LDAP_P(( Backend *be, char *type, struct berval **vals, ID id, unsigned int op )); - /* * kerberos.c */ @@ -179,11 +176,9 @@ int ldbm_modify_internal LDAP_P((Backend *be, * nextid.c */ -int put_nextid LDAP_P(( Backend *be, ID id )); ID next_id LDAP_P(( Backend *be )); -void next_id_return LDAP_P(( Backend *be, ID id )); ID next_id_get LDAP_P(( Backend *be )); -int next_id_save LDAP_P(( Backend *be )); +ID next_id_write LDAP_P(( Backend *be, ID id )); LDAP_END_DECL #endif diff --git a/servers/slapd/back-ldbm/search.c b/servers/slapd/back-ldbm/search.c index 6c2cc6169c..32028a6544 100644 --- a/servers/slapd/back-ldbm/search.c +++ b/servers/slapd/back-ldbm/search.c @@ -400,40 +400,20 @@ search_candidates( lf->f_choice = LDAP_FILTER_AND; lf->f_and = (Filter *) ch_malloc( sizeof(Filter) ); -#ifndef DN_INDICES - lf->f_and->f_choice = LDAP_FILTER_SUBSTRINGS; - lf->f_and->f_sub_type = ch_strdup( "dn" ); - lf->f_and->f_sub_initial = NULL; - lf->f_and->f_sub_any = NULL; - lf->f_and->f_sub_final = ch_strdup( e->e_ndn ); -#else lf->f_and->f_choice = SLAPD_FILTER_DN_SUBTREE; lf->f_and->f_dn = e->e_ndn; -#endif lf->f_and->f_next = f; f = lf; } else if ( scope == LDAP_SCOPE_ONELEVEL ) { -#ifndef DN_INDICES - char buf[16]; -#endif - lf = (Filter *) ch_malloc( sizeof(Filter) ); lf->f_next = NULL; lf->f_choice = LDAP_FILTER_AND; lf->f_and = (Filter *) ch_malloc( sizeof(Filter) ); -#ifndef DN_INDICES - lf->f_and->f_choice = LDAP_FILTER_EQUALITY; - lf->f_and->f_ava.ava_type = ch_strdup( "id2children" ); - sprintf( buf, "%ld", e != NULL ? e->e_id : 0 ); - lf->f_and->f_ava.ava_value.bv_val = ch_strdup( buf ); - lf->f_and->f_ava.ava_value.bv_len = strlen( buf ); -#else lf->f_and->f_choice = SLAPD_FILTER_DN_ONE; lf->f_and->f_dn = e->e_ndn; -#endif lf->f_and->f_next = f; f = lf; @@ -446,13 +426,8 @@ search_candidates( /* free up filter additions we allocated above */ if( lf != NULL ) { -#ifndef DN_INDICES - lf->f_and->f_next = NULL; - filter_free( lf ); -#else free( lf->f_and ); free( lf ); -#endif } if( af != NULL ) { diff --git a/servers/slapd/back-ldbm/tools.c b/servers/slapd/back-ldbm/tools.c new file mode 100644 index 0000000000..fe593c7144 --- /dev/null +++ b/servers/slapd/back-ldbm/tools.c @@ -0,0 +1,248 @@ +/* tools.c - tools for slap tools */ +/* + * Copyright 1998-1999 The OpenLDAP Foundation, All Rights Reserved. + * COPYING RESTRICTIONS APPLY, see COPYRIGHT file + */ + +#include "portable.h" + +#include + +#include + +#include "slap.h" +#include "back-ldbm.h" + +static LDBMCursor *cursorp = NULL; +static DBCache *id2entry = NULL; + +int ldbm_tool_entry_open( + BackendDB *be, int mode ) +{ + struct ldbminfo *li = (struct ldbminfo *) be->be_private; + int flags; + + assert( slapMode & SLAP_TOOL_MODE ); + assert( id2entry == NULL ); + + switch( mode ) { + case 1: + flags = LDBM_WRCREAT; + break; + case 2: +#ifdef TRUNCATE_MODE + flags = LDBM_NEWDB; +#else + flags = LDBM_WRCREAT; +#endif + break; + default: + flags = LDBM_READER; + } + + li->li_dbcachewsync = 0; + + if ( (id2entry = ldbm_cache_open( be, "id2entry", LDBM_SUFFIX, flags )) + == NULL ) { + Debug( LDAP_DEBUG_ANY, "Could not open/create id2entry" LDBM_SUFFIX "\n", + 0, 0, 0 ); + return( -1 ); + } + + return 0; +} + +int ldbm_tool_entry_close( + BackendDB *be ) +{ + struct ldbminfo *li = (struct ldbminfo *) be->be_private; + + assert( slapMode & SLAP_TOOL_MODE ); + assert( id2entry != NULL ); + + ldbm_cache_close( be, id2entry ); + li->li_dbcachewsync = 1; + id2entry = NULL; + + return 0; +} + +ID ldbm_tool_entry_first( + BackendDB *be ) +{ + Datum key; + ID id; + + assert( slapMode & SLAP_TOOL_MODE ); + assert( id2entry != NULL ); + + key = ldbm_firstkey( id2entry->dbc_db, &cursorp ); + + if( key.dptr == NULL ) { + return NOID; + } + + memcpy( &id, key.dptr, key.dsize ); + + ldbm_datum_free( id2entry->dbc_db, key ); + + return id; +} + +ID ldbm_tool_entry_next( + BackendDB *be ) +{ + Datum key; + ID id; + int count; + + assert( slapMode & SLAP_TOOL_MODE ); + assert( id2entry != NULL ); + + /* allow for NEXTID */ + ldbm_datum_init( key ); + + key = ldbm_nextkey( id2entry->dbc_db, key, cursorp ); + + if( key.dptr == NULL ) { + return NOID; + } + + memcpy( &id, key.dptr, key.dsize ); + + ldbm_datum_free( id2entry->dbc_db, key ); + + return id; +} + +Entry* ldbm_tool_entry_get( BackendDB *be, ID id ) +{ + Entry *e; + Datum key, data; + assert( slapMode & SLAP_TOOL_MODE ); + assert( id2entry != NULL ); + + ldbm_datum_init( key ); + + key.dptr = (char *) &id; + key.dsize = sizeof(ID); + + data = ldbm_cache_fetch( id2entry, key ); + + if ( data.dptr == NULL ) { + return NULL; + } + + e = str2entry( data.dptr ); + ldbm_datum_free( id2entry->dbc_db, data ); + + return e; +} + +ID ldbm_tool_entry_put( + BackendDB *be, + Entry *e ) +{ + struct ldbminfo *li = (struct ldbminfo *) be->be_private; + Datum key, data; + int rc, len; + + assert( slapMode & SLAP_TOOL_MODE ); + assert( id2entry != NULL ); + + if( next_id_get( be ) == NOID ) { + return NOID; + } + + e->e_id = li->li_nextid++; + + Debug( LDAP_DEBUG_TRACE, "=> ldbm_tool_entry_put( %ld, \"%s\" )\n", + e->e_id, e->e_dn, 0 ); + + rc = index_add_entry( be, e ); + + if( rc != 0 ) { + return NOID; + } + + rc = dn2id_add( be, e->e_ndn, e->e_id ); + + if( rc != 0 ) { + return NOID; + } + + ldbm_datum_init( key ); + ldbm_datum_init( data ); + + key.dptr = (char *) &e->e_id; + key.dsize = sizeof(ID); + + data.dptr = entry2str( e, &len ); + data.dsize = len + 1; + + /* store it */ + rc = ldbm_cache_store( id2entry, key, data, LDBM_REPLACE ); + + if( rc != 0 ) { + (void) dn2id_delete( be, e->e_ndn ); + return NOID; + } + + return e->e_id; +} + +int ldbm_tool_index_attr( + BackendDB *be, + char* type ) +{ + static DBCache *db = NULL; + int indexmask, syntaxmask; + char * at_cn; + + assert( slapMode & SLAP_TOOL_MODE ); + + attr_masks( be->be_private, type, &indexmask, &syntaxmask ); + + attr_normalize( type ); + at_cn = at_canonical_name( type ); + + if ( (db = ldbm_cache_open( be, at_cn, LDBM_SUFFIX, LDBM_NEWDB )) + == NULL ) { + Debug( LDAP_DEBUG_ANY, + "<= index_read NULL (could not open %s%s)\n", at_cn, + LDBM_SUFFIX, 0 ); + return( NULL ); + } + + ldbm_cache_close( be, db ); + + return indexmask != 0; +} + +int ldbm_tool_index_change( + BackendDB *be, + char* type, + struct berval **bv, + ID id, + int op ) +{ + assert( slapMode & SLAP_TOOL_MODE ); + + index_change_values( be, + type, bv, id, op ); + + return 0; +} + +int ldbm_tool_sync( BackendDB *be ) +{ + struct ldbminfo *li = (struct ldbminfo *) be->be_private; + + assert( slapMode & SLAP_TOOL_MODE ); + + if ( li->li_nextid != NOID ) { + next_id_write( be, li->li_nextid ); + } + + return 0; +} diff --git a/servers/slapd/back-perl/add.c b/servers/slapd/back-perl/add.c index 89193b499a..ed30475ac9 100644 --- a/servers/slapd/back-perl/add.c +++ b/servers/slapd/back-perl/add.c @@ -34,14 +34,15 @@ perl_back_add( PerlBackend *perl_back = (PerlBackend *) be->be_private; - ldap_pvt_thread_mutex_lock( &perl_interpreter_mutex ); + ldap_pvt_thread_mutex_lock( &perl_interpreter_mutex ); + ldap_pvt_thread_mutex_lock( &entry2str_mutex ); { dSP; ENTER; SAVETMPS; PUSHMARK(sp); XPUSHs( perl_back->pb_obj_ref ); - XPUSHs(sv_2mortal(newSVpv( entry2str( e, &len, 0 ), 0 ))); + XPUSHs(sv_2mortal(newSVpv( entry2str( e, &len ), 0 ))); PUTBACK; @@ -58,6 +59,7 @@ perl_back_add( PUTBACK; FREETMPS; LEAVE; } + ldap_pvt_thread_mutex_unlock( &entry2str_mutex ); ldap_pvt_thread_mutex_unlock( &perl_interpreter_mutex ); if( return_code != 0 ) { diff --git a/servers/slapd/back-shell/add.c b/servers/slapd/back-shell/add.c index 9c033e7be8..1c189a96d4 100644 --- a/servers/slapd/back-shell/add.c +++ b/servers/slapd/back-shell/add.c @@ -39,7 +39,7 @@ shell_back_add( fprintf( wfp, "msgid: %ld\n", op->o_msgid ); print_suffixes( wfp, be ); ldap_pvt_thread_mutex_lock( &entry2str_mutex ); - fprintf( wfp, "%s", entry2str( e, &len, 0 ) ); + fprintf( wfp, "%s", entry2str( e, &len ) ); ldap_pvt_thread_mutex_unlock( &entry2str_mutex ); fclose( wfp ); diff --git a/servers/slapd/back-tcl/tcl_util.c b/servers/slapd/back-tcl/tcl_util.c index 879c9c34f8..b1c64b5ac7 100644 --- a/servers/slapd/back-tcl/tcl_util.c +++ b/servers/slapd/back-tcl/tcl_util.c @@ -1,6 +1,6 @@ /* result.c - tcl backend utility functions * - * $Id: tcl_util.c,v 1.7 1999/07/16 00:45:52 kdz Exp $ + * $Id: tcl_util.c,v 1.8 1999/08/02 23:38:43 hallvard Exp $ * * Copyright 1999, Ben Collins , All rights reserved. * @@ -110,9 +110,8 @@ tcl_clean_entry ( char *entrystr, *mark1, *mark2, *buf, *bp, *dup; int len, bsize; - pthread_mutex_lock (&entry2str_mutex); - entrystr = entry2str (e, &len, 0); - pthread_mutex_unlock (&entry2str_mutex); + ldap_pvt_thread_mutex_lock(&entry2str_mutex); + entrystr = entry2str (e, &len); buf = (char *) ch_malloc (BUFSIZ); buf[0] = '\0'; @@ -147,6 +146,8 @@ tcl_clean_entry ( } free (dup); } while ((mark1 = (char *) strchr (mark1, '\n')) != NULL); + + ldap_pvt_thread_mutex_unlock (&entry2str_mutex); return buf; } diff --git a/servers/slapd/backend.c b/servers/slapd/backend.c index 0c07a87a9b..7e8a1cf327 100644 --- a/servers/slapd/backend.c +++ b/servers/slapd/backend.c @@ -84,11 +84,10 @@ int backend_init(void) } for( ; - binfo[nBackendInfo].bi_type != NULL; + binfo[nBackendInfo].bi_type != NULL; nBackendInfo++ ) { - rc = binfo[nBackendInfo].bi_init( - &binfo[nBackendInfo] ); + rc = binfo[nBackendInfo].bi_init( &binfo[nBackendInfo] ); if(rc != 0) { Debug( LDAP_DEBUG_ANY, @@ -158,7 +157,7 @@ int backend_add(BackendInfo *aBackendInfo) } } -int backend_startup(int n) +int backend_startup(Backend *be) { int i; int rc = 0; @@ -171,24 +170,14 @@ int backend_startup(int n) return 1; } - if(n >= 0) { + if(be != NULL) { /* startup a specific backend database */ Debug( LDAP_DEBUG_TRACE, - "backend_startup: starting database %d\n", - n, 0, 0 ); + "backend_startup: starting database\n", + 0, 0, 0 ); - /* make sure, n does not exceed the number of backend databases */ - if ( n >= nbackends ) { - - Debug( LDAP_DEBUG_ANY, - "backend_startup: database number %d exceeding maximum (%d)\n", - n, nbackends, 0 ); - return 1; - } - - if ( backendDB[n].bd_info->bi_open ) { - rc = backendDB[n].bd_info->bi_open( - backendDB[n].bd_info ); + if ( be->bd_info->bi_open ) { + rc = be->bd_info->bi_open( be->bd_info ); } if(rc != 0) { @@ -198,9 +187,8 @@ int backend_startup(int n) return rc; } - if ( backendDB[n].bd_info->bi_db_open ) { - rc = backendDB[n].bd_info->bi_db_open( - &backendDB[n] ); + if ( be->bd_info->bi_db_open ) { + rc = be->bd_info->bi_db_open( be ); } if(rc != 0) { @@ -251,36 +239,37 @@ int backend_startup(int n) return rc; } -int backend_shutdown(int n) +int backend_num( Backend *be ) { int i; - int rc = 0; - if(n >= 0) { - /* shutdown a specific backend database */ + if( be == NULL ) return -1; + + for( i = 0; i < nBackendDB; i++ ) { + if( be == &backendDB[i] ) return i; + } + return -1; +} - /* make sure, n does not exceed the number of backend databases */ - if ( n >= nbackends ) { +int backend_shutdown( Backend *be ) +{ + int i; + int rc = 0; - Debug( LDAP_DEBUG_ANY, - "backend_startup: database number %d exceeding maximum (%d)\n", - n, nbackends, 0 ); - return 1; - } + if( be != NULL ) { + /* shutdown a specific backend database */ - if ( backendDB[n].bd_info->bi_nDB == 0 ) { + if ( be->bd_info->bi_nDB == 0 ) { /* no database of this type, we never opened it */ return 0; } - if ( backendDB[n].bd_info->bi_db_close ) { - backendDB[n].bd_info->bi_db_close( - &backendDB[n] ); + if ( be->bd_info->bi_db_close ) { + be->bd_info->bi_db_close( be ); } - if( backendDB[n].bd_info->bi_close ) { - backendDB[n].bd_info->bi_close( - backendDB[n].bd_info ); + if( be->bd_info->bi_close ) { + be->bd_info->bi_close( be->bd_info ); } return 0; diff --git a/servers/slapd/entry.c b/servers/slapd/entry.c index d58b4a7093..370864ba77 100644 --- a/servers/slapd/entry.c +++ b/servers/slapd/entry.c @@ -20,9 +20,8 @@ static unsigned char *ecur; /* pointer to end of currently used ebuf */ static int emaxsize;/* max size of ebuf */ Entry * -str2entry( char *s ) +str2entry( char *s ) { - int id = 0; Entry *e; Attribute **a; char *type; @@ -35,9 +34,9 @@ str2entry( char *s ) char ptype[64]; /* - * In string format, an entry looks like this: + * LDIF is used as the string format. + * An entry looks like this: * - * \n * dn: \n * [:[:] \n] * [\n]* @@ -52,17 +51,7 @@ str2entry( char *s ) Debug( LDAP_DEBUG_TRACE, "=> str2entry\n", s ? s : "NULL", 0, 0 ); - /* check to see if there's an id included */ next = s; - if ( isdigit( (unsigned char) *s ) ) { - id = atoi( s ); - if ( (s = ldif_getline( &next )) == NULL ) { - Debug( LDAP_DEBUG_TRACE, - "<= str2entry NULL (missing newline after id)\n", - 0, 0, 0 ); - return( NULL ); - } - } /* initialize reader/writer lock */ e = (Entry *) ch_calloc( 1, sizeof(Entry) ); @@ -74,7 +63,7 @@ str2entry( char *s ) return( NULL ); } - e->e_id = id; + e->e_id = NOID; e->e_private = NULL; /* dn + attributes */ @@ -172,9 +161,7 @@ str2entry( char *s ) char * entry2str( Entry *e, - int *len, - int printid -) + int *len ) { Attribute *a; struct berval *bv; @@ -189,13 +176,6 @@ entry2str( ecur = ebuf; - if ( printid ) { - /* id + newline */ - MAKE_SPACE( 10 ); - sprintf( (char *) ecur, "%ld\n", e->e_id ); - ecur = (unsigned char *) strchr( (char *) ecur, '\0' ); - } - /* put the dn */ if ( e->e_dn != NULL ) { /* put "dn: " */ diff --git a/servers/slapd/init.c b/servers/slapd/init.c index f11af8f24a..5e0fcb3e38 100644 --- a/servers/slapd/init.c +++ b/servers/slapd/init.c @@ -70,6 +70,8 @@ slap_init( int mode, char *name ) { int rc; + assert( mode ); + if( slapMode != SLAP_UNDEFINED_MODE ) { Debug( LDAP_DEBUG_ANY, "%s init: init called twice (old=%d, new=%d)\n", @@ -79,18 +81,12 @@ slap_init( int mode, char *name ) slapMode = mode; - switch ( slapMode ) { - + switch ( slapMode & SLAP_MODE ) { case SLAP_SERVER_MODE: case SLAP_TOOL_MODE: -#ifdef SLAP_TIMEDSERVER_MODE - case SLAP_TIMEDSERVER_MODE: -#endif - case SLAP_TOOLID_MODE: - Debug( LDAP_DEBUG_TRACE, "%s init: initiated %s.\n", - name, (mode == SLAP_TOOL_MODE || mode == SLAP_TOOLID_MODE) ? "tool" : "server", 0 ); + name, ( mode & SLAP_TOOL_MODE ) ? "tool" : "server", 0 ); slap_name = name; @@ -110,7 +106,7 @@ slap_init( int mode, char *name ) ldap_pvt_thread_mutex_init( &crypt_mutex ); #endif - rc = backend_init(); + rc = backend_init( ); break; default: @@ -123,7 +119,7 @@ slap_init( int mode, char *name ) return rc; } -int slap_startup(int dbnum) +int slap_startup( Backend *be ) { int rc; @@ -131,7 +127,7 @@ int slap_startup(int dbnum) "%s startup: initiated.\n", slap_name, 0, 0 ); - rc = backend_startup(dbnum); + rc = backend_startup( be ); if( rc == 0 ) { rc = sasl_init(); @@ -140,7 +136,7 @@ int slap_startup(int dbnum) return rc; } -int slap_shutdown(int dbnum) +int slap_shutdown( Backend *be ) { int rc; @@ -151,7 +147,7 @@ int slap_shutdown(int dbnum) sasl_destroy(); /* let backends do whatever cleanup they need to do */ - rc = backend_shutdown(dbnum); + rc = backend_shutdown( be ); return rc; } diff --git a/servers/slapd/main.c b/servers/slapd/main.c index 8386f6eeb9..9d0544573b 100644 --- a/servers/slapd/main.c +++ b/servers/slapd/main.c @@ -282,7 +282,7 @@ int main( int argc, char **argv ) #ifdef SLAPD_BDB2 case 't': /* timed server */ - serverMode = SLAP_TIMEDSERVER_MODE; + serverMode |= SLAP_TIMED_MODE; break; #endif @@ -384,7 +384,7 @@ int main( int argc, char **argv ) #endif #endif /* HAVE_WINSOCK */ - if ( slap_startup(-1) != 0 ) { + if ( slap_startup( NULL ) != 0 ) { rc = 1; SERVICE_EXIT( ERROR_SERVICE_SPECIFIC_ERROR, 20 ); goto shutdown; @@ -427,7 +427,7 @@ int main( int argc, char **argv ) shutdown: /* remember an error during shutdown */ - rc |= slap_shutdown(-1); + rc |= slap_shutdown( NULL ); destroy: /* remember an error during destroy */ rc |= slap_destroy(); diff --git a/servers/slapd/proto-slap.h b/servers/slapd/proto-slap.h index 801dbd2afc..5c29a9cf75 100644 --- a/servers/slapd/proto-slap.h +++ b/servers/slapd/proto-slap.h @@ -79,8 +79,9 @@ void ava_free LDAP_P(( Ava *ava, int freeit )); int backend_init LDAP_P((void)); int backend_add LDAP_P((BackendInfo *aBackendInfo)); -int backend_startup LDAP_P((int dbnum)); -int backend_shutdown LDAP_P((int dbnum)); +int backend_num LDAP_P((Backend *be)); +int backend_startup LDAP_P((Backend *be)); +int backend_shutdown LDAP_P((Backend *be)); int backend_destroy LDAP_P((void)); BackendInfo * backend_info LDAP_P(( char *type )); @@ -206,7 +207,7 @@ void build_new_dn LDAP_P(( char ** new_dn, char *e_dn, char * p_dn, */ Entry * str2entry LDAP_P(( char *s )); -char * entry2str LDAP_P(( Entry *e, int *len, int printid )); +char * entry2str LDAP_P(( Entry *e, int *len )); void entry_free LDAP_P(( Entry *e )); int entry_cmp LDAP_P(( Entry *a, Entry *b )); @@ -441,8 +442,8 @@ extern ldap_pvt_thread_mutex_t gmtime_mutex; extern AccessControl *global_acl; int slap_init LDAP_P((int mode, char* name)); -int slap_startup LDAP_P((int dbnum)); -int slap_shutdown LDAP_P((int dbnum)); +int slap_startup LDAP_P(( Backend *be )); +int slap_shutdown LDAP_P(( Backend *be )); int slap_destroy LDAP_P((void)); struct sockaddr_in; diff --git a/servers/slapd/repl.c b/servers/slapd/repl.c index 8f8b643922..39e4e71218 100644 --- a/servers/slapd/repl.c +++ b/servers/slapd/repl.c @@ -99,7 +99,7 @@ replog( e = change; fprintf( fp, "changetype: add\n" ); ldap_pvt_thread_mutex_lock( &entry2str_mutex ); - tmp = entry2str( e, &len, 0 ); + tmp = entry2str( e, &len ); while ( (tmp = strchr( tmp, '\n' )) != NULL ) { tmp++; if ( ! isspace( (unsigned char) *tmp ) ) diff --git a/servers/slapd/slap.h b/servers/slapd/slap.h index a9a21d1467..bc67e28b85 100644 --- a/servers/slapd/slap.h +++ b/servers/slapd/slap.h @@ -390,12 +390,15 @@ extern int nBackendDB; extern BackendInfo *backendInfo; extern BackendDB *backendDB; -extern int slapMode; -#define SLAP_UNDEFINED_MODE 0 -#define SLAP_SERVER_MODE 1 -#define SLAP_TOOL_MODE 2 +extern int slapMode; +#define SLAP_UNDEFINED_MODE 0x0000 +#define SLAP_SERVER_MODE 0x0001 +#define SLAP_TOOL_MODE 0x0002 +#define SLAP_MODE 0x0003 + +#define SLAP_TRUNCATE_MODE 0x0100 #ifdef SLAPD_BDB2 -# define SLAP_TIMEDSERVER_MODE 3 +#define SLAP_TIMED_MODE 0x1000 #endif #define SLAP_TOOLID_MODE 4 @@ -426,6 +429,17 @@ struct slap_backend_db { #define be_connection_init bd_info->bi_connection_init #define be_connection_destroy bd_info->bi_connection_destroy +#ifdef SLAPD_TOOLS +#define be_entry_open bd_info->bi_tool_entry_open +#define be_entry_close bd_info->bi_tool_entry_close +#define be_entry_first bd_info->bi_tool_entry_first +#define be_entry_next bd_info->bi_tool_entry_next +#define be_entry_get bd_info->bi_tool_entry_get +#define be_entry_put bd_info->bi_tool_entry_put +#define be_index_attr bd_info->bi_tool_index_attr +#define be_index_change bd_info->bi_tool_index_change +#define be_sync bd_info->bi_tool_sync +#endif /* these should be renamed from be_ to bd_ */ char **be_suffix; /* the DN suffixes of data in this backend */ @@ -554,6 +568,20 @@ struct slap_backend_info { int (*bi_connection_destroy) LDAP_P((BackendDB *bd, struct slap_conn *c)); + /* hooks for slap tools */ + int (*bi_tool_entry_open) LDAP_P(( BackendDB *be, int mode )); + int (*bi_tool_entry_close) LDAP_P(( BackendDB *be )); + ID (*bi_tool_entry_first) LDAP_P(( BackendDB *be )); + ID (*bi_tool_entry_next) LDAP_P(( BackendDB *be )); + Entry* (*bi_tool_entry_get) LDAP_P(( BackendDB *be, ID id )); + ID (*bi_tool_entry_put) LDAP_P(( BackendDB *be, Entry *e )); + int (*bi_tool_index_attr) LDAP_P(( BackendDB *be, char* type )); + int (*bi_tool_index_change) LDAP_P(( BackendDB *be, char* type, + struct berval **bv, ID id, int op )); + int (*bi_tool_sync) LDAP_P(( BackendDB *be )); + +#define SLAP_INDEX_ADD_OP 0x0001 +#define SLAP_INDEX_DELETE_OP 0x0002 unsigned int bi_nDB; /* number of databases of this type */ void *bi_private; /* anything the backend type needs */ diff --git a/servers/slapd/tools/Makefile.in b/servers/slapd/tools/Makefile.in index 731d6fbaf6..4e04a7391e 100644 --- a/servers/slapd/tools/Makefile.in +++ b/servers/slapd/tools/Makefile.in @@ -12,9 +12,9 @@ # Stand alone LDAP server tools makefile # #----------------------------------------------------------------------------- -HAVE_QUIPU = @BUILD_QUIPU@ BUILD_LDBM = @BUILD_LDBM@ BUILD_BDB2 = @BUILD_BDB2@ +BUILD_QUIPU = @BUILD_QUIPU@ LDAP_INCDIR= ../../../include LDAP_LIBDIR= ../../../libraries @@ -30,133 +30,110 @@ XXLIBS = $(LDAPD_LIBS) $(SLAPD_LIBS) \ $(LDIF_LIBS) $(LUTIL_LIBS) XXXLIBS = $(LTHREAD_LIBS) $(MODULES_LIBS) -PROGRAMS=ldif2index ldif2ldbm ldbmcat ldif2id2entry ldif2id2children \ - centipede ldbmtest ldif +PROGRAMS=ldif slapadd slapcat slapindex +LDBMPROGRAMS=centipede sizecount +BDB2PROGRAMS= +QUIPUPROGRAMS=chlog2replog edb2ldif -PROGRAMS2=ldif2index-bdb2 ldif2ldbm-bdb2 \ - ldif2id2entry-bdb2 ldif2id2children-bdb2 - -SRCS = centipede.c ldbmcat.c ldbmtest.c sizecount.c \ - ldif.c ldif2id2children.c ldif2id2entry.c ldif2index.c ldif2ldbm.c \ - mimic.c ldif2common.c - -SRCS2 = ldif2id2children-bdb2.c ldif2id2entry-bdb2.c \ - ldif2index-bdb2.c ldif2ldbm-bdb2.c +SRCS = ldif.c mimic.c slapcommon.c XSRCS = edb2-vers.c -EDB2LDIFSRCS = edb2ldif.c ldapsyntax.c -EDB2LDIFOBJS = edb2ldif.o ldapsyntax.o +LDBMSRCS = centipede.c sizecount.c + +BDB2SRCS = -OBJS1 = mimic.o \ - ../config.o ../ch_malloc.o ../backend.o ../charray.o \ +QUIPUSRCS = edb2ldif.c ldapsyntax.c chlog2replog.c +SLAPD_OBJS = ../config.o ../ch_malloc.o ../backend.o ../charray.o \ ../module.o ../aclparse.o ../schema.o ../filterentry.o \ ../acl.o ../phonetic.o ../attr.o ../value.o ../entry.o \ ../dn.o ../filter.o ../str2filter.o ../ava.o ../init.o \ ../controls.o ../schemaparse.o -OBJS2 = $(OBJS1) ldif2common.o +SLAPOBJS = $(SLAPD_OBJS) slapcommon.o mimic.o -all-local: build-ldbm build-bdb2 build-edb2ldif build-chlog2replog +EDB2LDIFSRCS = edb2ldif.c ldapsyntax.c +EDB2LDIFOBJS = edb2ldif.o ldapsyntax.o + +all-local: build-progs build-ldbm build-bdb2 build-quipu + +build-progs: $(PROGRAMS) build-ldbm: ldbm-tools-$(BUILD_LDBM) ldbm-tools-no: @echo "run configure with --enable-ldbm to build LDBM tools" +ldbm-tools-yes ldbm-tools-mod: $(LDBMPROGRAMS) + build-bdb2: bdb2-tools-$(BUILD_BDB2) bdb2-tools-no: @echo "run configure with --enable-bdb2 to build BDB2 tools" -ldbm-tools-yes ldbm-tools-mod: $(PROGRAMS) - -bdb2-tools-yes bdb2-tools-mod: $(PROGRAMS2) - -build-edb2ldif: edb-$(HAVE_QUIPU) -edb-no: - @echo "run configure with --enable-quipu to build edb2ldif" -edb-yes: edb2ldif - -edb2ldif: edb2-vers.o - $(CC) $(LDFLAGS) -o $@ $(EDB2LDIFOBJS) edb2-vers.o $(LIBS) - -edb2-vers.c: $(EDB2LDIFOBJS) - @-$(RM) $@ - $(MKVERSION) ebd2ldif > $@ - -build-chlog2replog: chlog-$(HAVE_QUIPU) -chlog-no: - @echo "run configure with --enable-quipu to build chlog2replog" -chlog-yes: chlog2replog - -chlog2replog: chlog2replog.o ../lock.o ../ch_malloc.o $(SLAPD_LIBDEPEND) - $(LTLINK) -o $@ chlog2replog.o ../lock.o ../ch_malloc.o $(LIBS) - -ldif2index: ldif2index.o ../libbackends.a $(OBJS2) $(SLAPD_LIBDEPEND) - $(LTLINK) -o $@ ldif2index.o $(OBJS2) ../libbackends.a $(LIBS) - -ldif2index-bdb2: ldif2index-bdb2.o ../libbackends.a \ - $(OBJS2) $(SLAPD_LIBDEPEND) - $(LTLINK) -o $@ ldif2index-bdb2.o $(OBJS2) ../libbackends.a $(LIBS) +bdb2-tools-yes bdb2-tools-mod: $(BDB2PROGRAMS) -ldif2ldbm: ldif2ldbm.o ../libbackends.a $(OBJS2) $(SLAPD_LIBDEPEND) - $(LTLINK) -o $@ ldif2ldbm.o $(OBJS2) ../libbackends.a $(LIBS) +build-quipu: quipu-tools-$(BUILD_QUIPU) +quipu-tools-no: + @echo "run configure with --enable-quipu to build QUIPU tools" -ldif2ldbm-bdb2: ldif2ldbm-bdb2.o ../libbackends.a $(OBJS2) $(SLAPD_LIBDEPEND) - $(LTLINK) -o $@ ldif2ldbm-bdb2.o $(OBJS2) ../libbackends.a $(LIBS) +quipu-tools-yes quipu-tools-mod: $(QUIPUPROGRAMS) -ldif2id2entry: ldif2id2entry.o ../libbackends.a $(OBJS2) $(SLAPD_LIBDEPEND) - $(LTLINK) -o $@ ldif2id2entry.o $(OBJS2) ../libbackends.a $(LIBS) - -ldif2id2entry-bdb2: ldif2id2entry-bdb2.o ../libbackends.a \ - $(OBJS2) $(SLAPD_LIBDEPEND) - $(LTLINK) -o $@ ldif2id2entry-bdb2.o $(OBJS2) ../libbackends.a $(LIBS) - -ldif2id2children: ldif2id2children.o ../libbackends.a \ - $(OBJS2) $(SLAPD_LIBDEPEND) - $(LTLINK) -o $@ ldif2id2children.o $(OBJS2) ../libbackends.a $(LIBS) +# +# SLAP Tools +# +slapadd: slapadd.o ../libbackends.a $(SLAPOBJS) $(SLAPD_LIBDEPEND) + $(LTLINK) -o $@ slapadd.o $(SLAPOBJS) ../libbackends.a $(LIBS) -ldif2id2children-bdb2: ldif2id2children-bdb2.o ../libbackends.a \ - $(OBJS2) $(SLAPD_LIBDEPEND) - $(LTLINK) -o $@ ldif2id2children-bdb2.o $(OBJS2) ../libbackends.a $(LIBS) +slapcat: slapcat.o ../libbackends.a $(SLAPOBJS) $(SLAPD_LIBDEPEND) + $(LTLINK) -o $@ slapcat.o $(SLAPOBJS) ../libbackends.a $(LIBS) -ldbmcat: ldbmcat.o $(SLAPD_LIBDEPEND) - $(LTLINK) -o $@ ldbmcat.o $(LIBS) +slapindex: slapindex.o ../libbackends.a $(SLAPOBJS) $(SLAPD_LIBDEPEND) + $(LTLINK) -o $@ slapindex.o $(SLAPOBJS) ../libbackends.a $(LIBS) ldif: ldif.o $(SLAPD_LIBDEPEND) $(LTLINK) -o $@ ldif.o $(LIBS) +# +# LDBM Specific Tools +# centipede: centipede.o $(SLAPD_LIBDEPEND) $(LTLINK) -o $@ centipede.o $(LIBS) sizecount: sizecount.o ../phonetic.o ../ch_malloc.o $(SLAPD_LIBDEPEND) $(LTLINK) -o $@ sizecount.o ../phonetic.o ../ch_malloc.o $(LIBS) -ldbmtest: ldbmtest.o ../libbackends.a $(OBJS1) $(SLAPD_LIBDEPEND) - $(LTLINK) -o ldbmtest ldbmtest.o $(OBJS1) ../libbackends.a $(LIBS) +# +# BDBM Specific Tools +# + +# +# QUIPU Specific Tools +# +edb2ldif: edb2-vers.o + $(CC) $(LDFLAGS) -o $@ $(EDB2LDIFOBJS) edb2-vers.o $(LIBS) + +edb2-vers.c: $(EDB2LDIFOBJS) + @-$(RM) $@ + $(MKVERSION) ebd2ldif > $@ + +chlog2replog: chlog2replog.o ../lock.o ../ch_malloc.o $(SLAPD_LIBDEPEND) + $(LTLINK) -o $@ chlog2replog.o ../lock.o ../ch_malloc.o $(LIBS) clean-local: FORCE - $(RM) $(PROGRAMS) $(PROGRAMS2) $(XPROGRAMS) $(XSRCS) edb2-vers.c \ - *.o core .libs/* + $(RM) $(PROGRAMS) $(LDBMPROGRAMS2) $(BDB2PROGRAMS) $(QUIPUPROGRAM) \ + $(XPROGRAMS) $(XSRCS) *.o core .libs/* depend-local: FORCE - @DEPEND=no ; DEPEND_LDBM= ; DEPEND_BDB2= ; DEPEND_QUIPU= ; \ + @DEPEND_LDBM= ; DEPEND_BDB2= ; DEPEND_QUIPU= ; \ if [ "$(BUILD_LDBM)" != "no" ]; then \ - DEPEND_LDBM="$(SRCS)"; \ - DEPEND=yes ; \ + DEPEND_LDBM="$(LDBMSRCS)"; \ fi; \ if [ "$(BUILD_BDB2)" != "no" ]; then \ - DEPEND_BDB2="$(SRCS2)"; \ - DEPEND=yes ; \ + DEPEND_BDB2="$(BDBMSRCS)"; \ fi; \ - if [ "$(HAVE_QUIPU)" != "no" ]; then \ - DEPEND_QUIPU="$(QUIPUINCLUDEFLAG) chlog2replog.c $(EDB2LDIFSRCS)"; \ - DEPEND=yes ; \ + if [ "$(BUILD_QUIPU)" != "no" ]; then \ + DEPEND_QUIPU="$(QUIPUINCLUDEFLAG) $(QUIPUSRCS)"; \ fi; \ - if [ "$$DEPEND" = "yes" ]; then \ - $(MKDEP) $(DEFS) $(DEFINES) $$DEPEND_QUIPU \ - $$DEPEND_LDBM $$DEPEND_BDB2; \ - else \ - echo "slapd-tools: no dependencies to make"; \ - fi + $(MKDEP) $(DEFS) $(DEFINES) $(SRCS) $$DEPEND_QUIPU \ + $$DEPEND_LDBM $$DEPEND_BDB2 install-local: install-ldbm-$(BUILD_LDBM) install-bdb2-$(BUILD_BDB2) \ install-quipu-$(HAVE_QUIPU) @@ -165,24 +142,16 @@ install-ldbm-no install-bdb2-no install-quipu-no: install-ldbm-yes install-ldbm-mod: FORCE @-$(MKDIR) $(sbindir) - $(LTINSTALL) $(INSTALLFLAGS) -m 755 ldif2ldbm $(sbindir) ; \ - $(LTINSTALL) $(INSTALLFLAGS) -m 755 ldif2index $(sbindir) ; \ - $(LTINSTALL) $(INSTALLFLAGS) -m 755 ldif2id2entry $(sbindir) ; \ - $(LTINSTALL) $(INSTALLFLAGS) -m 755 ldif2id2children $(sbindir) ; \ - $(LTINSTALL) $(INSTALLFLAGS) -m 755 ldbmcat $(sbindir) ; \ + $(LTINSTALL) $(INSTALLFLAGS) -m 755 slapcat $(sbindir) ; \ + $(LTINSTALL) $(INSTALLFLAGS) -m 755 slapentry $(sbindir) ; \ + $(LTINSTALL) $(INSTALLFLAGS) -m 755 slapindex $(sbindir) ; \ $(LTINSTALL) $(INSTALLFLAGS) -m 755 ldif $(sbindir) ; \ - $(LTINSTALL) $(INSTALLFLAGS) -m 755 centipede $(sbindir) ; \ - $(LTINSTALL) $(INSTALLFLAGS) -m 755 ldbmtest $(sbindir) + $(LTINSTALL) $(INSTALLFLAGS) -m 755 centipede $(sbindir) install-bdb2-yes install-bdb2-mod: FORCE @-$(MKDIR) $(sbindir) - $(LTINSTALL) $(INSTALLFLAGS) -m 755 ldif2ldbm-bdb2 $(sbindir) ; \ - $(LTINSTALL) $(INSTALLFLAGS) -m 755 ldif2index-bdb2 $(sbindir) ; \ - $(LTINSTALL) $(INSTALLFLAGS) -m 755 ldif2id2entry-bdb2 $(sbindir) ; \ - $(LTINSTALL) $(INSTALLFLAGS) -m 755 ldif2id2children-bdb2 $(sbindir) install-quipu-yes: FORCE @-$(MKDIR) $(sbindir) $(LTINSTALL) $(INSTALLFLAGS) -m 755 edb2ldif $(sbindir); \ $(LTINSTALL) $(INSTALLFLAGS) -m 755 chlog2replog $(sbindir) - diff --git a/servers/slapd/tools/centipede.c b/servers/slapd/tools/centipede.c index e0927ccc1a..be3f03baab 100644 --- a/servers/slapd/tools/centipede.c +++ b/servers/slapd/tools/centipede.c @@ -10,11 +10,11 @@ #include #include /* get link(), unlink() */ -#include #include - #include +int slap_debug; + #define DEFAULT_LDAPFILTER "(objectclass=*)" #define CENTROID_VALUE 1 @@ -565,10 +565,8 @@ diff_centroids( int amax, acur, dmax, dcur; char **vals; -#ifdef HAVE_BERKELEY_DB2 - DBC *ocursorp; - DBC *ncursorp; -#endif /* HAVE_BERKELEY_DB2 */ + LDBMCursor *ocursorp; + LDBMCursor *ncursorp; if ( verbose ) { printf( "Generating mods for differential %s centroid...", attr ); @@ -622,14 +620,10 @@ diff_centroids( olast.dptr = NULL; nlast.dptr = NULL; -#ifdef HAVE_BERKELEY_DB2 + for ( okey = ldbm_firstkey( oldbm, &ocursorp ), nkey = ldbm_firstkey( nldbm, &ncursorp ); okey.dptr != NULL && nkey.dptr != NULL; ) -#else - for ( okey = ldbm_firstkey( oldbm ), nkey = ldbm_firstkey( nldbm ); - okey.dptr != NULL && nkey.dptr != NULL; ) -#endif { int rc = strcmp( okey.dptr, nkey.dptr ); @@ -644,13 +638,9 @@ diff_centroids( } nlast = nkey; -#ifdef HAVE_BERKELEY_DB2 okey = ldbm_nextkey( oldbm, olast, ocursorp ); nkey = ldbm_nextkey( nldbm, nlast, ncursorp ); -#else - okey = ldbm_nextkey( oldbm, olast ); - nkey = ldbm_nextkey( nldbm, nlast ); -#endif + } else if ( rc > 0 ) { /* new value is not in old centroid - add it */ if ( charray_add_dup( &avals, &acur, &amax, nkey.dptr ) == NULL ) { @@ -663,11 +653,8 @@ diff_centroids( } nlast = nkey; -#ifdef HAVE_BERKELEY_DB2 nkey = ldbm_nextkey( nldbm, nlast, ncursorp ); -#else - nkey = ldbm_nextkey( nldbm, nlast ); -#endif + } else { /* old value is not in new centroid - delete it */ if ( charray_add_dup( &dvals, &dcur, &dmax, okey.dptr ) == NULL ) { @@ -680,11 +667,7 @@ diff_centroids( } olast = okey; -#ifdef HAVE_BERKELEY_DB2 okey = ldbm_nextkey( oldbm, olast, ocursorp ); -#else - okey = ldbm_nextkey( oldbm, olast ); -#endif } } @@ -694,11 +677,7 @@ diff_centroids( return( NULL ); } -#ifdef HAVE_BERKELEY_DB2 okey = ldbm_nextkey( oldbm, olast, ocursorp ); -#else - okey = ldbm_nextkey( oldbm, olast ); -#endif if ( olast.dptr != NULL ) { ldbm_datum_free( oldbm, olast ); } @@ -713,11 +692,7 @@ diff_centroids( return( NULL ); } -#ifdef HAVE_BERKELEY_DB2 nkey = ldbm_nextkey( nldbm, nlast, ncursorp ); -#else - nkey = ldbm_nextkey( nldbm, nlast ); -#endif if ( nlast.dptr != NULL ) { ldbm_datum_free( nldbm, nlast ); } @@ -738,13 +713,8 @@ diff_centroids( /* generate list of values to add */ lastkey.dptr = NULL; -#ifdef HAVE_BERKELEY_DB2 for ( key = ldbm_firstkey( nldbm, &ncursorp ); key.dptr != NULL; key = ldbm_nextkey( nldbm, lastkey, ncursorp ) ) -#else - for ( key = ldbm_firstkey( nldbm ); key.dptr != NULL; - key = ldbm_nextkey( nldbm, lastkey ) ) -#endif { /* see if it's in the old one */ data = ldbm_fetch( oldbm, key ); @@ -769,13 +739,8 @@ diff_centroids( /* generate list of values to delete */ lastkey.dptr = NULL; -#ifdef HAVE_BERKELEY_DB2 for ( key = ldbm_firstkey( oldbm, &ocursorp ); key.dptr != NULL; key = ldbm_nextkey( oldbm, lastkey, ocursorp ) ) -#else - for ( key = ldbm_firstkey( oldbm ); key.dptr != NULL; - key = ldbm_nextkey( oldbm, lastkey ) ) -#endif { /* see if it's in the new one */ data = ldbm_fetch( nldbm, key ); @@ -836,9 +801,7 @@ full_centroid( char **vals; int vcur, vmax; -#ifdef HAVE_BERKELEY_DB2 - DBC *cursorp; -#endif + LDBMCursor *cursorp; if ( verbose ) { printf( "Generating mods for full %s centroid...", attr ); @@ -870,13 +833,9 @@ full_centroid( lastkey.dptr = NULL; vals = NULL; vcur = vmax = 0; -#ifdef HAVE_BERKELEY_DB2 + for ( key = ldbm_firstkey( ldbm, &cursorp ); key.dptr != NULL; key = ldbm_nextkey( ldbm, lastkey, cursorp ) ) -#else - for ( key = ldbm_firstkey( ldbm ); key.dptr != NULL; - key = ldbm_nextkey( ldbm, lastkey ) ) -#endif { if ( charray_add_dup( &vals, &vcur, &vmax, key.dptr ) == NULL ) { ldap_mods_free( mods, 1 ); diff --git a/servers/slapd/tools/ldbmcat.c b/servers/slapd/tools/ldbmcat.c deleted file mode 100644 index 7580c2efdc..0000000000 --- a/servers/slapd/tools/ldbmcat.c +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Copyright 1998-1999 The OpenLDAP Foundation, All Rights Reserved. - * COPYING RESTRICTIONS APPLY, see COPYRIGHT file - */ -#include "portable.h" - -#include - -#include -#include -#include -#include - -#include "ldbm.h" -#include "../slap.h" - -static void -usage( char *name ) -{ - fprintf( stderr, "usage: %s [-n] \n", name ); -} - -int -main( int argc, char **argv ) -{ - Datum key, data; - LDBM dbp; - char *file, *s; - int printid = 1; - -#ifdef HAVE_BERKELEY_DB2 - DBC *cursorp; -#endif - - ldbm_datum_init( key ); - ldbm_datum_init( data ); - - if ( argc < 2 || argc > 3 || ( argc == 3 && strcmp( argv[1], "-n" ) - != 0 )) { - usage( argv[0] ); - return EXIT_FAILURE; - } - if ( argc == 3 && strcmp( argv[1], "-n" ) == 0 ) { - printid = 0; - file = argv[2]; - } else { - file = argv[1]; - } - - if ( (dbp = ldbm_open( file, LDBM_READER, 0, 0 )) == NULL ) { - perror( file ); - return EXIT_FAILURE; - } - -#ifdef HAVE_BERKELEY_DB2 - for ( key = ldbm_firstkey( dbp, &cursorp ); key.dptr != NULL; - key = ldbm_nextkey( dbp, key, cursorp ) ) -#else - for ( key = ldbm_firstkey( dbp ); key.dptr != NULL; - key = ldbm_nextkey( dbp, key ) ) -#endif - { - data = ldbm_fetch( dbp, key ); - - if (( s = data.dptr ) != NULL ) { - - if ( !printid && isdigit( (unsigned char) *s )) { - if (( s = strchr( s, '\n' )) != NULL ) { - ++s; - } - } - if ( s != NULL ) { - puts( s ); - } - - ldbm_datum_free( dbp, data ); - } - } - - ldbm_close( dbp ); - - return EXIT_SUCCESS; -} diff --git a/servers/slapd/tools/ldbmcat.dsp b/servers/slapd/tools/ldbmcat.dsp deleted file mode 100644 index e74b773e51..0000000000 --- a/servers/slapd/tools/ldbmcat.dsp +++ /dev/null @@ -1,148 +0,0 @@ -# Microsoft Developer Studio Project File - Name="ldbmcat" - Package Owner=<4> -# Microsoft Developer Studio Generated Build File, Format Version 5.00 -# ** DO NOT EDIT ** - -# TARGTYPE "Win32 (x86) Console Application" 0x0103 - -CFG=ldbmcat - Win32 Single Debug -!MESSAGE This is not a valid makefile. To build this project using NMAKE, -!MESSAGE use the Export Makefile command and run -!MESSAGE -!MESSAGE NMAKE /f "ldbmcat.mak". -!MESSAGE -!MESSAGE You can specify a configuration when running NMAKE -!MESSAGE by defining the macro CFG on the command line. For example: -!MESSAGE -!MESSAGE NMAKE /f "ldbmcat.mak" CFG="ldbmcat - Win32 Single Debug" -!MESSAGE -!MESSAGE Possible choices for configuration are: -!MESSAGE -!MESSAGE "ldbmcat - Win32 Release" (based on "Win32 (x86) Console Application") -!MESSAGE "ldbmcat - Win32 Debug" (based on "Win32 (x86) Console Application") -!MESSAGE "ldbmcat - Win32 Single Debug" (based on\ - "Win32 (x86) Console Application") -!MESSAGE "ldbmcat - Win32 Single Release" (based on\ - "Win32 (x86) Console Application") -!MESSAGE - -# Begin Project -# PROP Scc_ProjName "" -# PROP Scc_LocalPath "" -CPP=cl.exe -RSC=rc.exe - -!IF "$(CFG)" == "ldbmcat - Win32 Release" - -# PROP BASE Use_MFC 0 -# PROP BASE Use_Debug_Libraries 0 -# PROP BASE Output_Dir "Release" -# PROP BASE Intermediate_Dir "Release" -# PROP BASE Target_Dir "" -# PROP Use_MFC 0 -# PROP Use_Debug_Libraries 0 -# PROP Output_Dir "..\Release" -# PROP Intermediate_Dir "..\Release\ldbmcat" -# PROP Ignore_Export_Lib 0 -# PROP Target_Dir "" -# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c -# ADD CPP /nologo /MT /W3 /GX /O2 /I "..\..\..\include" /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c -# ADD BASE RSC /l 0x409 /d "NDEBUG" -# ADD RSC /l 0x409 /d "NDEBUG" -BSC32=bscmake.exe -# ADD BASE BSC32 /nologo -# ADD BSC32 /nologo -LINK32=link.exe -# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 -# ADD LINK32 libdb.lib /nologo /subsystem:console /machine:I386 /libpath:"..\..\..\libraries\Release" - -!ELSEIF "$(CFG)" == "ldbmcat - Win32 Debug" - -# PROP BASE Use_MFC 0 -# PROP BASE Use_Debug_Libraries 1 -# PROP BASE Output_Dir "ldbmcat_" -# PROP BASE Intermediate_Dir "ldbmcat_" -# PROP BASE Target_Dir "" -# PROP Use_MFC 0 -# PROP Use_Debug_Libraries 1 -# PROP Output_Dir "..\Debug" -# PROP Intermediate_Dir "..\Debug\ldbmcat" -# PROP Ignore_Export_Lib 0 -# PROP Target_Dir "" -# ADD BASE CPP /nologo /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c -# ADD CPP /nologo /MTd /W3 /Gm /GX /Zi /Od /I "..\..\..\include" /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /FR /YX /FD /c -# ADD BASE RSC /l 0x409 /d "_DEBUG" -# ADD RSC /l 0x409 /d "_DEBUG" -BSC32=bscmake.exe -# ADD BASE BSC32 /nologo -# ADD BSC32 /nologo -LINK32=link.exe -# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept -# ADD LINK32 libdb.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept /libpath:"..\..\..\libraries\Debug" - -!ELSEIF "$(CFG)" == "ldbmcat - Win32 Single Debug" - -# PROP BASE Use_MFC 0 -# PROP BASE Use_Debug_Libraries 1 -# PROP BASE Output_Dir "ldbmcat_" -# PROP BASE Intermediate_Dir "ldbmcat_" -# PROP BASE Ignore_Export_Lib 0 -# PROP BASE Target_Dir "" -# PROP Use_MFC 0 -# PROP Use_Debug_Libraries 1 -# PROP Output_Dir "..\Sdebug" -# PROP Intermediate_Dir "..\SDebug\ldbmcat" -# PROP Ignore_Export_Lib 0 -# PROP Target_Dir "" -# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /Zi /Od /I "..\..\..\include" /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c -# ADD CPP /nologo /W3 /Gm /GX /Zi /Od /I "..\..\..\include" /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /FR /YX /FD /c -# ADD BASE RSC /l 0x409 /d "_DEBUG" -# ADD RSC /l 0x409 /d "_DEBUG" -BSC32=bscmake.exe -# ADD BASE BSC32 /nologo -# ADD BSC32 /nologo -LINK32=link.exe -# ADD BASE LINK32 oldbm32.lib libdb.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept /libpath:"..\..\..\libraries\Debug" -# ADD LINK32 libdb.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept /libpath:"..\..\..\libraries\Debug" - -!ELSEIF "$(CFG)" == "ldbmcat - Win32 Single Release" - -# PROP BASE Use_MFC 0 -# PROP BASE Use_Debug_Libraries 0 -# PROP BASE Output_Dir "ldbmcat0" -# PROP BASE Intermediate_Dir "ldbmcat0" -# PROP BASE Target_Dir "" -# PROP Use_MFC 0 -# PROP Use_Debug_Libraries 0 -# PROP Output_Dir "..\SRelease" -# PROP Intermediate_Dir "..\SRelease\ldbmcat" -# PROP Ignore_Export_Lib 0 -# PROP Target_Dir "" -# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c -# ADD CPP /nologo /W3 /GX /O2 /I "..\..\..\include" /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c -# ADD BASE RSC /l 0x409 /d "NDEBUG" -# ADD RSC /l 0x409 /d "NDEBUG" -BSC32=bscmake.exe -# ADD BASE BSC32 /nologo -# ADD BSC32 /nologo -LINK32=link.exe -# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib libdb.lib /nologo /subsystem:console /machine:I386 /libpath:"..\..\..\libraries\Release" -# ADD LINK32 libdbs.lib /nologo /subsystem:console /machine:I386 /libpath:"..\..\..\libraries\Release" - -!ENDIF - -# Begin Target - -# Name "ldbmcat - Win32 Release" -# Name "ldbmcat - Win32 Debug" -# Name "ldbmcat - Win32 Single Debug" -# Name "ldbmcat - Win32 Single Release" -# Begin Source File - -SOURCE=.\ldbmcat.c -# End Source File -# Begin Source File - -SOURCE=.\mimic.c -# End Source File -# End Target -# End Project diff --git a/servers/slapd/tools/ldbmcat.dsw b/servers/slapd/tools/ldbmcat.dsw deleted file mode 100644 index 61f9a1bb4b..0000000000 --- a/servers/slapd/tools/ldbmcat.dsw +++ /dev/null @@ -1,44 +0,0 @@ -Microsoft Developer Studio Workspace File, Format Version 5.00 -# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE! - -############################################################################### - -Project: "ldbmcat"=.\ldbmcat.dsp - Package Owner=<4> - -Package=<5> -{{{ -}}} - -Package=<4> -{{{ - Begin Project Dependency - Project_Dep_Name libldbm - End Project Dependency -}}} - -############################################################################### - -Project: "libldbm"=..\..\..\libraries\libldbm\libldbm.dsp - Package Owner=<4> - -Package=<5> -{{{ -}}} - -Package=<4> -{{{ -}}} - -############################################################################### - -Global: - -Package=<5> -{{{ -}}} - -Package=<3> -{{{ -}}} - -############################################################################### - diff --git a/servers/slapd/tools/ldbmtest.c b/servers/slapd/tools/ldbmtest.c index fb058df05b..b0a6766b2c 100644 --- a/servers/slapd/tools/ldbmtest.c +++ b/servers/slapd/tools/ldbmtest.c @@ -57,9 +57,12 @@ main( int argc, char **argv ) int i; char *tailorfile; -#ifdef HAVE_BERKELEY_DB2 - DBC *cursorp; -#endif + LDBMCursor *cursorp; + + fprintf(stderr, + "ldbmtest not updated to support new index formats!\n" ); + exit( EXIT_FAILURE ); + ldbm_datum_init( savekey ); ldbm_datum_init( key ); @@ -91,7 +94,7 @@ main( int argc, char **argv ) slap_init(SLAP_TOOL_MODE, "ldbmtest"); read_config( tailorfile ); - slap_startup(-1); + slap_startup( NULL ); while ( 1 ) { printf( "dbtest: " ); @@ -114,7 +117,7 @@ main( int argc, char **argv ) } break; - case 'l': /* lookup somethig in an index */ + case 'l': /* lookup something in an index */ if ( (dbc = openchoice( buf[1], LDBM_READER, 1, NULL )) == NULL ) { continue; @@ -153,15 +156,9 @@ main( int argc, char **argv ) } savekey.dptr = NULL; -#ifdef HAVE_BERKELEY_DB2 for ( key = ldbm_firstkey( dbc->dbc_db, &cursorp ); key.dptr != NULL; key = ldbm_nextkey( dbc->dbc_db, key, cursorp ) ) -#else - for ( key = ldbm_firstkey( dbc->dbc_db ); - key.dptr != NULL; - key = ldbm_nextkey( dbc->dbc_db, key ) ) -#endif { if ( savekey.dptr != NULL ) ldbm_datum_free( dbc->dbc_db, savekey ); @@ -327,14 +324,9 @@ main( int argc, char **argv ) last.dptr = NULL; -#ifdef HAVE_BERKELEY_DB2 for ( key = ldbm_firstkey( dbp, &cursorp ); key.dptr != NULL; key = ldbm_nextkey( dbp, last, cursorp ) ) -#else - for ( key = ldbm_firstkey( dbp ); key.dptr != NULL; - key = ldbm_nextkey( dbp, last ) ) -#endif { if ( last.dptr != NULL ) { ldbm_datum_free( dbp, last ); @@ -360,7 +352,6 @@ main( int argc, char **argv ) printf( " b => change default backend\n" ); printf( " B => print default backend\n" ); printf( "where is a char selecting the index:\n" ); - printf( " c => id2children\n" ); printf( " d => dn2id\n" ); printf( " e => id2entry\n" ); printf( " f => arbitrary file\n" ); @@ -369,7 +360,7 @@ main( int argc, char **argv ) } } - slap_shutdown(-1); + slap_shutdown( NULL ); slap_destroy(); return( EXIT_SUCCESS ); @@ -608,9 +599,6 @@ openchoice( char c, int mode, int verbose, char **fname ) static char name[MAXPATHLEN]; switch ( c ) { - case 'c': /* id2children */ - sprintf( name, "id2children" ); - break; case 'd': /* dn2id */ sprintf( name, "dn2id" ); break; @@ -626,7 +614,7 @@ openchoice( char c, int mode, int verbose, char **fname ) } break; default: - printf( "specify one of [fdeci] to select file\n" ); + printf( "specify one of [fdei] to select file\n" ); return( NULL ); break; } @@ -689,7 +677,6 @@ print_entry( } break; - case 'c': case 'i': /* index - key is string, data is dnid[] */ if ( key != NULL ) fprintf( fp, "%s%s (len %d)\n", klabel, key->dptr, @@ -706,8 +693,7 @@ print_entry( fprintf( fp, "\t%ld\n", ID_BLOCK_ID(idl, i) ); } } else if ( ID_BLOCK_ALLIDS( idl ) ) { - fprintf( fp, "\tALLIDS (1..%ld)\n", - ID_BLOCK_NIDS(idl) - 1 ); + fprintf( fp, "\tALLIDS\n" ); } else { for ( i = 0; i < ID_BLOCK_NIDS(idl); i++ ) { fprintf( fp, "\t%ld\n", ID_BLOCK_ID(idl,i) ); @@ -726,7 +712,7 @@ print_entry( break; default: - fprintf( stderr, "specify [deci] to select a file\n" ); + fprintf( stderr, "specify [dei] to select a file\n" ); break; } } @@ -785,7 +771,6 @@ get_keydata( FILE *fp, char c, Datum *key, Datum *data ) } break; - case 'c': /* id2children - key is string dnid, data is dnid[] */ case 'i': /* index - key is string, data is dnid[] */ if ( key != NULL ) { if ( tty ) @@ -804,7 +789,7 @@ get_keydata( FILE *fp, char c, Datum *key, Datum *data ) break; default: - fprintf(stderr, "specify [deci] to select file type\n"); + fprintf(stderr, "specify [dei] to select file type\n"); break; } } diff --git a/servers/slapd/tools/ldbmtest.dsp b/servers/slapd/tools/ldbmtest.dsp index 6bd91f19b9..b7202b6af5 100644 --- a/servers/slapd/tools/ldbmtest.dsp +++ b/servers/slapd/tools/ldbmtest.dsp @@ -70,7 +70,7 @@ LINK32=link.exe # PROP Ignore_Export_Lib 0 # PROP Target_Dir "" # ADD BASE CPP /nologo /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c -# ADD CPP /nologo /MTd /W3 /Gm /GX /Zi /Od /I "..\..\..\include" /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c +# ADD CPP /nologo /MTd /W3 /Gm /GX /Zi /Od /I "..\..\..\include" /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /FR /YX /FD /c # ADD BASE RSC /l 0x409 /d "_DEBUG" # ADD RSC /l 0x409 /d "_DEBUG" BSC32=bscmake.exe diff --git a/servers/slapd/tools/ldif2common.c b/servers/slapd/tools/ldif2common.c deleted file mode 100644 index 3bc52e04a5..0000000000 --- a/servers/slapd/tools/ldif2common.c +++ /dev/null @@ -1,203 +0,0 @@ -/* - * Copyright 1998-1999 The OpenLDAP Foundation, All Rights Reserved. - * COPYING RESTRICTIONS APPLY, see COPYRIGHT file - */ -/* ldif2common.c - common definitions for the ldif2* tools */ - -#include "portable.h" - -#include - -#include -#include -#include -#include -#include - -#include "ldif2common.h" - - -char *progname; -char *tailorfile = SLAPD_DEFAULT_CONFIGFILE; -char *inputfile = NULL; -char *sbindir = LDAP_SBINDIR; /* used by ldif2ldbm */ -int cmdkids = 1; /* used by ldif2ldbm */ -int dbnum; - - -static void -usage( int tool ) -{ - fprintf( stderr, "usage: %s %s\n\t%s%s\n", - progname, "-i inputfile [-d debuglevel] [-f configfile]", - "[-n databasenumber]", - ((tool == LDIF2LDBM) ? " [-j #jobs] [-s sbindir]" : - (tool == LDIF2INDEX) ? " attr" : - "") ); - exit( EXIT_FAILURE ); -} - - -/* - * slap_ldif_init - initialize ldif utility, handle program options. - * args: tool - which ldif2* program is running. - * argc, argv - from main. - * dbtype - "ldbm"/"bdb2". - * options - to getopt. - */ - -void -slap_ldif_init( int argc, char **argv, int tool, const char *dbtype, int mode ) -{ - char *options = (tool == LDIF2LDBM ? "e:s:j:d:f:i:n:" : "d:f:i:n:"); - int rc, i; - - progname = strrchr ( argv[0], '/' ); - progname = ch_strdup( progname ? progname + 1 : argv[0] ); - - inputfile = NULL; - tailorfile = SLAPD_DEFAULT_CONFIGFILE; - dbnum = -1; - while ( (i = getopt( argc, argv, options )) != EOF ) { - switch ( i ) { - case 'd': /* turn on debugging */ - ldap_debug = atoi( optarg ); - break; - - case 's': /* alternate sbindir (index cmd location) */ - case 'e': /* accept -e for backwards compatibility */ - /* only used by ldif2ldbm and ldif2ldbm-bdb2 */ - sbindir = strdup( optarg ); - break; - - case 'f': /* specify a tailor file */ - tailorfile = strdup( optarg ); - break; - - case 'i': /* input file */ - inputfile = strdup( optarg ); - break; - - case 'j': /* number of parallel index procs */ - /* only in ldif2ldbm and ldif2ldbm-bdb2 */ - cmdkids = atoi( optarg ); - break; - - case 'n': /* which config file db to index */ - dbnum = atoi( optarg ) - 1; - break; - - default: - usage( tool ); - break; - } - } - if ( inputfile == NULL || (argc != optind + (tool == LDIF2INDEX)) ) - usage( tool ); - - if ( freopen( inputfile, "r", stdin ) == NULL ) { - perror( inputfile ); - exit( EXIT_FAILURE ); - } - - /* - * initialize stuff and figure out which backend we're dealing with - */ - - rc = slap_init( mode, progname ); - if (rc != 0 ) { - fprintf( stderr, "%s: slap_init failed!\n", progname ); - exit( EXIT_FAILURE ); - } - - read_config( tailorfile ); - - if ( dbnum == -1 ) { - for ( dbnum = 0; dbnum < nbackends; dbnum++ ) { - if ( strcasecmp( backends[dbnum].be_type, dbtype ) - == 0 ) { - break; - } - } - if ( dbnum == nbackends ) { - fprintf( stderr, "No %s database found in config file\n", dbtype ); - exit( EXIT_FAILURE ); - } - } else if ( dbnum < 0 || dbnum > (nbackends-1) ) { - fprintf( stderr, "Database number selected via -n is out of range\n" ); - fprintf( stderr, "Must be in the range 1 to %d (number of databases in the config file)\n", nbackends ); - exit( EXIT_FAILURE ); - } else if ( strcasecmp( backends[dbnum].be_type, dbtype ) != 0 ) { - fprintf( stderr, "Database number %d selected via -n is not an %s database\n", dbnum, dbtype ); - exit( EXIT_FAILURE ); - } -} - - -#define IDBUFSIZ 100 /* enough to hold \n\0 */ - -/* - * slap_read_ldif - read an ldif record. Return 1 for success, 0 for EOF. - */ -int -slap_read_ldif( - int *lno, /* ptr to line number counter */ - char **bufp, /* ptr to malloced output buffer */ - int *buflenp, /* ptr to length of *bufp */ - ID *idp, /* ptr to ID number to be read/incremented */ - int idout ) /* flag to begin *buf with ID number */ -{ - char linebuf[IDBUFSIZ + BUFSIZ], *line; - ber_len_t lcur = 0, idlen, len, linesize; - int last_ch = '\n', found_entry = 0, stop; - - line = linebuf + IDBUFSIZ; - linesize = sizeof( linebuf ) - IDBUFSIZ; - - for ( stop = feof( stdin ); !stop; last_ch = line[len-1] ) { - if ( fgets( line, linesize, stdin ) == NULL ) { - stop = 1; - /* Add \n in case the file does not end with newline */ - line = "\n"; - } - len = strlen( line ); - - if ( last_ch == '\n' ) { - (*lno)++; - - if ( line[0] == '\n' ) { - if ( !found_entry ) - continue; - break; - } - - if ( !found_entry ) { - /* Found a new entry */ - found_entry = 1; - - if ( isdigit( (unsigned char) line[0] ) ) { - *idp = atol( line ); - if ( !idout ) - continue; - } else { - ++(*idp); - if ( idout ) { - sprintf( linebuf, "%ld\n", (long) *idp ); - idlen = strlen( linebuf ); - line -= idlen; - linesize += idlen; - len += idlen; - SAFEMEMCPY( line, linebuf, idlen ); - } - } - } - } - - if ( *buflenp - lcur <= len ) - *bufp = ch_realloc( *bufp, *buflenp += len + BUFSIZ ); - strcpy( *bufp + lcur, line ); - lcur += len; - } - - return( found_entry ); -} diff --git a/servers/slapd/tools/ldif2common.h b/servers/slapd/tools/ldif2common.h deleted file mode 100644 index 0d63a8b7c2..0000000000 --- a/servers/slapd/tools/ldif2common.h +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright 1998-1999 The OpenLDAP Foundation, All Rights Reserved. - * COPYING RESTRICTIONS APPLY, see COPYRIGHT file - */ -/* ldif2common.h - common definitions for the ldif2* tools */ - -#ifndef LDIF2COMMON_H_ -#define LDIF2COMMON_H_ - -#include "ldap_defaults.h" -#include "../slap.h" - -enum ldiftool { - LDIF2LDBM = 1, LDIF2INDEX, LDIF2ID2ENTRY, LDIF2ID2CHILDREN -}; - - -extern char *progname; -extern char *tailorfile; -extern char *inputfile; -extern char *sbindir; -extern int cmdkids; -extern int dbnum; - - -void slap_ldif_init LDAP_P(( int, char **, int, const char *, int )); -int slap_read_ldif LDAP_P(( int *, char **, int *, ID *, int )); - - -#endif /* LDIF2COMMON_H_ */ diff --git a/servers/slapd/tools/ldif2id2children-bdb2.c b/servers/slapd/tools/ldif2id2children-bdb2.c deleted file mode 100644 index caa49a82a0..0000000000 --- a/servers/slapd/tools/ldif2id2children-bdb2.c +++ /dev/null @@ -1,247 +0,0 @@ -#include "portable.h" - -#include - -#include - -#include -#include -#include -#include - -#include "ldif2common.h" -#include "../back-bdb2/back-bdb2.h" -#include "ldif.h" - -int -main( int argc, char **argv ) -{ - int i, stop; - char *linep, *buf; - char line[BUFSIZ]; - int lineno, elineno; - int lmax, lcur; - ID id; - struct dbcache *db, *db2; - Backend *be = NULL; - struct ldbminfo *li; - struct berval bv; - struct berval *vals[2]; - - slap_ldif_init( argc, argv, LDIF2ID2CHILDREN, "bdb2", SLAP_TOOL_MODE ); - - slap_startup(dbnum); - be = &backends[dbnum]; - - /* disable write sync'ing */ - li = (struct ldbminfo *) be->be_private; - li->li_dbcachewsync = 0; - - /* - * first, make the dn2id index - */ - - if ( (db = bdb2i_cache_open( be, "dn2id", BDB2_SUFFIX, LDBM_NEWDB )) - == NULL ) { - perror( "dn2id file" ); - exit( EXIT_FAILURE ); - } - - id = 0; - stop = 0; - lineno = 0; - buf = NULL; - lcur = lmax = 0; - vals[0] = &bv; - vals[1] = NULL; - while ( ! stop ) { - char *type, *val, *s; - ber_len_t vlen; - Datum key, data; - - ldbm_datum_init( key ); - ldbm_datum_init( data ); - - if ( fgets( line, sizeof(line), stdin ) != NULL ) { - int len; - - lineno++; - len = strlen( line ); - while ( lcur + len + 1 > lmax ) { - lmax += BUFSIZ; - buf = (char *) ch_realloc( buf, lmax ); - } - strcpy( buf + lcur, line ); - lcur += len; - } else { - stop = 1; - } - if ( line[0] == '\n' || stop && buf && *buf ) { - if ( *buf != '\n' ) { - if (isdigit((unsigned char) *buf)) { - id = atol(buf); - } else { - id++; - } - s = buf; - elineno = 0; - while ( (linep = ldif_getline( &s )) != NULL ) { - elineno++; - if ( ldif_parse_line( linep, &type, &val, - &vlen ) != 0 ) { - Debug( LDAP_DEBUG_PARSE, - "bad line %d in entry ending at line %d ignored\n", - elineno, lineno, 0 ); - continue; - } - - if ( strcmp( type, "dn" ) == 0 ) - break; - } - - if ( linep == NULL ) { - fprintf( stderr, "entry %ld has no dn\n", - id ); - } else { - if( val != NULL ) { - (void) dn_normalize_case( val ); - } - key.dptr = val; - key.dsize = strlen( val != NULL ? val : "" ) + 1; - data.dptr = (char *) &id; - data.dsize = sizeof(ID); - if ( ldbm_store( db->dbc_db, key, data, - LDBM_REPLACE ) != 0 ) { - perror( "dn2id ldbm_store..." ); - exit( EXIT_FAILURE ); - } - } - } - *buf = '\0'; - lcur = 0; - line[0] = '\0'; - } - } - if ( buf ) - free( buf ); - - /* - * next, make the id2children index - */ - - if ( (db2 = bdb2i_cache_open( be, "id2children", BDB2_SUFFIX, - LDBM_NEWDB )) == NULL ) { - perror( "id2children file" ); - exit( EXIT_FAILURE ); - } - - rewind( stdin ); - id = 0; - stop = 0; - buf = NULL; - lineno = 0; - lcur = lmax = 0; - vals[0] = &bv; - vals[1] = NULL; - while ( ! stop ) { - char *type, *val, *s, *dn; - ber_len_t vlen; - ID pid; - char buf2[20]; - Datum key, data; - - ldbm_datum_init( key ); - ldbm_datum_init( data ); - - if ( fgets( line, sizeof(line), stdin ) != NULL ) { - int len; - - len = strlen( line ); - while ( lcur + len + 1 > lmax ) { - lmax += BUFSIZ; - buf = (char *) ch_realloc( buf, lmax ); - } - strcpy( buf + lcur, line ); - lcur += len; - } else { - stop = 1; - } - if ( line[0] == '\n' || stop && buf && *buf ) { - if ( * buf != '\n' ) { - if (isdigit((unsigned char) *buf)) { - id = atol(buf); - } else { - id++; - } - s = buf; - while ( (linep = ldif_getline( &s )) != NULL ) { - if ( ldif_parse_line( linep, &type, &val, - &vlen ) != 0 ) { - Debug( LDAP_DEBUG_PARSE, - "bad line %d ignored\n", - lineno, 0, 0 ); - continue; - } - - if ( strcmp( type, "dn" ) == 0 ) - break; - } - - if ( linep == NULL ) { - fprintf( stderr, "entry %ld has no dn\n", - id ); - } else { - if ( (dn = dn_parent( be, val )) - == NULL ) { - pid = 0; - } else { - (void) dn_normalize_case( dn ); - key.dptr = dn; - key.dsize = strlen( dn ) + 1; - - data = ldbm_fetch( db->dbc_db, - key ); - free( dn ); - if ( data.dptr == NULL ) { - (void) dn_normalize_case( val ); - if ( ! be_issuffix( be, - val ) ) { - Debug( LDAP_DEBUG_PARSE, "no parent \"%s\" of \"%s\"\n", dn, val, 0 ); - } - *buf = '\0'; - lcur = 0; - line[0] = '\0'; - continue; - } - (void) memcpy( (char *) &pid, - data.dptr, sizeof(ID) ); - - ldbm_datum_free( db->dbc_db, data); - } - - sprintf( buf2, "%c%ld", EQ_PREFIX, pid ); - key.dptr = buf2; - key.dsize = strlen( buf2 ) + 1; - if ( bdb2i_idl_insert_key( be, db2, key, id ) - != 0 ) { - perror( "bdb2i_idl_insert_key" ); - exit( EXIT_FAILURE ); - } - } - } - *buf = '\0'; - lcur = 0; - line[0] = '\0'; - } - } - -#ifdef SLAP_CLEANUP - bdb2i_cache_close( be, db2 ); - bdb2i_cache_close( be, db ); -#endif - - slap_shutdown(dbnum); - slap_destroy(); - - exit( EXIT_SUCCESS ); -} diff --git a/servers/slapd/tools/ldif2id2children.c b/servers/slapd/tools/ldif2id2children.c deleted file mode 100644 index 37d8190cf5..0000000000 --- a/servers/slapd/tools/ldif2id2children.c +++ /dev/null @@ -1,260 +0,0 @@ -/* - * Copyright 1998-1999 The OpenLDAP Foundation, All Rights Reserved. - * COPYING RESTRICTIONS APPLY, see COPYRIGHT file - */ -#include "portable.h" - -#include - -#include - -#include -#include -#include -#include - -#include "ldif2common.h" -#include "../back-ldbm/back-ldbm.h" -#include "ldif.h" - -int -main( int argc, char **argv ) -{ - char *linep, *buf; - int lineno, elineno; - int lmax; - ID id; - DBCache *db; -#ifndef DN_INDICES - DBCache *db2; -#endif - Backend *be = NULL; - struct ldbminfo *li; - struct berval bv; - struct berval *vals[2]; - - slap_ldif_init( argc, argv, LDIF2ID2CHILDREN, "ldbm", SLAP_TOOL_MODE ); - - slap_startup(dbnum); - be = &backends[dbnum]; - - /* disable write sync'ing */ - li = (struct ldbminfo *) be->be_private; - li->li_dbcachewsync = 0; - - /* - * first, make the dn2id index - */ - - if ( (db = ldbm_cache_open( be, "dn2id", LDBM_SUFFIX, LDBM_NEWDB )) - == NULL ) { - perror( "dn2id file" ); - exit( EXIT_FAILURE ); - } - - id = 0; - lineno = 0; - buf = NULL; - lmax = 0; - vals[0] = &bv; - vals[1] = NULL; - while ( slap_read_ldif( &lineno, &buf, &lmax, &id, 0 ) ) { - char *type, *val, *s; - ber_len_t vlen; - Datum key, data; - - ldbm_datum_init( key ); - ldbm_datum_init( data ); - - s = buf; - elineno = 0; - while ( (linep = ldif_getline( &s )) != NULL ) { - elineno++; - if ( ldif_parse_line( linep, &type, &val, - &vlen ) != 0 ) { - Debug( LDAP_DEBUG_PARSE, - "bad line %d in entry ending at line %d ignored\n", - elineno, lineno, 0 ); - continue; - } - - if ( strcmp( type, "dn" ) == 0 ) - break; - } - - if ( linep == NULL ) { - fprintf( stderr, "entry %ld has no dn\n", - id ); - } else { - if( val != NULL ) { - (void) dn_normalize_case( val ); - } -#ifndef DN_INDICES - key.dptr = val; - key.dsize = strlen( val != NULL ? val : "" ) + 1; -#else - key.dsize = strlen( val != NULL ? val : "" ) + 2; - key.dptr = ch_malloc( key.dsize ); - sprintf( key.dptr, "%c%s", DN_BASE_PREFIX, - val != NULL ? val : "" ); -#endif - data.dptr = (char *) &id; - data.dsize = sizeof(ID); - if ( ldbm_store( db->dbc_db, key, data, - LDBM_REPLACE ) != 0 ) { - perror( "dn2id ldbm_store" ); - exit( EXIT_FAILURE ); - } -#ifdef DN_INDICES - free( key.dptr ); - - { - int rc = 0; - char *pdn = dn_parent( NULL, val ); - - if( pdn != NULL ) { - key.dsize = strlen( pdn ) + 2; - key.dptr = ch_malloc( key.dsize ); - sprintf( key.dptr, "%c%s", - DN_ONE_PREFIX, pdn ); - rc = idl_insert_key( be, db, key, id ); - free( key.dptr ); - } - - if( rc == -1 ) { - perror( "dn2id dn_parent insert" ); - exit( EXIT_FAILURE ); - } - } - - { - int rc = 0; - char **subtree = dn_subtree( NULL, val ); - - if( subtree != NULL ) { - int i; - for( i=0; subtree[i] != NULL; i++ ) { - key.dsize = strlen( subtree[i] ) + 2; - key.dptr = ch_malloc( key.dsize ); - sprintf( key.dptr, "%c%s", - DN_SUBTREE_PREFIX, subtree[i] ); - - rc = idl_insert_key( be, db, key, id ); - - free( key.dptr ); - - if( rc == -1 ) { - perror( "dn2id dn_subtree insert" ); - exit( EXIT_FAILURE ); - } - } - - charray_free( subtree ); - } - - } -#endif - } - } - if ( buf ) - free( buf ); - - -#ifndef DN_INDICES - /* - * next, make the id2children index - */ - - if ( (db2 = ldbm_cache_open( be, "id2children", LDBM_SUFFIX, - LDBM_NEWDB )) == NULL ) { - perror( "id2children file" ); - exit( EXIT_FAILURE ); - } - - rewind( stdin ); - id = 0; - buf = NULL; - lineno = 0; - lmax = 0; - vals[0] = &bv; - vals[1] = NULL; - while ( slap_read_ldif( &lineno, &buf, &lmax, &id, 0 ) ) { - char *type, *val, *s, *dn; - ber_len_t vlen; - ID pid; - char buf2[20]; - Datum key, data; - - ldbm_datum_init( key ); - ldbm_datum_init( data ); - - s = buf; - while ( (linep = ldif_getline( &s )) != NULL ) { - if ( ldif_parse_line( linep, &type, &val, - &vlen ) != 0 ) { - Debug( LDAP_DEBUG_PARSE, - "bad line %d ignored\n", - lineno, 0, 0 ); - continue; - } - - if ( strcmp( type, "dn" ) == 0 ) - break; - } - - if ( linep == NULL ) { - fprintf( stderr, "entry %ld has no dn\n", - id ); - } else { - if ( (dn = dn_parent( be, val )) - == NULL ) { - pid = 0; - } else { - (void) dn_normalize_case( dn ); - key.dptr = dn; - key.dsize = strlen( dn ) + 1; - - data = ldbm_fetch( db->dbc_db, - key ); - free( dn ); - if ( data.dptr == NULL ) { - (void) dn_normalize_case( val ); - if ( ! be_issuffix( be, - val ) ) { - Debug( LDAP_DEBUG_PARSE, "no parent \"%s\" of \"%s\"\n", dn, val, 0 ); - } - continue; - } - (void) memcpy( (char *) &pid, - data.dptr, sizeof(ID) ); - - ldbm_datum_free( db->dbc_db, data); - } - - sprintf( buf2, "%c%ld", EQ_PREFIX, pid ); - key.dptr = buf2; - key.dsize = strlen( buf2 ) + 1; - if ( idl_insert_key( be, db2, key, id ) - != 0 ) { - perror( "idl_insert_key" ); - exit( EXIT_FAILURE ); - } - } - } - -#ifdef SLAP_CLEANUP - ldbm_cache_close( be, db2 ); - ldbm_cache_close( be, db ); -#endif -#else -#ifdef SLAP_CLEANUP - ldbm_cache_close( be, db ); -#endif -#endif - - - slap_shutdown(dbnum); - slap_destroy(); - - return( EXIT_SUCCESS ); -} diff --git a/servers/slapd/tools/ldif2id2children.dsp b/servers/slapd/tools/ldif2id2children.dsp deleted file mode 100644 index c165ee3176..0000000000 --- a/servers/slapd/tools/ldif2id2children.dsp +++ /dev/null @@ -1,160 +0,0 @@ -# Microsoft Developer Studio Project File - Name="ldif2id2children" - Package Owner=<4> -# Microsoft Developer Studio Generated Build File, Format Version 5.00 -# ** DO NOT EDIT ** - -# TARGTYPE "Win32 (x86) Console Application" 0x0103 - -CFG=ldif2id2children - Win32 Single Debug -!MESSAGE This is not a valid makefile. To build this project using NMAKE, -!MESSAGE use the Export Makefile command and run -!MESSAGE -!MESSAGE NMAKE /f "ldif2id2children.mak". -!MESSAGE -!MESSAGE You can specify a configuration when running NMAKE -!MESSAGE by defining the macro CFG on the command line. For example: -!MESSAGE -!MESSAGE NMAKE /f "ldif2id2children.mak"\ - CFG="ldif2id2children - Win32 Single Debug" -!MESSAGE -!MESSAGE Possible choices for configuration are: -!MESSAGE -!MESSAGE "ldif2id2children - Win32 Release" (based on\ - "Win32 (x86) Console Application") -!MESSAGE "ldif2id2children - Win32 Debug" (based on\ - "Win32 (x86) Console Application") -!MESSAGE "ldif2id2children - Win32 Single Debug" (based on\ - "Win32 (x86) Console Application") -!MESSAGE "ldif2id2children - Win32 Single Release" (based on\ - "Win32 (x86) Console Application") -!MESSAGE - -# Begin Project -# PROP Scc_ProjName "" -# PROP Scc_LocalPath "" -CPP=cl.exe -RSC=rc.exe - -!IF "$(CFG)" == "ldif2id2children - Win32 Release" - -# PROP BASE Use_MFC 0 -# PROP BASE Use_Debug_Libraries 0 -# PROP BASE Output_Dir "Release" -# PROP BASE Intermediate_Dir "Release" -# PROP BASE Target_Dir "" -# PROP Use_MFC 0 -# PROP Use_Debug_Libraries 0 -# PROP Output_Dir "..\Release" -# PROP Intermediate_Dir "..\Release\ldif2id2children" -# PROP Ignore_Export_Lib 0 -# PROP Target_Dir "" -# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c -# ADD CPP /nologo /MT /W3 /GX /O2 /I "..\..\..\include" /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c -# ADD BASE RSC /l 0x409 /d "NDEBUG" -# ADD RSC /l 0x409 /d "NDEBUG" -BSC32=bscmake.exe -# ADD BASE BSC32 /nologo -# ADD BSC32 /nologo -LINK32=link.exe -# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 -# ADD LINK32 hs_regex.lib libdb.lib ws2_32.lib /nologo /subsystem:console /machine:I386 - -!ELSEIF "$(CFG)" == "ldif2id2children - Win32 Debug" - -# PROP BASE Use_MFC 0 -# PROP BASE Use_Debug_Libraries 1 -# PROP BASE Output_Dir "Debug" -# PROP BASE Intermediate_Dir "Debug" -# PROP BASE Target_Dir "" -# PROP Use_MFC 0 -# PROP Use_Debug_Libraries 1 -# PROP Output_Dir "..\Debug" -# PROP Intermediate_Dir "..\Debug\ldif2id2children" -# PROP Ignore_Export_Lib 0 -# PROP Target_Dir "" -# ADD BASE CPP /nologo /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c -# ADD CPP /nologo /MTd /W3 /Gm /GX /Zi /Od /I "..\..\..\include" /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /FR /YX /FD /c -# ADD BASE RSC /l 0x409 /d "_DEBUG" -# ADD RSC /l 0x409 /d "_DEBUG" -BSC32=bscmake.exe -# ADD BASE BSC32 /nologo -# ADD BSC32 /nologo -LINK32=link.exe -# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept -# ADD LINK32 hs_regex.lib libdb.lib ws2_32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept - -!ELSEIF "$(CFG)" == "ldif2id2children - Win32 Single Debug" - -# PROP BASE Use_MFC 0 -# PROP BASE Use_Debug_Libraries 1 -# PROP BASE Output_Dir "ldif2id2" -# PROP BASE Intermediate_Dir "ldif2id2" -# PROP BASE Ignore_Export_Lib 0 -# PROP BASE Target_Dir "" -# PROP Use_MFC 0 -# PROP Use_Debug_Libraries 1 -# PROP Output_Dir "..\SDebug" -# PROP Intermediate_Dir "..\SDebug\ldif2id2children" -# PROP Ignore_Export_Lib 0 -# PROP Target_Dir "" -# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /Zi /Od /I "..\..\..\include" /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c -# ADD CPP /nologo /W3 /Gm /GX /Zi /Od /I "..\..\..\include" /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /FR /YX /FD /c -# ADD BASE RSC /l 0x409 /d "_DEBUG" -# ADD RSC /l 0x409 /d "_DEBUG" -BSC32=bscmake.exe -# ADD BASE BSC32 /nologo -# ADD BSC32 /nologo -LINK32=link.exe -# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib hs_regexd.lib libdbs.lib ws2_32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept -# ADD LINK32 hs_regex.lib libdbs.lib ws2_32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept - -!ELSEIF "$(CFG)" == "ldif2id2children - Win32 Single Release" - -# PROP BASE Use_MFC 0 -# PROP BASE Use_Debug_Libraries 0 -# PROP BASE Output_Dir "ldif2id0" -# PROP BASE Intermediate_Dir "ldif2id0" -# PROP BASE Ignore_Export_Lib 0 -# PROP BASE Target_Dir "" -# PROP Use_MFC 0 -# PROP Use_Debug_Libraries 0 -# PROP Output_Dir "..\SRelease" -# PROP Intermediate_Dir "..\SRelease\ldif2id2children" -# PROP Ignore_Export_Lib 0 -# PROP Target_Dir "" -# ADD BASE CPP /nologo /MT /W3 /GX /O2 /I "..\..\..\include" /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c -# ADD CPP /nologo /W3 /GX /O2 /I "..\..\..\include" /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c -# ADD BASE RSC /l 0x409 /d "NDEBUG" -# ADD RSC /l 0x409 /d "NDEBUG" -BSC32=bscmake.exe -# ADD BASE BSC32 /nologo -# ADD BSC32 /nologo -LINK32=link.exe -# ADD BASE LINK32 hs_regex.lib libdb.lib ws2_32.lib /nologo /subsystem:console /machine:I386 -# ADD LINK32 hs_regex.lib libdbs.lib ws2_32.lib /nologo /subsystem:console /machine:I386 - -!ENDIF - -# Begin Target - -# Name "ldif2id2children - Win32 Release" -# Name "ldif2id2children - Win32 Debug" -# Name "ldif2id2children - Win32 Single Debug" -# Name "ldif2id2children - Win32 Single Release" -# Begin Source File - -SOURCE=.\ldif2common.c -# End Source File -# Begin Source File - -SOURCE=.\ldif2common.h -# End Source File -# Begin Source File - -SOURCE=.\ldif2id2children.c -# End Source File -# Begin Source File - -SOURCE=.\mimic.c -# End Source File -# End Target -# End Project diff --git a/servers/slapd/tools/ldif2id2entry-bdb2.c b/servers/slapd/tools/ldif2id2entry-bdb2.c deleted file mode 100644 index b51c2c4ec0..0000000000 --- a/servers/slapd/tools/ldif2id2entry-bdb2.c +++ /dev/null @@ -1,129 +0,0 @@ -#include "portable.h" - -#include - -#include - -#include -#include -#include -#include - -#include "ldif2common.h" -#include "../back-bdb2/back-bdb2.h" - -int -main( int argc, char **argv ) -{ - int i, stop; - char *buf; - char line[BUFSIZ], idbuf[BUFSIZ]; - int lmax, lcur; - ID id; - ID maxid; - struct dbcache *db; - Backend *be = NULL; - struct ldbminfo *li; - struct berval bv; - struct berval *vals[2]; - FILE *fp; - - slap_ldif_init( argc, argv, LDIF2ID2ENTRY, "bdb2", SLAP_TOOLID_MODE ); - - slap_startup(dbnum); - - be = &backends[dbnum]; - - /* disable write sync'ing */ - li = (struct ldbminfo *) be->be_private; - li->li_dbcachewsync = 0; - - if ( (db = bdb2i_cache_open( be, "id2entry", BDB2_SUFFIX, LDBM_NEWDB )) - == NULL ) { - perror( "id2entry file" ); - exit( EXIT_FAILURE ); - } - - id = 0; - maxid = 0; - stop = 0; - buf = NULL; - lcur = lmax = 0; - vals[0] = &bv; - vals[1] = NULL; - while ( ! stop ) { - Datum key, data; - - ldbm_datum_init( key ); - ldbm_datum_init( data ); - - if ( fgets( line, sizeof(line), stdin ) != NULL ) { - int len, idlen; - - len = strlen( line ); - if ( buf == NULL || *buf == '\0' ) { - if (!isdigit((unsigned char) line[0])) { - sprintf( idbuf, "%ld\n", id + 1 ); - idlen = strlen( idbuf ); - } else { - id = atol(line) - 1; - idlen = 0; - } - } else { - idlen = 0; - } - - while ( lcur + len + idlen + 1 > lmax ) { - lmax += BUFSIZ; - buf = (char *) ch_realloc( buf, lmax ); - } - - if ( idlen > 0 ) { - strcpy( buf + lcur, idbuf ); - lcur += idlen; - } - strcpy( buf + lcur, line ); - lcur += len; - } else { - stop = 1; - } - if ( line[0] == '\n' || stop && buf && *buf ) { - if ( *buf != '\n' ) { - int len; - - id++; - if ( id > maxid ) - maxid = id; - key.dptr = (char *) &id; - key.dsize = sizeof(ID); - data.dptr = buf; - len = strlen(buf); - if (buf[len - 1] == '\n') - buf[--len] = '\0'; - data.dsize = len + 1; - if ( ldbm_store( db->dbc_db, key, data, - LDBM_INSERT ) != 0 ) { - fputs("id2entry ldbm_store failed\n", - stderr); - exit( EXIT_FAILURE ); - } - } - *buf = '\0'; - lcur = 0; - line[0] = '\0'; - } - } - - maxid++; - bdb2i_put_nextid( be, maxid ); - -#ifdef SLAP_CLEANUP - bdb2i_cache_close( be, db ); -#endif - - slap_shutdown(dbnum); - - slap_destroy(); - - exit( EXIT_SUCCESS ); -} diff --git a/servers/slapd/tools/ldif2id2entry.c b/servers/slapd/tools/ldif2id2entry.c deleted file mode 100644 index 9d279bda3f..0000000000 --- a/servers/slapd/tools/ldif2id2entry.c +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Copyright 1998-1999 The OpenLDAP Foundation, All Rights Reserved. - * COPYING RESTRICTIONS APPLY, see COPYRIGHT file - */ -#include "portable.h" - -#include - -#include - -#include -#include -#include -#include - -#include "ldif2common.h" -#include "../back-ldbm/back-ldbm.h" - -int -main( int argc, char **argv ) -{ - char *buf; - int lineno; - int lmax; - ID id; - ID maxid; - DBCache *db; - Backend *be = NULL; - struct ldbminfo *li; - struct berval bv; - struct berval *vals[2]; - - slap_ldif_init( argc, argv, LDIF2ID2ENTRY, "ldbm", SLAP_TOOLID_MODE ); - - slap_startup(dbnum); - - be = &backends[dbnum]; - - /* disable write sync'ing */ - li = (struct ldbminfo *) be->be_private; - li->li_dbcachewsync = 0; - - if ( (db = ldbm_cache_open( be, "id2entry", LDBM_SUFFIX, LDBM_NEWDB )) - == NULL ) { - perror( "id2entry file" ); - exit( EXIT_FAILURE ); - } - - id = 0; - maxid = 0; - buf = NULL; - lmax = 0; - vals[0] = &bv; - vals[1] = NULL; - while ( slap_read_ldif( &lineno, &buf, &lmax, &id, 1 ) ) { - Datum key, data; - - ldbm_datum_init( key ); - ldbm_datum_init( data ); - - if ( id > maxid ) - maxid = id; - key.dptr = (char *) &id; - key.dsize = sizeof(ID); - data.dptr = buf; - data.dsize = strlen( buf ) + 1; - if ( ldbm_store( db->dbc_db, key, data, - LDBM_INSERT ) != 0 ) { - fputs("id2entry ldbm_store failed\n", - stderr); - exit( EXIT_FAILURE ); - } - } - - maxid++; - put_nextid( be, maxid ); - -#ifdef SLAP_CLEANUP - ldbm_cache_close( be, db ); -#endif - - slap_shutdown(dbnum); - - slap_destroy(); - - return( EXIT_SUCCESS ); -} diff --git a/servers/slapd/tools/ldif2id2entry.dsp b/servers/slapd/tools/ldif2id2entry.dsp deleted file mode 100644 index 64457eb0dc..0000000000 --- a/servers/slapd/tools/ldif2id2entry.dsp +++ /dev/null @@ -1,159 +0,0 @@ -# Microsoft Developer Studio Project File - Name="ldif2id2entry" - Package Owner=<4> -# Microsoft Developer Studio Generated Build File, Format Version 5.00 -# ** DO NOT EDIT ** - -# TARGTYPE "Win32 (x86) Console Application" 0x0103 - -CFG=ldif2id2entry - Win32 Single Debug -!MESSAGE This is not a valid makefile. To build this project using NMAKE, -!MESSAGE use the Export Makefile command and run -!MESSAGE -!MESSAGE NMAKE /f "ldif2id2entry.mak". -!MESSAGE -!MESSAGE You can specify a configuration when running NMAKE -!MESSAGE by defining the macro CFG on the command line. For example: -!MESSAGE -!MESSAGE NMAKE /f "ldif2id2entry.mak" CFG="ldif2id2entry - Win32 Single Debug" -!MESSAGE -!MESSAGE Possible choices for configuration are: -!MESSAGE -!MESSAGE "ldif2id2entry - Win32 Release" (based on\ - "Win32 (x86) Console Application") -!MESSAGE "ldif2id2entry - Win32 Debug" (based on\ - "Win32 (x86) Console Application") -!MESSAGE "ldif2id2entry - Win32 Single Debug" (based on\ - "Win32 (x86) Console Application") -!MESSAGE "ldif2id2entry - Win32 Single Release" (based on\ - "Win32 (x86) Console Application") -!MESSAGE - -# Begin Project -# PROP Scc_ProjName "" -# PROP Scc_LocalPath "" -CPP=cl.exe -RSC=rc.exe - -!IF "$(CFG)" == "ldif2id2entry - Win32 Release" - -# PROP BASE Use_MFC 0 -# PROP BASE Use_Debug_Libraries 0 -# PROP BASE Output_Dir "Release" -# PROP BASE Intermediate_Dir "Release" -# PROP BASE Target_Dir "" -# PROP Use_MFC 0 -# PROP Use_Debug_Libraries 0 -# PROP Output_Dir "..\Release" -# PROP Intermediate_Dir "..\Release\ldif2id2entry" -# PROP Ignore_Export_Lib 0 -# PROP Target_Dir "" -# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c -# ADD CPP /nologo /MT /W3 /GX /O2 /I "..\..\..\include" /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c -# ADD BASE RSC /l 0x409 /d "NDEBUG" -# ADD RSC /l 0x409 /d "NDEBUG" -BSC32=bscmake.exe -# ADD BASE BSC32 /nologo -# ADD BSC32 /nologo -LINK32=link.exe -# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 -# ADD LINK32 hs_regex.lib libdb.lib ws2_32.lib /nologo /subsystem:console /machine:I386 - -!ELSEIF "$(CFG)" == "ldif2id2entry - Win32 Debug" - -# PROP BASE Use_MFC 0 -# PROP BASE Use_Debug_Libraries 1 -# PROP BASE Output_Dir "ldif2id2" -# PROP BASE Intermediate_Dir "ldif2id2" -# PROP BASE Target_Dir "" -# PROP Use_MFC 0 -# PROP Use_Debug_Libraries 1 -# PROP Output_Dir "..\Debug" -# PROP Intermediate_Dir "..\Debug\ldif2id2entry" -# PROP Ignore_Export_Lib 0 -# PROP Target_Dir "" -# ADD BASE CPP /nologo /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c -# ADD CPP /nologo /MTd /W3 /Gm /GX /Zi /Od /I "..\..\..\include" /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /FR /YX /FD /c -# ADD BASE RSC /l 0x409 /d "_DEBUG" -# ADD RSC /l 0x409 /d "_DEBUG" -BSC32=bscmake.exe -# ADD BASE BSC32 /nologo -# ADD BSC32 /nologo -LINK32=link.exe -# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept -# ADD LINK32 hs_regex.lib libdb.lib ws2_32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept - -!ELSEIF "$(CFG)" == "ldif2id2entry - Win32 Single Debug" - -# PROP BASE Use_MFC 0 -# PROP BASE Use_Debug_Libraries 1 -# PROP BASE Output_Dir "ldif2id2" -# PROP BASE Intermediate_Dir "ldif2id2" -# PROP BASE Ignore_Export_Lib 0 -# PROP BASE Target_Dir "" -# PROP Use_MFC 0 -# PROP Use_Debug_Libraries 1 -# PROP Output_Dir "..\SDebug" -# PROP Intermediate_Dir "..\SDebug\ldif2id2entry" -# PROP Ignore_Export_Lib 0 -# PROP Target_Dir "" -# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /Zi /Od /I "..\..\..\include" /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c -# ADD CPP /nologo /W3 /Gm /GX /Zi /Od /I "..\..\..\include" /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /FR /YX /FD /c -# ADD BASE RSC /l 0x409 /d "_DEBUG" -# ADD RSC /l 0x409 /d "_DEBUG" -BSC32=bscmake.exe -# ADD BASE BSC32 /nologo -# ADD BSC32 /nologo -LINK32=link.exe -# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib hs_regexd.lib libdbs.lib ws2_32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept -# ADD LINK32 hs_regexd.lib libdbs.lib ws2_32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept - -!ELSEIF "$(CFG)" == "ldif2id2entry - Win32 Single Release" - -# PROP BASE Use_MFC 0 -# PROP BASE Use_Debug_Libraries 0 -# PROP BASE Output_Dir "ldif2id0" -# PROP BASE Intermediate_Dir "ldif2id0" -# PROP BASE Ignore_Export_Lib 0 -# PROP BASE Target_Dir "" -# PROP Use_MFC 0 -# PROP Use_Debug_Libraries 0 -# PROP Output_Dir "..\SRelease" -# PROP Intermediate_Dir "..\SRelease\ldif2id2entry" -# PROP Ignore_Export_Lib 0 -# PROP Target_Dir "" -# ADD BASE CPP /nologo /MT /W3 /GX /O2 /I "..\..\..\include" /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c -# ADD CPP /nologo /W3 /GX /O2 /I "..\..\..\include" /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c -# ADD BASE RSC /l 0x409 /d "NDEBUG" -# ADD RSC /l 0x409 /d "NDEBUG" -BSC32=bscmake.exe -# ADD BASE BSC32 /nologo -# ADD BSC32 /nologo -LINK32=link.exe -# ADD BASE LINK32 hs_regex.lib libdb.lib ws2_32.lib /nologo /subsystem:console /machine:I386 -# ADD LINK32 hs_regex.lib libdbs.lib ws2_32.lib /nologo /subsystem:console /machine:I386 - -!ENDIF - -# Begin Target - -# Name "ldif2id2entry - Win32 Release" -# Name "ldif2id2entry - Win32 Debug" -# Name "ldif2id2entry - Win32 Single Debug" -# Name "ldif2id2entry - Win32 Single Release" -# Begin Source File - -SOURCE=.\ldif2common.c -# End Source File -# Begin Source File - -SOURCE=.\ldif2common.h -# End Source File -# Begin Source File - -SOURCE=.\ldif2id2entry.c -# End Source File -# Begin Source File - -SOURCE=.\mimic.c -# End Source File -# End Target -# End Project diff --git a/servers/slapd/tools/ldif2index-bdb2.c b/servers/slapd/tools/ldif2index-bdb2.c deleted file mode 100644 index 4a4374f65f..0000000000 --- a/servers/slapd/tools/ldif2index-bdb2.c +++ /dev/null @@ -1,107 +0,0 @@ -#include "portable.h" - -#include - -#include - -#include -#include -#include -#include - -#include "ldif2common.h" -#include "../back-bdb2/back-bdb2.h" -#include "ldif.h" - -int -main( int argc, char **argv ) -{ - int i, stop; - char *linep, *buf, *attr; - char line[BUFSIZ]; - int lineno, elineno; - int lmax, lcur, indexmask, syntaxmask; - unsigned long id; - Backend *be = NULL; - struct ldbminfo *li; - struct berval bv; - struct berval *vals[2]; - - slap_ldif_init( argc, argv, LDIF2INDEX, "bdb2", SLAP_TOOL_MODE ); - attr = attr_normalize( argv[argc - 1] ); - - slap_startup(dbnum); - - be = &backends[dbnum]; - - /* disable write sync'ing */ - li = (struct ldbminfo *) be->be_private; - li->li_dbcachewsync = 0; - - bdb2i_attr_masks( be->be_private, attr, &indexmask, &syntaxmask ); - if ( indexmask == 0 ) { - exit( EXIT_SUCCESS ); - } - - id = 0; - stop = 0; - lineno = 0; - buf = NULL; - lcur = lmax = 0; - vals[0] = &bv; - vals[1] = NULL; - while ( ! stop ) { - char *type, *val, *s; - ber_len_t vlen; - - if ( fgets( line, sizeof(line), stdin ) != NULL ) { - int len; - - lineno++; - len = strlen( line ); - while ( lcur + len + 1 > lmax ) { - lmax += BUFSIZ; - buf = (char *) ch_realloc( buf, lmax ); - } - strcpy( buf + lcur, line ); - lcur += len; - } else { - stop = 1; - } - if ( line[0] == '\n' || stop && buf && *buf ) { - if ( *buf != '\n' ) { - if (isdigit((unsigned char) *buf)) { - id = atol(buf); - } else { - id++; - } - s = buf; - elineno = 0; - while ( (linep = ldif_getline( &s )) != NULL ) { - elineno++; - if ( ldif_parse_line( linep, &type, &val, - &vlen ) != 0 ) { - Debug( LDAP_DEBUG_PARSE, - "bad line %d in entry ending at line %d ignored\n", - elineno, lineno, 0 ); - continue; - } - - if ( strcasecmp( type, attr ) == 0 ) { - bv.bv_val = val; - bv.bv_len = vlen; - bdb2i_index_add_values( be, attr, - vals, id ); - } - } - } - *buf = '\0'; - lcur = 0; - } - } - - slap_shutdown(dbnum); - slap_destroy(); - - exit( EXIT_SUCCESS ); -} diff --git a/servers/slapd/tools/ldif2index.c b/servers/slapd/tools/ldif2index.c deleted file mode 100644 index d6a38ed582..0000000000 --- a/servers/slapd/tools/ldif2index.c +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Copyright 1998-1999 The OpenLDAP Foundation, All Rights Reserved. - * COPYING RESTRICTIONS APPLY, see COPYRIGHT file - */ -#include "portable.h" - -#include - -#include - -#include -#include -#include -#include - -#include "ldif2common.h" -#include "../back-ldbm/back-ldbm.h" -#include "ldif.h" - -int -main( int argc, char **argv ) -{ - char *linep, *buf, *attr; - int lineno, elineno; - int lmax; - int indexmask, syntaxmask; - ID id; - Backend *be = NULL; - struct ldbminfo *li; - struct berval bv; - struct berval *vals[2]; - - slap_ldif_init( argc, argv, LDIF2INDEX, "ldbm", SLAP_TOOL_MODE ); - attr = attr_normalize( argv[argc - 1] ); - - slap_startup(dbnum); - - be = &backends[dbnum]; - - /* disable write sync'ing */ - li = (struct ldbminfo *) be->be_private; - li->li_dbcachewsync = 0; - - attr_masks( be->be_private, attr, &indexmask, &syntaxmask ); - if ( indexmask == 0 ) { - exit( EXIT_SUCCESS ); - } - - id = 0; - lineno = 0; - buf = NULL; - lmax = 0; - vals[0] = &bv; - vals[1] = NULL; - while ( slap_read_ldif( &lineno, &buf, &lmax, &id, 0 ) ) { - char *type, *val, *s; - ber_len_t vlen; - - s = buf; - elineno = 0; - while ( (linep = ldif_getline( &s )) != NULL ) { - elineno++; - if ( ldif_parse_line( linep, &type, &val, - &vlen ) != 0 ) { - Debug( LDAP_DEBUG_PARSE, - "bad line %d in entry ending at line %d ignored\n", - elineno, lineno, 0 ); - continue; - } - - if ( strcasecmp( type, attr ) == 0 ) { - bv.bv_val = val; - bv.bv_len = vlen; - index_change_values( be, - attr, - vals, - id, - __INDEX_ADD_OP); - } - } - } - - slap_shutdown(dbnum); - slap_destroy(); - - return( EXIT_SUCCESS ); -} diff --git a/servers/slapd/tools/ldif2index.dsp b/servers/slapd/tools/ldif2index.dsp deleted file mode 100644 index 65b8cdd76b..0000000000 --- a/servers/slapd/tools/ldif2index.dsp +++ /dev/null @@ -1,159 +0,0 @@ -# Microsoft Developer Studio Project File - Name="ldif2index" - Package Owner=<4> -# Microsoft Developer Studio Generated Build File, Format Version 5.00 -# ** DO NOT EDIT ** - -# TARGTYPE "Win32 (x86) Console Application" 0x0103 - -CFG=ldif2index - Win32 Single Debug -!MESSAGE This is not a valid makefile. To build this project using NMAKE, -!MESSAGE use the Export Makefile command and run -!MESSAGE -!MESSAGE NMAKE /f "ldif2index.mak". -!MESSAGE -!MESSAGE You can specify a configuration when running NMAKE -!MESSAGE by defining the macro CFG on the command line. For example: -!MESSAGE -!MESSAGE NMAKE /f "ldif2index.mak" CFG="ldif2index - Win32 Single Debug" -!MESSAGE -!MESSAGE Possible choices for configuration are: -!MESSAGE -!MESSAGE "ldif2index - Win32 Release" (based on\ - "Win32 (x86) Console Application") -!MESSAGE "ldif2index - Win32 Debug" (based on\ - "Win32 (x86) Console Application") -!MESSAGE "ldif2index - Win32 Single Debug" (based on\ - "Win32 (x86) Console Application") -!MESSAGE "ldif2index - Win32 Single Release" (based on\ - "Win32 (x86) Console Application") -!MESSAGE - -# Begin Project -# PROP Scc_ProjName "" -# PROP Scc_LocalPath "" -CPP=cl.exe -RSC=rc.exe - -!IF "$(CFG)" == "ldif2index - Win32 Release" - -# PROP BASE Use_MFC 0 -# PROP BASE Use_Debug_Libraries 0 -# PROP BASE Output_Dir "Release" -# PROP BASE Intermediate_Dir "Release" -# PROP BASE Target_Dir "" -# PROP Use_MFC 0 -# PROP Use_Debug_Libraries 0 -# PROP Output_Dir "..\Release" -# PROP Intermediate_Dir "..\Release\ldif2index" -# PROP Ignore_Export_Lib 0 -# PROP Target_Dir "" -# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c -# ADD CPP /nologo /MT /W3 /GX /O2 /I "..\..\..\include" /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c -# ADD BASE RSC /l 0x409 /d "NDEBUG" -# ADD RSC /l 0x409 /d "NDEBUG" -BSC32=bscmake.exe -# ADD BASE BSC32 /nologo -# ADD BSC32 /nologo -LINK32=link.exe -# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 -# ADD LINK32 hs_regex.lib libdb.lib ws2_32.lib /nologo /subsystem:console /machine:I386 - -!ELSEIF "$(CFG)" == "ldif2index - Win32 Debug" - -# PROP BASE Use_MFC 0 -# PROP BASE Use_Debug_Libraries 1 -# PROP BASE Output_Dir "ldif2ind" -# PROP BASE Intermediate_Dir "ldif2ind" -# PROP BASE Target_Dir "" -# PROP Use_MFC 0 -# PROP Use_Debug_Libraries 1 -# PROP Output_Dir "..\Debug" -# PROP Intermediate_Dir "..\Debug\ldif2index" -# PROP Ignore_Export_Lib 0 -# PROP Target_Dir "" -# ADD BASE CPP /nologo /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c -# ADD CPP /nologo /MTd /W3 /Gm /GX /Zi /Od /I "..\..\..\include" /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /FR /YX /FD /c -# ADD BASE RSC /l 0x409 /d "_DEBUG" -# ADD RSC /l 0x409 /d "_DEBUG" -BSC32=bscmake.exe -# ADD BASE BSC32 /nologo -# ADD BSC32 /nologo -LINK32=link.exe -# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept -# ADD LINK32 hs_regex.lib libdb.lib ws2_32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept - -!ELSEIF "$(CFG)" == "ldif2index - Win32 Single Debug" - -# PROP BASE Use_MFC 0 -# PROP BASE Use_Debug_Libraries 1 -# PROP BASE Output_Dir "ldif2ind" -# PROP BASE Intermediate_Dir "ldif2ind" -# PROP BASE Ignore_Export_Lib 0 -# PROP BASE Target_Dir "" -# PROP Use_MFC 0 -# PROP Use_Debug_Libraries 1 -# PROP Output_Dir "..\SDebug" -# PROP Intermediate_Dir "..\SDebug\ldif2index" -# PROP Ignore_Export_Lib 0 -# PROP Target_Dir "" -# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /Zi /Od /I "..\..\..\include" /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c -# ADD CPP /nologo /W3 /Gm /GX /Zi /Od /I "..\..\..\include" /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /FR /YX /FD /c -# ADD BASE RSC /l 0x409 /d "_DEBUG" -# ADD RSC /l 0x409 /d "_DEBUG" -BSC32=bscmake.exe -# ADD BASE BSC32 /nologo -# ADD BSC32 /nologo -LINK32=link.exe -# ADD BASE LINK32 kernel32.lib shell32.lib hs_regexd.lib libdbs.lib ws2_32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept -# ADD LINK32 hs_regex.lib libdbs.lib ws2_32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept - -!ELSEIF "$(CFG)" == "ldif2index - Win32 Single Release" - -# PROP BASE Use_MFC 0 -# PROP BASE Use_Debug_Libraries 0 -# PROP BASE Output_Dir "ldif2in0" -# PROP BASE Intermediate_Dir "ldif2in0" -# PROP BASE Ignore_Export_Lib 0 -# PROP BASE Target_Dir "" -# PROP Use_MFC 0 -# PROP Use_Debug_Libraries 0 -# PROP Output_Dir "..\SRelease" -# PROP Intermediate_Dir "..\SRelease\ldif2index" -# PROP Ignore_Export_Lib 0 -# PROP Target_Dir "" -# ADD BASE CPP /nologo /MT /W3 /GX /O2 /I "..\..\..\include" /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c -# ADD CPP /nologo /W3 /GX /O2 /I "..\..\..\include" /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c -# ADD BASE RSC /l 0x409 /d "NDEBUG" -# ADD RSC /l 0x409 /d "NDEBUG" -BSC32=bscmake.exe -# ADD BASE BSC32 /nologo -# ADD BSC32 /nologo -LINK32=link.exe -# ADD BASE LINK32 hs_regex.lib libdb.lib ws2_32.lib /nologo /subsystem:console /machine:I386 -# ADD LINK32 hs_regex.lib libdbs.lib ws2_32.lib /nologo /subsystem:console /machine:I386 - -!ENDIF - -# Begin Target - -# Name "ldif2index - Win32 Release" -# Name "ldif2index - Win32 Debug" -# Name "ldif2index - Win32 Single Debug" -# Name "ldif2index - Win32 Single Release" -# Begin Source File - -SOURCE=.\ldif2common.c -# End Source File -# Begin Source File - -SOURCE=.\ldif2common.h -# End Source File -# Begin Source File - -SOURCE=.\ldif2index.c -# End Source File -# Begin Source File - -SOURCE=.\mimic.c -# End Source File -# End Target -# End Project diff --git a/servers/slapd/tools/ldif2ldbm-bdb2.c b/servers/slapd/tools/ldif2ldbm-bdb2.c deleted file mode 100644 index 46fabe677a..0000000000 --- a/servers/slapd/tools/ldif2ldbm-bdb2.c +++ /dev/null @@ -1,250 +0,0 @@ -#include "portable.h" - -#include - -#include -#include -#include -#include -#include -#include - -#ifdef HAVE_SYS_PARAM_H -#include -#endif - -#include "ldif2common.h" -#include "../back-bdb2/back-bdb2.h" -#include "ldif.h" - -#define INDEXCMD "ldif2index-bdb2" -#define ID2ENTRYCMD "ldif2id2entry-bdb2" -#define ID2CHILDRENCMD "ldif2id2children-bdb2" -#define MAXARGS 100 - -static void fork_child( char *prog, char *args[] ); -static void wait4kids( int nkidval ); - -static int maxkids = 1; -static int nkids; - -int -main( int argc, char **argv ) -{ - int i, stop; - char *linep, *buf; - char *args[MAXARGS]; - char buf2[20], buf3[20]; - char line[BUFSIZ]; - char cmd[MAXPATHLEN]; - int lineno, elineno; - int lmax, lcur; - ID id; - Backend *be = NULL; - struct ldbminfo *li; - struct berval bv; - struct berval *vals[2]; - Avlnode *avltypes = NULL; - - slap_ldif_init( argc, argv, LDIF2LDBM, "bdb2", SLAP_TOOL_MODE ); - - slap_startup(dbnum); - - be = &backends[dbnum]; - - /* disable write sync'ing */ - li = (struct ldbminfo *) be->be_private; - li->li_dbcachewsync = 0; - - /* - * generate the id2entry index - */ - - i = 0; - sprintf( cmd, "%s/%s", sbindir, ID2ENTRYCMD ); - args[i++] = cmd; - args[i++] = "-i"; - args[i++] = inputfile; - args[i++] = "-f"; - args[i++] = tailorfile; - args[i++] = "-n"; - sprintf( buf2, "%d", dbnum+1 ); - args[i++] = buf2; - if ( ldap_debug ) { - sprintf( buf3, "%d", ldap_debug ); - args[i++] = "-d"; - args[i++] = buf3; - } - args[i++] = NULL; - fork_child( cmd, args ); - - /* - * generate the dn2id and id2children indexes - */ - - i = 0; - sprintf( cmd, "%s/%s", sbindir, ID2CHILDRENCMD ); - args[i++] = cmd; - args[i++] = "-i"; - args[i++] = inputfile; - args[i++] = "-f"; - args[i++] = tailorfile; - args[i++] = "-n"; - sprintf( buf2, "%d", dbnum+1 ); - args[i++] = buf2; - if ( ldap_debug ) { - sprintf( buf3, "%d", ldap_debug ); - args[i++] = "-d"; - args[i++] = buf3; - } - args[i++] = NULL; - fork_child( cmd, args ); - - maxkids = cmdkids; - - /* - * generate the attribute indexes - */ - - i = 0; - sprintf( cmd, "%s/%s", sbindir, INDEXCMD ); - args[i++] = cmd; - args[i++] = "-i"; - args[i++] = inputfile; - args[i++] = "-f"; - args[i++] = tailorfile; - args[i++] = "-n"; - sprintf( buf2, "%d", dbnum+1 ); - args[i++] = buf2; - if ( ldap_debug ) { - sprintf( buf3, "%d", ldap_debug ); - args[i++] = "-d"; - args[i++] = buf3; - } - args[i++] = NULL; /* will hold the attribute name */ - args[i++] = NULL; - - id = 0; - stop = 0; - buf = NULL; - lineno = 0; - lcur = lmax = 0; - vals[0] = &bv; - vals[1] = NULL; - while ( ! stop ) { - char *type, *val, *s; - ber_len_t vlen; - int indexmask, syntaxmask; - - if ( fgets( line, sizeof(line), stdin ) != NULL ) { - int len; - - lineno++; - len = strlen( line ); - while ( lcur + len + 1 > lmax ) { - lmax += BUFSIZ; - buf = (char *) ch_realloc( buf, lmax ); - } - strcpy( buf + lcur, line ); - lcur += len; - } else { - stop = 1; - } - if ( line[0] == '\n' || stop && buf && *buf ) { - id++; - s = buf; - elineno = 0; - while ( (linep = ldif_getline( &s )) != NULL ) { - elineno++; - if ( ldif_parse_line( linep, &type, &val, &vlen ) - != 0 ) { - Debug( LDAP_DEBUG_PARSE, - "bad line %d in entry ending at line %d ignored\n", - elineno, lineno, 0 ); - continue; - } - - if ( !isascii( *type ) || isdigit( *type ) ) - continue; - - type = strdup( type ); - if ( avl_insert( &avltypes, type, (AVL_CMP) strcasecmp, - avl_dup_error ) != 0 ) { - free( type ); - } else { - bdb2i_attr_masks( be->be_private, type, - &indexmask, &syntaxmask ); - if ( indexmask ) { - args[i - 2] = type; - fork_child( cmd, args ); - } - } - } - *buf = '\0'; - lcur = 0; - } - } - - slap_shutdown(dbnum); - - wait4kids( -1 ); - - slap_destroy(); - - exit( EXIT_SUCCESS ); -} - -static void -fork_child( char *prog, char *args[] ) -{ - int pid; - - wait4kids( maxkids ); - - switch ( pid = fork() ) { - case 0: /* child */ - execvp( prog, args ); - fprintf( stderr, "%s: ", prog ); - perror( "execv" ); - exit( EXIT_FAILURE ); - break; - - case -1: /* trouble */ - fprintf( stderr, "Could not fork to run %s\n", prog ); - perror( "fork" ); - break; - - default: /* parent */ - nkids++; - break; - } -} - -static void -wait4kids( int nkidval ) -{ - int status; - unsigned char *p; - - while ( nkids >= nkidval ) { - wait( &status ); - p = (unsigned char *) &status; - if ( p[sizeof(int) - 1] == 0177 ) { - fprintf( stderr, - "stopping: child stopped with signal %d\n", - p[sizeof(int) - 2] ); - } else if ( p[sizeof(int) - 1] != 0 ) { - fprintf( stderr, - "stopping: child terminated with signal %d\n", - p[sizeof(int) - 1] ); - exit( p[sizeof(int) - 1] ); - } else if ( p[sizeof(int) - 2] != 0 ) { - fprintf( stderr, - "stopping: child exited with status %d\n", - p[sizeof(int) - 2] ); - exit( p[sizeof(int) - 2] ); - } else { - nkids--; - } - } -} diff --git a/servers/slapd/tools/ldif2ldbm.c b/servers/slapd/tools/ldif2ldbm.c deleted file mode 100644 index cc8984021f..0000000000 --- a/servers/slapd/tools/ldif2ldbm.c +++ /dev/null @@ -1,298 +0,0 @@ -/* - * Copyright 1998-1999 The OpenLDAP Foundation, All Rights Reserved. - * COPYING RESTRICTIONS APPLY, see COPYRIGHT file - */ -#include "portable.h" - -#include - -#include -#include -#include -#include -#include -#include - -#ifdef HAVE_SYS_PARAM_H -#include -#endif - -#include "ldif2common.h" -#include "../back-ldbm/back-ldbm.h" -#include "ldif.h" - -#define INDEXCMD "ldif2index" EXEEXT -#define ID2ENTRYCMD "ldif2id2entry" EXEEXT -#define ID2CHILDRENCMD "ldif2id2children" EXEEXT - -#define MAXARGS 100 - -static void fork_child( char *prog, char *args[] ); -static void wait4kids( int nkidval ); - -static int maxkids = 1; -static int nkids; - -int -main( int argc, char **argv ) -{ - int i; - char *linep, *buf; - char *args[MAXARGS]; - char buf2[20], buf3[20]; - char cmd[MAXPATHLEN]; - int lineno, elineno; - int lmax; - ID id; - Backend *be = NULL; - struct ldbminfo *li; - struct berval bv; - struct berval *vals[2]; - Avlnode *avltypes = NULL; - - slap_ldif_init( argc, argv, LDIF2LDBM, "ldbm", SLAP_TOOL_MODE ); - - slap_startup(dbnum); - - be = &backends[dbnum]; - - /* disable write sync'ing */ - li = (struct ldbminfo *) be->be_private; - li->li_dbcachewsync = 0; - - /* - * generate the id2entry index - */ - - i = 0; - sprintf( cmd, "%s/%s", sbindir, ID2ENTRYCMD ); - args[i++] = cmd; - args[i++] = "-i"; - args[i++] = inputfile; - args[i++] = "-f"; - args[i++] = tailorfile; - args[i++] = "-n"; - sprintf( buf2, "%d", dbnum+1 ); - args[i++] = buf2; - if ( ldap_debug ) { - sprintf( buf3, "%d", ldap_debug ); - args[i++] = "-d"; - args[i++] = buf3; - } - args[i++] = NULL; - fork_child( cmd, args ); - - /* - * generate the dn2id and id2children indexes - */ - - i = 0; - sprintf( cmd, "%s/%s", sbindir, ID2CHILDRENCMD ); - args[i++] = cmd; - args[i++] = "-i"; - args[i++] = inputfile; - args[i++] = "-f"; - args[i++] = tailorfile; - args[i++] = "-n"; - sprintf( buf2, "%d", dbnum+1 ); - args[i++] = buf2; - if ( ldap_debug ) { - sprintf( buf3, "%d", ldap_debug ); - args[i++] = "-d"; - args[i++] = buf3; - } - args[i++] = NULL; - fork_child( cmd, args ); - - maxkids = cmdkids; - - /* - * generate the attribute indexes - */ - - i = 0; - sprintf( cmd, "%s/%s", sbindir, INDEXCMD ); - args[i++] = cmd; - args[i++] = "-i"; - args[i++] = inputfile; - args[i++] = "-f"; - args[i++] = tailorfile; - args[i++] = "-n"; - sprintf( buf2, "%d", dbnum+1 ); - args[i++] = buf2; - if ( ldap_debug ) { - sprintf( buf3, "%d", ldap_debug ); - args[i++] = "-d"; - args[i++] = buf3; - } - args[i++] = NULL; /* will hold the attribute name */ - args[i++] = NULL; - - id = 0; - buf = NULL; - lineno = 0; - lmax = 0; - vals[0] = &bv; - vals[1] = NULL; - while ( slap_read_ldif( &lineno, &buf, &lmax, &id, 0 ) ) { - char *type, *val, *s; - ber_len_t vlen; - int indexmask, syntaxmask; - - s = buf; - elineno = 0; - while ( (linep = ldif_getline( &s )) != NULL ) { - elineno++; - if ( ldif_parse_line( linep, &type, &val, &vlen ) - != 0 ) { - Debug( LDAP_DEBUG_PARSE, - "bad line %d in entry ending at line %d ignored\n", - elineno, lineno, 0 ); - continue; - } - - if ( !isascii( *type ) || isdigit( *type ) ) - continue; - - type = strdup( type ); - if ( avl_insert( &avltypes, type, (AVL_CMP) strcasecmp, - avl_dup_error ) != 0 ) { - free( type ); - } else { - attr_masks( be->be_private, type, - &indexmask, &syntaxmask ); - if ( indexmask ) { - args[i - 2] = type; - fork_child( cmd, args ); - } - } - } - } - - wait4kids( -1 ); - - slap_shutdown(dbnum); - - slap_destroy(); - - return( EXIT_SUCCESS ); -} - -#ifdef WIN32 - -static HANDLE processes[MAXIMUM_WAIT_OBJECTS]; - -static void -fork_child( char *prog, char *args[] ) -{ - PROCESS_INFORMATION proc_info; - PROCESS_INFORMATION *pinfo = &proc_info; - STARTUPINFO start_info; - int i; - char cmdLine[2048]; - - wait4kids( maxkids ); - - i = 1; - memset( &start_info, 0, sizeof(STARTUPINFO) ); - memset( cmdLine, 0, sizeof(cmdLine) ); - strcpy( cmdLine, prog ); - while ( args[i] != NULL ) - { - strcat( cmdLine, " " ); - strcat( cmdLine, args[i] ); - i++; - } - - if ( !CreateProcess( NULL, cmdLine, NULL, NULL, - TRUE, CREATE_NEW_CONSOLE, - NULL, NULL, &start_info, pinfo ) ) - { - fprintf( stderr, "Could not create %s: ", prog ); - perror( "CreateProcess" ); - exit (EXIT_FAILURE); - } - - processes[nkids] = proc_info.hProcess; - nkids++; - -} - -static void -wait4kids( int nkidval ) -{ - DWORD wait_index; - while( nkids >= nkidval ) - { - wait_index = WaitForMultipleObjects( nkids, processes, FALSE, INFINITE ); - /* - * processes[wait_index] completed. Move any remaining indexes into its - * place in the array so it stays filled. - */ - if ( nkids > 1 ) - { - memcpy ( &processes[wait_index], &processes[wait_index+1], sizeof(HANDLE)*(nkids-1) ); - processes[nkids] = 0; - } - nkids--; - } -} - -#else - -static void -fork_child( char *prog, char *args[] ) -{ - int pid; - - wait4kids( maxkids ); - - switch ( pid = fork() ) { - case 0: /* child */ - execvp( prog, args ); - fprintf( stderr, "%s: ", prog ); - perror( "execv" ); - exit( EXIT_FAILURE ); - break; - - case -1: /* trouble */ - fprintf( stderr, "Could not fork to run %s\n", prog ); - perror( "fork" ); - break; - - default: /* parent */ - nkids++; - break; - } -} - -static void -wait4kids( int nkidval ) -{ - int status; - unsigned char *p; - - while ( nkids >= nkidval ) { - wait( &status ); - p = (unsigned char *) &status; - if ( p[sizeof(int) - 1] == 0177 ) { - fprintf( stderr, - "stopping: child stopped with signal %d\n", - p[sizeof(int) - 2] ); - } else if ( p[sizeof(int) - 1] != 0 ) { - fprintf( stderr, - "stopping: child terminated with signal %d\n", - p[sizeof(int) - 1] ); - exit( p[sizeof(int) - 1] ); - } else if ( p[sizeof(int) - 2] != 0 ) { - fprintf( stderr, - "stopping: child exited with status %d\n", - p[sizeof(int) - 2] ); - exit( p[sizeof(int) - 2] ); - } else { - nkids--; - } - } -} - -#endif diff --git a/servers/slapd/tools/ldif2ldbm.dsp b/servers/slapd/tools/ldif2ldbm.dsp deleted file mode 100644 index 964d2a4fbf..0000000000 --- a/servers/slapd/tools/ldif2ldbm.dsp +++ /dev/null @@ -1,158 +0,0 @@ -# Microsoft Developer Studio Project File - Name="ldif2ldbm" - Package Owner=<4> -# Microsoft Developer Studio Generated Build File, Format Version 5.00 -# ** DO NOT EDIT ** - -# TARGTYPE "Win32 (x86) Console Application" 0x0103 - -CFG=ldif2ldbm - Win32 Single Debug -!MESSAGE This is not a valid makefile. To build this project using NMAKE, -!MESSAGE use the Export Makefile command and run -!MESSAGE -!MESSAGE NMAKE /f "ldif2ldbm.mak". -!MESSAGE -!MESSAGE You can specify a configuration when running NMAKE -!MESSAGE by defining the macro CFG on the command line. For example: -!MESSAGE -!MESSAGE NMAKE /f "ldif2ldbm.mak" CFG="ldif2ldbm - Win32 Single Debug" -!MESSAGE -!MESSAGE Possible choices for configuration are: -!MESSAGE -!MESSAGE "ldif2ldbm - Win32 Release" (based on\ - "Win32 (x86) Console Application") -!MESSAGE "ldif2ldbm - Win32 Debug" (based on "Win32 (x86) Console Application") -!MESSAGE "ldif2ldbm - Win32 Single Debug" (based on\ - "Win32 (x86) Console Application") -!MESSAGE "ldif2ldbm - Win32 Single Release" (based on\ - "Win32 (x86) Console Application") -!MESSAGE - -# Begin Project -# PROP Scc_ProjName "" -# PROP Scc_LocalPath "" -CPP=cl.exe -RSC=rc.exe - -!IF "$(CFG)" == "ldif2ldbm - Win32 Release" - -# PROP BASE Use_MFC 0 -# PROP BASE Use_Debug_Libraries 0 -# PROP BASE Output_Dir "Release" -# PROP BASE Intermediate_Dir "Release" -# PROP BASE Target_Dir "" -# PROP Use_MFC 0 -# PROP Use_Debug_Libraries 0 -# PROP Output_Dir "..\Release" -# PROP Intermediate_Dir "..\Release\ldif2ldbm" -# PROP Ignore_Export_Lib 0 -# PROP Target_Dir "" -# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c -# ADD CPP /nologo /MT /W3 /GX /O2 /I "..\..\..\include" /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c -# ADD BASE RSC /l 0x409 /d "NDEBUG" -# ADD RSC /l 0x409 /d "NDEBUG" -BSC32=bscmake.exe -# ADD BASE BSC32 /nologo -# ADD BSC32 /nologo -LINK32=link.exe -# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 -# ADD LINK32 hs_regex.lib libdb.lib ws2_32.lib /nologo /subsystem:console /machine:I386 - -!ELSEIF "$(CFG)" == "ldif2ldbm - Win32 Debug" - -# PROP BASE Use_MFC 0 -# PROP BASE Use_Debug_Libraries 1 -# PROP BASE Output_Dir "Debug" -# PROP BASE Intermediate_Dir "Debug" -# PROP BASE Target_Dir "" -# PROP Use_MFC 0 -# PROP Use_Debug_Libraries 1 -# PROP Output_Dir "..\Debug" -# PROP Intermediate_Dir "..\Debug\ldif2dlbm" -# PROP Ignore_Export_Lib 0 -# PROP Target_Dir "" -# ADD BASE CPP /nologo /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c -# ADD CPP /nologo /MTd /W3 /Gm /GX /Zi /Od /I "..\..\..\include" /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /FR /YX /FD /c -# ADD BASE RSC /l 0x409 /d "_DEBUG" -# ADD RSC /l 0x409 /d "_DEBUG" -BSC32=bscmake.exe -# ADD BASE BSC32 /nologo -# ADD BSC32 /nologo -LINK32=link.exe -# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept -# ADD LINK32 hs_regex.lib libdb.lib ws2_32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept - -!ELSEIF "$(CFG)" == "ldif2ldbm - Win32 Single Debug" - -# PROP BASE Use_MFC 0 -# PROP BASE Use_Debug_Libraries 1 -# PROP BASE Output_Dir "ldif2ldb" -# PROP BASE Intermediate_Dir "ldif2ldb" -# PROP BASE Ignore_Export_Lib 0 -# PROP BASE Target_Dir "" -# PROP Use_MFC 0 -# PROP Use_Debug_Libraries 1 -# PROP Output_Dir "..\SDebug" -# PROP Intermediate_Dir "..\SDebug\ldif2dlbm" -# PROP Ignore_Export_Lib 0 -# PROP Target_Dir "" -# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /Zi /Od /I "..\..\..\include" /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /FR /YX /FD /c -# ADD CPP /nologo /W3 /Gm /GX /Zi /Od /I "..\..\..\include" /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /FR /YX /FD /c -# ADD BASE RSC /l 0x409 /d "_DEBUG" -# ADD RSC /l 0x409 /d "_DEBUG" -BSC32=bscmake.exe -# ADD BASE BSC32 /nologo -# ADD BSC32 /nologo -LINK32=link.exe -# ADD BASE LINK32 kernel32.lib user32.lib shell32.lib hs_regexd.lib libdbs.lib ws2_32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept -# ADD LINK32 hs_regex.lib libdbs.lib ws2_32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept - -!ELSEIF "$(CFG)" == "ldif2ldbm - Win32 Single Release" - -# PROP BASE Use_MFC 0 -# PROP BASE Use_Debug_Libraries 0 -# PROP BASE Output_Dir "ldif2ld0" -# PROP BASE Intermediate_Dir "ldif2ld0" -# PROP BASE Ignore_Export_Lib 0 -# PROP BASE Target_Dir "" -# PROP Use_MFC 0 -# PROP Use_Debug_Libraries 0 -# PROP Output_Dir "..\SRelease" -# PROP Intermediate_Dir "..\SRelease\ldif2dlbm" -# PROP Ignore_Export_Lib 0 -# PROP Target_Dir "" -# ADD BASE CPP /nologo /MT /W3 /GX /O2 /I "..\..\..\include" /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c -# ADD CPP /nologo /W3 /GX /O2 /I "..\..\..\include" /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c -# ADD BASE RSC /l 0x409 /d "NDEBUG" -# ADD RSC /l 0x409 /d "NDEBUG" -BSC32=bscmake.exe -# ADD BASE BSC32 /nologo -# ADD BSC32 /nologo -LINK32=link.exe -# ADD BASE LINK32 hs_regex.lib libdb.lib ws2_32.lib /nologo /subsystem:console /machine:I386 -# ADD LINK32 hs_regex.lib libdbs.lib ws2_32.lib /nologo /subsystem:console /machine:I386 - -!ENDIF - -# Begin Target - -# Name "ldif2ldbm - Win32 Release" -# Name "ldif2ldbm - Win32 Debug" -# Name "ldif2ldbm - Win32 Single Debug" -# Name "ldif2ldbm - Win32 Single Release" -# Begin Source File - -SOURCE=.\ldif2common.c -# End Source File -# Begin Source File - -SOURCE=.\ldif2common.h -# End Source File -# Begin Source File - -SOURCE=..\tools\ldif2ldbm.c -# End Source File -# Begin Source File - -SOURCE=.\mimic.c -# End Source File -# End Target -# End Project diff --git a/servers/slapd/tools/sizecount.c b/servers/slapd/tools/sizecount.c index 74e96fc4a1..52f19d20eb 100644 --- a/servers/slapd/tools/sizecount.c +++ b/servers/slapd/tools/sizecount.c @@ -6,10 +6,8 @@ #include #include -#include -#include #include -#include "portable.h" +#include #define CACHE_SIZE 1000000 #define MODE 0600 @@ -23,6 +21,7 @@ extern char *phonetic(char *); extern int ldap_debug; +int slap_debug; int ldap_syslog; int ldap_syslog_level; diff --git a/servers/slapd/tools/slapadd.c b/servers/slapd/tools/slapadd.c new file mode 100644 index 0000000000..99a793244a --- /dev/null +++ b/servers/slapd/tools/slapadd.c @@ -0,0 +1,83 @@ +/* + * Copyright 1998-1999 The OpenLDAP Foundation, All Rights Reserved. + * COPYING RESTRICTIONS APPLY, see COPYRIGHT file + */ +#include "portable.h" + +#include + +#include + +#include +#include +#include +#include + +#include "slapcommon.h" + +int +main( int argc, char **argv ) +{ + char *buf; + int lineno; + int lmax; + int rc = EXIT_SUCCESS; + + slap_tool_init( "slapadd", SLAPADD, argc, argv ); + slap_startup( be ); + + if( !be->be_entry_open && + !be->be_entry_close && + !be->be_entry_put ) + { + fprintf( stderr, "%s: database doesn't support necessary operations.\n", + progname ); + exit( EXIT_FAILURE ); + } + + buf = NULL; + lmax = 0; + + if( be->be_entry_open( be, 1 ) != 0 ) { + fprintf( stderr, "%s: could not open database.\n", + progname ); + exit( EXIT_FAILURE ); + } + + while( ldif_read_record( ldiffp, &lineno, &buf, &lmax ) ) { + ID id; + Entry *e = str2entry( buf ); + + if( e == NULL ) { + fprintf( stderr, "%s: could not parse entry at line %d\n", + progname, lineno ); + rc = EXIT_FAILURE; + continue; + } + + id = be->be_entry_put( be, e ); + + if( id == NOID ) { + fprintf( stderr, "%s: could not add entry (%s) at line %d\n", + progname, e->e_dn, lineno ); + rc = EXIT_FAILURE; + + } else if ( verbose ) { + fprintf( stderr, "added: \"%s\" (%08ld)\n", + e->e_dn, (long) id ); + } + + entry_free( e ); + } + + be->be_entry_close( be ); + + if( be->be_sync ) { + be->be_sync( be ); + } + + slap_shutdown( be ); + slap_destroy(); + + return rc; +} diff --git a/servers/slapd/tools/slapadd.dsp b/servers/slapd/tools/slapadd.dsp new file mode 100644 index 0000000000..d269441ae8 --- /dev/null +++ b/servers/slapd/tools/slapadd.dsp @@ -0,0 +1,157 @@ +# Microsoft Developer Studio Project File - Name="slapadd" - Package Owner=<4> +# Microsoft Developer Studio Generated Build File, Format Version 5.00 +# ** DO NOT EDIT ** + +# TARGTYPE "Win32 (x86) Console Application" 0x0103 + +CFG=slapadd - Win32 Single Debug +!MESSAGE This is not a valid makefile. To build this project using NMAKE, +!MESSAGE use the Export Makefile command and run +!MESSAGE +!MESSAGE NMAKE /f "slapadd.mak". +!MESSAGE +!MESSAGE You can specify a configuration when running NMAKE +!MESSAGE by defining the macro CFG on the command line. For example: +!MESSAGE +!MESSAGE NMAKE /f "slapadd.mak" CFG="slapadd - Win32 Single Debug" +!MESSAGE +!MESSAGE Possible choices for configuration are: +!MESSAGE +!MESSAGE "slapadd - Win32 Release" (based on "Win32 (x86) Console Application") +!MESSAGE "slapadd - Win32 Debug" (based on "Win32 (x86) Console Application") +!MESSAGE "slapadd - Win32 Single Debug" (based on\ + "Win32 (x86) Console Application") +!MESSAGE "slapadd - Win32 Single Release" (based on\ + "Win32 (x86) Console Application") +!MESSAGE + +# Begin Project +# PROP Scc_ProjName "" +# PROP Scc_LocalPath "" +CPP=cl.exe +RSC=rc.exe + +!IF "$(CFG)" == "slapadd - Win32 Release" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 0 +# PROP BASE Output_Dir "Release" +# PROP BASE Intermediate_Dir "Release" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 0 +# PROP Output_Dir "..\Release" +# PROP Intermediate_Dir "..\Release\slapadd" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c +# ADD CPP /nologo /MT /W3 /GX /O2 /I "..\..\..\include" /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c +# ADD BASE RSC /l 0x409 /d "NDEBUG" +# ADD RSC /l 0x409 /d "NDEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 +# ADD LINK32 hs_regex.lib libdb.lib ws2_32.lib /nologo /subsystem:console /machine:I386 + +!ELSEIF "$(CFG)" == "slapadd - Win32 Debug" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 1 +# PROP BASE Output_Dir "ldif2" +# PROP BASE Intermediate_Dir "ldif2" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 1 +# PROP Output_Dir "..\Debug" +# PROP Intermediate_Dir "..\Debug\slapadd" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c +# ADD CPP /nologo /MTd /W3 /Gm /GX /Zi /Od /I "..\..\..\include" /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /FR /YX /FD /c +# ADD BASE RSC /l 0x409 /d "_DEBUG" +# ADD RSC /l 0x409 /d "_DEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept +# ADD LINK32 hs_regex.lib libdb.lib ws2_32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept + +!ELSEIF "$(CFG)" == "slapadd - Win32 Single Debug" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 1 +# PROP BASE Output_Dir "ldif2" +# PROP BASE Intermediate_Dir "ldif2" +# PROP BASE Ignore_Export_Lib 0 +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 1 +# PROP Output_Dir "..\SDebug" +# PROP Intermediate_Dir "..\SDebug\slapadd" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /Zi /Od /I "..\..\..\include" /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c +# ADD CPP /nologo /W3 /Gm /GX /Zi /Od /I "..\..\..\include" /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /FR /YX /FD /c +# ADD BASE RSC /l 0x409 /d "_DEBUG" +# ADD RSC /l 0x409 /d "_DEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib hs_regexd.lib libdbs.lib ws2_32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept +# ADD LINK32 hs_regexd.lib libdbs.lib ws2_32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept + +!ELSEIF "$(CFG)" == "slapadd - Win32 Single Release" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 0 +# PROP BASE Output_Dir "ldif2id0" +# PROP BASE Intermediate_Dir "ldif2id0" +# PROP BASE Ignore_Export_Lib 0 +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 0 +# PROP Output_Dir "..\SRelease" +# PROP Intermediate_Dir "..\SRelease\slapadd" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /MT /W3 /GX /O2 /I "..\..\..\include" /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c +# ADD CPP /nologo /W3 /GX /O2 /I "..\..\..\include" /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c +# ADD BASE RSC /l 0x409 /d "NDEBUG" +# ADD RSC /l 0x409 /d "NDEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 hs_regex.lib libdb.lib ws2_32.lib /nologo /subsystem:console /machine:I386 +# ADD LINK32 hs_regex.lib libdbs.lib ws2_32.lib /nologo /subsystem:console /machine:I386 + +!ENDIF + +# Begin Target + +# Name "slapadd - Win32 Release" +# Name "slapadd - Win32 Debug" +# Name "slapadd - Win32 Single Debug" +# Name "slapadd - Win32 Single Release" +# Begin Source File + +SOURCE=.\mimic.c +# End Source File +# Begin Source File + +SOURCE=.\slapadd.c +# End Source File +# Begin Source File + +SOURCE=.\slapcommon.c +# End Source File +# Begin Source File + +SOURCE=.\slapcommon.h +# End Source File +# End Target +# End Project diff --git a/servers/slapd/tools/slapcat.c b/servers/slapd/tools/slapcat.c new file mode 100644 index 0000000000..f5d035e4ab --- /dev/null +++ b/servers/slapd/tools/slapcat.c @@ -0,0 +1,73 @@ +/* + * Copyright 1998-1999 The OpenLDAP Foundation, All Rights Reserved. + * COPYING RESTRICTIONS APPLY, see COPYRIGHT file + */ +#include "portable.h" + +#include + +#include +#include +#include +#include + +#include "slapcommon.h" + +int +main( int argc, char **argv ) +{ + ID id; + int rc = EXIT_SUCCESS; + + slap_tool_init( "slapcat", SLAPCAT, argc, argv ); + + slap_startup( be ); + + if( !be->be_entry_open && + !be->be_entry_close && + !be->be_entry_first && + !be->be_entry_next && + !be->be_entry_get ) + { + fprintf( stderr, "%s: database doesn't support necessary operations.\n", + progname ); + exit( EXIT_FAILURE ); + } + + if( be->be_entry_open( be, 0 ) != 0 ) { + fprintf( stderr, "%s: could not open database.\n", + progname ); + exit( EXIT_FAILURE ); + } + + for ( id = be->be_entry_first( be ); + id != NOID; + id = be->be_entry_next( be ) ) + { + char *data; + int len; + Entry* e = be->be_entry_get( be, id ); + + if( verbose ) { + printf( "# id=%08lx\n", (long) id ); + } + + if ( e == NULL ) { + printf("# no data for entry id=%08lx\n\n", (long) id ); + rc = EXIT_FAILURE; + continue; + } + + data = entry2str( e, &len ); + + fputs( data, ldiffp ); + fputs( "\n", ldiffp ); + } + + be->be_entry_close( be ); + + slap_shutdown( be ); + slap_destroy(); + + return rc; +} diff --git a/servers/slapd/tools/slapcat.dsp b/servers/slapd/tools/slapcat.dsp new file mode 100644 index 0000000000..8a73d66066 --- /dev/null +++ b/servers/slapd/tools/slapcat.dsp @@ -0,0 +1,156 @@ +# Microsoft Developer Studio Project File - Name="slapcat" - Package Owner=<4> +# Microsoft Developer Studio Generated Build File, Format Version 5.00 +# ** DO NOT EDIT ** + +# TARGTYPE "Win32 (x86) Console Application" 0x0103 + +CFG=slapcat - Win32 Single Debug +!MESSAGE This is not a valid makefile. To build this project using NMAKE, +!MESSAGE use the Export Makefile command and run +!MESSAGE +!MESSAGE NMAKE /f "slapcat.mak". +!MESSAGE +!MESSAGE You can specify a configuration when running NMAKE +!MESSAGE by defining the macro CFG on the command line. For example: +!MESSAGE +!MESSAGE NMAKE /f "slapcat.mak" CFG="slapcat - Win32 Single Debug" +!MESSAGE +!MESSAGE Possible choices for configuration are: +!MESSAGE +!MESSAGE "slapcat - Win32 Release" (based on "Win32 (x86) Console Application") +!MESSAGE "slapcat - Win32 Debug" (based on "Win32 (x86) Console Application") +!MESSAGE "slapcat - Win32 Single Debug" (based on\ + "Win32 (x86) Console Application") +!MESSAGE "slapcat - Win32 Single Release" (based on\ + "Win32 (x86) Console Application") +!MESSAGE + +# Begin Project +# PROP Scc_ProjName "" +# PROP Scc_LocalPath "" +CPP=cl.exe +RSC=rc.exe + +!IF "$(CFG)" == "slapcat - Win32 Release" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 0 +# PROP BASE Output_Dir "Release" +# PROP BASE Intermediate_Dir "Release" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 0 +# PROP Output_Dir "..\Release" +# PROP Intermediate_Dir "..\Release\slapcat" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c +# ADD CPP /nologo /MT /W3 /GX /O2 /I "..\..\..\include" /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c +# ADD BASE RSC /l 0x409 /d "NDEBUG" +# ADD RSC /l 0x409 /d "NDEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 +# ADD LINK32 hs_regex.lib libdb.lib ws2_32.lib /nologo /subsystem:console /machine:I386 /libpath:"..\..\..\libraries\Release" + +!ELSEIF "$(CFG)" == "slapcat - Win32 Debug" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 1 +# PROP BASE Output_Dir "slapcat" +# PROP BASE Intermediate_Dir "slapcat" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 1 +# PROP Output_Dir "..\Debug" +# PROP Intermediate_Dir "..\Debug\slapcat" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c +# ADD CPP /nologo /MTd /W3 /Gm /GX /Zi /Od /I "..\..\..\include" /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /FR /YX /FD /c +# ADD BASE RSC /l 0x409 /d "_DEBUG" +# ADD RSC /l 0x409 /d "_DEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept +# ADD LINK32 hs_regex.lib libdb.lib ws2_32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept /libpath:"..\..\..\libraries\Debug" + +!ELSEIF "$(CFG)" == "slapcat - Win32 Single Debug" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 1 +# PROP BASE Output_Dir "slapcat" +# PROP BASE Intermediate_Dir "slapcat" +# PROP BASE Ignore_Export_Lib 0 +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 1 +# PROP Output_Dir "..\Sdebug" +# PROP Intermediate_Dir "..\SDebug\slapcat" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /Zi /Od /I "..\..\..\include" /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c +# ADD CPP /nologo /W3 /Gm /GX /Zi /Od /I "..\..\..\include" /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /FR /YX /FD /c +# ADD BASE RSC /l 0x409 /d "_DEBUG" +# ADD RSC /l 0x409 /d "_DEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 oldbm32.lib libdb.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept /libpath:"..\..\..\libraries\Debug" +# ADD LINK32 hs_regex.lib libdbs.lib ws2_32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept /libpath:"..\..\..\libraries\Debug" + +!ELSEIF "$(CFG)" == "slapcat - Win32 Single Release" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 0 +# PROP BASE Output_Dir "slapcat" +# PROP BASE Intermediate_Dir "slapcat" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 0 +# PROP Output_Dir "..\SRelease" +# PROP Intermediate_Dir "..\SRelease\slapcat" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c +# ADD CPP /nologo /W3 /GX /O2 /I "..\..\..\include" /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c +# ADD BASE RSC /l 0x409 /d "NDEBUG" +# ADD RSC /l 0x409 /d "NDEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib libdb.lib /nologo /subsystem:console /machine:I386 /libpath:"..\..\..\libraries\Release" +# ADD LINK32 hs_regex.lib libdbs.lib ws2_32.lib /nologo /subsystem:console /machine:I386 /libpath:"..\..\..\libraries\Release" + +!ENDIF + +# Begin Target + +# Name "slapcat - Win32 Release" +# Name "slapcat - Win32 Debug" +# Name "slapcat - Win32 Single Debug" +# Name "slapcat - Win32 Single Release" +# Begin Source File + +SOURCE=.\mimic.c +# End Source File +# Begin Source File + +SOURCE=.\slapcat.c +# End Source File +# Begin Source File + +SOURCE=.\slapcommon.c +# End Source File +# Begin Source File + +SOURCE=.\slapcommon.h +# End Source File +# End Target +# End Project diff --git a/servers/slapd/tools/slapcommon.c b/servers/slapd/tools/slapcommon.c new file mode 100644 index 0000000000..f2791a629d --- /dev/null +++ b/servers/slapd/tools/slapcommon.c @@ -0,0 +1,203 @@ +/* + * Copyright 1998-1999 The OpenLDAP Foundation, All Rights Reserved. + * COPYING RESTRICTIONS APPLY, see COPYRIGHT file + */ +/* slapcommon.c - common routine for the slap tools */ + +#include "portable.h" + +#include + +#include +#include +#include +#include +#include + +#include "slapcommon.h" +#include "lutil.h" + + +char *progname = NULL; +char *conffile = SLAPD_DEFAULT_CONFIGFILE; +int truncatemode = 0; +int verbose = 0; + +char *ldiffile = NULL; +FILE *ldiffp = NULL; + +Backend *be = NULL; + +static void +usage( int tool ) +{ + char *options = NULL; + fprintf( stderr, + "usage: %s [-v] [-d debuglevel] [-f configfile]\n" + "\t[-n databasenumber | -b suffix]", progname ); + + switch( tool ) { + case SLAPADD: + options = "\t[-l ldiffile]\n"; + break; + + case SLAPCAT: + options = "\t[-l ldiffile]\n"; + break; + + case SLAPINDEX: + options = "\tattributetype\n"; + break; + } + + if( options != NULL ) { + fputs( options, stderr ); + } + exit( EXIT_FAILURE ); +} + + +/* + * slap_tool_init - initialize slap utility, handle program options. + * arguments: + * name program name + * tool tool code + * argc, argv command line arguments + */ + +void +slap_tool_init( + const char* name, + int tool, + int argc, char **argv ) +{ + char *options; + char *base = NULL; + int rc, i, dbnum; + int mode = SLAP_TOOL_MODE; + + progname = lutil_progname( name, argc, argv ); + + switch( tool ) { + case SLAPADD: + options = "b:d:f:l:n:tv"; + break; + + case SLAPINDEX: + options = "b:d:f:n:v"; + break; + + case SLAPCAT: + options = "b:d:f:l:n:v"; + break; + + default: + fprintf( stderr, "%s: unknown tool mode (%d)\n", tool ); + exit( EXIT_FAILURE ); + } + + ldiffile = NULL; + conffile = SLAPD_DEFAULT_CONFIGFILE; + dbnum = -1; + while ( (i = getopt( argc, argv, options )) != EOF ) { + switch ( i ) { + case 'b': + base = strdup( optarg ); + + case 'd': /* turn on debugging */ + ldap_debug = atoi( optarg ); + break; + + case 'f': /* specify a conf file */ + conffile = strdup( optarg ); + break; + + case 'l': /* LDIF file */ + ldiffile = strdup( optarg ); + break; + + case 'n': /* which config file db to index */ + dbnum = atoi( optarg ) - 1; + break; + + case 't': /* turn on truncate */ + truncatemode++; + mode |= SLAP_TRUNCATE_MODE; + break; + + case 'v': /* turn on verbose */ + verbose++; + break; + + default: + usage( tool ); + break; + } + } + + if ( ( argc != optind + (tool == SLAPINDEX ? 1 : 0) ) + || (dbnum >= 0 && base != NULL ) ) + { + usage( tool ); + } + + if ( ldiffile == NULL ) { + ldiffp = tool == SLAPCAT ? stdout : stdin; + + } else if( (ldiffp = fopen( ldiffile, tool == SLAPCAT ? "w" : "r" )) + == NULL ) + { + perror( ldiffile ); + exit( EXIT_FAILURE ); + } + + /* + * initialize stuff and figure out which backend we're dealing with + */ + + rc = slap_init( mode, progname ); + + if (rc != 0 ) { + fprintf( stderr, "%s: slap_init failed!\n", progname ); + exit( EXIT_FAILURE ); + } + + read_config( conffile ); + + if ( !nbackends ) { + fprintf( stderr, "No databases found in config file\n" ); + exit( EXIT_FAILURE ); + } + + if( base != NULL ) { + char *tbase = ch_strdup( base ); + + if( dn_normalize_case( tbase ) == NULL ) { + fprintf( stderr, "%s: slap_init invalid suffix (\"%s\")\n", + progname, base ); + exit( EXIT_FAILURE ); + } + + be = select_backend( tbase ); + free( tbase ); + + if( be == NULL ) { + fprintf( stderr, "%s: slap_init no backend for \"%s\"\n", + progname, base ); + exit( EXIT_FAILURE ); + } + + } else if ( dbnum == -1 ) { + be = &backends[dbnum=0]; + + } else if ( dbnum < 0 || dbnum > (nbackends-1) ) { + fprintf( stderr, + "Database number selected via -n is out of range\n" + "Must be in the range 1 to %d (number of databases in the config file)\n", + nbackends ); + exit( EXIT_FAILURE ); + + } else { + be = &backends[dbnum]; + } +} diff --git a/servers/slapd/tools/slapcommon.h b/servers/slapd/tools/slapcommon.h new file mode 100644 index 0000000000..a5b62b42b1 --- /dev/null +++ b/servers/slapd/tools/slapcommon.h @@ -0,0 +1,36 @@ +/* + * Copyright 1998-1999 The OpenLDAP Foundation, All Rights Reserved. + * COPYING RESTRICTIONS APPLY, see COPYRIGHT file + */ +/* slapcommon.h - common definitions for the slap tools */ + +#ifndef SLAPCOMMON_H_ +#define SLAPCOMMON_H_ 1 + +#define SLAPD_TOOLS 1 +#include "ldap_defaults.h" +#include "../slap.h" + +enum slaptool { + SLAPCAT=1, /* database -> LDIF tool */ + SLAPADD, /* LDIF -> database tool */ + SLAPINDEX, /* database index tool */ + SLAPTEST /* database testing tool */ +}; + + +extern char *progname; +extern char *conffile; +extern Backend *be; +extern int appendmode; +extern int verbose; + +extern char *ldiffile; +extern FILE *ldiffp; + +void slap_tool_init LDAP_P(( + const char* name, + int tool, + int argc, char **argv )); + +#endif /* SLAPCOMMON_H_ */ diff --git a/servers/slapd/tools/slapindex.c b/servers/slapd/tools/slapindex.c new file mode 100644 index 0000000000..8de92b938d --- /dev/null +++ b/servers/slapd/tools/slapindex.c @@ -0,0 +1,109 @@ +/* + * Copyright 1998-1999 The OpenLDAP Foundation, All Rights Reserved. + * COPYING RESTRICTIONS APPLY, see COPYRIGHT file + */ +#include "portable.h" + +#include + +#include + +#include +#include +#include +#include + +#include "slapcommon.h" + +int +main( int argc, char **argv ) +{ + char *type; + ID id; + int rc = EXIT_SUCCESS; + + slap_tool_init( "slapindex", SLAPINDEX, argc, argv ); + + slap_startup( be ); + + if( !be->be_entry_open && + !be->be_entry_close && + !be->be_entry_first && + !be->be_entry_next && + !be->be_entry_get && + !be->be_index_attr && + !be->be_index_change ) + { + fprintf( stderr, "%s: database doesn't support necessary operations.\n", + progname ); + exit( EXIT_FAILURE ); + } + + type = attr_normalize( argv[argc - 1] ); + + if ( !be->be_index_attr( be, type ) ) { + fprintf( stderr, "attribute type \"%s\": no indices to generate\n", + type ); + exit( EXIT_FAILURE ); + } + + if( be->be_entry_open( be, 0 ) != 0 ) { + fprintf( stderr, "%s: could not open database.\n", + progname ); + exit( EXIT_FAILURE ); + } + + for ( id = be->be_entry_first( be ); + id != NOID; + id = be->be_entry_next( be ) ) + { + Attribute *attr; + struct berval **values; + Entry* e = be->be_entry_get( be, id ); + struct berval bv; + struct berval *bvals[2]; + + if ( e == NULL ) { + fprintf( stderr, + "entry id=%08lx: no data\n", (long) id ); + rc = EXIT_FAILURE; + continue; + } + + if( verbose ) { + printf("indexing id=%08lx dn=\"%s\"\n", + id, e->e_dn ); + } + + if( strcasecmp( type, "dn" ) == 0 ) { + attr = attr_find( e->e_attrs, type ); + + if( attr == NULL ) continue; + + values = attr->a_vals; + + } else { + bv.bv_val = e->e_ndn; + bv.bv_len = strlen( bv.bv_val ); + bvals[0] = &bv; + bvals[1] = NULL; + + values = bvals; + } + + if ( be->be_index_change( be, + type, attr->a_vals, id, SLAP_INDEX_ADD_OP ) ) + { + rc = EXIT_FAILURE; + } + + entry_free( e ); + } + + (void) be->be_entry_close( be ); + + slap_shutdown( be ); + slap_destroy(); + + return( rc ); +} diff --git a/servers/slapd/tools/slapindex.dsp b/servers/slapd/tools/slapindex.dsp new file mode 100644 index 0000000000..7c935bf238 --- /dev/null +++ b/servers/slapd/tools/slapindex.dsp @@ -0,0 +1,158 @@ +# Microsoft Developer Studio Project File - Name="slapindex" - Package Owner=<4> +# Microsoft Developer Studio Generated Build File, Format Version 5.00 +# ** DO NOT EDIT ** + +# TARGTYPE "Win32 (x86) Console Application" 0x0103 + +CFG=slapindex - Win32 Single Debug +!MESSAGE This is not a valid makefile. To build this project using NMAKE, +!MESSAGE use the Export Makefile command and run +!MESSAGE +!MESSAGE NMAKE /f "slapindex.mak". +!MESSAGE +!MESSAGE You can specify a configuration when running NMAKE +!MESSAGE by defining the macro CFG on the command line. For example: +!MESSAGE +!MESSAGE NMAKE /f "slapindex.mak" CFG="slapindex - Win32 Single Debug" +!MESSAGE +!MESSAGE Possible choices for configuration are: +!MESSAGE +!MESSAGE "slapindex - Win32 Release" (based on\ + "Win32 (x86) Console Application") +!MESSAGE "slapindex - Win32 Debug" (based on "Win32 (x86) Console Application") +!MESSAGE "slapindex - Win32 Single Debug" (based on\ + "Win32 (x86) Console Application") +!MESSAGE "slapindex - Win32 Single Release" (based on\ + "Win32 (x86) Console Application") +!MESSAGE + +# Begin Project +# PROP Scc_ProjName "" +# PROP Scc_LocalPath "" +CPP=cl.exe +RSC=rc.exe + +!IF "$(CFG)" == "slapindex - Win32 Release" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 0 +# PROP BASE Output_Dir "Release" +# PROP BASE Intermediate_Dir "Release" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 0 +# PROP Output_Dir "..\Release" +# PROP Intermediate_Dir "..\Release\slapindex" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c +# ADD CPP /nologo /MT /W3 /GX /O2 /I "..\..\..\include" /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c +# ADD BASE RSC /l 0x409 /d "NDEBUG" +# ADD RSC /l 0x409 /d "NDEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 +# ADD LINK32 hs_regex.lib libdb.lib ws2_32.lib /nologo /subsystem:console /machine:I386 + +!ELSEIF "$(CFG)" == "slapindex - Win32 Debug" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 1 +# PROP BASE Output_Dir "ldif2ind" +# PROP BASE Intermediate_Dir "ldif2ind" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 1 +# PROP Output_Dir "..\Debug" +# PROP Intermediate_Dir "..\Debug\slapindex" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c +# ADD CPP /nologo /MTd /W3 /Gm /GX /Zi /Od /I "..\..\..\include" /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /FR /YX /FD /c +# ADD BASE RSC /l 0x409 /d "_DEBUG" +# ADD RSC /l 0x409 /d "_DEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept +# ADD LINK32 hs_regex.lib libdb.lib ws2_32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept + +!ELSEIF "$(CFG)" == "slapindex - Win32 Single Debug" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 1 +# PROP BASE Output_Dir "ldif2ind" +# PROP BASE Intermediate_Dir "ldif2ind" +# PROP BASE Ignore_Export_Lib 0 +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 1 +# PROP Output_Dir "..\SDebug" +# PROP Intermediate_Dir "..\SDebug\slapindex" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /Zi /Od /I "..\..\..\include" /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c +# ADD CPP /nologo /W3 /Gm /GX /Zi /Od /I "..\..\..\include" /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /FR /YX /FD /c +# ADD BASE RSC /l 0x409 /d "_DEBUG" +# ADD RSC /l 0x409 /d "_DEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib shell32.lib hs_regexd.lib libdbs.lib ws2_32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept +# ADD LINK32 hs_regex.lib libdbs.lib ws2_32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept + +!ELSEIF "$(CFG)" == "slapindex - Win32 Single Release" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 0 +# PROP BASE Output_Dir "ldif2in0" +# PROP BASE Intermediate_Dir "ldif2in0" +# PROP BASE Ignore_Export_Lib 0 +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 0 +# PROP Output_Dir "..\SRelease" +# PROP Intermediate_Dir "..\SRelease\slapindex" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /MT /W3 /GX /O2 /I "..\..\..\include" /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c +# ADD CPP /nologo /W3 /GX /O2 /I "..\..\..\include" /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c +# ADD BASE RSC /l 0x409 /d "NDEBUG" +# ADD RSC /l 0x409 /d "NDEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 hs_regex.lib libdb.lib ws2_32.lib /nologo /subsystem:console /machine:I386 +# ADD LINK32 hs_regex.lib libdbs.lib ws2_32.lib /nologo /subsystem:console /machine:I386 + +!ENDIF + +# Begin Target + +# Name "slapindex - Win32 Release" +# Name "slapindex - Win32 Debug" +# Name "slapindex - Win32 Single Debug" +# Name "slapindex - Win32 Single Release" +# Begin Source File + +SOURCE=.\mimic.c +# End Source File +# Begin Source File + +SOURCE=.\slapcommon.c +# End Source File +# Begin Source File + +SOURCE=.\slapcommon.h +# End Source File +# Begin Source File + +SOURCE=.\slapindex.c +# End Source File +# End Target +# End Project diff --git a/tests/scripts/defines.sh b/tests/scripts/defines.sh index f13800d21e..8e3f6b1ed3 100755 --- a/tests/scripts/defines.sh +++ b/tests/scripts/defines.sh @@ -3,7 +3,6 @@ DATADIR=$SRCDIR/data PROGDIR=./progs if test "$BACKEND" = "bdb2" ; then - LDIF2LDBM=../servers/slapd/tools/ldif2ldbm-bdb2 CONF=$DATADIR/slapd-bdb2-master.conf ACLCONF=$DATADIR/slapd-bdb2-acl.conf MASTERCONF=$DATADIR/slapd-bdb2-repl-master.conf @@ -11,7 +10,6 @@ if test "$BACKEND" = "bdb2" ; then REFSLAVECONF=$DATADIR/slapd-bdb2-ref-slave.conf TIMING="-t" else - LDIF2LDBM=../servers/slapd/tools/ldif2ldbm CONF=$DATADIR/slapd-master.conf ACLCONF=$DATADIR/slapd-acl.conf MASTERCONF=$DATADIR/slapd-repl-master.conf @@ -28,6 +26,8 @@ PASSWDCONF=$DATADIR/slapd-passwd.conf CLIENTDIR=../clients/tools #CLIENTDIR=/usr/local/bin +LDIF2LDBM="../servers/slapd/tools/slapadd $LDAP_VERBOSE" + SLAPD=../servers/slapd/slapd SLURPD=../servers/slurpd/slurpd LDAPSEARCH="$CLIENTDIR/ldapsearch $PROTO -LLL" diff --git a/tests/scripts/makeldbm.sh b/tests/scripts/makeldbm.sh index 72cdb3053d..4107012e97 100755 --- a/tests/scripts/makeldbm.sh +++ b/tests/scripts/makeldbm.sh @@ -7,7 +7,7 @@ echo "Cleaning up in $DBDIR..." rm -f $DBDIR/[!C]* echo "Running ldif2ldbm to build slapd database..." -$LDIF2LDBM -f $CONF -i $LDIF -e ../servers/slapd/tools +$LDIF2LDBM -f $CONF -l $LDIF RC=$? if test $RC != 0 ; then echo "ldif2ldbm failed!" diff --git a/tests/scripts/startup_nis_ldap_server.sh b/tests/scripts/startup_nis_ldap_server.sh index 2c71f4f2e7..06391bb48c 100755 --- a/tests/scripts/startup_nis_ldap_server.sh +++ b/tests/scripts/startup_nis_ldap_server.sh @@ -27,7 +27,7 @@ echo "Cleaning up in $DBDIR..." rm -f $DBDIR/[!C]* echo "Running ldif2ldbm to build slapd database..." -$LDIF2LDBM -f $NIS_CONF -i $NIS_LDIF -e ../servers/slapd/tools +$LDIF2LDBM -f $NIS_CONF -l $NIS_LDIF RC=$? if [ $RC != 0 ]; then echo "ldif2ldbm failed!" diff --git a/tests/scripts/test001-ldif2ldbm b/tests/scripts/test001-ldif2ldbm index 42123ec417..8fde6c4131 100755 --- a/tests/scripts/test001-ldif2ldbm +++ b/tests/scripts/test001-ldif2ldbm @@ -20,7 +20,7 @@ echo "Cleaning up in $DBDIR..." rm -f $DBDIR/[!C]* echo "Running ldif2ldbm to build slapd database..." -$LDIF2LDBM -f $CONF -i $LDIF -e ../servers/slapd/tools +$LDIF2LDBM -f $CONF -l $LDIF RC=$? if test $RC != 0 ; then echo "ldif2ldbm failed!" diff --git a/tests/scripts/test001-slapadd b/tests/scripts/test001-slapadd index 42123ec417..8fde6c4131 100755 --- a/tests/scripts/test001-slapadd +++ b/tests/scripts/test001-slapadd @@ -20,7 +20,7 @@ echo "Cleaning up in $DBDIR..." rm -f $DBDIR/[!C]* echo "Running ldif2ldbm to build slapd database..." -$LDIF2LDBM -f $CONF -i $LDIF -e ../servers/slapd/tools +$LDIF2LDBM -f $CONF -l $LDIF RC=$? if test $RC != 0 ; then echo "ldif2ldbm failed!" diff --git a/tests/scripts/test003-search b/tests/scripts/test003-search index 2999b01117..de58905d9e 100755 --- a/tests/scripts/test003-search +++ b/tests/scripts/test003-search @@ -17,7 +17,7 @@ echo "Cleaning up in $DBDIR..." rm -f $DBDIR/[!C]* echo "Running ldif2ldbm to build slapd database..." -$LDIF2LDBM -f $CONF -i $LDIF -e ../servers/slapd/tools +$LDIF2LDBM -f $CONF -l $LDIF RC=$? if test $RC != 0 ; then echo "ldif2ldbm failed!" diff --git a/tests/scripts/test004-modify b/tests/scripts/test004-modify index acd91b58c1..c9fbd09029 100755 --- a/tests/scripts/test004-modify +++ b/tests/scripts/test004-modify @@ -17,7 +17,7 @@ echo "Cleaning up in $DBDIR..." rm -f $DBDIR/[!C]* echo "Running ldif2ldbm to build slapd database..." -$LDIF2LDBM -f $CONF -i $LDIF -e ../servers/slapd/tools +$LDIF2LDBM -f $CONF -l $LDIF RC=$? if test $RC != 0 ; then echo "ldif2ldbm failed!" diff --git a/tests/scripts/test005-modrdn b/tests/scripts/test005-modrdn index d7f63a8482..caf0df4f8a 100755 --- a/tests/scripts/test005-modrdn +++ b/tests/scripts/test005-modrdn @@ -17,7 +17,7 @@ echo "Cleaning up in $DBDIR..." rm -f $DBDIR/[!C]* echo "Running ldif2ldbm to build slapd database..." -$LDIF2LDBM -f $CONF -i $LDIF -e ../servers/slapd/tools +$LDIF2LDBM -f $CONF -l $LDIF RC=$? if test $RC != 0 ; then echo "ldif2ldbm failed!" diff --git a/tests/scripts/test006-acls b/tests/scripts/test006-acls index 8ea7024661..ad866b7f1a 100755 --- a/tests/scripts/test006-acls +++ b/tests/scripts/test006-acls @@ -17,7 +17,7 @@ echo "Cleaning up in $DBDIR..." rm -f $DBDIR/[!C]* echo "Running ldif2ldbm to build slapd database..." -$LDIF2LDBM -f $CONF -i $LDIF -e ../servers/slapd/tools +$LDIF2LDBM -f $CONF -l $LDIF RC=$? if test $RC != 0 ; then echo "ldif2ldbm failed!" diff --git a/tests/scripts/test008-concurrency b/tests/scripts/test008-concurrency index 2ba50426d8..9644566ee7 100755 --- a/tests/scripts/test008-concurrency +++ b/tests/scripts/test008-concurrency @@ -20,7 +20,7 @@ echo "Cleaning up in $DBDIR..." rm -f $DBDIR/[!C]* echo "Running ldif2ldbm to build slapd database..." -$LDIF2LDBM -f $CONF -i $LDIF -e ../servers/slapd/tools +$LDIF2LDBM -f $CONF -l $LDIF RC=$? if test $RC != 0 ; then echo "ldif2ldbm failed!" diff --git a/tests/scripts/test009-referral b/tests/scripts/test009-referral index c4c5bbf83f..3bc69ea74f 100755 --- a/tests/scripts/test009-referral +++ b/tests/scripts/test009-referral @@ -22,7 +22,7 @@ rm -f $DBDIR/[!C]* rm -f $REPLDIR/[!C]* echo "Running ldif2ldbm to build slapd database..." -$LDIF2LDBM -f $CONF -i $LDIF -e ../servers/slapd/tools +$LDIF2LDBM -f $CONF -l $LDIF RC=$? if test $RC != 0 ; then echo "ldif2ldbm failed!"