summaryrefslogtreecommitdiffstats
path: root/src/modules/UserBackendMysql
diff options
context:
space:
mode:
authorMatthias Schiffer <matthias@gamezock.de>2009-08-07 00:12:52 +0200
committerMatthias Schiffer <matthias@gamezock.de>2009-08-07 00:12:52 +0200
commit758f3cf98f95fc906c2517c0d4537ce81cf7386d (patch)
tree7e3afe4df48961a509cc25196d1bc6bb7d3ee28f /src/modules/UserBackendMysql
parent94c00010a0280b8adc220377916a65b8dba08b62 (diff)
downloadmad-758f3cf98f95fc906c2517c0d4537ce81cf7386d.tar
mad-758f3cf98f95fc906c2517c0d4537ce81cf7386d.zip
UserBackendMysql, client: Added group administration
Diffstat (limited to 'src/modules/UserBackendMysql')
-rw-r--r--src/modules/UserBackendMysql/UserBackendMysql.cpp71
-rw-r--r--src/modules/UserBackendMysql/UserBackendMysql.h5
2 files changed, 76 insertions, 0 deletions
diff --git a/src/modules/UserBackendMysql/UserBackendMysql.cpp b/src/modules/UserBackendMysql/UserBackendMysql.cpp
index 3ef44d1..f2729ab 100644
--- a/src/modules/UserBackendMysql/UserBackendMysql.cpp
+++ b/src/modules/UserBackendMysql/UserBackendMysql.cpp
@@ -128,6 +128,18 @@ bool UserBackendMysql::handleConfigEntry(const Core::ConfigEntry &entry, bool /*
if(entry[4].empty())
queryDeleteUser = entry[3][0];
}
+ else if(entry[3].getKey().matches("AddGroup")) {
+ if(entry[4].empty())
+ queryAddGroup = entry[3][0];
+ }
+ else if(entry[3].getKey().matches("UpdateGroup")) {
+ if(entry[4].empty())
+ queryUpdateGroup = entry[3][0];
+ }
+ else if(entry[3].getKey().matches("DeleteGroup")) {
+ if(entry[4].empty())
+ queryDeleteGroup = entry[3][0];
+ }
else if(entry[3].getKey().matches("AddUserToGroup")) {
if(entry[4].empty())
queryAddUserToGroup = entry[3][0];
@@ -538,6 +550,65 @@ void UserBackendMysql::deleteUser(unsigned long uid) throw(Core::Exception) {
lastUpdate = boost::posix_time::microsec_clock::universal_time();
}
+void UserBackendMysql::addGroup(const Common::GroupInfo &groupInfo) throw(Core::Exception) {
+ application->getThreadManager()->detach();
+
+ boost::lock_guard<boost::mutex> lock(mutex);
+
+ ArgumentMap args;
+ args.insert(std::make_pair("GID", groupInfo.getGid()));
+ args.insert(std::make_pair("GROUP", groupInfo.getName()));
+
+ Result result = query(queryAddGroup, args);
+
+ if(result.getErrno()) {
+ if(result.getErrno() == ER_DUP_ENTRY)
+ throw Core::Exception(Core::Exception::DUPLICATE_ENTRY);
+ else
+ throw Core::Exception(Core::Exception::NOT_AVAILABLE);
+ }
+
+ lastUpdate = boost::posix_time::microsec_clock::universal_time();
+}
+
+void UserBackendMysql::updateGroup(unsigned long gid, const Common::GroupInfo &groupInfo) throw(Core::Exception) {
+ application->getThreadManager()->detach();
+
+ boost::lock_guard<boost::mutex> lock(mutex);
+
+ ArgumentMap args;
+ args.insert(std::make_pair("ORIG_GID", gid));
+ args.insert(std::make_pair("GID", groupInfo.getGid()));
+ args.insert(std::make_pair("GROUP", groupInfo.getName()));
+
+ Result result = query(queryUpdateGroup, args);
+
+ if(result.getErrno()) {
+ if(result.getErrno() == ER_DUP_ENTRY)
+ throw Core::Exception(Core::Exception::DUPLICATE_ENTRY);
+ else
+ throw Core::Exception(Core::Exception::NOT_AVAILABLE);
+ }
+
+ lastUpdate = boost::posix_time::microsec_clock::universal_time();
+}
+
+void UserBackendMysql::deleteGroup(unsigned long gid) throw(Core::Exception) {
+ application->getThreadManager()->detach();
+
+ boost::lock_guard<boost::mutex> lock(mutex);
+
+ ArgumentMap args;
+ args.insert(std::make_pair("GID", gid));
+
+ Result result = query(queryDeleteGroup, args);
+
+ if(result.getErrno())
+ throw Core::Exception(Core::Exception::NOT_AVAILABLE);
+
+ lastUpdate = boost::posix_time::microsec_clock::universal_time();
+}
+
void UserBackendMysql::addUserToGroup(unsigned long uid, unsigned long gid) throw(Core::Exception) {
application->getThreadManager()->detach();
diff --git a/src/modules/UserBackendMysql/UserBackendMysql.h b/src/modules/UserBackendMysql/UserBackendMysql.h
index 85bc678..c3848c0 100644
--- a/src/modules/UserBackendMysql/UserBackendMysql.h
+++ b/src/modules/UserBackendMysql/UserBackendMysql.h
@@ -97,6 +97,7 @@ class UserBackendMysql : public Common::UserDBBackend, private Core::Configurabl
std::string queryGroupById, queryGroupByName;
std::string queryUserGroupTable;
std::string queryAddUser, queryUpdateUser, queryDeleteUser;
+ std::string queryAddGroup, queryUpdateGroup, queryDeleteGroup;
std::string queryAddUserToGroup, queryDeleteUserFromGroup;
MYSQL *mysql;
@@ -125,6 +126,10 @@ class UserBackendMysql : public Common::UserDBBackend, private Core::Configurabl
virtual void updateUser(unsigned long uid, const Common::UserInfo &userInfo) throw(Core::Exception);
virtual void deleteUser(unsigned long uid) throw(Core::Exception);
+ virtual void addGroup(const Common::GroupInfo &groupInfo) throw(Core::Exception);
+ virtual void updateGroup(unsigned long gid, const Common::GroupInfo &groupInfo) throw(Core::Exception);
+ virtual void deleteGroup(unsigned long gid) 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);