1998-10-25 09:41:42 +08:00
|
|
|
#include "portable.h"
|
|
|
|
|
1998-08-09 08:43:13 +08:00
|
|
|
#include <stdio.h>
|
1999-06-03 08:37:44 +08:00
|
|
|
|
|
|
|
#include <ac/stdlib.h>
|
1998-10-25 09:41:42 +08:00
|
|
|
|
1998-12-01 06:26:11 +08:00
|
|
|
#include <ac/ctype.h>
|
1998-10-25 09:41:42 +08:00
|
|
|
#include <ac/string.h>
|
|
|
|
#include <ac/socket.h>
|
1998-11-16 13:07:27 +08:00
|
|
|
#include <ac/unistd.h>
|
1998-10-25 09:41:42 +08:00
|
|
|
|
1998-08-09 08:43:13 +08:00
|
|
|
#include "../slap.h"
|
Protoized, moved extern definitions to .h files, fixed related bugs.
Most function and variable definitions are now preceded by its extern
definition, for error checking. Retyped a number of functions, usually
to return void. Fixed a number of printf format errors.
API changes (in ldap/include):
Added avl_dup_ok, avl_prefixapply, removed ber_fatten (probably typo
for ber_flatten), retyped ldap_sort_strcasecmp, grew lutil.h.
A number of `extern' declarations are left (some added by protoize), to
be cleaned away later. Mostly strdup(), strcasecmp(), mktemp(), optind,
optarg, errno.
1998-11-16 06:40:11 +08:00
|
|
|
#include "../back-ldbm/back-ldbm.h"
|
1998-08-09 08:43:13 +08:00
|
|
|
|
1998-09-17 11:38:36 +08:00
|
|
|
#include "ldapconfig.h"
|
1998-11-13 04:17:01 +08:00
|
|
|
#include "ldif.h"
|
1998-09-17 11:38:36 +08:00
|
|
|
|
1998-08-09 08:43:13 +08:00
|
|
|
#define MAXARGS 100
|
|
|
|
|
|
|
|
static void
|
|
|
|
usage( char *name )
|
|
|
|
{
|
|
|
|
fprintf( stderr, "usage: %s -i inputfile [-d debuglevel] [-f configfile] [-n databasenumber] attr\n", name );
|
|
|
|
exit( 1 );
|
|
|
|
}
|
|
|
|
|
Protoized, moved extern definitions to .h files, fixed related bugs.
Most function and variable definitions are now preceded by its extern
definition, for error checking. Retyped a number of functions, usually
to return void. Fixed a number of printf format errors.
API changes (in ldap/include):
Added avl_dup_ok, avl_prefixapply, removed ber_fatten (probably typo
for ber_flatten), retyped ldap_sort_strcasecmp, grew lutil.h.
A number of `extern' declarations are left (some added by protoize), to
be cleaned away later. Mostly strdup(), strcasecmp(), mktemp(), optind,
optarg, errno.
1998-11-16 06:40:11 +08:00
|
|
|
int
|
1998-08-09 08:43:13 +08:00
|
|
|
main( int argc, char **argv )
|
|
|
|
{
|
1999-03-06 14:33:34 +08:00
|
|
|
int i, stop;
|
1998-08-09 08:43:13 +08:00
|
|
|
char *tailorfile, *inputfile;
|
|
|
|
char *linep, *buf, *attr;
|
|
|
|
char line[BUFSIZ];
|
|
|
|
int lineno, elineno;
|
|
|
|
int lmax, lcur, indexmask, syntaxmask;
|
|
|
|
int dbnum;
|
|
|
|
unsigned long id;
|
1998-08-18 05:10:02 +08:00
|
|
|
Backend *be = NULL;
|
1998-12-19 06:21:16 +08:00
|
|
|
struct ldbminfo *li;
|
1998-08-09 08:43:13 +08:00
|
|
|
struct berval bv;
|
|
|
|
struct berval *vals[2];
|
|
|
|
|
1999-04-30 13:24:16 +08:00
|
|
|
ldbm_ignore_nextid_file = 1;
|
|
|
|
|
1998-08-09 08:43:13 +08:00
|
|
|
inputfile = NULL;
|
1998-09-17 11:38:36 +08:00
|
|
|
tailorfile = SLAPD_DEFAULT_CONFIGFILE;
|
1998-08-09 08:43:13 +08:00
|
|
|
dbnum = -1;
|
|
|
|
while ( (i = getopt( argc, argv, "d:f:i:n:" )) != EOF ) {
|
|
|
|
switch ( i ) {
|
|
|
|
case 'd': /* turn on debugging */
|
|
|
|
ldap_debug = atoi( optarg );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'f': /* specify a tailor file */
|
|
|
|
tailorfile = strdup( optarg );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'i': /* input file */
|
|
|
|
inputfile = strdup( optarg );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'n': /* which config file db to index */
|
|
|
|
dbnum = atoi( optarg ) - 1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
usage( argv[0] );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
attr = attr_normalize( argv[argc - 1] );
|
|
|
|
if ( inputfile == NULL ) {
|
|
|
|
usage( argv[0] );
|
|
|
|
} else {
|
|
|
|
if ( freopen( inputfile, "r", stdin ) == NULL ) {
|
|
|
|
perror( inputfile );
|
|
|
|
exit( 1 );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-02-05 17:03:47 +08:00
|
|
|
slap_init(SLAP_TOOL_MODE, ch_strdup(argv[0]));
|
|
|
|
read_config( tailorfile );
|
1998-08-09 08:43:13 +08:00
|
|
|
|
|
|
|
if ( dbnum == -1 ) {
|
|
|
|
for ( dbnum = 0; dbnum < nbackends; dbnum++ ) {
|
|
|
|
if ( strcasecmp( backends[dbnum].be_type, "ldbm" )
|
|
|
|
== 0 ) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ( dbnum == nbackends ) {
|
|
|
|
fprintf( stderr, "No ldbm database found in config file\n" );
|
|
|
|
exit( 1 );
|
|
|
|
}
|
1998-08-09 10:33:01 +08:00
|
|
|
} else if ( dbnum < 0 || dbnum > (nbackends-1) ) {
|
1998-08-09 08:43:13 +08:00
|
|
|
fprintf( stderr, "Database number selected via -n is out of range\n" );
|
|
|
|
fprintf( stderr, "Must be in the range 1 to %d (number of databases in the config file)\n", nbackends );
|
|
|
|
exit( 1 );
|
|
|
|
} else if ( strcasecmp( backends[dbnum].be_type, "ldbm" ) != 0 ) {
|
|
|
|
fprintf( stderr, "Database number %d selected via -n is not an ldbm database\n", dbnum );
|
|
|
|
exit( 1 );
|
|
|
|
}
|
1999-02-05 17:03:47 +08:00
|
|
|
|
|
|
|
slap_startup(dbnum);
|
|
|
|
|
1998-08-09 08:43:13 +08:00
|
|
|
be = &backends[dbnum];
|
|
|
|
|
1998-12-19 06:21:16 +08:00
|
|
|
/* disable write sync'ing */
|
|
|
|
li = (struct ldbminfo *) be->be_private;
|
|
|
|
li->li_dbcachewsync = 0;
|
|
|
|
|
1998-08-09 08:43:13 +08:00
|
|
|
attr_masks( be->be_private, attr, &indexmask, &syntaxmask );
|
|
|
|
if ( indexmask == 0 ) {
|
|
|
|
exit( 0 );
|
|
|
|
}
|
|
|
|
|
|
|
|
id = 0;
|
|
|
|
stop = 0;
|
|
|
|
lineno = 0;
|
|
|
|
buf = NULL;
|
|
|
|
lcur = lmax = 0;
|
|
|
|
vals[0] = &bv;
|
|
|
|
vals[1] = NULL;
|
|
|
|
while ( ! stop ) {
|
|
|
|
char *type, *val, *s;
|
|
|
|
int vlen;
|
|
|
|
|
|
|
|
if ( fgets( line, sizeof(line), stdin ) != NULL ) {
|
|
|
|
int len;
|
|
|
|
|
|
|
|
lineno++;
|
|
|
|
len = strlen( line );
|
|
|
|
while ( lcur + len + 1 > lmax ) {
|
|
|
|
lmax += BUFSIZ;
|
|
|
|
buf = (char *) ch_realloc( buf, lmax );
|
|
|
|
}
|
|
|
|
strcpy( buf + lcur, line );
|
|
|
|
lcur += len;
|
|
|
|
} else {
|
|
|
|
stop = 1;
|
|
|
|
}
|
|
|
|
if ( line[0] == '\n' || stop && buf && *buf ) {
|
|
|
|
if ( *buf != '\n' ) {
|
1999-02-23 01:57:22 +08:00
|
|
|
if (isdigit((unsigned char) *buf)) {
|
1998-12-01 06:26:11 +08:00
|
|
|
id = atol(buf);
|
|
|
|
} else {
|
|
|
|
id++;
|
|
|
|
}
|
1998-08-09 08:43:13 +08:00
|
|
|
s = buf;
|
|
|
|
elineno = 0;
|
1998-12-21 06:28:33 +08:00
|
|
|
while ( (linep = ldif_getline( &s )) != NULL ) {
|
1998-08-09 08:43:13 +08:00
|
|
|
elineno++;
|
1998-12-21 06:28:33 +08:00
|
|
|
if ( ldif_parse_line( linep, &type, &val,
|
1998-08-09 08:43:13 +08:00
|
|
|
&vlen ) != 0 ) {
|
|
|
|
Debug( LDAP_DEBUG_PARSE,
|
|
|
|
"bad line %d in entry ending at line %d ignored\n",
|
|
|
|
elineno, elineno, 0 );
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( strcasecmp( type, attr ) == 0 ) {
|
|
|
|
bv.bv_val = val;
|
|
|
|
bv.bv_len = vlen;
|
|
|
|
index_add_values( be, attr,
|
|
|
|
vals, id );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*buf = '\0';
|
|
|
|
lcur = 0;
|
|
|
|
}
|
|
|
|
}
|
1999-02-05 17:03:47 +08:00
|
|
|
|
|
|
|
slap_shutdown(dbnum);
|
|
|
|
slap_destroy();
|
1998-08-09 08:43:13 +08:00
|
|
|
|
1999-04-14 22:10:09 +08:00
|
|
|
return( 0 );
|
1998-08-09 08:43:13 +08:00
|
|
|
}
|