From: Zofia Grzelewska Date: Mon, 23 Apr 2018 14:43:33 +0000 (+0200) Subject: Handle exceptions in logic X-Git-Tag: accepted/tizen/unified/20180425.133707~3 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F93%2F176993%2F4;p=platform%2Fcore%2Fsecurity%2Faskuser.git Handle exceptions in logic Catch exceptions thrown when security-manager or efl failes inside Logic class. Change-Id: I0735f10e1f12e29dcf93da351890a43fdf68e4fc --- diff --git a/src/notification-daemon/Logic.cpp b/src/notification-daemon/Logic.cpp index cd6e666..2a47a4c 100644 --- a/src/notification-daemon/Logic.cpp +++ b/src/notification-daemon/Logic.cpp @@ -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()