]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/tools/centipede.c
Import ksp's changes to support newer versions of DB2 (ITS#27).
[openldap] / servers / slapd / tools / centipede.c
index 9f1e81f9773c3aa5ba78e9aad24b974d7d02512a..306203427843922e4f48f4f862f0478ea9a0539f 100644 (file)
@@ -8,6 +8,7 @@
 #include <ac/ctype.h>
 #include <ac/string.h>
 #include <ac/time.h>
+#include <ac/unistd.h>         /* get link(), unlink() */
 
 #include <lber.h>
 #include <ldap.h>
@@ -41,13 +42,13 @@ int         destldapauthmethod;
 int            verbose;
 int            not;
 
-static LDAP            *start_ldap_search();
-static LDAP            *bind_to_destination_ldap();
-static int             create_tmp_files();
-static int             generate_new_centroids();
-static LDAPMod **diff_centroids();
-static LDAPMod **full_centroid();
-static char            **charray_add_dup();
+static LDAP            *start_ldap_search(char *ldapsrcurl, char *ldapfilter, char **attrs);
+static LDAP            *bind_to_destination_ldap(char *ldapsrcurl, char *ldapdesturl);
+static int             create_tmp_files(char **attrs, char ***tmpfile, LDBM **ldbm);
+static int             generate_new_centroids(LDAP *ld, char **attrs, LDBM *ldbm);
+static LDAPMod **diff_centroids(char *attr, LDBM oldbm, LDBM nldbm, int nentries);
+static LDAPMod **full_centroid(char *attr, LDBM ldbm, int nentries);
+static char            **charray_add_dup(char ***a, int *cur, int *max, char *s);
 
 static void usage( char *name )
 {
@@ -72,6 +73,7 @@ static void usage( char *name )
        fprintf( stderr, "\t-c size\t\tldbm cache size\n" );
 }
 
+int
 main( int argc, char **argv )
 {
        char            *ldapfilter;
@@ -85,13 +87,11 @@ main( int argc, char **argv )
        char            buf[BUFSIZ];
        int                     i, j, k, count;
        char            *s;
-       extern int      optind;
-       extern char     *optarg;
 
        ldapsrcurl = NULL;
        ldapdesturl = NULL;
-       ldaphost = LDAPHOST;
-       ldapbase = DEFAULT_BASE;
+       ldaphost = NULL;
+       ldapbase = NULL;
        srcldapauthmethod = LDAP_AUTH_SIMPLE;
        destldapauthmethod = LDAP_AUTH_SIMPLE;
        srcldapbinddn = NULL;
@@ -384,7 +384,7 @@ start_ldap_search(
                fflush( stdout );
        }
 
-       if ( (ld = ldap_open( ldaphost, LDAP_PORT )) == NULL ) {
+       if ( (ld = ldap_open( ldaphost, 0 )) == NULL ) {
                perror( "ldap_open" );
                return( NULL );
        }
@@ -474,6 +474,8 @@ generate_new_centroids(
        char            **val;
        char            last;
 
+       ldbm_datum_init( data );
+
        if ( verbose ) {
                printf( "Generating new centroids for..." );
                fflush( stdout );
@@ -496,6 +498,9 @@ generate_new_centroids(
 
                        /* for each value */
                        for ( j = 0; val[j] != NULL; j++ ) {
+
+                               ldbm_datum_init( key );
+
                                /* normalize the value */
                                for ( s = val[j]; *s; s++ ) {
                                        if ( isascii( *s ) ) {
@@ -556,7 +561,6 @@ diff_centroids(
        Datum   olast, nlast;
        Datum   lastkey, key;
        Datum   data;
-       int             rc;
        LDAPMod **mods;
        char    **avals, **dvals;
        int             amax, acur, dmax, dcur;
@@ -572,6 +576,14 @@ diff_centroids(
                fflush( stdout );
        }
 
+       ldbm_datum_init( okey );
+       ldbm_datum_init( nkey );
+       ldbm_datum_init( olast );
+       ldbm_datum_init( nlast );
+       ldbm_datum_init( lastkey );
+       ldbm_datum_init( key );
+       ldbm_datum_init( data );
+
        if ( (mods = (LDAPMod **) malloc( sizeof(LDAPMod *) * 4 )) == NULL ||
             (mods[0] = (LDAPMod *) malloc( sizeof(LDAPMod) )) == NULL ||
             (mods[1] = (LDAPMod *) malloc( sizeof(LDAPMod) )) == NULL ||
@@ -620,7 +632,7 @@ diff_centroids(
              okey.dptr != NULL && nkey.dptr != NULL; )
 #endif
        {
-               rc = strcmp( okey.dptr, nkey.dptr );
+               int     rc = strcmp( okey.dptr, nkey.dptr );
 
                if ( rc == 0 ) {
                        /* value is in both places - leave it */
@@ -834,6 +846,9 @@ full_centroid(
                fflush( stdout );
        }
 
+       ldbm_datum_init( key );
+       ldbm_datum_init( lastkey );
+
        if ( (mods = (LDAPMod **) malloc( sizeof(LDAPMod *) * 3 )) == NULL ||
             (mods[0] = (LDAPMod *) malloc( sizeof(LDAPMod) )) == NULL ||
             (mods[1] = (LDAPMod *) malloc( sizeof(LDAPMod) )) == NULL ||
@@ -962,7 +977,7 @@ bind_to_destination_ldap(
        free( ldapbase );
        ldapbase = strdup( buf );
 
-       if ( (ld = ldap_open( ldaphost, LDAP_PORT )) == NULL ) {
+       if ( (ld = ldap_open( ldaphost, 0 )) == NULL ) {
                perror( "ldap_open" );
                return( NULL );
        }