11 #include "ldapconfig.h"
13 #include "../back-ldbm/back-ldbm.h"
19 int ldap_syslog_level;
20 long num_entries_sent;
23 char *default_referral;
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];
60 struct berval *vals[2];
61 Avlnode *avltypes = NULL;
64 tailorfile = SLAPD_DEFAULT_CONFIGFILE;
66 while ( (i = getopt( argc, argv, "d:f:i:n:" )) != EOF ) {
68 case 'd': /* turn on debugging */
69 ldap_debug = atoi( optarg );
72 case 'f': /* specify a tailor file */
73 tailorfile = strdup( optarg );
76 case 'i': /* input file */
77 inputfile = strdup( optarg );
80 case 'n': /* which config file db to index */
81 dbnum = atoi( optarg ) - 1;
89 if ( inputfile == NULL ) {
92 if ( freopen( inputfile, "r", stdin ) == NULL ) {
99 * initialize stuff and figure out which backend we're dealing with
103 read_config( tailorfile, &be, NULL );
106 for ( dbnum = 0; dbnum < nbackends; dbnum++ ) {
107 if ( strcasecmp( backends[dbnum].be_type, "ldbm" )
112 if ( dbnum == nbackends ) {
113 fprintf( stderr, "No ldbm database found in config file\n" );
116 } else if ( dbnum < 0 || dbnum > (nbackends-1) ) {
117 fprintf( stderr, "Database number selected via -n is out of range\n" );
118 fprintf( stderr, "Must be in the range 1 to %d (number of databases in the config file)\n", nbackends );
120 } else if ( strcasecmp( backends[dbnum].be_type, "ldbm" ) != 0 ) {
121 fprintf( stderr, "Database number %d selected via -n is not an ldbm database\n", dbnum );
124 be = &backends[dbnum];
126 /* disable write sync'ing */
127 li = (struct ldbminfo *) be->be_private;
128 li->li_dbcachewsync = 0;
130 if ( (db = ldbm_cache_open( be, "id2entry", LDBM_SUFFIX, LDBM_NEWDB ))
132 perror( "id2entry file" );
143 char *type, *val, *s;
147 memset( &key, 0, sizeof( key ));
148 memset( &data, 0, sizeof( data ));
150 if ( fgets( line, sizeof(line), stdin ) != NULL ) {
153 len = strlen( line );
154 if ( buf == NULL || *buf == '\0' ) {
155 if (!isdigit(line[0])) {
156 sprintf( idbuf, "%d\n", id + 1 );
157 idlen = strlen( idbuf );
166 while ( lcur + len + idlen + 1 > lmax ) {
168 buf = (char *) ch_realloc( buf, lmax );
172 strcpy( buf + lcur, idbuf );
175 strcpy( buf + lcur, line );
180 if ( line[0] == '\n' || stop && buf && *buf ) {
181 if ( *buf != '\n' ) {
185 key.dptr = (char *) &id;
186 key.dsize = sizeof(ID);
189 if (buf[len - 1] == '\n')
191 data.dsize = len + 1;
192 if ( ldbm_store( db->dbc_db, key, data,
193 LDBM_INSERT ) != 0 ) {
194 fputs("id2entry ldbm_store failed\n",
204 (*be->be_close)( be );
207 sprintf( line, "%s/NEXTID",
208 ((struct ldbminfo *) be->be_private)->li_directory );
209 if ( (fp = fopen( line, "w" )) == NULL ) {
211 fprintf( stderr, "Could not write next id %ld\n", id );
213 fprintf( fp, "%ld\n", id );