12 #include "../back-ldbm/back-ldbm.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 ) {
81 read_config( tailorfile, &be, NULL );
84 for ( dbnum = 0; dbnum < nbackends; dbnum++ ) {
85 if ( strcasecmp( backends[dbnum].be_type, "ldbm" )
90 if ( dbnum == nbackends ) {
91 fprintf( stderr, "No ldbm 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, "ldbm" ) != 0 ) {
99 fprintf( stderr, "Database number %d selected via -n is not an ldbm database\n", dbnum );
102 be = &backends[dbnum];
104 /* disable write sync'ing */
105 li = (struct ldbminfo *) be->be_private;
106 li->li_dbcachewsync = 0;
108 attr_masks( be->be_private, attr, &indexmask, &syntaxmask );
109 if ( indexmask == 0 ) {
121 char *type, *val, *s;
124 if ( fgets( line, sizeof(line), stdin ) != NULL ) {
128 len = strlen( line );
129 while ( lcur + len + 1 > lmax ) {
131 buf = (char *) ch_realloc( buf, lmax );
133 strcpy( buf + lcur, line );
138 if ( line[0] == '\n' || stop && buf && *buf ) {
139 if ( *buf != '\n' ) {
147 while ( (linep = ldif_getline( &s )) != NULL ) {
149 if ( ldif_parse_line( linep, &type, &val,
151 Debug( LDAP_DEBUG_PARSE,
152 "bad line %d in entry ending at line %d ignored\n",
153 elineno, elineno, 0 );
157 if ( strcasecmp( type, attr ) == 0 ) {
160 index_add_values( be, attr,
169 (*be->be_close)( be );