PolicyEventNotifier::init();
setPrivilegeChecker(std::bind(&DevicePolicyManager::checkPeerPrivilege, this, _1, _2));
+ setNewConnectionCallback(std::bind(&DevicePolicyManager::checkNewConnection, this, _1));
+ setCloseConnectionCallback(std::bind(&DevicePolicyManager::checkCloseConnection, this, _1));
expose(this, "", (int)(DevicePolicyManager::enroll)(std::string, uid_t));
expose(this, "", (int)(DevicePolicyManager::disenroll)(std::string, uid_t));
return true;
}
+
+bool DevicePolicyManager::checkNewConnection(const rmi::Connection& connection)
+{
+ auto pid = (connection.getPeerCredentials()).pid;
+ if(clientRegistry.count(pid)) {
+ if(clientRegistry[pid] >= MAX_CLIENT_CONNECTIONS) {
+ return false;
+ } else {
+ clientRegistry[pid]++;
+ }
+ } else {
+ clientRegistry.emplace(pid, 1);
+ }
+
+ return true;
+}
+
+bool DevicePolicyManager::checkCloseConnection(const rmi::Connection& connection)
+{
+ auto pid = (connection.getPeerCredentials()).pid;
+ if(clientRegistry.count(pid)) {
+ clientRegistry[pid]--;
+ if(clientRegistry[pid] == 0) {
+ clientRegistry.erase(pid);
+ }
+ }
+
+ return true;
+}
#include "plugin.h"
#include "sql-backend.h"
+#define MAX_CLIENT_CONNECTIONS 10
+
class DevicePolicyManager : public rmi::Service {
public:
DevicePolicyManager();
int disenroll(const std::string& name, uid_t uid);
bool checkPeerPrivilege(const rmi::Credentials& cred, const std::string& privilege);
+ bool checkNewConnection(const rmi::Connection& connection);
+ bool checkCloseConnection(const rmi::Connection& connection);
private:
+ typedef std::unordered_map<int, int> ClientRegistry;
+ ClientRegistry clientRegistry;
+
std::vector<AbstractPolicyProvider *> policyList;
std::unique_ptr<PolicyLoader> policyLoader;
};