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;
62 struct berval *vals[2];
65 tailorfile = SLAPD_DEFAULT_CONFIGFILE;
67 while ( (i = getopt( argc, argv, "d:f:i:n:" )) != EOF ) {
69 case 'd': /* turn on debugging */
70 ldap_debug = atoi( optarg );
73 case 'f': /* specify a tailor file */
74 tailorfile = strdup( optarg );
77 case 'i': /* input file */
78 inputfile = strdup( optarg );
81 case 'n': /* which config file db to index */
82 dbnum = atoi( optarg ) - 1;
90 attr = attr_normalize( argv[argc - 1] );
91 if ( inputfile == NULL ) {
94 if ( freopen( inputfile, "r", stdin ) == NULL ) {
101 read_config( tailorfile, &be, NULL );
104 for ( dbnum = 0; dbnum < nbackends; dbnum++ ) {
105 if ( strcasecmp( backends[dbnum].be_type, "ldbm" )
110 if ( dbnum == nbackends ) {
111 fprintf( stderr, "No ldbm database found in config file\n" );
114 } else if ( dbnum < 0 || dbnum > (nbackends-1) ) {
115 fprintf( stderr, "Database number selected via -n is out of range\n" );
116 fprintf( stderr, "Must be in the range 1 to %d (number of databases in the config file)\n", nbackends );
118 } else if ( strcasecmp( backends[dbnum].be_type, "ldbm" ) != 0 ) {
119 fprintf( stderr, "Database number %d selected via -n is not an ldbm database\n", dbnum );
122 be = &backends[dbnum];
124 attr_masks( be->be_private, attr, &indexmask, &syntaxmask );
125 if ( indexmask == 0 ) {
137 char *type, *val, *s;
140 if ( fgets( line, sizeof(line), stdin ) != NULL ) {
144 len = strlen( line );
145 while ( lcur + len + 1 > lmax ) {
147 buf = (char *) ch_realloc( buf, lmax );
149 strcpy( buf + lcur, line );
154 if ( line[0] == '\n' || stop && buf && *buf ) {
155 if ( *buf != '\n' ) {
163 while ( (linep = str_getline( &s )) != NULL ) {
165 if ( str_parse_line( linep, &type, &val,
167 Debug( LDAP_DEBUG_PARSE,
168 "bad line %d in entry ending at line %d ignored\n",
169 elineno, elineno, 0 );
173 if ( strcasecmp( type, attr ) == 0 ) {
176 index_add_values( be, attr,
185 (*be->be_close)( be );