1 /* centipede.c - generate and install indexing information (view w/tabstop=4) */
11 #include <ac/unistd.h> /* get link(), unlink() */
12 extern char *strdup (const char *);
13 extern char *strtok (char *, const char *);
14 extern char *strpbrk (const char *, const char *);
21 #define DEFAULT_LDAPFILTER "(objectclass=*)"
23 #define CENTROID_VALUE 1
24 #define CENTROID_WORD 2
26 #define CENTROID_RELATIVE 1
27 #define CENTROID_FULL 2
29 #define WORD_BREAKS " -',.()!;:&$%*\"/\\+_<>=?[]|^~"
42 int srcldapauthmethod;
43 int destldapauthmethod;
47 static LDAP *start_ldap_search(char *ldapsrcurl, char *ldapfilter, char **attrs);
48 static LDAP *bind_to_destination_ldap(char *ldapsrcurl, char *ldapdesturl);
49 static int create_tmp_files(char **attrs, char ***tmpfile, LDBM **ldbm);
50 static int generate_new_centroids(LDAP *ld, char **attrs, LDBM *ldbm);
51 static LDAPMod **diff_centroids(char *attr, LDBM oldbm, LDBM nldbm, int nentries);
52 static LDAPMod **full_centroid(char *attr, LDBM ldbm, int nentries);
53 static char **charray_add_dup(char ***a, int *cur, int *max, char *s);
55 static void usage( char *name )
57 fprintf( stderr, "usage: %s [options] -s url -d url attributes\n", name );
58 fprintf( stderr, "where:\n" );
59 fprintf( stderr, "\t-s url\t\t[[ldap://][host[:port]]/]searchbasedn\n");
60 fprintf( stderr, "\t-d url\t\t[[ldap://][host[:port]]/]centroidentrydn\n");
61 fprintf( stderr, "options:\n" );
62 fprintf( stderr, "\t-v \t\tturn on verbose mode\n" );
63 fprintf( stderr, "\t-n \t\tgenerate, but do not install index info\n" );
64 fprintf( stderr, "\t-f filter\tentry selection filter\n" );
65 fprintf( stderr, "\t-F \t\tgenerate a full centroid\n" );
66 fprintf( stderr, "\t-R \t\tgenerate a relative centroid\n" );
67 fprintf( stderr, "\t-w \t\tgenerate a word-based centroid\n" );
68 fprintf( stderr, "\t-t directory\tcentroid directory\n" );
69 fprintf( stderr, "\t-b binddn\tsource bind dn\n" );
70 fprintf( stderr, "\t-p passwd\tsource bind passwd (for simple auth)\n" );
71 fprintf( stderr, "\t-m authmethod\tsource authmethod \"simple\" or \"kerberos\"\n" );
72 fprintf( stderr, "\t-B binddn\tdestination bind dn\n" );
73 fprintf( stderr, "\t-P passwd\tdestination bind passwd (for simple auth)\n" );
74 fprintf( stderr, "\t-M authmethod\tdestination authmethod \"simple\" or \"kerberos\"\n" );
75 fprintf( stderr, "\t-c size\t\tldbm cache size\n" );
79 main( int argc, char **argv )
82 char *ldapsrcurl, *ldapdesturl;
99 srcldapauthmethod = LDAP_AUTH_SIMPLE;
100 destldapauthmethod = LDAP_AUTH_SIMPLE;
101 srcldapbinddn = NULL;
102 srcldappasswd = NULL;
103 destldapbinddn = NULL;
104 destldappasswd = NULL;
105 ldapfilter = DEFAULT_LDAPFILTER;
106 centroidvalues = CENTROID_VALUE;
107 centroidtype = CENTROID_RELATIVE;
112 while ( (i = getopt( argc, argv, "s:d:c:b:B:f:FRWp:P:m:M:t:vwn" ))
115 case 's': /* source url [[ldap://][host[:port]]/]basedn */
116 ldapsrcurl = strdup( optarg );
119 case 'd': /* destination url [[ldap://][host[:port]]/]entrydn */
120 ldapdesturl = strdup( optarg );
123 case 'f': /* specify a filter */
124 ldapfilter = strdup( optarg );
127 case 'F': /* generate full centroid */
128 centroidtype = CENTROID_FULL;
131 case 'R': /* generate relative centroid */
132 centroidtype = CENTROID_RELATIVE;
135 case 'w': /* generate word centroid */
136 centroidvalues = CENTROID_WORD;
139 case 'W': /* generate weights */
143 case 't': /* temp file directory */
144 centdir = strdup( optarg );
147 case 'b': /* src bind dn */
148 srcldapbinddn = strdup( optarg );
151 case 'p': /* src bind password */
152 srcldappasswd = strdup( optarg );
157 case 'B': /* dest bind dn */
158 destldapbinddn = strdup( optarg );
161 case 'P': /* dest bind password */
162 destldappasswd = strdup( optarg );
167 case 'm': /* src bind method */
168 if ( strcasecmp( optarg, "simple" ) == 0 ) {
169 srcldapauthmethod = LDAP_AUTH_SIMPLE;
170 } else if ( strcasecmp( optarg, "kerberos" ) == 0 ) {
171 srcldapauthmethod = LDAP_AUTH_KRBV4;
173 fprintf( stderr, "%s: unknown auth method\n", optarg );
174 fputs( "expecting \"simple\" or \"kerberos\"\n", stderr );
179 case 'M': /* dest bind method */
180 if ( strcasecmp( optarg, "simple" ) == 0 ) {
181 destldapauthmethod = LDAP_AUTH_SIMPLE;
182 } else if ( strcasecmp( optarg, "kerberos" ) == 0 ) {
183 destldapauthmethod = LDAP_AUTH_KRBV4;
185 fprintf( stderr, "%s: unknown auth method\n", optarg );
186 fputs( "expecting \"simple\" or \"kerberos\"\n", stderr );
191 case 'c': /* ldbm cache size */
192 ldbmcachesize = atoi( optarg );
195 case 'v': /* turn on verbose mode */
199 case 'n': /* don't actually install index info */
208 if ( optind == argc || ldapsrcurl == NULL || ldapdesturl == NULL ) {
212 attrs = &argv[optind];
215 * open the ldap connection and start searching for the entries
216 * we will use to generate the centroids.
219 if ( (ld = start_ldap_search( ldapsrcurl, ldapfilter, attrs )) == NULL ) {
220 fprintf( stderr, "could not initiate ldap search\n" );
224 if ( create_tmp_files( attrs, &tmpfile, &ldbm ) != 0 ) {
225 fprintf( stderr, "could not create temp files\n" );
230 * go through the entries returned, building a centroid for each
231 * attribute as we go.
234 if ( (count = generate_new_centroids( ld, attrs, ldbm )) < 1 ) {
236 fprintf( stderr, "no entries matched\n" );
239 fprintf( stderr, "could not generate new centroid\n" );
245 * for each centroid we generated above, compare to the existing
246 * centroid, if any, and produce adds and deletes, or produce
247 * an entirely new centroid. in either case, update the "current"
248 * centroid version with the new one we just generated.
251 if ( (ld = bind_to_destination_ldap( ldapsrcurl, ldapdesturl )) == NULL ) {
253 "could not bind to index server, or could not create index entry\n" );
257 for ( i = 0; ldbm[i] != NULL; i++ ) {
258 /* generate the name of the existing centroid, if any */
259 s = strrchr( tmpfile[i], '/' );
261 sprintf( buf, "%s/cent.%s", tmpfile[i], attrs[i] );
264 /* generate the full centroid changes */
265 if ( centroidtype == CENTROID_FULL || (oldbm = ldbm_open( buf,
266 LDBM_WRITER, 0, ldbmcachesize )) == NULL ) {
267 if ( (mods = full_centroid( attrs[i], ldbm[i], count )) == NULL ) {
268 fprintf( stderr, "could not produce full centroid for %s\n",
273 /* generate the differential centroid changes */
275 if ( (mods = diff_centroids( attrs[i], oldbm, ldbm[i], count ))
277 fprintf( stderr, "could not diff centroids\n" );
285 printf("changes:\n");
286 for ( j = 0; mods[j] != NULL; j++ ) {
287 switch( mods[j]->mod_op ) {
289 printf( "\tadd: %s\n",mods[j]->mod_type );
291 case LDAP_MOD_DELETE:
292 printf( "\tdelete: %s\n",mods[j]->mod_type );
294 case LDAP_MOD_REPLACE:
295 printf( "\treplace: %s\n",mods[j]->mod_type );
298 if ( mods[j]->mod_values != NULL ) {
299 for ( k = 0; mods[j]->mod_values[k] != NULL; k++ ) {
300 printf( "\t\t%s\n", mods[j]->mod_values[k] );
304 printf("end changes:\n");
308 printf( "%sModifying centroid...", not ? "Not " : "" );
312 /* attempt to make the changes to the index server entry */
313 if ( !not && ldap_modify_s( ld, ldapbase, mods ) != LDAP_SUCCESS ) {
314 fprintf( stderr, "could not apply centroid modification for %s\n",
316 ldap_perror( ld, ldapbase );
318 ldap_mods_free( mods, 1 );
325 /* move the new centroid into the old one's place */
327 (void) unlink( buf );
328 if ( link( tmpfile[i], buf ) != 0 ) {
330 fprintf( stderr, "could not rename %s to %s\n", buf,
335 (void) unlink( tmpfile[i] );
339 for ( i = 0; attrs[i] != NULL; i++ ) {
340 ldbm_close( ldbm[i] );
350 * open an ldap connection, bind, and initiate the search
364 if ( strncmp( ldapsrcurl, "ldap://", 7 ) != 0 ) {
365 fputs( "Not an LDAP URL", stderr ); /* Should be smarter? */
369 if ( (s2 = strchr( s, '/' )) == NULL ) {
370 ldapbase = strdup( s );
374 ldaphost = strdup( s );
377 ldapbase = strdup( s2 + 1 );
381 printf( "Base: %s\n", ldapbase );
382 printf( "Attributes:" );
383 for ( i = 0; attrs[i] != NULL; i++ ) {
384 printf( " %s", attrs[i] );
387 printf( "Binding to source LDAP server..." );
391 if ( (ld = ldap_open( ldaphost, LDAP_PORT )) == NULL ) {
392 perror( "ldap_open" );
396 if ( ldap_bind_s( ld, srcldapbinddn, srcldappasswd, srcldapauthmethod )
398 ldap_perror( ld, "ldap_bind_s" );
403 printf( "\nInitiating search..." );
404 if ( ldap_search( ld, ldapbase, LDAP_SCOPE_SUBTREE, ldapfilter, attrs, 0 )
406 ldap_perror( ld, "ldap_search" );
419 * create the temporary ldbm files we will use to hold the new centroids
431 for ( i = 0; attrs[i] != NULL; i++ )
435 if ( (*tmpfile = (char **) malloc( i * sizeof(char *) )) == NULL ) {
439 if ( (*ldbm = (LDBM *) malloc( i * sizeof(LDBM) )) == NULL ) {
443 for ( i = 0; attrs[i] != NULL; i++ ) {
444 if ( ((*tmpfile)[i] = tempnam( centdir, NULL )) == NULL ) {
449 if ( ((*ldbm)[i] = ldbm_open( (*tmpfile)[i], LDBM_WRCREAT, 0600,
450 ldbmcachesize )) == NULL ) {
451 fprintf( stderr, "ldbm_open of \"%s\" failed\n", (*tmpfile)[i] );
452 perror( "ldbm_open" );
456 (*tmpfile)[i] = NULL;
463 * step through each entry returned from the search and generate
464 * the appropriate centroid values.
468 generate_new_centroids(
476 LDAPMessage *res, *e;
482 printf( "Generating new centroids for..." );
489 while ( (rc = ldap_result( ld, LDAP_RES_ANY, 0, NULL, &res ))
490 == LDAP_RES_SEARCH_ENTRY ) {
492 e = ldap_first_entry( ld, res );
493 dn = ldap_get_dn( ld, e );
495 /* for each attr we want to generate a centroid for */
496 for ( i = 0; attrs[i] != NULL; i++ ) {
497 if ( (val = ldap_get_values( ld, e, attrs[i] )) == NULL ) {
502 for ( j = 0; val[j] != NULL; j++ ) {
503 /* normalize the value */
504 for ( s = val[j]; *s; s++ ) {
505 if ( isascii( *s ) ) {
510 if ( isascii( last ) && isdigit( last ) ) {
514 /* generate a value-based centroid */
515 if ( centroidvalues == CENTROID_VALUE ) {
517 key.dsize = strlen( key.dptr ) + 1;
518 (void) ldbm_store( ldbm[i], key, data, LDBM_INSERT );
520 /* generate a word-based centroid */
522 for ( w = strtok( val[j], WORD_BREAKS ); w != NULL;
523 w = strtok( NULL, WORD_BREAKS ) ) {
525 key.dsize = strlen( key.dptr ) + 1;
526 (void) ldbm_store( ldbm[i], key, data, LDBM_INSERT );
530 ldap_value_free( val );
539 printf( "%d entries\n", count );
546 * compare the old and new centroids, generating the appropriate add
547 * and delete operations. if the underlying database is ordered, we
548 * can do this more efficiently.
564 char **avals, **dvals;
565 int amax, acur, dmax, dcur;
568 #ifdef HAVE_BERKELEY_DB2
571 #endif /* HAVE_BERKELEY_DB2 */
574 printf( "Generating mods for differential %s centroid...", attr );
578 if ( (mods = (LDAPMod **) malloc( sizeof(LDAPMod *) * 4 )) == NULL ||
579 (mods[0] = (LDAPMod *) malloc( sizeof(LDAPMod) )) == NULL ||
580 (mods[1] = (LDAPMod *) malloc( sizeof(LDAPMod) )) == NULL ||
581 (mods[2] = (LDAPMod *) malloc( sizeof(LDAPMod) )) == NULL ||
582 (vals = (char **) malloc( 2 * sizeof(char *) )) == NULL ||
583 (vals[0] = (char *) malloc( 20 )) == NULL )
588 /* add values in mods[0] */
589 mods[0]->mod_op = LDAP_MOD_ADD;
590 mods[0]->mod_type = attr;
591 mods[0]->mod_values = NULL;
594 /* delete values in mods[1] */
595 mods[1]->mod_op = LDAP_MOD_DELETE;
596 mods[1]->mod_type = attr;
597 mods[1]->mod_values = NULL;
600 /* number of entries in mods[2] */
601 sprintf( vals[0], "%d", nentries );
603 mods[2]->mod_op = LDAP_MOD_REPLACE;
604 mods[2]->mod_type = "nentries";
605 mods[2]->mod_values = vals;
606 /* null terminate list of mods */
611 * if the underlying database is ordered, we can do a more efficient
612 * dual traversal, yielding O(N) performance.
617 #ifdef HAVE_BERKELEY_DB2
618 for ( okey = ldbm_firstkey( oldbm, &ocursorp ),
619 nkey = ldbm_firstkey( nldbm, &ncursorp );
620 okey.dptr != NULL && nkey.dptr != NULL; )
622 for ( okey = ldbm_firstkey( oldbm ), nkey = ldbm_firstkey( nldbm );
623 okey.dptr != NULL && nkey.dptr != NULL; )
626 int rc = strcmp( okey.dptr, nkey.dptr );
629 /* value is in both places - leave it */
630 if ( olast.dptr != NULL ) {
631 ldbm_datum_free( oldbm, olast );
634 if ( nlast.dptr != NULL ) {
635 ldbm_datum_free( nldbm, nlast );
639 #ifdef HAVE_BERKELEY_DB2
640 okey = ldbm_nextkey( oldbm, olast, ocursorp );
641 nkey = ldbm_nextkey( nldbm, nlast, ncursorp );
643 okey = ldbm_nextkey( oldbm, olast );
644 nkey = ldbm_nextkey( nldbm, nlast );
646 } else if ( rc > 0 ) {
647 /* new value is not in old centroid - add it */
648 if ( charray_add_dup( &avals, &acur, &amax, nkey.dptr ) == NULL ) {
649 ldap_mods_free( mods, 1 );
653 if ( nlast.dptr != NULL ) {
654 ldbm_datum_free( nldbm, nlast );
658 #ifdef HAVE_BERKELEY_DB2
659 nkey = ldbm_nextkey( nldbm, nlast, ncursorp );
661 nkey = ldbm_nextkey( nldbm, nlast );
664 /* old value is not in new centroid - delete it */
665 if ( charray_add_dup( &dvals, &dcur, &dmax, okey.dptr ) == NULL ) {
666 ldap_mods_free( mods, 1 );
670 if ( olast.dptr != NULL ) {
671 ldbm_datum_free( oldbm, olast );
675 #ifdef HAVE_BERKELEY_DB2
676 okey = ldbm_nextkey( oldbm, olast, ocursorp );
678 okey = ldbm_nextkey( oldbm, olast );
683 while ( okey.dptr != NULL ) {
684 if ( charray_add_dup( &dvals, &dcur, &dmax, okey.dptr ) == NULL ) {
685 ldap_mods_free( mods, 1 );
689 #ifdef HAVE_BERKELEY_DB2
690 okey = ldbm_nextkey( oldbm, olast, ocursorp );
692 okey = ldbm_nextkey( oldbm, olast );
694 if ( olast.dptr != NULL ) {
695 ldbm_datum_free( oldbm, olast );
699 if ( olast.dptr != NULL ) {
700 ldbm_datum_free( oldbm, olast );
702 while ( nkey.dptr != NULL ) {
703 if ( charray_add_dup( &avals, &acur, &amax, nkey.dptr ) == NULL ) {
704 ldap_mods_free( mods, 1 );
708 #ifdef HAVE_BERKELEY_DB2
709 nkey = ldbm_nextkey( nldbm, nlast, ncursorp );
711 nkey = ldbm_nextkey( nldbm, nlast );
713 if ( nlast.dptr != NULL ) {
714 ldbm_datum_free( nldbm, nlast );
718 if ( nlast.dptr != NULL ) {
719 ldbm_datum_free( nldbm, nlast );
723 * if the underlying database is not ordered, we have to
724 * generate list of values to add by stepping through all new
725 * values and looking them up in the old centroid (not there => add),
726 * then stepping through all old values and looking them up in the
727 * new centroid (not there => delete). this yields O(Nf(N)) performance,
728 * where f(N) is the order to retrieve a single item.
731 /* generate list of values to add */
733 #ifdef HAVE_BERKELEY_DB2
734 for ( key = ldbm_firstkey( nldbm, &ncursorp ); key.dptr != NULL;
735 key = ldbm_nextkey( nldbm, lastkey, ncursorp ) )
737 for ( key = ldbm_firstkey( nldbm ); key.dptr != NULL;
738 key = ldbm_nextkey( nldbm, lastkey ) )
741 /* see if it's in the old one */
742 data = ldbm_fetch( oldbm, key );
744 /* not there - add it */
745 if ( data.dptr == NULL ) {
746 if ( charray_add_dup( &avals, &acur, &amax, key.dptr ) == NULL ) {
747 ldap_mods_free( mods, 1 );
751 ldbm_datum_free( oldbm, data );
753 if ( lastkey.dptr != NULL ) {
754 ldbm_datum_free( nldbm, lastkey );
758 if ( lastkey.dptr != NULL ) {
759 ldbm_datum_free( nldbm, lastkey );
762 /* generate list of values to delete */
764 #ifdef HAVE_BERKELEY_DB2
765 for ( key = ldbm_firstkey( oldbm, &ocursorp ); key.dptr != NULL;
766 key = ldbm_nextkey( oldbm, lastkey, ocursorp ) )
768 for ( key = ldbm_firstkey( oldbm ); key.dptr != NULL;
769 key = ldbm_nextkey( oldbm, lastkey ) )
772 /* see if it's in the new one */
773 data = ldbm_fetch( nldbm, key );
775 /* not there - delete it */
776 if ( data.dptr == NULL ) {
777 if ( charray_add_dup( &dvals, &dcur, &dmax, key.dptr ) == NULL ) {
778 ldap_mods_free( mods, 1 );
782 ldbm_datum_free( nldbm, data );
784 if ( lastkey.dptr != NULL ) {
785 ldbm_datum_free( oldbm, lastkey );
789 if ( lastkey.dptr != NULL ) {
790 ldbm_datum_free( oldbm, lastkey );
794 mods[0]->mod_values = avals;
795 mods[1]->mod_values = dvals;
802 if ( mods[1]->mod_values == NULL ) {
803 free( (char *) mods[1] );
806 if ( mods[0]->mod_values == NULL ) {
807 free( (char *) mods[0] );
811 if ( mods[0] == NULL ) {
812 free( (char *) mods );
831 #ifdef HAVE_BERKELEY_DB2
836 printf( "Generating mods for full %s centroid...", attr );
840 if ( (mods = (LDAPMod **) malloc( sizeof(LDAPMod *) * 3 )) == NULL ||
841 (mods[0] = (LDAPMod *) malloc( sizeof(LDAPMod) )) == NULL ||
842 (mods[1] = (LDAPMod *) malloc( sizeof(LDAPMod) )) == NULL ||
843 (vals = (char **) malloc( 2 * sizeof(char *) )) == NULL ||
844 (vals[0] = (char *) malloc( 20 )) == NULL )
849 mods[0]->mod_op = LDAP_MOD_REPLACE;
850 mods[0]->mod_type = attr;
851 mods[0]->mod_values = NULL;
852 sprintf( vals[0], "%d", nentries );
854 mods[1]->mod_op = LDAP_MOD_REPLACE;
855 mods[1]->mod_type = "nentries";
856 mods[1]->mod_values = vals;
862 #ifdef HAVE_BERKELEY_DB2
863 for ( key = ldbm_firstkey( ldbm, &cursorp ); key.dptr != NULL;
864 key = ldbm_nextkey( ldbm, lastkey, cursorp ) )
866 for ( key = ldbm_firstkey( ldbm ); key.dptr != NULL;
867 key = ldbm_nextkey( ldbm, lastkey ) )
870 if ( charray_add_dup( &vals, &vcur, &vmax, key.dptr ) == NULL ) {
871 ldap_mods_free( mods, 1 );
875 if ( lastkey.dptr != NULL ) {
876 ldbm_datum_free( ldbm, lastkey );
880 if ( lastkey.dptr != NULL ) {
881 ldbm_datum_free( ldbm, lastkey );
883 mods[0]->mod_values = vals;
890 if ( mods[0]->mod_values == NULL ) {
891 free( (char *) mods[0] );
892 free( (char *) mods );
900 * extract the destination ldap host, port, and base object for the
901 * server to receive the index information. then, open a connection,
902 * bind, and see if the entry exists. if not, create it and set things
903 * up so the centroid full and diff routines can modify it to contain
904 * the new centroid information.
908 bind_to_destination_ldap(
917 char *attrs[2], *refvalues[2], *ocvalues[2];
923 printf( "Binding to destination LDAP server..." );
927 /* first, pick out the destination ldap server info */
928 if ( ldapbase != NULL ) {
932 if ( strncmp( ldapdesturl, "ldap://", 7 ) != 0 ) {
933 fputs( "Not an LDAP URL", stderr ); /* Should be smarter? */
937 if ( (s2 = strchr( s, '/' )) == NULL ) {
938 ldapbase = strdup( s );
942 if ( ldaphost != NULL )
944 ldaphost = strdup( s );
947 ldapbase = strdup( s2 + 1 );
949 strcpy( buf, "ref=" );
950 if ( strpbrk( ldapsrcurl, " ,;" ) != NULL ) {
953 for ( s = d = ldapsrcurl; *s; s++ ) {
959 strcat( buf, ldapsrcurl );
960 if ( strpbrk( ldapsrcurl, " ,;" ) != NULL ) {
964 strcat( buf, ldapbase );
966 ldapbase = strdup( buf );
968 if ( (ld = ldap_open( ldaphost, LDAP_PORT )) == NULL ) {
969 perror( "ldap_open" );
973 if ( ldap_bind_s( ld, destldapbinddn, destldappasswd, destldapauthmethod )
975 ldap_perror( ld, "ldap_bind_s" );
985 rc = ldap_search_s( ld, ldapbase, LDAP_SCOPE_BASE, "(objectclass=*)",
989 if ( rc == LDAP_NO_SUCH_OBJECT ) {
991 printf( "%sCreating centroid entry...", not ? "Not " : "" );
995 /* create the centroid index entry */
997 m[0].mod_type = "ref";
998 refvalues[0] = ldapsrcurl;
1000 m[0].mod_values = refvalues;
1002 m[1].mod_type = "objectclass";
1003 ocvalues[0] = "indexentry";
1005 m[1].mod_values = ocvalues;
1010 if ( !not && ldap_add_s( ld, ldapbase, mp ) != LDAP_SUCCESS ) {
1011 ldap_perror( ld, ldapbase );
1020 } else if ( rc != LDAP_SUCCESS ) {
1021 ldap_perror( ld, "ldap_search_s" );
1040 *a = (char **) malloc( (BUFSIZ + 1) * sizeof(char *) );
1043 } else if ( *cur >= *max ) {
1045 *a = (char **) realloc( *a, (*max + 1) * sizeof(char *) );
1051 (*a)[(*cur)++] = strdup( s );