diff options
author | Berke Viktor <bviktor@hexchat.org> | 2012-07-11 19:46:46 +0200 |
---|---|---|
committer | Berke Viktor <bviktor@hexchat.org> | 2012-07-11 19:46:46 +0200 |
commit | 1ea726a91809340451c7a05ede34e7be00ba7863 (patch) | |
tree | 936bb6fce5c26b3876a7324ec82ee0bb232875d7 /plugins/xsasl | |
parent | d81619cca95831e2fd444d71cd078201f3db0e39 (diff) | |
parent | 9d9c24c8d347aa44efbd63e8f8c8dfb5b3cddedb (diff) |
Merge branch 'wdk'
Diffstat (limited to 'plugins/xsasl')
-rw-r--r-- | plugins/xsasl/makefile.mak | 18 | ||||
-rw-r--r-- | plugins/xsasl/xsasl.c | 314 | ||||
-rw-r--r-- | plugins/xsasl/xsasl.def | 3 | ||||
-rw-r--r-- | plugins/xsasl/xsasl.vcxproj | 110 | ||||
-rw-r--r-- | plugins/xsasl/xsasl.vcxproj.filters | 23 | ||||
-rw-r--r-- | plugins/xsasl/xsasl.vcxproj.user | 3 |
6 files changed, 471 insertions, 0 deletions
diff --git a/plugins/xsasl/makefile.mak b/plugins/xsasl/makefile.mak new file mode 100644 index 00000000..e1ffd0ec --- /dev/null +++ b/plugins/xsasl/makefile.mak @@ -0,0 +1,18 @@ +include "..\..\src\makeinc.mak" + +all: xsasl.obj xsasl.def + link $(LDFLAGS) $(LIBS) /dll /out:xcxsasl.dll /def:xsasl.def xsasl.obj + +xsasl.def: + echo EXPORTS > xsasl.def + echo xchat_plugin_init >> xsasl.def + echo xchat_plugin_deinit >> xsasl.def + +xsasl.obj: xsasl.c makefile.mak + cl $(CFLAGS) $(GLIB) /I.. xsasl.c + +clean: + del *.obj + del *.dll + del *.exp + del *.lib diff --git a/plugins/xsasl/xsasl.c b/plugins/xsasl/xsasl.c new file mode 100644 index 00000000..8abce20b --- /dev/null +++ b/plugins/xsasl/xsasl.c @@ -0,0 +1,314 @@ +/* XChat-WDK + * Copyright (c) 2010 <ygrek@autistici.org> + * 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 + * + * 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 <string.h> +#include <stdlib.h> +#include <assert.h> +#include <glib/gbase64.h> + +#include "xchat-plugin.h" + +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 <login> <password> <network>, enable/update SASL authentication for given network\n /XSASL DEL <network>, disable SASL authentication for given network\n /XSASL LIST, get the list of SASL-enabled networks\n"; + +struct sasl_info +{ + char const* login; + char const* password; + char const* network; +}; + +typedef struct sasl_info sasl_info; + +static int +add_info (char const* login, char const* password, char const* network) +{ + char buffer[512]; + + sprintf (buffer, "%s:%s", login, password); + return xchat_pluginpref_set_str (ph, network, buffer); +} + +static int +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) +{ + char buffer[512]; + char* token; + sasl_info* cur = (sasl_info*) malloc (sizeof (sasl_info)); + + if (xchat_pluginpref_get_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) +{ + 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) +{ + if (get_info ()) + { + /* omit cryptic server message parts */ + xchat_printf (ph, "%s\t%s\n", name, ++word_eol[4]); + xchat_commandf (ph, "QUOTE CAP END"); + } + + return XCHAT_EAT_ALL; +} + +/* +static int +disconnect_cb (char *word[], void *userdata) +{ + xchat_printf (ph, "disconnected\n"); + return XCHAT_EAT_NONE; +} +*/ + +static int +server_cb (char *word[], char *word_eol[], void *userdata) +{ + size_t len; + char* buf; + char* enc; + sasl_info* p; + + if (strcmp ("AUTHENTICATE", word[1]) == 0 && strcmp ("+", word[2]) == 0) + { + p = get_info (); + + if (!p) + { + return XCHAT_EAT_NONE; + } + + 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); + 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 */ + /* 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"); + } + + return XCHAT_EAT_ALL; +} + +static int +sasl_cmd_cb (char *word[], char *word_eol[], void *userdata) +{ + const char* login; + const char* password; + const char* network; + const char* mode = word[2]; + + if (!stricmp ("ADD", mode)) + { + 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]; + + if (!network || !*network) + { + xchat_printf (ph, "%s", xsasl_help); + 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 if (!stricmp ("LIST", mode)) + { + print_info (); + return XCHAT_EAT_ALL; + } + else + { + xchat_printf (ph, "%s", xsasl_help); + return XCHAT_EAT_ALL; + } +} + +static int +connect_cb (char *word[], void *userdata) +{ + if (get_info ()) + { + xchat_printf (ph, "%s\tSASL enabled\n", name); + 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 = name; + *plugin_desc = desc; + *plugin_version = version; + + 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); + 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; +} + +int +xchat_plugin_deinit (void) +{ + xchat_printf (ph, "%s plugin unloaded\n", name); + return 1; +} diff --git a/plugins/xsasl/xsasl.def b/plugins/xsasl/xsasl.def new file mode 100644 index 00000000..77670bf2 --- /dev/null +++ b/plugins/xsasl/xsasl.def @@ -0,0 +1,3 @@ +EXPORTS +xchat_plugin_init +xchat_plugin_deinit diff --git a/plugins/xsasl/xsasl.vcxproj b/plugins/xsasl/xsasl.vcxproj new file mode 100644 index 00000000..bec3da94 --- /dev/null +++ b/plugins/xsasl/xsasl.vcxproj @@ -0,0 +1,110 @@ +<?xml version="1.0" encoding="utf-8"?> +<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + <ItemGroup Label="ProjectConfigurations"> + <ProjectConfiguration Include="Release|Win32"> + <Configuration>Release</Configuration> + <Platform>Win32</Platform> + </ProjectConfiguration> + <ProjectConfiguration Include="Release|x64"> + <Configuration>Release</Configuration> + <Platform>x64</Platform> + </ProjectConfiguration> + </ItemGroup> + <PropertyGroup Label="Globals"> + <ProjectGuid>{18871EBA-AC85-4652-8919-EB8064B9A714}</ProjectGuid> + <Keyword>Win32Proj</Keyword> + <RootNamespace>xsasl</RootNamespace> + </PropertyGroup> + <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration"> + <ConfigurationType>DynamicLibrary</ConfigurationType> + <UseDebugLibraries>false</UseDebugLibraries> + <WholeProgramOptimization>true</WholeProgramOptimization> + <CharacterSet>MultiByte</CharacterSet> + <PlatformToolset>WDK7</PlatformToolset> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration"> + <ConfigurationType>DynamicLibrary</ConfigurationType> + <UseDebugLibraries>false</UseDebugLibraries> + <WholeProgramOptimization>true</WholeProgramOptimization> + <CharacterSet>MultiByte</CharacterSet> + <PlatformToolset>WDK7</PlatformToolset> + </PropertyGroup> + <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> + <ImportGroup Label="ExtensionSettings"> + </ImportGroup> + <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> + <Import Project="..\..\win32\xchat.props" /> + </ImportGroup> + <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets"> + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> + <Import Project="..\..\win32\xchat.props" /> + </ImportGroup> + <PropertyGroup Label="UserMacros" /> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> + <LinkIncremental>false</LinkIncremental> + <TargetName>xcxsasl</TargetName> + <OutDir>$(SolutionDir)build\$(PlatformName)\bin</OutDir> + <IntDir>$(SolutionDir)build\$(PlatformName)\obj\$(ProjectName)</IntDir> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> + <LinkIncremental>false</LinkIncremental> + <TargetName>xcxsasl</TargetName> + <OutDir>$(SolutionDir)build\$(PlatformName)\bin</OutDir> + <IntDir>$(SolutionDir)build\$(PlatformName)\obj\$(ProjectName)</IntDir> + </PropertyGroup> + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> + <ClCompile> + <WarningLevel>Level1</WarningLevel> + <PrecompiledHeader> + </PrecompiledHeader> + <Optimization>MaxSpeed</Optimization> + <FunctionLevelLinking>true</FunctionLevelLinking> + <IntrinsicFunctions>true</IntrinsicFunctions> + <PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_USRDLL;XSASL_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions> + <AdditionalIncludeDirectories>$(Glib);..;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> + <MultiProcessorCompilation>true</MultiProcessorCompilation> + </ClCompile> + <Link> + <SubSystem>Windows</SubSystem> + <GenerateDebugInformation>true</GenerateDebugInformation> + <EnableCOMDATFolding>true</EnableCOMDATFolding> + <OptimizeReferences>true</OptimizeReferences> + <ModuleDefinitionFile>xsasl.def</ModuleDefinitionFile> + <AdditionalLibraryDirectories>$(DepsRoot)\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories> + <AdditionalDependencies>$(DepLibs);%(AdditionalDependencies)</AdditionalDependencies> + </Link> + </ItemDefinitionGroup> + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> + <ClCompile> + <WarningLevel>Level1</WarningLevel> + <PrecompiledHeader> + </PrecompiledHeader> + <Optimization>MaxSpeed</Optimization> + <FunctionLevelLinking>true</FunctionLevelLinking> + <IntrinsicFunctions>true</IntrinsicFunctions> + <PreprocessorDefinitions>WIN32;_WIN64;NDEBUG;_WINDOWS;_USRDLL;XSASL_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions> + <AdditionalIncludeDirectories>$(Glib);..;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> + <MultiProcessorCompilation>true</MultiProcessorCompilation> + </ClCompile> + <Link> + <SubSystem>Windows</SubSystem> + <GenerateDebugInformation>true</GenerateDebugInformation> + <EnableCOMDATFolding>true</EnableCOMDATFolding> + <OptimizeReferences>true</OptimizeReferences> + <ModuleDefinitionFile>xsasl.def</ModuleDefinitionFile> + <AdditionalLibraryDirectories>$(DepsRoot)\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories> + <AdditionalDependencies>$(DepLibs);%(AdditionalDependencies)</AdditionalDependencies> + </Link> + </ItemDefinitionGroup> + <ItemGroup> + <None Include="xsasl.def" /> + </ItemGroup> + <ItemGroup> + <ClCompile Include="xsasl.c" /> + </ItemGroup> + <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> + <ImportGroup Label="ExtensionTargets"> + </ImportGroup> +</Project> \ No newline at end of file diff --git a/plugins/xsasl/xsasl.vcxproj.filters b/plugins/xsasl/xsasl.vcxproj.filters new file mode 100644 index 00000000..b01aa8eb --- /dev/null +++ b/plugins/xsasl/xsasl.vcxproj.filters @@ -0,0 +1,23 @@ +<?xml version="1.0" encoding="utf-8"?> +<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + <ItemGroup> + <Filter Include="Source Files"> + <UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier> + <Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions> + </Filter> + <Filter Include="Resource Files"> + <UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier> + <Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions> + </Filter> + </ItemGroup> + <ItemGroup> + <None Include="xsasl.def"> + <Filter>Resource Files</Filter> + </None> + </ItemGroup> + <ItemGroup> + <ClCompile Include="xsasl.c"> + <Filter>Source Files</Filter> + </ClCompile> + </ItemGroup> +</Project> \ No newline at end of file diff --git a/plugins/xsasl/xsasl.vcxproj.user b/plugins/xsasl/xsasl.vcxproj.user new file mode 100644 index 00000000..695b5c78 --- /dev/null +++ b/plugins/xsasl/xsasl.vcxproj.user @@ -0,0 +1,3 @@ +<?xml version="1.0" encoding="utf-8"?> +<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> +</Project> \ No newline at end of file |