]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/tools/ldif2ldbm.c
Updated some items
[openldap] / servers / slapd / tools / ldif2ldbm.c
index 3daafb85598181ff303f7f64d3af7e8c87403696..9cbdf52b378f9573bed46b992a53e29ccbdde2e4 100644 (file)
@@ -1,54 +1,34 @@
+#include "portable.h"
+
 #include <stdio.h>
-#include <string.h>
-#include <sys/types.h>
-#include <sys/socket.h>
+
+#include <ac/string.h>
+#include <ac/ctype.h>
+#include <ac/socket.h>
+#include <ac/unistd.h>
+#include <ac/wait.h>
+
 #include <sys/param.h>
+
+#include "ldapconfig.h"
 #include "../slap.h"
 #include "../back-ldbm/back-ldbm.h"
+#include "ldif.h"
 
-#define DEFAULT_CONFIGFILE     "%ETCDIR%/slapd.conf"
-#define DEFAULT_SBINDIR                "%SBINDIR%"
 #define INDEXCMD               "ldif2index"
 #define ID2ENTRYCMD            "ldif2id2entry"
 #define ID2CHILDRENCMD         "ldif2id2children"
 #define MAXARGS                100
 
-extern void            attr_index_config();
-extern char            *str_getline();
-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 void    fork_child();
-static void    wait4kids();
+static void fork_child( char *prog, char *args[] );
+static void    wait4kids( int nkidval );
 
 static char    *indexcmd;
 static char    *tailorfile;
 static char    *inputfile;
 static int      maxkids = 1;
 static int      nkids;
+
 static void
 usage( char *name )
 {
@@ -56,11 +36,12 @@ usage( char *name )
        exit( 1 );
 }
 
+int
 main( int argc, char **argv )
 {
        int             i, stop, status;
        char            *linep, *buf, *sbindir;
-       char            *args[10];
+       char            *args[MAXARGS];
        char            buf2[20], buf3[20];
        char            line[BUFSIZ];
        char            cmd[MAXPATHLEN];
@@ -68,14 +49,15 @@ main( int argc, char **argv )
        int             lmax, lcur;
        int             dbnum;
        ID              id;
+       int             rc;
        Backend         *be = NULL;
+       struct ldbminfo *li;
        struct berval   bv;
        struct berval   *vals[2];
        Avlnode         *avltypes = NULL;
-       extern char     *optarg;
 
        sbindir = DEFAULT_SBINDIR;
-       tailorfile = DEFAULT_CONFIGFILE;
+       tailorfile = SLAPD_DEFAULT_CONFIGFILE;
        dbnum = -1;
        while ( (i = getopt( argc, argv, "d:e:s:f:i:j:n:" )) != EOF ) {
                switch ( i ) {
@@ -122,8 +104,13 @@ main( int argc, char **argv )
         * initialize stuff and figure out which backend we're dealing with
         */
 
-       init();
-       read_config( tailorfile, &be, NULL );
+       rc = slap_init(SLAP_TOOL_MODE, "ldif2ldbm");
+       if (rc != 0 ) {
+               fprintf( stderr, "ldif2ldbm: slap_init failed!\n");
+               exit(1);
+       }
+
+       read_config( tailorfile );
 
        if ( dbnum == -1 ) {
                for ( dbnum = 0; dbnum < nbackends; dbnum++ ) {
@@ -144,8 +131,15 @@ main( int argc, char **argv )
                fprintf( stderr, "Database number %d selected via -n is not an ldbm database\n", dbnum );
                exit( 1 );
        }
+
+       slap_startup(dbnum);
+
        be = &backends[dbnum];
 
+       /* disable write sync'ing */
+       li = (struct ldbminfo *) be->be_private;
+       li->li_dbcachewsync = 0;
+
        /*
         * generate the id2entry index
         */
@@ -224,6 +218,9 @@ main( int argc, char **argv )
                int             vlen, indexmask, syntaxmask;
                Datum           key, data;
 
+               ldbm_datum_init( key );
+               ldbm_datum_init( data );
+
                if ( fgets( line, sizeof(line), stdin ) != NULL ) {
                        int     len;
 
@@ -242,9 +239,9 @@ main( int argc, char **argv )
                        id++;
                        s = buf;
                        elineno = 0;
-                       while ( (linep = str_getline( &s )) != NULL ) {
+                       while ( (linep = ldif_getline( &s )) != NULL ) {
                                elineno++;
-                               if ( str_parse_line( linep, &type, &val, &vlen )
+                               if ( ldif_parse_line( linep, &type, &val, &vlen )
                                    != 0 ) {
                                        Debug( LDAP_DEBUG_PARSE,
                            "bad line %d in entry ending at line %d ignored\n",
@@ -272,10 +269,13 @@ main( int argc, char **argv )
                        lcur = 0;
                }
        }
-       (*be->be_close)( be );
+
+       slap_shutdown(dbnum);
 
        wait4kids( -1 );
 
+       slap_destroy();
+
        exit( 0 );
 }