* limitations under the License.
*/
+#include <fnmatch.h>
+
#include "lib/res_info/res_app_info.hh"
#include "lib/common/log_private.hh"
bool ResPkgInfo::IsAllowedPkg(const std::string& pkgid,
const std::set<std::string>& app_priv) {
- if (!allowed_pkg_priv_map_.count(pkgid))
- return false;
-
- for (const std::string& required_priv : allowed_pkg_priv_map_[pkgid]) {
- if (!app_priv.count(required_priv))
- return false;
+ for (const auto& it : allowed_pkg_priv_list_) {
+ if (fnmatch(it.first.c_str(), pkgid.c_str(), FNM_NOESCAPE))
+ continue;
+
+ bool has_required_priv = true;
+ for (const std::string& required_priv : it.second) {
+ if (!app_priv.count(required_priv)) {
+ has_required_priv = false;
+ break;
+ }
+ }
+ if (has_required_priv)
+ return true;
}
- return true;
+ return false;
}
void ResPkgInfo::SetBlocking() {
char* res_type;
char* res_version;
char* root_path;
- AllowedPkgPrivMap allowed_pkg_priv_map;
+ AllowedPkgPrivList allowed_pkg_priv_list;
if (pkgmgrinfo_pkginfo_get_pkgid(handle, &pkgid) != PMINFO_R_OK)
return nullptr;
if (!allowed_package)
return 0;
- AllowedPkgPrivMap* allowed_pkg_priv_map =
- reinterpret_cast<AllowedPkgPrivMap*>(user_data);
+ AllowedPkgPrivList* allowed_pkg_priv_list =
+ reinterpret_cast<AllowedPkgPrivList*>(user_data);
std::set<std::string> priv_set;
}, &priv_set) != PMINFO_R_OK)
return 0;
- (*allowed_pkg_priv_map)[allowed_package] = std::move(priv_set);
+ allowed_pkg_priv_list->emplace_back(
+ std::make_pair(allowed_package, std::move(priv_set)));
return 0;
- }, &allowed_pkg_priv_map) != PMINFO_R_OK)
+ }, &allowed_pkg_priv_list) != PMINFO_R_OK)
return nullptr;
return std::shared_ptr<ResPkgInfo>(new ResPkgInfo(pkgid, res_type,
- res_version, root_path, std::move(allowed_pkg_priv_map)));
+ res_version, root_path, std::move(allowed_pkg_priv_list)));
}
std::shared_ptr<ResPkgInfo> ResPkgInfo::CreateResPkgInfo(
#include <memory>
#include <string>
-using AllowedPkgPrivMap = std::map<std::string, std::set<std::string>>;
+using AllowedPkgPrivList =
+ std::vector<std::pair<std::string, std::set<std::string>>>;
namespace amd {
private:
ResPkgInfo(std::string pkgid, std::string res_type, std::string res_version,
- std::string root_path, AllowedPkgPrivMap priv_map)
+ std::string root_path, AllowedPkgPrivList priv_list)
: pkgid_(std::move(pkgid)),
res_type_(std::move(res_type)),
res_version_(std::move(res_version)),
root_path_(std::move(root_path)),
- allowed_pkg_priv_map_(std::move(priv_map)),
+ allowed_pkg_priv_list_(std::move(priv_list)),
is_blocked_(false) {}
std::string pkgid_;
std::string res_type_;
std::string res_version_;
std::string root_path_;
- AllowedPkgPrivMap allowed_pkg_priv_map_;
+ AllowedPkgPrivList allowed_pkg_priv_list_;
bool is_blocked_;
};