]> git.sur5r.net Git - openldap/blobdiff - servers/slurpd/re.c
Ignore back-ldif if config directory is inaccessible
[openldap] / servers / slurpd / re.c
index 4d6ee77a65a76743aeeac3fc7f29e5ee01b202f5..05fd60743c9479b217e8ae098ed159d6cc74b666 100644 (file)
@@ -1,5 +1,18 @@
-/*
- * Copyright (c) 1996 Regents of the University of Michigan.
+/* $OpenLDAP$ */
+/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
+ *
+ * Copyright 1998-2005 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>.
+ */
+/* Portions Copyright (c) 1996 Regents of the University of Michigan.
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms are permitted
@@ -9,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.
 
 #include <stdio.h>
 
+#include <ac/stdlib.h>
 #include <ac/errno.h>
 #include <ac/socket.h>
 #include <ac/string.h>
 #include <ac/ctype.h>
 
+#include "../slapd/slap.h"
+
 #include "slurp.h"
 #include "globals.h"
 
-#include "../slapd/slap.h"
-
 /* Forward references */
 static Rh      *get_repl_hosts LDAP_P(( char *, int *, char ** ));
 static int     gettype LDAP_P(( char * ));
@@ -83,7 +101,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,7 +192,7 @@ Re_parse(
                /* there was a sequence number */
                *p++ = '\0';
            }
-           re->re_timestamp = strdup( value );
+           re->re_timestamp = atol( value );
            if ( p != NULL && isdigit( (unsigned char) *p )) {
                re->re_seq = atoi( p );
            }
@@ -183,7 +200,7 @@ Re_parse(
            break;
        case T_DN:
            re->re_dn = ch_malloc( len + 1 );
-               memcpy( re->re_dn, value, len );
+               AC_MEMCPY( re->re_dn, value, len );
                re->re_dn[ len ]='\0';
            state |= GOT_DN;
            break;
@@ -193,14 +210,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 ) {
@@ -233,7 +248,7 @@ Re_parse(
        re->re_mods[ nml ].mi_type = strdup( type );
        if ( value != NULL ) {
            re->re_mods[ nml ].mi_val = ch_malloc( len + 1 );
-               memcpy( re->re_mods[ nml ].mi_val, value, len );
+               AC_MEMCPY( re->re_mods[ nml ].mi_val, value, len );
                re->re_mods[ nml ].mi_val[ len ] = '\0';
            re->re_mods[ nml ].mi_len = len;
        } else {
@@ -269,7 +284,6 @@ get_repl_hosts(
     char       **r_rp
 )
 {
-    char               buf[ LDIF_LINE_WIDTH + 1 ];
     char               *type, *value, *line, *p;
     Rh                 *rh = NULL;
     int                        nreplicas;
@@ -330,8 +344,7 @@ get_repl_hosts(
        free( type );
        if ( !repl_ok ) {
            warn_unknown_replica( value, port );
-           if ( value != NULL )
-               free( value );
+           free( value );
            continue;
        }
 
@@ -345,8 +358,7 @@ get_repl_hosts(
        rh[ nreplicas ].rh_port = port;
        nreplicas++;
 
-       if ( value != NULL )
-               free( value );
+       free( value );
     }
 
     if ( nreplicas == 0 ) {
@@ -459,7 +471,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++ ) {
@@ -536,7 +548,7 @@ Re_write(
            goto bad;
        }
     } 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 ) {
@@ -545,7 +557,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;
     }
@@ -709,7 +721,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;