12 #include "../back-bdb2/back-bdb2.h"
14 #include "ldapconfig.h"
22 fprintf( stderr, "usage: %s -i inputfile [-d debuglevel] [-f configfile] [-n databasenumber] attr\n", name );
27 main( int argc, char **argv )
29 int i, cargc, indb, stop;
31 char *defargv[MAXARGS];
32 char *tailorfile, *inputfile;
33 char *linep, *buf, *attr;
36 int lmax, lcur, indexmask, syntaxmask;
42 struct berval *vals[2];
45 tailorfile = SLAPD_DEFAULT_CONFIGFILE;
47 while ( (i = getopt( argc, argv, "d:f:i:n:" )) != EOF ) {
49 case 'd': /* turn on debugging */
50 ldap_debug = atoi( optarg );
53 case 'f': /* specify a tailor file */
54 tailorfile = strdup( optarg );
57 case 'i': /* input file */
58 inputfile = strdup( optarg );
61 case 'n': /* which config file db to index */
62 dbnum = atoi( optarg ) - 1;
70 attr = attr_normalize( argv[argc - 1] );
71 if ( inputfile == NULL ) {
74 if ( freopen( inputfile, "r", stdin ) == NULL ) {
80 slap_init(SLAP_TOOL_MODE, ch_strdup(argv[0]));
81 read_config( tailorfile );
84 for ( dbnum = 0; dbnum < nbackends; dbnum++ ) {
85 if ( strcasecmp( backends[dbnum].be_type, "bdb2" )
90 if ( dbnum == nbackends ) {
91 fprintf( stderr, "No bdb2 database found in config file\n" );
94 } else if ( dbnum < 0 || dbnum > (nbackends-1) ) {
95 fprintf( stderr, "Database number selected via -n is out of range\n" );
96 fprintf( stderr, "Must be in the range 1 to %d (number of databases in the config file)\n", nbackends );
98 } else if ( strcasecmp( backends[dbnum].be_type, "bdb2" ) != 0 ) {
99 fprintf( stderr, "Database number %d selected via -n is not an bdb2 database\n", dbnum );
105 be = &backends[dbnum];
107 /* disable write sync'ing */
108 li = (struct ldbminfo *) be->be_private;
109 li->li_dbcachewsync = 0;
111 bdb2i_attr_masks( be->be_private, attr, &indexmask, &syntaxmask );
112 if ( indexmask == 0 ) {
124 char *type, *val, *s;
127 if ( fgets( line, sizeof(line), stdin ) != NULL ) {
131 len = strlen( line );
132 while ( lcur + len + 1 > lmax ) {
134 buf = (char *) ch_realloc( buf, lmax );
136 strcpy( buf + lcur, line );
141 if ( line[0] == '\n' || stop && buf && *buf ) {
142 if ( *buf != '\n' ) {
150 while ( (linep = ldif_getline( &s )) != NULL ) {
152 if ( ldif_parse_line( linep, &type, &val,
154 Debug( LDAP_DEBUG_PARSE,
155 "bad line %d in entry ending at line %d ignored\n",
156 elineno, elineno, 0 );
160 if ( strcasecmp( type, attr ) == 0 ) {
163 bdb2i_index_add_values( be, attr,
173 slap_shutdown(dbnum);