X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fmodules%2Fm_dccallow.cpp;h=98bcbf4cd46506083603d3fd5adb813a2907516b;hb=80e81e3b81b779901fd9d67f8ae030ee30c0bcec;hp=e0ea4c7aeed89e7d20ab38cdc05bb0320e4e8ff5;hpb=87b1461e2a4710a38b32186c2582da9fe9bb3804;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/modules/m_dccallow.cpp b/src/modules/m_dccallow.cpp index e0ea4c7ae..98bcbf4cd 100644 --- a/src/modules/m_dccallow.cpp +++ b/src/modules/m_dccallow.cpp @@ -1,13 +1,19 @@ /* * InspIRCd -- Internet Relay Chat Daemon * - * Copyright (C) 2009 Daniel De Graaf - * Copyright (C) 2008 John Brooks - * Copyright (C) 2008 Pippijn van Steenhoven - * Copyright (C) 2006-2008 Craig Edwards + * Copyright (C) 2019 Matt Schatz + * Copyright (C) 2018 linuxdaemon + * Copyright (C) 2016 Adam + * Copyright (C) 2013, 2017-2020 Sadie Powell + * Copyright (C) 2012-2016 Attila Molnar + * Copyright (C) 2012, 2014, 2019 Robby + * Copyright (C) 2009-2010 Daniel De Graaf + * Copyright (C) 2009 Matt Smith + * Copyright (C) 2008, 2010 Craig Edwards + * Copyright (C) 2008 John Brooks * Copyright (C) 2007-2008 Robin Burchell - * Copyright (C) 2007 Dennis Friis - * Copyright (C) 2006 Jamie ??? + * Copyright (C) 2007-2008 Dennis Friis + * Copyright (C) 2006 jamie * * This file is part of InspIRCd. InspIRCd is free software: you can * redistribute it and/or modify it under the terms of the GNU General Public @@ -98,21 +104,92 @@ typedef std::vector dccallowlist; dccallowlist* dl; typedef std::vector bannedfilelist; bannedfilelist bfl; -typedef SimpleExtItem DCCAllowExt; -class CommandDccallow : public Command +class DCCAllowExt : public SimpleExtItem { - DCCAllowExt& ext; - public: unsigned int maxentries; + + DCCAllowExt(Module* Creator) + : SimpleExtItem("dccallow", ExtensionItem::EXT_USER, Creator) + { + } + + void FromInternal(Extensible* container, const std::string& value) CXX11_OVERRIDE + { + LocalUser* user = IS_LOCAL(static_cast(container)); + if (!user) + return; + + // Remove the old list and create a new one. + unset(user); + dccallowlist* list = new dccallowlist(); + + irc::spacesepstream ts(value); + while (!ts.StreamEnd()) + { + // Check we have space for another entry. + if (list->size() >= maxentries) + { + ServerInstance->Logs->Log(MODNAME, LOG_DEBUG, "Oversized DCC allow list received for %s: %s", + user->uuid.c_str(), value.c_str()); + delete list; + return; + } + + // Extract the fields. + DCCAllow dccallow; + if (!ts.GetToken(dccallow.nickname) || + !ts.GetToken(dccallow.hostmask) || + !ts.GetNumericToken(dccallow.set_on) || + !ts.GetNumericToken(dccallow.length)) + { + ServerInstance->Logs->Log(MODNAME, LOG_DEBUG, "Malformed DCC allow list received for %s: %s", + user->uuid.c_str(), value.c_str()); + delete list; + return; + } + + // Store the DCC allow entry. + list->push_back(dccallow); + } + + // The value was well formed. + set(user, list); + } + + std::string ToInternal(const Extensible* container, void* item) const CXX11_OVERRIDE + { + dccallowlist* list = static_cast(item); + std::string buf; + for (dccallowlist::const_iterator iter = list->begin(); iter != list->end(); ++iter) + { + if (iter != list->begin()) + buf.push_back(' '); + + buf.append(iter->nickname); + buf.push_back(' '); + buf.append(iter->hostmask); + buf.push_back(' '); + buf.append(ConvToStr(iter->set_on)); + buf.push_back(' '); + buf.append(ConvToStr(iter->length)); + } + return buf; + } +}; + +class CommandDccallow : public Command +{ + public: + DCCAllowExt& ext; unsigned long defaultlength; CommandDccallow(Module* parent, DCCAllowExt& Ext) : Command(parent, "DCCALLOW", 0) , ext(Ext) { syntax = "[(+|-) [