diff options
author | Cho Woong Suk <ws77.cho@samsung.com> | 2017-04-11 10:18:16 +0900 |
---|---|---|
committer | Cho Woong Suk <ws77.cho@samsung.com> | 2017-04-11 10:18:16 +0900 |
commit | 2cb2f43727ac65ecff5a9725feb132c9f9619291 (patch) | |
tree | 0844a840cd3caf513f79ceb2d66c2bf0e18e8360 | |
parent | 3cf211da1beb8cafd4ad8a94f3827caa673a63bf (diff) | |
download | launcher-2cb2f43727ac65ecff5a9725feb132c9f9619291.tar.gz launcher-2cb2f43727ac65ecff5a9725feb132c9f9619291.tar.bz2 launcher-2cb2f43727ac65ecff5a9725feb132c9f9619291.zip |
change smack and owner for generated ni filesubmit/tizen/20170411.013258accepted/tizen/unified/20170411.035136
Change-Id: Ia4c992b2984fe0b87e77bb06b031c67dcbbb8c9c
-rw-r--r-- | NativeLauncher/installer-plugin/common.cc | 37 |
1 files changed, 28 insertions, 9 deletions
diff --git a/NativeLauncher/installer-plugin/common.cc b/NativeLauncher/installer-plugin/common.cc index 5d1306c..d2c9c3f 100644 --- a/NativeLauncher/installer-plugin/common.cc +++ b/NativeLauncher/installer-plugin/common.cc @@ -29,6 +29,11 @@ #include <algorithm> #include <string> +#include <pwd.h> +#include <grp.h> +#include <sys/stat.h> +#include <unistd.h> + #include "common.h" #ifdef LOG_TAG @@ -58,7 +63,7 @@ static const char* JITPath = __STR(RUNTIME_DIR)"/libclrjit.so"; #undef __XSTR static void crossgen(const char* dll_path, const char* app_path); -static void smack_(const char* dll_path); +static void smack_(const char* dll_path, const char* label); std::string Replace(std::string &str, const std::string& from, const std::string& to) { @@ -79,14 +84,14 @@ void create_ni_platform() if (FileNotExist(nicorlib)) { crossgen(corlib.c_str(), nullptr); - smack_(nicorlib.c_str()); + smack_(nicorlib.c_str(), "_"); } const char* platform_dirs[] = {RuntimeDir, DeviceAPIDir, "/usr/bin"}; const char* ignores[] = {corlib.c_str()}; create_ni_under_dirs(platform_dirs, 3, ignores, 1, [](const char* ni){ - smack_(ni); + smack_(ni, "_"); }); } @@ -98,7 +103,7 @@ void create_ni_select(const char* dll_path) if (FileNotExist(nicorlib)) { crossgen(corlib.c_str(), nullptr); - smack_(nicorlib.c_str()); + smack_(nicorlib.c_str(), "_"); } if (!FileNotExist(dll_path)) @@ -109,11 +114,11 @@ void create_ni_select(const char* dll_path) crossgen(dll_path, nullptr); else printf("Already [%s] file is exist\n", ni_path.c_str()); - smack_(ni_path.c_str()); + smack_(ni_path.c_str(), "_"); } } -static void smack_(const char* dll_path) +static void smack_(const char* dll_path, const char* label) { static const char* CHKSMACK = "/usr/bin/chsmack"; pid_t pid = fork(); @@ -135,7 +140,7 @@ static void smack_(const char* dll_path) { const char* args[] = { CHKSMACK, - "-a", "_", + "-a", label, dll_path, nullptr }; @@ -259,7 +264,8 @@ static int get_root_path(const char *pkgid, std::string& root_path) static bool NIExist(const std::string& path, std::string& ni) { static const char* possible_exts[] = { - ".ni.dll", ".NI.dll", ".NI.DLL", ".ni.DLL" + ".ni.dll", ".NI.dll", ".NI.DLL", ".ni.DLL", + ".ni.exe", ".NI.exe", ".NI.EXE", ".ni.EXE" }; std::string fname = path.substr(0, path.size() - 4); @@ -302,6 +308,14 @@ void create_ni_under_dirs(const char* root_paths[], int count, const char* ignor crossgen(path, app_paths.c_str()); if (NIExist(path, ni)) { + // change owner and groups for generated ni file. + struct stat info; + if (!stat(path, &info)) { + if (chown(ni.c_str(), info.st_uid, info.st_gid) == -1) { + _ERR("Failed to change owner and group name"); + } + } + if (cb != nullptr) { cb(ni.c_str()); @@ -346,7 +360,12 @@ int create_ni_under_pkg_root(const char* pkg_name) bindir.c_str(), libdir.c_str() }; - create_ni_under_dirs(paths, 2); + + // change smack label for generated ni file. + std::string label = "User::Pkg::" + std::string(pkg_name) + "::RO"; + create_ni_under_dirs(paths, 2, [label](const char* ni){ + smack_(ni, label.c_str()); + }); return 0; } |