ITS#2594 add URI support for replica config

This commit is contained in:
Howard Chu 2003-06-14 00:06:36 +00:00
parent a505d0c1fa
commit 44e32b3f7f
6 changed files with 121 additions and 7 deletions

View 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 modify the database will return an "unwilling to perform" error. By
default, readonly is off. default, readonly is off.
.HP .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 [suffix=<suffix> [...]]
.B bindmethod=simple|sasl [binddn=<simple DN>] [credentials=<simple password>] .B bindmethod=simple|sasl [binddn=<simple DN>] [credentials=<simple password>]
.B [saslmech=<SASL mech>] [secprops=<properties>] [realm=<realm>] .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 directory service. Zero or more
.B suffix .B suffix
instances can be used to select the subtrees that will be replicated 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 .B bindmethod
of of
.B simple .B simple

View File

@ -94,7 +94,8 @@ read_config( const char *fname, int depth )
int lineno, i; int lineno, i;
int rc; int rc;
struct berval vals[2]; struct berval vals[2];
char *replicahost;
LDAPURLDesc *ludp;
static int lastmod = 1; static int lastmod = 1;
static BackendInfo *bi = NULL; static BackendInfo *bi = NULL;
static BackendDB *be = NULL; static BackendDB *be = NULL;
@ -1758,11 +1759,11 @@ read_config( const char *fname, int depth )
if ( cargc < 2 ) { if ( cargc < 2 ) {
#ifdef NEW_LOGGING #ifdef NEW_LOGGING
LDAP_LOG( CONFIG, CRIT, 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 ); " <host[:port]\" line\n", fname, lineno , 0 );
#else #else
Debug( LDAP_DEBUG_ANY, 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 ); fname, lineno, 0 );
#endif #endif
@ -1789,16 +1790,62 @@ read_config( const char *fname, int depth )
nr = add_replica_info( be, nr = add_replica_info( be,
cargv[i] + 5 ); cargv[i] + 5 );
break; 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 ) { if ( i == cargc ) {
#ifdef NEW_LOGGING #ifdef NEW_LOGGING
LDAP_LOG( CONFIG, INFO, 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 ); fname, lineno , 0 );
#else #else
Debug( LDAP_DEBUG_ANY, 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 ); fname, lineno, 0 );
#endif #endif
return 1; return 1;

View File

@ -442,9 +442,16 @@ parse_replica_line(
int gots = 0; int gots = 0;
int i; int i;
char *hp, *val; char *hp, *val;
LDAPURLDesc *ludp;
for ( i = 1; i < cargc; i++ ) { for ( i = 1; i < cargc; i++ ) {
if ( !strncasecmp( cargv[ i ], HOSTSTR, sizeof( HOSTSTR ) - 1 ) ) { 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 '=' */ val = cargv[ i ] + sizeof( HOSTSTR ); /* '\0' string terminator accounts for '=' */
if (( hp = strchr( val, ':' )) != NULL ) { if (( hp = strchr( val, ':' )) != NULL ) {
*hp = '\0'; *hp = '\0';
@ -456,6 +463,30 @@ parse_replica_line(
} }
ri->ri_hostname = strdup( val ); ri->ri_hostname = strdup( val );
gots |= GOT_HOST; 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 ], } else if ( !strncasecmp( cargv[ i ],
ATTRSTR, sizeof( ATTRSTR ) - 1 ) ) { ATTRSTR, sizeof( ATTRSTR ) - 1 ) ) {
/* ignore it */ ; /* ignore it */ ;

View File

@ -777,7 +777,31 @@ retry:
} }
ri->ri_ldp = NULL; 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 #ifdef NEW_LOGGING
LDAP_LOG ( OPERATION, ARGS, LDAP_LOG ( OPERATION, ARGS,
"do_bind: Initializing session to %s:%d\n", "do_bind: Initializing session to %s:%d\n",
@ -798,6 +822,7 @@ retry:
ri->ri_hostname, ri->ri_port, sys_errlist[ errno ] ); ri->ri_hostname, ri->ri_port, sys_errlist[ errno ] );
#endif #endif
return( BIND_ERR_OPEN ); return( BIND_ERR_OPEN );
}
} }
{ /* set version 3 */ { /* set version 3 */

View File

@ -212,6 +212,7 @@ Ri_init(
/* Initialize private data */ /* Initialize private data */
(*ri)->ri_hostname = NULL; (*ri)->ri_hostname = NULL;
(*ri)->ri_uri = NULL;
(*ri)->ri_ldp = NULL; (*ri)->ri_ldp = NULL;
(*ri)->ri_bind_dn = NULL; (*ri)->ri_bind_dn = NULL;
(*ri)->ri_password = NULL; (*ri)->ri_password = NULL;

View File

@ -128,6 +128,7 @@
/* Config file keywords */ /* Config file keywords */
#define HOSTSTR "host" #define HOSTSTR "host"
#define URISTR "uri"
#define ATTRSTR "attr" #define ATTRSTR "attr"
#define SUFFIXSTR "suffix" #define SUFFIXSTR "suffix"
#define BINDDNSTR "binddn" #define BINDDNSTR "binddn"
@ -214,6 +215,7 @@ struct ri {
/* Private data */ /* Private data */
char *ri_hostname; /* canonical hostname of replica */ char *ri_hostname; /* canonical hostname of replica */
int ri_port; /* port where slave slapd running */ 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 */ LDAP *ri_ldp; /* LDAP struct for this replica */
int ri_tls; /* TLS: 0=no, 1=yes, 2=critical */ int ri_tls; /* TLS: 0=no, 1=yes, 2=critical */
int ri_bind_method; /* AUTH_SIMPLE or AUTH_KERBEROS */ int ri_bind_method; /* AUTH_SIMPLE or AUTH_KERBEROS */