From c596b797ed9776920184aa17641b742409abb781 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Kuzn=C3=ADk?= Date: Tue, 14 Mar 2017 10:42:13 +0000 Subject: [PATCH] Backend configuration --- servers/lloadd/config.c | 110 +++++++++++++++++++++++++++++++++++++++- servers/lloadd/slap.h | 29 ++++++++++- 2 files changed, 135 insertions(+), 4 deletions(-) diff --git a/servers/lloadd/config.c b/servers/lloadd/config.c index 0c64b3f31a..d464ffba52 100644 --- a/servers/lloadd/config.c +++ b/servers/lloadd/config.c @@ -95,6 +95,7 @@ static ConfigFile *cfn; static ConfigDriver config_fname; static ConfigDriver config_generic; +static ConfigDriver config_backend; #ifdef LDAP_TCP_BUFFER static ConfigDriver config_tcp_buffer; #endif /* LDAP_TCP_BUFFER */ @@ -106,6 +107,8 @@ static ConfigDriver config_tls_option; static ConfigDriver config_tls_config; #endif +slap_b_head backend = LDAP_STAILQ_HEAD_INITIALIZER(backend); + enum { CFG_ACL = 1, CFG_BACKEND, @@ -151,9 +154,9 @@ static ConfigTable config_back_cf_table[] = { ARG_INT|ARG_MAGIC|CFG_CONCUR, &config_generic, }, - { "database", "type", 2, 2, 0, + { "backend", "type", 2, 2, 0, ARG_MAGIC|CFG_DATABASE, - &config_generic, + &config_backend, }, { "gentlehup", "on|off", 2, 2, 0, #ifdef SIGHUP @@ -426,6 +429,109 @@ config_generic( ConfigArgs *c ) return 0; } +static int +config_backend( ConfigArgs *c ) +{ + int i, tmp, rc = -1; + LDAPURLDesc *lud = NULL; + Backend *b; + + b = ch_calloc( 1, sizeof(Backend) ); + + for ( i = 1; i < c->argc; i++ ) { + if ( bindconf_parse( c->argv[i], &b->b_bindconf ) ) { + Debug( LDAP_DEBUG_ANY, "config_backend: " + "error parsing backend configuration item '%s'\n", + c->argv[i] ); + rc = -1; + goto done; + } + } + + if ( BER_BVISNULL( &b->b_bindconf.sb_uri ) ) { + Debug( LDAP_DEBUG_ANY, "config_backend: " + "backend address not specified\n" ); + rc = -1; + goto done; + } + + rc = ldap_url_parse( b->b_bindconf.sb_uri.bv_val, &lud ); + if ( rc != LDAP_URL_SUCCESS ) { + Debug( LDAP_DEBUG_ANY, "config_backend: " + "listen URL \"%s\" parse error=%d\n", + b->b_bindconf.sb_uri.bv_val, rc ); + rc = -1; + goto done; + } + +#ifndef HAVE_TLS + if ( ldap_pvt_url_scheme2tls( lud->lud_scheme ) ) { + Debug( LDAP_DEBUG_ANY, "config_backend: " + "TLS not supported (%s)\n", + b->b_bindconf.sb_uri.bv_val ); + rc = -1; + goto done; + } + + if ( !lud->lud_port ) { + b->b_port = LDAP_PORT; + } else { + b->b_port = lud->lud_port; + } + +#else /* HAVE_TLS */ + tmp = ldap_pvt_url_scheme2tls( lud->lud_scheme ); + if ( tmp ) { + b->b_tls = LLOAD_LDAPS; + } + + if ( !lud->lud_port ) { + b->b_port = b->b_tls ? LDAPS_PORT : LDAP_PORT; + } else { + b->b_port = lud->lud_port; + } +#endif /* HAVE_TLS */ + + b->b_proto = tmp = ldap_pvt_url_scheme2proto( lud->lud_scheme ); + if ( tmp == LDAP_PROTO_IPC ) { +#ifdef LDAP_PF_LOCAL + if ( lud->lud_host == NULL || lud->lud_host[0] == '\0' ) { + b->b_host = ch_strdup( LDAPI_SOCK ); + } +#else /* ! LDAP_PF_LOCAL */ + + Debug( LDAP_DEBUG_ANY, "config_backend: " + "URL scheme not supported: %s", + url ); + rc = -1; + goto done; +#endif /* ! LDAP_PF_LOCAL */ + } else { + if ( lud->lud_host == NULL || lud->lud_host[0] == '\0' ) { + Debug( LDAP_DEBUG_ANY, "config_backend: " + "backend url missing hostname: '%s'\n", + b->b_bindconf.sb_uri.bv_val ); + rc = -1; + goto done; + } + } + if ( !b->b_host ) { + b->b_host = ch_strdup( lud->lud_host ); + } + + ldap_pvt_thread_mutex_init( &b->b_lock ); + +done: + ldap_free_urldesc( lud ); + if ( rc ) { + ch_free( b ); + } else { + LDAP_STAILQ_INSERT_TAIL( &backend, b, b_next ); + } + + return rc; +} + static int config_fname( ConfigArgs *c ) { diff --git a/servers/lloadd/slap.h b/servers/lloadd/slap.h index d89c7e21ba..c79fae79e2 100644 --- a/servers/lloadd/slap.h +++ b/servers/lloadd/slap.h @@ -96,6 +96,7 @@ LDAP_SLAPD_V (int) slap_debug; typedef unsigned long slap_mask_t; +typedef struct Backend Backend; typedef struct Connection Connection; /* end of forward declarations */ @@ -115,6 +116,10 @@ typedef union Sockaddr { extern int slap_inet4or6; #endif +typedef LDAP_STAILQ_HEAD(BeSt, Backend) slap_b_head; + +LDAP_SLAPD_V (slap_b_head) backend; + LDAP_SLAPD_V (int) slapMode; #define SLAP_UNDEFINED_MODE 0x0000 #define SLAP_SERVER_MODE 0x0001 @@ -217,6 +222,26 @@ typedef struct config_reply_s ConfigReply; /* config.h */ typedef struct Listener Listener; +enum lload_tls_type { + LLOAD_CLEARTEXT = 0, + LLOAD_LDAPS, + LLOAD_STARTTLS, +}; + +struct Backend { + struct slap_bindconf b_bindconf; + ldap_pvt_thread_mutex_t b_lock; + + int b_proto, b_port; + enum lload_tls_type b_tls; + char *b_host; + + int b_numconns, b_numbindconns; + Connection *b_conns, *b_bindconns; + + LDAP_STAILQ_ENTRY(Backend) b_next; +}; + /* * represents a connection from an ldap client */ @@ -267,8 +292,8 @@ struct Connection { #define CONN_IS_IPC 8 #ifdef HAVE_TLS - char c_is_tls; /* true if this LDAP over raw TLS */ - char c_needs_tls_accept; /* true if SSL_accept should be called */ + enum lload_tls_type c_is_tls; /* true if this LDAP over raw TLS */ + char c_needs_tls_accept; /* true if SSL_accept should be called */ #endif long c_n_ops_executing; /* num of ops currently executing */