10 #include "../back-ldbm/back-ldbm.h"
12 #include "ldapconfig.h"
19 int ldap_syslog_level;
20 int global_schemacheck;
21 long num_entries_sent;
24 char *default_referral;
25 struct objclass *global_oc;
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;
60 struct berval *vals[2];
63 tailorfile = SLAPD_DEFAULT_CONFIGFILE;
65 while ( (i = getopt( argc, argv, "d:f:i:n:" )) != EOF ) {
67 case 'd': /* turn on debugging */
68 ldap_debug = atoi( optarg );
71 case 'f': /* specify a tailor file */
72 tailorfile = strdup( optarg );
75 case 'i': /* input file */
76 inputfile = strdup( optarg );
79 case 'n': /* which config file db to index */
80 dbnum = atoi( optarg ) - 1;
88 attr = attr_normalize( argv[argc - 1] );
89 if ( inputfile == NULL ) {
92 if ( freopen( inputfile, "r", stdin ) == NULL ) {
99 read_config( tailorfile, &be, NULL );
102 for ( dbnum = 0; dbnum < nbackends; dbnum++ ) {
103 if ( strcasecmp( backends[dbnum].be_type, "ldbm" )
108 if ( dbnum == nbackends ) {
109 fprintf( stderr, "No ldbm database found in config file\n" );
112 } else if ( dbnum < 0 || dbnum > (nbackends-1) ) {
113 fprintf( stderr, "Database number selected via -n is out of range\n" );
114 fprintf( stderr, "Must be in the range 1 to %d (number of databases in the config file)\n", nbackends );
116 } else if ( strcasecmp( backends[dbnum].be_type, "ldbm" ) != 0 ) {
117 fprintf( stderr, "Database number %d selected via -n is not an ldbm database\n", dbnum );
120 be = &backends[dbnum];
122 attr_masks( be->be_private, attr, &indexmask, &syntaxmask );
123 if ( indexmask == 0 ) {
135 char *type, *val, *s;
138 if ( fgets( line, sizeof(line), stdin ) != NULL ) {
142 len = strlen( line );
143 while ( lcur + len + 1 > lmax ) {
145 buf = (char *) ch_realloc( buf, lmax );
147 strcpy( buf + lcur, line );
152 if ( line[0] == '\n' || stop && buf && *buf ) {
153 if ( *buf != '\n' ) {
157 while ( (linep = str_getline( &s )) != NULL ) {
159 if ( str_parse_line( linep, &type, &val,
161 Debug( LDAP_DEBUG_PARSE,
162 "bad line %d in entry ending at line %d ignored\n",
163 elineno, elineno, 0 );
167 if ( strcasecmp( type, attr ) == 0 ) {
170 index_add_values( be, attr,
179 (*be->be_close)( be );