From f081fe91875fc285fb2723a05a069e904d425591 2012-08-01 13:50:38 From: Jan Kaluza Date: 2012-08-01 13:50:38 Subject: [PATCH] Support for [registration] allowed_usernames --- diff --git a/src/config.cpp b/src/config.cpp index e7f505f54a66915a5a833e0c1a63871f0cc52e84..3ec7f508a7673f2d699a02e62cba8b26dcb4b80e 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 7d083c2e602a910c22bd436e0ef6e7dcac539fca..e32507dff03d97dc513e346ff50b55663cc38580 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;