/* $OpenLDAP$ */
-/*
- * Copyright 1998-2003 The OpenLDAP Foundation, All Rights Reserved.
- * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
+/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
+ *
+ * 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
+ * <http://www.OpenLDAP.org/license.html>.
*/
-/*
- * 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
* 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.
#include "slurp.h"
#include "globals.h"
+#include "lutil.h"
/* Forward references */
static Rh *get_repl_hosts LDAP_P(( char *, int *, char ** ));
return 0;
}
if ( re->re_refcnt > 0 ) {
-#ifdef NEW_LOGGING
- LDAP_LOG ( SLURPD, WARNING, "Re_free: "
- "Warning: freeing re (dn: %s) with nonzero refcnt\n", re->re_dn, 0, 0 );
-#else
Debug( LDAP_DEBUG_ANY,
"Warning: freeing re (dn: %s) with nonzero refcnt\n",
re->re_dn, 0, 0 );
-#endif
}
ldap_pvt_thread_mutex_destroy( &re->re_mutex );
int nreplicas;
if ( re == NULL ) {
-#ifdef NEW_LOGGING
- LDAP_LOG ( SLURPD, ERR, "Re_parse: Error: re is NULL\n", 0, 0, 0 );
-#else
Debug( LDAP_DEBUG_ANY, "Re_parse: error: re is NULL\n", 0, 0, 0 );
-#endif
return -1;
}
if ( replbuf == NULL ) {
-#ifdef NEW_LOGGING
- LDAP_LOG ( SLURPD, ERR, "Re_parse: Error: replbuf is NULL\n", 0, 0, 0 );
-#else
Debug( LDAP_DEBUG_ANY, "Re_parse: error: replbuf is NULL\n", 0, 0, 0 );
-#endif
return -1;
}
}
buflen = strlen( buf );
if ( ldif_parse_line( buf, &type, &value, &len ) < 0 ) {
-#ifdef NEW_LOGGING
- LDAP_LOG ( SLURPD, ERR,
- "Re_parse: Error: malformed replog file\n", 0, 0, 0 );
-#else
Debug( LDAP_DEBUG_ANY,
"Error: Re_parse: malformed replog file\n",
0, 0, 0 );
-#endif
return -1;
}
switch ( gettype( type )) {
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 );
break;
default:
if ( !( state == GOT_ALL )) {
-#ifdef NEW_LOGGING
- LDAP_LOG ( SLURPD, ERR,
- "Re_parse: Error: bad type <%s>\n", type, 0, 0 );
-#else
Debug( LDAP_DEBUG_ANY,
"Error: Re_parse: bad type <%s>\n",
type, 0, 0 );
-#endif
free( type );
free( value );
return -1;
}
if ( state != GOT_ALL ) {
-#ifdef NEW_LOGGING
- LDAP_LOG ( SLURPD, ERR,
- "Re_parse: Error: malformed replog file\n", 0, 0, 0 );
-#else
Debug( LDAP_DEBUG_ANY,
"Error: Re_parse: malformed replog file\n",
0, 0, 0 );
-#endif
return -1;
}
value = NULL;
} else {
if ( ldif_parse_line( buf, &type, &value, &len ) < 0 ) {
-#ifdef NEW_LOGGING
- LDAP_LOG ( SLURPD, ERR,
- "Re_parse: Error: malformed replog line \"%s\"\n", buf, 0, 0 );
-#else
Debug( LDAP_DEBUG_ANY,
"Error: malformed replog line \"%s\"\n",
buf, 0, 0 );
-#endif
return -1;
}
}
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 );
}
}
rh = (Rh *) ch_realloc((char *) rh, ( nreplicas + 2 ) * sizeof( Rh ));
if ( rh == NULL ) {
-#ifdef NEW_LOGGING
- LDAP_LOG ( SLURPD, ERR,
- "get_repl_hosts: Out of memory\n", 0, 0, 0 );
-#else
Debug( LDAP_DEBUG_ANY, "Out of memory in get_repl_hosts\n",
0, 0, 0 );
-#endif
return NULL;
}
rh[ nreplicas ].rh_hostname = strdup( value );
+#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 */
Mi *mi;
if ( re == NULL ) {
-#ifdef NEW_LOGGING
- LDAP_LOG ( SLURPD, ERR, "Re_dump: re is NULL\n", 0, 0, 0 );
-#else
Debug( LDAP_DEBUG_TRACE, "Re_dump: re is NULL\n", 0, 0, 0 );
-#endif
return;
}
fprintf( fp, "Re_dump: ******\n" );
int rc = 0;
if ( re == NULL || fp == NULL ) {
-#ifdef NEW_LOGGING
- LDAP_LOG ( SLURPD, ERR,
- "Re_write: Internal error: NULL argument\n", 0, 0, 0 );
-#else
Debug( LDAP_DEBUG_ANY, "Internal error: Re_write: NULL argument\n",
0, 0, 0 );
-#endif
return -1;
}
}
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",
}
bad:
if ( rc != 0 ) {
-#ifdef NEW_LOGGING
- LDAP_LOG ( SLURPD, ERR,
- "Re_write: Error while writing: %s\n", sys_errlist[ errno ], 0, 0 );
-#else
Debug( LDAP_DEBUG_ANY, "Error while writing: %s\n",
sys_errlist[ errno ], 0, 0 );
-#endif
}
return rc;
}
}
}
if ( !found ) {
-#ifdef NEW_LOGGING
- LDAP_LOG ( SLURPD, WARNING, "warn_unknown_replica: "
- "Warning: unknown replica %s:%d found in replication log\n",
- host, port, 0 );
-#else
Debug( LDAP_DEBUG_ANY,
"Warning: unknown replica %s:%d found in replication log\n",
host, port, 0 );
-#endif
nur++;
ur = (Rh *) ch_realloc( (char *) ur, ( nur * sizeof( Rh )));
ur[ nur - 1 ].rh_hostname = strdup( host );