diff options
author | Matthias Schiffer <matthias@gamezock.de> | 2009-09-27 19:58:24 +0200 |
---|---|---|
committer | Matthias Schiffer <matthias@gamezock.de> | 2009-09-27 19:58:24 +0200 |
commit | b40ba0cf91603b695f1f2380cbd39966a458f22f (patch) | |
tree | 1fec48ddc59eb1392fac38495b230e4b2cbf7528 /src/modules/AuthProviderFile | |
parent | e1d8490f0654a3da0b900407d80d91d8d0da68c8 (diff) | |
download | mad-b40ba0cf91603b695f1f2380cbd39966a458f22f.tar mad-b40ba0cf91603b695f1f2380cbd39966a458f22f.zip |
Use Unicode-aware String class instead of std::string
Diffstat (limited to 'src/modules/AuthProviderFile')
-rw-r--r-- | src/modules/AuthProviderFile/AuthProviderFile.cpp | 42 | ||||
-rw-r--r-- | src/modules/AuthProviderFile/AuthProviderFile.h | 14 |
2 files changed, 29 insertions, 27 deletions
diff --git a/src/modules/AuthProviderFile/AuthProviderFile.cpp b/src/modules/AuthProviderFile/AuthProviderFile.cpp index b1e1e52..b006cdc 100644 --- a/src/modules/AuthProviderFile/AuthProviderFile.cpp +++ b/src/modules/AuthProviderFile/AuthProviderFile.cpp @@ -54,17 +54,19 @@ void AuthProviderFile::readFile(const std::string &name) { continue; } - std::string password = match[2].str(); + Core::String password = match[2].str().c_str(); + + if(filehash.isEmpty()) { + std::string utf8pass = password.extractUTF8(); - if(filehash.empty()) { boost::lock_guard<boost::mutex> lock(mutex); - userMap.insert(std::make_pair(match[1].str(), std::vector<boost::uint8_t>(password.begin(), password.end()))); + userMap.insert(std::make_pair(match[1].str().c_str(), std::vector<boost::uint8_t>(utf8pass.begin(), utf8pass.end()))); } else { std::vector<boost::uint8_t> data; - data.reserve(password.size()/2); + data.reserve(password.length()/2); - for(size_t c = 0; c < password.size()-1; c += 2) { + for(boost::int32_t c = 0; c < password.length()-1; c += 2) { char buffer[3] = {password[c], password[c+1], 0}; unsigned char byte; @@ -79,7 +81,7 @@ void AuthProviderFile::readFile(const std::string &name) { if(!data.empty()) { boost::lock_guard<boost::mutex> lock(mutex); - userMap.insert(std::make_pair(match[1].str(), data)); + userMap.insert(std::make_pair(match[1].str().c_str(), data)); } } } @@ -94,15 +96,15 @@ bool AuthProviderFile::handleConfigEntry(const Core::ConfigEntry &entry, bool /* if(entry[1].getKey().matches("Hash")) { if(entry[2].isEmpty()) { - filehash = entry[1][0].extract(); + filehash = entry[1][0]; if(!Common::Hash::isHashSupported(filehash)) - application->logf(Core::Logger::LOG_WARNING, "AuthProviderFile: Unsupported hash '%s'", filehash.c_str()); + application->logf(Core::Logger::LOG_WARNING, "AuthProviderFile: Unsupported hash '%s'", filehash.extract().c_str()); } } else if(entry[1].getKey().matches("File")) { if(entry[2].isEmpty()) { - files.push_back(entry[1][0].extract()); + files.push_back(entry[1][0]); } } else if(!entry[2].isEmpty()) @@ -112,9 +114,9 @@ bool AuthProviderFile::handleConfigEntry(const Core::ConfigEntry &entry, bool /* } void AuthProviderFile::configFinished() { - if(filehash.empty() || boost::algorithm::to_lower_copy(filehash) == "clear") { + if(filehash.isEmpty() || filehash.matches("clear")) { hashes = Common::Hash::getHashList(); - filehash.clear(); + filehash.remove(); } else { hashes.clear(); @@ -123,12 +125,12 @@ void AuthProviderFile::configFinished() { hashes.push_back("Clear"); - for(std::vector<std::string>::iterator file = files.begin(); file != files.end(); ++file) - readFile(*file); + for(std::vector<Core::String>::iterator file = files.begin(); file != files.end(); ++file) + readFile(file->extract()); } -bool AuthProviderFile::checkPassword(const std::string &user, const std::vector<boost::uint8_t> &data, const std::string &hash) throw(Core::Exception) { - if((hash.empty() || boost::algorithm::to_lower_copy(hash) == "clear") && !filehash.empty()) { +bool AuthProviderFile::checkPassword(const Core::String &user, const std::vector<boost::uint8_t> &data, const Core::String &hash) throw(Core::Exception) { + if((hash.isEmpty() || hash.matches("clear")) && !filehash.isEmpty()) { std::vector<boost::uint8_t> password = getPassword(user, filehash); std::vector<boost::uint8_t> hashdata = Common::Hash::hash(data, filehash); @@ -140,20 +142,20 @@ bool AuthProviderFile::checkPassword(const std::string &user, const std::vector< } } -std::vector<boost::uint8_t> AuthProviderFile::getPassword(const std::string &user, const std::string &hash) throw(Core::Exception) { +std::vector<boost::uint8_t> AuthProviderFile::getPassword(const Core::String &user, const Core::String &hash) throw(Core::Exception) { boost::lock_guard<boost::mutex> lock(mutex); - std::map<std::string, std::vector<boost::uint8_t> >::iterator userIt = userMap.find(user); + std::map<Core::String, std::vector<boost::uint8_t> >::iterator userIt = userMap.find(user); if(userIt == userMap.end()) return std::vector<boost::uint8_t>(); - if(filehash.empty()) { - if(boost::algorithm::to_lower_copy(hash) == "clear") + if(filehash.isEmpty()) { + if(hash.matches("clear")) return userIt->second; else return Common::Hash::hash(userIt->second, hash); } - else if(boost::algorithm::to_lower_copy(filehash) == boost::algorithm::to_lower_copy(hash)) { + else if(filehash.matches(hash)) { return userIt->second; } else diff --git a/src/modules/AuthProviderFile/AuthProviderFile.h b/src/modules/AuthProviderFile/AuthProviderFile.h index 63f3d28..6ca907f 100644 --- a/src/modules/AuthProviderFile/AuthProviderFile.h +++ b/src/modules/AuthProviderFile/AuthProviderFile.h @@ -42,23 +42,23 @@ class MAD_MODULE_EXPORT AuthProviderFile : public Common::AuthProvider, private boost::mutex mutex; - std::map<std::string, std::vector<boost::uint8_t> > userMap; + std::map<Core::String, std::vector<boost::uint8_t> > userMap; - std::vector<std::string> files; - std::string filehash; + std::vector<Core::String> files; + Core::String filehash; - std::vector<std::string> hashes; + std::vector<Core::String> hashes; protected: virtual bool handleConfigEntry(const Core::ConfigEntry &entry, bool /*handled*/); virtual void configFinished(); - virtual const std::vector<std::string>& getHashes() const { + virtual const std::vector<Core::String>& getHashes() const { return hashes; } - virtual bool checkPassword(const std::string &user, const std::vector<boost::uint8_t> &data, const std::string &hash) throw(Core::Exception); - virtual std::vector<boost::uint8_t> getPassword(const std::string &user, const std::string &hash) throw(Core::Exception); + virtual bool checkPassword(const Core::String &user, const std::vector<boost::uint8_t> &data, const Core::String &hash) throw(Core::Exception); + virtual std::vector<boost::uint8_t> getPassword(const Core::String &user, const Core::String &hash) throw(Core::Exception); public: AuthProviderFile(Common::Application *application0) : application(application0) { |