10 #include "ldapconfig.h"
15 extern void attr_index_config();
16 extern char *attr_normalize();
18 extern Backend *backends;
19 extern int ldap_debug;
23 int ldap_syslog_level;
24 int global_schemacheck;
28 char *default_referral;
29 struct objclass *global_oc;
31 pthread_t listener_tid;
32 pthread_mutex_t num_sent_mutex;
33 pthread_mutex_t entry2str_mutex;
34 pthread_mutex_t active_threads_mutex;
35 pthread_mutex_t new_conn_mutex;
36 pthread_mutex_t currenttime_mutex;
37 pthread_mutex_t replog_mutex;
38 pthread_mutex_t ops_mutex;
39 pthread_mutex_t regex_mutex;
44 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];
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 attr_masks( be->be_private, attr, &indexmask, &syntaxmask );
126 if ( indexmask == 0 ) {
138 char *type, *val, *s;
141 if ( fgets( line, sizeof(line), stdin ) != NULL ) {
145 len = strlen( line );
146 while ( lcur + len + 1 > lmax ) {
148 buf = (char *) ch_realloc( buf, lmax );
150 strcpy( buf + lcur, line );
155 if ( line[0] == '\n' || stop && buf && *buf ) {
156 if ( *buf != '\n' ) {
160 while ( (linep = str_getline( &s )) != NULL ) {
162 if ( str_parse_line( linep, &type, &val,
164 Debug( LDAP_DEBUG_PARSE,
165 "bad line %d in entry ending at line %d ignored\n",
166 elineno, elineno, 0 );
170 if ( strcasecmp( type, attr ) == 0 ) {
173 index_add_values( be, attr,
182 (*be->be_close)( be );