2 * Copyright 1998-1999 The OpenLDAP Foundation, All Rights Reserved.
3 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
12 #include <ac/string.h>
13 #include <ac/socket.h>
14 #include <ac/unistd.h>
16 #include "ldif2common.h"
17 #include "../back-ldbm/back-ldbm.h"
21 main( int argc, char **argv )
33 struct berval *vals[2];
35 ldbm_ignore_nextid_file = 1;
37 slap_ldif_init( argc, argv, LDIF2ID2CHILDREN, "ldbm", SLAP_TOOL_MODE );
40 be = &backends[dbnum];
42 /* disable write sync'ing */
43 li = (struct ldbminfo *) be->be_private;
44 li->li_dbcachewsync = 0;
47 * first, make the dn2id index
50 if ( (db = ldbm_cache_open( be, "dn2id", LDBM_SUFFIX, LDBM_NEWDB ))
52 perror( "dn2id file" );
68 ldbm_datum_init( key );
69 ldbm_datum_init( data );
71 if ( fgets( line, sizeof(line), stdin ) != NULL ) {
76 while ( lcur + len + 1 > lmax ) {
78 buf = (char *) ch_realloc( buf, lmax );
80 strcpy( buf + lcur, line );
85 if ( line[0] == '\n' || stop && buf && *buf ) {
87 if (isdigit((unsigned char) *buf)) {
94 while ( (linep = ldif_getline( &s )) != NULL ) {
96 if ( ldif_parse_line( linep, &type, &val,
98 Debug( LDAP_DEBUG_PARSE,
99 "bad line %d in entry ending at line %d ignored\n",
100 elineno, lineno, 0 );
104 if ( strcmp( type, "dn" ) == 0 )
108 if ( linep == NULL ) {
109 fprintf( stderr, "entry %ld has no dn\n",
112 (void) dn_normalize_case( val );
114 key.dsize = strlen( val ) + 1;
115 data.dptr = (char *) &id;
116 data.dsize = sizeof(ID);
117 if ( ldbm_store( db->dbc_db, key, data,
118 LDBM_REPLACE ) != 0 ) {
119 perror( "dn2id ldbm_store" );
120 exit( EXIT_FAILURE );
133 * next, make the id2children index
136 if ( (db2 = ldbm_cache_open( be, "id2children", LDBM_SUFFIX,
137 LDBM_NEWDB )) == NULL ) {
138 perror( "id2children file" );
139 exit( EXIT_FAILURE );
151 char *type, *val, *s, *dn;
157 ldbm_datum_init( key );
158 ldbm_datum_init( data );
160 if ( fgets( line, sizeof(line), stdin ) != NULL ) {
163 len = strlen( line );
164 while ( lcur + len + 1 > lmax ) {
166 buf = (char *) ch_realloc( buf, lmax );
168 strcpy( buf + lcur, line );
173 if ( line[0] == '\n' || stop && buf && *buf ) {
174 if ( * buf != '\n' ) {
175 if (isdigit((unsigned char) *buf)) {
181 while ( (linep = ldif_getline( &s )) != NULL ) {
182 if ( ldif_parse_line( linep, &type, &val,
184 Debug( LDAP_DEBUG_PARSE,
185 "bad line %d ignored\n",
190 if ( strcmp( type, "dn" ) == 0 )
194 if ( linep == NULL ) {
195 fprintf( stderr, "entry %ld has no dn\n",
198 if ( (dn = dn_parent( be, val ))
202 (void) dn_normalize_case( dn );
204 key.dsize = strlen( dn ) + 1;
206 data = ldbm_fetch( db->dbc_db,
209 if ( data.dptr == NULL ) {
210 (void) dn_normalize_case( val );
211 if ( ! be_issuffix( be,
213 Debug( LDAP_DEBUG_PARSE, "no parent \"%s\" of \"%s\"\n", dn, val, 0 );
220 (void) memcpy( (char *) &pid,
221 data.dptr, sizeof(ID) );
223 ldbm_datum_free( db->dbc_db, data);
226 sprintf( buf2, "%c%ld", EQ_PREFIX, pid );
228 key.dsize = strlen( buf2 ) + 1;
229 if ( idl_insert_key( be, db2, key, id )
231 perror( "idl_insert_key" );
232 exit( EXIT_FAILURE );
243 ldbm_cache_close( be, db2 );
244 ldbm_cache_close( be, db );
247 slap_shutdown(dbnum);
250 return( EXIT_SUCCESS );