summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSebastien Helleu <flashcode@flashtux.org>2010-09-17 16:44:35 +0200
committerSebastien Helleu <flashcode@flashtux.org>2010-09-17 16:44:35 +0200
commit914e3bcc9ed33c12838b73158532de7dd02ed52d (patch)
tree51f0d6dc299e85334e9d5994e426917d74d90ce2 /src
parent8b26f3c953f248cc2d66b2bf1a296f76e48c4c6d (diff)
downloadweechat-914e3bcc9ed33c12838b73158532de7dd02ed52d.zip
Add new option relay.network.password
Diffstat (limited to 'src')
-rw-r--r--src/plugins/relay/relay-client-irc.c32
-rw-r--r--src/plugins/relay/relay-client-irc.h1
-rw-r--r--src/plugins/relay/relay-config.c7
-rw-r--r--src/plugins/relay/relay-config.h1
4 files changed, 40 insertions, 1 deletions
diff --git a/src/plugins/relay/relay-client-irc.c b/src/plugins/relay/relay-client-irc.c
index 63a7e57b9..61fb119f4 100644
--- a/src/plugins/relay/relay-client-irc.c
+++ b/src/plugins/relay/relay-client-irc.c
@@ -35,6 +35,7 @@
#include "relay.h"
#include "relay-client-irc.h"
#include "relay-client.h"
+#include "relay-config.h"
#include "relay-raw.h"
@@ -639,6 +640,18 @@ relay_client_irc_recv_one_msg (struct t_relay_client *client, char *data)
}
if (!RELAY_IRC_DATA(client, connected))
{
+ if (irc_command && (weechat_strcasecmp (irc_command, "pass") == 0))
+ {
+ if (!RELAY_IRC_DATA(client, password_ok))
+ {
+ if (irc_args && irc_args[0]
+ && (strcmp (weechat_config_string (relay_config_network_password),
+ irc_args) == 0))
+ {
+ RELAY_IRC_DATA(client, password_ok) = 1;
+ }
+ }
+ }
if (irc_command && (weechat_strcasecmp (irc_command, "user") == 0))
{
/* check if connection to server is ok */
@@ -671,8 +684,20 @@ relay_client_irc_recv_one_msg (struct t_relay_client *client, char *data)
weechat_infolist_free (infolist_server);
}
}
- if (RELAY_IRC_DATA(client, nick) && RELAY_IRC_DATA(client, user_received))
+ if (RELAY_IRC_DATA(client, nick)
+ && RELAY_IRC_DATA(client, user_received))
{
+ /* disconnect client if password was not received or wrong */
+ if (!RELAY_IRC_DATA(client, password_ok))
+ {
+ relay_client_irc_sendf (client,
+ ":%s ERROR :WeeChat: password error",
+ RELAY_IRC_DATA(client, address));
+ relay_client_set_status (client,
+ RELAY_STATUS_DISCONNECTED);
+ return;
+ }
+
RELAY_IRC_DATA(client, connected) = 1;
/*
@@ -923,11 +948,15 @@ void
relay_client_irc_alloc (struct t_relay_client *client)
{
struct t_relay_client_irc_data *irc_data;
+ const char *password;
+
+ password = weechat_config_string (relay_config_network_password);
client->protocol_data = malloc (sizeof (*irc_data));
if (client->protocol_data)
{
RELAY_IRC_DATA(client, address) = strdup ("weechat.relay.irc");
+ RELAY_IRC_DATA(client, password_ok) = (password && password[0]) ? 0 : 1;
RELAY_IRC_DATA(client, nick) = NULL;
RELAY_IRC_DATA(client, user_received) = 0;
RELAY_IRC_DATA(client, connected) = 0;
@@ -974,6 +1003,7 @@ relay_client_irc_print_log (struct t_relay_client *client)
if (client->protocol_data)
{
weechat_log_printf (" address. . . . . . . . : '%s'", RELAY_IRC_DATA(client, address));
+ weechat_log_printf (" password_ok. . . . . . : %d", RELAY_IRC_DATA(client, password_ok));
weechat_log_printf (" nick . . . . . . . . . : '%s'", RELAY_IRC_DATA(client, nick));
weechat_log_printf (" user_received. . . . . : %d", RELAY_IRC_DATA(client, user_received));
weechat_log_printf (" connected. . . . . . . : %d", RELAY_IRC_DATA(client, connected));
diff --git a/src/plugins/relay/relay-client-irc.h b/src/plugins/relay/relay-client-irc.h
index b74c57670..951a89570 100644
--- a/src/plugins/relay/relay-client-irc.h
+++ b/src/plugins/relay/relay-client-irc.h
@@ -29,6 +29,7 @@ struct t_relay_client_irc_data
{
char *address; /* client address (used when sending */
/* data to client) */
+ int password_ok; /* password received and ok? */
char *nick; /* nick for client */
int user_received; /* command "USER" received */
int connected; /* 1 if client is connected as IRC */
diff --git a/src/plugins/relay/relay-config.c b/src/plugins/relay/relay-config.c
index 1e99113ee..1248a9391 100644
--- a/src/plugins/relay/relay-config.c
+++ b/src/plugins/relay/relay-config.c
@@ -50,6 +50,7 @@ struct t_config_option *relay_config_color_status[RELAY_NUM_STATUS];
/* relay config, network section */
struct t_config_option *relay_config_network_max_clients;
+struct t_config_option *relay_config_network_password;
/*
@@ -342,6 +343,12 @@ relay_config_init ()
N_("maximum number of clients connecting to a port"),
NULL, 1, 1024, "5", NULL, 0,
NULL, NULL, NULL, NULL, NULL, NULL);
+ relay_config_network_password = weechat_config_new_option (
+ relay_config_file, ptr_section,
+ "password", "string",
+ N_("password required by clients to access this relay (empty value "
+ "means no password required)"),
+ NULL, 0, 0, "", NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL);
ptr_section = weechat_config_new_section (relay_config_file, "port",
1, 1,
diff --git a/src/plugins/relay/relay-config.h b/src/plugins/relay/relay-config.h
index a6f14b54a..781ffb881 100644
--- a/src/plugins/relay/relay-config.h
+++ b/src/plugins/relay/relay-config.h
@@ -34,6 +34,7 @@ extern struct t_config_option *relay_config_color_text_selected;
extern struct t_config_option *relay_config_color_status[];
extern struct t_config_option *relay_config_network_max_clients;
+extern struct t_config_option *relay_config_network_password;
extern int relay_config_create_option_port (void *data,
struct t_config_file *config_file,