const char kSharedTrustedDir[] = "shared/trusted";
const char kSkelAppDir[] = "/etc/skel/apps_rw";
const char kLegacyAppDir[] = "/opt/usr/apps";
-const char kPackagePattern[] = R"(^[0-9a-zA-Z_-]+(\.?[0-9a-zA-Z_-]+)*$)";
const int32_t kPWBufSize = sysconf(_SC_GETPW_R_SIZE_MAX);
const int32_t kGRBufSize = sysconf(_SC_GETGR_R_SIZE_MAX);
-bool ValidateTizenPackageId(const std::string& id) {
- std::regex package_regex(kPackagePattern);
- return std::regex_match(id, package_regex);
-}
-
-int PkgmgrListCallback(const pkgmgrinfo_pkginfo_h handle, void *user_data) {
- auto pkgs = reinterpret_cast<ci::PkgList*>(user_data);
- char* pkgid = nullptr;
- if (pkgmgrinfo_pkginfo_get_pkgid(handle, &pkgid) != PMINFO_R_OK) {
- return -1;
- }
- char* api_version;
- if (pkgmgrinfo_pkginfo_get_api_version(handle, &api_version) != PMINFO_R_OK) {
- return -1;
- }
- pkgmgrinfo_certinfo_h cert_handle;
- if (pkgmgrinfo_pkginfo_create_certinfo(&cert_handle) != PMINFO_R_OK) {
- return -1;
- }
- if (pkgmgrinfo_pkginfo_load_certinfo(pkgid, cert_handle, 0) != PMINFO_R_OK) {
- pkgmgrinfo_pkginfo_destroy_certinfo(cert_handle);
- return -1;
- }
- const char* author_cert;
- if (pkgmgrinfo_pkginfo_get_cert_value(cert_handle, PMINFO_AUTHOR_SIGNER_CERT,
- &author_cert) != PMINFO_R_OK) {
- pkgmgrinfo_pkginfo_destroy_certinfo(cert_handle);
- return -1;
- }
- if (author_cert) {
- ValidationCore::Certificate cert(author_cert,
- ValidationCore::Certificate::FORM_BASE64);
- unsigned char* public_key;
- size_t len;
- cert.getPublicKeyDER(&public_key, &len);
- std::string author_id =
- ci::EncodeBase64(reinterpret_cast<const char*>(public_key));
- pkgs->emplace_back(pkgid, api_version, author_id);
- } else {
- pkgs->emplace_back(pkgid, std::string(), std::string());
- }
-
- pkgmgrinfo_pkginfo_destroy_certinfo(cert_handle);
-
- return 0;
-}
-
-ci::PkgList GetAllGlobalAppsInformation() {
- ci::PkgList pkgs;
- if (pkgmgrinfo_pkginfo_get_usr_list(&PkgmgrListCallback,
- &pkgs, GLOBAL_USER) != PMINFO_R_OK) {
- LOG(ERROR) << "Failed to query global application list";
- return {};
- }
- return pkgs;
-}
-
-ci::PkgList GetPkgInformation(uid_t uid, const std::string& pkgid) {
- if (!ValidateTizenPackageId(pkgid)) {
- LOG(DEBUG) << "Package id validation failed. pkgid = " << pkgid;
- return ci::PkgList();
- }
-
- ci::PkgList pkgs;
- pkgmgrinfo_pkginfo_h handle;
- if (pkgmgrinfo_pkginfo_get_usr_pkginfo(pkgid.c_str(), uid, &handle) !=
- PMINFO_R_OK) {
- LOG(DEBUG) << "pkgmgrinfo_pkginfo_get_pkginfo failed, for pkgid=" << pkgid;
- return {};
- }
- if (PkgmgrListCallback(handle, &pkgs) != 0) {
- pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
- LOG(DEBUG) << "PkgmgrListCallback failed";
- return {};
- }
- pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
- return pkgs;
-}
-
bool SetOwnerAndPermissions(const bf::path& subpath, uid_t uid,
gid_t gid, bf::perms perms) {
bs::error_code error;
return GetExternalCardPath().string();
}
-bool PerformInternalDirectoryCreationForUser(uid_t user,
- const std::string& pkgid,
- bool trusted) {
- const char* internal_storage_prefix = tzplatform_getenv(TZ_SYS_HOME);
- const bool set_permissions = true;
- if (!CreateUserDirectories(user, pkgid, trusted,
- internal_storage_prefix, set_permissions))
- return false;
- return true;
-}
-
bool PerformExternalDirectoryCreationForUser(uid_t user,
const std::string& pkgid) {
bf::path storage_path = GetExternalCardPath();
GetDirectoryPathForStorage(user, storage_apps_path.string()), pkgid);
}
-bool PerformInternalDirectoryCreationForAllUsers(const std::string& pkgid,
- bool trusted) {
- user_list list = GetUserList();
- for (auto l : list) {
- if (!PerformInternalDirectoryCreationForUser(std::get<0>(l),
- pkgid,
- trusted))
- LOG(ERROR) << "Could not create internal storage directories for user: "
- << std::get<0>(l);
- }
- return true;
-}
-
bool PerformExternalDirectoryCreationForAllUsers(const std::string& pkgid) {
user_list list = GetUserList();
for (auto l : list) {
return true;
}
-ci::PkgList CreatePkgInformationList(uid_t uid,
- const std::vector<std::string>& pkgs) {
- return pkgs.empty() ?
- GetAllGlobalAppsInformation() : GetPkgInformation(uid, *pkgs.begin());
-}
-
bool CreateLegacyDirectories(const std::string& pkgid) {
// create lagcay directories for backward compatibility
bs::error_code error;
namespace common_installer {
-struct PkgInfo {
- PkgInfo(std::string pkg_id_, std::string api_version_, std::string author_)
- : pkg_id(pkg_id_),
- api_version(api_version_),
- author_id(author_) {}
-
- std::string pkg_id;
- std::string api_version;
- std::string author_id;
-};
-
-using PkgList = std::vector<PkgInfo>;
-
-/**
- * \brief Performs a creation of directories for specific user in internal storage
- *
- * \param pkgid id of package
- * \param trusted is package trusted
- * \param create_skel_directories flag
- *
- * \return true if succeed, false otherwise
- */
-bool PerformInternalDirectoryCreationForUser(uid_t uid,
- const std::string& pkgid,
- bool trusted);
-
/**
* \brief Performs a creation of directories for specific user in external storage
*
const std::string& pkgid);
/**
- * \brief Performs a creation of directories in internal storage
- *
- * \param pkgid id of package
- * \param trusted is package trusted
- * \param create_skel_directories flag
- *
- * \return true if succeed, false otherwise
- *
- */
-bool PerformInternalDirectoryCreationForAllUsers(const std::string& pkgid,
- bool trusted);
-
-/**
* \brief Performs a creation of directories in external storage (eg. SD card)
*
* \param pkgid id of package
bool PerformExternalDirectoryDeletionForAllUsers(const std::string& pkgid);
/**
- * \brief Helper function fetching information about packages
- *
- * \param pkgs list of packages requested to fetch information about. If list
- * is empty, all possible pkg id's are considered.
- *
- * \return pkg_list list containing information about requested packages
- *
- */
-PkgList CreatePkgInformationList(uid_t uid = getuid(),
- const std::vector<std::string>& pkgs =
- std::vector<std::string>());
-
-/**
* \brief Create skeleton directories for package
*
* \param pkgid package id