X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=servers%2Fslurpd%2Fre.c;h=591db0d6462d41a2fd322df5d1583b6c98ce11ca;hb=93d5e01390d334e2173d33932a76287959a745aa;hp=b5195b2f5be1b6d623cb512b9f4684f6e6ec86a8;hpb=a93a15d9fc460963c111f66cf0f3995e5a2f5d42;p=openldap diff --git a/servers/slurpd/re.c b/servers/slurpd/re.c index b5195b2f5b..591db0d646 100644 --- a/servers/slurpd/re.c +++ b/servers/slurpd/re.c @@ -1,10 +1,18 @@ /* $OpenLDAP$ */ -/* - * Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved. - * COPYING RESTRICTIONS APPLY, see COPYRIGHT file +/* This work is part of OpenLDAP Software . + * + * Copyright 1998-2006 The OpenLDAP Foundation. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted only as authorized by the OpenLDAP + * Public License. + * + * A copy of this license is available in file LICENSE in the + * top-level directory of the distribution or, alternatively, at + * . */ -/* - * Copyright (c) 1996 Regents of the University of Michigan. +/* Portions Copyright (c) 1996 Regents of the University of Michigan. * All rights reserved. * * Redistribution and use in source and binary forms are permitted @@ -14,6 +22,10 @@ * software without specific prior written permission. This software * is provided ``as is'' without express or implied warranty. */ +/* ACKNOWLEDGEMENTS: + * This work was originally developed by the University of Michigan + * (as part of U-MICH LDAP). + */ /* * re.c - routines which deal with Re (Replication entry) structures. @@ -27,15 +39,17 @@ #include +#include #include #include #include #include +#include "../slapd/slap.h" + #include "slurp.h" #include "globals.h" - -#include "../slapd/slap.h" +#include "lutil.h" /* Forward references */ static Rh *get_repl_hosts LDAP_P(( char *, int *, char ** )); @@ -88,7 +102,6 @@ Re_free( ldap_pvt_thread_mutex_destroy( &re->re_mutex ); - ch_free( re->re_timestamp ); if (( rh = re->re_replicas ) != NULL ) { for ( i = 0; rh[ i ].rh_hostname != NULL; i++ ) { free( rh[ i ].rh_hostname ); @@ -175,17 +188,30 @@ Re_parse( re->re_changetype = getchangetype( value ); state |= GOT_CHANGETYPE; break; - case T_TIME: + case T_TIME: { + unsigned long t; + if (( p = strchr( value, '.' )) != NULL ) { /* there was a sequence number */ *p++ = '\0'; } - re->re_timestamp = strdup( value ); - if ( p != NULL && isdigit( (unsigned char) *p )) { - re->re_seq = atoi( p ); + if ( lutil_atoul( &t, value ) != 0 ) { + Debug( LDAP_DEBUG_ANY, + "Error: Re_parse: unable to parse timestamp \"%s\"\n", + value, 0, 0 ); + return -1; + } + re->re_timestamp = (time_t)t; + if ( p != NULL && isdigit( (unsigned char) *p ) + && lutil_atoi( &re->re_seq, p ) != 0 ) + { + Debug( LDAP_DEBUG_ANY, + "Error: Re_parse: unable to parse sequence number \"%s\"\n", + p, 0, 0 ); + return -1; } state |= GOT_TIME; - break; + } break; case T_DN: re->re_dn = ch_malloc( len + 1 ); AC_MEMCPY( re->re_dn, value, len ); @@ -198,14 +224,12 @@ Re_parse( "Error: Re_parse: bad type <%s>\n", type, 0, 0 ); free( type ); - if ( value != NULL ) - free( value ); + free( value ); return -1; } } free( type ); - if ( value != NULL ) - free( value ); + free( value ); } if ( state != GOT_ALL ) { @@ -311,12 +335,12 @@ get_repl_hosts( if ( ldif_parse_line( line, &type, &value, &len ) < 0 ) { return( NULL ); } - port = 0; + port = LDAP_PORT; if (( p = strchr( value, ':' )) != NULL ) { *p = '\0'; p++; - if ( *p != '\0' ) { - port = atoi( p ); + if ( *p != '\0' && lutil_atoi( &port, p ) != 0 ) { + return( NULL ); } } @@ -334,8 +358,7 @@ get_repl_hosts( free( type ); if ( !repl_ok ) { warn_unknown_replica( value, port ); - if ( value != NULL ) - free( value ); + free( value ); continue; } @@ -349,8 +372,7 @@ get_repl_hosts( rh[ nreplicas ].rh_port = port; nreplicas++; - if ( value != NULL ) - free( value ); + free( value ); } if ( nreplicas == 0 ) { @@ -415,6 +437,7 @@ getchangetype( +#if 0 /* * Find the first line which is not a "replica:" line in buf. * Returns a pointer to the line. Returns NULL if there are @@ -440,6 +463,7 @@ skip_replica_lines( } } } +#endif /* 0 */ @@ -463,7 +487,7 @@ Re_dump( } fprintf( fp, "Re_dump: ******\n" ); fprintf( fp, "re_refcnt: %d\n", re->re_refcnt ); - fprintf( fp, "re_timestamp: %s\n", re->re_timestamp ); + fprintf( fp, "re_timestamp: %ld\n", (long) re->re_timestamp ); fprintf( fp, "re_seq: %d\n", re->re_seq ); for ( i = 0; re->re_replicas && re->re_replicas[ i ].rh_hostname != NULL; i++ ) { @@ -534,13 +558,20 @@ Re_write( } if ( ri != NULL ) { /* write a single "replica:" line */ - if ( fprintf( fp, "replica: %s:%d\n", ri->ri_hostname, - ri->ri_port ) < 0 ) { + if ( ri->ri_port != 0 ) { + rc = fprintf( fp, "replica: %s:%d\n", ri->ri_hostname, + ri->ri_port ); + } else { + rc = fprintf( fp, "replica: %s\n", ri->ri_hostname ); + } + if ( rc < 0 ) { rc = -1; goto bad; } + rc = 0; + } else { /* write multiple "replica:" lines */ - for ( i = 0; re->re_replicas[ i ].rh_hostname != NULL; i++ ) { + for ( i = 0; re->re_replicas && re->re_replicas[ i ].rh_hostname != NULL; i++ ) { if ( fprintf( fp, "replica: %s:%d\n", re->re_replicas[ i ].rh_hostname, re->re_replicas[ i ].rh_port ) < 0 ) { @@ -549,7 +580,7 @@ Re_write( } } } - if ( fprintf( fp, "time: %s.%d\n", re->re_timestamp, re->re_seq ) < 0 ) { + if ( fprintf( fp, "time: %ld.%d\n", (long) re->re_timestamp, re->re_seq ) < 0 ) { rc = -1; goto bad; } @@ -713,7 +744,7 @@ Re_init( /* Initialize private data */ (*re)->re_refcnt = sglob->num_replicas; - (*re)->re_timestamp = NULL; + (*re)->re_timestamp = (time_t) 0L; (*re)->re_replicas = NULL; (*re)->re_dn = NULL; (*re)->re_changetype = 0;