4 #include <sys/socket.h>
6 #include "../back-ldbm/back-ldbm.h"
8 #include "ldapconfig.h"
12 extern struct dbcache *ldbm_cache_open();
13 extern void attr_index_config();
14 extern char *str_getline();
15 extern char *dn_parent();
16 extern char *dn_normalize_case();
17 extern int strcasecmp();
19 extern Backend *backends;
20 extern int ldap_debug;
25 int ldap_syslog_level;
26 int global_schemacheck;
30 char *default_referral;
31 struct objclass *global_oc;
33 pthread_t listener_tid;
34 pthread_mutex_t num_sent_mutex;
35 pthread_mutex_t entry2str_mutex;
36 pthread_mutex_t active_threads_mutex;
37 pthread_mutex_t new_conn_mutex;
38 pthread_mutex_t currenttime_mutex;
39 pthread_mutex_t replog_mutex;
40 pthread_mutex_t ops_mutex;
41 pthread_mutex_t regex_mutex;
43 static int make_index();
45 static char *tailorfile;
46 static char *inputfile;
51 fprintf( stderr, "usage: %s -i inputfile [-d debuglevel] [-f configfile] [-n databasenumber]\n", name );
55 main( int argc, char **argv )
57 int i, cargc, indb, stop, status;
59 char *defargv[MAXARGS];
66 struct dbcache *db, *db2;
69 struct berval *vals[2];
70 Avlnode *avltypes = NULL;
73 tailorfile = SLAPD_DEFAULT_CONFIGFILE;
75 while ( (i = getopt( argc, argv, "d:f:i:n:" )) != EOF ) {
77 case 'd': /* turn on debugging */
78 ldap_debug = atoi( optarg );
81 case 'f': /* specify a tailor file */
82 tailorfile = strdup( optarg );
85 case 'i': /* input file */
86 inputfile = strdup( optarg );
89 case 'n': /* which config file db to index */
90 dbnum = atoi( optarg ) - 1;
98 if ( inputfile == NULL ) {
101 if ( freopen( inputfile, "r", stdin ) == NULL ) {
108 * initialize stuff and figure out which backend we're dealing with
112 read_config( tailorfile, &be, NULL );
115 for ( dbnum = 0; dbnum < nbackends; dbnum++ ) {
116 if ( strcasecmp( backends[dbnum].be_type, "ldbm" )
121 if ( dbnum == nbackends ) {
122 fprintf( stderr, "No ldbm database found in config file\n" );
125 } else if ( dbnum < 0 || dbnum > (nbackends-1) ) {
126 fprintf( stderr, "Database number selected via -n is out of range\n" );
127 fprintf( stderr, "Must be in the range 1 to %d (number of databases in the config file)\n", nbackends );
129 } else if ( strcasecmp( backends[dbnum].be_type, "ldbm" ) != 0 ) {
130 fprintf( stderr, "Database number %d selected via -n is not an ldbm database\n", dbnum );
133 be = &backends[dbnum];
136 * first, make the dn2id index
139 if ( (db = ldbm_cache_open( be, "dn2id", LDBM_SUFFIX, LDBM_NEWDB ))
141 perror( "dn2id file" );
153 char *type, *val, *s;
157 if ( fgets( line, sizeof(line), stdin ) != NULL ) {
161 len = strlen( line );
162 while ( lcur + len + 1 > lmax ) {
164 buf = (char *) ch_realloc( buf, lmax );
166 strcpy( buf + lcur, line );
171 if ( line[0] == '\n' || stop && buf && *buf ) {
172 if ( *buf != '\n' ) {
176 while ( (linep = str_getline( &s )) != NULL ) {
178 if ( str_parse_line( linep, &type, &val,
180 Debug( LDAP_DEBUG_PARSE,
181 "bad line %d in entry ending at line %d ignored\n",
182 elineno, lineno, 0 );
186 if ( strcmp( type, "dn" ) == 0 )
190 if ( linep == NULL ) {
191 fprintf( stderr, "entry %d has no dn\n",
194 key.dptr = dn_normalize_case( val );
195 key.dsize = strlen( val ) + 1;
196 data.dptr = (char *) &id;
197 data.dsize = sizeof(ID);
198 if ( ldbm_store( db->dbc_db, key, data,
199 LDBM_REPLACE ) != 0 ) {
200 perror( "dn2id ldbm_store" );
212 * next, make the id2children index
215 if ( (db2 = ldbm_cache_open( be, "id2children", LDBM_SUFFIX,
216 LDBM_NEWDB )) == NULL ) {
217 perror( "id2children file" );
230 char *type, *val, *s, *dn;
236 if ( fgets( line, sizeof(line), stdin ) != NULL ) {
239 len = strlen( line );
240 while ( lcur + len + 1 > lmax ) {
242 buf = (char *) ch_realloc( buf, lmax );
244 strcpy( buf + lcur, line );
249 if ( line[0] == '\n' || stop && buf && *buf ) {
250 if ( * buf != '\n' ) {
253 while ( (linep = str_getline( &s )) != NULL ) {
254 if ( str_parse_line( linep, &type, &val,
256 Debug( LDAP_DEBUG_PARSE,
257 "bad line %d ignored\n",
262 if ( strcmp( type, "dn" ) == 0 )
266 if ( linep == NULL ) {
267 fprintf( stderr, "entry %d has no dn\n",
270 if ( (dn = dn_parent( be, val ))
275 dn_normalize_case( dn );
276 key.dsize = strlen( dn ) + 1;
278 data = ldbm_fetch( db->dbc_db,
280 if ( data.dptr == NULL ) {
282 if ( ! be_issuffix( be,
284 Debug( LDAP_DEBUG_PARSE, "no parent \"%s\" of \"%s\"\n", dn, val, 0 );
291 (void) memcpy( (char *) &pid,
292 data.dptr, sizeof(ID) );
295 sprintf( buf2, "%c%d", EQ_PREFIX, pid );
297 key.dsize = strlen( buf2 ) + 1;
298 if ( idl_insert_key( be, db2, key, id )
300 perror( "idl_insert_key" );
310 (*be->be_close)( be );