9 #include "ldapconfig.h"
11 #include "../back-ldbm/back-ldbm.h"
20 int ldap_syslog_level;
21 int global_schemacheck;
22 long num_entries_sent;
25 char *default_referral;
26 struct objclass *global_oc;
28 pthread_t listener_tid;
29 pthread_mutex_t num_sent_mutex;
30 pthread_mutex_t entry2str_mutex;
31 pthread_mutex_t active_threads_mutex;
32 pthread_mutex_t new_conn_mutex;
33 pthread_mutex_t currenttime_mutex;
34 pthread_mutex_t replog_mutex;
35 pthread_mutex_t ops_mutex;
36 pthread_mutex_t regex_mutex;
38 static char *tailorfile;
39 static char *inputfile;
44 fprintf( stderr, "usage: %s -i inputfile [-d debuglevel] [-f configfile] [-n databasenumber]\n", name );
49 main( int argc, char **argv )
51 int i, cargc, indb, stop, status;
53 char *defargv[MAXARGS];
60 struct dbcache *db, *db2;
63 struct berval *vals[2];
64 Avlnode *avltypes = NULL;
66 tailorfile = SLAPD_DEFAULT_CONFIGFILE;
68 while ( (i = getopt( argc, argv, "d:f:i:n:" )) != EOF ) {
70 case 'd': /* turn on debugging */
71 ldap_debug = atoi( optarg );
74 case 'f': /* specify a tailor file */
75 tailorfile = strdup( optarg );
78 case 'i': /* input file */
79 inputfile = strdup( optarg );
82 case 'n': /* which config file db to index */
83 dbnum = atoi( optarg ) - 1;
91 if ( inputfile == NULL ) {
94 if ( freopen( inputfile, "r", stdin ) == NULL ) {
101 * initialize stuff and figure out which backend we're dealing with
105 read_config( tailorfile, &be, NULL );
108 for ( dbnum = 0; dbnum < nbackends; dbnum++ ) {
109 if ( strcasecmp( backends[dbnum].be_type, "ldbm" )
114 if ( dbnum == nbackends ) {
115 fprintf( stderr, "No ldbm database found in config file\n" );
118 } else if ( dbnum < 0 || dbnum > (nbackends-1) ) {
119 fprintf( stderr, "Database number selected via -n is out of range\n" );
120 fprintf( stderr, "Must be in the range 1 to %d (number of databases in the config file)\n", nbackends );
122 } else if ( strcasecmp( backends[dbnum].be_type, "ldbm" ) != 0 ) {
123 fprintf( stderr, "Database number %d selected via -n is not an ldbm database\n", dbnum );
126 be = &backends[dbnum];
129 * first, make the dn2id index
132 if ( (db = ldbm_cache_open( be, "dn2id", LDBM_SUFFIX, LDBM_NEWDB ))
134 perror( "dn2id file" );
146 char *type, *val, *s;
150 if ( fgets( line, sizeof(line), stdin ) != NULL ) {
154 len = strlen( line );
155 while ( lcur + len + 1 > lmax ) {
157 buf = (char *) ch_realloc( buf, lmax );
159 strcpy( buf + lcur, line );
164 if ( line[0] == '\n' || stop && buf && *buf ) {
165 if ( *buf != '\n' ) {
169 while ( (linep = str_getline( &s )) != NULL ) {
171 if ( str_parse_line( linep, &type, &val,
173 Debug( LDAP_DEBUG_PARSE,
174 "bad line %d in entry ending at line %d ignored\n",
175 elineno, lineno, 0 );
179 if ( strcmp( type, "dn" ) == 0 )
183 if ( linep == NULL ) {
184 fprintf( stderr, "entry %lu has no dn\n",
187 key.dptr = dn_normalize_case( val );
188 key.dsize = strlen( val ) + 1;
189 data.dptr = (char *) &id;
190 data.dsize = sizeof(ID);
191 if ( ldbm_store( db->dbc_db, key, data,
192 LDBM_REPLACE ) != 0 ) {
193 perror( "dn2id ldbm_store" );
205 * next, make the id2children index
208 if ( (db2 = ldbm_cache_open( be, "id2children", LDBM_SUFFIX,
209 LDBM_NEWDB )) == NULL ) {
210 perror( "id2children file" );
223 char *type, *val, *s, *dn;
229 if ( fgets( line, sizeof(line), stdin ) != NULL ) {
232 len = strlen( line );
233 while ( lcur + len + 1 > lmax ) {
235 buf = (char *) ch_realloc( buf, lmax );
237 strcpy( buf + lcur, line );
242 if ( line[0] == '\n' || stop && buf && *buf ) {
243 if ( * buf != '\n' ) {
246 while ( (linep = str_getline( &s )) != NULL ) {
247 if ( str_parse_line( linep, &type, &val,
249 Debug( LDAP_DEBUG_PARSE,
250 "bad line %d ignored\n",
255 if ( strcmp( type, "dn" ) == 0 )
259 if ( linep == NULL ) {
260 fprintf( stderr, "entry %lu has no dn\n",
263 if ( (dn = dn_parent( be, val ))
268 dn_normalize_case( dn );
269 key.dsize = strlen( dn ) + 1;
271 data = ldbm_fetch( db->dbc_db,
274 if ( data.dptr == NULL ) {
276 if ( ! be_issuffix( be,
278 Debug( LDAP_DEBUG_PARSE, "no parent \"%s\" of \"%s\"\n", dn, val, 0 );
285 (void) memcpy( (char *) &pid,
286 data.dptr, sizeof(ID) );
289 sprintf( buf2, "%c%ld", EQ_PREFIX, pid );
291 key.dsize = strlen( buf2 ) + 1;
292 if ( idl_insert_key( be, db2, key, id )
294 perror( "idl_insert_key" );
304 (*be->be_close)( be );