9 #include "ldapconfig.h"
11 #include "../back-ldbm/back-ldbm.h"
17 int ldap_syslog_level;
18 int global_schemacheck;
19 long num_entries_sent;
22 char *default_referral;
23 struct objclass *global_oc;
25 pthread_t listener_tid;
26 pthread_mutex_t num_sent_mutex;
27 pthread_mutex_t entry2str_mutex;
28 pthread_mutex_t active_threads_mutex;
29 pthread_mutex_t new_conn_mutex;
30 pthread_mutex_t currenttime_mutex;
31 pthread_mutex_t replog_mutex;
32 pthread_mutex_t ops_mutex;
33 pthread_mutex_t regex_mutex;
35 static char *tailorfile;
36 static char *inputfile;
41 fprintf( stderr, "usage: %s -i inputfile [-d debuglevel] [-f configfile] [-n databasenumber]\n", name );
46 main( int argc, char **argv )
48 int i, cargc, indb, stop, status;
50 char *defargv[MAXARGS];
52 char line[BUFSIZ], idbuf[BUFSIZ];
59 struct berval *vals[2];
60 Avlnode *avltypes = NULL;
63 tailorfile = SLAPD_DEFAULT_CONFIGFILE;
65 while ( (i = getopt( argc, argv, "d:f:i:n:" )) != EOF ) {
67 case 'd': /* turn on debugging */
68 ldap_debug = atoi( optarg );
71 case 'f': /* specify a tailor file */
72 tailorfile = strdup( optarg );
75 case 'i': /* input file */
76 inputfile = strdup( optarg );
79 case 'n': /* which config file db to index */
80 dbnum = atoi( optarg ) - 1;
88 if ( inputfile == NULL ) {
91 if ( freopen( inputfile, "r", stdin ) == NULL ) {
98 * initialize stuff and figure out which backend we're dealing with
102 read_config( tailorfile, &be, NULL );
105 for ( dbnum = 0; dbnum < nbackends; dbnum++ ) {
106 if ( strcasecmp( backends[dbnum].be_type, "ldbm" )
111 if ( dbnum == nbackends ) {
112 fprintf( stderr, "No ldbm database found in config file\n" );
115 } else if ( dbnum < 0 || dbnum > (nbackends-1) ) {
116 fprintf( stderr, "Database number selected via -n is out of range\n" );
117 fprintf( stderr, "Must be in the range 1 to %d (number of databases in the config file)\n", nbackends );
119 } else if ( strcasecmp( backends[dbnum].be_type, "ldbm" ) != 0 ) {
120 fprintf( stderr, "Database number %d selected via -n is not an ldbm database\n", dbnum );
123 be = &backends[dbnum];
125 if ( (db = ldbm_cache_open( be, "id2entry", LDBM_SUFFIX, LDBM_NEWDB ))
127 perror( "id2entry file" );
138 char *type, *val, *s;
142 if ( fgets( line, sizeof(line), stdin ) != NULL ) {
145 len = strlen( line );
146 if ( buf == NULL || *buf == '\0' ) {
147 sprintf( idbuf, "%lu\n", id + 1 );
148 idlen = strlen( idbuf );
153 while ( lcur + len + idlen + 1 > lmax ) {
155 buf = (char *) ch_realloc( buf, lmax );
159 strcpy( buf + lcur, idbuf );
162 strcpy( buf + lcur, line );
167 if ( line[0] == '\n' || stop && buf && *buf ) {
168 if ( *buf != '\n' ) {
170 key.dptr = (char *) &id;
171 key.dsize = sizeof(ID);
173 data.dsize = strlen( buf ) + 1;
174 if ( ldbm_store( db->dbc_db, key, data,
175 LDBM_INSERT ) != 0 ) {
176 fputs("id2entry ldbm_store failed\n",
186 (*be->be_close)( be );
189 sprintf( line, "%s/NEXTID",
190 ((struct ldbminfo *) be->be_private)->li_directory );
191 if ( (fp = fopen( line, "w" )) == NULL ) {
193 fprintf( stderr, "Could not write next id %ld\n", id );
195 fprintf( fp, "%ld\n", id );