summaryrefslogtreecommitdiffstats
path: root/src/modules/UserBackendMysql
diff options
context:
space:
mode:
Diffstat (limited to 'src/modules/UserBackendMysql')
-rw-r--r--src/modules/UserBackendMysql/UserBackendMysql.cpp51
-rw-r--r--src/modules/UserBackendMysql/UserBackendMysql.h4
2 files changed, 51 insertions, 4 deletions
diff --git a/src/modules/UserBackendMysql/UserBackendMysql.cpp b/src/modules/UserBackendMysql/UserBackendMysql.cpp
index 015c5a1..f169593 100644
--- a/src/modules/UserBackendMysql/UserBackendMysql.cpp
+++ b/src/modules/UserBackendMysql/UserBackendMysql.cpp
@@ -116,6 +116,14 @@ bool UserBackendMysql::handleConfigEntry(const Core::ConfigEntry &entry, bool ha
if(entry[3].empty())
queryAddUser = entry[2][0];
}
+ else if(entry[2].getKey().matches("UpdateUser")) {
+ if(entry[3].empty())
+ queryUpdateUser = entry[2][0];
+ }
+ else if(entry[2].getKey().matches("DeleteUser")) {
+ if(entry[3].empty())
+ queryDeleteUser = entry[2][0];
+ }
else if(!entry[2].empty())
return false;
}
@@ -463,9 +471,6 @@ void UserBackendMysql::addUser(const Common::UserInfo &userInfo) throw(Core::Exc
boost::lock_guard<boost::mutex> lock(mutex);
- if(!mysql || mysql_ping(mysql))
- throw Core::Exception(Core::Exception::NOT_AVAILABLE);
-
ArgumentMap args;
args.insert(std::make_pair("UID", userInfo.getUid()));
args.insert(std::make_pair("GID", userInfo.getGid()));
@@ -484,6 +489,46 @@ void UserBackendMysql::addUser(const Common::UserInfo &userInfo) throw(Core::Exc
lastUpdate = boost::posix_time::microsec_clock::universal_time();
}
+void UserBackendMysql::updateUser(unsigned long uid, const Common::UserInfo &userInfo) throw(Core::Exception) {
+ application->getThreadManager()->detach();
+
+ boost::lock_guard<boost::mutex> lock(mutex);
+
+ ArgumentMap args;
+ args.insert(std::make_pair("ORIG_UID", uid));
+ args.insert(std::make_pair("UID", userInfo.getUid()));
+ args.insert(std::make_pair("GID", userInfo.getGid()));
+ args.insert(std::make_pair("USER", userInfo.getUsername()));
+ args.insert(std::make_pair("FULL_NAME", userInfo.getFullName()));
+
+ Result result = query(queryUpdateUser, 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::deleteUser(unsigned long uid) throw(Core::Exception) {
+ application->getThreadManager()->detach();
+
+ boost::lock_guard<boost::mutex> lock(mutex);
+
+ ArgumentMap args;
+ args.insert(std::make_pair("UID", uid));
+
+ Result result = query(queryDeleteUser, 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 78926b9..a1c2bb1 100644
--- a/src/modules/UserBackendMysql/UserBackendMysql.h
+++ b/src/modules/UserBackendMysql/UserBackendMysql.h
@@ -94,7 +94,7 @@ class UserBackendMysql : public Common::UserBackend, private Core::Configurable,
std::string queryUserById, queryUserByName;
std::string queryGroupById, queryGroupByName;
std::string queryUserGroupTable;
- std::string queryAddUser;
+ std::string queryAddUser, queryUpdateUser, queryDeleteUser;
MYSQL *mysql;
@@ -119,6 +119,8 @@ class UserBackendMysql : public Common::UserBackend, private Core::Configurable,
virtual boost::shared_ptr<const std::multimap<unsigned long, unsigned long> > getFullUserGroupList(boost::posix_time::ptime *timestamp) throw(Core::Exception);
virtual void addUser(const Common::UserInfo &userInfo) throw(Core::Exception);
+ virtual void updateUser(unsigned long uid, const Common::UserInfo &userInfo) throw(Core::Exception);
+ virtual void deleteUser(unsigned long uid) throw(Core::Exception);
public:
UserBackendMysql(Common::Application *application0) : application(application0), port(0), mysql(0), lastUpdate(boost::posix_time::microsec_clock::universal_time()) {