From 904a8c33df56b641364c7d463d335eded21b83b0 Mon Sep 17 00:00:00 2001 From: Sungbae Yoo Date: Fri, 23 Mar 2018 15:30:25 +0900 Subject: [PATCH] Add the gumd prefix to app-proxy and package-proxy APIs Change-Id: I5118eb9f19b3ea6893e41ecb33975319a80e3642 Signed-off-by: Sungbae Yoo --- server/app-proxy.cpp | 14 ++++++++------ server/manager.cpp | 25 +++++++++++++------------ server/package-proxy.cpp | 10 ++++++---- server/server.cpp | 6 ++++++ 4 files changed, 33 insertions(+), 22 deletions(-) diff --git a/server/app-proxy.cpp b/server/app-proxy.cpp index 48b031c..cb15c7c 100644 --- a/server/app-proxy.cpp +++ b/server/app-proxy.cpp @@ -31,6 +31,8 @@ #define PRIVILEGE_APP_LAUNCH "http://tizen.org/privilege/appmanager.launch" #define PRIVILEGE_APP_KILL "http://tizen.org/privilege/appmanager.kill" +extern std::string KRATE_ID_PREFIX; + namespace Krate { namespace { @@ -71,7 +73,7 @@ AppProxy::AppInfo AppProxy::getAppInfo(const std::string& name, const std::strin AppInfo appInfo; try { - runtime::User user(name); + runtime::User user(KRATE_ID_PREFIX + name); ApplicationInfo appinfo(appid, user.getUid()); char* locale; @@ -104,7 +106,7 @@ int AppProxy::createIterator(const std::string& name) int iteratorId = -1; try { PackageManager& packman = PackageManager::instance(); - runtime::User user(name); + runtime::User user(KRATE_ID_PREFIX + name); IteratorData data; iteratorId = newIteratorId; @@ -184,7 +186,7 @@ int AppProxy::destroyIterator(int iterator) int AppProxy::launch(const std::string& name, const AppProxy::Bundle& bundle) { try { - runtime::User user(name); + runtime::User user(KRATE_ID_PREFIX + name); ::Bundle b; if (!bundle.operation.empty()) { @@ -220,7 +222,7 @@ int AppProxy::launch(const std::string& name, const AppProxy::Bundle& bundle) int AppProxy::resume(const std::string& name, const std::string& appid) { try { - runtime::User user(name); + runtime::User user(KRATE_ID_PREFIX + name); Launchpad launchpad(user.getUid()); launchpad.resume(appid); } catch (runtime::Exception& e) { @@ -233,7 +235,7 @@ int AppProxy::resume(const std::string& name, const std::string& appid) int AppProxy::terminate(const std::string& name, const std::string& appid) { try { - runtime::User user(name); + runtime::User user(KRATE_ID_PREFIX + name); Launchpad launchpad(user.getUid()); launchpad.terminate(appid); } catch (runtime::Exception& e) { @@ -246,7 +248,7 @@ int AppProxy::terminate(const std::string& name, const std::string& appid) bool AppProxy::isRunning(const std::string& name, const std::string& appid) { try { - runtime::User user(name); + runtime::User user(KRATE_ID_PREFIX + name); Launchpad launchpad(user.getUid()); return launchpad.isRunning(appid); } catch (runtime::Exception& e) { diff --git a/server/manager.cpp b/server/manager.cpp index 643deb1..a817093 100755 --- a/server/manager.cpp +++ b/server/manager.cpp @@ -49,6 +49,8 @@ #define DEFAULT_ICON_PATH ICON_PATH "/default_icon.png" #define NOTIFICATION_SUB_ICON_PATH ICON_PATH "/notification_sub_icon.png" +extern std::string KRATE_ID_PREFIX; + namespace Krate { namespace { @@ -70,7 +72,6 @@ const std::string KRATE_CREATE_HOOK_PATH = "/etc/gumd/useradd.d"; const std::string KRATE_REMOVE_HOOK_PATH = "/etc/gumd/userdel.d"; std::string KRATE_DEFAULT_OWNER; -std::string KRATE_ID_PREFIX; std::list createdKrateList; static std::atomic isKrateForeground(false); @@ -461,7 +462,7 @@ void notiProxyUpdate(const runtime::User& owner, const runtime::User& user, int void notiProxyCallback(void *data, notification_type_e type, notification_op *op_list, int num_op) { static runtime::User owner(KRATE_DEFAULT_OWNER); - runtime::User user(*reinterpret_cast(data)); + runtime::User user(KRATE_ID_PREFIX + *reinterpret_cast(data)); if (user.getName() == owner.getName()) { // TODO : should remove noti in the krate when related-krate is removed @@ -512,7 +513,6 @@ Manager::Manager(KrateControlContext& ctx) : runtime::Cgroup::create(CGROUP_SUBSYSTEM, CGROUP_SUBSYSTEM); KRATE_DEFAULT_OWNER = ::tzplatform_getenv(TZ_SYS_DEFAULT_USER); - KRATE_ID_PREFIX = gum_user_type_to_prefix(GUM_USERTYPE_SECURITY); PackageManager& packageManager = PackageManager::instance(); packageManager.setEventCallback(packageEventHandler, this); @@ -547,17 +547,18 @@ int Manager::createKrate(const std::string& name, const std::string& manifest) for (int i = 0; i < GUMD_RETRY_COUNT && guser == NULL; i++) { guser = gum_user_create_sync(FALSE); } - g_object_set(G_OBJECT(guser), "username", name.c_str(), + g_object_set(G_OBJECT(guser), "username", + (KRATE_ID_PREFIX + name).c_str(), "usertype", GUM_USERTYPE_SECURITY, NULL); ret = gum_user_add_sync(guser); g_object_unref(guser); } if (!ret) { - throw runtime::Exception("Failed to remove user (" + name + ") by gumd"); + throw runtime::Exception("Failed to create user (" + name + ") by gumd"); } - runtime::User user(name + KRATE_ID_PREFIX); + runtime::User user(KRATE_ID_PREFIX + name); maskUserServices(user); @@ -585,6 +586,7 @@ int Manager::createKrate(const std::string& name, const std::string& manifest) auto it = createdKrateList.insert(createdKrateList.end(), name); notification_register_detailed_changed_cb_for_uid(notiProxyCallback, &(*it), user.getUid()); + context.notify("Manager::created", name, ""); } catch (runtime::Exception& e) { ERROR(e.what()); @@ -717,12 +719,11 @@ int Manager::getKrateState(const std::string& name) runtime::User user(KRATE_ID_PREFIX + name); try { dbus::Connection& systemDBus = dbus::Connection::getSystem(); - const dbus::Variant& var = systemDBus.methodcall - ("org.freedesktop.login1", - "/org/freedesktop/login1", - "org.freedesktop.login1.Manager", - "GetUser", - -1, "(o)", "(u)", user.getUid()); + systemDBus.methodcall("org.freedesktop.login1", + "/org/freedesktop/login1", + "org.freedesktop.login1.Manager", + "GetUser", + -1, "(o)", "(u)", user.getUid()); return Manager::State::Running; } catch (runtime::Exception& e) { return Manager::State::Locked; diff --git a/server/package-proxy.cpp b/server/package-proxy.cpp index 15ad13a..7e6b5a9 100644 --- a/server/package-proxy.cpp +++ b/server/package-proxy.cpp @@ -26,6 +26,8 @@ #define PRIVLEGE_PACKAGE_ADMIN "http://tizen.org/privilege/packagemanager.admin" +extern std::string KRATE_ID_PREFIX; + namespace Krate { PackageProxy::PackageProxy(KrateControlContext& ctx) : @@ -59,7 +61,7 @@ PackageProxy::PackageInfo PackageProxy::getPackageInfo(const std::string& name, free(locale); try { - runtime::User user(name); + runtime::User user(KRATE_ID_PREFIX + name); ::PackageInfo pkginfo(pkgid, user.getUid()); package.type = pkginfo.getType(); @@ -88,7 +90,7 @@ PackageProxy::PackageInfo PackageProxy::getPackageInfo(const std::string& name, std::vector PackageProxy::getPackageList(const std::string& name) { try { - runtime::User user(name); + runtime::User user(KRATE_ID_PREFIX + name); PackageManager& packman = PackageManager::instance(); return packman.getPackageList(user.getUid()); } catch (runtime::Exception& e) { @@ -101,7 +103,7 @@ std::vector PackageProxy::getPackageList(const std::string& name) int PackageProxy::install(const std::string& name, const std::string& pkgpath) { try { - runtime::User user(name); + runtime::User user(KRATE_ID_PREFIX + name); PackageManager& packman = PackageManager::instance(); packman.installPackage(pkgpath, user.getUid()); } catch (runtime::Exception& e) { @@ -115,7 +117,7 @@ int PackageProxy::install(const std::string& name, const std::string& pkgpath) int PackageProxy::uninstall(const std::string& name, const std::string& pkgid) { try { - runtime::User user(name); + runtime::User user(KRATE_ID_PREFIX + name); PackageManager& packman = PackageManager::instance(); packman.uninstallPackage(pkgid, user.getUid()); } catch (runtime::Exception& e) { diff --git a/server/server.cpp b/server/server.cpp index 54ee475..60959a3 100644 --- a/server/server.cpp +++ b/server/server.cpp @@ -19,6 +19,8 @@ #include #include +#include + #include "server.h" #include "rmi/manager.h" @@ -27,6 +29,8 @@ using namespace std::placeholders; +std::string KRATE_ID_PREFIX; + namespace { const std::string KRATE_MANAGER_ADDRESS = "/tmp/.krate.sock"; @@ -49,6 +53,8 @@ Server::Server() manager.reset(new Krate::Manager(*this)); appProxy.reset(new Krate::AppProxy(*this)); packageProxy.reset(new Krate::PackageProxy(*this)); + + KRATE_ID_PREFIX = gum_user_type_to_prefix(GUM_USERTYPE_SECURITY); } Server::~Server() -- 2.7.4