4 #include <sys/socket.h>
6 #include "../back-ldbm/back-ldbm.h"
8 #define DEFAULT_CONFIGFILE "/usr/local/etc/slapd.conf"
11 extern struct dbcache *ldbm_cache_open();
12 extern void attr_index_config();
13 extern char *str_getline();
14 extern char *dn_parent();
15 extern char *dn_normalize_case();
16 extern int strcasecmp();
18 extern Backend *backends;
19 extern int ldap_debug;
24 int ldap_syslog_level;
25 int global_schemacheck;
29 char *default_referral;
30 struct objclass *global_oc;
32 pthread_t listener_tid;
33 pthread_mutex_t num_sent_mutex;
34 pthread_mutex_t entry2str_mutex;
35 pthread_mutex_t active_threads_mutex;
36 pthread_mutex_t new_conn_mutex;
37 pthread_mutex_t currenttime_mutex;
38 pthread_mutex_t replog_mutex;
39 pthread_mutex_t ops_mutex;
40 pthread_mutex_t regex_mutex;
42 static int make_index();
44 static char *tailorfile;
45 static char *inputfile;
50 fprintf( stderr, "usage: %s -i inputfile [-d debuglevel] [-f configfile] [-n databasenumber]\n", name );
54 main( int argc, char **argv )
56 int i, cargc, indb, stop, status;
58 char *defargv[MAXARGS];
65 struct dbcache *db, *db2;
68 struct berval *vals[2];
69 Avlnode *avltypes = NULL;
72 tailorfile = DEFAULT_CONFIGFILE;
74 while ( (i = getopt( argc, argv, "d:f:i:n:" )) != EOF ) {
76 case 'd': /* turn on debugging */
77 ldap_debug = atoi( optarg );
80 case 'f': /* specify a tailor file */
81 tailorfile = strdup( optarg );
84 case 'i': /* input file */
85 inputfile = strdup( optarg );
88 case 'n': /* which config file db to index */
89 dbnum = atoi( optarg ) - 1;
97 if ( inputfile == NULL ) {
100 if ( freopen( inputfile, "r", stdin ) == NULL ) {
107 * initialize stuff and figure out which backend we're dealing with
111 read_config( tailorfile, &be, NULL );
114 for ( dbnum = 0; dbnum < nbackends; dbnum++ ) {
115 if ( strcasecmp( backends[dbnum].be_type, "ldbm" )
120 if ( dbnum == nbackends ) {
121 fprintf( stderr, "No ldbm database found in config file\n" );
124 } else if ( dbnum < 0 || dbnum > (nbackends-1) ) {
125 fprintf( stderr, "Database number selected via -n is out of range\n" );
126 fprintf( stderr, "Must be in the range 1 to %d (number of databases in the config file)\n", nbackends );
128 } else if ( strcasecmp( backends[dbnum].be_type, "ldbm" ) != 0 ) {
129 fprintf( stderr, "Database number %d selected via -n is not an ldbm database\n", dbnum );
132 be = &backends[dbnum];
135 * first, make the dn2id index
138 if ( (db = ldbm_cache_open( be, "dn2id", LDBM_SUFFIX, LDBM_NEWDB ))
140 perror( "dn2id file" );
152 char *type, *val, *s;
156 if ( fgets( line, sizeof(line), stdin ) != NULL ) {
160 len = strlen( line );
161 while ( lcur + len + 1 > lmax ) {
163 buf = (char *) ch_realloc( buf, lmax );
165 strcpy( buf + lcur, line );
170 if ( line[0] == '\n' || stop && buf && *buf ) {
171 if ( *buf != '\n' ) {
175 while ( (linep = str_getline( &s )) != NULL ) {
177 if ( str_parse_line( linep, &type, &val,
179 Debug( LDAP_DEBUG_PARSE,
180 "bad line %d in entry ending at line %d ignored\n",
181 elineno, lineno, 0 );
185 if ( strcmp( type, "dn" ) == 0 )
189 if ( linep == NULL ) {
190 fprintf( stderr, "entry %d has no dn\n",
193 key.dptr = dn_normalize_case( val );
194 key.dsize = strlen( val ) + 1;
195 data.dptr = (char *) &id;
196 data.dsize = sizeof(ID);
197 if ( ldbm_store( db->dbc_db, key, data,
198 LDBM_REPLACE ) != 0 ) {
199 perror( "dn2id ldbm_store" );
211 * next, make the id2children index
214 if ( (db2 = ldbm_cache_open( be, "id2children", LDBM_SUFFIX,
215 LDBM_NEWDB )) == NULL ) {
216 perror( "id2children file" );
229 char *type, *val, *s, *dn;
235 if ( fgets( line, sizeof(line), stdin ) != NULL ) {
238 len = strlen( line );
239 while ( lcur + len + 1 > lmax ) {
241 buf = (char *) ch_realloc( buf, lmax );
243 strcpy( buf + lcur, line );
248 if ( line[0] == '\n' || stop && buf && *buf ) {
249 if ( * buf != '\n' ) {
252 while ( (linep = str_getline( &s )) != NULL ) {
253 if ( str_parse_line( linep, &type, &val,
255 Debug( LDAP_DEBUG_PARSE,
256 "bad line %d ignored\n",
261 if ( strcmp( type, "dn" ) == 0 )
265 if ( linep == NULL ) {
266 fprintf( stderr, "entry %d has no dn\n",
269 if ( (dn = dn_parent( be, val ))
274 dn_normalize_case( dn );
275 key.dsize = strlen( dn ) + 1;
277 data = ldbm_fetch( db->dbc_db,
279 if ( data.dptr == NULL ) {
281 if ( ! be_issuffix( be,
283 Debug( LDAP_DEBUG_PARSE, "no parent \"%s\" of \"%s\"\n", dn, val, 0 );
290 (void) memcpy( (char *) &pid,
291 data.dptr, sizeof(ID) );
294 sprintf( buf2, "%c%d", EQ_PREFIX, pid );
296 key.dsize = strlen( buf2 ) + 1;
297 if ( idl_insert_key( be, db2, key, id )
299 perror( "idl_insert_key" );
309 (*be->be_close)( be );