PKG_CHECK_MODULES(PDP_DEP
REQUIRED
cynara-plugin
+ security-manager
)
INCLUDE_DIRECTORIES(
${ASKUSER_PATH}/common/config
+ ${ASKUSER_PATH}/common/protocol
SYSTEM
${PDP_DEP_INCLUDE_DIRS}
)
ADD_LIBRARY(${TARGET_PRIVACYDENIED_PLUGIN_SERVICE} SHARED ${PDP_SERVICE_SOURCES})
ADD_LIBRARY(${TARGET_PRIVACYDENIED_PLUGIN_CLIENT} SHARED ${PDP_CLIENT_SOURCES})
-TARGET_LINK_LIBRARIES(${TARGET_PRIVACYDENIED_PLUGIN_SERVICE} ${PDP_DEP_LIBRARIES})
+TARGET_LINK_LIBRARIES(${TARGET_PRIVACYDENIED_PLUGIN_SERVICE} ${PDP_DEP_LIBRARIES} ${TARGET_ASKUSER_NOTIFICATION_LIB})
TARGET_LINK_LIBRARIES(${TARGET_PRIVACYDENIED_PLUGIN_CLIENT} ${PDP_DEP_LIBRARIES})
INSTALL(TARGETS ${TARGET_PRIVACYDENIED_PLUGIN_SERVICE}
return true;
}
- bool isUsable(const ClientSession &session UNUSED,
- const ClientSession &prevSession UNUSED,
+ bool isUsable(const ClientSession &session,
+ const ClientSession &prevSession,
bool &updateSession,
- PolicyResult & result UNUSED)
+ PolicyResult &result UNUSED)
{
updateSession = false;
- return true;
+ return (session.compare(prevSession) == 0);
}
void invalidate() {}
int toResult(const ClientSession &session UNUSED, PolicyResult &result UNUSED) {
- // This is the place where notify service should be notified
return CYNARA_API_ACCESS_DENIED;
}
};
* @brief Implementation of cynara service side PrivacyDenied plugin.
*/
+#include <memory>
#include <string>
#include <vector>
#include <cynara-plugin.h>
+#include <app-runtime.h>
#include <attributes/attributes.h>
#include <PrivacyConfig.h>
+#include <askuser-notification/ask-user-client.h>
using namespace Cynara;
return serviceDescriptions;
}
- PluginStatus check(const std::string &client UNUSED,
- const std::string &user UNUSED,
- const std::string &privilege UNUSED,
+ PluginStatus check(const std::string &client,
+ const std::string &user,
+ const std::string &privilege,
PolicyResult &result UNUSED,
AgentType &requiredAgent UNUSED,
PluginData &pluginData UNUSED) noexcept
{
- // Don't touch result. It's already set up by cynara
- return PluginStatus::SUCCESS;
+ toast(client, user, privilege);
+ return PluginStatus::ANSWER_READY;
}
PluginStatus update(const std::string &client UNUSED,
}
void invalidate() {}
+
+private:
+ void toast(const std::string &client, const std::string &user, const std::string &privilege) {
+ char *pkgName = nullptr, *appName = nullptr;
+ int ret = security_manager_identify_app_from_cynara_client(client.c_str(), &pkgName, &appName);
+ if (ret != SECURITY_MANAGER_SUCCESS || pkgName == nullptr)
+ return;
+
+ std::unique_ptr<char, decltype(free)*> pkgNamePtr(pkgName, free);
+ std::unique_ptr<char, decltype(free)*> appNamePtr(appName, free);
+ AskUser::Protocol::toast_deny(pkgName, (appName ? appName : ""), std::stoi(user), privilege);
+ }
};
} // namespace PrivacyDeniedPlugin