summaryrefslogtreecommitdiffstats
path: root/src/modules
diff options
context:
space:
mode:
authorMatthias Schiffer <matthias@gamezock.de>2009-09-27 23:51:34 +0200
committerMatthias Schiffer <matthias@gamezock.de>2009-09-27 23:51:34 +0200
commita7a285eb61dd83afc892bc1d64ffe14b9f1426a3 (patch)
tree08d2efcaec46e5f5702d9e336a0e8ba7e636aff9 /src/modules
parentb40ba0cf91603b695f1f2380cbd39966a458f22f (diff)
downloadmad-a7a285eb61dd83afc892bc1d64ffe14b9f1426a3.tar
mad-a7a285eb61dd83afc892bc1d64ffe14b9f1426a3.zip
Completely migrate to Unicode String class
Diffstat (limited to 'src/modules')
-rw-r--r--src/modules/AuthProviderFile/AuthProviderFile.cpp13
-rw-r--r--src/modules/FileLogger/FileLogger.h4
-rw-r--r--src/modules/FileLogger/Module.cpp4
-rw-r--r--src/modules/StorageBackendFile/StorageBackendFile.cpp8
-rw-r--r--src/modules/UserConfigBackendHome/UserConfigBackendHome.cpp22
-rw-r--r--src/modules/UserConfigBackendKrb5/UserConfigBackendKrb5.cpp57
-rw-r--r--src/modules/UserConfigBackendKrb5/UserConfigBackendKrb5.h6
-rw-r--r--src/modules/UserDBBackendMysql/UserDBBackendMysql.cpp12
8 files changed, 66 insertions, 60 deletions
diff --git a/src/modules/AuthProviderFile/AuthProviderFile.cpp b/src/modules/AuthProviderFile/AuthProviderFile.cpp
index b006cdc..177d633 100644
--- a/src/modules/AuthProviderFile/AuthProviderFile.cpp
+++ b/src/modules/AuthProviderFile/AuthProviderFile.cpp
@@ -54,13 +54,14 @@ void AuthProviderFile::readFile(const std::string &name) {
continue;
}
- Core::String password = match[2].str().c_str();
+ Core::String username = Core::String::fromLocale(match[1].str());
+ Core::String password = Core::String::fromLocale(match[2].str());
if(filehash.isEmpty()) {
- std::string utf8pass = password.extractUTF8();
+ std::string utf8pass = password.toUTF8();
boost::lock_guard<boost::mutex> lock(mutex);
- userMap.insert(std::make_pair(match[1].str().c_str(), std::vector<boost::uint8_t>(utf8pass.begin(), utf8pass.end())));
+ userMap.insert(std::make_pair(username, std::vector<boost::uint8_t>(utf8pass.begin(), utf8pass.end())));
}
else {
std::vector<boost::uint8_t> data;
@@ -81,7 +82,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().c_str(), data));
+ userMap.insert(std::make_pair(username, data));
}
}
}
@@ -99,7 +100,7 @@ bool AuthProviderFile::handleConfigEntry(const Core::ConfigEntry &entry, bool /*
filehash = entry[1][0];
if(!Common::Hash::isHashSupported(filehash))
- application->logf(Core::Logger::LOG_WARNING, "AuthProviderFile: Unsupported hash '%s'", filehash.extract().c_str());
+ application->logf(Core::Logger::LOG_WARNING, "AuthProviderFile: Unsupported hash '%s'", filehash.toLocale().c_str());
}
}
else if(entry[1].getKey().matches("File")) {
@@ -126,7 +127,7 @@ void AuthProviderFile::configFinished() {
hashes.push_back("Clear");
for(std::vector<Core::String>::iterator file = files.begin(); file != files.end(); ++file)
- readFile(file->extract());
+ readFile(file->toLocale());
}
bool AuthProviderFile::checkPassword(const Core::String &user, const std::vector<boost::uint8_t> &data, const Core::String &hash) throw(Core::Exception) {
diff --git a/src/modules/FileLogger/FileLogger.h b/src/modules/FileLogger/FileLogger.h
index edd74a8..9fccc64 100644
--- a/src/modules/FileLogger/FileLogger.h
+++ b/src/modules/FileLogger/FileLogger.h
@@ -33,8 +33,8 @@ class FileLogger : public Core::Logger {
std::ofstream file;
protected:
- virtual void logMessage(MessageCategory /*category*/, MessageLevel /*level*/, boost::posix_time::ptime /*timestamp*/, const std::string &message, const std::string &source) {
- if(source.empty())
+ virtual void logMessage(MessageCategory /*category*/, MessageLevel /*level*/, boost::posix_time::ptime /*timestamp*/, const Core::String &message, const Core::String &source) {
+ if(source.isEmpty())
file << message << std::endl;
else
file << message << " from " << source << std::endl;
diff --git a/src/modules/FileLogger/Module.cpp b/src/modules/FileLogger/Module.cpp
index 663389f..d8a302c 100644
--- a/src/modules/FileLogger/Module.cpp
+++ b/src/modules/FileLogger/Module.cpp
@@ -34,7 +34,7 @@ bool Module::handleConfigEntry(const Core::ConfigEntry &entry, bool handled) {
if(entry[0][0].matches("File")) {
if(entry[1].isEmpty()) {
if(!entry[0][1].isEmpty()) {
- lastLogger.reset(new FileLogger(entry[0][1].extract()));
+ lastLogger.reset(new FileLogger(entry[0][1].toLocale()));
loggers.insert(lastLogger);
application->getLogManager()->registerLogger(lastLogger);
@@ -55,7 +55,7 @@ bool Module::handleConfigEntry(const Core::ConfigEntry &entry, bool handled) {
lastLogger->setLevel(Core::LogManager::parseLevel(entry[1][0]));
}
catch(Core::Exception e) {
- application->logf(Core::Logger::LOG_WARNING, "Unknown log level '%s'.", entry[1][0].extract().c_str());
+ application->logf(Core::Logger::LOG_WARNING, "Unknown log level '%s'.", entry[1][0].toLocale().c_str());
}
return true;
diff --git a/src/modules/StorageBackendFile/StorageBackendFile.cpp b/src/modules/StorageBackendFile/StorageBackendFile.cpp
index 0affc2c..e5da4e0 100644
--- a/src/modules/StorageBackendFile/StorageBackendFile.cpp
+++ b/src/modules/StorageBackendFile/StorageBackendFile.cpp
@@ -38,7 +38,7 @@ bool StorageBackendFile::handleConfigEntry(const Core::ConfigEntry &entry, bool
if(!entry[2].isEmpty())
return false;
- storageRoot = entry[1][0].extract();
+ storageRoot = entry[1][0].toLocale();
}
else if(!entry[1].isEmpty()) {
return false;
@@ -65,8 +65,8 @@ void StorageBackendFile::configFinished() {
boost::filesystem::path StorageBackendFile::getFileName(const Core::String &type, const Core::String &name) {
boost::filesystem::path path(storageRoot);
- path /= type.extract();
- path /= Core::String(name + ".xml").extract();
+ path /= type.toLocale();
+ path /= Core::String(name + ".xml").toLocale();
return path;
}
@@ -101,7 +101,7 @@ std::set<Core::String> StorageBackendFile::list(const Core::String &type) throw
std::set<Core::String> ret;
boost::filesystem::path path(storageRoot);
- path /= type.extract();
+ path /= type.toLocale();
try {
for(boost::filesystem::directory_iterator it(path); it != boost::filesystem::directory_iterator(); ++it) {
diff --git a/src/modules/UserConfigBackendHome/UserConfigBackendHome.cpp b/src/modules/UserConfigBackendHome/UserConfigBackendHome.cpp
index e1db3b9..4dca729 100644
--- a/src/modules/UserConfigBackendHome/UserConfigBackendHome.cpp
+++ b/src/modules/UserConfigBackendHome/UserConfigBackendHome.cpp
@@ -48,9 +48,9 @@ bool UserConfigBackendHome::handleConfigEntry(const Core::ConfigEntry &entry, bo
}
else {
char *endptr;
- unsigned long val = std::strtoul(entry[1][0].extract().c_str(), &endptr, 8);
+ unsigned long val = std::strtoul(entry[1][0].toString().c_str(), &endptr, 8);
if(*endptr || val > 07777) {
- application->logf(Core::Logger::LOG_WARNING, "UserBackendHome: Invalid configuration: DirMode '%s'", entry[1][0].extract().c_str());
+ application->logf(Core::Logger::LOG_WARNING, "UserBackendHome: Invalid configuration: DirMode '%s'", entry[1][0].toLocale().c_str());
}
else {
dirMode = val;
@@ -104,8 +104,8 @@ void UserConfigBackendHome::migrateOwner(const std::string &path, const Common::
}
void UserConfigBackendHome::addUser(const Common::UserInfo &userInfo) throw(Core::Exception) {
- boost::filesystem::path path(homeDir.extract());
- path /= userInfo.getUsername().extract();
+ boost::filesystem::path path(homeDir.toLocale());
+ path /= userInfo.getUsername().toLocale();
boost::filesystem::create_directories(path);
@@ -118,7 +118,7 @@ void UserConfigBackendHome::addUser(const Common::UserInfo &userInfo) throw(Core
// TODO Error
}
- boost::filesystem::path skeletonPath(skeleton.extract());
+ boost::filesystem::path skeletonPath(skeleton.toLocale());
if(!boost::filesystem::is_directory(skeletonPath))
return;
@@ -161,11 +161,11 @@ void UserConfigBackendHome::addUser(const Common::UserInfo &userInfo) throw(Core
}
void UserConfigBackendHome::updateUser(const Common::UserInfo &oldUserInfo, const Common::UserInfo &userInfo) throw(Core::Exception) {
- boost::filesystem::path oldPath(homeDir.extract());
- oldPath /= oldUserInfo.getUsername().extract();
+ boost::filesystem::path oldPath(homeDir.toLocale());
+ oldPath /= oldUserInfo.getUsername().toLocale();
- boost::filesystem::path path(homeDir.extract());
- path /= userInfo.getUsername().extract();
+ boost::filesystem::path path(homeDir.toLocale());
+ path /= userInfo.getUsername().toLocale();
if(oldPath != path) {
try {
@@ -202,8 +202,8 @@ void UserConfigBackendHome::updateUser(const Common::UserInfo &oldUserInfo, cons
}
void UserConfigBackendHome::deleteUser(const Common::UserInfo &userInfo) throw(Core::Exception) {
- boost::filesystem::path path(homeDir.extract());
- path /= userInfo.getUsername().extract();
+ boost::filesystem::path path(homeDir.toLocale());
+ path /= userInfo.getUsername().toLocale();
boost::filesystem::remove_all(path);
}
diff --git a/src/modules/UserConfigBackendKrb5/UserConfigBackendKrb5.cpp b/src/modules/UserConfigBackendKrb5/UserConfigBackendKrb5.cpp
index 7d53e55..f0c65b1 100644
--- a/src/modules/UserConfigBackendKrb5/UserConfigBackendKrb5.cpp
+++ b/src/modules/UserConfigBackendKrb5/UserConfigBackendKrb5.cpp
@@ -30,12 +30,12 @@ namespace Modules {
namespace UserConfigBackendKrb5 {
void UserConfigBackendKrb5::_connect() {
- if(principal.empty()) {
+ if(principal.isEmpty()) {
application->log(Core::Logger::LOG_USER, Core::Logger::LOG_ERROR, "UserConfigBackendKrb5: no principal given");
return;
}
- if(realm.empty()) {
+ if(realm.isEmpty()) {
application->log(Core::Logger::LOG_USER, Core::Logger::LOG_ERROR, "UserConfigBackendKrb5: no realm given and no default realm available");
return;
}
@@ -49,20 +49,22 @@ void UserConfigBackendKrb5::_connect() {
}
kadm5_config_params params;
- params.realm = const_cast<char*>(realm.c_str());
+ std::string realmStr = realm.toLocale();
+ params.realm = const_cast<char*>(realmStr.c_str());
params.mask = KADM5_CONFIG_REALM;
- if(!server.empty()) {
- params.admin_server = const_cast<char*>(server.c_str());
+ std::string serverStr = server.toLocale();
+ if(!serverStr.empty()) {
+ params.admin_server = const_cast<char*>(serverStr.c_str());
params.mask |= KADM5_CONFIG_ADMIN_SERVER;
}
- std::string princ = principal;
- if(princ.find('@') == std::string::npos)
+ Core::String princ = principal;
+ if(princ.indexOf('@') < 0)
princ += "@" + realm;
- if(!password.empty() && keytab.empty()) {
- krb5_error_code err = kadm5_init_with_password(const_cast<char*>(princ.c_str()), const_cast<char*>(password.c_str()),
+ if(!password.isEmpty() && keytab.isEmpty()) {
+ krb5_error_code err = kadm5_init_with_password(const_cast<char*>(princ.toLocale().c_str()), const_cast<char*>(password.toLocale().c_str()),
const_cast<char*>(KADM5_ADMIN_SERVICE), &params, KADM5_STRUCT_VERSION, KADM5_API_VERSION_2, 0, &handle);
if(err) {
@@ -72,10 +74,13 @@ void UserConfigBackendKrb5::_connect() {
}
else {
char *keytabName = 0;
- if(!keytab.empty())
- keytabName = const_cast<char*>(keytab.c_str());
- krb5_error_code err = kadm5_init_with_skey(const_cast<char*>(princ.c_str()), keytabName,
+ std::string keytabStr = keytab.toLocale();
+ if(!keytabStr.empty()) {
+ keytabName = const_cast<char*>(keytabStr.c_str());
+ }
+
+ krb5_error_code err = kadm5_init_with_skey(const_cast<char*>(princ.toLocale().c_str()), keytabName,
const_cast<char*>(KADM5_ADMIN_SERVICE), &params, KADM5_STRUCT_VERSION, KADM5_API_VERSION_2, 0, &handle);
if(err) {
@@ -102,23 +107,23 @@ bool UserConfigBackendKrb5::handleConfigEntry(const Core::ConfigEntry &entry, bo
if(entry[2].getKey().matches("Realm")) {
if(entry[3].isEmpty())
- realm = entry[2][0].extract();
+ realm = entry[2][0];
}
else if(entry[2].getKey().matches("Principal")) {
if(entry[3].isEmpty())
- principal = entry[2][0].extract();
+ principal = entry[2][0];
}
else if(entry[2].getKey().matches("Server")) {
if(entry[3].isEmpty())
- server = entry[2][0].extract();
+ server = entry[2][0];
}
else if(entry[2].getKey().matches("Password")) {
if(entry[3].isEmpty())
- password = entry[2][0].extract();
+ password = entry[2][0];
}
else if(entry[2].getKey().matches("Keytab")) {
if(entry[3].isEmpty())
- keytab = entry[2][0].extract();
+ keytab = entry[2][0];
}
else if(!entry[2].isEmpty())
return false;
@@ -133,7 +138,7 @@ void UserConfigBackendKrb5::configFinished() {
void UserConfigBackendKrb5::checkUserInfo(const Common::UserInfo &userInfo) throw(Core::Exception) {
- std::string username = userInfo.getUsername().extract();
+ std::string username = userInfo.getUsername().toLocale();
if(std::strcspn(username.c_str(), "/@") != username.length())
throw Core::Exception(Core::Exception::INVALID_INPUT);
@@ -147,11 +152,11 @@ void UserConfigBackendKrb5::addUser(const Common::UserInfo &userInfo) throw(Core
if(!context || !handle)
throw Core::Exception(Core::Exception::NOT_AVAILABLE);
- std::string princStr = userInfo.getUsername().extract() + "@" + realm;
+ Core::String princStr = userInfo.getUsername() + "@" + realm;
kadm5_principal_ent_rec princ;
- krb5_error_code err = krb5_parse_name(context, princStr.c_str(), &princ.principal);
+ krb5_error_code err = krb5_parse_name(context, princStr.toLocale().c_str(), &princ.principal);
if(err)
throw Core::Exception("krb5_parse_name", Core::Exception::INTERNAL_ERRNO, err);
@@ -230,10 +235,10 @@ void UserConfigBackendKrb5::deleteUser(const Common::UserInfo &userInfo) throw(C
if(!context || !handle)
throw Core::Exception(Core::Exception::NOT_AVAILABLE);
- std::string princStr = userInfo.getUsername().extract() + "@" + realm;
+ Core::String princStr = userInfo.getUsername() + "@" + realm;
krb5_principal princ;
- krb5_error_code err = krb5_parse_name(context, princStr.c_str(), &princ);
+ krb5_error_code err = krb5_parse_name(context, princStr.toLocale().c_str(), &princ);
if(err)
throw Core::Exception("krb5_parse_name", Core::Exception::INTERNAL_ERRNO, err);
@@ -255,7 +260,7 @@ void UserConfigBackendKrb5::deleteUser(const Common::UserInfo &userInfo) throw(C
application->logf(Core::Logger::LOG_USER, Core::Logger::LOG_WARNING, "kadm5_delete_principal: %s", krb5_get_error_message(context, err));
}
-void UserConfigBackendKrb5::setPassword(const Common::UserInfo &userInfo, const std::string &password) throw(Core::Exception) {
+void UserConfigBackendKrb5::setPassword(const Common::UserInfo &userInfo, const Core::String &password) throw(Core::Exception) {
application->getThreadManager()->detach();
boost::lock_guard<boost::mutex> lock(mutex);
@@ -263,17 +268,17 @@ void UserConfigBackendKrb5::setPassword(const Common::UserInfo &userInfo, const
if(!context || !handle)
throw Core::Exception(Core::Exception::NOT_AVAILABLE);
- std::string princStr = userInfo.getUsername().extract() + "@" + realm;
+ Core::String princStr = userInfo.getUsername() + "@" + realm;
krb5_principal princ;
- krb5_error_code err = krb5_parse_name(context, princStr.c_str(), &princ);
+ krb5_error_code err = krb5_parse_name(context, princStr.toLocale().c_str(), &princ);
if(err)
throw Core::Exception("krb5_parse_name", Core::Exception::INTERNAL_ERRNO, err);
int retryCount = 3;
do {
- err = kadm5_chpass_principal(handle, princ, const_cast<char*>(password.c_str()));
+ err = kadm5_chpass_principal(handle, princ, const_cast<char*>(password.toLocale().c_str()));
if(err == KADM5_RPC_ERROR && retryCount > 0) {
application->log(Core::Logger::LOG_USER, Core::Logger::LOG_VERBOSE, "Connection to kerberos admin server lost. Reconnecting...");
_connect();
diff --git a/src/modules/UserConfigBackendKrb5/UserConfigBackendKrb5.h b/src/modules/UserConfigBackendKrb5/UserConfigBackendKrb5.h
index c2b35fe..eab8be4 100644
--- a/src/modules/UserConfigBackendKrb5/UserConfigBackendKrb5.h
+++ b/src/modules/UserConfigBackendKrb5/UserConfigBackendKrb5.h
@@ -41,8 +41,8 @@ class UserConfigBackendKrb5 : public Common::UserConfigBackend, private Core::Co
boost::mutex mutex;
- std::string realm, principal, server;
- std::string password, keytab;
+ Core::String realm, principal, server;
+ Core::String password, keytab;
krb5_context context;
void *handle;
@@ -59,7 +59,7 @@ class UserConfigBackendKrb5 : public Common::UserConfigBackend, private Core::Co
virtual void updateUser(const Common::UserInfo &oldUserInfo, const Common::UserInfo &userInfo) throw(Core::Exception);
virtual void deleteUser(const Common::UserInfo &userInfo) throw(Core::Exception);
- virtual void setPassword(const Common::UserInfo &userInfo, const std::string &password) throw(Core::Exception);
+ virtual void setPassword(const Common::UserInfo &userInfo, const Core::String &password) throw(Core::Exception);
public:
UserConfigBackendKrb5(Common::Application *application0) : application(application0), handle(0) {
diff --git a/src/modules/UserDBBackendMysql/UserDBBackendMysql.cpp b/src/modules/UserDBBackendMysql/UserDBBackendMysql.cpp
index 46f9d12..1d213a8 100644
--- a/src/modules/UserDBBackendMysql/UserDBBackendMysql.cpp
+++ b/src/modules/UserDBBackendMysql/UserDBBackendMysql.cpp
@@ -68,7 +68,7 @@ bool UserDBBackendMysql::handleConfigEntry(const Core::ConfigEntry &entry, bool
char *endptr;
long val;
- val = strtol(entry[2][0].extract().c_str(), &endptr, 10);
+ val = strtol(entry[2][0].toString().c_str(), &endptr, 10);
if(endptr != 0 || val < 0 || val > 65535)
application->log(Core::Logger::LOG_WARNING, "UserDBBackendMysql: Invalid port");
@@ -166,8 +166,8 @@ void UserDBBackendMysql::configFinished() {
boost::lock_guard<boost::mutex> lock(mutex);
mysql = mysql_init(0);
- mysql_real_connect(mysql, host.extract().c_str(), username.extract().c_str(), passwd.extract().c_str(),
- db.extract().c_str(), port, unixSocket.isEmpty() ? 0 : unixSocket.extract().c_str(), 0);
+ mysql_real_connect(mysql, host.toLocale().c_str(), username.toLocale().c_str(), passwd.toLocale().c_str(),
+ db.toLocale().c_str(), port, unixSocket.isEmpty() ? 0 : unixSocket.toLocale().c_str(), 0);
}
@@ -175,7 +175,7 @@ UserDBBackendMysql::Result UserDBBackendMysql::query(const Core::String &query,
if(!mysql || mysql_ping(mysql))
throw Core::Exception(Core::Exception::NOT_AVAILABLE);
- std::string queryStr = query.extract();
+ std::string queryStr = query.toLocale();
if(args.empty()) {
mysql_real_query(mysql, queryStr.c_str(), queryStr.length());
@@ -185,7 +185,7 @@ UserDBBackendMysql::Result UserDBBackendMysql::query(const Core::String &query,
std::string argStr;
try {
- argStr = boost::get<Core::String>(arg->second).extract();
+ argStr = boost::get<Core::String>(arg->second).toLocale();
}
catch(...) {
std::ostringstream stream;
@@ -196,7 +196,7 @@ UserDBBackendMysql::Result UserDBBackendMysql::query(const Core::String &query,
boost::scoped_array<char> escaped(new char[argStr.length()*2+1]);
mysql_real_escape_string(mysql, escaped.get(), argStr.c_str(), argStr.length());
- queryStr = boost::regex_replace(queryStr, boost::regex("\\{" + arg->first.extract() + "\\}"), "\"" + std::string(escaped.get()) + "\"", boost::match_default);
+ queryStr = boost::regex_replace(queryStr, boost::regex("\\{" + arg->first.toLocale() + "\\}"), "\"" + std::string(escaped.get()) + "\"", boost::match_default);
}
mysql_real_query(mysql, queryStr.c_str(), queryStr.length());