Added stacktrace support with --enable-stack-trace option.
[silc.git] / apps / silcd / serverconfig.c
index b5dbc04ce5a90ba6c885c9202719d725d270f96f..505e87622c31d8dc5803be5cb7f0ec5eea38a02f 100644 (file)
   __type__ *findtmp, *tmp = (__type__ *) config->tmp;                  \
   int got_errno = 0
 
+/* allocate the tmp field for fetching data */
+#define SILC_SERVER_CONFIG_ALLOCTMP(__type__)                          \
+  if (!tmp) {                                                          \
+    config->tmp = silc_calloc(1, sizeof(*findtmp));                    \
+    tmp = (__type__ *) config->tmp;                                    \
+  }
+
 /* append the tmp field to the specified list */
 #define SILC_SERVER_CONFIG_LIST_APPENDTMP(__list__)                    \
   if (!__list__) {                                                     \
@@ -78,7 +85,7 @@ my_set_param_defaults(SilcServerConfigConnParams *params,
   (params->p ? params->p : (defaults && defaults->p ? defaults->p : d))
 
   SET_PARAM_DEFAULT(connections_max, SILC_SERVER_MAX_CONNECTIONS);
-  SET_PARAM_DEFAULT(connections_max_per_host, 
+  SET_PARAM_DEFAULT(connections_max_per_host,
                    SILC_SERVER_MAX_CONNECTIONS_SINGLE);
   SET_PARAM_DEFAULT(keepalive_secs, SILC_SERVER_KEEPALIVE);
   SET_PARAM_DEFAULT(reconnect_count, SILC_SERVER_RETRY_COUNT);
@@ -91,7 +98,7 @@ my_set_param_defaults(SilcServerConfigConnParams *params,
 
 /* Find connection parameters by the parameter block name. */
 static SilcServerConfigConnParams *
-my_find_param(SilcServerConfig config, const char *name, SilcUInt32 line)
+my_find_param(SilcServerConfig config, const char *name)
 {
   SilcServerConfigConnParams *param;
 
@@ -100,31 +107,39 @@ my_find_param(SilcServerConfig config, const char *name, SilcUInt32 line)
       return param;
   }
 
-  SILC_SERVER_LOG_ERROR(("\nError while parsing config file at line %lu: "
-                        "Cannot find Param \"%s\".\n", line, name));
+  SILC_SERVER_LOG_ERROR(("Error while parsing config file: "
+                        "Cannot find Params \"%s\".\n", name));
 
   return NULL;
 }
 
 /* parse an authdata according to its auth method */
-static bool my_parse_authdata(SilcAuthMethod auth_meth, char *p, 
-                             SilcUInt32 line, void **auth_data, 
+static bool my_parse_authdata(SilcAuthMethod auth_meth, char *p,
+                             SilcUInt32 line, void **auth_data,
                              SilcUInt32 *auth_data_len)
 {
   if (auth_meth == SILC_AUTH_PASSWORD) {
     /* p is a plain text password */
-    if (auth_data)
-      *auth_data = (void *) strdup(p);
-    if (auth_data_len)
-      *auth_data_len = (SilcUInt32) strlen(p);
+    if (auth_data && auth_data_len) {
+      if (!silc_utf8_valid(p, strlen(p))) {
+       *auth_data_len = silc_utf8_encoded_len(p, strlen(p), 0);
+       *auth_data = silc_calloc(*auth_data_len, sizeof(unsigned char));
+       silc_utf8_encode(p, strlen(p), SILC_STRING_ASCII, *auth_data,
+                        *auth_data_len);
+      } else {
+       *auth_data = (void *) strdup(p);
+       *auth_data_len = (SilcUInt32) strlen(p);
+      }
+    }
   } else if (auth_meth == SILC_AUTH_PUBLIC_KEY) {
     /* p is a public key file name */
     SilcPublicKey public_key;
 
     if (!silc_pkcs_load_public_key(p, &public_key, SILC_PKCS_FILE_PEM))
       if (!silc_pkcs_load_public_key(p, &public_key, SILC_PKCS_FILE_BIN)) {
-       SILC_SERVER_LOG_ERROR(("\nError while parsing config file at line %lu: "
-                              "Could not load public key file!\n", line));
+       SILC_SERVER_LOG_ERROR(("\nError while parsing config file at line "
+                              "%lu: Could not load public key file!\n",
+                              line));
        return FALSE;
       }
 
@@ -200,19 +215,25 @@ SILC_CONFIG_CALLBACK(fetch_generic)
   }
   else if (!strcmp(name, "version_protocol")) {
     CONFIG_IS_DOUBLE(config->param.version_protocol);
-    config->param.version_protocol = 
+    config->param.version_protocol =
       (*(char *)val ? strdup((char *) val) : NULL);
   }
   else if (!strcmp(name, "version_software")) {
     CONFIG_IS_DOUBLE(config->param.version_software);
-    config->param.version_software = 
+    config->param.version_software =
       (*(char *)val ? strdup((char *) val) : NULL);
   }
   else if (!strcmp(name, "version_software_vendor")) {
     CONFIG_IS_DOUBLE(config->param.version_software_vendor);;
-    config->param.version_software_vendor = 
+    config->param.version_software_vendor =
       (*(char *)val ? strdup((char *) val) : NULL);
   }
+  else if (!strcmp(name, "detach_disabled")) {
+    config->detach_disabled = *(bool *)val;
+  }
+  else if (!strcmp(name, "detach_timeout")) {
+    config->detach_timeout = (SilcUInt32) *(int *)val;
+  }
   else
     return SILC_CONFIG_EINTERNAL;
 
@@ -230,22 +251,18 @@ SILC_CONFIG_CALLBACK(fetch_cipher)
                       type, name, context));
   if (type == SILC_CONFIG_ARG_BLOCK) {
     /* check the temporary struct's fields */
-    if (!tmp) /* empty sub-block? */
+    if (!tmp) /* discard empty sub-blocks */
       return SILC_CONFIG_OK;
     if (!tmp->name) {
       got_errno = SILC_CONFIG_EMISSFIELDS;
       goto got_err;
     }
-    /* the temporary struct is ok, append it to the list */
+
     SILC_SERVER_CONFIG_LIST_APPENDTMP(config->cipher);
     config->tmp = NULL;
     return SILC_CONFIG_OK;
   }
-  /* if there isn't a temporary struct alloc one */
-  if (!tmp) {
-    config->tmp = silc_calloc(1, sizeof(*findtmp));
-    tmp = (SilcServerConfigCipher *) config->tmp;
-  }
+  SILC_SERVER_CONFIG_ALLOCTMP(SilcServerConfigCipher);
 
   /* Identify and save this value */
   if (!strcmp(name, "name")) {
@@ -282,23 +299,18 @@ SILC_CONFIG_CALLBACK(fetch_hash)
                       type, name, context));
   if (type == SILC_CONFIG_ARG_BLOCK) {
     /* check the temporary struct's fields */
-    if (!tmp) /* empty sub-block? */
+    if (!tmp) /* discard empty sub-blocks */
       return SILC_CONFIG_OK;
     if (!tmp->name || (tmp->block_length == 0) || (tmp->digest_length == 0)) {
       got_errno = SILC_CONFIG_EMISSFIELDS;
       goto got_err;
     }
-    /* the temporary struct in tmp is ok */
+
     SILC_SERVER_CONFIG_LIST_APPENDTMP(config->hash);
     config->tmp = NULL;
     return SILC_CONFIG_OK;
   }
-
-  /* if there isn't a temporary struct alloc one */
-  if (!tmp) {
-    config->tmp = silc_calloc(1, sizeof(*findtmp));
-    tmp = (SilcServerConfigHash *) config->tmp;
-  }
+  SILC_SERVER_CONFIG_ALLOCTMP(SilcServerConfigHash);
 
   /* Identify and save this value */
   if (!strcmp(name, "name")) {
@@ -335,22 +347,18 @@ SILC_CONFIG_CALLBACK(fetch_hmac)
                       type, name, context));
   if (type == SILC_CONFIG_ARG_BLOCK) {
     /* check the temporary struct's fields */
-    if (!tmp) /* empty sub-block? */
+    if (!tmp) /* discard empty sub-blocks */
       return SILC_CONFIG_OK;
     if (!tmp->name || !tmp->hash || (tmp->mac_length == 0)) {
       got_errno = SILC_CONFIG_EMISSFIELDS;
       goto got_err;
     }
-    /* the temporary struct is ok, append it to the list */
+
     SILC_SERVER_CONFIG_LIST_APPENDTMP(config->hmac);
     config->tmp = NULL;
     return SILC_CONFIG_OK;
   }
-  /* if there isn't a temporary struct alloc one */
-  if (!tmp) {
-    config->tmp = silc_calloc(1, sizeof(*findtmp));
-    tmp = (SilcServerConfigHmac *) config->tmp;
-  }
+  SILC_SERVER_CONFIG_ALLOCTMP(SilcServerConfigHmac);
 
   /* Identify and save this value */
   if (!strcmp(name, "name")) {
@@ -384,22 +392,18 @@ SILC_CONFIG_CALLBACK(fetch_pkcs)
                       type, name, context));
   if (type == SILC_CONFIG_ARG_BLOCK) {
     /* check the temporary struct's fields */
-    if (!tmp) /* empty sub-block? */
+    if (!tmp) /* discard empty sub-blocks */
       return SILC_CONFIG_OK;
     if (!tmp->name) {
       got_errno = SILC_CONFIG_EMISSFIELDS;
       goto got_err;
     }
-    /* the temporary struct is ok, append it to the list */
+
     SILC_SERVER_CONFIG_LIST_APPENDTMP(config->pkcs);
     config->tmp = NULL;
     return SILC_CONFIG_OK;
   }
-  /* if there isn't a temporary struct alloc one */
-  if (!tmp) {
-    config->tmp = silc_calloc(1, sizeof(*findtmp));
-    tmp = (SilcServerConfigPkcs *) config->tmp;
-  }
+  SILC_SERVER_CONFIG_ALLOCTMP(SilcServerConfigPkcs);
 
   /* Identify and save this value */
   if (!strcmp(name, "name")) {
@@ -419,9 +423,8 @@ SILC_CONFIG_CALLBACK(fetch_pkcs)
 
 SILC_CONFIG_CALLBACK(fetch_serverinfo)
 {
-  SilcServerConfig config = (SilcServerConfig) context;
+  SILC_SERVER_CONFIG_SECTION_INIT(SilcServerConfigServerInfoInterface);
   SilcServerConfigServerInfo *server_info = config->server_info;
-  int got_errno = 0;
 
   /* if there isn't the struct alloc it */
   if (!server_info)
@@ -429,8 +432,20 @@ SILC_CONFIG_CALLBACK(fetch_serverinfo)
                silc_calloc(1, sizeof(*server_info));
 
   if (type == SILC_CONFIG_ARG_BLOCK) {
-    /* check for mandatory inputs */
-    if (!server_info->public_key || !server_info->private_key) {
+    if (!strcmp(name, "primary")) {
+      CONFIG_IS_DOUBLE(server_info->primary);
+      if (!tmp)
+       return SILC_CONFIG_OK;
+      server_info->primary = tmp;
+      config->tmp = NULL;
+      return SILC_CONFIG_OK;
+    } else if (!strcmp(name, "secondary")) {
+      if (!tmp)
+       return SILC_CONFIG_OK;
+      SILC_SERVER_CONFIG_LIST_APPENDTMP(server_info->secondary);
+      config->tmp = NULL;
+      return SILC_CONFIG_OK;
+    } else if (!server_info->public_key || !server_info->private_key) {
       got_errno = SILC_CONFIG_EMISSFIELDS;
       goto got_err;
     }
@@ -441,16 +456,20 @@ SILC_CONFIG_CALLBACK(fetch_serverinfo)
     server_info->server_name = strdup((char *) val);
   }
   else if (!strcmp(name, "ip")) {
-    CONFIG_IS_DOUBLE(server_info->server_ip);
-    server_info->server_ip = strdup((char *) val);
+    SILC_SERVER_CONFIG_ALLOCTMP(SilcServerConfigServerInfoInterface);
+    CONFIG_IS_DOUBLE(tmp->server_ip);
+    tmp->server_ip = strdup((char *) val);
   }
   else if (!strcmp(name, "port")) {
     int port = *(int *)val;
+    SILC_SERVER_CONFIG_ALLOCTMP(SilcServerConfigServerInfoInterface);
     if ((port <= 0) || (port > 65535)) {
-      SILC_SERVER_LOG_ERROR(("Error: line %lu: Invalid port number!\n", line));
-      return SILC_CONFIG_ESILENT;
+      SILC_SERVER_LOG_ERROR(("Error while parsing config file: "
+                            "Invalid port number!\n"));
+      got_errno = SILC_CONFIG_EPRINTLINE;
+      goto got_err;
     }
-    server_info->port = (SilcUInt16) port;
+    tmp->port = (SilcUInt16) port;
   }
   else if (!strcmp(name, "servertype")) {
     CONFIG_IS_DOUBLE(server_info->server_type);
@@ -493,7 +512,7 @@ SILC_CONFIG_CALLBACK(fetch_serverinfo)
       if (!silc_pkcs_load_public_key(file_tmp, &server_info->public_key,
                                     SILC_PKCS_FILE_BIN)) {
        SILC_SERVER_LOG_ERROR(("Error: Could not load public key file.\n"));
-       SILC_SERVER_LOG_ERROR(("   line %lu: file \"%s\"\n", line, file_tmp));
+       SILC_SERVER_LOG_ERROR(("   line %lu, file \"%s\"\n", line, file_tmp));
        return SILC_CONFIG_ESILENT;
       }
   }
@@ -506,7 +525,7 @@ SILC_CONFIG_CALLBACK(fetch_serverinfo)
       if (!silc_pkcs_load_private_key(file_tmp, &server_info->private_key,
                                      SILC_PKCS_FILE_PEM)) {
        SILC_SERVER_LOG_ERROR(("Error: Could not load private key file.\n"));
-       SILC_SERVER_LOG_ERROR(("   line %lu: file \"%s\"\n", line, file_tmp));
+       SILC_SERVER_LOG_ERROR(("   line %lu, file \"%s\"\n", line, file_tmp));
        return SILC_CONFIG_ESILENT;
       }
   }
@@ -515,15 +534,15 @@ SILC_CONFIG_CALLBACK(fetch_serverinfo)
   return SILC_CONFIG_OK;
 
  got_err:
+  silc_free(tmp);
+  silc_free(config->tmp);
+  config->tmp = NULL;
   return got_errno;
 }
 
 SILC_CONFIG_CALLBACK(fetch_logging)
 {
-  SilcServerConfig config = (SilcServerConfig) context;
-  SilcServerConfigLogging *tmp =
-       (SilcServerConfigLogging *) config->tmp;
-  int got_errno;
+  SILC_SERVER_CONFIG_SECTION_INIT(SilcServerConfigLogging);
 
   if (!strcmp(name, "quicklogs")) {
     config->logging_quick = *(bool *)val;
@@ -531,12 +550,19 @@ SILC_CONFIG_CALLBACK(fetch_logging)
   else if (!strcmp(name, "flushdelay")) {
     int flushdelay = *(int *)val;
     if (flushdelay < 2) { /* this value was taken from silclog.h (min delay) */
-      SILC_SERVER_LOG_ERROR(("Error: line %lu: Invalid flushdelay value, use "
-                       "quicklogs if you want real-time logging.\n", line));
-      return SILC_CONFIG_ESILENT;
+      SILC_SERVER_LOG_ERROR(("Error while parsing config file: "
+                           "Invalid flushdelay value, use quicklogs if you "
+                           "want real-time logging.\n"));
+      return SILC_CONFIG_EPRINTLINE;
     }
     config->logging_flushdelay = (long) flushdelay;
   }
+
+  /* The following istances happens only in Logging's sub-blocks, a match
+     for the sub-block name means that you should store the filename/maxsize
+     temporary struct to the proper logging channel.
+     If we get a match for "file" or "maxsize" this means that we are inside
+     a sub-sub-block and it is safe to alloc a new tmp. */
 #define FETCH_LOGGING_CHAN(__chan__, __member__)               \
   else if (!strcmp(name, __chan__)) {                          \
     if (!tmp) return SILC_CONFIG_OK;                           \
@@ -552,13 +578,8 @@ SILC_CONFIG_CALLBACK(fetch_logging)
   FETCH_LOGGING_CHAN("fatals", logging_fatals)
 #undef FETCH_LOGGING_CHAN
   else if (!strcmp(name, "file")) {
-    if (!tmp) { /* FIXME: what the fuck is this? */
-      config->tmp = silc_calloc(1, sizeof(*tmp));
-      tmp = (SilcServerConfigLogging *) config->tmp;
-    }
-    if (tmp->file) {
-      got_errno = SILC_CONFIG_EMISSFIELDS; goto got_err;
-    }
+    SILC_SERVER_CONFIG_ALLOCTMP(SilcServerConfigLogging);
+    CONFIG_IS_DOUBLE(tmp->file);
     tmp->file = strdup((char *) val);
   }
   else if (!strcmp(name, "size")) {
@@ -583,18 +604,16 @@ SILC_CONFIG_CALLBACK(fetch_connparam)
 {
   SILC_SERVER_CONFIG_SECTION_INIT(SilcServerConfigConnParams);
 
-  SERVER_CONFIG_DEBUG(("Received CONNPARAM type=%d name=\"%s\" (val=%x)", 
+  SERVER_CONFIG_DEBUG(("Received CONNPARAM type=%d name=\"%s\" (val=%x)",
                       type, name, context));
-
   if (type == SILC_CONFIG_ARG_BLOCK) {
-    if (!tmp)
+    /* check the temporary struct's fields */
+    if (!tmp) /* discard empty sub-blocks */
       return SILC_CONFIG_OK;
-
     if (!tmp->name) {
       got_errno = SILC_CONFIG_EMISSFIELDS;
       goto got_err;
     }
-
     /* Set defaults */
     my_set_param_defaults(tmp, &config->param);
 
@@ -602,12 +621,7 @@ SILC_CONFIG_CALLBACK(fetch_connparam)
     config->tmp = NULL;
     return SILC_CONFIG_OK;
   }
-
-  /* if there isn't a temporary struct alloc one */
-  if (!tmp) {
-    config->tmp = silc_calloc(1, sizeof(*findtmp));
-    tmp = (SilcServerConfigConnParams *) config->tmp;
-  }
+  SILC_SERVER_CONFIG_ALLOCTMP(SilcServerConfigConnParams);
 
   if (!strcmp(name, "name")) {
     CONFIG_IS_DOUBLE(tmp->name);
@@ -650,7 +664,7 @@ SILC_CONFIG_CALLBACK(fetch_connparam)
   }
   else if (!strcmp(name, "version_software_vendor")) {
     CONFIG_IS_DOUBLE(tmp->version_software_vendor);;
-    tmp->version_software_vendor = 
+    tmp->version_software_vendor =
       (*(char *)val ? strdup((char *) val) : NULL);
   }
   else
@@ -672,14 +686,11 @@ SILC_CONFIG_CALLBACK(fetch_client)
   SERVER_CONFIG_DEBUG(("Received CLIENT type=%d name=\"%s\" (val=%x)",
                       type, name, context));
 
-  /* alloc tmp before block checking (empty sub-blocks are welcome here) */
-  if (!tmp) {
-    config->tmp = silc_calloc(1, sizeof(*findtmp));
-    tmp = (SilcServerConfigClient *) config->tmp;
-  }
+  /* Alloc before block checking, because empty sub-blocks are welcome here */
+  SILC_SERVER_CONFIG_ALLOCTMP(SilcServerConfigClient);
 
   if (type == SILC_CONFIG_ARG_BLOCK) {
-    /* closing the block */
+    /* empty sub-blocks are welcome */
     SILC_SERVER_CONFIG_LIST_APPENDTMP(config->clients);
     config->tmp = NULL;
     return SILC_CONFIG_OK;
@@ -708,9 +719,9 @@ SILC_CONFIG_CALLBACK(fetch_client)
   }
   else if (!strcmp(name, "params")) {
     CONFIG_IS_DOUBLE(tmp->param);
-    tmp->param = my_find_param(config, (char *) val, line);
-    if (!tmp->param) { /* error already output */
-      got_errno = SILC_CONFIG_ESILENT;
+    tmp->param = my_find_param(config, (char *) val);
+    if (!tmp->param) { /* error message already output */
+      got_errno = SILC_CONFIG_EPRINTLINE;
       goto got_err;
     }
   }
@@ -732,22 +743,16 @@ SILC_CONFIG_CALLBACK(fetch_admin)
 
   SERVER_CONFIG_DEBUG(("Received CLIENT type=%d name=\"%s\" (val=%x)",
                       type, name, context));
-
   if (type == SILC_CONFIG_ARG_BLOCK) {
     /* check the temporary struct's fields */
-    if (!tmp) /* empty sub-block? */
+    if (!tmp) /* discard empty sub-blocks */
       return SILC_CONFIG_OK;
 
     SILC_SERVER_CONFIG_LIST_APPENDTMP(config->admins);
     config->tmp = NULL;
     return SILC_CONFIG_OK;
   }
-
-  /* if there isn't a temporary struct alloc one */
-  if (!tmp) {
-    config->tmp = silc_calloc(1, sizeof(*findtmp));
-    tmp = (SilcServerConfigAdmin *) config->tmp;
-  }
+  SILC_SERVER_CONFIG_ALLOCTMP(SilcServerConfigAdmin);
 
   /* Identify and save this value */
   if (!strcmp(name, "host")) {
@@ -801,21 +806,18 @@ SILC_CONFIG_CALLBACK(fetch_deny)
                       type, name, context));
   if (type == SILC_CONFIG_ARG_BLOCK) {
     /* check the temporary struct's fields */
-    if (!tmp) /* empty sub-block? */
+    if (!tmp) /* discard empty sub-blocks */
       return SILC_CONFIG_OK;
     if (!tmp->reason) {
       got_errno = SILC_CONFIG_EMISSFIELDS;
       goto got_err;
     }
+
     SILC_SERVER_CONFIG_LIST_APPENDTMP(config->denied);
     config->tmp = NULL;
     return SILC_CONFIG_OK;
   }
-  /* if there isn't a temporary struct alloc one */
-  if (!tmp) {
-    config->tmp = silc_calloc(1, sizeof(*findtmp));
-    tmp = (SilcServerConfigDeny *) config->tmp;
-  }
+  SILC_SERVER_CONFIG_ALLOCTMP(SilcServerConfigDeny);
 
   /* Identify and save this value */
   if (!strcmp(name, "host")) {
@@ -844,10 +846,9 @@ SILC_CONFIG_CALLBACK(fetch_server)
 
   SERVER_CONFIG_DEBUG(("Received SERVER type=%d name=\"%s\" (val=%x)",
                       type, name, context));
-
   if (type == SILC_CONFIG_ARG_BLOCK) {
     /* check the temporary struct's fields */
-    if (!tmp) /* empty sub-block? */
+    if (!tmp) /* discard empty sub-blocks */
       return SILC_CONFIG_OK;
 
     /* the temporary struct is ok, append it to the list */
@@ -855,12 +856,7 @@ SILC_CONFIG_CALLBACK(fetch_server)
     config->tmp = NULL;
     return SILC_CONFIG_OK;
   }
-
-  /* if there isn't a temporary struct alloc one */
-  if (!tmp) {
-    config->tmp = silc_calloc(1, sizeof(*findtmp));
-    tmp = (SilcServerConfigServer *) config->tmp;
-  }
+  SILC_SERVER_CONFIG_ALLOCTMP(SilcServerConfigServer);
 
   /* Identify and save this value */
   if (!strcmp(name, "host")) {
@@ -886,9 +882,9 @@ SILC_CONFIG_CALLBACK(fetch_server)
   }
   else if (!strcmp(name, "params")) {
     CONFIG_IS_DOUBLE(tmp->param);
-    tmp->param = my_find_param(config, (char *) val, line);
-    if (!tmp->param) { /* error already output */
-      got_errno = SILC_CONFIG_ESILENT;
+    tmp->param = my_find_param(config, (char *) val);
+    if (!tmp->param) { /* error message already output */
+      got_errno = SILC_CONFIG_EPRINTLINE;
       goto got_err;
     }
   }
@@ -914,22 +910,15 @@ SILC_CONFIG_CALLBACK(fetch_router)
 
   SERVER_CONFIG_DEBUG(("Received ROUTER type=%d name=\"%s\" (val=%x)",
                       type, name, context));
-
   if (type == SILC_CONFIG_ARG_BLOCK) {
-    if (!tmp) /* empty sub-block? */
+    if (!tmp) /* discard empty sub-blocks */
       return SILC_CONFIG_OK;
 
-    /* the temporary struct is ok, append it to the list */
     SILC_SERVER_CONFIG_LIST_APPENDTMP(config->routers);
     config->tmp = NULL;
     return SILC_CONFIG_OK;
   }
-
-  /* if there isn't a temporary struct alloc one */
-  if (!tmp) {
-    config->tmp = silc_calloc(1, sizeof(*findtmp));
-    tmp = (SilcServerConfigRouter *) config->tmp;
-  }
+  SILC_SERVER_CONFIG_ALLOCTMP(SilcServerConfigRouter);
 
   /* Identify and save this value */
   if (!strcmp(name, "host")) {
@@ -939,8 +928,10 @@ SILC_CONFIG_CALLBACK(fetch_router)
   else if (!strcmp(name, "port")) {
     int port = *(int *)val;
     if ((port <= 0) || (port > 65535)) {
-      SILC_SERVER_LOG_ERROR(("Error: line %lu: Invalid port number!\n", line));
-      return SILC_CONFIG_ESILENT;
+      SILC_SERVER_LOG_ERROR(("Error while parsing config file: "
+                            "Invalid port number!\n"));
+      got_errno = SILC_CONFIG_EPRINTLINE;
+      goto got_err;
     }
     tmp->port = (SilcUInt16) port;
   }
@@ -963,9 +954,9 @@ SILC_CONFIG_CALLBACK(fetch_router)
   }
   else if (!strcmp(name, "params")) {
     CONFIG_IS_DOUBLE(tmp->param);
-    tmp->param = my_find_param(config, (char *) val, line);
-    if (!tmp->param) { /* error already output */
-      got_errno = SILC_CONFIG_ESILENT;
+    tmp->param = my_find_param(config, (char *) val);
+    if (!tmp->param) { /* error message already output */
+      got_errno = SILC_CONFIG_EPRINTLINE;
       goto got_err;
     }
   }
@@ -976,12 +967,15 @@ SILC_CONFIG_CALLBACK(fetch_router)
     CONFIG_IS_DOUBLE(tmp->backup_replace_ip);
     tmp->backup_replace_ip = (*(char *)val ? strdup((char *) val) :
                              strdup("*"));
+    tmp->backup_router = TRUE;
   }
   else if (!strcmp(name, "backupport")) {
     int port = *(int *)val;
     if ((port <= 0) || (port > 65535)) {
-      SILC_SERVER_LOG_ERROR(("Error: line %lu: Invalid port number!\n", line));
-      return SILC_CONFIG_ESILENT;
+      SILC_SERVER_LOG_ERROR(("Error while parsing config file: "
+                            "Invalid port number!\n"));
+      got_errno = SILC_CONFIG_EPRINTLINE;
+      goto got_err;
     }
     tmp->backup_replace_port = (SilcUInt16) port;
   }
@@ -1019,9 +1013,11 @@ static const SilcConfigTable table_general[] = {
   { "channel_rekey_secs",      SILC_CONFIG_ARG_INT,    fetch_generic,  NULL },
   { "key_exchange_timeout",    SILC_CONFIG_ARG_INT,    fetch_generic,  NULL },
   { "conn_auth_timeout",       SILC_CONFIG_ARG_INT,    fetch_generic,  NULL },
-  { "version_protocol",                SILC_CONFIG_ARG_STR,    fetch_generic,  NULL },
-  { "version_software",                SILC_CONFIG_ARG_STR,    fetch_generic,  NULL },
-  { "version_software_vendor",  SILC_CONFIG_ARG_STR,    fetch_generic, NULL },
+  { "version_protocol",                SILC_CONFIG_ARG_STR,    fetch_generic,  NULL },
+  { "version_software",                SILC_CONFIG_ARG_STR,    fetch_generic,  NULL },
+  { "version_software_vendor", SILC_CONFIG_ARG_STR,    fetch_generic,  NULL },
+  { "detach_disabled",         SILC_CONFIG_ARG_TOGGLE, fetch_generic,  NULL },
+  { "detach_timeout",          SILC_CONFIG_ARG_INT,    fetch_generic,  NULL },
   { 0, 0, 0, 0 }
 };
 
@@ -1053,10 +1049,16 @@ static const SilcConfigTable table_pkcs[] = {
   { 0, 0, 0, 0 }
 };
 
-static const SilcConfigTable table_serverinfo[] = {
-  { "hostname",                SILC_CONFIG_ARG_STR,    fetch_serverinfo, NULL},
+static const SilcConfigTable table_serverinfo_c[] = {
   { "ip",              SILC_CONFIG_ARG_STR,    fetch_serverinfo, NULL},
   { "port",            SILC_CONFIG_ARG_INT,    fetch_serverinfo, NULL},
+  { 0, 0, 0, 0 }
+};
+
+static const SilcConfigTable table_serverinfo[] = {
+  { "hostname",                SILC_CONFIG_ARG_STR,    fetch_serverinfo, NULL},
+  { "primary",         SILC_CONFIG_ARG_BLOCK,  fetch_serverinfo, table_serverinfo_c},
+  { "secondary",       SILC_CONFIG_ARG_BLOCK,  fetch_serverinfo, table_serverinfo_c},
   { "servertype",      SILC_CONFIG_ARG_STR,    fetch_serverinfo, NULL},
   { "location",                SILC_CONFIG_ARG_STR,    fetch_serverinfo, NULL},
   { "admin",           SILC_CONFIG_ARG_STR,    fetch_serverinfo, NULL},
@@ -1101,7 +1103,7 @@ static const SilcConfigTable table_connparam[] = {
   { "key_exchange_pfs",               SILC_CONFIG_ARG_TOGGLE, fetch_connparam, NULL },
   { "version_protocol",               SILC_CONFIG_ARG_STR,    fetch_connparam, NULL },
   { "version_software",               SILC_CONFIG_ARG_STR,    fetch_connparam, NULL },
-  { "version_software_vendor", SILC_CONFIG_ARG_STR,    fetch_connparam,        NULL },
+  { "version_software_vendor", SILC_CONFIG_ARG_STR,     fetch_connparam,       NULL },
   { 0, 0, 0, 0 }
 };
 
@@ -1231,10 +1233,11 @@ SilcServerConfig silc_server_config_alloc(const char *filename)
     if (ret != SILC_CONFIG_ESILENT) {
       char *linebuf, *filename = silc_config_get_filename(file);
       SilcUInt32 line = silc_config_get_line(file);
-      SILC_SERVER_LOG_ERROR(("Error while parsing config file: %s.\n",
-                            silc_config_strerror(ret)));
+      if (ret != SILC_CONFIG_EPRINTLINE)
+        SILC_SERVER_LOG_ERROR(("Error while parsing config file: %s.\n",
+                              silc_config_strerror(ret)));
       linebuf = silc_config_read_line(file, line);
-      SILC_SERVER_LOG_ERROR(("  file %s line %lu:  %s\n", filename,
+      SILC_SERVER_LOG_ERROR(("  file %s line %lu:  %s\n\n", filename,
                             line, linebuf));
       silc_free(linebuf);
     }
@@ -1253,8 +1256,6 @@ SilcServerConfig silc_server_config_alloc(const char *filename)
     return NULL;
   }
 
-  /* XXX are there any other mandatory sections in the config file? */
-
   /* Set default to configuration parameters */
   silc_server_config_set_defaults(config_new);
 
@@ -1313,12 +1314,29 @@ void silc_server_config_destroy(SilcServerConfig config)
     silc_free(config->logging_errors->file);
   if (config->logging_fatals)
     silc_free(config->logging_fatals->file);
+  silc_free(config->logging_info);
+  silc_free(config->logging_warnings);
+  silc_free(config->logging_errors);
+  silc_free(config->logging_fatals);
+
+  silc_log_set_file(SILC_LOG_INFO, NULL, 0, NULL);
+  silc_log_set_file(SILC_LOG_WARNING, NULL, 0, NULL);
+  silc_log_set_file(SILC_LOG_ERROR, NULL, 0, NULL);
+  silc_log_set_file(SILC_LOG_FATAL, NULL, 0, NULL);
 
   /* Destroy the ServerInfo struct */
   if (config->server_info) {
     register SilcServerConfigServerInfo *si = config->server_info;
     silc_free(si->server_name);
-    silc_free(si->server_ip);
+    if (si->primary) {
+      silc_free(si->primary->server_ip);
+      silc_free(si->primary);
+    }
+    SILC_SERVER_CONFIG_LIST_DESTROY(SilcServerConfigServerInfoInterface,
+                                 si->secondary)
+      silc_free(di->server_ip);
+      silc_free(di);
+    }
     silc_free(si->server_type);
     silc_free(si->location);
     silc_free(si->admin);
@@ -1329,6 +1347,7 @@ void silc_server_config_destroy(SilcServerConfig config)
     silc_free(si->pid_file);
     silc_pkcs_public_key_free(si->public_key);
     silc_pkcs_private_key_free(si->private_key);
+    silc_free(si);
   }
 
   /* Now let's destroy the lists */
@@ -1452,7 +1471,7 @@ bool silc_server_config_register_ciphers(SilcServer server)
                                                SILC_CIPHER_SIM_SET_KEY));
        SILC_LOG_DEBUG(("set_key=%p", cipher_obj.set_key));
        cipher_obj.set_key_with_string =
-         silc_sim_getsym(sim, 
+         silc_sim_getsym(sim,
            silc_sim_symname(alg_name,
              SILC_CIPHER_SIM_SET_KEY_WITH_STRING));
        SILC_LOG_DEBUG(("set_key_with_string=%p",
@@ -1651,7 +1670,7 @@ void silc_server_config_setlogfiles(SilcServer server)
   SILC_LOG_DEBUG(("Setting configured log file names and options"));
 
   silc_log_quick = config->logging_quick;
-  silc_log_flushdelay = (config->logging_flushdelay ? 
+  silc_log_flushdelay = (config->logging_flushdelay ?
                         config->logging_flushdelay :
                         SILC_SERVER_LOG_FLUSH_DELAY);
 
@@ -1695,7 +1714,7 @@ silc_server_config_find_client(SilcServer server, char *host)
    nickname. */
 
 SilcServerConfigAdmin *
-silc_server_config_find_admin(SilcServer server, char *host, char *user, 
+silc_server_config_find_admin(SilcServer server, char *host, char *user,
                              char *nick)
 {
   SilcServerConfig config = server->config;