10 #include <ac/unistd.h>
13 #include "../back-ldbm/back-ldbm.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];
43 ldbm_ignore_nextid_file = 1;
46 tailorfile = SLAPD_DEFAULT_CONFIGFILE;
48 while ( (i = getopt( argc, argv, "d:f:i:n:" )) != EOF ) {
50 case 'd': /* turn on debugging */
51 ldap_debug = atoi( optarg );
54 case 'f': /* specify a tailor file */
55 tailorfile = strdup( optarg );
58 case 'i': /* input file */
59 inputfile = strdup( optarg );
62 case 'n': /* which config file db to index */
63 dbnum = atoi( optarg ) - 1;
71 attr = attr_normalize( argv[argc - 1] );
72 if ( inputfile == NULL ) {
75 if ( freopen( inputfile, "r", stdin ) == NULL ) {
81 slap_init(SLAP_TOOL_MODE, ch_strdup(argv[0]));
82 read_config( tailorfile );
85 for ( dbnum = 0; dbnum < nbackends; dbnum++ ) {
86 if ( strcasecmp( backends[dbnum].be_type, "ldbm" )
91 if ( dbnum == nbackends ) {
92 fprintf( stderr, "No ldbm database found in config file\n" );
95 } else if ( dbnum < 0 || dbnum > (nbackends-1) ) {
96 fprintf( stderr, "Database number selected via -n is out of range\n" );
97 fprintf( stderr, "Must be in the range 1 to %d (number of databases in the config file)\n", nbackends );
99 } else if ( strcasecmp( backends[dbnum].be_type, "ldbm" ) != 0 ) {
100 fprintf( stderr, "Database number %d selected via -n is not an ldbm database\n", dbnum );
106 be = &backends[dbnum];
108 /* disable write sync'ing */
109 li = (struct ldbminfo *) be->be_private;
110 li->li_dbcachewsync = 0;
112 attr_masks( be->be_private, attr, &indexmask, &syntaxmask );
113 if ( indexmask == 0 ) {
125 char *type, *val, *s;
128 if ( fgets( line, sizeof(line), stdin ) != NULL ) {
132 len = strlen( line );
133 while ( lcur + len + 1 > lmax ) {
135 buf = (char *) ch_realloc( buf, lmax );
137 strcpy( buf + lcur, line );
142 if ( line[0] == '\n' || stop && buf && *buf ) {
143 if ( *buf != '\n' ) {
144 if (isdigit((unsigned char) *buf)) {
151 while ( (linep = ldif_getline( &s )) != NULL ) {
153 if ( ldif_parse_line( linep, &type, &val,
155 Debug( LDAP_DEBUG_PARSE,
156 "bad line %d in entry ending at line %d ignored\n",
157 elineno, elineno, 0 );
161 if ( strcasecmp( type, attr ) == 0 ) {
164 index_change_values( be,
177 slap_shutdown(dbnum);