Merge branch 'master' of github.com:janvidar/uhub

This commit is contained in:
Jan Vidar Krey
2011-09-05 23:34:05 +02:00
15 changed files with 260 additions and 51 deletions

View File

@@ -1,6 +1,6 @@
/*
* uhub - A tiny ADC p2p connection hub
* Copyright (C) 2007-2010, Jan Vidar Krey
* Copyright (C) 2007-2011, Jan Vidar Krey
*
* 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
@@ -732,15 +732,22 @@ static int command_register(struct hub_info* hub, struct hub_user* user, struct
data.password[MAX_PASS_LEN] = '\0';
data.credentials = auth_cred_user;
if (acl_register_user(hub, &data))
if (hub->config->register_self)
{
sprintf(tmp, "User \"%s\" registered.", user->id.nick);
return command_status(hub, user, cmd, tmp);
if (acl_register_user(hub, &data))
{
sprintf(tmp, "User \"%s\" registered.", user->id.nick);
return command_status(hub, user, cmd, tmp);
}
else
{
sprintf(tmp, "Unable to register user \"%s\".", user->id.nick);
return command_status(hub, user, cmd, tmp);
}
}
else
{
sprintf(tmp, "Unable to register user \"%s\".", user->id.nick);
return command_status(hub, user, cmd, tmp);
return command_status(hub, user, cmd, "You are not allowed to register.");
}
}

View File

@@ -108,6 +108,15 @@
<since>0.1.1</since>
</option>
<option name="register_self" type="boolean" default="0">
<short>Allow users to register themselves on the hub.</short>
<description><![CDATA[
If this is enabled guests can register their nickname on the hub.
Otherwise only operators can register users.
]]></description>
<since>0.4.0</since>
</option>
<option name="obsolete_clients" type="boolean" default="0">
<short>Support obsolete clients using a ADC protocol prior to 1.0</short>
<description><![CDATA[
@@ -417,6 +426,17 @@
<since>0.3.0</since>
</option>
<option name="tls_require_redirect_addr" type="string" default="">
<check regexp="(adc|adcs|dchub)://.*" />
<short>A redirect address in case a client connects using "adc://" when "adcs://" is required.</short>
<description><![CDATA[
This is the redirect address used when the hub wants to redirect a client for not using ADCS.
For instance a hub at adc://adc.example.com might redirect to adcs://adc.example.com
]]></description>
<since>0.3.3</since>
</option>
<option name="tls_certificate" type="file" default="">
<short>Certificate file</short>
<description><![CDATA[

View File

@@ -11,6 +11,7 @@ void config_defaults(struct hub_config* config)
config->show_banner_sys_info = 1;
config->max_users = 500;
config->registered_users_only = 0;
config->register_self = 0;
config->obsolete_clients = 0;
config->chat_only = 0;
config->chat_is_privileged = 0;
@@ -42,6 +43,7 @@ void config_defaults(struct hub_config* config)
config->flood_ctl_extras = 0;
config->tls_enable = 0;
config->tls_require = 0;
config->tls_require_redirect_addr = hub_strdup("");
config->tls_certificate = hub_strdup("");
config->tls_private_key = hub_strdup("");
config->file_motd = hub_strdup("");
@@ -183,6 +185,16 @@ static int apply_config(struct hub_config* config, char* key, char* data, int li
return 0;
}
if (!strcmp(key, "register_self"))
{
if (!apply_boolean(key, data, &config->register_self))
{
LOG_ERROR("Configuration parse error on line %d", line_count);
return -1;
}
return 0;
}
if (!strcmp(key, "obsolete_clients"))
{
if (!apply_boolean(key, data, &config->obsolete_clients))
@@ -496,6 +508,16 @@ static int apply_config(struct hub_config* config, char* key, char* data, int li
return 0;
}
if (!strcmp(key, "tls_require_redirect_addr"))
{
if (!apply_string(key, data, &config->tls_require_redirect_addr, (char*) ""))
{
LOG_ERROR("Configuration parse error on line %d", line_count);
return -1;
}
return 0;
}
if (!strcmp(key, "tls_certificate"))
{
if (!apply_string(key, data, &config->tls_certificate, (char*) ""))
@@ -933,6 +955,8 @@ void free_config(struct hub_config* config)
hub_free(config->redirect_addr);
hub_free(config->tls_require_redirect_addr);
hub_free(config->tls_certificate);
hub_free(config->tls_private_key);
@@ -1048,6 +1072,9 @@ void dump_config(struct hub_config* config, int ignore_defaults)
if (!ignore_defaults || config->registered_users_only != 0)
fprintf(stdout, "registered_users_only = %s\n", config->registered_users_only ? "yes" : "no");
if (!ignore_defaults || config->register_self != 0)
fprintf(stdout, "register_self = %s\n", config->register_self ? "yes" : "no");
if (!ignore_defaults || config->obsolete_clients != 0)
fprintf(stdout, "obsolete_clients = %s\n", config->obsolete_clients ? "yes" : "no");
@@ -1141,6 +1168,9 @@ void dump_config(struct hub_config* config, int ignore_defaults)
if (!ignore_defaults || config->tls_require != 0)
fprintf(stdout, "tls_require = %s\n", config->tls_require ? "yes" : "no");
if (!ignore_defaults || strcmp(config->tls_require_redirect_addr, "") != 0)
fprintf(stdout, "tls_require_redirect_addr = \"%s\"\n", config->tls_require_redirect_addr);
if (!ignore_defaults || strcmp(config->tls_certificate, "") != 0)
fprintf(stdout, "tls_certificate = \"%s\"\n", config->tls_certificate);

View File

@@ -11,6 +11,7 @@ struct hub_config
int show_banner_sys_info; /*<<< Show banner on connect (default: 1) */
int max_users; /*<<< Maximum number of users allowed on the hub (default: 500) */
int registered_users_only; /*<<< Allow registered users only (default: 0) */
int register_self; /*<<< Allow users to register themselves on the hub. (default: 0) */
int obsolete_clients; /*<<< Support obsolete clients using a ADC protocol prior to 1.0 (default: 0) */
int chat_only; /*<<< Allow chat only operation on hub (default: 0) */
int chat_is_privileged; /*<<< Allow chat for operators and above only (default: 0) */
@@ -42,6 +43,7 @@ struct hub_config
int flood_ctl_extras; /*<<< Max extra messages allowed in time interval (default: 0) */
int tls_enable; /*<<< Enable SSL/TLS support (default: 0) */
int tls_require; /*<<< If SSL/TLS enabled, should it be required (default: 0) (default: 0) */
char* tls_require_redirect_addr; /*<<< A redirect address in case a client connects using "adc://" when "adcs://" is required. (default: ) */
char* tls_certificate; /*<<< Certificate file (default: ) */
char* tls_private_key; /*<<< Private key file (default: ) */
char* file_motd; /*<<< File containing the 'message of the day (default: ) */

View File

@@ -695,6 +695,7 @@ static int load_ssl_certificates(struct hub_info* hub, struct hub_config* config
/* Disable SSLv2 */
SSL_CTX_set_options(hub->ssl_ctx, SSL_OP_NO_SSLv2);
SSL_CTX_set_quiet_shutdown(hub->ssl_ctx, 1);
if (SSL_CTX_use_certificate_file(hub->ssl_ctx, config->tls_certificate, SSL_FILETYPE_PEM) < 0)
{
@@ -824,7 +825,6 @@ void hub_shutdown_service(struct hub_info* hub)
event_queue_shutdown(hub->queue);
net_con_close(hub->server);
hub_free(hub->server);
server_alt_port_stop(hub);
uman_shutdown(hub);
hub->status = hub_status_stopped;
@@ -840,21 +840,22 @@ void hub_shutdown_service(struct hub_info* hub)
}
#ifdef PLUGIN_SUPPORT
void hub_plugins_load(struct hub_info* hub)
int hub_plugins_load(struct hub_info* hub)
{
if (!hub->config->file_plugins || !*hub->config->file_plugins)
return;
return 0;
hub->plugins = hub_malloc_zero(sizeof(struct uhub_plugins));
if (!hub->plugins)
return;
return -1;
if (plugin_initialize(hub->config, hub->plugins) < 0)
{
hub_free(hub->plugins);
hub->plugins = 0;
return;
return -1;
}
return 0;
}
void hub_plugins_unload(struct hub_info* hub)
@@ -943,7 +944,11 @@ void hub_set_variables(struct hub_info* hub, struct acl_handle* acl)
}
#ifdef PLUGIN_SUPPORT
hub_plugins_load(hub);
if (hub_plugins_load(hub) < 0)
{
hub->status = hub_status_shutdown;
}
else
#endif
hub->status = (hub->config->hub_enabled ? hub_status_running : hub_status_disabled);

View File

@@ -50,6 +50,17 @@ static void probe_net_event(struct net_connection* con, int events, void *arg)
if (probe->hub->config->tls_enable && probe->hub->config->tls_require)
{
LOG_TRACE("Not TLS connection - closing connection.");
if (*probe->hub->config->tls_require_redirect_addr)
{
char buf[512];
ssize_t len = snprintf(buf, sizeof(buf), "ISUP " ADC_PROTO_SUPPORT "\nISID AAAB\nIINF NIRedirecting...\nIQUI AAAB RD%s\n", probe->hub->config->tls_require_redirect_addr);
net_con_send(con, buf, (size_t) len);
LOG_TRACE("Not TLS connection - Redirecting to %s.", probe->hub->config->tls_require_redirect_addr);
}
else
{
LOG_TRACE("Not TLS connection - closing connection.");
}
}
else
#endif
@@ -60,9 +71,8 @@ static void probe_net_event(struct net_connection* con, int events, void *arg)
probe_destroy(probe);
return;
}
#ifdef SSL_SUPPORT
if (bytes >= 11 &&
else if (bytes >= 11 &&
probe_recvbuf[0] == 22 &&
probe_recvbuf[1] == 3 && /* protocol major version */
probe_recvbuf[5] == 1 && /* message type */
@@ -107,6 +117,8 @@ struct hub_probe* probe_create(struct hub_info* hub, int sd, struct ip_addr_enca
if (probe == NULL)
return NULL; /* OOM */
LOG_TRACE("probe_create(): %p", probe);
probe->hub = hub;
probe->connection = net_con_create();
net_con_initialize(probe->connection, sd, probe_net_event, probe, NET_EVENT_READ);
@@ -118,6 +130,7 @@ struct hub_probe* probe_create(struct hub_info* hub, int sd, struct ip_addr_enca
void probe_destroy(struct hub_probe* probe)
{
LOG_TRACE("probe_destroy(): %p (connection=%p)", probe, probe->connection);
if (probe->connection)
{
net_con_close(probe->connection);

View File

@@ -71,6 +71,12 @@ void user_destroy(struct hub_user* user)
hub_recvq_destroy(user->recv_queue);
hub_sendq_destroy(user->send_queue);
if (user->connection)
{
LOG_TRACE("user_destory() -> net_con_close(%p)", user->connection);
net_con_close(user->connection);
}
adc_msg_free(user->info);
user_clear_feature_cast_support(user);
hub_free(user);