12 #include "../back-ldbm/back-ldbm.h"
14 #include "ldapconfig.h"
21 int ldap_syslog_level;
22 long num_entries_sent;
25 char *default_referral;
27 pthread_t listener_tid;
28 pthread_mutex_t num_sent_mutex;
29 pthread_mutex_t entry2str_mutex;
30 pthread_mutex_t active_threads_mutex;
31 pthread_mutex_t new_conn_mutex;
32 pthread_mutex_t currenttime_mutex;
33 pthread_mutex_t replog_mutex;
34 pthread_mutex_t ops_mutex;
35 pthread_mutex_t regex_mutex;
41 fprintf( stderr, "usage: %s -i inputfile [-d debuglevel] [-f configfile] [-n databasenumber] attr\n", name );
46 main( int argc, char **argv )
48 int i, cargc, indb, stop;
50 char *defargv[MAXARGS];
51 char *tailorfile, *inputfile;
52 char *linep, *buf, *attr;
55 int lmax, lcur, indexmask, syntaxmask;
61 struct berval *vals[2];
64 tailorfile = SLAPD_DEFAULT_CONFIGFILE;
66 while ( (i = getopt( argc, argv, "d:f:i:n:" )) != EOF ) {
68 case 'd': /* turn on debugging */
69 ldap_debug = atoi( optarg );
72 case 'f': /* specify a tailor file */
73 tailorfile = strdup( optarg );
76 case 'i': /* input file */
77 inputfile = strdup( optarg );
80 case 'n': /* which config file db to index */
81 dbnum = atoi( optarg ) - 1;
89 attr = attr_normalize( argv[argc - 1] );
90 if ( inputfile == NULL ) {
93 if ( freopen( inputfile, "r", stdin ) == NULL ) {
100 read_config( tailorfile, &be, NULL );
103 for ( dbnum = 0; dbnum < nbackends; dbnum++ ) {
104 if ( strcasecmp( backends[dbnum].be_type, "ldbm" )
109 if ( dbnum == nbackends ) {
110 fprintf( stderr, "No ldbm database found in config file\n" );
113 } else if ( dbnum < 0 || dbnum > (nbackends-1) ) {
114 fprintf( stderr, "Database number selected via -n is out of range\n" );
115 fprintf( stderr, "Must be in the range 1 to %d (number of databases in the config file)\n", nbackends );
117 } else if ( strcasecmp( backends[dbnum].be_type, "ldbm" ) != 0 ) {
118 fprintf( stderr, "Database number %d selected via -n is not an ldbm database\n", dbnum );
121 be = &backends[dbnum];
123 /* disable write sync'ing */
124 li = (struct ldbminfo *) be->be_private;
125 li->li_dbcachewsync = 0;
127 attr_masks( be->be_private, attr, &indexmask, &syntaxmask );
128 if ( indexmask == 0 ) {
140 char *type, *val, *s;
143 if ( fgets( line, sizeof(line), stdin ) != NULL ) {
147 len = strlen( line );
148 while ( lcur + len + 1 > lmax ) {
150 buf = (char *) ch_realloc( buf, lmax );
152 strcpy( buf + lcur, line );
157 if ( line[0] == '\n' || stop && buf && *buf ) {
158 if ( *buf != '\n' ) {
166 while ( (linep = str_getline( &s )) != NULL ) {
168 if ( str_parse_line( linep, &type, &val,
170 Debug( LDAP_DEBUG_PARSE,
171 "bad line %d in entry ending at line %d ignored\n",
172 elineno, elineno, 0 );
176 if ( strcasecmp( type, attr ) == 0 ) {
179 index_add_values( be, attr,
188 (*be->be_close)( be );