X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=servers%2Fslapd%2Ftools%2Fldif2index-bdb2.c;h=b0d010b45657ac63b85355c5f22acc17a107d952;hb=bc73fffe127e2b264669a26ee8a6033cbdf59dd3;hp=1c7f5331b221e806f18cd1fc11641297a62244b3;hpb=42f6e78dd4e2d481c1bc75b8bc6d38fe9c62bc07;p=openldap diff --git a/servers/slapd/tools/ldif2index-bdb2.c b/servers/slapd/tools/ldif2index-bdb2.c index 1c7f5331b2..b0d010b456 100644 --- a/servers/slapd/tools/ldif2index-bdb2.c +++ b/servers/slapd/tools/ldif2index-bdb2.c @@ -1,104 +1,34 @@ #include "portable.h" #include -#include + +#include #include #include #include #include -#include "../slap.h" +#include "ldif2common.h" #include "../back-bdb2/back-bdb2.h" - -#include "ldapconfig.h" #include "ldif.h" -#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 ); -} - int main( int argc, char **argv ) { - int i, cargc, indb, stop; - char *cargv[MAXARGS]; - char *defargv[MAXARGS]; - char *tailorfile, *inputfile; + int i, stop; char *linep, *buf, *attr; char line[BUFSIZ]; int lineno, elineno; int lmax, lcur, indexmask, syntaxmask; - int dbnum; unsigned long id; Backend *be = NULL; struct ldbminfo *li; struct berval bv; struct berval *vals[2]; - inputfile = NULL; - tailorfile = SLAPD_DEFAULT_CONFIGFILE; - 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; - } - } + slap_ldif_init( argc, argv, LDIF2INDEX, "bdb2", SLAP_TOOL_MODE ); attr = attr_normalize( argv[argc - 1] ); - if ( inputfile == NULL ) { - usage( argv[0] ); - } else { - if ( freopen( inputfile, "r", stdin ) == NULL ) { - perror( inputfile ); - exit( 1 ); - } - } - - slap_init(SLAP_TOOL_MODE, ch_strdup(argv[0])); - read_config( tailorfile ); - - if ( dbnum == -1 ) { - for ( dbnum = 0; dbnum < nbackends; dbnum++ ) { - if ( strcasecmp( backends[dbnum].be_type, "bdb2" ) - == 0 ) { - break; - } - } - if ( dbnum == nbackends ) { - fprintf( stderr, "No bdb2 database found in config file\n" ); - exit( 1 ); - } - } else if ( dbnum < 0 || dbnum > (nbackends-1) ) { - 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, "bdb2" ) != 0 ) { - fprintf( stderr, "Database number %d selected via -n is not an bdb2 database\n", dbnum ); - exit( 1 ); - } slap_startup(dbnum); @@ -108,9 +38,9 @@ main( int argc, char **argv ) li = (struct ldbminfo *) be->be_private; li->li_dbcachewsync = 0; - attr_masks( be->be_private, attr, &indexmask, &syntaxmask ); + bdb2i_attr_masks( be->be_private, attr, &indexmask, &syntaxmask ); if ( indexmask == 0 ) { - exit( 0 ); + exit( EXIT_SUCCESS ); } id = 0; @@ -122,7 +52,7 @@ main( int argc, char **argv ) vals[1] = NULL; while ( ! stop ) { char *type, *val, *s; - int vlen; + ber_len_t vlen; if ( fgets( line, sizeof(line), stdin ) != NULL ) { int len; @@ -140,7 +70,7 @@ main( int argc, char **argv ) } if ( line[0] == '\n' || stop && buf && *buf ) { if ( *buf != '\n' ) { - if (isdigit(*buf)) { + if (isdigit((unsigned char) *buf)) { id = atol(buf); } else { id++; @@ -160,7 +90,7 @@ main( int argc, char **argv ) if ( strcasecmp( type, attr ) == 0 ) { bv.bv_val = val; bv.bv_len = vlen; - index_add_values( be, attr, + bdb2i_index_add_values( be, attr, vals, id ); } } @@ -173,5 +103,5 @@ main( int argc, char **argv ) slap_shutdown(dbnum); slap_destroy(); - exit( 0 ); + exit( EXIT_SUCCESS ); }