10 #include <ac/unistd.h>
13 #include "../back-bdb2/back-bdb2.h"
15 #include "ldap_defaults.h"
23 fprintf( stderr, "usage: %s -i inputfile [-d debuglevel] [-f configfile] [-n databasenumber] attr\n", name );
28 main( int argc, char **argv )
31 char *tailorfile, *inputfile;
32 char *linep, *buf, *attr;
35 int lmax, lcur, indexmask, syntaxmask;
41 struct berval *vals[2];
44 tailorfile = SLAPD_DEFAULT_CONFIGFILE;
46 while ( (i = getopt( argc, argv, "d:f:i:n:" )) != EOF ) {
48 case 'd': /* turn on debugging */
49 ldap_debug = atoi( optarg );
52 case 'f': /* specify a tailor file */
53 tailorfile = strdup( optarg );
56 case 'i': /* input file */
57 inputfile = strdup( optarg );
60 case 'n': /* which config file db to index */
61 dbnum = atoi( optarg ) - 1;
69 attr = attr_normalize( argv[argc - 1] );
70 if ( inputfile == NULL ) {
73 if ( freopen( inputfile, "r", stdin ) == NULL ) {
79 slap_init(SLAP_TOOL_MODE, ch_strdup(argv[0]));
80 read_config( tailorfile );
83 for ( dbnum = 0; dbnum < nbackends; dbnum++ ) {
84 if ( strcasecmp( backends[dbnum].be_type, "bdb2" )
89 if ( dbnum == nbackends ) {
90 fprintf( stderr, "No bdb2 database found in config file\n" );
93 } else if ( dbnum < 0 || dbnum > (nbackends-1) ) {
94 fprintf( stderr, "Database number selected via -n is out of range\n" );
95 fprintf( stderr, "Must be in the range 1 to %d (number of databases in the config file)\n", nbackends );
97 } else if ( strcasecmp( backends[dbnum].be_type, "bdb2" ) != 0 ) {
98 fprintf( stderr, "Database number %d selected via -n is not an bdb2 database\n", dbnum );
104 be = &backends[dbnum];
106 /* disable write sync'ing */
107 li = (struct ldbminfo *) be->be_private;
108 li->li_dbcachewsync = 0;
110 bdb2i_attr_masks( be->be_private, attr, &indexmask, &syntaxmask );
111 if ( indexmask == 0 ) {
123 char *type, *val, *s;
126 if ( fgets( line, sizeof(line), stdin ) != NULL ) {
130 len = strlen( line );
131 while ( lcur + len + 1 > lmax ) {
133 buf = (char *) ch_realloc( buf, lmax );
135 strcpy( buf + lcur, line );
140 if ( line[0] == '\n' || stop && buf && *buf ) {
141 if ( *buf != '\n' ) {
142 if (isdigit((unsigned char) *buf)) {
149 while ( (linep = ldif_getline( &s )) != NULL ) {
151 if ( ldif_parse_line( linep, &type, &val,
153 Debug( LDAP_DEBUG_PARSE,
154 "bad line %d in entry ending at line %d ignored\n",
155 elineno, elineno, 0 );
159 if ( strcasecmp( type, attr ) == 0 ) {
162 bdb2i_index_add_values( be, attr,
172 slap_shutdown(dbnum);