#include <algorithm>
#include <string>
+#include <pwd.h>
+#include <grp.h>
+#include <sys/stat.h>
+#include <unistd.h>
+
#include "common.h"
#ifdef LOG_TAG
#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)
{
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, "_");
});
}
if (FileNotExist(nicorlib))
{
crossgen(corlib.c_str(), nullptr);
- smack_(nicorlib.c_str());
+ smack_(nicorlib.c_str(), "_");
}
if (!FileNotExist(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();
{
const char* args[] = {
CHKSMACK,
- "-a", "_",
+ "-a", label,
dll_path,
nullptr
};
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);
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());
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;
}