11 #include "ldapconfig.h"
13 #include "../back-ldbm/back-ldbm.h"
22 int ldap_syslog_level;
23 long num_entries_sent;
26 char *default_referral;
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 pthread_mutex_t crypt_mutex;
41 static char *tailorfile;
42 static char *inputfile;
47 fprintf( stderr, "usage: %s -i inputfile [-d debuglevel] [-f configfile] [-n databasenumber]\n", name );
52 main( int argc, char **argv )
54 int i, cargc, indb, stop, status;
56 char *defargv[MAXARGS];
63 struct dbcache *db, *db2;
67 struct berval *vals[2];
68 Avlnode *avltypes = NULL;
70 tailorfile = SLAPD_DEFAULT_CONFIGFILE;
72 while ( (i = getopt( argc, argv, "d:f:i:n:" )) != EOF ) {
74 case 'd': /* turn on debugging */
75 ldap_debug = atoi( optarg );
78 case 'f': /* specify a tailor file */
79 tailorfile = strdup( optarg );
82 case 'i': /* input file */
83 inputfile = strdup( optarg );
86 case 'n': /* which config file db to index */
87 dbnum = atoi( optarg ) - 1;
95 if ( inputfile == NULL ) {
98 if ( freopen( inputfile, "r", stdin ) == NULL ) {
105 * initialize stuff and figure out which backend we're dealing with
109 read_config( tailorfile, &be, NULL );
112 for ( dbnum = 0; dbnum < nbackends; dbnum++ ) {
113 if ( strcasecmp( backends[dbnum].be_type, "ldbm" )
118 if ( dbnum == nbackends ) {
119 fprintf( stderr, "No ldbm database found in config file\n" );
122 } else if ( dbnum < 0 || dbnum > (nbackends-1) ) {
123 fprintf( stderr, "Database number selected via -n is out of range\n" );
124 fprintf( stderr, "Must be in the range 1 to %d (number of databases in the config file)\n", nbackends );
126 } else if ( strcasecmp( backends[dbnum].be_type, "ldbm" ) != 0 ) {
127 fprintf( stderr, "Database number %d selected via -n is not an ldbm database\n", dbnum );
130 be = &backends[dbnum];
132 /* disable write sync'ing */
133 li = (struct ldbminfo *) be->be_private;
134 li->li_dbcachewsync = 0;
137 * first, make the dn2id index
140 if ( (db = ldbm_cache_open( be, "dn2id", LDBM_SUFFIX, LDBM_NEWDB ))
142 perror( "dn2id file" );
154 char *type, *val, *s;
158 ldbm_datum_init( key );
159 ldbm_datum_init( data );
161 if ( fgets( line, sizeof(line), stdin ) != NULL ) {
165 len = strlen( line );
166 while ( lcur + len + 1 > lmax ) {
168 buf = (char *) ch_realloc( buf, lmax );
170 strcpy( buf + lcur, line );
175 if ( line[0] == '\n' || stop && buf && *buf ) {
176 if ( *buf != '\n' ) {
184 while ( (linep = str_getline( &s )) != NULL ) {
186 if ( str_parse_line( linep, &type, &val,
188 Debug( LDAP_DEBUG_PARSE,
189 "bad line %d in entry ending at line %d ignored\n",
190 elineno, lineno, 0 );
194 if ( strcmp( type, "dn" ) == 0 )
198 if ( linep == NULL ) {
199 fprintf( stderr, "entry %lu has no dn\n",
202 key.dptr = dn_normalize_case( val );
203 key.dsize = strlen( val ) + 1;
204 data.dptr = (char *) &id;
205 data.dsize = sizeof(ID);
206 if ( ldbm_store( db->dbc_db, key, data,
207 LDBM_REPLACE ) != 0 ) {
208 perror( "dn2id ldbm_store" );
222 * next, make the id2children index
225 if ( (db2 = ldbm_cache_open( be, "id2children", LDBM_SUFFIX,
226 LDBM_NEWDB )) == NULL ) {
227 perror( "id2children file" );
240 char *type, *val, *s, *dn;
246 ldbm_datum_init( key );
247 ldbm_datum_init( data );
249 if ( fgets( line, sizeof(line), stdin ) != NULL ) {
252 len = strlen( line );
253 while ( lcur + len + 1 > lmax ) {
255 buf = (char *) ch_realloc( buf, lmax );
257 strcpy( buf + lcur, line );
262 if ( line[0] == '\n' || stop && buf && *buf ) {
263 if ( * buf != '\n' ) {
266 while ( (linep = str_getline( &s )) != NULL ) {
267 if ( str_parse_line( linep, &type, &val,
269 Debug( LDAP_DEBUG_PARSE,
270 "bad line %d ignored\n",
275 if ( strcmp( type, "dn" ) == 0 )
279 if ( linep == NULL ) {
280 fprintf( stderr, "entry %lu has no dn\n",
283 if ( (dn = dn_parent( be, val ))
288 dn_normalize_case( dn );
289 key.dsize = strlen( dn ) + 1;
291 data = ldbm_fetch( db->dbc_db,
294 if ( data.dptr == NULL ) {
296 if ( ! be_issuffix( be,
298 Debug( LDAP_DEBUG_PARSE, "no parent \"%s\" of \"%s\"\n", dn, val, 0 );
305 (void) memcpy( (char *) &pid,
306 data.dptr, sizeof(ID) );
309 sprintf( buf2, "%c%ld", EQ_PREFIX, pid );
311 key.dsize = strlen( buf2 ) + 1;
312 if ( idl_insert_key( be, db2, key, id )
314 perror( "idl_insert_key" );
324 (*be->be_close)( be );