SRCS = centipede.c ldbmcat.c ldbmtest.c sizecount.c \
ldif.c ldif2id2children.c ldif2id2entry.c ldif2index.c ldif2ldbm.c \
- mimic.c
+ mimic.c ldif2common.c
SRCS2 = ldif2id2children-bdb2.c ldif2id2entry-bdb2.c \
ldif2index-bdb2.c ldif2ldbm-bdb2.c
EDB2LDIFSRCS = edb2ldif.c ldapsyntax.c
EDB2LDIFOBJS = edb2ldif.o ldapsyntax.o
-OBJS2 = mimic.o \
+OBJS1 = mimic.o \
../config.o ../ch_malloc.o ../backend.o ../charray.o \
../module.o ../aclparse.o ../schema.o ../filterentry.o \
../acl.o ../phonetic.o ../attr.o ../value.o ../entry.o \
../dn.o ../filter.o ../str2filter.o ../ava.o ../init.o \
../controls.o ../schemaparse.o
+OBJS2 = $(OBJS1) ldif2common.o
all-local: build-ldbm build-bdb2 build-edb2ldif build-chlog2replog
sizecount: sizecount.o ../phonetic.o ../ch_malloc.o $(SLAPD_LIBDEPEND)
$(LTLINK) -o $@ sizecount.o ../phonetic.o ../ch_malloc.o $(LIBS)
-ldbmtest: ldbmtest.o ../libbackends.a $(OBJS2) $(SLAPD_LIBDEPEND)
- $(LTLINK) -o ldbmtest ldbmtest.o $(OBJS2) ../libbackends.a $(LIBS)
+ldbmtest: ldbmtest.o ../libbackends.a $(OBJS1) $(SLAPD_LIBDEPEND)
+ $(LTLINK) -o ldbmtest ldbmtest.o $(OBJS1) ../libbackends.a $(LIBS)
clean-local: FORCE
$(RM) $(PROGRAMS) $(PROGRAMS2) $(XPROGRAMS) $(XSRCS) edb2-vers.c \
--- /dev/null
+/* ldif2common.c - common definitions for the ldif2* tools */
+
+#include "portable.h"
+
+#include <stdio.h>
+
+#include <ac/stdlib.h>
+#include <ac/ctype.h>
+#include <ac/string.h>
+#include <ac/socket.h>
+#include <ac/unistd.h>
+
+#include "ldif2common.h"
+
+
+char *progname;
+char *tailorfile = SLAPD_DEFAULT_CONFIGFILE;
+char *inputfile = NULL;
+char *sbindir = LDAP_SBINDIR; /* used by ldif2ldbm */
+int cmdkids = 1; /* used by ldif2ldbm */
+int dbnum;
+
+
+static void
+usage( int tool )
+{
+ fprintf( stderr, "usage: %s %s\n\t%s%s\n",
+ progname, "-i inputfile [-d debuglevel] [-f configfile]",
+ "[-n databasenumber]",
+ ((tool == LDIF2LDBM) ? " [-j #jobs] [-s sbindir]" :
+ (tool == LDIF2INDEX) ? " attr" :
+ "") );
+ exit( EXIT_FAILURE );
+}
+
+
+/*
+ * slap_ldif_init - initialize ldif utility, handle program options.
+ * args: tool - which ldif2* program is running.
+ * argc, argv - from main.
+ * dbtype - "ldbm"/"bdb2".
+ * options - to getopt.
+ */
+
+void
+slap_ldif_init( int argc, char **argv, int tool, const char *dbtype, int mode )
+{
+ char *options = (tool == LDIF2LDBM ? "e:s:j:d:f:i:n:" : "d:f:i:n:");
+ int rc, i;
+
+ progname = strrchr ( argv[0], '/' );
+ progname = ch_strdup( progname ? progname + 1 : argv[0] );
+
+ inputfile = NULL;
+ tailorfile = SLAPD_DEFAULT_CONFIGFILE;
+ dbnum = -1;
+ while ( (i = getopt( argc, argv, options )) != EOF ) {
+ switch ( i ) {
+ case 'd': /* turn on debugging */
+ ldap_debug = atoi( optarg );
+ break;
+
+ case 's': /* alternate sbindir (index cmd location) */
+ case 'e': /* accept -e for backwards compatibility */
+ /* only used by ldif2ldbm and ldif2ldbm-bdb2 */
+ sbindir = strdup( optarg );
+ break;
+
+ case 'f': /* specify a tailor file */
+ tailorfile = strdup( optarg );
+ break;
+
+ case 'i': /* input file */
+ inputfile = strdup( optarg );
+ break;
+
+ case 'j': /* number of parallel index procs */
+ /* only in ldif2ldbm and ldif2ldbm-bdb2 */
+ cmdkids = atoi( optarg );
+ break;
+
+ case 'n': /* which config file db to index */
+ dbnum = atoi( optarg ) - 1;
+ break;
+
+ default:
+ usage( tool );
+ break;
+ }
+ }
+ if ( inputfile == NULL || (argc != optind + (tool == LDIF2INDEX)) )
+ usage( tool );
+
+ if ( freopen( inputfile, "r", stdin ) == NULL ) {
+ perror( inputfile );
+ exit( EXIT_FAILURE );
+ }
+
+ /*
+ * initialize stuff and figure out which backend we're dealing with
+ */
+
+ rc = slap_init( mode, progname );
+ if (rc != 0 ) {
+ fprintf( stderr, "%s: slap_init failed!\n", progname );
+ exit( EXIT_FAILURE );
+ }
+
+ read_config( tailorfile );
+
+ if ( dbnum == -1 ) {
+ for ( dbnum = 0; dbnum < nbackends; dbnum++ ) {
+ if ( strcasecmp( backends[dbnum].be_type, dbtype )
+ == 0 ) {
+ break;
+ }
+ }
+ if ( dbnum == nbackends ) {
+ fprintf( stderr, "No %s database found in config file\n", dbtype );
+ exit( EXIT_FAILURE );
+ }
+ } 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( EXIT_FAILURE );
+ } else if ( strcasecmp( backends[dbnum].be_type, dbtype ) != 0 ) {
+ fprintf( stderr, "Database number %d selected via -n is not an %s database\n", dbnum, dbtype );
+ exit( EXIT_FAILURE );
+ }
+}
--- /dev/null
+/* ldif2common.h - common definitions for the ldif2* tools */
+
+#ifndef LDIF2COMMON_H_
+#define LDIF2COMMON_H_
+
+#include "ldap_defaults.h"
+#include "../slap.h"
+
+enum ldiftool {
+ LDIF2LDBM = 1, LDIF2INDEX, LDIF2ID2ENTRY, LDIF2ID2CHILDREN
+};
+
+
+extern char *progname;
+extern char *tailorfile;
+extern char *inputfile;
+extern char *sbindir;
+extern int cmdkids;
+extern int dbnum;
+
+
+void slap_ldif_init LDAP_P(( int, char **, int, const char *, int ));
+
+#endif /* LDIF2COMMON_H_ */
#include <ac/socket.h>
#include <ac/unistd.h>
-#include "ldap_defaults.h"
-#include "../slap.h"
+#include "ldif2common.h"
#include "../back-bdb2/back-bdb2.h"
-
#include "ldif.h"
-#define MAXARGS 100
-
-static char *tailorfile;
-static char *inputfile;
-
-static void
-usage( char *name )
-{
- fprintf( stderr, "usage: %s -i inputfile [-d debuglevel] [-f configfile] [-n databasenumber]\n", name );
- exit( EXIT_FAILURE );
-}
-
int
main( int argc, char **argv )
{
char line[BUFSIZ];
int lineno, elineno;
int lmax, lcur;
- int dbnum;
ID id;
struct dbcache *db, *db2;
Backend *be = NULL;
struct berval bv;
struct berval *vals[2];
- 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;
- }
- }
- if ( inputfile == NULL ) {
- usage( argv[0] );
- } else {
- if ( freopen( inputfile, "r", stdin ) == NULL ) {
- perror( inputfile );
- exit( EXIT_FAILURE );
- }
- }
-
- /*
- * initialize stuff and figure out which backend we're dealing with
- */
-
- slap_init(SLAP_TOOL_MODE, "ldif2id2children");
- 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( EXIT_FAILURE );
- }
- } 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( EXIT_FAILURE );
- } 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( EXIT_FAILURE );
- }
+ slap_ldif_init( argc, argv, LDIF2ID2CHILDREN, "bdb2", SLAP_TOOL_MODE );
slap_startup(dbnum);
be = &backends[dbnum];
#include <ac/socket.h>
#include <ac/unistd.h>
-#include "ldap_defaults.h"
-#include "../slap.h"
+#include "ldif2common.h"
#include "../back-ldbm/back-ldbm.h"
-
#include "ldif.h"
-#define MAXARGS 100
-
-static char *tailorfile;
-static char *inputfile;
-
-static void
-usage( char *name )
-{
- fprintf( stderr, "usage: %s -i inputfile [-d debuglevel] [-f configfile] [-n databasenumber]\n", name );
- exit( EXIT_FAILURE );
-}
-
int
main( int argc, char **argv )
{
char line[BUFSIZ];
int lineno, elineno;
int lmax, lcur;
- int dbnum;
ID id;
DBCache *db, *db2;
Backend *be = NULL;
ldbm_ignore_nextid_file = 1;
- 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;
- }
- }
- if ( inputfile == NULL ) {
- usage( argv[0] );
- } else {
- if ( freopen( inputfile, "r", stdin ) == NULL ) {
- perror( inputfile );
- exit( EXIT_FAILURE );
- }
- }
-
- /*
- * initialize stuff and figure out which backend we're dealing with
- */
-
- slap_init(SLAP_TOOL_MODE, "ldif2id2children");
- read_config( tailorfile );
-
- 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( EXIT_FAILURE );
- }
- } 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( EXIT_FAILURE );
- } 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( EXIT_FAILURE );
- }
+ slap_ldif_init( argc, argv, LDIF2ID2CHILDREN, "ldbm", SLAP_TOOL_MODE );
slap_startup(dbnum);
be = &backends[dbnum];
#include <ac/socket.h>
#include <ac/unistd.h>
-#include "ldap_defaults.h"
-#include "../slap.h"
+#include "ldif2common.h"
#include "../back-bdb2/back-bdb2.h"
-#define MAXARGS 100
-
-static char *tailorfile;
-static char *inputfile;
-
-static void
-usage( char *name )
-{
- fprintf( stderr, "usage: %s -i inputfile [-d debuglevel] [-f configfile] [-n databasenumber]\n", name );
- exit( EXIT_FAILURE );
-}
-
int
main( int argc, char **argv )
{
char *buf;
char line[BUFSIZ], idbuf[BUFSIZ];
int lmax, lcur;
- int dbnum;
ID id;
ID maxid;
struct dbcache *db;
struct berval *vals[2];
FILE *fp;
- 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;
- }
- }
- if ( inputfile == NULL ) {
- usage( argv[0] );
- } else {
- if ( freopen( inputfile, "r", stdin ) == NULL ) {
- perror( inputfile );
- exit( EXIT_FAILURE );
- }
- }
-
- /*
- * initialize stuff and figure out which backend we're dealing with
- */
-
- slap_init(SLAP_TOOLID_MODE, "ldif2id2entry");
- 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( EXIT_FAILURE );
- }
- } 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( EXIT_FAILURE );
- } 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( EXIT_FAILURE );
- }
+ slap_ldif_init( argc, argv, LDIF2ID2ENTRY, "bdb2", SLAP_TOOLID_MODE );
slap_startup(dbnum);
#include <ac/socket.h>
#include <ac/unistd.h>
-#include "ldap_defaults.h"
-#include "../slap.h"
+#include "ldif2common.h"
#include "../back-ldbm/back-ldbm.h"
-#define MAXARGS 100
-
-static char *tailorfile;
-static char *inputfile;
-
-static void
-usage( char *name )
-{
- fprintf( stderr, "usage: %s -i inputfile [-d debuglevel] [-f configfile] [-n databasenumber]\n", name );
- exit( EXIT_FAILURE );
-}
-
int
main( int argc, char **argv )
{
char *buf;
char line[BUFSIZ], idbuf[BUFSIZ];
int lmax, lcur;
- int dbnum;
ID id;
ID maxid;
DBCache *db;
ldbm_ignore_nextid_file = 1;
- 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;
- }
- }
- if ( inputfile == NULL ) {
- usage( argv[0] );
- } else {
- if ( freopen( inputfile, "r", stdin ) == NULL ) {
- perror( inputfile );
- exit( EXIT_FAILURE );
- }
- }
-
- /*
- * initialize stuff and figure out which backend we're dealing with
- */
-
- slap_init(SLAP_TOOL_MODE, "ldif2id2entry");
- read_config( tailorfile );
-
- 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( EXIT_FAILURE );
- }
- } 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( EXIT_FAILURE );
- } 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( EXIT_FAILURE );
- }
+ slap_ldif_init( argc, argv, LDIF2ID2ENTRY, "ldbm", SLAP_TOOL_MODE );
slap_startup(dbnum);
#include <ac/socket.h>
#include <ac/unistd.h>
-#include "../slap.h"
+#include "ldif2common.h"
#include "../back-bdb2/back-bdb2.h"
-
-#include "ldap_defaults.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( EXIT_FAILURE );
-}
-
int
main( int argc, char **argv )
{
int i, stop;
- char *tailorfile, *inputfile;
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( EXIT_FAILURE );
- }
- }
-
- 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( EXIT_FAILURE );
- }
- } 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( EXIT_FAILURE );
- } 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( EXIT_FAILURE );
- }
slap_startup(dbnum);
#include <ac/socket.h>
#include <ac/unistd.h>
-#include "../slap.h"
+#include "ldif2common.h"
#include "../back-ldbm/back-ldbm.h"
-
-#include "ldap_defaults.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( EXIT_FAILURE );
-}
-
int
main( int argc, char **argv )
{
int i, stop;
- char *tailorfile, *inputfile;
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;
ldbm_ignore_nextid_file = 1;
- 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, "ldbm", 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( EXIT_FAILURE );
- }
- }
-
- 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, "ldbm" )
- == 0 ) {
- break;
- }
- }
- if ( dbnum == nbackends ) {
- fprintf( stderr, "No ldbm database found in config file\n" );
- exit( EXIT_FAILURE );
- }
- } 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( EXIT_FAILURE );
- } 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( EXIT_FAILURE );
- }
slap_startup(dbnum);
#include <sys/param.h>
-#include "ldap_defaults.h"
-#include "../slap.h"
+#include "ldif2common.h"
#include "../back-bdb2/back-bdb2.h"
#include "ldif.h"
static void fork_child( char *prog, char *args[] );
static void wait4kids( int nkidval );
-static char *tailorfile;
-static char *inputfile;
static int maxkids = 1;
static int nkids;
-static void
-usage( char *name )
-{
- fprintf( stderr, "usage: %s -i inputfile [-d debuglevel] [-f configfile] [-j #jobs] [-n databasenumber] [-s sbindir]\n", name );
- exit( EXIT_FAILURE );
-}
-
int
main( int argc, char **argv )
{
int i, stop;
- char *linep, *buf, *sbindir;
+ char *linep, *buf;
char *args[MAXARGS];
char buf2[20], buf3[20];
char line[BUFSIZ];
char cmd[MAXPATHLEN];
int lineno, elineno;
int lmax, lcur;
- int dbnum;
ID id;
- int rc;
Backend *be = NULL;
struct ldbminfo *li;
struct berval bv;
struct berval *vals[2];
Avlnode *avltypes = NULL;
- sbindir = LDAP_SBINDIR;
- tailorfile = SLAPD_DEFAULT_CONFIGFILE;
- dbnum = -1;
- while ( (i = getopt( argc, argv, "d:e:s:f:i:j:n:" )) != EOF ) {
- switch ( i ) {
- case 'd': /* turn on debugging */
- ldap_debug = atoi( optarg );
- break;
-
- case 's': /* alternate sbindir (index cmd location) */
- case 'e': /* accept -e for backwards compatibility */
- sbindir = strdup( optarg );
- break;
-
- case 'f': /* specify a tailor file */
- tailorfile = strdup( optarg );
- break;
-
- case 'i': /* input file */
- inputfile = strdup( optarg );
- break;
-
- case 'j': /* number of parallel index procs */
- maxkids = atoi( optarg );
- break;
-
- case 'n': /* which config file db to index */
- dbnum = atoi( optarg ) - 1;
- break;
-
- default:
- usage( argv[0] );
- break;
- }
- }
- if ( inputfile == NULL ) {
- usage( argv[0] );
- } else {
- if ( freopen( inputfile, "r", stdin ) == NULL ) {
- perror( inputfile );
- exit( EXIT_FAILURE );
- }
- }
-
- /*
- * initialize stuff and figure out which backend we're dealing with
- */
-
- rc = slap_init(SLAP_TOOL_MODE, "ldif2ldbm");
- if (rc != 0 ) {
- fprintf( stderr, "ldif2ldbm: slap_init failed!\n");
- exit(EXIT_FAILURE);
- }
-
- 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( EXIT_FAILURE );
- }
- } 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( EXIT_FAILURE );
- } 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( EXIT_FAILURE );
- }
+ slap_ldif_init( argc, argv, LDIF2LDBM, "bdb2", SLAP_TOOL_MODE );
slap_startup(dbnum);
args[i++] = NULL;
fork_child( cmd, args );
+ maxkids = cmdkids;
+
/*
* generate the attribute indexes
*/
#include <sys/param.h>
#endif
-#include "ldap_defaults.h"
-#include "../slap.h"
+#include "ldif2common.h"
#include "../back-ldbm/back-ldbm.h"
#include "ldif.h"
static void fork_child( char *prog, char *args[] );
static void wait4kids( int nkidval );
-static char *tailorfile;
-static char *inputfile;
static int maxkids = 1;
static int nkids;
-static void
-usage( char *name )
-{
- fprintf( stderr, "usage: %s -i inputfile [-d debuglevel] [-f configfile] [-j #jobs] [-n databasenumber] [-s sbindir]\n", name );
- exit( EXIT_FAILURE );
-}
-
int
main( int argc, char **argv )
{
int i, stop;
- char *linep, *buf, *sbindir;
+ char *linep, *buf;
char *args[MAXARGS];
char buf2[20], buf3[20];
char line[BUFSIZ];
char cmd[MAXPATHLEN];
int lineno, elineno;
int lmax, lcur;
- int dbnum;
ID id;
- int rc;
- int cmdkids = 1;
Backend *be = NULL;
struct ldbminfo *li;
struct berval bv;
ldbm_ignore_nextid_file = 1;
- sbindir = LDAP_SBINDIR;
- tailorfile = SLAPD_DEFAULT_CONFIGFILE;
- dbnum = -1;
- while ( (i = getopt( argc, argv, "d:e:s:f:i:j:n:" )) != EOF ) {
- switch ( i ) {
- case 'd': /* turn on debugging */
- ldap_debug = atoi( optarg );
- break;
-
- case 's': /* alternate sbindir (index cmd location) */
- case 'e': /* accept -e for backwards compatibility */
- sbindir = strdup( optarg );
- break;
-
- case 'f': /* specify a tailor file */
- tailorfile = strdup( optarg );
- break;
-
- case 'i': /* input file */
- inputfile = strdup( optarg );
- break;
-
- case 'j': /* number of parallel index procs */
- cmdkids = atoi( optarg );
- break;
-
- case 'n': /* which config file db to index */
- dbnum = atoi( optarg ) - 1;
- break;
-
- default:
- usage( argv[0] );
- break;
- }
- }
- if ( inputfile == NULL ) {
- usage( argv[0] );
- } else {
- if ( freopen( inputfile, "r", stdin ) == NULL ) {
- perror( inputfile );
- exit( EXIT_FAILURE );
- }
- }
-
- /*
- * initialize stuff and figure out which backend we're dealing with
- */
-
- rc = slap_init(SLAP_TOOL_MODE, "ldif2ldbm");
- if (rc != 0 ) {
- fprintf( stderr, "ldif2ldbm: slap_init failed!\n");
- exit(EXIT_FAILURE);
- }
-
- read_config( tailorfile );
-
- 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( EXIT_FAILURE );
- }
- } 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( EXIT_FAILURE );
- } 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( EXIT_FAILURE );
- }
+ slap_ldif_init( argc, argv, LDIF2LDBM, "ldbm", SLAP_TOOL_MODE );
slap_startup(dbnum);