12 #include "../back-ldbm/back-ldbm.h"
14 #include "ldapconfig.h"
21 int ldap_syslog_level;
22 int global_schemacheck;
23 long num_entries_sent;
26 char *default_referral;
27 struct objclass *global_oc;
29 pthread_t listener_tid;
30 pthread_mutex_t num_sent_mutex;
31 pthread_mutex_t entry2str_mutex;
32 pthread_mutex_t active_threads_mutex;
33 pthread_mutex_t new_conn_mutex;
34 pthread_mutex_t currenttime_mutex;
35 pthread_mutex_t replog_mutex;
36 pthread_mutex_t ops_mutex;
37 pthread_mutex_t regex_mutex;
43 fprintf( stderr, "usage: %s -i inputfile [-d debuglevel] [-f configfile] [-n databasenumber] attr\n", name );
48 main( int argc, char **argv )
50 int i, cargc, indb, stop;
52 char *defargv[MAXARGS];
53 char *tailorfile, *inputfile;
54 char *linep, *buf, *attr;
57 int lmax, lcur, indexmask, syntaxmask;
63 struct berval *vals[2];
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 attr = attr_normalize( argv[argc - 1] );
92 if ( inputfile == NULL ) {
95 if ( freopen( inputfile, "r", stdin ) == NULL ) {
102 read_config( tailorfile, &be, NULL );
105 for ( dbnum = 0; dbnum < nbackends; dbnum++ ) {
106 if ( strcasecmp( backends[dbnum].be_type, "ldbm" )
111 if ( dbnum == nbackends ) {
112 fprintf( stderr, "No ldbm database found in config file\n" );
115 } else if ( dbnum < 0 || dbnum > (nbackends-1) ) {
116 fprintf( stderr, "Database number selected via -n is out of range\n" );
117 fprintf( stderr, "Must be in the range 1 to %d (number of databases in the config file)\n", nbackends );
119 } else if ( strcasecmp( backends[dbnum].be_type, "ldbm" ) != 0 ) {
120 fprintf( stderr, "Database number %d selected via -n is not an ldbm database\n", dbnum );
123 be = &backends[dbnum];
125 /* disable write sync'ing */
126 li = (struct ldbminfo *) be->be_private;
127 li->li_dbcachewsync = 0;
129 attr_masks( be->be_private, attr, &indexmask, &syntaxmask );
130 if ( indexmask == 0 ) {
142 char *type, *val, *s;
145 if ( fgets( line, sizeof(line), stdin ) != NULL ) {
149 len = strlen( line );
150 while ( lcur + len + 1 > lmax ) {
152 buf = (char *) ch_realloc( buf, lmax );
154 strcpy( buf + lcur, line );
159 if ( line[0] == '\n' || stop && buf && *buf ) {
160 if ( *buf != '\n' ) {
168 while ( (linep = str_getline( &s )) != NULL ) {
170 if ( str_parse_line( linep, &type, &val,
172 Debug( LDAP_DEBUG_PARSE,
173 "bad line %d in entry ending at line %d ignored\n",
174 elineno, elineno, 0 );
178 if ( strcasecmp( type, attr ) == 0 ) {
181 index_add_values( be, attr,
190 (*be->be_close)( be );