fix listener not initialiazed before changeuid

Sun, 25 Sep 2022 12:12:53 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sun, 25 Sep 2022 12:12:53 +0200
changeset 393
79e542cc20a9
parent 392
0aef555055ee
child 394
4d2a1df73e18

fix listener not initialiazed before changeuid

src/server/daemon/config.c file | annotate | diff | comparison | revisions
--- a/src/server/daemon/config.c	Sun Sep 25 11:56:47 2022 +0200
+++ b/src/server/daemon/config.c	Sun Sep 25 12:12:53 2022 +0200
@@ -158,21 +158,16 @@
     serverconfig->resources = ucx_map_new_a(serverconfig->a, 16);
     serverconfig->dav = ucx_map_new_a(serverconfig->a, 16);
     
-    /*
-     * convert ServerConfig to ServerConfiguration
-     * 
-     * its important to do this in the correct order:
-     * LogFile (open log file first to log possible errors)
-     * Runtime
-     * Threadpool
-     * EventHandler
-     * AuthDB
-     * Listener (we set the VirtualServer later)
-     * VirtualServer (dependencies: Listener)
-     */
+    // STAGE 1 load_server_conf:
+    // At stage 1 we load the file and get the Runtime infos for changing
+    // the uid, which must be done before most steps.
+    // Before the uid can be changed, we also need to bind listeners,
+    // therefore we need to get the listener config and all dependencies.
+    // 
+    // Runtime
+    // Listener (dependencies: Threadpool, EventHandler)
     
-    // load Runtime  infos first, because we need that to change the uid
-    // and the server should do that as soon as possible
+    // load Runtime config
     UcxList *list = serverconfig_get_node_list(serverconf->root, CONFIG_NODE_OBJECT, SC("Runtime"));
     UCX_FOREACH(elm, list) {
         ConfigNode *runtimeobj = elm->data;
@@ -183,6 +178,48 @@
     }
     ucx_list_free(list);
     
+    // load threadpool config
+    log_ereport(LOG_DEBUG, "apply config: Threadpool");
+    list = serverconfig_get_node_list(serverconf->root, CONFIG_NODE_OBJECT, SC("Threadpool"));
+    UCX_FOREACH(elm, list) {
+        if(cfg_handle_threadpool(serverconfig, elm->data)) {
+            return NULL;
+        }
+    }
+    ucx_list_free(list);
+    // check thread pool config
+    if(check_thread_pool_cfg() != 0) {
+        /* critical error */
+        return NULL;
+    }
+    
+    // load eventhandler config
+    log_ereport(LOG_DEBUG, "apply config: EventHandler");
+    list = serverconfig_get_node_list(serverconf->root, CONFIG_NODE_OBJECT, SC("EventHandler"));
+    UCX_FOREACH(elm, list) {
+        if(cfg_handle_eventhandler(serverconfig, elm->data)) {
+            // error            
+            return NULL;
+        }
+    }
+    // check event handler config
+    if(check_event_handler_cfg() != 0) {
+        /* critical error */
+        return NULL;
+    }
+    ucx_list_free(list);
+    
+    // load Listener config
+    log_ereport(LOG_DEBUG, "apply config: Listener");
+    list = serverconfig_get_node_list(serverconf->root, CONFIG_NODE_OBJECT, SC("Listener"));
+    UCX_FOREACH(elm, list) {
+        ConfigNode *scfgobj = elm->data;
+        if(cfg_handle_listener(serverconfig, scfgobj)) {
+            return NULL;
+        }
+    }
+    ucx_list_free(list);
+    
     // we return here, to let the webserver use the runtime info to
     // change the uid if needed
     return serverconfig;
@@ -192,6 +229,18 @@
     ServerConfig *serverconf = mgr->serverconf;
     ServerConfiguration *serverconfig = mgr->cfg;
     
+    /*
+     * convert ServerConfig to ServerConfiguration
+     * 
+     * its important to do this in the correct order:
+     * LogFile (open log file first to log possible errors)
+     * Threadpool
+     * EventHandler
+     * AuthDB
+     * Listener (we set the VirtualServer later)
+     * VirtualServer (dependencies: Listener)
+     */
+    
     // init logfile first
     UcxList *list;
     
@@ -214,37 +263,6 @@
         return NULL;
     }
     ucx_list_free(list);
-     
-    
-    log_ereport(LOG_DEBUG, "apply config: Threadpool");
-    list = serverconfig_get_node_list(serverconf->root, CONFIG_NODE_OBJECT, SC("Threadpool"));
-    UCX_FOREACH(elm, list) {
-        if(cfg_handle_threadpool(serverconfig, elm->data)) {
-            return NULL;
-        }
-    }
-    ucx_list_free(list);
-    // check thread pool config
-    if(check_thread_pool_cfg() != 0) {
-        /* critical error */
-        return NULL;
-    }
-    
-    log_ereport(LOG_DEBUG, "apply config: EventHandler");
-    list = serverconfig_get_node_list(serverconf->root, CONFIG_NODE_OBJECT, SC("EventHandler"));
-    UCX_FOREACH(elm, list) {
-        if(cfg_handle_eventhandler(
-                serverconfig, elm->data)) {
-            // error            
-            return NULL;
-        }
-    }
-    // check event handler config
-    if(check_event_handler_cfg() != 0) {
-        /* critical error */
-        return NULL;
-    }
-    ucx_list_free(list);
     
     log_ereport(LOG_DEBUG, "apply config: AccessLog");
     list = serverconfig_get_node_list(serverconf->root, CONFIG_NODE_OBJECT, SC("AccessLog"));
@@ -266,16 +284,6 @@
     }
     ucx_list_free(list);
     
-    log_ereport(LOG_DEBUG, "apply config: Listener");
-    list = serverconfig_get_node_list(serverconf->root, CONFIG_NODE_OBJECT, SC("Listener"));
-    UCX_FOREACH(elm, list) {
-        ConfigNode *scfgobj = elm->data;
-        if(cfg_handle_listener(serverconfig, scfgobj)) {
-            return NULL;
-        }
-    }
-    ucx_list_free(list);
-    
     log_ereport(LOG_DEBUG, "apply config: VirtualServer");
     list = serverconfig_get_node_list(serverconf->root, CONFIG_NODE_OBJECT, SC("VirtualServer"));
     UCX_FOREACH(elm, list) {

mercurial