10 #include <ac/unistd.h>
12 #include "ldif2common.h"
13 #include "../back-bdb2/back-bdb2.h"
17 main( int argc, char **argv )
25 struct dbcache *db, *db2;
29 struct berval *vals[2];
31 slap_ldif_init( argc, argv, LDIF2ID2CHILDREN, "bdb2", SLAP_TOOL_MODE );
34 be = &backends[dbnum];
36 /* disable write sync'ing */
37 li = (struct ldbminfo *) be->be_private;
38 li->li_dbcachewsync = 0;
41 * first, make the dn2id index
44 if ( (db = bdb2i_cache_open( be, "dn2id", BDB2_SUFFIX, LDBM_NEWDB ))
46 perror( "dn2id file" );
62 ldbm_datum_init( key );
63 ldbm_datum_init( data );
65 if ( fgets( line, sizeof(line), stdin ) != NULL ) {
70 while ( lcur + len + 1 > lmax ) {
72 buf = (char *) ch_realloc( buf, lmax );
74 strcpy( buf + lcur, line );
79 if ( line[0] == '\n' || stop && buf && *buf ) {
81 if (isdigit((unsigned char) *buf)) {
88 while ( (linep = ldif_getline( &s )) != NULL ) {
90 if ( ldif_parse_line( linep, &type, &val,
92 Debug( LDAP_DEBUG_PARSE,
93 "bad line %d in entry ending at line %d ignored\n",
98 if ( strcmp( type, "dn" ) == 0 )
102 if ( linep == NULL ) {
103 fprintf( stderr, "entry %ld has no dn\n",
106 (void) dn_normalize_case( val );
108 key.dsize = strlen( val ) + 1;
109 data.dptr = (char *) &id;
110 data.dsize = sizeof(ID);
111 if ( ldbm_store( db->dbc_db, key, data,
112 LDBM_REPLACE ) != 0 ) {
113 perror( "dn2id ldbm_store..." );
114 exit( EXIT_FAILURE );
127 * next, make the id2children index
130 if ( (db2 = bdb2i_cache_open( be, "id2children", BDB2_SUFFIX,
131 LDBM_NEWDB )) == NULL ) {
132 perror( "id2children file" );
133 exit( EXIT_FAILURE );
145 char *type, *val, *s, *dn;
151 ldbm_datum_init( key );
152 ldbm_datum_init( data );
154 if ( fgets( line, sizeof(line), stdin ) != NULL ) {
157 len = strlen( line );
158 while ( lcur + len + 1 > lmax ) {
160 buf = (char *) ch_realloc( buf, lmax );
162 strcpy( buf + lcur, line );
167 if ( line[0] == '\n' || stop && buf && *buf ) {
168 if ( * buf != '\n' ) {
169 if (isdigit((unsigned char) *buf)) {
175 while ( (linep = ldif_getline( &s )) != NULL ) {
176 if ( ldif_parse_line( linep, &type, &val,
178 Debug( LDAP_DEBUG_PARSE,
179 "bad line %d ignored\n",
184 if ( strcmp( type, "dn" ) == 0 )
188 if ( linep == NULL ) {
189 fprintf( stderr, "entry %ld has no dn\n",
192 if ( (dn = dn_parent( be, val ))
196 (void) dn_normalize_case( dn );
198 key.dsize = strlen( dn ) + 1;
200 data = ldbm_fetch( db->dbc_db,
203 if ( data.dptr == NULL ) {
204 (void) dn_normalize_case( val );
205 if ( ! be_issuffix( be,
207 Debug( LDAP_DEBUG_PARSE, "no parent \"%s\" of \"%s\"\n", dn, val, 0 );
214 (void) memcpy( (char *) &pid,
215 data.dptr, sizeof(ID) );
217 ldbm_datum_free( db->dbc_db, data);
220 sprintf( buf2, "%c%ld", EQ_PREFIX, pid );
222 key.dsize = strlen( buf2 ) + 1;
223 if ( bdb2i_idl_insert_key( be, db2, key, id )
225 perror( "bdb2i_idl_insert_key" );
226 exit( EXIT_FAILURE );
237 bdb2i_cache_close( be, db2 );
238 bdb2i_cache_close( be, db );
241 slap_shutdown(dbnum);
244 exit( EXIT_SUCCESS );