diff options
Diffstat (limited to 'src/modules')
-rw-r--r-- | src/modules/UserBackendMysql/UserBackendMysql.cpp | 46 | ||||
-rw-r--r-- | src/modules/UserBackendMysql/UserBackendMysql.h | 4 |
2 files changed, 50 insertions, 0 deletions
diff --git a/src/modules/UserBackendMysql/UserBackendMysql.cpp b/src/modules/UserBackendMysql/UserBackendMysql.cpp index f169593..e076b10 100644 --- a/src/modules/UserBackendMysql/UserBackendMysql.cpp +++ b/src/modules/UserBackendMysql/UserBackendMysql.cpp @@ -124,6 +124,14 @@ bool UserBackendMysql::handleConfigEntry(const Core::ConfigEntry &entry, bool ha if(entry[3].empty()) queryDeleteUser = entry[2][0]; } + else if(entry[2].getKey().matches("AddUserToGroup")) { + if(entry[3].empty()) + queryAddUserToGroup = entry[2][0]; + } + else if(entry[2].getKey().matches("DeleteUserFromGroup")) { + if(entry[3].empty()) + queryDeleteUserFromGroup = entry[2][0]; + } else if(!entry[2].empty()) return false; } @@ -529,6 +537,44 @@ void UserBackendMysql::deleteUser(unsigned long uid) throw(Core::Exception) { lastUpdate = boost::posix_time::microsec_clock::universal_time(); } +void UserBackendMysql::addUserToGroup(unsigned long uid, unsigned long gid) throw(Core::Exception) { + application->getThreadManager()->detach(); + + boost::lock_guard<boost::mutex> lock(mutex); + + ArgumentMap args; + args.insert(std::make_pair("UID", uid)); + args.insert(std::make_pair("GID", gid)); + + Result result = query(queryAddUserToGroup, args); + + if(result.getErrno()) { + if(result.getErrno() == ER_DUP_ENTRY) + return; + else + throw Core::Exception(Core::Exception::NOT_AVAILABLE); + } + + lastUpdate = boost::posix_time::microsec_clock::universal_time(); +} + +void UserBackendMysql::deleteUserFromGroup(unsigned long uid, unsigned long gid) throw(Core::Exception) { + application->getThreadManager()->detach(); + + boost::lock_guard<boost::mutex> lock(mutex); + + ArgumentMap args; + args.insert(std::make_pair("UID", uid)); + args.insert(std::make_pair("GID", gid)); + + Result result = query(queryDeleteUserFromGroup, args); + + if(result.getErrno()) + throw Core::Exception(Core::Exception::NOT_AVAILABLE); + + lastUpdate = boost::posix_time::microsec_clock::universal_time(); +} + } } } diff --git a/src/modules/UserBackendMysql/UserBackendMysql.h b/src/modules/UserBackendMysql/UserBackendMysql.h index a1c2bb1..5ed8480 100644 --- a/src/modules/UserBackendMysql/UserBackendMysql.h +++ b/src/modules/UserBackendMysql/UserBackendMysql.h @@ -95,6 +95,7 @@ class UserBackendMysql : public Common::UserBackend, private Core::Configurable, std::string queryGroupById, queryGroupByName; std::string queryUserGroupTable; std::string queryAddUser, queryUpdateUser, queryDeleteUser; + std::string queryAddUserToGroup, queryDeleteUserFromGroup; MYSQL *mysql; @@ -122,6 +123,9 @@ class UserBackendMysql : public Common::UserBackend, private Core::Configurable, virtual void updateUser(unsigned long uid, const Common::UserInfo &userInfo) throw(Core::Exception); virtual void deleteUser(unsigned long uid) throw(Core::Exception); + virtual void addUserToGroup(unsigned long uid, unsigned long gid) throw(Core::Exception); + virtual void deleteUserFromGroup(unsigned long uid, unsigned long gid) throw(Core::Exception); + public: UserBackendMysql(Common::Application *application0) : application(application0), port(0), mysql(0), lastUpdate(boost::posix_time::microsec_clock::universal_time()) { application->getConfigManager()->registerConfigurable(this); |