From f081fe91875fc285fb2723a05a069e904d425591 Mon Sep 17 00:00:00 2001 From: Jan Kaluza Date: Wed, 1 Aug 2012 13:50:38 +0200 Subject: [PATCH] Support for [registration] allowed_usernames --- src/config.cpp | 1 + src/userregistration.cpp | 19 ++++++++++--------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/config.cpp b/src/config.cpp index e7f505f5..3ec7f508 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -101,6 +101,7 @@ bool Config::load(std::istream &ifs, boost::program_options::options_description ("registration.instructions", value()->default_value("Enter your legacy network username and password."), "Instructions showed to user in registration form") ("registration.username_label", value()->default_value("Legacy network username:"), "Label for username field") ("registration.username_mask", value()->default_value(""), "Username mask") + ("registration.allowed_usernanames", value()->default_value(""), "Allowed usernames") ("registration.auto_register", value()->default_value(false), "Register new user automatically when the presence arrives.") ("registration.encoding", value()->default_value("utf8"), "Default encoding in registration form") ("registration.require_local_account", value()->default_value(false), "True if users have to have a local account to register to this transport from remote servers.") diff --git a/src/userregistration.cpp b/src/userregistration.cpp index 7d083c2e..e32507df 100644 --- a/src/userregistration.cpp +++ b/src/userregistration.cpp @@ -29,6 +29,7 @@ #include #include #include +#include using namespace Swift; @@ -441,15 +442,15 @@ bool UserRegistration::handleSetRequest(const Swift::JID& from, const Swift::JID // return true; // } -//TODO: Part of spectrum1 registration stuff, this should be potentially rewritten for S2 too -// #if GLIB_CHECK_VERSION(2,14,0) -// if (!CONFIG_STRING(m_config, "registration.reg_allowed_usernames").empty() && -// !g_regex_match_simple(CONFIG_STRING(m_config, "registration.reg_allowed_usernames"), newUsername.c_str(),(GRegexCompileFlags) (G_REGEX_CASELESS | G_REGEX_EXTENDED), (GRegexMatchFlags) 0)) { -// Log("UserRegistration", "This is not valid username: "<< newUsername); -// sendError(from, id, ErrorPayload::NotAcceptable, ErrorPayload::Modify); -// return true; -// } -// #endif + if (!CONFIG_STRING(m_config, "registration.allowed_usernames").empty()) { + boost::regex expression(CONFIG_STRING(m_config, "registration.allowed_usernames")); + if (!regex_match(newUsername, expression)) { + LOG4CXX_INFO(logger, "This is not valid username: " << newUsername); + sendError(from, id, ErrorPayload::NotAcceptable, ErrorPayload::Modify); + return true; + } + } + if (!registered) { res.jid = barejid; res.uin = newUsername;