certificate_validation.cc
external_storage.cc
installer_context.cc
+ pkgdir_tool_request.cc
plugins/plugin_factory.cc
plugins/plugin_manager.cc
plugins/plugin_list_parser.cc
--- /dev/null
+// Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+// Use of this source code is governed by an apache-2.0 license that can be
+// found in the LICENSE file.
+
+#include "common/pkgdir_tool_request.h"
+
+#include <glib.h>
+#include <gio/gio.h>
+#include <manifest_parser/utils/logging.h>
+
+#include "common/shared_dirs.h"
+
+namespace {
+
+const char kDBusServiceName[] = "org.tizen.pkgdir_tool";
+const char kDBusObjectPath[] = "/org/tizen/pkgdir_tool";
+const char kDBusInterfaceName[] = "org.tizen.pkgdir_tool";
+
+bool RequestUserDirectoryOperation(const char* method,
+ const std::string& pkgid) {
+ GError* err = nullptr;
+ GDBusConnection* con = g_bus_get_sync(G_BUS_TYPE_SYSTEM, nullptr, &err);
+ if (!con || err) {
+ LOG(WARNING) << "Failed to get dbus connection: " << err->message;
+ g_error_free(err);
+ return false;
+ }
+ GDBusProxy* proxy = g_dbus_proxy_new_sync(con, G_DBUS_PROXY_FLAGS_NONE,
+ nullptr, kDBusServiceName, kDBusObjectPath, kDBusInterfaceName, nullptr,
+ &err);
+ if (!proxy) {
+ std::string err_msg;
+ if (err) {
+ err_msg = std::string(err->message);
+ g_error_free(err);
+ }
+ LOG(ERROR) << "Failed to get dbus proxy: " << err_msg;
+ g_object_unref(con);
+ return false;
+ }
+ GVariant* r = g_dbus_proxy_call_sync(proxy, method,
+ g_variant_new("(s)", pkgid.c_str()), G_DBUS_CALL_FLAGS_NONE, -1, nullptr,
+ &err);
+ if (!r) {
+ std::string err_msg;
+ if (err) {
+ err_msg = std::string(err->message);
+ g_error_free(err);
+ }
+ LOG(ERROR) << "Failed to request: " << err_msg;
+ g_object_unref(proxy);
+ g_object_unref(con);
+ return false;
+ }
+ bool result;
+ g_variant_get(r, "(b)", &result);
+
+ g_variant_unref(r);
+ g_object_unref(proxy);
+ g_object_unref(con);
+
+ return result;
+}
+
+} // namespace
+
+namespace common_installer {
+
+bool RequestCopyUserDirectories(const std::string& pkgid) {
+ if (!RequestUserDirectoryOperation("CopyUserDirs", pkgid)) {
+ LOG(INFO) << "Try to copy user directories directly";
+ return CopyUserDirectories(pkgid);
+ }
+ return true;
+}
+
+bool RequestDeleteUserDirectories(const std::string& pkgid) {
+ if (!RequestUserDirectoryOperation("DeleteUserDirs", pkgid)) {
+ LOG(INFO) << "Try to delete user directories directly";
+ return DeleteUserDirectories(pkgid);
+ }
+ return true;
+}
+
+bool RequestCreateExternalDirectories(const std::string& pkgid) {
+ if (!RequestUserDirectoryOperation("CreateExternalDirs", pkgid)) {
+ LOG(INFO) << "Try to create external directories directly";
+ return PerformExternalDirectoryCreationForAllUsers(pkgid);
+ }
+ return true;
+}
+
+bool RequestDeleteExternalDirectories(const std::string& pkgid) {
+ if (!RequestUserDirectoryOperation("DeleteExternalDirs", pkgid)) {
+ LOG(INFO) << "Try to remove external directories directly";
+ return PerformExternalDirectoryDeletionForAllUsers(pkgid);
+ }
+ return true;
+}
+
+} // namespace common_installer
--- /dev/null
+// Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+// Use of this source code is governed by an apache-2.0 license that can be
+// found in the LICENSE file.
+
+#ifndef COMMON_PKGDIR_TOOL_REQUEST_H_
+#define COMMON_PKGDIR_TOOL_REQUEST_H_
+
+#include <string>
+
+namespace common_installer {
+
+/**
+ * \brief Request to copy per-user directories
+ *
+ * \param pkgid package id
+ *
+ * If IPC fails, fall back to direct function call (for offline)
+ *
+ * \return bool true if succeed, false otherwise
+ */
+bool RequestCopyUserDirectories(const std::string& pkgid);
+
+/**
+ * \brief Request to delete per-user directories
+ *
+ * \param pkgid package id
+ *
+ * If IPC fails, fall back to direct function call (for offline)
+ *
+ * \return bool true if succeed, false otherwise
+ */
+bool RequestDeleteUserDirectories(const std::string& pkgid);
+
+/**
+ * \brief Request to create external directories
+ *
+ * \param pkgid package id
+ *
+ * If IPC fails, fall back to direct function call (for offline)
+ *
+ * \return bool true if succeed, false otherwise
+ */
+bool RequestCreateExternalDirectories(const std::string& pkgid);
+
+/**
+ * \brief Request to delete external directories
+ *
+ * \param pkgid package id
+ *
+ * If IPC fails, fall back to direct function call (for offline)
+ *
+ * \return bool true if succeed, false otherwise
+ */
+bool RequestDeleteExternalDirectories(const std::string& pkgid);
+
+} // namespace common_installer
+
+#endif // COMMON_PKGDIR_TOOL_REQUEST_H_
pkgmgrinfo_pkginfo_h handle;
int ret = pkgmgrinfo_pkginfo_get_usr_pkginfo(pkg_id.c_str(), getuid(),
&handle);
- if (ret != PMINFO_R_OK)
+ if (ret != PMINFO_R_OK) {
+ LOG(ERROR) << "Failed to call pkgmgrinfo_pkginfo_get_usr_pkginfo";
return false;
+ }
bool is_global = false;
if (pkgmgrinfo_pkginfo_is_for_all_users(handle, &is_global) != PMINFO_R_OK) {
LOG(ERROR) << "pkgmgrinfo_pkginfo_is_for_all_users failed";
bool IsPackageInstalled(const std::string& pkg_id, uid_t uid) {
pkgmgrinfo_pkginfo_h handle;
int ret = pkgmgrinfo_pkginfo_get_usr_pkginfo(pkg_id.c_str(), uid, &handle);
- if (ret != PMINFO_R_OK)
+ if (ret != PMINFO_R_OK) {
+ LOG(ERROR) << "Failed to call pkgmgrinfo_pkginfo_get_usr_pkginfo";
return false;
+ }
bool is_global = false;
if (pkgmgrinfo_pkginfo_is_for_all_users(handle, &is_global) != PMINFO_R_OK) {
/**
* \brief Adapter interface for external PkgMgr module used for checking
- * if given package is installed/registered
+ * if given package is installed/registered per given uid only
*
* \param pkg_id package id
* \param uid user id
const char kSkelAppDir[] = "/etc/skel/apps_rw";
const char kPackagePattern[] = R"(^[0-9a-zA-Z_-]+(\.?[0-9a-zA-Z_-]+)*$)";
const char kExternalStorageDirPrefix[] = "SDCardA1";
-const char kDBusServiceName[] = "org.tizen.pkgdir_tool";
-const char kDBusObjectPath[] = "/org/tizen/pkgdir_tool";
-const char kDBusInterfaceName[] = "org.tizen.pkgdir_tool";
const int32_t kPWBufSize = sysconf(_SC_GETPW_R_SIZE_MAX);
const int32_t kGRBufSize = sysconf(_SC_GETGR_R_SIZE_MAX);
}
bool CreateDirectories(const bf::path& app_dir, const std::string& pkgid,
- const std::string& author_id,
+ bool trusted,
uid_t uid, gid_t gid, const bool set_permissions) {
bf::path base_dir = app_dir / pkgid;
if (bf::exists(base_dir)) {
bs::error_code error;
std::vector<const char*> dirs(kEntries);
- if (!author_id.empty())
+ if (trusted)
dirs.push_back(kTrustedDir);
for (auto& entry : dirs) {
bf::path subpath = base_dir / entry;
}
bool CreateUserDirectories(uid_t user, const std::string& pkgid,
- const std::string& author_id,
+ bool trusted,
const std::string& apps_prefix, const bool set_permissions) {
struct passwd pwd;
struct passwd *pwd_result;
return false;
}
- if (!CreateDirectories(apps_rw, pkgid, author_id,
+ if (!CreateDirectories(apps_rw, pkgid, trusted,
pwd.pw_uid, pwd.pw_gid, set_permissions)) {
return false;
}
return true;
}
-bool RequestUserDirectoryOperation(const char* method,
- const std::string& pkgid) {
- GError* err = nullptr;
- GDBusConnection* con = g_bus_get_sync(G_BUS_TYPE_SYSTEM, nullptr, &err);
- if (!con || err) {
- LOG(WARNING) << "Failed to get dbus connection: " << err->message;
- g_error_free(err);
- return false;
- }
- GDBusProxy* proxy = g_dbus_proxy_new_sync(con, G_DBUS_PROXY_FLAGS_NONE,
- nullptr, kDBusServiceName, kDBusObjectPath, kDBusInterfaceName, nullptr,
- &err);
- if (!proxy) {
- std::string err_msg;
- if (err) {
- err_msg = std::string(err->message);
- g_error_free(err);
- }
- LOG(ERROR) << "Failed to get dbus proxy: " << err_msg;
- g_object_unref(con);
- return false;
- }
- GVariant* r = g_dbus_proxy_call_sync(proxy, method,
- g_variant_new("(s)", pkgid.c_str()), G_DBUS_CALL_FLAGS_NONE, -1, nullptr,
- &err);
- if (!r) {
- std::string err_msg;
- if (err) {
- err_msg = std::string(err->message);
- g_error_free(err);
- }
- LOG(ERROR) << "Failed to request: " << err_msg;
- g_object_unref(proxy);
- g_object_unref(con);
- return false;
- }
- bool result;
- g_variant_get(r, "(b)", &result);
-
- g_variant_unref(r);
- g_object_unref(proxy);
- g_object_unref(con);
-
- return result;
-}
-
user_list GetUserList() {
GumUserService* service =
gum_user_service_create_sync((getuid() == 0) ? TRUE : FALSE);
bool PerformInternalDirectoryCreationForUser(uid_t user,
const std::string& pkgid,
- const std::string& author_id) {
+ bool trusted) {
const char* internal_storage_prefix = tzplatform_getenv(TZ_SYS_HOME);
const bool set_permissions = true;
- if (!CreateUserDirectories(user, pkgid, author_id,
+ if (!CreateUserDirectories(user, pkgid, trusted,
internal_storage_prefix, set_permissions))
return false;
return true;
}
bool PerformExternalDirectoryCreationForUser(uid_t user,
- const std::string& pkgid,
- const std::string& author_id) {
+ const std::string& pkgid) {
+ // TODO(t.iwanek): trusted in this context means that we have signature
+ // this argument is not longer needed as all package must be signed
+ // so that trusted directory may be labeled correctly by security-manager in
+ // all cases. This parameter and its propagation should be removed.
+ bool trusted = true;
+
const char* storage_path = tzplatform_mkpath(TZ_SYS_MEDIA,
kExternalStorageDirPrefix);
const bool set_permissions = false;
}
}
- if (CreateUserDirectories(user, pkgid, author_id,
+ if (CreateUserDirectories(user, pkgid, trusted,
storage_apps_path.c_str(), set_permissions)) {
}
return true;
}
+bool PerformExternalDirectoryDeletionForUser(uid_t user,
+ const std::string& pkgid) {
+ const char* storage_path = tzplatform_mkpath(TZ_SYS_MEDIA,
+ kExternalStorageDirPrefix);
+ if (!bf::exists(storage_path)) {
+ LOG(WARNING) << "External storage (SD Card) is not mounted.";
+ return false;
+ }
+
+ bf::path storage_apps_path = bf::path(storage_path) / "apps";
+ return DeleteDirectories(
+ GetDirectoryPathForStorage(user, storage_apps_path.string()), pkgid);
+}
+
bool PerformInternalDirectoryCreationForAllUsers(const std::string& pkgid,
- const std::string& author_id) {
+ bool trusted) {
user_list list = GetUserList();
for (auto l : list) {
if (!PerformInternalDirectoryCreationForUser(std::get<0>(l),
pkgid,
- author_id))
+ trusted))
LOG(ERROR) << "Could not create internal storage directories for user: "
<< std::get<0>(l);
}
return true;
}
-bool PerformExternalDirectoryCreationForAllUsers(const std::string& pkgid,
- const std::string& author_id) {
+bool PerformExternalDirectoryCreationForAllUsers(const std::string& pkgid) {
user_list list = GetUserList();
for (auto l : list) {
if (!PerformExternalDirectoryCreationForUser(std::get<0>(l),
- pkgid,
- author_id))
+ pkgid))
LOG(WARNING) << "Could not create external storage directories for user: "
<< std::get<0>(l);
}
return true;
}
+bool PerformExternalDirectoryDeletionForAllUsers(const std::string& pkgid) {
+ user_list list = GetUserList();
+ for (auto l : list) {
+ uid_t uid = std::get<0>(l);
+ LOG(DEBUG) << "Deleting directories for user: " << uid;
+ if (IsPackageInstalled(pkgid, uid)) {
+ LOG(DEBUG) << "Package: " << pkgid << " for uid: " << uid
+ << " still exists. Skipping";
+ continue;
+ }
+
+ if (!PerformExternalDirectoryDeletionForUser(uid, pkgid))
+ LOG(WARNING) << "Could not delete external storage directories for user: "
+ << uid;
+ }
+ return true;
+}
+
bool CreateSkelDirectories(const std::string& pkgid) {
bf::path path = bf::path(kSkelAppDir) / pkgid;
LOG(DEBUG) << "Creating directories in: " << path;
return true;
}
+bool DeleteUserExternalDirectories(const std::string& pkgid) {
+ user_list list = GetUserList();
+ for (auto l : list) {
+ if (ci::IsPackageInstalled(pkgid, std::get<0>(l))) {
+ LOG(INFO) << pkgid << " is installed for user " << std::get<0>(l);
+ continue;
+ }
+
+ LOG(DEBUG) << "Deleting external directories of " << pkgid
+ << ", for uid: " << std::get<0>(l);
+ bf::path apps_rw(std::get<2>(l) / "apps_rw");
+ if (!DeleteDirectories(apps_rw, pkgid)) {
+ return false;
+ }
+ }
+ return true;
+}
+
bool CopyUserDirectories(const std::string& pkgid) {
user_list list = GetUserList();
return true;
}
-bool RequestCopyUserDirectories(const std::string& pkgid) {
- if (!RequestUserDirectoryOperation("CopyUserDirs", pkgid)) {
- LOG(INFO) << "Try to copy user directories directly";
- return CopyUserDirectories(pkgid);
- }
- return true;
-}
-
-bool RequestDeleteUserDirectories(const std::string& pkgid) {
- if (!RequestUserDirectoryOperation("DeleteUserDirs", pkgid)) {
- LOG(INFO) << "Try to delete user directories directly";
- return DeleteUserDirectories(pkgid);
- }
- return true;
-}
-
ci::PkgList CreatePkgInformationList(uid_t uid,
const std::vector<std::string>& pkgs) {
return pkgs.empty() ?
#define COMMON_SHARED_DIRS_H_
#include <boost/filesystem/path.hpp>
+#include <pkgmgrinfo_basic.h>
#include <string>
#include <vector>
* \brief Performs a creation of directories for specific user in internal storage
*
* \param pkgid id of package
- * \param author_id id of author
+ * \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,
- const std::string& author_id);
+ bool trusted);
/**
* \brief Performs a creation of directories for specific user in external storage
*
* \param pkgid id of package
- * \param author_id id of author
* \param create_skel_directories flag
*
* \return true if succeed, false otherwise
*
*/
bool PerformExternalDirectoryCreationForUser(uid_t uid,
- const std::string& pkgid,
- const std::string& author_id);
+ const std::string& pkgid);
+
+/**
+ * \brief Performs a removal of directories for specific user in external storage
+ * \param user id of user
+ * \param pkgid id of package
+ *
+ * \return true if succeed, false otherwise
+ */
+bool PerformExternalDirectoryDeletionForUser(uid_t user,
+ const std::string& pkgid);
/**
* \brief Performs a creation of directories in internal storage
*
* \param pkgid id of package
- * \param author_id id of author
+ * \param trusted is package trusted
* \param create_skel_directories flag
*
* \return true if succeed, false otherwise
*
*/
bool PerformInternalDirectoryCreationForAllUsers(const std::string& pkgid,
- const std::string& author_id);
+ bool trusted);
/**
* \brief Performs a creation of directories in external storage (eg. SD card)
*
* \param pkgid id of package
- * \param author_id id of author
* \param create_skel_directories flag
*
* \return true if succeed, false otherwise
*
*/
-bool PerformExternalDirectoryCreationForAllUsers(const std::string& pkgid,
- const std::string& author_id);
+bool PerformExternalDirectoryCreationForAllUsers(const std::string& pkgid);
/**
- * \brief Performs deletion of directories
- *
- * \param pkg_path package path
+ * \brief Performs a removal of directories in external storage (eg. SD card)
+ * \param pkgid id of package
*
* \return true if succeed, false otherwise
- *
*/
-bool PerformDirectoryDeletionForAllUsers(const std::string& pkgid);
+bool PerformExternalDirectoryDeletionForAllUsers(const std::string& pkgid);
/**
* \brief Helper function fetching information about packages
bool CopyUserDirectories(const std::string& pkgid);
/**
- * \brief Request to copy per-user directories
- *
- * \param pkgid package id
- *
- * \return bool true if succeed, false otherwise
- *
- */
-bool RequestCopyUserDirectories(const std::string& pkgid);
-
-/**
- * \brief Request to delete per-user directories
- *
- * \param pkgid package id
- *
- * \return bool true if succeed, false otherwise
- *
- */
-bool RequestDeleteUserDirectories(const std::string& pkgid);
-
-/**
* \brief Returns path prefix for internal storage, typically '/home'
*
* \return path prefix
#include "common/step/filesystem/step_create_per_user_storage_directories.h"
#include "common/privileges.h"
+#include "common/pkgdir_tool_request.h"
#include "common/shared_dirs.h"
#include "common/utils/glist_range.h"
namespace filesystem {
common_installer::Step::Status StepCreatePerUserStorageDirectories::process() {
- if (!CreateExternalStorageDir()) return Step::Status::APP_DIR_ERROR;
- if (GLOBAL_USER != context_->uid.get()) return Step::Status::OK;
+ if (context_->request_mode.get() != RequestMode::GLOBAL)
+ return Step::Status::OK;
std::string package_id = context_->pkgid.get();
LOG(INFO) << "Creating per-user directories for package: " << package_id;
return Status::OK;
}
-bool StepCreatePerUserStorageDirectories::CreateExternalStorageDir() {
- auto manifest = context_->manifest_data.get();
- bool has_external_storage_priv = false;
- for (const char* priv : GListRange<char*>(manifest->privileges)) {
- if (strcmp(priv, common::privileges::kPrivForExternalAppData) == 0) {
- has_external_storage_priv = true;
- LOG(DEBUG) << "External storage privilege has been found.";
- break;
- }
- }
- if (!has_external_storage_priv) {
- LOG(DEBUG) << "External storage privilege not found, skipping.";
- return true;
- }
- std::vector<std::string> pkg_ids = { context_->pkgid.get() };
- auto pkg_list = CreatePkgInformationList(context_->uid.get(), pkg_ids);
-
- if (pkg_list.empty()) {
- LOG(ERROR) << "Could not create pkg information list.";
- return false;
- }
-
- PkgInfo pkg = *pkg_list.begin();
-
- switch (context_->request_mode.get()) {
- case RequestMode::GLOBAL: {
- LOG(DEBUG) << "Creating external directories for all users";
- PerformExternalDirectoryCreationForAllUsers(pkg.pkg_id,
- pkg.author_id);
- }
- break;
- case RequestMode::USER: {
- LOG(DEBUG) << "Creating external directories for user: "
- << context_->uid.get();
- PerformExternalDirectoryCreationForUser(context_->uid.get(),
- pkg.pkg_id,
- pkg.author_id);
- }
- break;
- }
- return true;
-}
-
} // namespace filesystem
} // namespace common_installer
Status precheck() override { return Status::OK; }
STEP_NAME(CreatePerUserStorageDirectories)
-
- private:
- bool CreateExternalStorageDir();
};
} // namespace filesystem
#include <vector>
#include "common/installer_context.h"
+#include "common/pkgdir_tool_request.h"
#include "common/shared_dirs.h"
namespace common_installer {
namespace filesystem {
Step::Status StepRemovePerUserStorageDirectories::process() {
- if (GLOBAL_USER != context_->uid.get()) return Step::Status::OK;
+ if (context_->request_mode.get() != RequestMode::GLOBAL)
+ return Step::Status::OK;
std::string package_id = context_->pkgid.get();
" <arg type='s' name='pkgid' direction='in'/>"
" <arg type='b' name='result' direction='out'/>"
" </method>"
+ " <method name='CreateExternalDirs'>"
+ " <arg type='s' name='pkgid' direction='in'/>"
+ " <arg type='b' name='result' direction='out'/>"
+ " </method>"
+ " <method name='DeleteExternalDirs'>"
+ " <arg type='s' name='pkgid' direction='in'/>"
+ " <arg type='b' name='result' direction='out'/>"
+ " </method>"
" </interface>"
"</node>";
const char kDBusServiceName[] = "org.tizen.pkgdir_tool";
r = ci::CopyUserDirectories(std::string(val));
} else if (g_strcmp0(method_name, "DeleteUserDirs") == 0) {
r = ci::DeleteUserDirectories(std::string(val));
+ } else if (g_strcmp0(method_name, "CreateExternalDirs") == 0) {
+ r = ci::PerformExternalDirectoryCreationForAllUsers(std::string(val));
+ } else if (g_strcmp0(method_name, "DeleteExternalDirs") == 0) {
+ r = ci::PerformExternalDirectoryDeletionForAllUsers(std::string(val));
} else {
LOG(ERROR) << "Unknown method call: " << method_name;
}