]> git.ipfire.org Git - thirdparty/openldap.git/commitdiff
Rework lloadd startup
authorOndřej Kuzník <okuznik@symas.com>
Fri, 16 Mar 2018 13:08:08 +0000 (13:08 +0000)
committerOndřej Kuzník <okuznik@symas.com>
Tue, 17 Nov 2020 17:58:15 +0000 (17:58 +0000)
servers/lloadd/Makefile.in
servers/lloadd/Makefile_server.in
servers/lloadd/init.c
servers/lloadd/main.c
servers/lloadd/module_init.c
servers/lloadd/proto-lload.h

index 767794f3980fa11a616a0fdfc92db17882ea185e..c78bb3acd92a3a733964b3934068dcaf781c84ac 100644 (file)
@@ -20,7 +20,7 @@ NT_SRCS = nt_svc.c
 NT_OBJS = nt_svc.o ../../libraries/liblutil/slapdmsg.res
 
 SRCS   = backend.c bind.c config.c connection.c client.c \
-                 daemon.c extended.c operation.c \
+                 daemon.c extended.c init.c operation.c \
                  upstream.c libevent_support.c \
                  $(@PLAT@_SRCS)
 
index 8a41869d8d046c959ba4fb15f29b820fdf2aaae1..5ffca6b722d36a175cb7256153bb74aa5380397f 100644 (file)
@@ -21,7 +21,7 @@ XSRCS = version.c
 NT_SRCS = ../slapd/nt_svc.c
 NT_OBJS = ../slapd/nt_svc.o ../../libraries/liblutil/slapdmsg.res
 
-SRCS   += main.c init.c value.c \
+SRCS   += main.c value.c \
                  ../slapd/ch_malloc.c ../slapd/sl_malloc.c ../slapd/user.c
 
 OBJS   = $(patsubst %.c,%.o,$(SRCS)) $(@PLAT@_OBJS)
index 96481ccc410c9ff079addc8cdae063927875dbc6..41c5a06700581fa5186b76b8ffa5ded9f27b1785 100644 (file)
@@ -67,6 +67,69 @@ int slapMode = SLAP_UNDEFINED_MODE;
 
 static const char *lload_name = NULL;
 
+int
+lload_global_init( void )
+{
+    int rc;
+
+    if ( lload_libevent_init() ) {
+        return -1;
+    }
+
+#ifdef HAVE_TLS
+    if ( ldap_create( &lload_tls_backend_ld ) ) {
+        return -1;
+    }
+    if ( ldap_create( &lload_tls_ld ) ) {
+        return -1;
+    }
+
+    /* Library defaults to full certificate checking. This is correct when
+     * a client is verifying a server because all servers should have a
+     * valid cert. But few clients have valid certs, so we want our default
+     * to be no checking. The config file can override this as usual.
+     */
+    rc = LDAP_OPT_X_TLS_NEVER;
+    (void)ldap_pvt_tls_set_option(
+            lload_tls_ld, LDAP_OPT_X_TLS_REQUIRE_CERT, &rc );
+#endif
+
+    ldap_pvt_thread_mutex_init( &lload_wait_mutex );
+    ldap_pvt_thread_cond_init( &lload_wait_cond );
+    ldap_pvt_thread_cond_init( &lload_pause_cond );
+
+    ldap_pvt_thread_mutex_init( &backend_mutex );
+    ldap_pvt_thread_mutex_init( &clients_mutex );
+    ldap_pvt_thread_mutex_init( &lload_pin_mutex );
+
+    if ( lload_exop_init() ) {
+        return -1;
+    }
+    return 0;
+}
+
+int
+lload_tls_init( void )
+{
+#ifdef HAVE_TLS
+    int rc, opt = 1;
+
+    /* Force new ctx to be created */
+    rc = ldap_pvt_tls_set_option( lload_tls_ld, LDAP_OPT_X_TLS_NEWCTX, &opt );
+    if ( rc == 0 ) {
+        /* The ctx's refcount is bumped up here */
+        ldap_pvt_tls_get_option(
+                lload_tls_ld, LDAP_OPT_X_TLS_CTX, &lload_tls_ctx );
+    } else if ( rc != LDAP_NOT_SUPPORTED ) {
+        Debug( LDAP_DEBUG_ANY, "lload_global_init: "
+                "TLS init def ctx failed: %d\n",
+                rc );
+        return -1;
+    }
+#endif
+    return 0;
+}
+
 int
 lload_init( int mode, const char *name )
 {
@@ -101,16 +164,7 @@ lload_init( int mode, const char *name )
             LDAP_STAILQ_INIT( &slapd_rq.task_list );
             LDAP_STAILQ_INIT( &slapd_rq.run_list );
 
-            ldap_pvt_thread_mutex_init( &lload_wait_mutex );
-            ldap_pvt_thread_cond_init( &lload_wait_cond );
-            ldap_pvt_thread_cond_init( &lload_pause_cond );
-
-            ldap_pvt_thread_mutex_init( &backend_mutex );
-            ldap_pvt_thread_mutex_init( &clients_mutex );
-            ldap_pvt_thread_mutex_init( &lload_pin_mutex );
-
-            lload_exop_init();
-
+            rc = lload_global_init();
             break;
 
         default:
index 605a0f07b601fbc70fa73bfa6ba451a7fc4f0690..cfd6290ffab30fab7ccd9d4fd4e25ffb6647cefe 100644 (file)
@@ -625,10 +625,6 @@ unhandled_option:;
 
     Debug( LDAP_DEBUG_ANY, "%s", Versionstr );
 
-    if ( lload_libevent_init() ) {
-        goto stop;
-    }
-
     global_host = ldap_pvt_get_fqdn( NULL );
 
     if ( check == CHECK_NONE && lloadd_daemon_init( urls ) != 0 ) {
@@ -663,27 +659,6 @@ unhandled_option:;
     }
 #endif
 
-#ifdef HAVE_TLS
-    rc = ldap_create( &lload_tls_backend_ld );
-    if ( rc ) {
-        SERVICE_EXIT( ERROR_SERVICE_SPECIFIC_ERROR, 20 );
-        goto destroy;
-    }
-    rc = ldap_create( &lload_tls_ld );
-    if ( rc ) {
-        SERVICE_EXIT( ERROR_SERVICE_SPECIFIC_ERROR, 20 );
-        goto destroy;
-    }
-    /* Library defaults to full certificate checking. This is correct when
-     * a client is verifying a server because all servers should have a
-     * valid cert. But few clients have valid certs, so we want our default
-     * to be no checking. The config file can override this as usual.
-     */
-    rc = LDAP_OPT_X_TLS_NEVER;
-    (void)ldap_pvt_tls_set_option(
-            lload_tls_ld, LDAP_OPT_X_TLS_REQUIRE_CERT, &rc );
-#endif
-
     rc = lload_init( serverMode, serverName );
     if ( rc ) {
         SERVICE_EXIT( ERROR_SERVICE_SPECIFIC_ERROR, 18 );
@@ -740,24 +715,10 @@ unhandled_option:;
         goto destroy;
     }
 
-    {
-        int opt = 1;
-
-        /* Force new ctx to be created */
-        rc = ldap_pvt_tls_set_option(
-                lload_tls_ld, LDAP_OPT_X_TLS_NEWCTX, &opt );
-        if ( rc == 0 ) {
-            /* The ctx's refcount is bumped up here */
-            ldap_pvt_tls_get_option(
-                    lload_tls_ld, LDAP_OPT_X_TLS_CTX, &lload_tls_ctx );
-        } else if ( rc != LDAP_NOT_SUPPORTED ) {
-            Debug( LDAP_DEBUG_ANY, "main: "
-                    "TLS init def ctx failed: %d\n",
-                    rc );
-            rc = 1;
-            SERVICE_EXIT( ERROR_SERVICE_SPECIFIC_ERROR, 20 );
-            goto destroy;
-        }
+    if ( lload_tls_init() ) {
+        rc = 1;
+        SERVICE_EXIT( ERROR_SERVICE_SPECIFIC_ERROR, 20 );
+        goto destroy;
     }
 #endif
 
index 3a65eedfe2c21a15c4c33d2d2cbfd10a303c60d1..98fcbc2812d528c274cc4d50f8b771f544c492a5 100644 (file)
@@ -33,6 +33,7 @@
 #include <ac/time.h>
 
 #include "../servers/slapd/slap.h"
+#include "../servers/slapd/config.h"
 
 #include "lload.h"
 #include "lber_pvt.h"
@@ -45,7 +46,7 @@ struct lload_conf_info lload_info;
 void *
 lload_start_daemon( void *arg )
 {
-    int rc = 0, i;
+    int rc = 0;
 
     daemon_base = event_base_new();
     if ( !daemon_base ) {
@@ -59,37 +60,21 @@ lload_start_daemon( void *arg )
     return (void *)(uintptr_t)rc;
 }
 
-/* from init.c */
-int
-lload_conn_pool_init()
-{
-    int rc = 0;
-
-    ldap_pvt_thread_mutex_init( &lload_wait_mutex );
-    ldap_pvt_thread_cond_init( &lload_pause_cond );
-    ldap_pvt_thread_cond_init( &lload_wait_cond );
-
-    ldap_pvt_thread_mutex_init( &backend_mutex );
-    ldap_pvt_thread_mutex_init( &clients_mutex );
-    ldap_pvt_thread_mutex_init( &lload_pin_mutex );
-
-    lload_exop_init();
-    Debug( LDAP_DEBUG_TRACE, "lload_conn_pool_init: "
-            "mutexes initialized.\n" );
-    return rc;
-}
-
 static int
 lload_pause_cb( BackendInfo *bi )
 {
-    lload_pause_server();
+    if ( daemon_base ) {
+        lload_pause_server();
+    }
     return 0;
 }
 
 static int
 lload_unpause_cb( BackendInfo *bi )
 {
-    lload_unpause_server();
+    if ( daemon_base ) {
+        lload_unpause_server();
+    }
     return 0;
 }
 
@@ -99,20 +84,14 @@ lload_back_open( BackendInfo *bi )
     if ( slapMode & SLAP_TOOL_MODE ) {
         return 0;
     }
-    if ( lload_libevent_init() ) {
-        return -1;
-    }
-    global_host = ldap_pvt_get_fqdn( NULL );
-#ifdef HAVE_TLS
-    if ( ldap_create( &lload_tls_backend_ld ) ) {
+
+    if ( lload_tls_init() != 0 ) {
         return -1;
     }
-#endif /* HAVE_TLS */
 
     if ( lloadd_daemon_init( listeners_list ) != 0 ) {
         return -1;
     }
-    lload_conn_pool_init();
 
     if ( lload_monitor_open() != 0 ) {
         return -1;
@@ -172,6 +151,10 @@ lload_back_initialize( BackendInfo *bi )
     bi->bi_connection_init = 0;
     bi->bi_connection_destroy = 0;
 
+    if ( lload_global_init() ) {
+        return -1;
+    }
+
     bi->bi_private = &lload_info;
     return lload_back_init_cf( bi );
 }
index c0f0dc38b76e7b051f5cc25cf96e6a229fb2720e..e3fd5b421875ae565057945274f622ae0235f7fd 100644 (file)
@@ -134,6 +134,8 @@ LDAP_SLAPD_F (int) lload_exop_init( void );
 /*
  * init.c
  */
+LDAP_SLAPD_F (int) lload_global_init( void );
+LDAP_SLAPD_F (int) lload_tls_init( void );
 LDAP_SLAPD_F (int) lload_init( int mode, const char *name );
 LDAP_SLAPD_F (int) lload_destroy( void );
 LDAP_SLAPD_F (void) lload_counters_init( void );