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 pthread_mutex_t crypt_mutex;
38 static char *tailorfile;
39 static char *inputfile;
44 fprintf( stderr, "usage: %s -i inputfile [-d debuglevel] [-f configfile] [-n databasenumber]\n", name );
49 main( int argc, char **argv )
51 int i, cargc, indb, stop, status;
53 char *defargv[MAXARGS];
55 char line[BUFSIZ], idbuf[BUFSIZ];
63 struct berval *vals[2];
64 Avlnode *avltypes = NULL;
67 tailorfile = SLAPD_DEFAULT_CONFIGFILE;
69 while ( (i = getopt( argc, argv, "d:f:i:n:" )) != EOF ) {
71 case 'd': /* turn on debugging */
72 ldap_debug = atoi( optarg );
75 case 'f': /* specify a tailor file */
76 tailorfile = strdup( optarg );
79 case 'i': /* input file */
80 inputfile = strdup( optarg );
83 case 'n': /* which config file db to index */
84 dbnum = atoi( optarg ) - 1;
92 if ( inputfile == NULL ) {
95 if ( freopen( inputfile, "r", stdin ) == NULL ) {
102 * initialize stuff and figure out which backend we're dealing with
106 read_config( tailorfile, &be, NULL );
109 for ( dbnum = 0; dbnum < nbackends; dbnum++ ) {
110 if ( strcasecmp( backends[dbnum].be_type, "ldbm" )
115 if ( dbnum == nbackends ) {
116 fprintf( stderr, "No ldbm database found in config file\n" );
119 } else if ( dbnum < 0 || dbnum > (nbackends-1) ) {
120 fprintf( stderr, "Database number selected via -n is out of range\n" );
121 fprintf( stderr, "Must be in the range 1 to %d (number of databases in the config file)\n", nbackends );
123 } else if ( strcasecmp( backends[dbnum].be_type, "ldbm" ) != 0 ) {
124 fprintf( stderr, "Database number %d selected via -n is not an ldbm database\n", dbnum );
127 be = &backends[dbnum];
129 /* disable write sync'ing */
130 li = (struct ldbminfo *) be->be_private;
131 li->li_dbcachewsync = 0;
133 if ( (db = ldbm_cache_open( be, "id2entry", LDBM_SUFFIX, LDBM_NEWDB ))
135 perror( "id2entry file" );
146 char *type, *val, *s;
150 ldbm_datum_init( key );
151 ldbm_datum_init( data );
153 if ( fgets( line, sizeof(line), stdin ) != NULL ) {
156 len = strlen( line );
157 if ( buf == NULL || *buf == '\0' ) {
158 if (!isdigit(line[0])) {
159 sprintf( idbuf, "%d\n", id + 1 );
160 idlen = strlen( idbuf );
169 while ( lcur + len + idlen + 1 > lmax ) {
171 buf = (char *) ch_realloc( buf, lmax );
175 strcpy( buf + lcur, idbuf );
178 strcpy( buf + lcur, line );
183 if ( line[0] == '\n' || stop && buf && *buf ) {
184 if ( *buf != '\n' ) {
188 key.dptr = (char *) &id;
189 key.dsize = sizeof(ID);
192 if (buf[len - 1] == '\n')
194 data.dsize = len + 1;
195 if ( ldbm_store( db->dbc_db, key, data,
196 LDBM_INSERT ) != 0 ) {
197 fputs("id2entry ldbm_store failed\n",
207 (*be->be_close)( be );
210 sprintf( line, "%s/NEXTID",
211 ((struct ldbminfo *) be->be_private)->li_directory );
212 if ( (fp = fopen( line, "w" )) == NULL ) {
214 fprintf( stderr, "Could not write next id %ld\n", id );
216 fprintf( fp, "%ld\n", id );