From d8278e97c604bc29b0fddbc027b69ae21bb4c776 Mon Sep 17 00:00:00 2001 From: Sungbae Yoo Date: Mon, 26 Sep 2016 17:42:58 +0900 Subject: [PATCH] Change manifest file path into each home directories Signed-off-by: Sungbae Yoo Change-Id: Ife496f7bf33b129120cf5eb6c34818e713d82e6d --- CMakeLists.txt | 4 ---- module/CMakeLists.txt | 4 ---- module/krate.cpp | 2 +- packaging/krate.spec | 2 -- server/CMakeLists.txt | 1 - server/manager.cpp | 55 ++++++++++++++++++++++++++++++++++++++++----------- 6 files changed, 45 insertions(+), 23 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c7e3422..bb54602 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -80,10 +80,6 @@ IF(NOT DEFINED SYSTEMD_UNIT_DIR) SET(SYSTEMD_UNIT_DIR "${CMAKE_INSTALL_PREFIX}/lib/systemd/system") ENDIF(NOT DEFINED SYSTEMD_UNIT_DIR) -IF(NOT DEFINED CONF_DIR) - SET(CONF_INSTALL_DIR "${SYSCONF_INSTALL_DIR}/krate") -ENDIF(NOT DEFINED CONF_DIR) - ADD_DEFINITIONS(-DUG_WAYLAND) ADD_SUBDIRECTORY(${KRATE_LIB}) diff --git a/module/CMakeLists.txt b/module/CMakeLists.txt index ab4f5e3..9a7295f 100644 --- a/module/CMakeLists.txt +++ b/module/CMakeLists.txt @@ -44,10 +44,6 @@ PKG_CHECK_MODULES(PAM_DEPS REQUIRED INCLUDE_DIRECTORIES(${PAM_INCLUDE_DIR} ${PAM_DEPS_INCLUDE_DIRS}) TARGET_LINK_LIBRARIES(${PAM_NAME} ${PAM_LIBRARY} ${PAM_DEPS_LIBRARIES} pthread) -TARGET_COMPILE_DEFINITIONS(${PAM_NAME} PRIVATE - CONF_PATH="${CONF_DIR}" -) - CONFIGURE_FILE(pam.d/systemd-user.in pam.d/systemd-user-${PROJECT_NAME}) INSTALL(TARGETS ${PAM_NAME} DESTINATION ${LIB_INSTALL_DIR}/security) diff --git a/module/krate.cpp b/module/krate.cpp index b81a901..409b12e 100644 --- a/module/krate.cpp +++ b/module/krate.cpp @@ -40,7 +40,7 @@ std::string buildKrateManifestPath(const std::string& name) { - return CONF_PATH "/" + name + ".xml"; + return "/home/" + name + "/.config/krate/krate.xml"; } std::string getKrateName(pam_handle_t* handle) diff --git a/packaging/krate.spec b/packaging/krate.spec index 62c6508..9454f00 100644 --- a/packaging/krate.spec +++ b/packaging/krate.spec @@ -41,7 +41,6 @@ krates. %attr(644,root,root) %{TZ_SYS_RO_ICONS}/krate/shortcut_icon.png %attr(644,root,root) %{TZ_SYS_RO_ICONS}/krate/indicator_icon.png %attr(644,root,root) %{TZ_SYS_RO_ICONS}/krate/notification_sub_icon.png -#%attr(700,root,root) %dir %{TZ_SYS_ETC}/krate %attr(755,root,root) %{_libdir}/security/pam_krate.so %attr(700,root,root) %{_sbindir}/krate-admin-cli %config /etc/pam.d/* @@ -67,7 +66,6 @@ krates. -DHOME_DIR=%{TZ_SYS_HOME} \ -DSYSTEMD_UNIT_DIR=%{_unitdir} \ -DPAMD_DIR=/etc/pam.d \ - -DCONF_DIR=%{TZ_SYS_ETC}/krate \ -DICON_DIR="%{TZ_SYS_RO_ICONS}/krate" \ -DAPP_INSTALL_PREFIX="%{TZ_SYS_RO_APP}" \ -DAPP_SHARE_PACKAGES_DIR="%{TZ_SYS_RO_PACKAGES}" diff --git a/server/CMakeLists.txt b/server/CMakeLists.txt index c973a82..91bc477 100644 --- a/server/CMakeLists.txt +++ b/server/CMakeLists.txt @@ -55,7 +55,6 @@ SET_TARGET_PROPERTIES(${SERVER_NAME} PROPERTIES COMPILE_FLAGS "-fPIE") SET_TARGET_PROPERTIES(${SERVER_NAME} PROPERTIES LINK_FLAGS "-pie") TARGET_COMPILE_DEFINITIONS(${SERVER_NAME} PRIVATE - CONF_PATH="${CONF_DIR}" RUN_PATH="${RUN_DIR}" ICON_PATH="${ICON_DIR}" ) diff --git a/server/manager.cpp b/server/manager.cpp index ec6f58a..ad7fb6a 100644 --- a/server/manager.cpp +++ b/server/manager.cpp @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include @@ -191,17 +192,35 @@ int packageEventHandler(uid_t target_uid, int req_id, return 0; } -void initializeCreatedKrateList() { - try { - runtime::DirectoryIterator iter(CONF_PATH "/"), end; +void initializeCreatedKrateList() +{ + const gchar *type[] = {"security", NULL}; + gchar *username; + GumUserService *service; + GumUserList *users; + GumUser *user; + + service = gum_user_service_create_sync(FALSE); + if (!service) { + return; + } + + users = gum_user_service_get_user_list_sync(service, type); + if (!users) { + return; + } - while (iter != end) { - const std::string& file = iter->getName(); - const std::string& name(file.substr(0, file.rfind(".xml"))); - createdKrateList.push_back(name); - ++iter; + for (GumUserList *src_list = users; src_list != NULL; src_list = g_list_next(src_list)) { + user = (GumUser*) src_list->data; + if (user) { + g_object_get(G_OBJECT(user), "username", &username, NULL); + createdKrateList.push_back(username); + g_free(username); } - } catch (runtime::Exception& e) {} + } + + gum_user_service_list_free(users); + g_object_unref(service); } #define NT_TITLE NOTIFICATION_TEXT_TYPE_TITLE @@ -536,13 +555,21 @@ int Manager::createKrate(const std::string& name, const std::string& manifest) maskUserServices(user); + ::tzplatform_set_user(user.getUid()); + runtime::File confDir(std::string(::tzplatform_getenv(TZ_USER_HOME)) + "/.config/krate"); + ::tzplatform_reset_user(); + if (!confDir.exists()) { + confDir.makeDirectory(true); + confDir.chmod(700); + } + manifestFile.reset(xml::Parser::parseString(manifest)); //write container author info if (!pkgId.empty()) { std::cout << manifestFile->getRootNode().getName() << std::endl; manifestFile->getRootNode().addNewChild("author").setContent(pkgId); } - manifestFile->write(CONF_PATH "/" + name + ".xml", "UTF-8", true); + manifestFile->write(confDir.getPath() + "/" + name + ".xml", "UTF-8", true); //unlock the user setKrateState(user.getUid(), 1); @@ -571,7 +598,13 @@ int Manager::removeKrate(const std::string& name) std::unique_ptr manifestFile; bool canRemove = false; - manifestFile.reset(xml::Parser::parseFile(CONF_PATH "/" + name + ".xml")); + runtime::User user(name); + ::tzplatform_set_user(user.getUid()); + std::string confPath(::tzplatform_getenv(TZ_USER_HOME)); + confPath += "/.config/krate"; + ::tzplatform_reset_user(); + + manifestFile.reset(xml::Parser::parseFile(confPath + "/" + name + ".xml")); xml::Node::NodeList authors = manifestFile->evaluate("/manifest/author"); for (const xml::Node& author : authors) { if (author.getContent() == pkgId) { -- 2.7.4