From: Hallvard Furuseth Date: Wed, 4 Aug 1999 05:49:36 +0000 (+0000) Subject: Factor out ldif2* intialization to ldif2common.c X-Git-Tag: TWEB_OL_BASE~295 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=48b63d4f165269f29c35f89cceddd880c3966ef5;p=openldap Factor out ldif2* intialization to ldif2common.c --- diff --git a/servers/slapd/tools/Makefile.in b/servers/slapd/tools/Makefile.in index c921d87bd7..551610bf64 100644 --- a/servers/slapd/tools/Makefile.in +++ b/servers/slapd/tools/Makefile.in @@ -36,7 +36,7 @@ PROGRAMS2=ldif2index-bdb2 ldif2ldbm-bdb2 \ 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 @@ -46,12 +46,13 @@ XSRCS = edb2-vers.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 @@ -137,8 +138,8 @@ centipede: centipede.o $(SLAPD_LIBDEPEND) 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 \ diff --git a/servers/slapd/tools/ldif2common.c b/servers/slapd/tools/ldif2common.c new file mode 100644 index 0000000000..3d15698a03 --- /dev/null +++ b/servers/slapd/tools/ldif2common.c @@ -0,0 +1,130 @@ +/* ldif2common.c - common definitions for the ldif2* tools */ + +#include "portable.h" + +#include + +#include +#include +#include +#include +#include + +#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 ); + } +} diff --git a/servers/slapd/tools/ldif2common.h b/servers/slapd/tools/ldif2common.h new file mode 100644 index 0000000000..e681d2073f --- /dev/null +++ b/servers/slapd/tools/ldif2common.h @@ -0,0 +1,24 @@ +/* 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_ */ diff --git a/servers/slapd/tools/ldif2id2children-bdb2.c b/servers/slapd/tools/ldif2id2children-bdb2.c index aa1652dfa6..367f86a08f 100644 --- a/servers/slapd/tools/ldif2id2children-bdb2.c +++ b/servers/slapd/tools/ldif2id2children-bdb2.c @@ -9,24 +9,10 @@ #include #include -#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 ) { @@ -35,7 +21,6 @@ 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; @@ -43,66 +28,7 @@ main( int argc, char **argv ) 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]; diff --git a/servers/slapd/tools/ldif2id2children.c b/servers/slapd/tools/ldif2id2children.c index 97587c23fe..bd146e6447 100644 --- a/servers/slapd/tools/ldif2id2children.c +++ b/servers/slapd/tools/ldif2id2children.c @@ -9,24 +9,10 @@ #include #include -#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 ) { @@ -35,7 +21,6 @@ main( int argc, char **argv ) char line[BUFSIZ]; int lineno, elineno; int lmax, lcur; - int dbnum; ID id; DBCache *db, *db2; Backend *be = NULL; @@ -45,66 +30,7 @@ main( int argc, char **argv ) 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]; diff --git a/servers/slapd/tools/ldif2id2entry-bdb2.c b/servers/slapd/tools/ldif2id2entry-bdb2.c index 5e86e79712..b51c2c4ec0 100644 --- a/servers/slapd/tools/ldif2id2entry-bdb2.c +++ b/servers/slapd/tools/ldif2id2entry-bdb2.c @@ -9,22 +9,9 @@ #include #include -#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 ) { @@ -32,7 +19,6 @@ main( int argc, char **argv ) char *buf; char line[BUFSIZ], idbuf[BUFSIZ]; int lmax, lcur; - int dbnum; ID id; ID maxid; struct dbcache *db; @@ -42,66 +28,7 @@ main( int argc, char **argv ) 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); diff --git a/servers/slapd/tools/ldif2id2entry.c b/servers/slapd/tools/ldif2id2entry.c index aa90d138bc..52ad2ff060 100644 --- a/servers/slapd/tools/ldif2id2entry.c +++ b/servers/slapd/tools/ldif2id2entry.c @@ -9,22 +9,9 @@ #include #include -#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 ) { @@ -32,7 +19,6 @@ main( int argc, char **argv ) char *buf; char line[BUFSIZ], idbuf[BUFSIZ]; int lmax, lcur; - int dbnum; ID id; ID maxid; DBCache *db; @@ -44,66 +30,7 @@ main( int argc, char **argv ) 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); diff --git a/servers/slapd/tools/ldif2index-bdb2.c b/servers/slapd/tools/ldif2index-bdb2.c index 04f9f4baa6..b0d010b456 100644 --- a/servers/slapd/tools/ldif2index-bdb2.c +++ b/servers/slapd/tools/ldif2index-bdb2.c @@ -9,95 +9,26 @@ #include #include -#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); diff --git a/servers/slapd/tools/ldif2index.c b/servers/slapd/tools/ldif2index.c index 84d86d3f57..ed488175af 100644 --- a/servers/slapd/tools/ldif2index.c +++ b/servers/slapd/tools/ldif2index.c @@ -9,31 +9,18 @@ #include #include -#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; @@ -42,64 +29,8 @@ main( int argc, char **argv ) 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); diff --git a/servers/slapd/tools/ldif2ldbm-bdb2.c b/servers/slapd/tools/ldif2ldbm-bdb2.c index f2cb07e5aa..1cafdcf730 100644 --- a/servers/slapd/tools/ldif2ldbm-bdb2.c +++ b/servers/slapd/tools/ldif2ldbm-bdb2.c @@ -10,8 +10,7 @@ #include -#include "ldap_defaults.h" -#include "../slap.h" +#include "ldif2common.h" #include "../back-bdb2/back-bdb2.h" #include "ldif.h" @@ -23,113 +22,28 @@ 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); @@ -183,6 +97,8 @@ main( int argc, char **argv ) args[i++] = NULL; fork_child( cmd, args ); + maxkids = cmdkids; + /* * generate the attribute indexes */ diff --git a/servers/slapd/tools/ldif2ldbm.c b/servers/slapd/tools/ldif2ldbm.c index cff24fd6a9..84ed71c4a0 100644 --- a/servers/slapd/tools/ldif2ldbm.c +++ b/servers/slapd/tools/ldif2ldbm.c @@ -12,8 +12,7 @@ #include #endif -#include "ldap_defaults.h" -#include "../slap.h" +#include "ldif2common.h" #include "../back-ldbm/back-ldbm.h" #include "ldif.h" @@ -26,33 +25,21 @@ 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; @@ -61,81 +48,7 @@ main( int argc, char **argv ) 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);