11 #include "ldapconfig.h"
13 #include "../back-ldbm/back-ldbm.h"
19 int ldap_syslog_level;
20 int global_schemacheck;
21 long num_entries_sent;
24 char *default_referral;
25 struct objclass *global_oc;
27 pthread_t listener_tid;
28 pthread_mutex_t num_sent_mutex;
29 pthread_mutex_t entry2str_mutex;
30 pthread_mutex_t active_threads_mutex;
31 pthread_mutex_t new_conn_mutex;
32 pthread_mutex_t currenttime_mutex;
33 pthread_mutex_t replog_mutex;
34 pthread_mutex_t ops_mutex;
35 pthread_mutex_t regex_mutex;
37 static char *tailorfile;
38 static char *inputfile;
43 fprintf( stderr, "usage: %s -i inputfile [-d debuglevel] [-f configfile] [-n databasenumber]\n", name );
48 main( int argc, char **argv )
50 int i, cargc, indb, stop, status;
52 char *defargv[MAXARGS];
54 char line[BUFSIZ], idbuf[BUFSIZ];
62 struct berval *vals[2];
63 Avlnode *avltypes = NULL;
66 tailorfile = SLAPD_DEFAULT_CONFIGFILE;
68 while ( (i = getopt( argc, argv, "d:f:i:n:" )) != EOF ) {
70 case 'd': /* turn on debugging */
71 ldap_debug = atoi( optarg );
74 case 'f': /* specify a tailor file */
75 tailorfile = strdup( optarg );
78 case 'i': /* input file */
79 inputfile = strdup( optarg );
82 case 'n': /* which config file db to index */
83 dbnum = atoi( optarg ) - 1;
91 if ( inputfile == NULL ) {
94 if ( freopen( inputfile, "r", stdin ) == NULL ) {
101 * initialize stuff and figure out which backend we're dealing with
105 read_config( tailorfile, &be, NULL );
108 for ( dbnum = 0; dbnum < nbackends; dbnum++ ) {
109 if ( strcasecmp( backends[dbnum].be_type, "ldbm" )
114 if ( dbnum == nbackends ) {
115 fprintf( stderr, "No ldbm database found in config file\n" );
118 } else if ( dbnum < 0 || dbnum > (nbackends-1) ) {
119 fprintf( stderr, "Database number selected via -n is out of range\n" );
120 fprintf( stderr, "Must be in the range 1 to %d (number of databases in the config file)\n", nbackends );
122 } else if ( strcasecmp( backends[dbnum].be_type, "ldbm" ) != 0 ) {
123 fprintf( stderr, "Database number %d selected via -n is not an ldbm database\n", dbnum );
126 be = &backends[dbnum];
128 /* disable write sync'ing */
129 li = (struct ldbminfo *) be->be_private;
130 li->li_dbcachewsync = 0;
132 if ( (db = ldbm_cache_open( be, "id2entry", LDBM_SUFFIX, LDBM_NEWDB ))
134 perror( "id2entry file" );
145 char *type, *val, *s;
149 memset( &key, 0, sizeof( key ));
150 memset( &data, 0, sizeof( data ));
152 if ( fgets( line, sizeof(line), stdin ) != NULL ) {
155 len = strlen( line );
156 if ( buf == NULL || *buf == '\0' ) {
157 if (!isdigit(line[0])) {
158 sprintf( idbuf, "%d\n", id + 1 );
159 idlen = strlen( idbuf );
168 while ( lcur + len + idlen + 1 > lmax ) {
170 buf = (char *) ch_realloc( buf, lmax );
174 strcpy( buf + lcur, idbuf );
177 strcpy( buf + lcur, line );
182 if ( line[0] == '\n' || stop && buf && *buf ) {
183 if ( *buf != '\n' ) {
187 key.dptr = (char *) &id;
188 key.dsize = sizeof(ID);
191 if (buf[len - 1] == '\n')
193 data.dsize = len + 1;
194 if ( ldbm_store( db->dbc_db, key, data,
195 LDBM_INSERT ) != 0 ) {
196 fputs("id2entry ldbm_store failed\n",
206 (*be->be_close)( be );
209 sprintf( line, "%s/NEXTID",
210 ((struct ldbminfo *) be->be_private)->li_directory );
211 if ( (fp = fopen( line, "w" )) == NULL ) {
213 fprintf( stderr, "Could not write next id %ld\n", id );
215 fprintf( fp, "%ld\n", id );