}
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) {
}
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()