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 strtok_mutex;
34 pthread_mutex_t replog_mutex;
35 pthread_mutex_t ops_mutex;
36 pthread_mutex_t regex_mutex;
38 pthread_mutex_t crypt_mutex;
45 fprintf( stderr, "usage: %s -i inputfile [-d debuglevel] [-f configfile] [-n databasenumber] attr\n", name );
50 main( int argc, char **argv )
52 int i, cargc, indb, stop;
54 char *defargv[MAXARGS];
55 char *tailorfile, *inputfile;
56 char *linep, *buf, *attr;
59 int lmax, lcur, indexmask, syntaxmask;
65 struct berval *vals[2];
68 tailorfile = SLAPD_DEFAULT_CONFIGFILE;
70 while ( (i = getopt( argc, argv, "d:f:i:n:" )) != EOF ) {
72 case 'd': /* turn on debugging */
73 ldap_debug = atoi( optarg );
76 case 'f': /* specify a tailor file */
77 tailorfile = strdup( optarg );
80 case 'i': /* input file */
81 inputfile = strdup( optarg );
84 case 'n': /* which config file db to index */
85 dbnum = atoi( optarg ) - 1;
93 attr = attr_normalize( argv[argc - 1] );
94 if ( inputfile == NULL ) {
97 if ( freopen( inputfile, "r", stdin ) == NULL ) {
104 read_config( tailorfile, &be, NULL );
107 for ( dbnum = 0; dbnum < nbackends; dbnum++ ) {
108 if ( strcasecmp( backends[dbnum].be_type, "ldbm" )
113 if ( dbnum == nbackends ) {
114 fprintf( stderr, "No ldbm database found in config file\n" );
117 } else if ( dbnum < 0 || dbnum > (nbackends-1) ) {
118 fprintf( stderr, "Database number selected via -n is out of range\n" );
119 fprintf( stderr, "Must be in the range 1 to %d (number of databases in the config file)\n", nbackends );
121 } else if ( strcasecmp( backends[dbnum].be_type, "ldbm" ) != 0 ) {
122 fprintf( stderr, "Database number %d selected via -n is not an ldbm database\n", dbnum );
125 be = &backends[dbnum];
127 /* disable write sync'ing */
128 li = (struct ldbminfo *) be->be_private;
129 li->li_dbcachewsync = 0;
131 attr_masks( be->be_private, attr, &indexmask, &syntaxmask );
132 if ( indexmask == 0 ) {
144 char *type, *val, *s;
147 if ( fgets( line, sizeof(line), stdin ) != NULL ) {
151 len = strlen( line );
152 while ( lcur + len + 1 > lmax ) {
154 buf = (char *) ch_realloc( buf, lmax );
156 strcpy( buf + lcur, line );
161 if ( line[0] == '\n' || stop && buf && *buf ) {
162 if ( *buf != '\n' ) {
170 while ( (linep = ldif_getline( &s )) != NULL ) {
172 if ( ldif_parse_line( linep, &type, &val,
174 Debug( LDAP_DEBUG_PARSE,
175 "bad line %d in entry ending at line %d ignored\n",
176 elineno, elineno, 0 );
180 if ( strcasecmp( type, attr ) == 0 ) {
183 index_add_values( be, attr,
192 (*be->be_close)( be );