#include <unistd.h>
#include <pkgmgr_installer.h>
+#include <pkgmgrinfo_type.h>
#include <vcore/Certificate.h>
#include <cassert>
#include <string>
#include "common/pkgmgr_registration.h"
+#include "common/privileges.h"
#include "common/utils/pkgmgr_query.h"
#include "common/utils/file_util.h"
return true;
}
+bool StepUnregisterApplication::BackupPrivileges() {
+ PkgQueryInterface pkg_query(context_->pkgid.get(), context_->uid.get());
+ if (!pkg_query.IsValid()) {
+ LOG(ERROR) << "This package is not installed";
+ return false;
+ }
+
+ std::vector<std::tuple<int, std::string, std::string>> result;
+ if (!pkg_query.PrivilegesForPkgId(&result)) {
+ LOG(ERROR) << "Failed to get package's privileges";
+ return false;
+ }
+
+ manifest_x* manifest = context_->manifest_data.get();
+ g_list_free_full(manifest->privileges, common_installer::FreePrivilegeX);
+ manifest->privileges = nullptr;
+ for (const auto& it : result) {
+ if (std::get<0>(it) != static_cast<int>(PMINFO_PRIVILEGE_NORMAL))
+ continue;
+
+ privilege_x* privilege =
+ reinterpret_cast<privilege_x*>(calloc(1, sizeof(privilege_x)));
+ if (!privilege) {
+ LOG(ERROR) << "Out of memory";
+ return false;
+ }
+ privilege->value = strdup(std::get<1>(it).c_str());
+ privilege->type = strdup(std::get<2>(it).c_str());
+ manifest->privileges = g_list_append(manifest->privileges, privilege);
+ }
+
+ return true;
+}
+
Step::Status StepUnregisterApplication::process() {
// Prepare certificate info for rollback operations
if (!BackupCertInfo())
LOG(ERROR) << "Failed to backup cert info";
+ if (!BackupPrivileges())
+ LOG(ERROR) << "can't backup privilege";
+
if (!UnregisterAppInPkgmgr(context_->manifest_data.get(),
context_->pkgid.get(),
context_->uid.get(),
private:
bool BackupCertInfo();
+ bool BackupPrivileges();
STEP_NAME(UnregisterApplication)
};
#include <manifest_parser/utils/logging.h>
#include <pkgmgr_installer.h>
#include <pkgmgr_parser.h>
+#include <pkgmgrinfo_type.h>
#include <tzplatform_config.h>
#include <cstring>
return error_ == PMINFO_R_OK;
}
-bool PkgQueryInterface::PrivilegesForPkgId(std::vector<std::string>* result) {
+//bool PkgQueryInterface::PrivilegesForPkgId(std::vector<std::string>* result) {
+// if (!IsValid())
+// return false;
+// error_ = pkgmgrinfo_pkginfo_foreach_privilege(handle_->handle,
+// [](const char* privilege_name, void* user_data) -> int {
+// auto* data = static_cast<std::vector<std::string>*>(user_data);
+// data->emplace_back(privilege_name);
+// return PMINFO_R_OK;
+// },
+// result);
+// return error_ == PMINFO_R_OK;
+//}
+
+bool PkgQueryInterface::PrivilegesForPkgId(
+ std::vector<std::tuple<int, std::string, std::string>>* result) {
if (!IsValid())
return false;
- error_ = pkgmgrinfo_pkginfo_foreach_privilege(handle_->handle,
- [](const char* privilege_name, void* user_data) -> int {
- auto* data = static_cast<std::vector<std::string>*>(user_data);
- data->emplace_back(privilege_name);
- return PMINFO_R_OK;
+ error_ = pkgmgrinfo_pkginfo_foreach_privilege_v2(handle_->handle,
+ [](pkgmgrinfo_pkginfo_privilege_h handle, void *user_data) -> int {
+ auto* data = static_cast<std::vector<std::tuple<int, std::string, std::string>>*>(user_data);
+ pkgmgrinfo_privilege_category ca;
+ char* type;
+ char* name;
+
+ if (pkgmgrinfo_get_privilege_category(handle, &ca) != PMINFO_R_OK)
+ return 0;
+
+ if (pkgmgrinfo_get_privilege_name(handle, &name) != PMINFO_R_OK)
+ return 0;
+
+ if (pkgmgrinfo_get_privilege_type(handle, &type) != PMINFO_R_OK)
+ return 0;
+
+ data->emplace_back(std::make_tuple(static_cast<int>(ca), std::string(name), std::string(type)));
+ return 0;
},
result);
return error_ == PMINFO_R_OK;
*
* \return true if success
*/
- bool PrivilegesForPkgId(std::vector<std::string>* result);
+ bool PrivilegesForPkgId(std::vector<std::tuple<int, std::string, std::string>>* result);
/**
* \brief Returns whether plugin has executed for given package