From 66d8b0ad7b849ed743d3c3b4199fd05ece3891bb Mon Sep 17 00:00:00 2001 From: Berke Viktor Date: Tue, 10 Jan 2012 04:00:20 +0100 Subject: initial XSASL plugin based on cap_sasl --- plugins/xsasl/xsasl.c | 224 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 224 insertions(+) create mode 100644 plugins/xsasl/xsasl.c (limited to 'plugins/xsasl/xsasl.c') diff --git a/plugins/xsasl/xsasl.c b/plugins/xsasl/xsasl.c new file mode 100644 index 00000000..776b8137 --- /dev/null +++ b/plugins/xsasl/xsasl.c @@ -0,0 +1,224 @@ +/* + * SASL authentication plugin for XChat + * Extremely primitive: only PLAIN, no error checking + * + * Copyright (c) 2010, + * http://ygrek.org.ua/p/cap_sasl.html + * + * Docs: + * http://hg.atheme.org/charybdis/charybdis/file/6144f52a119b/doc/sasl.txt + * http://tools.ietf.org/html/rfc4422 + */ + + +#include +#include +#include +#include + +#include "xchat-plugin.h" + +#define PNAME "XSASL" +#define PDESC "SASL authentication plugin"; +#define PVERSION "0.0.4" + +static xchat_plugin *ph; /* plugin handle */ + +struct sasl_info; + +struct sasl_info +{ + char const* login; + char const* password; + char const* network; + struct sasl_info* next; +}; + +typedef struct sasl_info sasl_info; + +sasl_info* all_info = NULL; + +static void add_info(char const* login, char const* password, char const* network) +{ + sasl_info* prev = all_info; + sasl_info* info = (sasl_info*)malloc(sizeof(sasl_info)); + + info->login = strdup(login); + info->password = strdup(password); + info->network = strdup(network); + info->next = prev; + + all_info = info; +} + +static sasl_info* find_info(char const* network) +{ + sasl_info* cur = all_info; + while (cur) + { + if (0 == strcmp(cur->network, network)) return cur; + cur = cur->next; + } + return NULL; +} + +static sasl_info* get_info(void) +{ + const char* name = xchat_get_info(ph, "network"); + if (name) + return find_info(name); + else + return NULL; +} + +static int authend_cb(char *word[], char *word_eol[], void *userdata) +{ + if (get_info()) + { + xchat_printf(ph, "XSASL result: %s", word_eol[1]); + xchat_commandf(ph, "QUOTE CAP END"); + } + return XCHAT_EAT_ALL; +} + +/* +static int disconnect_cb(char *word[], void *userdata) +{ + xchat_printf(ph, "disconnected"); + return XCHAT_EAT_NONE; +} +*/ + +static int server_cb(char *word[], char *word_eol[], void *userdata) +{ + if (0 == strcmp("AUTHENTICATE",word[1]) && 0 == strcmp("+",word[2])) + { + size_t len; + char* buf; + char* enc; + sasl_info* p = get_info(); + if (!p) return XCHAT_EAT_NONE; + + xchat_printf(ph,"XSASL authenticating as %s",p->login); + + len = strlen(p->login)*2 + 2 + strlen(p->password); + buf = (char*)malloc(len + 1); + strcpy(buf,p->login); + strcpy(buf+strlen(p->login)+1,p->login); + strcpy(buf+strlen(p->login)*2+2,p->password); + enc = g_base64_encode((unsigned char*)buf,len); + + /*xchat_printf(ph,"AUTHENTICATE %s",enc);*/ + xchat_commandf(ph,"QUOTE AUTHENTICATE %s",enc); + + free(enc); + free(buf); + + return XCHAT_EAT_ALL; + } + return XCHAT_EAT_NONE; +} + +static int cap_cb(char *word[], char *word_eol[], void *userdata) +{ + if (get_info()) + { + /* FIXME test sasl cap */ + xchat_printf(ph, "XSASL info: %s", word_eol[1]); + xchat_commandf(ph,"QUOTE AUTHENTICATE PLAIN"); + } + + return XCHAT_EAT_ALL; +} + +static int sasl_cmd_cb(char *word[], char *word_eol[], void *userdata) +{ + const char* login = word[2]; + const char* password = word[3]; + const char* network = word_eol[4]; + + if (!login || !*login) + { + sasl_info *cur = all_info; + if (NULL == cur) + { + xchat_printf(ph,"Nothing, see /help sasl"); + return XCHAT_EAT_ALL; + } + + while (cur) + { + xchat_printf(ph,"%s:%s at %s",cur->login,cur->password,cur->network); + cur = cur->next; + } + return XCHAT_EAT_ALL; + } + + if (!login || !password || !network || !*login || !*password || !*network) + { + xchat_printf(ph,"Wrong usage, try /help sasl"); + return XCHAT_EAT_ALL; + } + + add_info(login,password,network); + + xchat_printf(ph,"Enabled SASL authentication for %s",network); + + return XCHAT_EAT_ALL; +} + +static int connect_cb(char *word[], void *userdata) +{ + if (get_info()) + { + xchat_printf(ph, "XSASL enabled"); + xchat_commandf(ph, "QUOTE CAP REQ :sasl"); + } + + return XCHAT_EAT_NONE; +} + +int xchat_plugin_init(xchat_plugin *plugin_handle, + char **plugin_name, + char **plugin_desc, + char **plugin_version, + char *arg) +{ + /* we need to save this for use with any xchat_* functions */ + ph = plugin_handle; + + /* tell xchat our info */ + *plugin_name = PNAME; + *plugin_desc = PDESC; + *plugin_version = PVERSION; + + xchat_hook_command(ph, "sasl", XCHAT_PRI_NORM, sasl_cmd_cb, + "Usage: SASL , enable SASL authentication for given network", 0); + + xchat_hook_print(ph, "Connected", XCHAT_PRI_NORM, connect_cb, NULL); +/* + xchat_hook_print(ph, "Disconnected", XCHAT_PRI_NORM, disconnect_cb, NULL); +*/ + + xchat_hook_server(ph, "CAP", XCHAT_PRI_NORM, cap_cb, NULL); + xchat_hook_server(ph, "RAW LINE", XCHAT_PRI_NORM, server_cb, NULL); + + xchat_hook_server(ph, "903", XCHAT_PRI_NORM, authend_cb, NULL); + xchat_hook_server(ph, "904", XCHAT_PRI_NORM, authend_cb, NULL); + xchat_hook_server(ph, "905", XCHAT_PRI_NORM, authend_cb, NULL); + xchat_hook_server(ph, "906", XCHAT_PRI_NORM, authend_cb, NULL); + xchat_hook_server(ph, "907", XCHAT_PRI_NORM, authend_cb, NULL); + + /* xchat_print(ph,"Loading cap_sasl.conf"); + xchat_commandf(ph, "load -e %s/cap_sasl.conf",xchat_get_info(ph, "xchatdir")); */ + + xchat_printf(ph, PNAME " plugin loaded\n"); + + return 1; +} + +int xchat_plugin_deinit (void) +{ + xchat_printf(ph, PNAME " plugin unloaded\n"); + return 1; +} -- cgit 1.4.1 From 1cbe3789da4a3684db9de79f6bfd98ff3de3c5ff Mon Sep 17 00:00:00 2001 From: Berke Viktor Date: Tue, 10 Jan 2012 05:22:58 +0100 Subject: xsasl save/load more or less works, need to get rid of lists --- plugins/xsasl/xsasl.c | 38 +++++++++++++++++++++++++++++++++----- 1 file changed, 33 insertions(+), 5 deletions(-) (limited to 'plugins/xsasl/xsasl.c') diff --git a/plugins/xsasl/xsasl.c b/plugins/xsasl/xsasl.c index 776b8137..4b1e06b3 100644 --- a/plugins/xsasl/xsasl.c +++ b/plugins/xsasl/xsasl.c @@ -20,7 +20,7 @@ #define PNAME "XSASL" #define PDESC "SASL authentication plugin"; -#define PVERSION "0.0.4" +#define PVERSION "1.0" static xchat_plugin *ph; /* plugin handle */ @@ -40,6 +40,7 @@ sasl_info* all_info = NULL; static void add_info(char const* login, char const* password, char const* network) { + char buffer[512]; sasl_info* prev = all_info; sasl_info* info = (sasl_info*)malloc(sizeof(sasl_info)); @@ -49,16 +50,43 @@ static void add_info(char const* login, char const* password, char const* networ info->next = prev; all_info = info; + + sprintf (buffer, "%s:%s", login, password); + xchat_set_pluginpref_str (ph, network, buffer); } static sasl_info* find_info(char const* network) { - sasl_info* cur = all_info; + //sasl_info* cur; + sasl_info* cur = (sasl_info*)malloc(sizeof(sasl_info)); + char buffer[512]; + char* pos; + char* token; + + // DEBUG + if (xchat_get_pluginpref_str (ph, network, buffer)) + { + cur->network = strdup (network); + //pos = strchr (buffer, ':'); + //cur->login = g_strndup (buffer, pos-buffer); + token = strtok (buffer, ":"); + cur->login = g_strdup (token); + token = strtok (NULL, ":"); + cur->password = g_strdup (token); + //xchat_printf (ph, "network: %s\n", cur->network); + //xchat_printf (ph, "login: %s\n", cur->login); + //xchat_printf (ph, "password: %s\n", cur->password); + cur->next = NULL; + return cur; + } +#if 0 + cur = all_info; while (cur) { if (0 == strcmp(cur->network, network)) return cur; cur = cur->next; } +#endif return NULL; } @@ -142,7 +170,7 @@ static int sasl_cmd_cb(char *word[], char *word_eol[], void *userdata) sasl_info *cur = all_info; if (NULL == cur) { - xchat_printf(ph,"Nothing, see /help sasl"); + xchat_printf(ph,"Nothing, see /HELP XSASL"); return XCHAT_EAT_ALL; } @@ -156,7 +184,7 @@ static int sasl_cmd_cb(char *word[], char *word_eol[], void *userdata) if (!login || !password || !network || !*login || !*password || !*network) { - xchat_printf(ph,"Wrong usage, try /help sasl"); + xchat_printf(ph,"Wrong usage, try /HELP XSASL"); return XCHAT_EAT_ALL; } @@ -192,7 +220,7 @@ int xchat_plugin_init(xchat_plugin *plugin_handle, *plugin_desc = PDESC; *plugin_version = PVERSION; - xchat_hook_command(ph, "sasl", XCHAT_PRI_NORM, sasl_cmd_cb, + xchat_hook_command(ph, "xsasl", XCHAT_PRI_NORM, sasl_cmd_cb, "Usage: SASL , enable SASL authentication for given network", 0); xchat_hook_print(ph, "Connected", XCHAT_PRI_NORM, connect_cb, NULL); -- cgit 1.4.1 From 2456d0d3fa48b155eb870eebf011732463782562 Mon Sep 17 00:00:00 2001 From: Berke Viktor Date: Tue, 10 Jan 2012 06:15:03 +0100 Subject: reformatting, cleanup --- plugins/xsasl/xsasl.c | 359 ++++++++++++++++++++++++-------------------------- 1 file changed, 172 insertions(+), 187 deletions(-) (limited to 'plugins/xsasl/xsasl.c') diff --git a/plugins/xsasl/xsasl.c b/plugins/xsasl/xsasl.c index 4b1e06b3..c8f452a0 100644 --- a/plugins/xsasl/xsasl.c +++ b/plugins/xsasl/xsasl.c @@ -1,8 +1,30 @@ +/* XChat-WDK + * Copyright (c) 2010 + * Copyright (c) 2012 Berke Viktor. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + /* * SASL authentication plugin for XChat * Extremely primitive: only PLAIN, no error checking * - * Copyright (c) 2010, * http://ygrek.org.ua/p/cap_sasl.html * * Docs: @@ -10,7 +32,6 @@ * http://tools.ietf.org/html/rfc4422 */ - #include #include #include @@ -18,235 +39,199 @@ #include "xchat-plugin.h" -#define PNAME "XSASL" -#define PDESC "SASL authentication plugin"; -#define PVERSION "1.0" - static xchat_plugin *ph; /* plugin handle */ - -struct sasl_info; +static const char name[] = "XSASL"; +static const char desc[] = "SASL authentication plugin for XChat"; +static const char version[] = "1.0"; struct sasl_info { - char const* login; - char const* password; - char const* network; - struct sasl_info* next; + char const* login; + char const* password; + char const* network; }; typedef struct sasl_info sasl_info; -sasl_info* all_info = NULL; - -static void add_info(char const* login, char const* password, char const* network) +static void +add_info (char const* login, char const* password, char const* network) { - char buffer[512]; - sasl_info* prev = all_info; - sasl_info* info = (sasl_info*)malloc(sizeof(sasl_info)); + char buffer[512]; - info->login = strdup(login); - info->password = strdup(password); - info->network = strdup(network); - info->next = prev; - - all_info = info; - - sprintf (buffer, "%s:%s", login, password); - xchat_set_pluginpref_str (ph, network, buffer); + sprintf (buffer, "%s:%s", login, password); + xchat_set_pluginpref_str (ph, network, buffer); } -static sasl_info* find_info(char const* network) +static sasl_info* +find_info (char const* network) { - //sasl_info* cur; - sasl_info* cur = (sasl_info*)malloc(sizeof(sasl_info)); - char buffer[512]; - char* pos; - char* token; - - // DEBUG - if (xchat_get_pluginpref_str (ph, network, buffer)) - { - cur->network = strdup (network); - //pos = strchr (buffer, ':'); - //cur->login = g_strndup (buffer, pos-buffer); - token = strtok (buffer, ":"); - cur->login = g_strdup (token); - token = strtok (NULL, ":"); - cur->password = g_strdup (token); - //xchat_printf (ph, "network: %s\n", cur->network); - //xchat_printf (ph, "login: %s\n", cur->login); - //xchat_printf (ph, "password: %s\n", cur->password); - cur->next = NULL; - return cur; - } -#if 0 - cur = all_info; - while (cur) - { - if (0 == strcmp(cur->network, network)) return cur; - cur = cur->next; - } -#endif - return NULL; + char buffer[512]; + char* token; + sasl_info* cur = (sasl_info*) malloc (sizeof (sasl_info)); + + if (xchat_get_pluginpref_str (ph, network, buffer)) + { + token = strtok (buffer, ":"); + cur->login = g_strdup (token); + token = strtok (NULL, ":"); + cur->password = g_strdup (token); + cur->network = g_strdup (network); + + return cur; + } + + return NULL; } -static sasl_info* get_info(void) +static sasl_info* +get_info (void) { - const char* name = xchat_get_info(ph, "network"); - if (name) - return find_info(name); - else - return NULL; + const char* name; + name = xchat_get_info (ph, "network"); + + if (name) + { + return find_info (name); + } + else + { + return NULL; + } } -static int authend_cb(char *word[], char *word_eol[], void *userdata) +static int +authend_cb (char *word[], char *word_eol[], void *userdata) { - if (get_info()) - { - xchat_printf(ph, "XSASL result: %s", word_eol[1]); - xchat_commandf(ph, "QUOTE CAP END"); - } - return XCHAT_EAT_ALL; + if (get_info ()) + { + xchat_printf (ph, "XSASL result: %s\n", word_eol[1]); + xchat_commandf (ph, "QUOTE CAP END"); + } + + return XCHAT_EAT_ALL; } /* -static int disconnect_cb(char *word[], void *userdata) +static int +disconnect_cb (char *word[], void *userdata) { - xchat_printf(ph, "disconnected"); - return XCHAT_EAT_NONE; + xchat_printf (ph, "disconnected\n"); + return XCHAT_EAT_NONE; } */ -static int server_cb(char *word[], char *word_eol[], void *userdata) +static int +server_cb (char *word[], char *word_eol[], void *userdata) { - if (0 == strcmp("AUTHENTICATE",word[1]) && 0 == strcmp("+",word[2])) - { - size_t len; - char* buf; - char* enc; - sasl_info* p = get_info(); - if (!p) return XCHAT_EAT_NONE; - - xchat_printf(ph,"XSASL authenticating as %s",p->login); - - len = strlen(p->login)*2 + 2 + strlen(p->password); - buf = (char*)malloc(len + 1); - strcpy(buf,p->login); - strcpy(buf+strlen(p->login)+1,p->login); - strcpy(buf+strlen(p->login)*2+2,p->password); - enc = g_base64_encode((unsigned char*)buf,len); - - /*xchat_printf(ph,"AUTHENTICATE %s",enc);*/ - xchat_commandf(ph,"QUOTE AUTHENTICATE %s",enc); - - free(enc); - free(buf); - - return XCHAT_EAT_ALL; - } - return XCHAT_EAT_NONE; -} + size_t len; + char* buf; + char* enc; + sasl_info* p; -static int cap_cb(char *word[], char *word_eol[], void *userdata) -{ - if (get_info()) - { - /* FIXME test sasl cap */ - xchat_printf(ph, "XSASL info: %s", word_eol[1]); - xchat_commandf(ph,"QUOTE AUTHENTICATE PLAIN"); - } - - return XCHAT_EAT_ALL; -} + if (strcmp ("AUTHENTICATE", word[1]) == 0 && strcmp ("+", word[2]) == 0) + { + p = get_info (); -static int sasl_cmd_cb(char *word[], char *word_eol[], void *userdata) -{ - const char* login = word[2]; - const char* password = word[3]; - const char* network = word_eol[4]; - - if (!login || !*login) - { - sasl_info *cur = all_info; - if (NULL == cur) - { - xchat_printf(ph,"Nothing, see /HELP XSASL"); - return XCHAT_EAT_ALL; - } - - while (cur) - { - xchat_printf(ph,"%s:%s at %s",cur->login,cur->password,cur->network); - cur = cur->next; - } - return XCHAT_EAT_ALL; - } - - if (!login || !password || !network || !*login || !*password || !*network) - { - xchat_printf(ph,"Wrong usage, try /HELP XSASL"); - return XCHAT_EAT_ALL; - } - - add_info(login,password,network); - - xchat_printf(ph,"Enabled SASL authentication for %s",network); - - return XCHAT_EAT_ALL; + if (!p) + { + return XCHAT_EAT_NONE; + } + + xchat_printf (ph, "XSASL authenticating as %s\n", p->login); + + len = strlen (p->login) * 2 + 2 + strlen (p->password); + buf = (char*) malloc (len + 1); + strcpy (buf, p->login); + strcpy (buf + strlen (p->login) + 1, p->login); + strcpy (buf + strlen (p->login) * 2 + 2, p->password); + enc = g_base64_encode ((unsigned char*) buf, len); + + /* xchat_printf (ph, "AUTHENTICATE %s\}", enc); */ + xchat_commandf (ph, "QUOTE AUTHENTICATE %s", enc); + + free (enc); + free (buf); + + return XCHAT_EAT_ALL; + } + + return XCHAT_EAT_NONE; } -static int connect_cb(char *word[], void *userdata) +static int +cap_cb (char *word[], char *word_eol[], void *userdata) { - if (get_info()) - { - xchat_printf(ph, "XSASL enabled"); - xchat_commandf(ph, "QUOTE CAP REQ :sasl"); - } - - return XCHAT_EAT_NONE; + if (get_info ()) + { + /* FIXME test sasl cap */ + xchat_printf (ph, "XSASL info: %s\n", word_eol[1]); + xchat_commandf (ph, "QUOTE AUTHENTICATE PLAIN"); + } + + return XCHAT_EAT_ALL; } -int xchat_plugin_init(xchat_plugin *plugin_handle, - char **plugin_name, - char **plugin_desc, - char **plugin_version, - char *arg) +static int +sasl_cmd_cb (char *word[], char *word_eol[], void *userdata) { - /* we need to save this for use with any xchat_* functions */ - ph = plugin_handle; + const char* login = word[2]; + const char* password = word[3]; + const char* network = word_eol[4]; - /* tell xchat our info */ - *plugin_name = PNAME; - *plugin_desc = PDESC; - *plugin_version = PVERSION; + if (!login || !password || !network || !*login || !*password || !*network) + { + xchat_printf (ph, "Usage: SASL , enable SASL authentication for given network\n"); + return XCHAT_EAT_ALL; + } - xchat_hook_command(ph, "xsasl", XCHAT_PRI_NORM, sasl_cmd_cb, - "Usage: SASL , enable SASL authentication for given network", 0); + add_info (login, password, network); + xchat_printf (ph, "Enabled SASL authentication for the \"%s\" network\n", network); - xchat_hook_print(ph, "Connected", XCHAT_PRI_NORM, connect_cb, NULL); -/* - xchat_hook_print(ph, "Disconnected", XCHAT_PRI_NORM, disconnect_cb, NULL); -*/ - - xchat_hook_server(ph, "CAP", XCHAT_PRI_NORM, cap_cb, NULL); - xchat_hook_server(ph, "RAW LINE", XCHAT_PRI_NORM, server_cb, NULL); + return XCHAT_EAT_ALL; +} - xchat_hook_server(ph, "903", XCHAT_PRI_NORM, authend_cb, NULL); - xchat_hook_server(ph, "904", XCHAT_PRI_NORM, authend_cb, NULL); - xchat_hook_server(ph, "905", XCHAT_PRI_NORM, authend_cb, NULL); - xchat_hook_server(ph, "906", XCHAT_PRI_NORM, authend_cb, NULL); - xchat_hook_server(ph, "907", XCHAT_PRI_NORM, authend_cb, NULL); +static int +connect_cb (char *word[], void *userdata) +{ + if (get_info ()) + { + xchat_printf (ph, "XSASL enabled\n"); + xchat_commandf (ph, "QUOTE CAP REQ :sasl"); + } - /* xchat_print(ph,"Loading cap_sasl.conf"); - xchat_commandf(ph, "load -e %s/cap_sasl.conf",xchat_get_info(ph, "xchatdir")); */ + return XCHAT_EAT_NONE; +} - xchat_printf(ph, PNAME " plugin loaded\n"); +int +xchat_plugin_init (xchat_plugin *plugin_handle, char **plugin_name, char **plugin_desc, char **plugin_version, char *arg) +{ + /* we need to save this for use with any xchat_* functions */ + ph = plugin_handle; + + /* tell xchat our info */ + *plugin_name = name; + *plugin_desc = desc; + *plugin_version = version; + + xchat_hook_command (ph, "XSASL", XCHAT_PRI_NORM, sasl_cmd_cb, "Usage: SASL , enable SASL authentication for given network", 0); + xchat_hook_print (ph, "Connected", XCHAT_PRI_NORM, connect_cb, NULL); + /* xchat_hook_print (ph, "Disconnected", XCHAT_PRI_NORM, disconnect_cb, NULL); */ + xchat_hook_server (ph, "CAP", XCHAT_PRI_NORM, cap_cb, NULL); + xchat_hook_server (ph, "RAW LINE", XCHAT_PRI_NORM, server_cb, NULL); + xchat_hook_server (ph, "903", XCHAT_PRI_NORM, authend_cb, NULL); + xchat_hook_server (ph, "904", XCHAT_PRI_NORM, authend_cb, NULL); + xchat_hook_server (ph, "905", XCHAT_PRI_NORM, authend_cb, NULL); + xchat_hook_server (ph, "906", XCHAT_PRI_NORM, authend_cb, NULL); + xchat_hook_server (ph, "907", XCHAT_PRI_NORM, authend_cb, NULL); + + xchat_printf (ph, "%s plugin loaded\n", name); - return 1; + return 1; } -int xchat_plugin_deinit (void) +int +xchat_plugin_deinit (void) { - xchat_printf(ph, PNAME " plugin unloaded\n"); + xchat_printf (ph, "%s plugin unloaded\n", name); return 1; } -- cgit 1.4.1 From 6a0aa95fee2de466dfc925db7cc475ec538a4a88 Mon Sep 17 00:00:00 2001 From: Berke Viktor Date: Tue, 10 Jan 2012 08:28:03 +0100 Subject: update command names --- plugins/xsasl/xsasl.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'plugins/xsasl/xsasl.c') diff --git a/plugins/xsasl/xsasl.c b/plugins/xsasl/xsasl.c index c8f452a0..c902c7b6 100644 --- a/plugins/xsasl/xsasl.c +++ b/plugins/xsasl/xsasl.c @@ -180,7 +180,7 @@ sasl_cmd_cb (char *word[], char *word_eol[], void *userdata) if (!login || !password || !network || !*login || !*password || !*network) { - xchat_printf (ph, "Usage: SASL , enable SASL authentication for given network\n"); + xchat_printf (ph, "Usage: XSASL , enable SASL authentication for given network\n"); return XCHAT_EAT_ALL; } @@ -213,7 +213,7 @@ xchat_plugin_init (xchat_plugin *plugin_handle, char **plugin_name, char **plugi *plugin_desc = desc; *plugin_version = version; - xchat_hook_command (ph, "XSASL", XCHAT_PRI_NORM, sasl_cmd_cb, "Usage: SASL , enable SASL authentication for given network", 0); + xchat_hook_command (ph, "XSASL", XCHAT_PRI_NORM, sasl_cmd_cb, "Usage: XSASL , enable SASL authentication for given network", 0); xchat_hook_print (ph, "Connected", XCHAT_PRI_NORM, connect_cb, NULL); /* xchat_hook_print (ph, "Disconnected", XCHAT_PRI_NORM, disconnect_cb, NULL); */ xchat_hook_server (ph, "CAP", XCHAT_PRI_NORM, cap_cb, NULL); -- cgit 1.4.1 From 9eae6db37feb2a66bf44d351e805e451d309f42a Mon Sep 17 00:00:00 2001 From: Berke Viktor Date: Wed, 11 Jan 2012 20:16:23 +0100 Subject: X-SASL cosmetics --- plugins/xsasl/xsasl.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'plugins/xsasl/xsasl.c') diff --git a/plugins/xsasl/xsasl.c b/plugins/xsasl/xsasl.c index c902c7b6..e6840ad1 100644 --- a/plugins/xsasl/xsasl.c +++ b/plugins/xsasl/xsasl.c @@ -40,7 +40,7 @@ #include "xchat-plugin.h" static xchat_plugin *ph; /* plugin handle */ -static const char name[] = "XSASL"; +static const char name[] = "X-SASL"; static const char desc[] = "SASL authentication plugin for XChat"; static const char version[] = "1.0"; @@ -104,7 +104,7 @@ authend_cb (char *word[], char *word_eol[], void *userdata) { if (get_info ()) { - xchat_printf (ph, "XSASL result: %s\n", word_eol[1]); + xchat_printf (ph, "%s\t %s\n", name, word_eol[1]); xchat_commandf (ph, "QUOTE CAP END"); } @@ -137,7 +137,7 @@ server_cb (char *word[], char *word_eol[], void *userdata) return XCHAT_EAT_NONE; } - xchat_printf (ph, "XSASL authenticating as %s\n", p->login); + xchat_printf (ph, "%s\tAuthenticating as %s\n", name, p->login); len = strlen (p->login) * 2 + 2 + strlen (p->password); buf = (char*) malloc (len + 1); @@ -164,7 +164,7 @@ cap_cb (char *word[], char *word_eol[], void *userdata) if (get_info ()) { /* FIXME test sasl cap */ - xchat_printf (ph, "XSASL info: %s\n", word_eol[1]); + xchat_printf (ph, "%s\t %s\n", name, word_eol[1]); xchat_commandf (ph, "QUOTE AUTHENTICATE PLAIN"); } @@ -185,7 +185,7 @@ sasl_cmd_cb (char *word[], char *word_eol[], void *userdata) } add_info (login, password, network); - xchat_printf (ph, "Enabled SASL authentication for the \"%s\" network\n", network); + xchat_printf (ph, "%s\tEnabled SASL authentication for the \"%s\" network\n", name, network); return XCHAT_EAT_ALL; } @@ -195,7 +195,7 @@ connect_cb (char *word[], void *userdata) { if (get_info ()) { - xchat_printf (ph, "XSASL enabled\n"); + xchat_printf (ph, "%s\tSASL enabled\n", name); xchat_commandf (ph, "QUOTE CAP REQ :sasl"); } -- cgit 1.4.1 From 6eb1fcbbe7438812620ce40f4c2c1a82e2820a1c Mon Sep 17 00:00:00 2001 From: Berke Viktor Date: Wed, 11 Jan 2012 20:31:11 +0100 Subject: remove extra spaces from xsasl messages --- plugins/xsasl/xsasl.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'plugins/xsasl/xsasl.c') diff --git a/plugins/xsasl/xsasl.c b/plugins/xsasl/xsasl.c index e6840ad1..e6d6312f 100644 --- a/plugins/xsasl/xsasl.c +++ b/plugins/xsasl/xsasl.c @@ -104,7 +104,7 @@ authend_cb (char *word[], char *word_eol[], void *userdata) { if (get_info ()) { - xchat_printf (ph, "%s\t %s\n", name, word_eol[1]); + xchat_printf (ph, "%s\t%s\n", name, word_eol[1]); xchat_commandf (ph, "QUOTE CAP END"); } @@ -164,7 +164,7 @@ cap_cb (char *word[], char *word_eol[], void *userdata) if (get_info ()) { /* FIXME test sasl cap */ - xchat_printf (ph, "%s\t %s\n", name, word_eol[1]); + xchat_printf (ph, "%s\t%s\n", name, word_eol[1]); xchat_commandf (ph, "QUOTE AUTHENTICATE PLAIN"); } -- cgit 1.4.1 From c979a8a8b7493538dde5b80936b298ad6b57c877 Mon Sep 17 00:00:00 2001 From: Berke Viktor Date: Wed, 11 Jan 2012 21:35:02 +0100 Subject: some more xsasl cosmetics --- plugins/xsasl/xsasl.c | 6 ++++-- win32/xchat-wdk-x64.skel.iss | 2 +- win32/xchat-wdk-x86.skel.iss | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) (limited to 'plugins/xsasl/xsasl.c') diff --git a/plugins/xsasl/xsasl.c b/plugins/xsasl/xsasl.c index e6d6312f..f0521c47 100644 --- a/plugins/xsasl/xsasl.c +++ b/plugins/xsasl/xsasl.c @@ -104,7 +104,8 @@ authend_cb (char *word[], char *word_eol[], void *userdata) { if (get_info ()) { - xchat_printf (ph, "%s\t%s\n", name, word_eol[1]); + /* omit cryptic server message parts */ + xchat_printf (ph, "%s\t%s\n", name, ++word_eol[4]); xchat_commandf (ph, "QUOTE CAP END"); } @@ -164,7 +165,8 @@ cap_cb (char *word[], char *word_eol[], void *userdata) if (get_info ()) { /* FIXME test sasl cap */ - xchat_printf (ph, "%s\t%s\n", name, word_eol[1]); + /* this is visible in the rawlog in case someone needs it, otherwise it's just noise */ + /* xchat_printf (ph, "%s\t%s\n", name, word_eol[1]); */ xchat_commandf (ph, "QUOTE AUTHENTICATE PLAIN"); } diff --git a/win32/xchat-wdk-x64.skel.iss b/win32/xchat-wdk-x64.skel.iss index c903a8d1..815bdd48 100644 --- a/win32/xchat-wdk-x64.skel.iss +++ b/win32/xchat-wdk-x64.skel.iss @@ -43,7 +43,7 @@ Name: "plugins\upd"; Description: "Update Checker"; Types: normal full custom; F Name: "plugins\winamp"; Description: "Winamp"; Types: full custom; Flags: disablenouninstallwarning Name: "plugins\winsys"; Description: "WinSys"; Types: full custom; Flags: disablenouninstallwarning Name: "plugins\wmpa"; Description: "Windows Media Player Announcer"; Types: full custom; Flags: disablenouninstallwarning -Name: "plugins\xsasl"; Description: "XSASL"; Types: full custom; Flags: disablenouninstallwarning +Name: "plugins\xsasl"; Description: "X-SASL"; Types: full custom; Flags: disablenouninstallwarning Name: "plugins\xtray"; Description: "X-Tray"; Types: full custom; Flags: disablenouninstallwarning Name: "langs"; Description: "Language Interfaces"; Types: full custom; Flags: disablenouninstallwarning Name: "langs\lua"; Description: "Lua"; Types: full custom; Flags: disablenouninstallwarning diff --git a/win32/xchat-wdk-x86.skel.iss b/win32/xchat-wdk-x86.skel.iss index 1dfeec09..2bc7969f 100644 --- a/win32/xchat-wdk-x86.skel.iss +++ b/win32/xchat-wdk-x86.skel.iss @@ -42,7 +42,7 @@ Name: "plugins\upd"; Description: "Update Checker"; Types: normal full custom; F Name: "plugins\winamp"; Description: "Winamp"; Types: full custom; Flags: disablenouninstallwarning Name: "plugins\winsys"; Description: "WinSys"; Types: full custom; Flags: disablenouninstallwarning Name: "plugins\wmpa"; Description: "Windows Media Player Announcer"; Types: full custom; Flags: disablenouninstallwarning -Name: "plugins\xsasl"; Description: "XSASL"; Types: full custom; Flags: disablenouninstallwarning +Name: "plugins\xsasl"; Description: "X-SASL"; Types: full custom; Flags: disablenouninstallwarning Name: "plugins\xtray"; Description: "X-Tray"; Types: full custom; Flags: disablenouninstallwarning Name: "langs"; Description: "Language Interfaces"; Types: full custom; Flags: disablenouninstallwarning Name: "langs\lua"; Description: "Lua"; Types: full custom; Flags: disablenouninstallwarning -- cgit 1.4.1 From e421c11686c7ab9e21d9fbf34ba363f990d45fa9 Mon Sep 17 00:00:00 2001 From: Berke Viktor Date: Sat, 14 Jan 2012 03:05:42 +0100 Subject: support for removing existing networks in xsasl --- plugins/xsasl/xsasl.c | 71 ++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 59 insertions(+), 12 deletions(-) (limited to 'plugins/xsasl/xsasl.c') diff --git a/plugins/xsasl/xsasl.c b/plugins/xsasl/xsasl.c index f0521c47..cbf569e2 100644 --- a/plugins/xsasl/xsasl.c +++ b/plugins/xsasl/xsasl.c @@ -42,7 +42,8 @@ static xchat_plugin *ph; /* plugin handle */ static const char name[] = "X-SASL"; static const char desc[] = "SASL authentication plugin for XChat"; -static const char version[] = "1.0"; +static const char version[] = "1.1"; +static const char xsasl_help[] = "X-SASL Usage:\n /XSASL ADD , enable SASL authentication for given network\n /XSASL DEL , disable SASL authentication for given network\n"; struct sasl_info { @@ -53,13 +54,19 @@ struct sasl_info typedef struct sasl_info sasl_info; -static void +static int add_info (char const* login, char const* password, char const* network) { char buffer[512]; sprintf (buffer, "%s:%s", login, password); - xchat_set_pluginpref_str (ph, network, buffer); + return xchat_set_pluginpref_str (ph, network, buffer); +} + +static int +del_info (char const* network) +{ + return xchat_del_pluginpref (ph, network); } static sasl_info* @@ -176,20 +183,60 @@ cap_cb (char *word[], char *word_eol[], void *userdata) static int sasl_cmd_cb (char *word[], char *word_eol[], void *userdata) { - const char* login = word[2]; - const char* password = word[3]; - const char* network = word_eol[4]; + const char* login; + const char* password; + const char* network; + const char* mode = word[2]; - if (!login || !password || !network || !*login || !*password || !*network) + if (!stricmp ("ADD", mode)) { - xchat_printf (ph, "Usage: XSASL , enable SASL authentication for given network\n"); + login = word[3]; + password = word[4]; + network = word_eol[5]; + + if (!network || !*network) /* only check for the last word, if it's there, the previous ones will be there, too */ + { + xchat_printf (ph, "%s", xsasl_help); + return XCHAT_EAT_ALL; + } + + if (add_info (login, password, network)) + { + xchat_printf (ph, "%s\tEnabled SASL authentication for the \"%s\" network\n", name, network); + } + else + { + xchat_printf (ph, "%s\tFailed to enable SASL authentication for the \"%s\" network\n", name, network); + } + return XCHAT_EAT_ALL; } + else if (!stricmp ("DEL", mode)) + { + network = word_eol[3]; - add_info (login, password, network); - xchat_printf (ph, "%s\tEnabled SASL authentication for the \"%s\" network\n", name, network); + if (!network || !*network) + { + xchat_printf (ph, "%s", xsasl_help); + return XCHAT_EAT_ALL; + } - return XCHAT_EAT_ALL; + if (del_info (network)) + { + xchat_printf (ph, "%s\tDisabled SASL authentication for the \"%s\" network\n", name, network); + } + else + { + xchat_printf (ph, "%s\tFailed to disable SASL authentication for the \"%s\" network\n", name, network); + } + + return XCHAT_EAT_ALL; + } + else + { + xchat_printf (ph, "%s", xsasl_help); + return XCHAT_EAT_ALL; + } } static int @@ -215,7 +262,7 @@ xchat_plugin_init (xchat_plugin *plugin_handle, char **plugin_name, char **plugi *plugin_desc = desc; *plugin_version = version; - xchat_hook_command (ph, "XSASL", XCHAT_PRI_NORM, sasl_cmd_cb, "Usage: XSASL , enable SASL authentication for given network", 0); + xchat_hook_command (ph, "XSASL", XCHAT_PRI_NORM, sasl_cmd_cb, xsasl_help, 0); xchat_hook_print (ph, "Connected", XCHAT_PRI_NORM, connect_cb, NULL); /* xchat_hook_print (ph, "Disconnected", XCHAT_PRI_NORM, disconnect_cb, NULL); */ xchat_hook_server (ph, "CAP", XCHAT_PRI_NORM, cap_cb, NULL); -- cgit 1.4.1 From 44e404838683b9256f60ccd8e3370a39e27c6b58 Mon Sep 17 00:00:00 2001 From: Berke Viktor Date: Sun, 15 Jan 2012 19:10:31 +0100 Subject: update xsasl according to api changes --- plugins/xsasl/xsasl.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'plugins/xsasl/xsasl.c') diff --git a/plugins/xsasl/xsasl.c b/plugins/xsasl/xsasl.c index cbf569e2..2b2ec0c7 100644 --- a/plugins/xsasl/xsasl.c +++ b/plugins/xsasl/xsasl.c @@ -60,13 +60,13 @@ add_info (char const* login, char const* password, char const* network) char buffer[512]; sprintf (buffer, "%s:%s", login, password); - return xchat_set_pluginpref_str (ph, network, buffer); + return xchat_pluginpref_set_str (ph, network, buffer); } static int del_info (char const* network) { - return xchat_del_pluginpref (ph, network); + return xchat_pluginpref_delete (ph, network); } static sasl_info* @@ -76,7 +76,7 @@ find_info (char const* network) char* token; sasl_info* cur = (sasl_info*) malloc (sizeof (sasl_info)); - if (xchat_get_pluginpref_str (ph, network, buffer)) + if (xchat_pluginpref_get_str (ph, network, buffer)) { token = strtok (buffer, ":"); cur->login = g_strdup (token); -- cgit 1.4.1 From 306b2a87075cfce4eb13e7821763bf27614c25f4 Mon Sep 17 00:00:00 2001 From: Berke Viktor Date: Sun, 15 Jan 2012 21:15:33 +0100 Subject: implement XSASL LIST --- plugins/xsasl/xsasl.c | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) (limited to 'plugins/xsasl/xsasl.c') diff --git a/plugins/xsasl/xsasl.c b/plugins/xsasl/xsasl.c index 2b2ec0c7..43689fd3 100644 --- a/plugins/xsasl/xsasl.c +++ b/plugins/xsasl/xsasl.c @@ -43,7 +43,7 @@ static xchat_plugin *ph; /* plugin handle */ static const char name[] = "X-SASL"; static const char desc[] = "SASL authentication plugin for XChat"; static const char version[] = "1.1"; -static const char xsasl_help[] = "X-SASL Usage:\n /XSASL ADD , enable SASL authentication for given network\n /XSASL DEL , disable SASL authentication for given network\n"; +static const char xsasl_help[] = "X-SASL Usage:\n /XSASL ADD , enable SASL authentication for given network\n /XSASL DEL , disable SASL authentication for given network\n /XSASL LIST, get the list of SASL-enabled networks\n"; struct sasl_info { @@ -69,6 +69,29 @@ del_info (char const* network) return xchat_pluginpref_delete (ph, network); } +static void +print_info () +{ + char list[512]; + char* token; + + if (xchat_pluginpref_list (ph, list)) + { + xchat_printf (ph, "%s\tSASL-enabled networks:", name); + xchat_printf (ph, "%s\t----------------------", name); + token = strtok (list, ","); + while (token != NULL) + { + xchat_printf (ph, "%s\t%s", name, token); + token = strtok (NULL, ","); + } + } + else + { + xchat_printf (ph, "%s\tThere are no SASL-enabled networks currently", name); + } +} + static sasl_info* find_info (char const* network) { @@ -232,6 +255,11 @@ sasl_cmd_cb (char *word[], char *word_eol[], void *userdata) return XCHAT_EAT_ALL; } + else if (!stricmp ("LIST", mode)) + { + print_info (); + return XCHAT_EAT_ALL; + } else { xchat_printf (ph, "%s", xsasl_help); -- cgit 1.4.1 From 70771ba2c60ee56b85ad84a09ed3cfcc8f5e40c9 Mon Sep 17 00:00:00 2001 From: Berke Viktor Date: Sun, 15 Jan 2012 21:41:45 +0100 Subject: add info about xsasl add replacing existing config --- plugins/xsasl/xsasl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'plugins/xsasl/xsasl.c') diff --git a/plugins/xsasl/xsasl.c b/plugins/xsasl/xsasl.c index 43689fd3..8abce20b 100644 --- a/plugins/xsasl/xsasl.c +++ b/plugins/xsasl/xsasl.c @@ -43,7 +43,7 @@ static xchat_plugin *ph; /* plugin handle */ static const char name[] = "X-SASL"; static const char desc[] = "SASL authentication plugin for XChat"; static const char version[] = "1.1"; -static const char xsasl_help[] = "X-SASL Usage:\n /XSASL ADD , enable SASL authentication for given network\n /XSASL DEL , disable SASL authentication for given network\n /XSASL LIST, get the list of SASL-enabled networks\n"; +static const char xsasl_help[] = "X-SASL Usage:\n /XSASL ADD , enable/update SASL authentication for given network\n /XSASL DEL , disable SASL authentication for given network\n /XSASL LIST, get the list of SASL-enabled networks\n"; struct sasl_info { -- cgit 1.4.1