4 #include <sys/socket.h>
6 #include "../back-ldbm/back-ldbm.h"
8 #include "ldapconfig.h"
12 extern struct dbcache *ldbm_cache_open();
13 extern void attr_index_config();
14 extern int strcasecmp();
16 extern Backend *backends;
17 extern int ldap_debug;
21 int ldap_syslog_level;
22 int global_schemacheck;
26 char *default_referral;
27 struct objclass *global_oc;
29 pthread_t listener_tid;
30 pthread_mutex_t num_sent_mutex;
31 pthread_mutex_t entry2str_mutex;
32 pthread_mutex_t active_threads_mutex;
33 pthread_mutex_t new_conn_mutex;
34 pthread_mutex_t currenttime_mutex;
35 pthread_mutex_t replog_mutex;
36 pthread_mutex_t ops_mutex;
37 pthread_mutex_t regex_mutex;
39 static int make_index();
41 static char *tailorfile;
42 static char *inputfile;
47 fprintf( stderr, "usage: %s -i inputfile [-d debuglevel] [-f configfile] [-n databasenumber]\n", name );
51 main( int argc, char **argv )
53 int i, cargc, indb, stop, status;
55 char *defargv[MAXARGS];
57 char line[BUFSIZ], idbuf[BUFSIZ];
64 struct berval *vals[2];
65 Avlnode *avltypes = NULL;
69 tailorfile = SLAPD_DEFAULT_CONFIGFILE;
71 while ( (i = getopt( argc, argv, "d:f:i:n:" )) != EOF ) {
73 case 'd': /* turn on debugging */
74 ldap_debug = atoi( optarg );
77 case 'f': /* specify a tailor file */
78 tailorfile = strdup( optarg );
81 case 'i': /* input file */
82 inputfile = strdup( optarg );
85 case 'n': /* which config file db to index */
86 dbnum = atoi( optarg ) - 1;
94 if ( inputfile == NULL ) {
97 if ( freopen( inputfile, "r", stdin ) == NULL ) {
104 * initialize stuff and figure out which backend we're dealing with
108 read_config( tailorfile, &be, NULL );
111 for ( dbnum = 0; dbnum < nbackends; dbnum++ ) {
112 if ( strcasecmp( backends[dbnum].be_type, "ldbm" )
117 if ( dbnum == nbackends ) {
118 fprintf( stderr, "No ldbm database found in config file\n" );
121 } else if ( dbnum < 0 || dbnum > (nbackends-1) ) {
122 fprintf( stderr, "Database number selected via -n is out of range\n" );
123 fprintf( stderr, "Must be in the range 1 to %d (number of databases in the config file)\n", nbackends );
125 } else if ( strcasecmp( backends[dbnum].be_type, "ldbm" ) != 0 ) {
126 fprintf( stderr, "Database number %d selected via -n is not an ldbm database\n", dbnum );
129 be = &backends[dbnum];
131 if ( (db = ldbm_cache_open( be, "id2entry", LDBM_SUFFIX, LDBM_NEWDB ))
133 perror( "id2entry file" );
144 char *type, *val, *s;
148 if ( fgets( line, sizeof(line), stdin ) != NULL ) {
151 len = strlen( line );
152 if ( buf == NULL || *buf == '\0' ) {
153 sprintf( idbuf, "%d\n", id + 1 );
154 idlen = strlen( idbuf );
159 while ( lcur + len + idlen + 1 > lmax ) {
161 buf = (char *) ch_realloc( buf, lmax );
165 strcpy( buf + lcur, idbuf );
168 strcpy( buf + lcur, line );
173 if ( line[0] == '\n' || stop && buf && *buf ) {
174 if ( *buf != '\n' ) {
176 key.dptr = (char *) &id;
177 key.dsize = sizeof(ID);
179 data.dsize = strlen( buf ) + 1;
180 if ( ldbm_store( db->dbc_db, key, data,
181 LDBM_INSERT ) != 0 ) {
182 perror( "id2entry ldbm_store" );
191 (*be->be_close)( be );
194 sprintf( line, "%s/NEXTID",
195 ((struct ldbminfo *) be->be_private)->li_directory );
196 if ( (fp = fopen( line, "w" )) == NULL ) {
198 fprintf( stderr, "Could not write next id %ld\n", id );
200 fprintf( fp, "%ld\n", id );