/* $OpenLDAP$ */
/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
*
- * Copyright 1998-2005 The OpenLDAP Foundation.
+ * Copyright 1998-2007 The OpenLDAP Foundation.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
#include "slurp.h"
#include "globals.h"
+#include "lutil.h"
/* Forward references */
static Rh *get_repl_hosts LDAP_P(( char *, int *, char ** ));
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 = atol( 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 );
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 );
}
}
+#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
}
}
}
+#endif /* 0 */
}
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 && re->re_replicas[ i ].rh_hostname != NULL; i++ ) {
if ( fprintf( fp, "replica: %s:%d\n",