]> git.sur5r.net Git - openldap/blob - servers/slurpd/re.c
improve previous commit; now special limit on the number of total entries of a paged...
[openldap] / servers / slurpd / re.c
1 /* $OpenLDAP$ */
2 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
3  *
4  * Copyright 1998-2004 The OpenLDAP Foundation.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted only as authorized by the OpenLDAP
9  * Public License.
10  *
11  * A copy of this license is available in file LICENSE in the
12  * top-level directory of the distribution or, alternatively, at
13  * <http://www.OpenLDAP.org/license.html>.
14  */
15 /* Portions Copyright (c) 1996 Regents of the University of Michigan.
16  * All rights reserved.
17  *
18  * Redistribution and use in source and binary forms are permitted
19  * provided that this notice is preserved and that due credit is given
20  * to the University of Michigan at Ann Arbor. The name of the University
21  * may not be used to endorse or promote products derived from this
22  * software without specific prior written permission. This software
23  * is provided ``as is'' without express or implied warranty.
24  */
25 /* ACKNOWLEDGEMENTS:
26  * This work was originally developed by the University of Michigan
27  * (as part of U-MICH LDAP).
28  */
29
30 /* 
31  * re.c - routines which deal with Re (Replication entry) structures.
32  * An Re struct is an in-core representation of one replication to
33  * be performed, along with member functions which are called by other
34  * routines.  The Re struct is defined in slurp.h.
35  */
36
37
38 #include "portable.h"
39
40 #include <stdio.h>
41
42 #include <ac/stdlib.h>
43 #include <ac/errno.h>
44 #include <ac/socket.h>
45 #include <ac/string.h>
46 #include <ac/ctype.h>
47
48 #include "../slapd/slap.h"
49
50 #include "slurp.h"
51 #include "globals.h"
52
53 /* Forward references */
54 static Rh       *get_repl_hosts LDAP_P(( char *, int *, char ** ));
55 static int      gettype LDAP_P(( char * ));
56 static int      getchangetype LDAP_P(( char * ));
57 static int      Re_parse LDAP_P(( Re *re, char *replbuf ));
58 static void     Re_dump LDAP_P(( Re *re, FILE *fp ));
59 static void     warn_unknown_replica LDAP_P(( char *, int port ));
60
61 /* Globals, scoped within this file */
62 static int      nur = 0;        /* Number of unknown replicas */
63 static Rh       *ur = NULL;     /* array of unknown replica names */
64
65
66 /*
67  * Return the next Re in a linked list.
68  */
69 static Re *
70 Re_getnext(
71     Re  *re
72 )
73 {
74     return(( re == NULL ) ? NULL :  re->re_next );
75 }
76
77
78
79
80 /*
81  * Free an Re
82  * ??? Something should apparently return nonzero here, but I dont know what.
83  */
84 static int
85 Re_free(
86     Re  *re
87 )
88 {
89     Rh  *rh;
90     Mi  *mi;
91     int i;
92
93     if ( re == NULL ) {
94         return 0;
95     }
96     if ( re->re_refcnt > 0 ) {
97 #ifdef NEW_LOGGING
98         LDAP_LOG ( SLURPD, WARNING, "Re_free: "
99                 "Warning: freeing re (dn: %s) with nonzero refcnt\n", re->re_dn, 0, 0 );
100 #else
101         Debug( LDAP_DEBUG_ANY,
102                 "Warning: freeing re (dn: %s) with nonzero refcnt\n",
103                 re->re_dn, 0, 0 );
104 #endif
105     }
106
107     ldap_pvt_thread_mutex_destroy( &re->re_mutex );
108
109     if (( rh = re->re_replicas ) != NULL ) {
110         for ( i = 0; rh[ i ].rh_hostname != NULL; i++ ) {
111             free( rh[ i ].rh_hostname );
112         }
113         free( rh );
114     }
115     ch_free( re->re_dn );
116     if (( mi = re->re_mods ) != NULL ) {
117         for ( i = 0; mi[ i ].mi_type != NULL; i++ ) {
118             free( mi[ i ].mi_type );
119             ch_free( mi[ i ].mi_val );
120         }
121         free( mi );
122     }
123     free( re );
124     return 0;
125 }
126
127
128
129
130 /*
131  * Read a buffer of data from a replication log file and fill in
132  * an (already allocated) Re.
133  */
134
135 #define BEGIN           0
136 #define GOT_DN          1
137 #define GOT_TIME        2
138 #define GOT_CHANGETYPE  4
139 #define GOT_ALL         ( GOT_DN | GOT_TIME | GOT_CHANGETYPE )
140
141 static int
142 Re_parse(
143     Re          *re,
144     char        *replbuf
145 )
146 {
147     int                 state;
148     int                 nml;
149     char                *buf, *rp, *p;
150     size_t              buflen;
151     char                *type, *value;
152     ber_len_t   len;
153     int                 nreplicas;
154
155     if ( re == NULL ) {
156 #ifdef NEW_LOGGING
157         LDAP_LOG ( SLURPD, ERR, "Re_parse: Error: re is NULL\n", 0, 0, 0 );
158 #else
159         Debug( LDAP_DEBUG_ANY, "Re_parse: error: re is NULL\n", 0, 0, 0 );
160 #endif
161         return -1;
162     }
163     if ( replbuf == NULL ) {
164 #ifdef NEW_LOGGING
165         LDAP_LOG ( SLURPD, ERR, "Re_parse: Error: replbuf is NULL\n", 0, 0, 0 );
166 #else
167         Debug( LDAP_DEBUG_ANY, "Re_parse: error: replbuf is NULL\n", 0, 0, 0 );
168 #endif
169         return -1;
170     }
171
172     state = BEGIN;
173     nml = 0;    /* number of modification information entries */
174     rp = replbuf;
175
176     re->re_replicas = get_repl_hosts( replbuf, &nreplicas, &rp );
177     re->re_refcnt = sglob->num_replicas;
178
179     for (;;) {
180         if (( state == GOT_ALL ) || ( buf = ldif_getline( &rp )) == NULL ) {
181             break;
182         }
183         /*
184          * If we're processing a rejection log, then the first line
185          * of each replication record will begin with "ERROR" - just
186          * ignore it.
187          */
188         if ( strncmp( buf, ERROR_STR, strlen( ERROR_STR )) == 0 ) {
189             continue;
190         }
191         buflen = strlen( buf );
192         if ( ldif_parse_line( buf, &type, &value, &len ) < 0 ) {
193 #ifdef NEW_LOGGING
194                 LDAP_LOG ( SLURPD, ERR, 
195                         "Re_parse: Error: malformed replog file\n", 0, 0, 0 );
196 #else
197             Debug( LDAP_DEBUG_ANY,
198                     "Error: Re_parse: malformed replog file\n",
199                     0, 0, 0 );
200 #endif
201             return -1;
202         }
203         switch ( gettype( type )) {
204         case T_CHANGETYPE:
205             re->re_changetype = getchangetype( value );
206             state |= GOT_CHANGETYPE;
207             break;
208         case T_TIME:
209             if (( p = strchr( value, '.' )) != NULL ) {
210                 /* there was a sequence number */
211                 *p++ = '\0';
212             }
213             re->re_timestamp = atol( value );
214             if ( p != NULL && isdigit( (unsigned char) *p )) {
215                 re->re_seq = atoi( p );
216             }
217             state |= GOT_TIME;
218             break;
219         case T_DN:
220             re->re_dn = ch_malloc( len + 1 );
221                 AC_MEMCPY( re->re_dn, value, len );
222                 re->re_dn[ len ]='\0';
223             state |= GOT_DN;
224             break;
225         default:
226             if ( !( state == GOT_ALL )) {
227 #ifdef NEW_LOGGING
228                 LDAP_LOG ( SLURPD, ERR, 
229                         "Re_parse: Error: bad type <%s>\n", type, 0, 0 );
230 #else
231                 Debug( LDAP_DEBUG_ANY,
232                         "Error: Re_parse: bad type <%s>\n",
233                         type, 0, 0 );
234 #endif
235                 free( type );
236                 free( value );
237                 return -1;
238             }
239         }
240         free( type );
241         free( value );
242     }
243
244     if ( state != GOT_ALL ) {
245 #ifdef NEW_LOGGING
246         LDAP_LOG ( SLURPD, ERR, 
247                 "Re_parse: Error: malformed replog file\n", 0, 0, 0 );
248 #else
249         Debug( LDAP_DEBUG_ANY,
250                 "Error: Re_parse: malformed replog file\n",
251                 0, 0, 0 );
252 #endif
253         return -1;
254     }
255
256     for (;;) {
257         char *const dash = "-";
258
259         if (( buf = ldif_getline( &rp )) == NULL ) {
260             break;
261         }
262         buflen = strlen( buf );
263         if (( buflen == 1 ) && ( buf[ 0 ] == '-' )) {
264             type  = dash;
265             value = NULL;
266         } else {
267             if ( ldif_parse_line( buf, &type, &value, &len ) < 0 ) {
268 #ifdef NEW_LOGGING
269                 LDAP_LOG ( SLURPD, ERR, 
270                         "Re_parse: Error: malformed replog line \"%s\"\n", buf, 0, 0 );
271 #else
272                 Debug( LDAP_DEBUG_ANY,
273                         "Error: malformed replog line \"%s\"\n",
274                         buf, 0, 0 );
275 #endif
276                 return -1;
277             }
278         }
279         re->re_mods = ( Mi  *) ch_realloc( (char *) re->re_mods,
280             sizeof( Mi ) * ( nml + 2 ));
281         re->re_mods[ nml ].mi_type = strdup( type );
282         if ( value != NULL ) {
283             re->re_mods[ nml ].mi_val = ch_malloc( len + 1 );
284                 AC_MEMCPY( re->re_mods[ nml ].mi_val, value, len );
285                 re->re_mods[ nml ].mi_val[ len ] = '\0';
286             re->re_mods[ nml ].mi_len = len;
287         } else {
288             re->re_mods[ nml ].mi_val = NULL;
289             re->re_mods[ nml ].mi_len = 0;
290         }
291         re->re_mods[ nml + 1 ].mi_type = NULL;
292         re->re_mods[ nml + 1 ].mi_val = NULL;
293         nml++;
294
295         if ( type != dash )
296                 free( type );
297         if ( value != NULL )
298                 free( value );
299     }
300     return 0;
301 }
302
303
304
305 /*
306  * Extract the replication hosts from a repl buf.  Check to be sure that
307  * each replica host and port number are ones we know about (that is, they're
308  * in the slapd config file we read at startup).  Without that information
309  * from the config file, we won't have the appropriate credentials to
310  * make modifications.  If there are any unknown replica names, don't
311  * add them the the Re struct.  Instead, log a warning message.
312  */
313 static Rh *
314 get_repl_hosts(
315     char        *replbuf,
316     int         *r_nreplicas,
317     char        **r_rp
318 )
319 {
320     char                *type, *value, *line, *p;
321     Rh                  *rh = NULL;
322     int                 nreplicas;
323         ber_len_t       len;
324     int                 port;
325     int                 repl_ok;
326     int                 i;
327
328     if ( replbuf == NULL ) {
329         return( NULL );
330     }
331
332     nreplicas = 0;
333
334     /*
335      * Get the host names of the replicas
336      */
337     *r_nreplicas = 0;
338     *r_rp = replbuf;
339     for (;;) {
340         /* If this is a reject log, we need to skip over the ERROR: line */
341         if ( !strncmp( *r_rp, ERROR_STR, strlen( ERROR_STR ))) {
342             line = ldif_getline( r_rp );
343             if ( line == NULL ) {
344                 break;
345             }
346         }
347         if ( strncasecmp( *r_rp, "replica:", 7 )) {
348             break;
349         }
350         line = ldif_getline( r_rp );
351         if ( line == NULL ) {
352             break;
353         }
354         if ( ldif_parse_line( line, &type, &value, &len ) < 0 ) {
355             return( NULL );
356         }
357         port = 0;
358         if (( p = strchr( value, ':' )) != NULL ) {
359             *p = '\0';
360             p++;
361             if ( *p != '\0' ) {
362                 port = atoi( p );
363             }
364         }
365
366         /* Verify that we've heard of this replica before */
367         repl_ok = 0;
368         for ( i = 0; i < sglob->num_replicas; i++ ) {
369             if ( strcmp( sglob->replicas[ i ]->ri_hostname, value )) {
370                 continue;
371             }
372             if ( sglob->replicas[ i ]->ri_port == port ) {
373                 repl_ok = 1;
374                 break;
375             }
376         }
377         free( type );
378         if ( !repl_ok ) {
379             warn_unknown_replica( value, port );
380             free( value );
381             continue;
382         }
383
384         rh = (Rh *) ch_realloc((char *) rh, ( nreplicas + 2 ) * sizeof( Rh ));
385         if ( rh == NULL ) {
386 #ifdef NEW_LOGGING
387                 LDAP_LOG ( SLURPD, ERR, 
388                         "get_repl_hosts: Out of memory\n", 0, 0, 0 );
389 #else
390             Debug( LDAP_DEBUG_ANY, "Out of memory in get_repl_hosts\n",
391                     0, 0, 0 );
392 #endif
393             return NULL;
394         }
395         rh[ nreplicas ].rh_hostname = strdup( value );
396         rh[ nreplicas ].rh_port = port;
397         nreplicas++;
398
399         free( value );
400     }
401
402     if ( nreplicas == 0 ) {
403         return( NULL );
404     }
405
406     rh[ nreplicas ].rh_hostname = NULL;
407     *r_nreplicas = nreplicas;
408
409     return( rh );
410 }
411
412
413
414
415
416 /*
417  * Convert "type" to an int.
418  */
419 static int
420 gettype(
421     char        *type
422 )
423 {
424     if ( !strcmp( type, T_CHANGETYPESTR )) {
425         return( T_CHANGETYPE );
426     }
427     if ( !strcmp( type, T_TIMESTR )) {
428         return( T_TIME );
429     }
430     if ( !strcmp( type, T_DNSTR )) {
431         return( T_DN );
432     }
433     return( T_ERR );
434 }
435
436
437
438 /*
439  * Convert "changetype" to an int.
440  */
441 static int
442 getchangetype(
443     char        *changetype
444 )
445 {
446     if ( !strcmp( changetype, T_ADDCTSTR )) {
447         return( T_ADDCT );
448     }
449     if ( !strcmp( changetype, T_MODIFYCTSTR )) {
450         return( T_MODIFYCT );
451     }
452     if ( !strcmp( changetype, T_DELETECTSTR )) {
453         return( T_DELETECT );
454     }
455     if ( !strcmp( changetype, T_MODRDNCTSTR )) {
456         return( T_MODRDNCT );
457     }
458     return( T_ERR );
459 }
460
461
462
463
464 /*
465  * Find the first line which is not a "replica:" line in buf.
466  * Returns a pointer to the line.  Returns NULL if there are
467  * only "replica:" lines in buf.
468  */
469 static char *
470 skip_replica_lines(
471     char        *buf
472 )
473 {
474     char *p = buf;
475     for (;;) {
476         if ( strncasecmp( p, "replica:", 8 )) {
477             return( p );
478         }
479         while (( *p != '\0' )  && ( *p != '\n' )) {
480             p++;
481         }
482         if ( *p == '\0' ) {
483             return ( NULL );
484         } else {
485             p++;
486         }
487     }
488 }
489
490
491
492
493 /*
494  * For debugging purposes: dump the contents of a replication entry.
495  * to the given stream.
496  */
497 static void
498 Re_dump(
499     Re          *re,
500     FILE        *fp
501 )
502 {
503     int i;
504     Mi *mi;
505
506     if ( re == NULL ) {
507 #ifdef NEW_LOGGING
508         LDAP_LOG ( SLURPD, ERR, "Re_dump: re is NULL\n", 0, 0, 0 );
509 #else
510         Debug( LDAP_DEBUG_TRACE, "Re_dump: re is NULL\n", 0, 0, 0 );
511 #endif
512         return;
513     }
514     fprintf( fp, "Re_dump: ******\n" );
515     fprintf( fp, "re_refcnt: %d\n", re->re_refcnt );
516     fprintf( fp, "re_timestamp: %ld\n", (long) re->re_timestamp );
517     fprintf( fp, "re_seq: %d\n", re->re_seq );
518     for ( i = 0; re->re_replicas && re->re_replicas[ i ].rh_hostname != NULL;
519                 i++ ) {
520         fprintf( fp, "re_replicas[%d]: %s:%d\n", 
521                 i, re->re_replicas[ i ].rh_hostname,
522                 re->re_replicas[ i ].rh_port );
523     }
524     fprintf( fp, "re_dn: %s\n", re->re_dn );
525     switch ( re->re_changetype ) {
526     case T_ADDCT:
527         fprintf( fp, "re_changetype: add\n" );
528         break;
529     case T_MODIFYCT:
530         fprintf( fp, "re_changetype: modify\n" );
531         break;
532     case T_DELETECT:
533         fprintf( fp, "re_changetype: delete\n" );
534         break;
535     case T_MODRDNCT:
536         fprintf( fp, "re_changetype: modrdn\n" );
537         break;
538     default:
539         fprintf( fp, "re_changetype: (unknown, type = %d\n",
540                 re->re_changetype );
541     }
542     if ( re->re_mods == NULL ) {
543         fprintf( fp, "re_mods: (none)\n" );
544     } else {
545         mi = re->re_mods;
546         fprintf( fp, "re_mods:\n" );
547         for ( i = 0; mi[ i ].mi_type != NULL; i++ ) {
548             fprintf( fp, "  %s, \"%s\", (%d bytes)\n",
549                     mi[ i ].mi_type,
550                     mi[ i ].mi_val == NULL ?  "(null)" : mi[ i ].mi_val,
551                     mi[ i ].mi_len );
552         }
553     }
554     return;
555 }
556
557
558 /* 
559  * Given an Ri, an Re, and a file pointer, write a replication record to
560  * the file pointer.  If ri is NULL, then include all replicas in the
561  * output.  If ri is non-NULL, then only include a single "replica:" line
562  * (used when writing rejection records).  Returns 0 on success, -1
563  * on failure.  Note that Re_write will not write anything out if the
564  * refcnt is zero.
565  */
566 static int
567 Re_write(
568     Ri          *ri,
569     Re          *re,
570     FILE        *fp )
571 {
572     int         i;
573     char        *s;
574     int         rc = 0;
575
576     if ( re == NULL || fp == NULL ) {
577 #ifdef NEW_LOGGING
578         LDAP_LOG ( SLURPD, ERR, 
579                 "Re_write: Internal error: NULL argument\n", 0, 0, 0 );
580 #else
581         Debug( LDAP_DEBUG_ANY, "Internal error: Re_write: NULL argument\n",
582                 0, 0, 0 );
583 #endif
584         return -1;
585     }
586
587     if ( re->re_refcnt < 1 ) {
588         return 0;               /* this is not an error */
589     }
590
591     if ( ri != NULL ) {         /* write a single "replica:" line */
592         if ( fprintf( fp, "replica: %s:%d\n", ri->ri_hostname,
593                 ri->ri_port ) < 0 ) {
594             rc = -1;
595             goto bad;
596         }
597     } else {                    /* write multiple "replica:" lines */
598         for ( i = 0; re->re_replicas && re->re_replicas[ i ].rh_hostname != NULL; i++ ) {
599             if ( fprintf( fp, "replica: %s:%d\n",
600                     re->re_replicas[ i ].rh_hostname,
601                     re->re_replicas[ i ].rh_port ) < 0 ) {
602                 rc = -1;
603                 goto bad;
604             }
605         }
606     }
607     if ( fprintf( fp, "time: %ld.%d\n", (long) re->re_timestamp, re->re_seq ) < 0 ) {
608         rc = -1;
609         goto bad;
610     }
611     if ( fprintf( fp, "dn: %s\n", re->re_dn ) < 0 ) {
612         rc = -1;
613         goto bad;
614     }
615     if ( fprintf( fp, "changetype: " ) < 0 ) {
616         rc = -1;
617         goto bad;
618     }
619     switch ( re->re_changetype ) {
620     case T_ADDCT:
621         s = T_ADDCTSTR;
622         break;
623     case T_MODIFYCT:
624         s = T_MODIFYCTSTR;
625         break;
626     case T_DELETECT:
627         s = T_DELETECTSTR;
628         break;
629     case T_MODRDNCT:
630         s = T_MODRDNCTSTR;
631         break;
632     default:
633         s = "IllegalModifyType!!!";
634     }
635     if ( fprintf( fp, "%s\n", s ) < 0 ) {
636         rc = -1;
637         goto bad;
638     }
639     for ( i = 0; (( re->re_mods != NULL ) &&
640             ( re->re_mods[ i ].mi_type != NULL )); i++ ) {
641         if ( !strcmp( re->re_mods[ i ].mi_type, T_MODSEPSTR )) {
642             if ( fprintf( fp, "%s\n", T_MODSEPSTR ) < 0 ) {
643                 rc = -1;
644                 goto bad;
645             }
646         } else {
647             char *obuf;
648             obuf = ldif_put( LDIF_PUT_VALUE,
649                         re->re_mods[ i ].mi_type,
650                     re->re_mods[ i ].mi_val ? re->re_mods[ i ].mi_val : "",
651                     re->re_mods[ i ].mi_len );
652             if ( fputs( obuf, fp ) < 0 ) {
653                 rc = -1;
654                 free( obuf );
655                 goto bad;
656             } else {
657                 ber_memfree( obuf );
658             }
659         }
660     }
661     if ( fprintf( fp, "\n" ) < 0 ) {
662         rc = -1;
663         goto bad;
664     }
665     if ( fflush( fp ) != 0 ) {
666         rc = -1;
667         goto bad;
668     }
669 bad:
670     if ( rc != 0 ) {
671 #ifdef NEW_LOGGING
672         LDAP_LOG ( SLURPD, ERR, 
673                 "Re_write: Error while writing: %s\n", sys_errlist[ errno ], 0, 0 );
674 #else
675         Debug( LDAP_DEBUG_ANY, "Error while writing: %s\n",
676                 sys_errlist[ errno ], 0, 0 );
677 #endif
678     }
679     return rc;
680 }
681
682
683
684
685 /*
686  * Decrement the refcnt.  Locking handled internally.
687  */
688 static int
689 Re_decrefcnt(
690     Re  *re
691 )
692 {
693     re->re_lock( re );
694     re->re_refcnt--;
695     re->re_unlock( re );
696     return 0;
697 }
698
699
700
701 /*
702  * Get the refcnt.  Locking handled internally.
703  */
704 static int
705 Re_getrefcnt(
706     Re  *re
707 )
708 {
709     int ret;
710
711     re->re_lock( re );
712     ret = re->re_refcnt;
713     re->re_unlock( re );
714     return ret;
715 }
716     
717     
718
719
720
721 /*
722  * Lock this replication entry
723  */
724 static int
725 Re_lock(
726     Re  *re
727 )
728 {
729     return( ldap_pvt_thread_mutex_lock( &re->re_mutex ));
730 }
731
732
733
734
735 /*
736  * Unlock this replication entry
737  */
738 static int
739 Re_unlock(
740     Re  *re
741 )
742 {
743     return( ldap_pvt_thread_mutex_unlock( &re->re_mutex ));
744 }
745
746
747
748
749 /* 
750  * Instantiate and initialize an Re.
751  */
752 int
753 Re_init(
754     Re **re
755 )
756 {
757     /* Instantiate */
758     (*re) = (Re *) malloc( sizeof( Re ));
759     if ( *re == NULL ) {
760         return -1;
761     }
762
763     /* Fill in the member function pointers */
764     (*re)->re_free = Re_free;
765     (*re)->re_getnext = Re_getnext;
766     (*re)->re_parse = Re_parse;
767     (*re)->re_write = Re_write;
768     (*re)->re_dump = Re_dump;
769     (*re)->re_lock = Re_lock;
770     (*re)->re_unlock = Re_unlock;
771     (*re)->re_decrefcnt = Re_decrefcnt;
772     (*re)->re_getrefcnt = Re_getrefcnt;
773
774     /* Initialize private data */
775    (*re)->re_refcnt = sglob->num_replicas;
776    (*re)->re_timestamp = (time_t) 0L;
777    (*re)->re_replicas = NULL;
778    (*re)->re_dn = NULL;
779    (*re)->re_changetype = 0;
780    (*re)->re_seq = 0;
781    (*re)->re_mods = NULL;
782    (*re)->re_next = NULL;
783
784    ldap_pvt_thread_mutex_init( &((*re)->re_mutex) );
785    return 0;
786 }
787
788
789
790
791 /*
792  * Given a host and port, generate a warning message iff we haven't already
793  * generated a message for this host:port combination.
794  */
795 static void
796 warn_unknown_replica( 
797     char        *host,
798     int         port
799 )
800 {
801     int found = 0;
802     int i;
803
804     for ( i = 0; i < nur; i++ ) {
805         if ( strcmp( ur[ i ].rh_hostname, host )) {
806             continue;
807         }
808         if ( ur[ i ].rh_port == port ) {
809             found = 1;
810             break;
811         }
812     }
813     if ( !found ) {
814 #ifdef NEW_LOGGING
815         LDAP_LOG ( SLURPD, WARNING, "warn_unknown_replica: "
816                 "Warning: unknown replica %s:%d found in replication log\n",
817                 host, port, 0 );
818 #else
819         Debug( LDAP_DEBUG_ANY,
820                 "Warning: unknown replica %s:%d found in replication log\n",
821                 host, port, 0 );
822 #endif
823         nur++;
824         ur = (Rh *) ch_realloc( (char *) ur, ( nur * sizeof( Rh )));
825         ur[ nur - 1 ].rh_hostname = strdup( host );
826         ur[ nur - 1 ].rh_port = port;
827     }
828 }