]> git.sur5r.net Git - openldap/commitdiff
ITS#2594 add URI support for replica config
authorHoward Chu <hyc@openldap.org>
Sat, 14 Jun 2003 00:06:36 +0000 (00:06 +0000)
committerHoward Chu <hyc@openldap.org>
Sat, 14 Jun 2003 00:06:36 +0000 (00:06 +0000)
doc/man/man5/slapd.conf.5
servers/slapd/config.c
servers/slurpd/config.c
servers/slurpd/ldap_op.c
servers/slurpd/ri.c
servers/slurpd/slurp.h

index 6b732977305142dae53ed2792dcec2d918c3ee4a..da0d011516bdff557ed5f163422167f2d783c4ac 100644 (file)
@@ -966,7 +966,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] [starttls=yes|critical]
+.B replica uri=ldap[s]://<hostname>[:port]|host=<hostname>[:port] 
+.B [starttls=yes|critical]
 .B [suffix=<suffix> [...]]
 .B bindmethod=simple|sasl [binddn=<simple DN>] [credentials=<simple password>]
 .B [saslmech=<SASL mech>] [secprops=<properties>] [realm=<realm>]
@@ -979,7 +980,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 d683233abea55353b67695e34ad43a1029ecf88c..c7d0df77d94d888e90321275de7346bbcdde0c23 100644 (file)
@@ -94,7 +94,8 @@ read_config( const char *fname, int depth )
        int     lineno, i;
        int rc;
        struct berval vals[2];
-
+       char *replicahost;
+       LDAPURLDesc *ludp;
        static int lastmod = 1;
        static BackendInfo *bi = NULL;
        static BackendDB        *be = NULL;
@@ -1758,11 +1759,11 @@ read_config( const char *fname, int depth )
                        if ( cargc < 2 ) {
 #ifdef NEW_LOGGING
                                LDAP_LOG( CONFIG, CRIT, 
-                                       "%s: line %d: missing host in \"replica "
+                                       "%s: line %d: missing host or uri in \"replica "
                                        " <host[:port]\" line\n", fname, lineno , 0 );
 #else
                                Debug( LDAP_DEBUG_ANY,
-           "%s: line %d: missing host in \"replica <host[:port]>\" line\n",
+           "%s: line %d: missing host or uri in \"replica <host[:port]>\" line\n",
                                    fname, lineno, 0 );
 #endif
 
@@ -1789,16 +1790,62 @@ read_config( const char *fname, int depth )
                                                nr = add_replica_info( be, 
                                                        cargv[i] + 5 );
                                                break;
+                                       } else if (strncasecmp( cargv[i], "uri=", 4 )
+                                           == 0 ) {
+                                           if ( ldap_url_parse( cargv[ i ] + 4, &ludp )
+                                               != LDAP_SUCCESS ) {
+#ifdef NEW_LOGGING
+                                                       LDAP_LOG( CONFIG, INFO, 
+                                                       "%s: line %d: replica line contains invalid "
+                                                       "uri definition.\n", fname, lineno, 0);
+#else
+                                                       Debug( LDAP_DEBUG_ANY,
+                                                       "%s: line %d: replica line contains invalid "
+                                                       "uri definition.\n", fname, lineno, 0);
+#endif
+                                                       return 1;
+                                               }
+                                               if (ludp->lud_host == NULL ) {
+#ifdef NEW_LOGGING
+                                                       LDAP_LOG( CONFIG, INFO, 
+                                                       "%s: line %d: replica line contains invalid "
+                                                       "uri definition - missing hostname.\n", 
+                                                       fname, lineno, 0);
+#else
+                                                       Debug( LDAP_DEBUG_ANY,
+                                                       "%s: line %d: replica line contains invalid "
+                                                       "uri definition - missing hostname.\n", fname, lineno, 0);
+#endif
+                                                       return 1;
+                                               }
+                                       replicahost = ch_malloc( strlen( cargv[ i ] ) );
+                                               if ( replicahost == NULL ) {
+#ifdef NEW_LOGGING
+                                                       LDAP_LOG( CONFIG, ERR, 
+                                                       "out of memory in read_config\n", 0, 0,0 );
+#else
+                                                       Debug( LDAP_DEBUG_ANY, 
+                                                       "out of memory in read_config\n", 0, 0, 0 );
+#endif
+                                                       ldap_free_urldesc( ludp );                              
+                                                       exit( EXIT_FAILURE );
+                                               }
+                                               sprintf(replicahost, "%s:%d", 
+                                                       ludp->lud_host, ludp->lud_port);
+                                               nr = add_replica_info( be, replicahost );
+                                               ldap_free_urldesc( ludp );                              
+                                               ch_free(replicahost);
+                                               break;
                                        }
                                }
                                if ( i == cargc ) {
 #ifdef NEW_LOGGING
                                        LDAP_LOG( CONFIG, INFO, 
-                                               "%s: line %d: missing host in \"replica\" line\n", 
+                                               "%s: line %d: missing host or uri in \"replica\" line\n", 
                                                fname, lineno , 0 );
 #else
                                        Debug( LDAP_DEBUG_ANY,
-                   "%s: line %d: missing host in \"replica\" line\n",
+                   "%s: line %d: missing host or uri in \"replica\" line\n",
                                            fname, lineno, 0 );
 #endif
                                        return 1;
index 4f0ee3b53f9de0f2544a7ec300a95b1b26efb0cb..6f3df19a0f95444217954371795a6984a7248d74 100644 (file)
@@ -442,9 +442,16 @@ parse_replica_line(
     int                gots = 0;
     int                i;
     char       *hp, *val;
+    LDAPURLDesc *ludp;
 
     for ( i = 1; i < cargc; i++ ) {
        if ( !strncasecmp( cargv[ i ], HOSTSTR, sizeof( HOSTSTR ) - 1 ) ) {
+               if ( gots & GOT_HOST ) {
+                       fprintf( stderr, "Error: Malformed \"replica\" line in slapd config " );
+                       fprintf( stderr, "file, too many host or uri names specified, line %d\n",
+                               lineno );
+                       return -1;
+               }       
            val = cargv[ i ] + sizeof( HOSTSTR ); /* '\0' string terminator accounts for '=' */
            if (( hp = strchr( val, ':' )) != NULL ) {
                *hp = '\0';
@@ -456,6 +463,30 @@ parse_replica_line(
            }
            ri->ri_hostname = strdup( val );
            gots |= GOT_HOST;
+       } else if ( !strncasecmp( cargv[ i ], URISTR, sizeof( URISTR ) - 1 ) ) {
+               if ( gots & GOT_HOST ) {
+                       fprintf( stderr, "Error: Malformed \"replica\" line in slapd config " );
+                       fprintf( stderr, "file, too many host or uri names specified, line %d\n",
+                               lineno );
+                       return -1;
+               }               
+               if ( ldap_url_parse( cargv[ i ] + sizeof( URISTR ), &ludp ) != LDAP_SUCCESS ) {
+                       fprintf( stderr, "Error: Malformed \"replica\" line in slapd config " );
+                       fprintf( stderr, "file, bad uri format specified, line %d\n",
+                               lineno );
+                       return -1;
+               }
+               if (ludp->lud_host == NULL) {
+                       fprintf( stderr, "Error: Malformed \"replica\" line in slapd config " );
+                       fprintf( stderr, "file, missing uri hostname, line %d\n",
+                               lineno );
+                       return -1;
+               }
+               ri->ri_hostname = strdup ( ludp->lud_host );
+               ri->ri_port = ludp->lud_port;
+               ri->ri_uri = strdup ( cargv[ i ] + sizeof( URISTR ) );          
+               ldap_free_urldesc( ludp );                              
+           gots |= GOT_HOST;
        } else if ( !strncasecmp( cargv[ i ], 
                        ATTRSTR, sizeof( ATTRSTR ) - 1 ) ) {
            /* ignore it */ ;
index 1a0ba704a5c55d294e129b0ebbe4740dc424bc35..b3a8561b2affa84a79f14002af5376fd0827c45a 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 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 54b7df03aae68e98e9bc12c528154eea9ba167ce..d5884f1c2b93ace83efc5e34ed08cd9ff6838c01 100644 (file)
 
 /* Config file keywords */
 #define        HOSTSTR                 "host"
+#define        URISTR                  "uri"
 #define        ATTRSTR                 "attr"
 #define        SUFFIXSTR               "suffix"
 #define        BINDDNSTR               "binddn"
@@ -214,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 */