pkg_check_modules(pkgs REQUIRED
dlog
appinfo
+ libprivilege-control
)
FOREACH(flag ${pkgs_CFLAGS})
#include <linux/capability.h>
#include <dlog.h>
+#include <privilege-control.h>
#include <appinfo.h>
#undef LOG_TAG
static void
adjust_privilege(const char* appid)
{
- void* handle = dlopen("libprivilege-control.so.0", RTLD_LAZY | RTLD_LOCAL);
- if (!handle)
- {
- fprintf(stderr, "Cannot open libprivilege-control.so.0\n");
- return;
- }
-
- char* msg = 0;
- dlerror();
-
- int (*ppriv_func)(const char*) = NULL;
-
- ppriv_func = (int (*)(const char*))dlsym(handle, "set_privilege");
- msg = dlerror();
- if (msg != NULL)
- {
- fprintf(stderr, "Dlsym error: %s\n", msg);
-
- dlclose(handle);
- return;
- }
-
- int ret = (*ppriv_func)(appid);
- if (ret < 0)
- {
- fprintf(stderr, "set_privilege() returned %d\n", ret);
- }
-
- dlclose(handle);
+ set_privilege(appid);
}
extern int capset(cap_user_header_t hdrp, const cap_user_data_t datap);
return 0;
}
+
static int
-osp_do_pre_exe(const char* bin_path)
+osp_do_pre_exe(const char* app_id, const char* bin_path)
{
int ret = 0;
void* handle = NULL;
}
LOGI("dlsym() ok");
- ret = do_pre_exec_fn(NULL, bin_path);
+ ret = do_pre_exec_fn(app_id, bin_path);
if (ret < 0)
{
LOGE("Failed to do_pre_exe() (%d)", ret);
{
void* real_handle = NULL;
char* errormsg = 0;
- char packageid[MAX_PACKAGEID + 1];
- char executable_name[MAX_APP_EXECUTABLE_NAME];
- char appid[MAX_APPID];
-
- void (*pAppInfoInit)(const char*, const char*, int, char* [], int) = NULL;
- int (*pRealMain)(int, char* []) = NULL;
-
- memset(packageid, 0, sizeof(packageid));
- memset(executable_name, 0, sizeof(executable_name));
- memset(appid, 0, sizeof(appid));
+ const char* pid = NULL;
LOGI("Initializing : argc %d, argv 0x%x.", argc, argv);
//print_args(argc, argv);
- // convert package path to package name
- get_packageid_executable_name_from_path(argv[0], packageid, executable_name);
- snprintf(appid, MAX_APPID, "%s.%s", packageid, executable_name);
+ if (appinfo_is_initialized() == 0)
+ {
+ // not initialized
+ char appid[MAX_APPID];
+ char packageid[MAX_PACKAGEID + 1];
+ char executable_name[MAX_APP_EXECUTABLE_NAME];
+
+ memset(appid, 0, sizeof(appid));
+ memset(packageid, 0, sizeof(packageid));
+ memset(executable_name, 0, sizeof(executable_name));
+
+ // convert package path to package name
+ get_packageid_executable_name_from_path(argv[0], packageid, executable_name);
+ snprintf(appid, MAX_APPID, "%s.%s", packageid, executable_name);
+
+ // initialize appid
+ appinfo_init(appid, 0);
+
+ LOGI("Non-preloading initialization done.");
+ }
+
+ pid = appinfo_get_appid();
#ifdef _SECURE_LOG
- LOGI("app is %s", appid);
+ LOGI("app is %s", pid);
#endif
if (getuid() == 0)
{
// self caging
- osp_do_pre_exe(argv[0]);
+ osp_do_pre_exe(pid, argv[0]);
// adjust privilege
- adjust_privilege(appid);
+ adjust_privilege(pid);
}
adjust_capability();
- // initialize appid
- appinfo_init(appid, 0);
appinfo_set_argv(argc, argv);
// actual loading
return -1;
}
- pAppInfoInit = (void (*)(const char*, const char*, int, char*[], int)) dlsym(real_handle, "InitAppInfo");
+ void (*pAppInfoInit)() = NULL;
+ pAppInfoInit = (void (*)()) dlsym(real_handle, "AppInfo_Update");
errormsg = dlerror();
if (errormsg != NULL)
{
return -1;
}
+ int (*pRealMain)(int, char* []) = NULL;
pRealMain = (int (*)(int, char*[])) dlsym(real_handle, "OspMain");
errormsg = dlerror();
if (errormsg != NULL)
}
// actual initialization
- (*pAppInfoInit)(packageid, executable_name, argc, argv, -1);
+ (*pAppInfoInit)();
(*pRealMain)(argc, argv);
LOGI("Osp application terminates.");
char executable_name[MAX_APP_EXECUTABLE_NAME];
char appid[MAX_APPID];
- void (*pAppInfoInit)(const char*, const char*, int, char* [], int) = NULL;
int (*pRealMain)(int, char* []) = NULL;
memset(packageid, 0, sizeof(packageid));
return -1;
}
- pAppInfoInit = (void (*)(const char*, const char*, int, char*[], int)) dlsym(real_handle, "InitAppInfo");
+ void (*pAppInfoInit)() = NULL;
+ pAppInfoInit = (void (*)()) dlsym(real_handle, "AppInfo_Update");
errormsg = dlerror();
if (errormsg != NULL)
{
}
// actual initialization
- (*pAppInfoInit)(packageid, executable_name, argc, argv, -1);
+ (*pAppInfoInit)();
(*pRealMain)(argc, argv);
LOGI("Osp application terminates.");
#include <linux/capability.h>
#include <dlog.h>
+#include <privilege-control.h>
#include <appinfo.h>
#undef LOG_TAG
static void
adjust_privilege(const char* appid)
{
- void* handle = dlopen("libprivilege-control.so.0", RTLD_LAZY | RTLD_LOCAL);
- if (!handle)
- {
- fprintf(stderr, "Cannot open libprivilege-control.so.0\n");
- return;
- }
-
- char* msg = 0;
- dlerror();
-
- int (*ppriv_func)(const char*) = NULL;
-
- ppriv_func = (int (*)(const char*))dlsym(handle, "set_privilege");
- msg = dlerror();
- if (msg != NULL)
- {
- fprintf(stderr, "Dlsym error: %s\n", msg);
-
- dlclose(handle);
- return;
- }
-
- int ret = (*ppriv_func)(appid);
- if (ret < 0)
- {
- fprintf(stderr, "set_privilege() returned %d\n", ret);
- }
-
- dlclose(handle);
+ set_privilege(appid);
}
extern int capset(cap_user_header_t hdrp, const cap_user_data_t datap);
}
static int
-osp_do_pre_exe(const char* bin_path)
+osp_do_pre_exe(const char* app_id, const char* bin_path)
{
int ret = 0;
void* handle = NULL;
}
LOGD("dlsym() ok");
- ret = do_pre_exec_fn(NULL, bin_path);
+ ret = do_pre_exec_fn(app_id, bin_path);
if (ret < 0)
{
LOGE("Failed to do_pre_exe() (%d)", ret);
{
void* handle = NULL;
char* errormsg = 0;
- char packageid[MAX_PACKAGEID + 1];
- char executable_name[MAX_APP_EXECUTABLE_NAME];
- char appid[MAX_APPID];
-
- void (*pAppInfoInit)(const char*, const char*, int, char* [], int) = NULL;
- int (*pRealMain)(int, char* []) = NULL;
-
- memset(packageid, 0, sizeof(packageid));
- memset(executable_name, 0, sizeof(executable_name));
- memset(appid, 0, sizeof(appid));
+ const char* pid = NULL;
LOGI("Initializeing : argc %d, argv 0x%x.", argc, argv);
//print_args(argc, argv);
- // convert package path to package name
- get_packageid_executable_name_from_path(argv[0], packageid, executable_name);
- snprintf(appid, MAX_APPID, "%s.%s", packageid, executable_name);
+ if (appinfo_is_initialized() == 0)
+ {
+ // not initialized
+ char packageid[MAX_PACKAGEID + 1];
+ char executable_name[MAX_APP_EXECUTABLE_NAME];
+ char appid[MAX_APPID];
+
+ memset(packageid, 0, sizeof(packageid));
+ memset(executable_name, 0, sizeof(executable_name));
+ memset(appid, 0, sizeof(appid));
+
+ // convert package path to package name
+ get_packageid_executable_name_from_path(argv[0], packageid, executable_name);
+ snprintf(appid, MAX_APPID, "%s.%s", packageid, executable_name);
+
+ // initialize appid
+ appinfo_init(appid, 0);
+
+ LOGI("Non-preloading initialization done.");
+ }
+
+ pid = appinfo_get_appid();
#ifdef _SECURE_LOG
- LOGI("app is %s", appid);
+ LOGI("app is %s", pid);
#endif
if (getuid() == 0)
{
// self caging
- osp_do_pre_exe(argv[0]);
+ osp_do_pre_exe(pid, argv[0]);
// adjust privilege
- adjust_privilege(appid);
+ adjust_privilege(pid);
}
adjust_capability();
- // initialize appid
- appinfo_init(appid, 0);
appinfo_set_argv(argc, argv);
// actual loading
return -1;
}
- pAppInfoInit = (void (*)(const char*, const char*, int, char*[], int)) dlsym(so_handle, "InitAppInfo");
+ void (*pAppInfoInit)() = NULL;
+ pAppInfoInit = (void (*)()) dlsym(so_handle, "AppInfo_Update");
errormsg = dlerror();
if (errormsg != NULL)
{
return -1;
}
+ int (*pRealMain)(int, char* []) = NULL;
pRealMain = (int (*)(int, char*[])) dlsym(handle, "OspMain");
errormsg = dlerror();
if (errormsg != NULL)
}
// actual initialization
- (*pAppInfoInit)(packageid, executable_name, argc, argv, -1);
+ (*pAppInfoInit)();
(*pRealMain)(argc, argv);
LOGI("Osp application terminates.");
Name: osp-loader
Summary: osp application loader
Version: 1.2.2.1
-Release: 1
+Release: 2
Group: TO_BE/FILLED_IN
License: Apache-2.0
Source0: %{name}-%{version}.tar.gz
BuildRequires: cmake
BuildRequires: pkgconfig(dlog)
BuildRequires: pkgconfig(appinfo) >= 0.1.0
-Requires: libprivilege-control
+BuildRequires: pkgconfig(libprivilege-control)
# runtime requires
Requires: osp-env-config