]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/tools/ldif2id2entry.c
Import minor trace output cleanup
[openldap] / servers / slapd / tools / ldif2id2entry.c
index 5c8874c513206ed06f65ddd22d54107b59f8a18c..96ed84ffe3c34e1e4cf8ba25db158c9c748cb06f 100644 (file)
@@ -1,42 +1,19 @@
+#include "portable.h"
+
 #include <stdio.h>
-#include <string.h>
-#include <sys/types.h>
-#include <sys/socket.h>
+#include <stdlib.h>
+
+#include <ac/ctype.h>
+#include <ac/string.h>
+#include <ac/socket.h>
+#include <ac/unistd.h>
+
+#include "ldapconfig.h"
 #include "../slap.h"
 #include "../back-ldbm/back-ldbm.h"
 
-#define DEFAULT_CONFIGFILE     "/usr/local/etc/slapd.conf"
 #define MAXARGS                100
 
-extern struct dbcache  *ldbm_cache_open();
-extern void            attr_index_config();
-extern int             strcasecmp();
-extern int             nbackends;
-extern Backend         *backends;
-extern int             ldap_debug;
-
-int            ldap_debug;
-int            ldap_syslog;
-int            ldap_syslog_level;
-int            global_schemacheck;
-int            num_entries_sent;
-int            num_bytes_sent;
-int            active_threads;
-char           *default_referral;
-struct objclass        *global_oc;
-time_t         currenttime;
-pthread_t      listener_tid;
-pthread_mutex_t        num_sent_mutex;
-pthread_mutex_t        entry2str_mutex;
-pthread_mutex_t        active_threads_mutex;
-pthread_mutex_t        new_conn_mutex;
-pthread_mutex_t        currenttime_mutex;
-pthread_mutex_t        replog_mutex;
-pthread_mutex_t        ops_mutex;
-pthread_mutex_t        regex_mutex;
-
-static int     make_index();
-
 static char    *tailorfile;
 static char    *inputfile;
  
@@ -47,6 +24,7 @@ usage( char *name )
        exit( 1 );
 }
 
+int
 main( int argc, char **argv )
 {
        int             i, cargc, indb, stop, status;
@@ -58,14 +36,14 @@ main( int argc, char **argv )
        int             dbnum;
        ID              id;
        struct dbcache  *db;
-       Backend         *be;
+       Backend         *be = NULL;
+       struct ldbminfo *li;
        struct berval   bv;
        struct berval   *vals[2];
        Avlnode         *avltypes = NULL;
        FILE            *fp;
-       extern char     *optarg;
 
-       tailorfile = DEFAULT_CONFIGFILE;
+       tailorfile = SLAPD_DEFAULT_CONFIGFILE;
        dbnum = -1;
        while ( (i = getopt( argc, argv, "d:f:i:n:" )) != EOF ) {
                switch ( i ) {
@@ -117,7 +95,7 @@ main( int argc, char **argv )
                        fprintf( stderr, "No ldbm database found in config file\n" );
                        exit( 1 );
                }
-       } else if ( dbnum < 1 || dbnum > nbackends ) {
+       } else if ( dbnum < 0 || dbnum > (nbackends-1) ) {
                fprintf( stderr, "Database number selected via -n is out of range\n" );
                fprintf( stderr, "Must be in the range 1 to %d (number of databases in the config file)\n", nbackends );
                exit( 1 );
@@ -127,6 +105,10 @@ main( int argc, char **argv )
        }
        be = &backends[dbnum];
 
+       /* disable write sync'ing */
+       li = (struct ldbminfo *) be->be_private;
+       li->li_dbcachewsync = 0;
+
        if ( (db = ldbm_cache_open( be, "id2entry", LDBM_SUFFIX, LDBM_NEWDB ))
            == NULL ) {
                perror( "id2entry file" );
@@ -144,13 +126,21 @@ main( int argc, char **argv )
                int             vlen;
                Datum           key, data;
 
+               ldbm_datum_init( key );
+               ldbm_datum_init( data );
+
                if ( fgets( line, sizeof(line), stdin ) != NULL ) {
                        int     len, idlen;
 
                        len = strlen( line );
                        if ( buf == NULL || *buf == '\0' ) {
-                               sprintf( idbuf, "%d\n", id + 1 );
-                               idlen = strlen( idbuf );
+                               if (!isdigit(line[0])) {
+                                       sprintf( idbuf, "%d\n", id + 1 );
+                                       idlen = strlen( idbuf );
+                               } else {
+                                       id = atol(line) - 1;
+                                       idlen = 0;
+                               }
                        } else {
                                idlen = 0;
                        }
@@ -171,14 +161,20 @@ main( int argc, char **argv )
                }
                if ( line[0] == '\n' || stop && buf && *buf ) {
                        if ( *buf != '\n' ) {
+                               int len;
+
                                id++;
                                key.dptr = (char *) &id;
                                key.dsize = sizeof(ID);
                                data.dptr = buf;
-                               data.dsize = strlen( buf ) + 1;
+                               len = strlen(buf);
+                               if (buf[len - 1] == '\n')
+                                       buf[--len] = '\0';
+                               data.dsize = len + 1;
                                if ( ldbm_store( db->dbc_db, key, data,
                                    LDBM_INSERT ) != 0 ) {
-                                       perror( "id2entry ldbm_store" );
+                                       fputs("id2entry ldbm_store failed\n",
+                                             stderr);
                                        exit( 1 );
                                }
                        }