Handle exceptions in logic 93/176993/4
authorZofia Grzelewska <z.abramowska@samsung.com>
Mon, 23 Apr 2018 14:43:33 +0000 (16:43 +0200)
committerZofia Grzelewska <z.abramowska@samsung.com>
Tue, 24 Apr 2018 12:15:33 +0000 (14:15 +0200)
Catch exceptions thrown when security-manager or efl
failes inside Logic class.

Change-Id: I0735f10e1f12e29dcf93da351890a43fdf68e4fc

src/notification-daemon/Logic.cpp

index cd6e666..2a47a4c 100644 (file)
@@ -91,27 +91,31 @@ std::string clientResponseToPolicy(int clientResponse) {
 }
 
 void Logic::addChannelFd(Protocol::ConnectionFd fd, const Protocol::Credentials &creds) {
-    ALOGD("Adding new client with fd " << fd);
-    auto it = m_connToInfo.find(fd);
-    if (it != m_connToInfo.end()) {
-        ALOGE("Connection with fd : " << fd << " already exists. Closing connection");
-        m_serverChannel->process(fd, 0);
-        return;
-    }
+    try {
+        ALOGD("Adding new client with fd " << fd);
+        auto it = m_connToInfo.find(fd);
+        if (it != m_connToInfo.end()) {
+            ALOGE("Connection with fd : " << fd << " already exists. Closing connection");
+            m_serverChannel->process(fd, 0);
+            return;
+        }
 
-    if (creds.uid != std::to_string(geteuid())) {
-        ALOGE("This is very unexpected, client with different uid connected : " << creds.uid);
-        m_serverChannel->process(fd, 0);
-    }
+        if (creds.uid != std::to_string(geteuid())) {
+            ALOGE("This is very unexpected, client with different uid connected : " << creds.uid);
+            m_serverChannel->process(fd, 0);
+        }
 
-    std::string appId, pkgLabel;
-    identifyApp(creds.label, appId, pkgLabel);
+        std::string appId, pkgLabel;
+        identifyApp(creds.label, appId, pkgLabel);
 
-    ALOGD("Proper client connected");
-    stopTimer();
+        ALOGD("Proper client connected");
+        stopTimer();
 
-    ConnectionInfo connInfo{appId, pkgLabel, creds.uid};
-    m_connToInfo.insert(it, std::make_pair(fd, connInfo));
+        ConnectionInfo connInfo{appId, pkgLabel, creds.uid};
+        m_connToInfo.insert(it, std::make_pair(fd, connInfo));
+    } catch (const std::exception &e) {
+        ALOGE("Failed to add channel fd " << fd);
+    }
 }
 
 void Logic::updateChannelFd(Protocol::ConnectionFd fd, Ecore_Fd_Handler_Flags flags) {
@@ -216,44 +220,49 @@ void Logic::addEvent(Protocol::ConnectionFd fd, Protocol::RequestId id, const st
 }
 
 void Logic::popup(Protocol::ConnectionFd fd, Protocol::RequestId id, const std::string &privilege) {
-    ALOGD("Request for privilege " << privilege << " from fd " << fd << " with id " << id);
+    try {
+        ALOGD("Request for privilege " << privilege << " from fd " << fd << " with id " << id);
 
-    auto it = m_connToInfo.find(fd);
-    if (it == m_connToInfo.end()) {
-        ALOGE("Got request to non existing fd " << fd);
-        return;
-    }
-    ConnectionInfo &conn = it->second;
+        auto it = m_connToInfo.find(fd);
+        if (it == m_connToInfo.end()) {
+            ALOGE("Got request to non existing fd " << fd);
+            return;
+        }
+        ConnectionInfo &conn = it->second;
 
-    PrivilegePolicy privPolicy(conn.appId, privilege);
-    auto policyLevel = privPolicy.calculatePolicy();
+        PrivilegePolicy privPolicy(conn.appId, privilege);
+        auto policyLevel = privPolicy.calculatePolicy();
 
-    ALOGD("Privilege policy level calculated to : " << policyLevel);
-    if (policyLevel == "Allow") {
-        m_serverChannel->popupResponse(fd, id, ASKUSER_ALLOW_FOREVER);
-        return;
-    }
-    if (policyLevel == "Deny") {
-        m_serverChannel->popupResponse(fd, id, ASKUSER_DENY_FOREVER);
-        return;
-    }
-    if (policyLevel != "Ask user") {
-        ALOGE("Unknown policy set : " << policyLevel << " for (" << conn.appId << ", " << conn.user
-              << ", " << privilege << ")");
-        m_serverChannel->popupResponse(fd, id, ASKUSER_DENY_ONCE);
-        return;
-    }
+        ALOGD("Privilege policy level calculated to : " << policyLevel);
+        if (policyLevel == "Allow") {
+            m_serverChannel->popupResponse(fd, id, ASKUSER_ALLOW_FOREVER);
+            return;
+        }
+        if (policyLevel == "Deny") {
+            m_serverChannel->popupResponse(fd, id, ASKUSER_DENY_FOREVER);
+            return;
+        }
+        if (policyLevel != "Ask user") {
+            ALOGE("Unknown policy set : " << policyLevel << " for (" << conn.appId << ", " << conn.user
+                  << ", " << privilege << ")");
+            m_serverChannel->popupResponse(fd, id, ASKUSER_DENY_ONCE);
+            return;
+        }
 
-    auto privacies = privPolicy.getAskablePrivacies();
-    if (privacies.empty()) {
-        ALOGE("All privacies for privilege " << privilege
-              << " are already allowed");
-        m_serverChannel->popupResponse(fd, id, ASKUSER_ALLOW_FOREVER);
-        return;
-    }
+        auto privacies = privPolicy.getAskablePrivacies();
+        if (privacies.empty()) {
+            ALOGE("All privacies for privilege " << privilege
+                  << " are already allowed");
+            m_serverChannel->popupResponse(fd, id, ASKUSER_ALLOW_FOREVER);
+            return;
+        }
 
-    addEvent(fd, id, privacies);
-    processEvents();
+        addEvent(fd, id, privacies);
+        processEvents();
+    } catch (const std::exception &e) {
+        ALOGE("Failed to handle popup request : " << e.what());
+        m_serverChannel->popupResponse(fd, id, ASKUSER_DENY_ONCE);
+    }
 }
 
 Logic::~Logic()