]> git.ipfire.org Git - thirdparty/openldap.git/commitdiff
Merged config patches from HEAD:
authorHoward Chu <hyc@openldap.org>
Wed, 10 Sep 2003 01:03:14 +0000 (01:03 +0000)
committerHoward Chu <hyc@openldap.org>
Wed, 10 Sep 2003 01:03:14 +0000 (01:03 +0000)
ITS#2594 replica uri
replica-pidfile, replica-argsfile

doc/man/man5/slapd.conf.5
servers/slurpd/ch_malloc.c
servers/slurpd/config.c
servers/slurpd/ldap_op.c
servers/slurpd/main.c
servers/slurpd/proto-slurp.h
servers/slurpd/ri.c
servers/slurpd/slurp.h

index 826b29723fc771621c4bb674b9ae558e0a1bd846..c20c7abe873133ea84a5841540ea6bea0e0661b6 100644 (file)
@@ -529,6 +529,19 @@ Specify the referral to pass back when
 cannot find a local database to handle a request.
 If specified multiple times, each url is provided.
 .TP
+.B replica-argsfile
+The ( absolute ) name of a file that will hold the 
+.B slurpd
+server's command line options
+if started without the debugging command line option.
+.TP
+.B replica-pidfile
+The ( absolute ) name of a file that will hold the 
+.B slurpd
+server's process ID ( see
+.BR getpid (2)
+) if started without the debugging command line option.
+.TP
 .B require <conditions>
 Specify a set of conditions (separated by white space) to
 require (default none).
@@ -940,7 +953,8 @@ This option puts the database into "read-only" mode.  Any attempts to
 modify the database will return an "unwilling to perform" error.  By
 default, readonly is off.
 .HP
-.B replica host=<hostname>[:port] [tls=yes|critical]
+.B replica uri=ldap[s]://<hostname>[:port]|host=<hostname>[:port]
+.B [tls=yes|critical]
 .B [suffix=<suffix> [...]]
 .B bindmethod=simple|sasl [binddn=<simple DN>] [credentials=<simple password>]
 .B [saslmech=<SASL mech>] [secprops=<properties>] [realm=<realm>]
@@ -953,7 +967,14 @@ Administrator's Guide" for detailed information on setting up a replicated
 directory service. Zero or more
 .B suffix
 instances can be used to select the subtrees that will be replicated
-(defaults to all the database). A
+(defaults to all the database). 
+.B host
+is deprecated in favor of the
+.B uri
+option.
+.B uri
+allows the replica LDAP server to be specified as an LDAP URI. 
+A
 .B bindmethod
 of
 .B simple
index 9c95a72cb7d3e3c22eeef5e0bb9b6612435c561f..2b42ab266329b1023ddcfe053e37423f789e78c6 100644 (file)
@@ -109,6 +109,25 @@ ch_calloc(
        return( new );
 }
 
+/*
+ * Just like strdup, except we check the returned value and exit
+ * if anything goes wrong.
+ */
+char *
+ch_strdup(
+    const char *string
+)
+{
+       char    *new;
+
+       if ( (new = ber_strdup( string )) == NULL ) {
+               fprintf( stderr, "ch_strdup: duplication of \"%s\" failed\n",
+                               string );
+               exit( EXIT_FAILURE );
+       }
+
+       return( new );
+}
 
 /*
  * Just like free, except we check to see if p is null.
index 4c6af08b510caa19f24f217065f48795ff119084..4c3a285347fcd652a4a507ae1504ccca581650d5 100644 (file)
@@ -48,7 +48,8 @@ char  **cargv;
 /* current config file line # */
 static int     lineno;
 
-
+char *slurpd_pid_file = NULL;
+char *slurpd_args_file = NULL;
 
 /*
  * Read the slapd config file, looking only for config options we're
@@ -153,6 +154,41 @@ slurpd_read_config(
                
            free( savefname );
            lineno = savelineno - 1;
+
+       } else if ( strcasecmp( cargv[0], "replica-pidfile" ) == 0 ) {
+               if ( cargc < 2 ) {
+#ifdef NEW_LOGGING
+                       LDAP_LOG( CONFIG, CRIT, 
+                               "%s: line %d missing file name in \"replica-pidfile <file>\" "
+                               "line.\n", fname, lineno, 0 );
+#else
+                       Debug( LDAP_DEBUG_ANY,
+           "%s: line %d: missing file name in \"replica-pidfile <file>\" line\n",
+                               fname, lineno, 0 );
+#endif
+
+                       return( 1 );
+               }
+
+               slurpd_pid_file = ch_strdup( cargv[1] );
+
+       } else if ( strcasecmp( cargv[0], "replica-argsfile" ) == 0 ) {
+               if ( cargc < 2 ) {
+#ifdef NEW_LOGGING
+                       LDAP_LOG( CONFIG, CRIT, 
+                                  "%s: %d: missing file name in "
+                                  "\"argsfile <file>\" line.\n",
+                                  fname, lineno, 0 );
+#else
+                       Debug( LDAP_DEBUG_ANY,
+           "%s: line %d: missing file name in \"argsfile <file>\" line\n",
+                           fname, lineno, 0 );
+#endif
+
+                       return( 1 );
+               }
+
+               slurpd_args_file = ch_strdup( cargv[1] );
        }
     }
     fclose( fp );
index 44aa465c45d8fc554c48b0c2c9e76cceedadca07..8da54946fe8bfa1d676a0db153d82eeb6d0d4f27 100644 (file)
@@ -777,7 +777,31 @@ retry:
        }
        ri->ri_ldp = NULL;
     }
+    
+       if ( ri->ri_uri != NULL ) { /* new URI style */
+#ifdef NEW_LOGGING
+               LDAP_LOG ( OPERATION, ARGS, 
+                       "do_bind: Initializing session to %s\n", 
+                   ri->ri_uri, 0, 0);
+#else
+           Debug( LDAP_DEBUG_ARGS, "Initializing session to %s\n",
+                   ri->ri_uri, 0, 0 );
+#endif
 
+               ldrc = ldap_initialize( &(ri->ri_ldp), ri->ri_uri);
+
+               if (ldrc != LDAP_SUCCESS) {
+#ifdef NEW_LOGGING
+               LDAP_LOG ( OPERATION, ERR, 
+                       "do_bind: ldap_initalize (0, %s) failed: %s\n",
+                       ri->ri_uri, ldap_err2string(ldrc), 0 );
+#else
+               Debug( LDAP_DEBUG_ANY, "Error: ldap_initialize(0, %s) failed: %s\n",
+                       ri->ri_uri, ldap_err2string(ldrc), 0 );
+#endif
+               return( BIND_ERR_OPEN );                
+               }
+       } else { /* old HOST style */
 #ifdef NEW_LOGGING
        LDAP_LOG ( OPERATION, ARGS, 
                "do_bind: Initializing session to %s:%d\n", 
@@ -798,6 +822,7 @@ retry:
                        ri->ri_hostname, ri->ri_port, sys_errlist[ errno ] );
 #endif
                return( BIND_ERR_OPEN );
+    }
     }
 
        {       /* set version 3 */
index 5afd941cb7fd1de3d7074b78953eff8b8b12a88e..c12f9e9022ebcc227f5ab6ee9930e409702b732c 100644 (file)
@@ -25,6 +25,7 @@
 #include <stdio.h>
 #include <sys/stat.h>
 #include <ac/stdlib.h>
+#include <ac/unistd.h>
 
 #include "slurp.h"
 #include "globals.h"
@@ -176,6 +177,35 @@ int main( int argc, char **argv )
        goto stop;
     }
 
+
+    if ( slurpd_pid_file != NULL ) {
+       FILE *fp = fopen( slurpd_pid_file, "w" );
+
+       if( fp != NULL ) {
+               fprintf( fp, "%d\n", (int) getpid() );
+               fclose( fp );
+
+       } else {
+               free(slurpd_pid_file);
+               slurpd_pid_file = NULL;
+       }
+    }
+
+    if ( slurpd_args_file != NULL ) {
+       FILE *fp = fopen( slurpd_args_file, "w" );
+
+       if( fp != NULL ) {
+               for ( i = 0; i < argc; i++ ) {
+                       fprintf( fp, "%s ", argv[i] );
+               }
+               fprintf( fp, "\n" );
+               fclose( fp );
+       } else {
+               free(slurpd_args_file);
+               slurpd_args_file = NULL;
+       }
+    }
+
     /*
      * Detach from the controlling terminal
      * unless the -d flag is given or in one-shot mode.
@@ -262,6 +292,15 @@ stop:
 #else
     Debug( LDAP_DEBUG_ANY, "slurpd: terminated.\n", 0, 0, 0 );
 #endif
+
+    if ( slurpd_pid_file != NULL ) {
+       unlink( slurpd_pid_file );
+    }
+    if ( slurpd_args_file != NULL ) {
+       unlink( slurpd_args_file );
+    }
+
+
        MAIN_RETURN(rc);
 #endif /* !NO_THREADS */
 }
index bdcce9ad688fda088a725e2e9d702995c5d78f6b..dc25d09e68ac12de4a100f8871921c374cf876ac 100644 (file)
@@ -21,17 +21,22 @@ int doargs  LDAP_P((int argc, char **argv, struct globals *g));
 #define ch_malloc malloc
 #define ch_realloc realloc
 #define ch_calloc calloc
+#define ch_strdup strdup
 #define ch_free free
 #else
 void *ch_malloc        LDAP_P((ber_len_t size));
 void *ch_realloc       LDAP_P((void *block, ber_len_t size));
 void *ch_calloc        LDAP_P((ber_len_t nelem, ber_len_t size));
+char *ch_strdup LDAP_P((const char *str));
 void ch_free   LDAP_P((void *p));
 #endif
 
 /* config.c */
 int slurpd_read_config LDAP_P((char *fname));
 
+char *slurpd_pid_file;
+char *slurpd_args_file;
+
 /* ch_malloc.c */
 void ch_free LDAP_P(( void *p ));
 
index 7225783c3937faa5044956c347a0aa8f0afbbf18..a614c4e2f66ffc0d74536dd9a5c127463424cf00 100644 (file)
@@ -212,6 +212,7 @@ Ri_init(
 
     /* Initialize private data */
     (*ri)->ri_hostname = NULL;
+    (*ri)->ri_uri = NULL;
     (*ri)->ri_ldp = NULL;
     (*ri)->ri_bind_dn = NULL;
     (*ri)->ri_password = NULL;
index 43f310dc623d0c0cf0274160840de94716264a49..d5884f1c2b93ace83efc5e34ed08cd9ff6838c01 100644 (file)
 
 /* Config file keywords */
 #define        HOSTSTR                 "host"
+#define        URISTR                  "uri"
 #define        ATTRSTR                 "attr"
 #define        SUFFIXSTR               "suffix"
 #define        BINDDNSTR               "binddn"
 #define        SASLMECHSTR             "saslmech"
 #define        REALMSTR                "realm"
 #define        SECPROPSSTR             "secprops"
+#define STARTTLSSTR            "starttls"
 #define TLSSTR                 "tls"
-#define TLSCRITICALSTR "critical"
+#define CRITICALSTR            "critical"
 
 #define        REPLICA_SLEEP_TIME      ( 10 )
 
@@ -213,6 +215,7 @@ struct ri {
     /* Private data */
     char       *ri_hostname;           /* canonical hostname of replica */
     int                ri_port;                /* port where slave slapd running */
+    char       *ri_uri;                /* e.g. "ldaps://ldap-1.example.com:636" */
     LDAP       *ri_ldp;                /* LDAP struct for this replica */
     int                ri_tls;                 /* TLS: 0=no, 1=yes, 2=critical */
     int                ri_bind_method;         /* AUTH_SIMPLE or AUTH_KERBEROS */