/* Free the authentication fields in the specified struct
* Expands to two instructions */
-#define CONFIG_FREE_AUTH(__section__) \
- silc_free(__section__->passphrase); \
- silc_pkcs_public_key_free(__section__->publickey)
+#define CONFIG_FREE_AUTH(__section__) \
+ silc_free(__section__->passphrase); \
+ if (__section__->publickeys) \
+ silc_hash_table_free(__section__->publickeys);
+
+static void my_free_public_key(void *key, void *context, void *user_data)
+{
+ silc_pkcs_public_key_free(context);
+}
/* Set default values to those parameters that have not been defined */
static void
my_set_param_defaults(SilcServerConfigConnParams *params,
SilcServerConfigConnParams *defaults)
{
-#define SET_PARAM_DEFAULT(p, d) \
+#define SET_PARAM_DEFAULT(p, d) params->p = \
(params->p ? params->p : (defaults && defaults->p ? defaults->p : d))
- params->connections_max =
- SET_PARAM_DEFAULT(connections_max, SILC_SERVER_MAX_CONNECTIONS);
- params->connections_max_per_host =
- SET_PARAM_DEFAULT(connections_max_per_host,
- SILC_SERVER_MAX_CONNECTIONS_SINGLE);
- params->keepalive_secs =
- SET_PARAM_DEFAULT(keepalive_secs, SILC_SERVER_KEEPALIVE);
- params->reconnect_count =
- SET_PARAM_DEFAULT(reconnect_count, SILC_SERVER_RETRY_COUNT);
- params->reconnect_interval =
- SET_PARAM_DEFAULT(reconnect_interval, SILC_SERVER_RETRY_INTERVAL_MIN);
- params->reconnect_interval_max =
- SET_PARAM_DEFAULT(reconnect_interval_max, SILC_SERVER_RETRY_INTERVAL_MAX);
- params->key_exchange_rekey =
- SET_PARAM_DEFAULT(key_exchange_rekey, SILC_SERVER_REKEY);
+ SET_PARAM_DEFAULT(connections_max, SILC_SERVER_MAX_CONNECTIONS);
+ 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);
+ SET_PARAM_DEFAULT(reconnect_interval, SILC_SERVER_RETRY_INTERVAL_MIN);
+ SET_PARAM_DEFAULT(reconnect_interval_max, SILC_SERVER_RETRY_INTERVAL_MAX);
+ SET_PARAM_DEFAULT(key_exchange_rekey, SILC_SERVER_REKEY);
}
/* Find connection parameters by the parameter block name. */
static SilcServerConfigConnParams *
-my_find_param(SilcServerConfig config, const char *name, uint32 line)
+my_find_param(SilcServerConfig config, const char *name, SilcUInt32 line)
{
SilcServerConfigConnParams *param;
}
/* parse an authdata according to its auth method */
-static bool my_parse_authdata(SilcAuthMethod auth_meth, char *p, uint32 line,
- void **auth_data, uint32 *auth_data_len)
+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 = (uint32) strlen(p);
+ *auth_data_len = (SilcUInt32) strlen(p);
} else if (auth_meth == SILC_AUTH_PUBLIC_KEY) {
- /* p is a 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))
"Could not load public key file!\n", line);
return FALSE;
}
- if (auth_data)
- *auth_data = (void *) public_key;
- if (auth_data_len)
- *auth_data_len = 0;
+
+ /* The auth_data is a pointer to the hash table of public keys. */
+ if (auth_data) {
+ if (*auth_data == NULL)
+ *auth_data = silc_hash_table_alloc(1, silc_hash_public_key, NULL,
+ NULL, NULL,
+ my_free_public_key, NULL,
+ TRUE);
+ silc_hash_table_add(*auth_data, public_key, public_key);
+ }
} else {
fprintf(stderr, "\nError while parsing config file at line %lu: "
"Unknown authentication method.\n", line);
config->require_reverse_lookup = *(bool *)val;
}
else if (!strcmp(name, "connections_max")) {
- config->param.connections_max = (uint32) *(int *)val;
+ config->param.connections_max = (SilcUInt32) *(int *)val;
}
else if (!strcmp(name, "connections_max_per_host")) {
- config->param.connections_max_per_host = (uint32) *(int *)val;
+ config->param.connections_max_per_host = (SilcUInt32) *(int *)val;
}
else if (!strcmp(name, "keepalive_secs")) {
- config->param.keepalive_secs = (uint32) *(int *)val;
+ config->param.keepalive_secs = (SilcUInt32) *(int *)val;
}
else if (!strcmp(name, "reconnect_count")) {
- config->param.reconnect_count = (uint32) *(int *)val;
+ config->param.reconnect_count = (SilcUInt32) *(int *)val;
}
else if (!strcmp(name, "reconnect_interval")) {
- config->param.reconnect_interval = (uint32) *(int *)val;
+ config->param.reconnect_interval = (SilcUInt32) *(int *)val;
}
else if (!strcmp(name, "reconnect_interval_max")) {
- config->param.reconnect_interval_max = (uint32) *(int *)val;
+ config->param.reconnect_interval_max = (SilcUInt32) *(int *)val;
}
else if (!strcmp(name, "reconnect_keep_trying")) {
config->param.reconnect_keep_trying = *(bool *)val;
}
else if (!strcmp(name, "key_exchange_rekey")) {
- config->param.key_exchange_rekey = (uint32) *(int *)val;
+ config->param.key_exchange_rekey = (SilcUInt32) *(int *)val;
}
else if (!strcmp(name, "key_exchange_pfs")) {
config->param.key_exchange_pfs = *(bool *)val;
}
else if (!strcmp(name, "channel_rekey_secs")) {
- config->channel_rekey_secs = (uint32) *(int *)val;
+ config->channel_rekey_secs = (SilcUInt32) *(int *)val;
}
else if (!strcmp(name, "key_exchange_timeout")) {
- config->key_exchange_timeout = (uint32) *(int *)val;
+ config->key_exchange_timeout = (SilcUInt32) *(int *)val;
}
else if (!strcmp(name, "conn_auth_timeout")) {
- config->conn_auth_timeout = (uint32) *(int *)val;
+ config->conn_auth_timeout = (SilcUInt32) *(int *)val;
+ }
+ else if (!strcmp(name, "version_protocol")) {
+ CONFIG_IS_DOUBLE(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 =
+ (*(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 =
+ (*(char *)val ? strdup((char *) val) : NULL);
}
else
return SILC_CONFIG_EINTERNAL;
tmp->module = (*(char *)val ? strdup((char *) val) : NULL);
}
else if (!strcmp(name, "keylength")) {
- tmp->key_length = *(uint32 *)val;
+ tmp->key_length = *(SilcUInt32 *)val;
}
else if (!strcmp(name, "blocklength")) {
- tmp->block_length = *(uint32 *)val;
+ tmp->block_length = *(SilcUInt32 *)val;
}
else
return SILC_CONFIG_EINTERNAL;
fprintf(stderr, "Invalid port number!\n");
return SILC_CONFIG_ESILENT;
}
- server_info->port = (uint16) port;
+ server_info->port = (SilcUInt16) port;
}
else if (!strcmp(name, "servertype")) {
CONFIG_IS_DOUBLE(server_info->server_type);
config->tmp = silc_calloc(1, sizeof(*tmp));
tmp = (SilcServerConfigLogging *) config->tmp;
}
- tmp->maxsize = *(uint32 *) val;
+ tmp->maxsize = *(SilcUInt32 *) val;
}
else
return SILC_CONFIG_EINTERNAL;
tmp->name = (*(char *)val ? strdup((char *) val) : NULL);
}
else if (!strcmp(name, "connections_max")) {
- tmp->connections_max = *(uint32 *)val;
+ tmp->connections_max = *(SilcUInt32 *)val;
}
else if (!strcmp(name, "connections_max_per_host")) {
- tmp->connections_max_per_host = *(uint32 *)val;
+ tmp->connections_max_per_host = *(SilcUInt32 *)val;
}
else if (!strcmp(name, "keepalive_secs")) {
- tmp->keepalive_secs = *(uint32 *)val;
+ tmp->keepalive_secs = *(SilcUInt32 *)val;
}
else if (!strcmp(name, "reconnect_count")) {
- tmp->reconnect_count = *(uint32 *)val;
+ tmp->reconnect_count = *(SilcUInt32 *)val;
}
else if (!strcmp(name, "reconnect_interval")) {
- tmp->reconnect_interval = *(uint32 *)val;
+ tmp->reconnect_interval = *(SilcUInt32 *)val;
}
else if (!strcmp(name, "reconnect_interval_max")) {
- tmp->reconnect_interval_max = *(uint32 *)val;
+ tmp->reconnect_interval_max = *(SilcUInt32 *)val;
}
else if (!strcmp(name, "reconnect_keep_trying")) {
tmp->reconnect_keep_trying = *(bool *)val;
}
else if (!strcmp(name, "key_exchange_rekey")) {
- tmp->key_exchange_rekey = *(uint32 *)val;
+ tmp->key_exchange_rekey = *(SilcUInt32 *)val;
}
else if (!strcmp(name, "key_exchange_pfs")) {
tmp->key_exchange_pfs = *(bool *)val;
}
+ else if (!strcmp(name, "version_protocol")) {
+ CONFIG_IS_DOUBLE(tmp->version_protocol);
+ tmp->version_protocol = (*(char *)val ? strdup((char *) val) : NULL);
+ }
+ else if (!strcmp(name, "version_software")) {
+ CONFIG_IS_DOUBLE(tmp->version_software);
+ tmp->version_software = (*(char *)val ? strdup((char *) val) : NULL);
+ }
+ else if (!strcmp(name, "version_software_vendor")) {
+ CONFIG_IS_DOUBLE(tmp->version_software_vendor);;
+ tmp->version_software_vendor =
+ (*(char *)val ? strdup((char *) val) : NULL);
+ }
else
return SILC_CONFIG_EINTERNAL;
tmp->host = (*(char *)val ? strdup((char *) val) : NULL);
}
else if (!strcmp(name, "passphrase")) {
+ CONFIG_IS_DOUBLE(tmp->passphrase);
if (!my_parse_authdata(SILC_AUTH_PASSWORD, (char *) val, line,
(void **)&tmp->passphrase,
&tmp->passphrase_len)) {
}
else if (!strcmp(name, "publickey")) {
if (!my_parse_authdata(SILC_AUTH_PUBLIC_KEY, (char *) val, line,
- &tmp->publickey, NULL)) {
+ (void **)&tmp->publickeys, NULL)) {
got_errno = SILC_CONFIG_ESILENT;
goto got_err;
}
tmp->nick = (*(char *)val ? strdup((char *) val) : NULL);
}
else if (!strcmp(name, "passphrase")) {
+ CONFIG_IS_DOUBLE(tmp->passphrase);
if (!my_parse_authdata(SILC_AUTH_PASSWORD, (char *) val, line,
(void **)&tmp->passphrase,
&tmp->passphrase_len)) {
}
}
else if (!strcmp(name, "publickey")) {
+ CONFIG_IS_DOUBLE(tmp->publickeys);
if (!my_parse_authdata(SILC_AUTH_PUBLIC_KEY, (char *) val, line,
- &tmp->publickey, NULL)) {
+ (void **)&tmp->publickeys, NULL)) {
got_errno = SILC_CONFIG_ESILENT;
goto got_err;
}
CONFIG_IS_DOUBLE(tmp->host);
tmp->host = (*(char *)val ? strdup((char *) val) : strdup("*"));
}
- else if (!strcmp(name, "port")) {
- int port = *(int *)val;
- if ((port <= 0) || (port > 65535)) {
- fprintf(stderr, "Invalid port number!\n");
- got_errno = SILC_CONFIG_ESILENT;
- goto got_err;
- }
- tmp->port = (uint16) port;
- }
else if (!strcmp(name, "reason")) {
CONFIG_IS_DOUBLE(tmp->reason);
tmp->reason = strdup((char *) val);
tmp->host = (*(char *)val ? strdup((char *) val) : strdup("*"));
}
else if (!strcmp(name, "passphrase")) {
+ CONFIG_IS_DOUBLE(tmp->passphrase);
if (!my_parse_authdata(SILC_AUTH_PASSWORD, (char *) val, line,
(void **)&tmp->passphrase,
&tmp->passphrase_len)) {
}
}
else if (!strcmp(name, "publickey")) {
+ CONFIG_IS_DOUBLE(tmp->publickeys);
if (!my_parse_authdata(SILC_AUTH_PUBLIC_KEY, (char *) val, line,
- &tmp->publickey, NULL)) {
+ (void **)&tmp->publickeys, NULL)) {
got_errno = SILC_CONFIG_ESILENT;
goto got_err;
}
fprintf(stderr, "Invalid port number!\n");
return SILC_CONFIG_ESILENT;
}
- tmp->port = (uint16) port;
+ tmp->port = (SilcUInt16) port;
}
else if (!strcmp(name, "passphrase")) {
+ CONFIG_IS_DOUBLE(tmp->passphrase);
if (!my_parse_authdata(SILC_AUTH_PASSWORD, (char *) val, line,
(void **)&tmp->passphrase,
&tmp->passphrase_len)) {
}
}
else if (!strcmp(name, "publickey")) {
+ CONFIG_IS_DOUBLE(tmp->publickeys);
if (!my_parse_authdata(SILC_AUTH_PUBLIC_KEY, (char *) val, line,
- &tmp->publickey, NULL)) {
+ (void **)&tmp->publickeys, NULL)) {
got_errno = SILC_CONFIG_ESILENT;
goto got_err;
}
tmp->backup_replace_ip = (*(char *)val ? strdup((char *) val) :
strdup("*"));
}
+ else if (!strcmp(name, "backupport")) {
+ int port = *(int *)val;
+ if ((port <= 0) || (port > 65535)) {
+ fprintf(stderr, "Invalid port number!\n");
+ return SILC_CONFIG_ESILENT;
+ }
+ tmp->backup_replace_port = (SilcUInt16) port;
+ }
+ else if (!strcmp(name, "backuplocal")) {
+ tmp->backup_local = *(bool *)val;
+ }
else
return SILC_CONFIG_EINTERNAL;
{ "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 },
{ 0, 0, 0, 0 }
};
{ "reconnect_keep_trying", SILC_CONFIG_ARG_TOGGLE, fetch_connparam, NULL },
{ "key_exchange_rekey", SILC_CONFIG_ARG_INT, fetch_connparam, NULL },
{ "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 },
{ 0, 0, 0, 0 }
};
static const SilcConfigTable table_deny[] = {
{ "host", SILC_CONFIG_ARG_STRE, fetch_deny, NULL },
- { "port", SILC_CONFIG_ARG_INT, fetch_deny, NULL },
{ "reason", SILC_CONFIG_ARG_STR, fetch_deny, NULL },
{ 0, 0, 0, 0 }
};
{ "initiator", SILC_CONFIG_ARG_TOGGLE, fetch_router, NULL },
{ "backuphost", SILC_CONFIG_ARG_STRE, fetch_router, NULL },
{ "backupport", SILC_CONFIG_ARG_INT, fetch_router, NULL },
- { "localbackup", SILC_CONFIG_ARG_TOGGLE, fetch_router, NULL },
+ { "backuplocal", SILC_CONFIG_ARG_TOGGLE, fetch_router, NULL },
{ 0, 0, 0, 0 }
};
/* handle this special error return which asks to quietly return */
if (ret != SILC_CONFIG_ESILENT) {
char *linebuf, *filename = silc_config_get_filename(file);
- uint32 line = silc_config_get_line(file);
+ SilcUInt32 line = silc_config_get_line(file);
fprintf(stderr, "\nError while parsing config file: %s.\n",
silc_config_strerror(ret));
linebuf = silc_config_read_line(file, line);
int i;
for (i = 0; silc_default_ciphers[i].name; i++)
if (!strcmp(silc_default_ciphers[i].name, cipher->name)) {
- silc_cipher_register(&silc_default_ciphers[i]);
+ silc_cipher_register((SilcCipherObject *)&silc_default_ciphers[i]);
break;
}
if (!silc_cipher_is_supported(cipher->name)) {
/* Load (try at least) the crypto SIM module */
char buf[1023], *alg_name;
SilcCipherObject cipher_obj;
- SilcSimContext *sim;
+ SilcSim sim;
memset(&cipher_obj, 0, sizeof(cipher_obj));
cipher_obj.name = cipher->name;
/* build the libname */
snprintf(buf, sizeof(buf), "%s/%s", config->module_path,
cipher->module);
- sim = silc_sim_alloc();
- sim->type = SILC_SIM_CIPHER;
- sim->libname = buf;
+ sim = silc_sim_alloc(SILC_SIM_CIPHER, buf, 0);
alg_name = strdup(cipher->name);
if (strchr(alg_name, '-'))
int i;
for (i = 0; silc_default_hash[i].name; i++)
if (!strcmp(silc_default_hash[i].name, hash->name)) {
- silc_hash_register(&silc_default_hash[i]);
+ silc_hash_register((SilcHashObject *)&silc_default_hash[i]);
break;
}
if (!silc_hash_is_supported(hash->name)) {
#ifdef SILC_SIM
/* Load (try at least) the hash SIM module */
SilcHashObject hash_obj;
- SilcSimContext *sim;
+ SilcSim sim;
memset(&hash_obj, 0, sizeof(hash_obj));
hash_obj.name = hash->name;
hash_obj.block_len = hash->block_length;
hash_obj.hash_len = hash->digest_length;
- sim = silc_sim_alloc();
- sim->type = SILC_SIM_HASH;
- sim->libname = hash->module;
+ sim = silc_sim_alloc(SILC_SIM_HASH, hash->module, 0);
if ((silc_sim_load(sim))) {
hash_obj.init =
silc_server_stop(server);
exit(1);
}
+
/* Register the HMAC */
memset(&hmac_obj, 0, sizeof(hmac_obj));
hmac_obj.name = hmac->name;
int i;
for (i = 0; silc_default_pkcs[i].name; i++)
if (!strcmp(silc_default_pkcs[i].name, pkcs->name)) {
- silc_pkcs_register(&silc_default_pkcs[i]);
+ silc_pkcs_register((SilcPKCSObject *)&silc_default_pkcs[i]);
break;
}
if (!silc_pkcs_is_supported(pkcs->name)) {
return admin;
}
-/* Returns the denied connection configuration entry by host and port. */
+/* Returns the denied connection configuration entry by host. */
SilcServerConfigDeny *
-silc_server_config_find_denied(SilcServer server, char *host, uint16 port)
+silc_server_config_find_denied(SilcServer server, char *host)
{
SilcServerConfig config = server->config;
SilcServerConfigDeny *deny;
/* make sure we have a value for the matching parameters */
- if (!config || !port) {
- SILC_LOG_WARNING(("Bogus: config_find_denied(config=0x%08x, "
- "host=0x%08x \"%s\", port=%hu)",
- (uint32) config, (uint32) host, host, port));
- return NULL;
- }
- if (!host)
+ if (!config || !host)
return NULL;
for (deny = config->denied; deny; deny = deny->next) {