summaryrefslogtreecommitdiffstats
path: root/src/modules/AuthProviderFile/AuthProviderFile.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/modules/AuthProviderFile/AuthProviderFile.cpp')
-rw-r--r--src/modules/AuthProviderFile/AuthProviderFile.cpp42
1 files changed, 22 insertions, 20 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