Author: Johnny Mnemonic <johnny@themnemonic.org>
- Copyright (C) 1997 - 2002 Johnny Mnemonic
+ Copyright (C) 1997 - 2002 Pekka Riikonen
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
{
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;
}
if (type == SILC_CONFIG_ARG_BLOCK) {
/* check for mandatory inputs */
+ if (!server_info->public_key || !server_info->private_key) {
+ got_errno = SILC_CONFIG_EMISSFIELDS;
+ goto got_err;
+ }
return SILC_CONFIG_OK;
}
if (!strcmp(name, "hostname")) {
goto got_err;
}
}
- else if (!strcmp(name, "versionid")) {
- CONFIG_IS_DOUBLE(tmp->version);
- tmp->version = strdup((char *) val);
- }
else if (!strcmp(name, "params")) {
CONFIG_IS_DOUBLE(tmp->param);
tmp->param = my_find_param(config, (char *) val, line);
got_err:
silc_free(tmp->host);
- silc_free(tmp->version);
CONFIG_FREE_AUTH(tmp);
silc_free(tmp);
config->tmp = NULL;
goto got_err;
}
}
- else if (!strcmp(name, "versionid")) {
- CONFIG_IS_DOUBLE(tmp->version);
- tmp->version = strdup((char *) val);
- }
else if (!strcmp(name, "params")) {
CONFIG_IS_DOUBLE(tmp->param);
tmp->param = my_find_param(config, (char *) val, line);
got_err:
silc_free(tmp->host);
- silc_free(tmp->version);
silc_free(tmp->backup_replace_ip);
CONFIG_FREE_AUTH(tmp);
silc_free(tmp);
{ "host", SILC_CONFIG_ARG_STRE, fetch_server, NULL },
{ "passphrase", SILC_CONFIG_ARG_STR, fetch_server, NULL },
{ "publickey", SILC_CONFIG_ARG_STR, fetch_server, NULL },
- { "versionid", SILC_CONFIG_ARG_STR, fetch_server, NULL },
{ "params", SILC_CONFIG_ARG_STR, fetch_server, NULL },
{ "backup", SILC_CONFIG_ARG_TOGGLE, fetch_server, NULL },
{ 0, 0, 0, 0 }
{ "port", SILC_CONFIG_ARG_INT, fetch_router, NULL },
{ "passphrase", SILC_CONFIG_ARG_STR, fetch_router, NULL },
{ "publickey", SILC_CONFIG_ARG_STR, fetch_router, NULL },
- { "versionid", SILC_CONFIG_ARG_STR, fetch_router, NULL },
{ "params", SILC_CONFIG_ARG_STR, fetch_router, NULL },
{ "initiator", SILC_CONFIG_ARG_TOGGLE, fetch_router, NULL },
{ "backuphost", SILC_CONFIG_ARG_STRE, fetch_router, NULL },
}
/* Allocates a new configuration object, opens configuration file and
- * parses it. The parsed data is returned to the newly allocated
- * configuration object. */
+ parses it. The parsed data is returned to the newly allocated
+ configuration object. The SilcServerConfig must be freed by calling
+ the silc_server_config_destroy function. */
-SilcServerConfig silc_server_config_alloc(SilcServer server,
- const char *filename)
+SilcServerConfig silc_server_config_alloc(const char *filename)
{
SilcServerConfig config_new;
SilcConfigEntity ent;
/* alloc a config object */
config_new = silc_calloc(1, sizeof(*config_new));
+ config_new->refcount = 1;
if (!config_new)
return NULL;
/* obtain a config file object */
file = silc_config_open(filename);
if (!file) {
- SILC_SERVER_LOG_ERROR(("\nError: can't open config file `%s'\n",
+ SILC_SERVER_LOG_ERROR(("\nError: can't open config file `%s'\n",
filename));
return NULL;
}
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", filename,
line, linebuf));
silc_free(linebuf);
}
/* Set default to configuration parameters */
silc_server_config_set_defaults(config_new);
- silc_server_config_ref(&server->config_ref, config_new, config_new);
return config_new;
}
config->refcount++;
ref->config = config;
ref->ref_ptr = ref_ptr;
- SILC_LOG_DEBUG(("Referencing config [%p] refcnt %hu->%hu", config,
+ SILC_LOG_DEBUG(("Referencing config [%p] refcnt %d->%d", config,
config->refcount - 1, config->refcount));
}
}
void silc_server_config_unref(SilcServerConfigRef *ref)
{
- SilcServerConfig config = ref->config;
- if (ref->ref_ptr) {
- config->refcount--;
- SILC_LOG_DEBUG(("Unreferencing config [%p] refcnt %hu->%hu", config,
- config->refcount + 1, config->refcount));
- if (!config->refcount)
- silc_server_config_destroy(config);
- }
+ if (ref->ref_ptr)
+ silc_server_config_destroy(ref->config);
}
/* Destroy a config object with all his children lists */
{
void *tmp;
- if (config->refcount > 0) {
- config->refcount--;
- SILC_LOG_DEBUG(("Unreferencing config [%p] refcnt %hu->%hu", config,
- config->refcount + 1, config->refcount));
- if (config->refcount > 0)
- return;
- }
+ config->refcount--;
+ SILC_LOG_DEBUG(("Unreferencing config [%p] refcnt %d->%d", config,
+ config->refcount + 1, config->refcount));
+ if (config->refcount > 0)
+ return;
SILC_LOG_DEBUG(("Freeing config context"));
+ /* Destroy general config stuff */
silc_free(config->module_path);
+ silc_free(config->param.version_protocol);
+ silc_free(config->param.version_software);
+ silc_free(config->param.version_software_vendor);
/* Destroy Logging channels */
if (config->logging_info)
silc_free(si->group);
silc_free(si->motd_file);
silc_free(si->pid_file);
+ silc_pkcs_public_key_free(si->public_key);
+ silc_pkcs_private_key_free(si->private_key);
}
/* Now let's destroy the lists */
silc_free(di->name);
silc_free(di);
}
- SILC_SERVER_CONFIG_LIST_DESTROY(SilcServerConfigClient,
- config->clients)
+ SILC_SERVER_CONFIG_LIST_DESTROY(SilcServerConfigConnParams,
+ config->conn_params)
+ silc_free(di->name);
+ silc_free(di->version_protocol);
+ silc_free(di->version_software);
+ silc_free(di->version_software_vendor);
+ silc_free(di);
+ }
+ SILC_SERVER_CONFIG_LIST_DESTROY(SilcServerConfigClient, config->clients)
silc_free(di->host);
CONFIG_FREE_AUTH(di);
silc_free(di);
SILC_SERVER_CONFIG_LIST_DESTROY(SilcServerConfigServer,
config->servers)
silc_free(di->host);
- silc_free(di->version);
CONFIG_FREE_AUTH(di);
silc_free(di);
}
SILC_SERVER_CONFIG_LIST_DESTROY(SilcServerConfigRouter,
config->routers)
silc_free(di->host);
- silc_free(di->version);
silc_free(di->backup_replace_ip);
CONFIG_FREE_AUTH(di);
silc_free(di);