+/* Set default values to stuff that was not configured. */
+
+static void silc_server_config_set_defaults(SilcServerConfig config)
+{
+ my_set_param_defaults(&config->param, NULL);
+
+ config->channel_rekey_secs = (config->channel_rekey_secs ?
+ config->channel_rekey_secs :
+ SILC_SERVER_CHANNEL_REKEY);
+ config->key_exchange_timeout = (config->key_exchange_timeout ?
+ config->key_exchange_timeout :
+ SILC_SERVER_SKE_TIMEOUT);
+ config->conn_auth_timeout = (config->conn_auth_timeout ?
+ config->conn_auth_timeout :
+ SILC_SERVER_CONNAUTH_TIMEOUT);
+}
+
+/* Check for correctness of the configuration */
+
+static bool silc_server_config_check(SilcServerConfig config)
+{
+ bool ret = TRUE;
+ SilcServerConfigServer *s;
+ SilcServerConfigRouter *r;
+ bool b = FALSE;
+
+ /* ServerConfig is mandatory */
+ if (!config->server_info) {
+ SILC_SERVER_LOG_ERROR(("\nError: Missing mandatory block `ServerInfo'"));
+ ret = FALSE;
+ }
+
+ /* RouterConnection sanity checks */
+
+ if (config->routers && config->routers->backup_router == TRUE &&
+ !config->servers) {
+ SILC_SERVER_LOG_ERROR((
+ "\nError: First RouterConnection block must be primary router "
+ "connection. You have marked it incorrectly as backup router."));
+ ret = FALSE;
+ }
+ if (config->routers && config->routers->initiator == FALSE &&
+ config->routers->backup_router == FALSE) {
+ SILC_SERVER_LOG_ERROR((
+ "\nError: First RouterConnection block must be primary router "
+ "connection and it must be marked as Initiator."));
+ ret = FALSE;
+ }
+ if (config->routers && config->routers->backup_router == TRUE &&
+ !config->servers && !config->routers->next) {
+ SILC_SERVER_LOG_ERROR((
+ "\nError: You have configured backup router but not primary router. "
+ "If backup router is configured also primary router must be "
+ "configured."));
+ ret = FALSE;
+ }
+
+ /* Backup router sanity checks */
+
+ for (r = config->routers; r; r = r->next) {
+ if (r->backup_router && !strcmp(r->host, r->backup_replace_ip)) {
+ SILC_SERVER_LOG_ERROR((
+ "\nError: Backup router connection incorrectly configured to use "
+ "primary and backup router as same host `%s'. They must not be "
+ "same host.", r->host));
+ ret = FALSE;
+ }
+ }
+
+ /* ServerConnection sanity checks */
+
+ for (s = config->servers; s; s = s->next) {
+ if (s->backup_router) {
+ b = TRUE;
+ break;
+ }
+ }
+ if (b) {
+ for (s = config->servers; s; s = s->next) {
+ if (!s->backup_router) {
+ SILC_SERVER_LOG_ERROR((
+ "\nError: Your server is backup router but not all ServerConnection "
+ "blocks were marked as backup connections. They all must be "
+ "marked as backup connections."));
+ ret = FALSE;
+ break;
+ }
+ }
+ }
+
+ return ret;
+}
+