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 )
30 char *tailorfile, *inputfile;
31 char *linep, *buf, *attr;
34 int lmax, lcur, indexmask, syntaxmask;
40 struct berval *vals[2];
43 tailorfile = SLAPD_DEFAULT_CONFIGFILE;
45 while ( (i = getopt( argc, argv, "d:f:i:n:" )) != EOF ) {
47 case 'd': /* turn on debugging */
48 ldap_debug = atoi( optarg );
51 case 'f': /* specify a tailor file */
52 tailorfile = strdup( optarg );
55 case 'i': /* input file */
56 inputfile = strdup( optarg );
59 case 'n': /* which config file db to index */
60 dbnum = atoi( optarg ) - 1;
68 attr = attr_normalize( argv[argc - 1] );
69 if ( inputfile == NULL ) {
72 if ( freopen( inputfile, "r", stdin ) == NULL ) {
78 slap_init(SLAP_TOOL_MODE, ch_strdup(argv[0]));
79 read_config( tailorfile );
82 for ( dbnum = 0; dbnum < nbackends; dbnum++ ) {
83 if ( strcasecmp( backends[dbnum].be_type, "ldbm" )
88 if ( dbnum == nbackends ) {
89 fprintf( stderr, "No ldbm database found in config file\n" );
92 } else if ( dbnum < 0 || dbnum > (nbackends-1) ) {
93 fprintf( stderr, "Database number selected via -n is out of range\n" );
94 fprintf( stderr, "Must be in the range 1 to %d (number of databases in the config file)\n", nbackends );
96 } else if ( strcasecmp( backends[dbnum].be_type, "ldbm" ) != 0 ) {
97 fprintf( stderr, "Database number %d selected via -n is not an ldbm database\n", dbnum );
103 be = &backends[dbnum];
105 /* disable write sync'ing */
106 li = (struct ldbminfo *) be->be_private;
107 li->li_dbcachewsync = 0;
109 attr_masks( be->be_private, attr, &indexmask, &syntaxmask );
110 if ( indexmask == 0 ) {
122 char *type, *val, *s;
125 if ( fgets( line, sizeof(line), stdin ) != NULL ) {
129 len = strlen( line );
130 while ( lcur + len + 1 > lmax ) {
132 buf = (char *) ch_realloc( buf, lmax );
134 strcpy( buf + lcur, line );
139 if ( line[0] == '\n' || stop && buf && *buf ) {
140 if ( *buf != '\n' ) {
141 if (isdigit((unsigned char) *buf)) {
148 while ( (linep = ldif_getline( &s )) != NULL ) {
150 if ( ldif_parse_line( linep, &type, &val,
152 Debug( LDAP_DEBUG_PARSE,
153 "bad line %d in entry ending at line %d ignored\n",
154 elineno, elineno, 0 );
158 if ( strcasecmp( type, attr ) == 0 ) {
161 index_add_values( be, attr,
171 slap_shutdown(dbnum);