const app_defined_privilege_type type,
const char *license)
{
- if (!p_req || !app_defined_privilege ||
- type < SM_APP_DEFINED_PRIVILEGE_TYPE_UNTRUSTED || type > SM_APP_DEFINED_PRIVILEGE_TYPE_LICENSED ||
- (type == SM_APP_DEFINED_PRIVILEGE_TYPE_LICENSED && !license))
+ if (!p_req ||
+ !app_defined_privilege ||
+ type < SM_APP_DEFINED_PRIVILEGE_TYPE_UNTRUSTED ||
+ type > SM_APP_DEFINED_PRIVILEGE_TYPE_LICENSED)
+ {
return SECURITY_MANAGER_ERROR_INPUT_PARAM;
+ }
+
+ // do not allow put empty license in database!
+ if (type == SM_APP_DEFINED_PRIVILEGE_TYPE_LICENSED && (!license || (0 == strlen(license)))) {
+ return SECURITY_MANAGER_ERROR_INPUT_PARAM;
+ }
p_req->appDefinedPrivileges.push_back(std::make_tuple(app_defined_privilege, static_cast<int>(type), license));
PrivilegeDb &m_privilegeDb;
};
+bool verifyAppDefinedPrivileges(const AppDefinedPrivilegesVector &privileges) {
+ // TODO check for collision with system privileges
+
+ // check if licenses are set for license-privileges
+ for (auto &e : privileges) {
+ if ((std::get<1>(e) == SM_APP_DEFINED_PRIVILEGE_TYPE_LICENSED) && std::get<2>(e).empty())
+ return false;
+ }
+ return true;
+}
+
} // end of anonymous namespace
ServiceImpl::ServiceImpl()
try {
std::vector<std::string> privilegeList;
privilegeList.reserve(req.privileges.size());
+ if (!verifyAppDefinedPrivileges(req.appDefinedPrivileges))
+ return SECURITY_MANAGER_ERROR_INPUT_PARAM;
for (auto &e : req.privileges)
privilegeList.push_back(e.first);