4 #include <sys/socket.h>
7 #define DEFAULT_CONFIGFILE "/usr/local/etc/slapd.conf"
10 extern void attr_index_config();
11 extern char *str_getline();
12 extern char *attr_normalize();
14 extern Backend *backends;
15 extern int ldap_debug;
19 int ldap_syslog_level;
20 int global_schemacheck;
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;
40 fprintf( stderr, "usage: %s -i inputfile [-d debuglevel] [-f configfile] [-n databasenumber] attr\n", name );
44 main( int argc, char **argv )
46 int i, cargc, indb, stop;
48 char *defargv[MAXARGS];
49 char *tailorfile, *inputfile;
50 char *linep, *buf, *attr;
53 int lmax, lcur, indexmask, syntaxmask;
58 struct berval *vals[2];
62 tailorfile = DEFAULT_CONFIGFILE;
64 while ( (i = getopt( argc, argv, "d:f:i:n:" )) != EOF ) {
66 case 'd': /* turn on debugging */
67 ldap_debug = atoi( optarg );
70 case 'f': /* specify a tailor file */
71 tailorfile = strdup( optarg );
74 case 'i': /* input file */
75 inputfile = strdup( optarg );
78 case 'n': /* which config file db to index */
79 dbnum = atoi( optarg ) - 1;
87 attr = attr_normalize( argv[argc - 1] );
88 if ( inputfile == NULL ) {
91 if ( freopen( inputfile, "r", stdin ) == NULL ) {
98 read_config( tailorfile, &be, NULL );
101 for ( dbnum = 0; dbnum < nbackends; dbnum++ ) {
102 if ( strcasecmp( backends[dbnum].be_type, "ldbm" )
107 if ( dbnum == nbackends ) {
108 fprintf( stderr, "No ldbm database found in config file\n" );
111 } else if ( dbnum < 1 || dbnum > nbackends ) {
112 fprintf( stderr, "Database number selected via -n is out of range\n" );
113 fprintf( stderr, "Must be in the range 1 to %d (number of databases in the config file)\n", nbackends );
115 } else if ( strcasecmp( backends[dbnum].be_type, "ldbm" ) != 0 ) {
116 fprintf( stderr, "Database number %d selected via -n is not an ldbm database\n", dbnum );
119 be = &backends[dbnum];
121 attr_masks( be->be_private, attr, &indexmask, &syntaxmask );
122 if ( indexmask == 0 ) {
134 char *type, *val, *s;
137 if ( fgets( line, sizeof(line), stdin ) != NULL ) {
141 len = strlen( line );
142 while ( lcur + len + 1 > lmax ) {
144 buf = (char *) ch_realloc( buf, lmax );
146 strcpy( buf + lcur, line );
151 if ( line[0] == '\n' || stop && buf && *buf ) {
152 if ( *buf != '\n' ) {
156 while ( (linep = str_getline( &s )) != NULL ) {
158 if ( str_parse_line( linep, &type, &val,
160 Debug( LDAP_DEBUG_PARSE,
161 "bad line %d in entry ending at line %d ignored\n",
162 elineno, elineno, 0 );
166 if ( strcasecmp( type, attr ) == 0 ) {
169 index_add_values( be, attr,
178 (*be->be_close)( be );