SET_TARGET_PROPERTIES(aul PROPERTIES VERSION ${VERSION})
# launchpad(old avatar) daemon
-SET(AVATAR_NAME "launchpad_preloading_preinitializing_daemon")
-IF (WITH_WAYLAND)
-add_executable(${AVATAR_NAME}
- launchpad_src/launchpad.c
+SET(AM_SESSION_AGENT_NAME "amd_session_agent")
+add_executable(${AM_SESSION_AGENT_NAME}
+ am_session_agent/agent.c
)
-ELSE(WITH_WAYLAND)
-add_executable(${AVATAR_NAME}
- launchpad_src/launchpad.c
- launchpad_src/util_x.c
- )
-ENDIF(WITH_WAYLAND)
-
MESSAGE(" "${pkgs_LDFLAGS})
-target_link_libraries(${AVATAR_NAME} aul_mods aul ${pkgs_LDFLAGS} ${LIB_DL})
-set_target_properties(${AVATAR_NAME}
+TARGET_LINK_LIBRARIES(${AM_SESSION_AGENT_NAME} ${PKGS_LDFLAGS} aul aul_mods)
+SET_TARGET_PROPERTIES(${AM_SESSION_AGENT_NAME} PROPERTIES COMPILE_FLAGS "${EXTRA_CFLAGS}")
+
+set_target_properties(${AM_SESSION_AGENT_NAME}
PROPERTIES SKIP_BUILD_RPATH true
) # remove rpath option that is automatically generated by cmake.
### Install ###
INSTALL(TARGETS aul DESTINATION ${LIB_INSTALL_DIR} COMPONENT RuntimeLibraries)
-INSTALL(TARGETS ${AVATAR_NAME} DESTINATION bin)
+INSTALL(TARGETS ${AM_SESSION_AGENT_NAME} DESTINATION bin)
INSTALL(TARGETS amd DESTINATION bin)
INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/aul.h DESTINATION include/aul)
GSList *app_status_info_list = NULL;
-int _add_app_status_info_list(char *appid, int pid)
+int _add_app_status_info_list(char *appid, int pid, uid_t uid)
{
GSList *iter = NULL;
app_status_info_t *info_t = NULL;
strncpy(info_t->appid, appid, MAX_PACKAGE_STR_SIZE-1);
info_t->status = STATUS_LAUNCHING;
info_t->pid = pid;
+ info_t->user = uid;
app_status_info_list = g_slist_append(app_status_info_list, info_t);
for (iter = app_status_info_list; iter != NULL; iter = g_slist_next(iter))
return 0;
}
-int _update_app_status_info_list(int pid, int status)
+int _update_app_status_info_list(int pid, int status, uid_t uid)
{
GSList *iter = NULL;
app_status_info_t *info_t = NULL;
for (iter = app_status_info_list; iter != NULL; iter = g_slist_next(iter))
{
info_t = (app_status_info_t *)iter->data;
- if(pid == info_t->pid) {
+ if((pid == info_t->pid) && ((info_t->user == uid) || (info_t->user == 0))) {
info_t->status = status;
break;
}
return 0;
}
-int _remove_app_status_info_list(int pid)
+int _remove_app_status_info_list(int pid, uid_t uid)
{
GSList *iter = NULL;
app_status_info_t *info_t = NULL;
for (iter = app_status_info_list; iter != NULL; iter = g_slist_next(iter))
{
info_t = (app_status_info_t *)iter->data;
- if(pid == info_t->pid) {
+ if((pid == info_t->pid) && ((info_t->user == uid) || (info_t->user == 0))) {
app_status_info_list = g_slist_remove(app_status_info_list, info_t);
free(info_t);
break;
char *noti_string;
char *type_string;
char *appid;
+ char *uid_string;
+ uid_t uid;
char *saveptr;
pkgmgrinfo_appinfo_h handle;
struct appinfomgr *cf = (struct appinfomgr *)data;
}
SECURE_LOGD("noti_string : %s",noti_string);
-
type_string = strtok_r(noti_string, ":", &saveptr);
appid = strtok_r(NULL, ":", &saveptr);
+ uid_string = strtok_r(NULL, ":", &saveptr);
+ uid = atoi(uid_string);
+ _D("type_string: [%s]\n", type_string);
+ _D("appid: [%s]\n", appid);
+ _D("uid: %d\n", uid);
if ( strncmp(type_string, "create", 6) == 0) {
- ret = pkgmgrinfo_appinfo_get_appinfo(appid, &handle);
+ ret = pkgmgrinfo_appinfo_get_appinfo_user(appid, uid, &handle);
if(ret < 0) {
_E("pkgmgrinfo_appinfo_get_appinfo fail");
}
} else if (strncmp(type_string, "update", 6) == 0){
/*REMOVE EXISTING ENTRY & CREATE AGAIN*/
if (g_hash_table_remove(cf->tbl, appid)){
- if (pkgmgrinfo_appinfo_get_appinfo(appid, &handle) == PMINFO_R_OK){
+ if (pkgmgrinfo_appinfo_get_appinfo_user(appid, uid, &handle) == PMINFO_R_OK){
__app_info_insert_handler(handle, data);
pkgmgrinfo_appinfo_destroy_appinfo(handle);
}
pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
}
-const struct appinfo *appinfo_find(struct appinfomgr *cf, const char *filename)
+const struct appinfo *appinfo_find(uid_t caller_uid, const char *appid)
{
- if (!cf || !filename || !*filename) {
- errno = EINVAL;
- _E("appinfo find: %s", strerror(errno));
- return NULL;
+ struct appinfo *res;
+ gboolean r;
+ bool multiple;
+ bool preload;
+ bool onboot;
+ char *exec;
+ bool restart;
+ char *pkgid;
+ char *type;
+ pkgmgrinfo_app_hwacceleration hwacc;
+ pkgmgrinfo_appinfo_h handle;
+ pkgmgrinfo_app_component component;
+ pkgmgrinfo_permission_type permission;
+ int ret;
+
+ ret = pkgmgrinfo_appinfo_get_appinfo( appid, &handle);
+ if (ret != PMINFO_R_OK){
+ ret = pkgmgrinfo_appinfo_get_appinfo_user(appid , caller_uid , &handle);
}
- return g_hash_table_lookup(cf->tbl, FILENAME(filename));
+ res = calloc(1, sizeof(*res));
+ if (!res) {
+ _E("create appinfo: %s", strerror(errno));
+ return -1;
+ }
+
+ memset(res, 0, sizeof(struct appinfo));
+
+ res->val[_AI_FILE] = strdup(appid);
+ if (!res->val[_AI_FILE]) {
+ _E("create appinfo: %s", strerror(errno));
+ _free_appinfo(res);
+ return -1;
+ }
+
+ res->val[_AI_NAME] = strdup(appid); //TODO :
+
+ pkgmgrinfo_appinfo_get_component(handle, &component);
+ if(component == PMINFO_UI_APP) {
+ res->val[_AI_COMP] = strdup("ui"); //TODO :
+
+ r = pkgmgrinfo_appinfo_is_multiple(handle, &multiple);
+ if(multiple == true)
+ res->val[_AI_MULTI] = strdup("true");
+ else res->val[_AI_MULTI] = strdup("false");
+
+ r = pkgmgrinfo_appinfo_is_preload(handle, &preload);
+ if (preload == false) {
+ res->val[_AI_PRELOAD] = strdup("false");
+ } else {
+ res->val[_AI_PRELOAD] = strdup("true");
+ }
+
+ if(gles == 0) {
+ res->val[_AI_HWACC] = strdup("NOT_USE");
+ } else {
+
+ r = pkgmgrinfo_appinfo_get_hwacceleration(handle, &hwacc);
+ if (hwacc == PMINFO_HWACCELERATION_USE_GL) {
+ res->val[_AI_HWACC] = strdup("USE");
+ } else if (hwacc == PMINFO_HWACCELERATION_USE_SYSTEM_SETTING) {
+ res->val[_AI_HWACC] = strdup("SYS");
+ } else {
+ res->val[_AI_HWACC] = strdup("NOT_USE");
+ }
+ }
+ } else {
+ res->val[_AI_COMP] = strdup("svc");
+
+ r = pkgmgrinfo_appinfo_is_onboot(handle, &onboot);
+ if(onboot == true)
+ res->val[_AI_ONBOOT] = strdup("true");
+ else res->val[_AI_ONBOOT] = strdup("false");
+
+ r = pkgmgrinfo_appinfo_is_autorestart(handle, &restart);
+ if(restart == true)
+ res->val[_AI_RESTART] = strdup("true");
+ else res->val[_AI_RESTART] = strdup("false");
+ }
+
+ r = pkgmgrinfo_appinfo_get_exec(handle, &exec);
+ res->val[_AI_EXEC] = strdup(exec);
+
+ r = pkgmgrinfo_appinfo_get_apptype(handle, &type);
+ if(strncmp(type, "capp", 4) == 0 ) {
+ res->val[_AI_TYPE] = strdup("rpm");
+ } else if (strncmp(type, "c++app", 6) == 0 || strncmp(type, "ospapp", 6) == 0) {
+ res->val[_AI_TYPE] = strdup("tpk");
+ } else if (strncmp(type, "webapp", 6) == 0) {
+ res->val[_AI_TYPE] = strdup("wgt");
+ }
+
+ r = pkgmgrinfo_appinfo_get_permission_type(handle, &permission);
+ if (permission == PMINFO_PERMISSION_SIGNATURE) {
+ res->val[_AI_PERM] = strdup("signature");
+ } else if (permission == PMINFO_PERMISSION_PRIVILEGE) {
+ res->val[_AI_PERM] = strdup("privilege");
+ } else {
+ res->val[_AI_PERM] = strdup("normal");
+ }
+
+ r = pkgmgrinfo_appinfo_get_pkgid(handle, &pkgid);
+ res->val[_AI_PKGID] = strdup(pkgid);
+
+ SECURE_LOGD("%s : %s : %s", res->val[_AI_FILE], res->val[_AI_COMP], res->val[_AI_TYPE]);
+
+ return res;
}
const char *appinfo_get_value(const struct appinfo *c, enum appinfo_type type)
const struct appinfo *appinfo_insert(struct appinfomgr *cf, const char *filename);
void appinfo_delete(struct appinfomgr *cf, const char *filename);
-const struct appinfo *appinfo_find(struct appinfomgr *cf, const char *filename);
+const struct appinfo *appinfo_find(uid_t caller_uid, const char *appid);
const char *appinfo_get_value(const struct appinfo *c, enum appinfo_type type);
const char *appinfo_get_filename(const struct appinfo *c);
int appinfo_get_boolean(const struct appinfo *c, enum appinfo_type type);
#define INIT_PID 1
#define AUL_PR_NAME 16
+
+// SDK related defines
#define PATH_APP_ROOT tzplatform_getenv(TZ_USER_APP)
#define PATH_DATA "/data"
#define SDK_CODE_COVERAGE "CODE_COVERAGE"
}
}
-#define USE_ENGINE(engine) setenv("ELM_ENGINE", engine, 1);
static void _set_env(const char *appid, bundle * kb, const char *hwacc)
{
signal(SIGTERM, SIG_DFL);
signal(SIGCHLD, SIG_DFL);
- ai = appinfo_find(_laf, appid);
+ ai = appinfo_find(getuid(), appid);
app_path = appinfo_get_value(ai, AIT_EXEC);
pkg_type = appinfo_get_value(ai, AIT_TYPE);
const char *app_path = NULL;
const char *pkg_type = NULL;
int pid = -1;
- char tmp_pid[MAX_PID_STR_BUFSZ];
+ char tmpbuf[MAX_PID_STR_BUFSZ];
const char *hwacc;
const char *permission;
const char *pkgid;
int pad_pid = LAUNCHPAD_PID;
bool consented = true;
- snprintf(tmp_pid, MAX_PID_STR_BUFSZ, "%d", caller_pid);
- bundle_add(kb, AUL_K_CALLER_PID, tmp_pid);
+ snprintf(tmpbuf, MAX_PID_STR_BUFSZ, "%d", caller_pid);
+ bundle_add(kb, AUL_K_CALLER_PID, tmpbuf);
+
+ snprintf(tmpbuf, MAX_PID_STR_BUFSZ, "%d", caller_uid);
+ bundle_add(kb, AUL_K_CALLER_UID, tmpbuf);
+
+ _D("_start_app: caller pid=%d uid=%d",caller_pid,caller_uid);
if (cmd == APP_START_RES)
bundle_add(kb, AUL_K_WAIT_RESULT, "1");
bundle_add(kb, AUL_K_CALLER_APPID, caller_appid);
}
- ai = appinfo_find(_laf, appid);
+ ai = appinfo_find(caller_uid, appid);
if(ai == NULL) {
__real_send(fd, -1);
appid = PRIVACY_POPUP;
bundle_del(kb, AUL_K_PKG_NAME);
bundle_add(kb, AUL_K_PKG_NAME, appid);
- ai = appinfo_find(_laf, appid);
+ ai = appinfo_find(caller_uid, appid);
}
}
if(permission && strncmp(permission, "signature", 9) == 0 ) {
if(caller_uid != 0 && (cmd == APP_START || cmd == APP_START_RES)){
const struct appinfo *caller_ai;
- caller_ai = appinfo_find(_laf, caller_appid);
+ caller_ai = appinfo_find(caller_uid, caller_appid);
preload = appinfo_get_value(caller_ai, AIT_PRELOAD);
if( preload && strncmp(preload, "true", 4) != 0 ) {
pkgmgrinfo_pkginfo_compare_app_cert_info(caller_appid, appid, &compare_result);
if (componet && strncmp(componet, "ui", 2) == 0) {
multiple = appinfo_get_value(ai, AIT_MULTI);
if (!multiple || strncmp(multiple, "false", 5) == 0) {
- pid = _status_app_is_running_v2(appid);
+ pid = _status_app_is_running(appid, caller_uid);
}
if (pid > 0) {
bundle_add(kb, AUL_K_HWACC, hwacc);
bundle_add(kb, AUL_K_EXEC, app_path);
bundle_add(kb, AUL_K_PACKAGETYPE, pkg_type);
- if(bundle_get_type(kb, AUL_K_SDK) != BUNDLE_TYPE_NONE) {
- pad_pid = DEBUG_LAUNCHPAD_PID;
- } else if(strncmp(pkg_type, "wgt", 3) == 0) {
- pad_pid = WEB_LAUNCHPAD_PID;
- }
- pid = app_send_cmd(pad_pid, cmd, kb);
- if(pid == -3) {
- pid = -ENOLAUNCHPAD;
- }
- //_add_cgroup(_lcg, appid, pid);
+ pid = app_agent_send_cmd(caller_uid, cmd, kb);
+
}
} else if (componet && strncmp(componet, "svc", 3) == 0) {
- pid = _status_app_is_running_v2(appid);
+ pid = _status_app_is_running_v2(caller_uid,appid);
if (pid > 0) {
if ((ret = __nofork_processing(cmd, pid, kb, fd)) < 0) {
pid = ret;
__real_send(fd, pid);
if(pid > 0) {
- _status_add_app_info_list(appid, app_path, pid, pad_pid);
+ _status_add_app_info_list(appid, app_path, pid, pad_pid, caller_uid);
ret = ac_server_check_launch_privilege(appid, appinfo_get_value(ai, AIT_TYPE), pid);
return ret != AC_R_ERROR ? pid : -1;
}
typedef struct _r_app_info_t{
char pkg_name[MAX_PACKAGE_STR_SIZE];
int pid;
+ uid_t user;
} r_app_info_t;
GSList *r_app_info_list = NULL;
static void __vconf_cb(keynode_t *key, void *data);
-static int __app_dead_handler(int pid, void *data);
static int __init();
extern int _status_init(struct amdmgr* amd);
return 0;
}
-static int __remove_item_running_list(int pid)
+static int __remove_item_running_list(int pid, uid_t user)
{
r_app_info_t *info_t = NULL;
GSList *iter = NULL;
for (iter = r_app_info_list; iter != NULL; iter = g_slist_next(iter))
{
info_t = (r_app_info_t *)iter->data;
- if(pid == info_t->pid) {
+ if( (pid == info_t->pid) && (user == info_t->user || 0 == info_t->pid )) {
r_app_info_list = g_slist_remove(r_app_info_list, info_t);
free(info_t);
break;
int limit;
char *pkgname;
int pid;
-
+ uid_t user;
item_pkt_t *item;
item = (item_pkt_t *)user_data;
pkgname = item->appid;
pid = item->pid;
-
+ user = item->uid;
if (vconf_get_int(VCONFKEY_SETAPPL_DEVOPTION_BGPROCESS, &limit) != 0){
_E("Unable to get VCONFKEY_SETAPPL_DEVOPTION_BGPROCESS\n");
}
for (iter = r_app_info_list; iter != NULL; iter = g_slist_next(iter))
{
info_t = (r_app_info_t *)iter->data;
- if(pid == info_t->pid) {
+ if((pid == info_t->pid) && (user == info_t->user)) {
found = 1;
r_app_info_list = g_slist_remove(r_app_info_list, info_t);
r_app_info_list = g_slist_append(r_app_info_list, info_t);
}
}
-static int __app_dead_handler(int pid, void *data)
+int __app_dead_handler(int pid)
{
+ // this function was called in single user mode as a callback to aul_listen_app_dead_signal
+ // but in multiuser mode, AMD daemon can't listen any more on DBUS system to catch those events
+ // AMD Agents must connect to AMD Daemon to signal a dead process
_unregister_key_event(pid);
- __remove_item_running_list(pid);
- _status_remove_app_info_list(pid);
+ __remove_item_running_list(pid, getuid());
+ _status_remove_app_info_list(pid, getuid());
return 0;
}
.cg = NULL
};
- int ret;
+ int ret=0;
ecore_init();
evas_init();
#endif
if (vconf_notify_key_changed(VCONFKEY_SETAPPL_DEVOPTION_BGPROCESS, __vconf_cb, NULL) != 0)
_E("Unable to register callback for VCONFKEY_SETAPPL_DEVOPTION_BGPROCESS\n");
- aul_listen_app_dead_signal(__app_dead_handler, NULL);
_start_services(&amd);
static int __send_result_to_client(int fd, int res);
static gboolean __request_handler(gpointer data);
+extern int __app_dead_handler(int pid);
+
static int __send_result_to_client(int fd, int res)
{
if (send(fd, &res, sizeof(int), MSG_NOSIGNAL) < 0) {
if (pkg_name == NULL)
return -1;
- if ((cr->uid != 0) && (cr->uid != INHOUSE_UID)) {
- _E("reject by security rule, your uid is %u\n", cr->uid);
- return -1;
- }
-
pid = atoi(pkg_name);
if (pid <= 1) {
_E("invalid pid");
char *appid = NULL;
char *app_path = NULL;
struct appinfo *ai;
- app_pkt_t *pkt = (app_pkt_t *)user_data;
+ pkt_t *pkt_uid = (pkt_t *)user_data;
- if (!pkt)
+ if (!pkt_uid)
return FALSE;
- kb = bundle_decode(pkt->data, pkt->len);
+ kb = bundle_decode(pkt_uid->pkt->data, pkt_uid->pkt->len);
appid = (char *)bundle_get_val(kb, AUL_K_PKG_NAME);
- ai = (struct appinfo *)appinfo_find(_raf, appid);
+ ai = (struct appinfo *)appinfo_find(pkt_uid->caller_uid, appid);
app_path = (char *)appinfo_get_value(ai, AIT_EXEC);
memset((void *)&rec, 0, sizeof(rec));
rec.pkg_name = appid;
rec.app_path = app_path;
- if(pkt->len > 0) {
- rec.arg = (char *)pkt->data;
+ if(pkt_uid->pkt->len > 0) {
+ rec.arg = (char *)pkt_uid->pkt->data;
}
SECURE_LOGD("add rua history %s %s", rec.pkg_name, rec.app_path);
if (kb != NULL)
bundle_free(kb);
- free(pkt);
+ free(pkt_uid->pkt);
+ free(pkt_uid);
return FALSE;
}
return 0;
}
-static int __release_srv(const char *filename)
+static int __release_srv(uid_t caller_uid, const char *filename)
{
int r;
const struct appinfo *ai;
if (r == -1)
return -1;
- ai = (struct appinfo *)appinfo_find(_raf, filename);
+ ai = (struct appinfo *)appinfo_find(caller_uid, filename);
if (!ai) {
SECURE_LOGE("release service: '%s' not found", filename);
return -1;
return 0;
}
+static int __handle_dead_signal(bundle* kb,int clifd, struct ucred * pcr) {
+ int ret=-1;
+ const char *pid_str;
+ int pid=0;
+
+ /* check the credentials from the caller: must be the amd agent */
+ // exe of calling process
+ char * caller=__proc_get_exe_bypid(pcr->pid);
+ if (!caller) {
+ _D("handle_dead_signal: unable to get caller exe");
+ return -1;
+ }
+
+ if (strcmp(caller,"/usr/bin/amd_session_agent")) {
+ _D("handle_dead_signal: caller is not amd session agent");
+ free(caller);
+ return -1;
+ }
+ free(caller);
+
+ /* get app pid from bundle */
+ pid_str = bundle_get_val(kb, AUL_K_PID);
+ if(!pid_str)
+ return -1;
+
+ pid=atoi(pid_str);
+ if (pid<=1)
+ return -1;
+
+ _D("APP_DEAD_SIGNAL : %d",pid);
+
+ ret=__app_dead_handler(pid);
+
+ return ret;
+}
+
static gboolean __request_handler(gpointer data)
{
GPollFD *gpollfd = (GPollFD *) data;
int pid;
bundle *kb = NULL;
item_pkt_t *item;
+ pkt_t *pkt_uid;
if ((pkt = __app_recv_raw(fd, &clifd, &cr)) == NULL) {
_E("recv error");
if(ret > 0) {
item = calloc(1, sizeof(item_pkt_t));
item->pid = ret;
+ item->uid = cr.uid;
strncpy(item->appid, appid, 511);
free_pkt = 0;
- g_timeout_add(1000, __add_history_handler, pkt);
+ pkt_uid = calloc(1, sizeof(pkt_t));
+ pkt_uid->caller_uid = cr.uid;
+ pkt_uid->pkt = pkt;
+
+ g_timeout_add(1000, __add_history_handler, pkt_uid);
g_timeout_add(1200, __add_item_running_list, item);
}
__real_send(clifd, ret);
break;
case APP_RUNNING_INFO:
- _status_send_running_appinfo_v2(clifd);
+ _status_send_running_appinfo(clifd);
break;
case APP_IS_RUNNING:
appid = malloc(MAX_PACKAGE_STR_SIZE);
strncpy(appid, (const char*)pkt->data, MAX_PACKAGE_STR_SIZE-1);
- ret = _status_app_is_running_v2(appid);
+ ret = _status_app_is_running(appid, cr.uid);
SECURE_LOGD("APP_IS_RUNNING : %s : %d",appid, ret);
__send_result_to_client(clifd, ret);
free(appid);
break;
case APP_STATUS_UPDATE:
status = (int *)pkt->data;
- ret = _status_update_app_info_list(cr.pid, *status);
+ ret = _status_update_app_info_list(cr.pid, *status, cr.uid);
//__send_result_to_client(clifd, ret);
close(clifd);
break;
case APP_RELEASED:
appid = malloc(MAX_PACKAGE_STR_SIZE);
strncpy(appid, (const char*)pkt->data, MAX_PACKAGE_STR_SIZE-1);
- ret = __release_srv(appid);
+ ret = __release_srv(cr.uid,appid);
__send_result_to_client(clifd, ret);
free(appid);
break;
ret = 0;
__send_result_to_client(clifd, ret);
break;
+ case APP_DEAD_SIGNAL:
+ kb = bundle_decode(pkt->data, pkt->len);
+ ret=__handle_dead_signal(kb,clifd,&cr);
+ break;
default:
_E("no support packet");
close(clifd);
struct appinfomgr *_saf = NULL;
-int _status_add_app_info_list(char *appid, char *app_path, int pid, int pad_pid)
+int _status_add_app_info_list(char *appid, char *app_path, int pid, int pad_pid, uid_t uid)
{
GSList *iter = NULL;
app_status_info_t *info_t = NULL;
{
info_t = (app_status_info_t *)iter->data;
if(pid == info_t->pid) {
- return 0;
+ if(uid == info_t->user)
+ return 0;
+ else {
+ //PID is unique so if it is exist but user value is not correct remove it.
+ app_status_info_list = g_slist_remove(app_status_info_list, info_t);
+ free(info_t);
+ break;
+ }
}
}
info_t->status = STATUS_LAUNCHING;
info_t->pid = pid;
info_t->pad_pid = pad_pid;
+ info_t->user = uid;
app_status_info_list = g_slist_append(app_status_info_list, info_t);
for (iter = app_status_info_list; iter != NULL; iter = g_slist_next(iter))
{
info_t = (app_status_info_t *)iter->data;
- //SECURE_LOGD("%s, %d, %d", info_t->appid, info_t->pid, info_t->status);
+ SECURE_LOGD(" [%d] : %s, %d, %d", info_t->user, info_t->appid, info_t->pid, info_t->status);
}
return 0;
return ECORE_CALLBACK_CANCEL;
}
-int _status_update_app_info_list(int pid, int status)
+int _status_update_app_info_list(int pid, int status, uid_t uid)
{
GSList *iter = NULL;
app_status_info_t *info_t = NULL;
for (iter = app_status_info_list; iter != NULL; iter = g_slist_next(iter))
{
info_t = (app_status_info_t *)iter->data;
- if(pid == info_t->pid) {
+ if((pid == info_t->pid) && ((info_t->user == uid) || (info_t->user == 0))) {
info_t->status = status;
if(status == STATUS_DYING) {
if(info_t->pad_pid != DEBUG_LAUNCHPAD_PID)
return 0;
}
-int _status_remove_app_info_list(int pid)
+int _status_remove_app_info_list(int pid, uid_t uid)
{
GSList *iter = NULL;
app_status_info_t *info_t = NULL;
for (iter = app_status_info_list; iter != NULL; iter = g_slist_next(iter))
{
info_t = (app_status_info_t *)iter->data;
- if(pid == info_t->pid) {
+ if((pid == info_t->pid) && ((info_t->user == uid) || (info_t->user == 0))) {
app_status_info_list = g_slist_remove(app_status_info_list, info_t);
free(info_t);
break;
}
-int _status_app_is_running(char *appid)
+int _status_app_is_running(char *appid, uid_t uid)
{
GSList *iter = NULL;
app_status_info_t *info_t = NULL;
for (iter = app_status_info_list; iter != NULL; iter = g_slist_next(iter))
{
info_t = (app_status_info_t *)iter->data;
- if( strncmp(appid, info_t->appid, MAX_PACKAGE_STR_SIZE) == 0 ) {
+ if(( strncmp(appid, info_t->appid, MAX_PACKAGE_STR_SIZE) == 0 ) && (info_t->user == uid)) {
return info_t->pid;
}
}
return 0;
}
-int _status_app_is_running_v2(char *appid)
+int _status_app_is_running_v2(uid_t caller_uid, char *appid)
{
char *apppath = NULL;
int ret = 0;
if(appid == NULL)
return -1;
- ai = appinfo_find(_saf, appid);
+ ai = appinfo_find(caller_uid, appid);
if(ai == NULL)
return -1;
*
*/
+#include <unistd.h>
+#include <sys/types.h>
-int _status_add_app_info_list(char *appid, char *app_path, int pid, int pad_pid);
-int _status_update_app_info_list(int pid, int status);
-int _status_remove_app_info_list(int pid);
+
+int _status_add_app_info_list(char *appid, char *app_path, int pid, int pad_pid, uid_t uid);
+int _status_update_app_info_list(int pid, int status, uid_t uid);
+int _status_remove_app_info_list(int pid, uid_t uid);
int _status_get_app_info_status(int pid);
-int _status_app_is_running(char *appid);
int _status_send_running_appinfo(int fd);
-int _status_app_is_running_v2(char *appid);
-int _status_send_running_appinfo_v2(int fd);
+int _status_app_is_running(char *appid, uid_t uid);
+int _status_send_running_appinfo_v2(int fd); //depcrecated
int _status_get_appid_bypid(int fd, int pid);
typedef struct _item_pkt_t {
int pid;
+ uid_t uid;
char appid[512];
} item_pkt_t;
/*
- * simple AUL daemon - launchpad
+ * AMD user session agent
*/
#include <stdio.h>
#include <string.h>
#include <dlfcn.h>
-#ifdef X11
-#include <X11/Xlib.h>
-#endif
#include <sys/types.h>
#include <signal.h>
#include <dirent.h>
#include <sys/prctl.h>
#include <malloc.h>
+#include "agent_config.h"
+
#include "app_sock.h"
#include "aul.h"
-#include "config.h"
-
#include "menu_db_util.h"
#include "simple_util.h"
#include "access_control.h"
#include "preload.h"
#include "preexec.h"
#include "perf.h"
-#include "sigchild.h"
#include "aul_util.h"
-
-#include "heap_dbg.h"
-
-#include "util_x.h"
-
-#include "gl.h"
+#include "sigchild.h"
#include <app-checker.h>
#include <sqlite3.h>
#define _static_ static inline
#define POLLFD_MAX 1
-#define SQLITE_FLUSH_MAX (1048576) /* (1024*1024) */
+#define SQLITE_FLUSH_MAX (1048576) /* (1024*1024) */
#define AUL_POLL_CNT 15
#define AUL_PR_NAME 16
-static char *launchpad_cmdline;
+static char *agent_cmdline;
static int initialized = 0;
_static_ char **__create_argc_argv(bundle * kb, int *margc);
_static_ int __normal_fork_exec(int argc, char **argv);
_static_ void __real_launch(const char *app_path, bundle * kb);
-static inline int __parser(const char *arg, char *out, int out_size);
+_static_ int __parser(const char *arg, char *out, int out_size);
_static_ void __modify_bundle(bundle * kb, int caller_pid,
app_info_from_db * menu_info, int cmd);
_static_ int __child_raise_win_by_x(int pid, void *priv);
_static_ int __resume_app(int pid);
_static_ int __real_send(int clifd, int ret);
_static_ void __send_result_to_caller(int clifd, int ret);
-_static_ void __launchpad_main_loop(int main_fd);
-_static_ int __launchpad_pre_init(int argc, char **argv);
-_static_ int __launchpad_post_init();
-
-extern ail_error_e ail_db_close(void);
+_static_ void __agent_main_loop(int main_fd);
+_static_ int __agent_pre_init(int argc, char **argv);
+_static_ int __agent_post_init();
char buf[MAX_LOCAL_BUFSZ];
FILE *fp;
- /* we should reset oomadj value as default because child
+ /* we should reset oomadj value as default because child
inherits from parent oom_adj*/
snprintf(buf, MAX_LOCAL_BUFSZ, "/proc/%d/oom_adj", getpid());
fp = fopen(buf, "w");
{
const char *str;
const char **str_array;
- int len;
- int i;
setenv("PKG_NAME", _get_pkgname(menu_info), 1);
_D("pkg_name : %s / pkg_type : %s / app_path : %s ", pkg_name, menu_info->pkg_type, app_path);
if ((ret = __set_access(pkg_name, menu_info->pkg_type, app_path)) < 0) {
_D("fail to set privileges - check your package's credential : %d\n", ret);
- return -1;
+ return -1;
}
}
/* SET DUMPABLE - for coredump*/
PERF("setup argument done");
/* Temporary log: launch time checking */
- LOG(LOG_DEBUG, "LAUNCH", "[%s:Platform:launchpad:done]", app_path);
-
+ LOG(LOG_DEBUG, "LAUNCH", "[%s:Platform:agent:done]", app_path);
+#ifdef PRELOAD_ACTIVATE
__preload_exec(app_argc, app_argv);
-
+#endif
__normal_fork_exec(app_argc, app_argv);
}
_static_ int __child_raise_win_by_x(int pid, void *priv)
{
+#ifdef X11
return x_util_raise_win(pid);
+#else
+ return 0;
+#endif
}
_static_ int __raise_win_by_x(int pid)
return pid;
}
+static int __get_caller_uid(bundle *kb)
+{
+ const char *uid_str;
+ int uid;
+
+ uid_str = bundle_get_val(kb, AUL_K_CALLER_UID);
+ if (uid_str == NULL)
+ return -1;
+
+end:
+ uid = atoi(uid_str);
+ if (uid <0)
+ return -1;
+
+ return uid;
+}
+
_static_ int __foward_cmd(int cmd, bundle *kb, int cr_pid)
{
int pid;
if (cmdline == NULL) {
_E("error founded when being launched with %d", ret);
- } else if (strcmp(cmdline, launchpad_cmdline)) {
+ } else if (strcmp(cmdline, agent_cmdline)) {
free(cmdline);
cmdline_changed = 1;
break;
if (!cmdline_changed)
_E("process launched, but cmdline not changed");
+ _D("send_result_to_caller: %d",ret);
+
if(__real_send(clifd, ret) < 0) {
r = kill(ret, SIGKILL);
if (r == -1)
_E("send SIGKILL: %s", strerror(errno));
}
-
+
return;
}
return menu_info;
}
-_static_ void __launchpad_main_loop(int main_fd)
+_static_ void __agent_main_loop(int main_fd)
{
bundle *kb = NULL;
app_pkt_t *pkt = NULL;
const char *pkg_name = NULL;
const char *app_path = NULL;
int pid = -1;
+ int uid = -1;
int clifd = -1;
struct ucred cr;
int is_real_launch = 0;
char sock_path[UNIX_PATH_MAX] = {0,};
+ _D("received request");
+
pkt = __app_recv_raw(main_fd, &clifd, &cr);
if (!pkt) {
_D("packet is NULL");
pkg_name = bundle_get_val(kb, AUL_K_PKG_NAME);
SECURE_LOGD("pkg name : %s\n", pkg_name);
+ /* get caller uid and check if not coming from someone else than AMD */
+ uid = __get_caller_uid(kb);
+ _D("caller uid: %d",uid);
+ if (uid<0) {
+ _E("Invalid caller uid");
+ goto end;
+ }
+ if ((uid != 0) && (uid != getuid())) {
+ _E("Invalid request coming from another user");
+ goto end;
+ }
+
menu_info = _get_app_info_from_bundle_by_pkgname(pkg_name, kb);
if (menu_info == NULL) {
- _D("such pkg no found");
+ _D("package not found");
goto end;
}
__modify_bundle(kb, cr.pid, menu_info, pkt->cmd);
pkg_name = _get_pkgname(menu_info);
- PERF("get package information & modify bundle done");
+ _D("start %s: type=%s caller_uid=%d path=%s",pkg_name,menu_info->pkg_type,uid,app_path);
+ PERF("get package information & modify bundle done");
+ if( !strcmp(menu_info->pkg_type, "wgt") || !strcmp(menu_info->pkg_type, "rpm") || !strcmp(menu_info->pkg_type, "tpk"))
{
pid = fork();
if (pid == 0) {
SECURE_LOGD("==> real launch pid : %d %s\n", pid, app_path);
is_real_launch = 1;
}
-
end:
__send_result_to_caller(clifd, pid);
if (is_real_launch) {
/*TODO: retry*/
__signal_block_sigchld();
- __send_app_launch_signal(pid);
+ __send_app_launch_signal_dbus(pid);
__signal_unblock_sigchld();
}
}
if (pkt != NULL)
free(pkt);
- /* Active Flusing for Daemon */
if (initialized > AUL_POLL_CNT) {
sqlite3_release_memory(SQLITE_FLUSH_MAX);
malloc_trim(0);
}
-_static_ int __launchpad_pre_init(int argc, char **argv)
+_static_ int __agent_pre_init(int argc, char **argv)
{
int fd;
-
+ char *socket_path = NULL;
/* signal init*/
__signal_init();
- /* get my(launchpad) command line*/
- launchpad_cmdline = __proc_get_cmdline_bypid(getpid());
- if (launchpad_cmdline == NULL) {
- _E("launchpad cmdline fail to get");
+ /* get my(agent) command line*/
+ agent_cmdline = __proc_get_cmdline_bypid(getpid());
+ if (agent_cmdline == NULL) {
+ _E("agent cmdline fail to get");
+ return -1;
+ }
+ _D("agent cmdline = %s", agent_cmdline);
+
+ /* create agent socket */
+ asprintf(&socket_path,"/run/user/%d/amd_agent",getuid());
+ if(socket_path)
+ fd = __create_server_sock_by_path(socket_path);
+ else
return -1;
- }
- _D("launchpad cmdline = %s", launchpad_cmdline);
-
- /* create launchpad sock */
- fd = __create_server_sock(LAUNCHPAD_PID);
+ free(socket_path);
if (fd < 0) {
_E("server sock error");
return -1;
}
- __preload_init(argc, argv);
-
- __preexec_init(argc, argv);
-
return fd;
}
-_static_ int __launchpad_post_init()
+_static_ int __agent_post_init()
{
- /* Setting this as a global variable to keep track
- of launchpad poll cnt */
+ /* Setting this as a global variable to keep track
+ of agent poll cnt */
/* static int initialized = 0;*/
if (initialized) {
struct pollfd pfds[POLLFD_MAX];
int i;
+ _D("amd_session_agent starting");
+
/* init without concerning X & EFL*/
- main_fd = __launchpad_pre_init(argc, argv);
+ main_fd = __agent_pre_init(argc, argv);
if (main_fd < 0) {
- _E("launchpad pre init failed");
+ _E("agent pre init failed");
exit(-1);
}
if (poll(pfds, POLLFD_MAX, -1) < 0)
continue;
- /* init with concerning X & EFL (because of booting
+ /* init with concerning X & EFL (because of booting
sequence problem)*/
- if (__launchpad_post_init() < 0) {
- _E("launcpad post init failed");
+ if (__agent_post_init() < 0) {
+ _E("agent post init failed");
exit(-1);
}
for (i = 0; i < POLLFD_MAX; i++) {
if ((pfds[i].revents & POLLIN) != 0) {
- __launchpad_main_loop(pfds[i].fd);
+ __agent_main_loop(pfds[i].fd);
}
}
}
--- /dev/null
+
+ /*
+ * aul
+ *
+ * Copyright (c) 2000 - 2014 Eurogiciel, Ltd. All rights reserved.
+ *
+ *
+ */
+
+
+/*
+ * AMD User Session agent - config file
+ */
+
+
+#define AGENT_LOG
*
*/
-
-#include <pthread.h>
+#include "aul_util.h"
#include "app_signal.h"
static struct sigaction old_sigchild;
closedir(dp);
}
-static inline int __send_app_dead_signal(int dead_pid)
+static inline int __send_app_dead_signal_amd(int dead_pid) {
+ bundle* kb=NULL;
+ char tmpbuf[MAX_PID_STR_BUFSZ];
+ int ret;
+
+ // send signal to AMD daemon using direct request
+ kb=bundle_create();
+ if (kb==NULL) {
+ _E("bundle creation failed");
+ return -1;
+ }
+
+ snprintf(tmpbuf, MAX_PID_STR_BUFSZ, "%d", dead_pid);
+ bundle_add(kb,AUL_K_PID,tmpbuf);
+
+ ret=app_send_cmd_with_noreply(AUL_UTIL_PID, APP_DEAD_SIGNAL,kb);
+
+ if (ret) {
+ _E("unable to send dead signal to amd proc PID %d",dead_pid);
+ }
+ else {
+ _D("send_app_dead_signal_amd done (pid=%d)\n",dead_pid);
+ }
+
+ bundle_free(kb);
+
+ return ret;
+}
+
+static inline int __send_app_dead_signal_dbus(int dead_pid)
{
DBusMessage *message;
+ // send over session dbus for other applications
if (bus == NULL)
return -1;
dbus_connection_flush(bus);
dbus_message_unref(message);
- _D("send dead signal done\n");
+ _D("send_app_dead_signal_dbus done (pid=%d)\n",dead_pid);
return 0;
}
-static inline int __send_app_launch_signal(int launch_pid)
+static inline int __send_app_launch_signal_dbus(int launch_pid)
{
DBusMessage *message;
dbus_connection_flush(bus);
dbus_message_unref(message);
- _D("send launch signal done\n");
+ _D("send_app_launch_signal_dbus done (pid=%d)",launch_pid);
return 0;
}
if (dead_pid <= 0)
goto end;
- __send_app_dead_signal(dead_pid);
+ __send_app_dead_signal_amd(dead_pid);
+ __send_app_dead_signal_dbus(dead_pid);
snprintf(buf, MAX_LOCAL_BUFSZ, "%s/%d", AUL_SOCK_PREFIX, dead_pid);
unlink(buf);
return 0;
}
-static void __launchpad_sig_child(int signo, siginfo_t *info, void *data)
+static void __agent_sig_child(int signo, siginfo_t *info, void *data)
{
int status;
pid_t child_pid;
dbus_error_init(&error);
dbus_threads_init_default();
- bus = dbus_bus_get_private(DBUS_BUS_SYSTEM, &error);
+ bus = dbus_bus_get_private(DBUS_BUS_SESSION, &error);
if (!bus) {
_E("Failed to connect to the D-BUS daemon: %s", error.message);
dbus_error_free(&error);
return -1;
}
- /* TODO: if process stop mechanism is included,
+ /* TODO: if process stop mechanism is included,
should be modified (SA_NOCLDSTOP)*/
act.sa_handler = NULL;
- act.sa_sigaction = __launchpad_sig_child;
+ act.sa_sigaction = __agent_sig_child;
sigemptyset(&act.sa_mask);
act.sa_flags = SA_NOCLDSTOP | SA_SIGINFO;
APP_STATUS_UPDATE,
APP_RELEASED,
APP_RUNNING_LIST_UPDATE,
- APP_TERM_REQ_BY_PID
+ APP_TERM_REQ_BY_PID,
+
+ /* reserved for AMD Agent */
+ APP_DEAD_SIGNAL
};
#define AUL_SOCK_PREFIX "/tmp/alaunch"
unsigned char data[1];
} app_pkt_t;
+typedef struct _pkt_t {
+ uid_t caller_uid;
+ app_pkt_t *pkt;
+} pkt_t;
+
int __create_server_sock(int pid);
int __create_client_sock(int pid);
int __app_send_raw(int pid, int cmd, unsigned char *kb_data, int datalen);
int __app_send_raw_with_delay_reply(int pid, int cmd, unsigned char *kb_data, int datalen);
app_pkt_t *__app_recv_raw(int fd, int *clifd, struct ucred *cr);
app_pkt_t *__app_send_cmd_with_result(int pid, int cmd, unsigned char *kb_data, int datalen);
+int __create_agent_client_sock(int uid);
#endif
/** AUL public key - To check callee's secuirty */
#define AUL_K_CALLEE_PID "__AUL_CALLEE_PID__"
+/** AUL public key - added for multiuser mode */
+#define AUL_K_CALLER_UID "__AUL_CALLER_UID__"
+/** AUL public key - added for multiuser mode */
+#define AUL_K_CALLEE_UID "__AUL_CALLEE_UID__"
+
/** AUL public key - To check caller's secuirty */
#define AUL_K_CALLER_APPID "__AUL_CALLER_APPID__"
/** AUL public key - To check caller's secuirty */
#ifndef __AUL_UTIL_H_
#define __AUL_UTIL_H_
+#include <unistd.h>
+#include <sys/types.h>
+
+#define USE_ENGINE(engine) setenv("ELM_ENGINE", engine, 1);
+
#define AUL_UTIL_PID -2
#define MAX_PACKAGE_STR_SIZE 512
int status;
int pid;
int pad_pid;
+ uid_t user;
} app_status_info_t;
+
struct amdmgr {
struct appinfomgr *af; /* appinfo manager */
struct cginfo *cg; /* cgroup infomation */
};
-int _add_app_status_info_list(char *appid, int pid);
-int _update_app_status_info_list(int pid, int status);
-int _remove_app_status_info_list(int pid);
+int _add_app_status_info_list(char *appid, int pid, uid_t uid);
+int _update_app_status_info_list(int pid, int status, uid_t uid);
+int _remove_app_status_info_list(int pid, uid_t uid);
#endif
#include <ctype.h>
#include <dlog.h>
+#undef LOG_TAG
+#define LOG_TAG "AUL"
+
#ifdef LAUNCHPAD_LOG
#undef LOG_TAG
#define LOG_TAG "AUL_PAD"
-#else
-#undef LOG_TAG
-#define LOG_TAG "AUL"
#endif
+
#ifdef AMD_LOG
#undef LOG_TAG
#define LOG_TAG "AUL_AMD"
#endif
+#ifdef AGENT_LOG
+#undef LOG_TAG
+#define LOG_TAG "AUL_AGENT"
+#endif
#define MAX_LOCAL_BUFSZ 128
#define MAX_PID_STR_BUFSZ 20
int __proc_iter_pgid(int pgid, int (*iterfunc) (int pid, void *priv),
void *priv);
char *__proc_get_cmdline_bypid(int pid);
+char *__proc_get_exe_bypid(int pid);
static inline const char *FILENAME(const char *filename)
{
+++ /dev/null
-/*
- * aul
- *
- * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Contact: Jayoun Lee <airjany@samsung.com>, Sewook Park <sewook7.park@samsung.com>, Jaeho Lee <jaeho81.lee@samsung.com>
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-
-#define LAUNCHPAD_LOG
-#define DAC_ACTIVATE
-#define PRELOAD_ACTIVATE
-#define PREEXEC_ACTIVATE
-/*#define GL_ACTIVATE*/
-/*#define HEAPDGB_ACTIVATE*/
-/*#define PERF_ACTIVATE*/
-
+++ /dev/null
-/*
- * aul
- *
- * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Contact: Jayoun Lee <airjany@samsung.com>, Sewook Park <sewook7.park@samsung.com>, Jaeho Lee <jaeho81.lee@samsung.com>
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-
-#ifdef GL_ACTIVATE
-
-#define USE_ENGINE(engine) setenv("ELM_ENGINE", engine, 1);
-
-#else
-
-#define USE_ENGINE(engine)
-
-#endif
-
+++ /dev/null
-/*
- * aul
- *
- * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Contact: Jayoun Lee <airjany@samsung.com>, Sewook Park <sewook7.park@samsung.com>, Jaeho Lee <jaeho81.lee@samsung.com>
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-
-#include <malloc.h>
-#include <stdio.h>
-#include <signal.h>
-
-#ifdef HEAPDGB_ACTIVATE
-
-#define HOOK_RESET() \
-do {\
- __malloc_hook = old_malloc_hook; \
- __free_hook = old_free_hook; \
-} while (0);
-
-#define HOOK_SET() \
-do {\
- __malloc_hook = my_malloc; \
- __free_hook = my_free; \
-} while (0);
-
-static void *(*old_malloc_hook) (size_t size, const void *caller);
-static void *(*old_realloc_hook) (void *ptr, size_t size, const void *caller);
-static void (*old_free_hook) (void *ptr, const void *caller);
-
-static void *my_malloc(size_t size, const void *caller);
-static void *my_realloc(void *ptr, size_t size, const void *caller);
-static void my_free(void *ptr, const void *caller);
-
-static void my_free(void *ptr, const void *caller)
-{
- void *callstack_addrs[20];
- char **callstack_strings;
- int i;
-
- HOOK_RESET();
-
- printf("%c[1;31m[FREE] %x %x", 27, ptr, caller);
- printf("%c[0m\n", 27);
- free(ptr);
-
- HOOK_SET();
-
-}
-
-static void *my_malloc(size_t size, const void *caller)
-{
- void *ptr;
-
- HOOK_RESET();
-
- ptr = malloc(size);
- printf("%c[1;31m[MALLOC] %x %x", 27, ptr, caller);
- printf("%c[0m\n", 27);
-
- HOOK_SET();
-
- return ptr;
-}
-
-static void malloc_init(void)
-{
- old_malloc_hook = __malloc_hook;
- old_free_hook = __free_hook;
-
- HOOK_SET();
-}
-
-__attribute__ ((visibility("default")))
-void (*__malloc_initialize_hook) (void) = malloc_init;
-
-#else
-
-#endif
+++ /dev/null
-/*
- * aul
- *
- * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Contact: Jayoun Lee <airjany@samsung.com>, Sewook Park <sewook7.park@samsung.com>, Jaeho Lee <jaeho81.lee@samsung.com>
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <errno.h>
-#include <signal.h>
-
-#include <X11/Xlib.h>
-#include <X11/Xatom.h>
-
-#include "simple_util.h"
-
-static Atom a_pid;
-static int (*x_old_error) (Display *, XErrorEvent *);
-
-
-static pid_t __get_win_pid(Display *d, Window win);
-static int __find_win(Display *d, Window *win, pid_t pid);
-static int __raise_win(Display *d, Window win);
-static int __cb_x_error(Display *disp, XErrorEvent *ev);
-
-static pid_t __get_win_pid(Display *d, Window win)
-{
- int r;
- pid_t pid;
-
- Atom a_type;
- int format;
- unsigned long nitems;
- unsigned long bytes_after;
- unsigned char *prop_ret;
-
- retv_if(d == NULL || !a_pid, -1);
-
- prop_ret = NULL;
- r = XGetWindowProperty(d, win, a_pid, 0, 1, False, XA_CARDINAL,
- &a_type, &format, &nitems, &bytes_after, &prop_ret);
- if (r != Success || prop_ret == NULL)
- return -1;
-
- if (a_type == XA_CARDINAL && format == 32)
- pid = *(unsigned long *)prop_ret;
- else
- pid = -1;
-
- XFree(prop_ret);
-
- return pid;
-}
-
-static int __find_win(Display *d, Window *win, pid_t pid)
-{
- int r;
- pid_t p;
- unsigned int n;
- Window root, parent, *child;
-
- p = __get_win_pid(d, *win);
- if (p == pid)
- return 1;
-
- r = XQueryTree(d, *win, &root, &parent, &child, &n);
- if (r) {
- int i;
- int found = 0;
-
- for (i = 0; i < n; i++) {
- found = __find_win(d, &child[i], pid);
- if (found) {
- *win = child[i];
- break;
- }
- }
- XFree(child);
-
- if (found)
- return 1;
- }
-
- return 0;
-}
-
-static int __raise_win(Display *d, Window win)
-{
- XWindowAttributes attr;
- attr.map_state = IsUnmapped;
-
- XMapRaised(d, win);
-
- XGetWindowAttributes(d, win, &attr);
-
- if (attr.map_state == IsUnmapped)
- _D("unmapped");
- else if (attr.map_state == IsUnviewable)
- _D("unviewable");
- else if (attr.map_state == IsViewable)
- _D("viewable");
-
- retv_if(attr.map_state != IsViewable, -1);
-
- XSetInputFocus(d, win, RevertToPointerRoot, CurrentTime);
-
- return 0;
-}
-
-int x_util_raise_win(pid_t pid)
-{
- int r;
- int found;
- Display *d;
- Window win;
-
- if (pid < 1)
- return -1;
-
- r = kill(pid, 0);
- if (r == -1)
- return -1;
-
- d = XOpenDisplay(NULL);
- retv_if(d == NULL, -1);
-
- win = XDefaultRootWindow(d);
-
- if (!a_pid)
- a_pid = XInternAtom(d, "X_CLIENT_PID", True);
-
- found = __find_win(d, &win, pid);
- if (!found) {
- XCloseDisplay(d);
- _E("cannot found window with pid - %d", pid);
- return -1;
- }
-
- r = __raise_win(d, win);
- if (r < 0)
- _E("fail to raise win");
-
- XCloseDisplay(d);
-
- return r;
-}
-
-int x_util_get_default_size(double *w, double *h)
-{
- Display *d;
- int screen_num;
-
- d = XOpenDisplay(NULL);
- if (d == NULL)
- return -1;
-
- screen_num = DefaultScreen(d);
-
- *w = DisplayWidth(d, screen_num);
- *h = DisplayHeight(d, screen_num);
-
- _D("Root Width = %lf, Height = %lf\n", *w, *h);
-
- XCloseDisplay(d);
-
- return 0;
-}
-
-static int __cb_x_error(Display *disp, XErrorEvent *ev)
-{
- _E("X error received - Error Code = %d", ev->error_code);
- return 0;
-}
-
-int x_util_init()
-{
- x_old_error = XSetErrorHandler(__cb_x_error);
- return 0;
-}
-
-int x_util_fini()
-{
- XSetErrorHandler(x_old_error);
- return 0;
-}
-
+++ /dev/null
-/*
- * aul
- *
- * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Contact: Jayoun Lee <airjany@samsung.com>, Sewook Park <sewook7.park@samsung.com>, Jaeho Lee <jaeho81.lee@samsung.com>
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-
-#ifndef __UTIL_X_H_
-#define __UTIL_X_H_
-
-int x_util_init();
-int x_util_fini();
-int x_util_get_default_size(double *w, double *h);
-int x_util_raise_win(pid_t pid);
-
-#endif
-
--- /dev/null
+#
+# Systemd script to Launch AMD Session agent
+#
+
+[Unit]
+Description=Start the USER Access Control Agent
+
+[Service]
+ExecStart=/usr/bin/amd_session_agent
+
+[Install]
+WantedBy=default.target
%bcond_with wayland
%bcond_with x
-
Name: aul
Summary: App utility library
-Version: 0.0.286
+Version: 0.0.300
Release: 1
Group: System/Libraries
License: Apache-2.0
Source0: %{name}-%{version}.tar.gz
Source101: launchpad-preload@.service
Source102: ac.service
+Source103: amd_session_agent.service
Source1001: %{name}.manifest
Requires(post): /sbin/ldconfig
CFLAGS="%{optflags} -D__emul__"; export CFLAGS
%endif
+%cmake . \
%if %{with wayland}
-%cmake . -DWITH_WAYLAND=On
+ -DWITH_WAYLAND=On \
%else
-%cmake . -DWITH_WAYLAND=Off
+ -DWITH_WAYLAND=Off \
%endif
make %{?jobs:-j%jobs}
rm -rf %{buildroot}/usr/share/aul/mida_db.sql
mkdir -p %{buildroot}/usr/lib/systemd/system/graphical.target.wants
+mkdir -p %{buildroot}/usr/lib/systemd/user/default.target.wants
install -m 0644 %SOURCE101 %{buildroot}/usr/lib/systemd/system/launchpad-preload@.service
install -m 0644 %SOURCE102 %{buildroot}/usr/lib/systemd/system/ac.service
ln -s ../launchpad-preload@.service %{buildroot}/usr/lib/systemd/system/graphical.target.wants/launchpad-preload@5000.service
ln -s ../ac.service %{buildroot}/usr/lib/systemd/system/graphical.target.wants/ac.service
-mkdir -p %{buildroot}%{TZ_SYS_SMACK}/accesses.d
-
-mkdir -p %{buildroot}/usr/share/license
-cp LICENSE %{buildroot}/usr/share/license/%{name}
-
+install -m 0644 %SOURCE103 %{buildroot}/usr/lib/systemd/user/amd_session_agent.service
+ln -s ../amd_session_agent.service %{buildroot}/usr/lib/systemd/user/default.target.wants/amd_session_agent.service
%preun
if [ $1 == 0 ]; then
systemctl daemon-reload
%files
+%license LICENSE
%manifest %{name}.manifest
%attr(0644,root,root) %{_libdir}/libaul.so.0
%attr(0644,root,root) %{_libdir}/libaul.so.0.1.0
%{_bindir}/aul_test
%{_bindir}/launch_app
%{_bindir}/open_app
+%{_bindir}/amd_session_agent
/usr/share/aul/miregex/*
/usr/share/aul/service/*
/usr/share/aul/preload_list.txt
/usr/share/aul/preexec_list.txt
-%{_bindir}/launchpad_preloading_preinitializing_daemon
/usr/lib/systemd/system/graphical.target.wants/launchpad-preload@5000.service
/usr/lib/systemd/system/graphical.target.wants/ac.service
/usr/lib/systemd/system/launchpad-preload@.service
/usr/lib/systemd/system/ac.service
+/usr/lib/systemd/user/amd_session_agent.service
+/usr/lib/systemd/user/default.target.wants/amd_session_agent.service
/usr/bin/amd
/usr/bin/daemon-manager-release-agent
/usr/bin/daemon-manager-launch-agent
-/usr/share/license/%{name}
%files devel
/usr/include/aul/*.h
return 0;
dbus_error_init(&error);
- bus = dbus_bus_get_private(DBUS_BUS_SYSTEM, &error);
+ bus = dbus_bus_get_private(DBUS_BUS_SESSION, &error);
if (!bus) {
_E("Failed to connect to the D-BUS daemon: %s", error.message);
dbus_error_free(&error);
return -1;
}
- if (dbus_connection_add_filter(bus,
+ if (dbus_connection_add_filter(bus,
__app_dbus_signal_filter, NULL, NULL) == FALSE)
return -1;
return fd;
}
+
+int __create_server_sock_by_path(char *path)
+{
+ struct sockaddr_un saddr;
+ struct sockaddr_un p_saddr;
+ int fd = socket(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0);
+ /* support above version 2.6.27*/
+ if (fd < 0) {
+ if (errno == EINVAL) {
+ fd = socket(AF_UNIX, SOCK_STREAM, 0);
+ if (fd < 0) {
+ _E("second chance - socket create error");
+ return -1;
+ }
+ } else {
+ _E("socket error");
+ return -1;
+ }
+ }
+
+ memset(&saddr, 0, sizeof(saddr));
+ saddr.sun_family = AF_UNIX;
+ snprintf(saddr.sun_path, UNIX_PATH_MAX, "%s", path);
+ unlink(saddr.sun_path);
+
+ if (bind(fd, (struct sockaddr *)&saddr, sizeof(saddr)) < 0) {
+ _E("bind error");
+ close(fd);
+ return -1;
+ }
+
+ if (chmod(saddr.sun_path, (S_IRWXU | S_IRWXG | S_IRWXO)) < 0) {
+ /* Flawfinder: ignore*/
+ _E("failed to change the socket permission");
+ close(fd);
+ return -1;
+ }
+ __set_sock_option(fd, 0);
+ if (listen(fd, 128) == -1) {
+ _E("listen error");
+ close(fd);
+ return -1;
+ }
+ return fd;
+}
+
+
+
+
+
+
+int __create_agent_client_sock(int uid)
+{
+ int fd = -1;
+ struct sockaddr_un saddr = { 0, };
+ int retry = 1;
+ int ret = -1;
+
+ fd = socket(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0);
+ /* support above version 2.6.27*/
+ if (fd < 0) {
+ if (errno == EINVAL) {
+ fd = socket(AF_UNIX, SOCK_STREAM, 0);
+ if (fd < 0) {
+ _E("second chance - socket create error");
+ return -1;
+ }
+ } else {
+ _E("socket error");
+ return -1;
+ }
+ }
+
+ saddr.sun_family = AF_UNIX;
+ snprintf(saddr.sun_path, UNIX_PATH_MAX, "/run/user/%d/amd_agent", uid);
+ retry_con:
+ ret = __connect_client_sock(fd, (struct sockaddr *)&saddr, sizeof(saddr),
+ 100 * 1000);
+ if (ret < -1) {
+ _E("maybe peer not launched or peer daed\n");
+ if (retry > 0) {
+ usleep(100 * 1000);
+ retry--;
+ goto retry_con;
+ }
+ }
+ if (ret < 0) {
+ close(fd);
+ return -1;
+ }
+
+ __set_sock_option(fd, 1);
+
+ return fd;
+}
+
+
int __create_client_sock(int pid)
{
int fd = -1;
return res;
}
+
+int __app_agent_send_raw(int uid, int cmd, unsigned char *kb_data, int datalen)
+{
+ int fd;
+ int len;
+ int ret;
+ int res = 0;
+ app_pkt_t *pkt = NULL;
+
+ if (kb_data == NULL || datalen > AUL_SOCK_MAXBUFF - 8) {
+ _E("keybundle error\n");
+ return -EINVAL;
+ }
+
+ _D("uid(%d) : cmd(%d)", uid, cmd);
+
+ fd = __create_agent_client_sock(uid);
+ if (fd < 0)
+ return -ECOMM;
+
+ pkt = (app_pkt_t *) malloc(sizeof(char) * AUL_SOCK_MAXBUFF);
+ if (NULL == pkt) {
+ _E("Malloc Failed!");
+ return -ENOMEM;
+ }
+ memset(pkt, 0, AUL_SOCK_MAXBUFF);
+
+ pkt->cmd = cmd;
+ pkt->len = datalen;
+ memcpy(pkt->data, kb_data, datalen);
+
+ if ((len = send(fd, pkt, datalen + 8, 0)) != datalen + 8) {
+ _E("sendto() failed - %d %d (errno %d)", len, datalen + 8, errno);
+ if(len > 0) {
+ while (len != datalen + 8) {
+ ret = send(fd, &pkt->data[len-8], datalen + 8 - len, 0);
+ if (ret < 0) {
+ _E("second sendto() failed - %d %d (errno %d)", ret, datalen + 8, errno);
+ if (errno == EPIPE) {
+ _E("uid:%d, fd:%d\n", uid, fd);
+ }
+ close(fd);
+ if (pkt) {
+ free(pkt);
+ pkt = NULL;
+ }
+ return -ECOMM;
+ }
+ len += ret;
+ _D("sendto() len - %d %d", len, datalen + 8);
+ }
+ } else {
+ if (errno == EPIPE) {
+ _E("uid:%d, fd:%d\n", uid, fd);
+ }
+ close(fd);
+ if (pkt) {
+ free(pkt);
+ pkt = NULL;
+ }
+ return -ECOMM;
+ }
+ }
+ if (pkt) {
+ free(pkt);
+ pkt = NULL;
+ }
+
+retry_recv:
+ len = recv(fd, &res, sizeof(int), 0);
+ if (len == -1) {
+ if (errno == EAGAIN) {
+ _E("recv timeout : %s", strerror(errno));
+ res = -EAGAIN;
+ } else if (errno == EINTR) {
+ _D("recv : %s", strerror(errno));
+ goto retry_recv;
+ } else {
+ _E("recv error : %s", strerror(errno));
+ res = -ECOMM;
+ }
+ }
+ close(fd);
+
+ return res;
+}
+
+
+int __app_agent_send_raw_with_noreply(int uid, int cmd, unsigned char *kb_data, int datalen)
+{
+ int fd;
+ int len;
+ int ret;
+ int res = 0;
+ app_pkt_t *pkt = NULL;
+
+ if (kb_data == NULL || datalen > AUL_SOCK_MAXBUFF - 8) {
+ _E("keybundle error\n");
+ return -EINVAL;
+ }
+
+ _D("uid(%d) : cmd(%d)", uid, cmd);
+
+ fd = __create_agent_client_sock(uid);
+ if (fd < 0)
+ return -ECOMM;
+
+ pkt = (app_pkt_t *) malloc(sizeof(char) * AUL_SOCK_MAXBUFF);
+ if (NULL == pkt) {
+ _E("Malloc Failed!");
+ return -ENOMEM;
+ }
+ memset(pkt, 0, AUL_SOCK_MAXBUFF);
+
+ pkt->cmd = cmd;
+ pkt->len = datalen;
+ memcpy(pkt->data, kb_data, datalen);
+
+ if ((len = send(fd, pkt, datalen + 8, 0)) != datalen + 8) {
+ _E("sendto() failed - %d %d (errno %d)", len, datalen + 8, errno);
+ if(len > 0) {
+ while (len != datalen + 8) {
+ ret = send(fd, &pkt->data[len-8], datalen + 8 - len, 0);
+ if (ret < 0) {
+ _E("second sendto() failed - %d %d (errno %d)", ret, datalen + 8, errno);
+ if (errno == EPIPE) {
+ _E("uid:%d, fd:%d\n", uid, fd);
+ }
+ close(fd);
+ if (pkt) {
+ free(pkt);
+ pkt = NULL;
+ }
+ return -ECOMM;
+ }
+ len += ret;
+ _D("sendto() len - %d %d", len, datalen + 8);
+ }
+ } else {
+ if (errno == EPIPE) {
+ _E("uid:%d, fd:%d\n", uid, fd);
+ }
+ close(fd);
+ if (pkt) {
+ free(pkt);
+ pkt = NULL;
+ }
+ return -ECOMM;
+ }
+ }
+ if (pkt) {
+ free(pkt);
+ pkt = NULL;
+ }
+
+ close(fd);
+
+ return res;
+}
+
+
+
+
+
+
int __app_send_raw_with_noreply(int pid, int cmd, unsigned char *kb_data, int datalen)
{
int fd;
return res;
}
+
+
+
+
+
int __app_send_raw_with_delay_reply(int pid, int cmd, unsigned char *kb_data, int datalen)
{
int fd;
}
+
+
+/**
+ * @brief encode kb and send it to 'pid'
+ * @param[in] pid receiver's pid
+ * @param[in] cmd message's status (APP_START | APP_RESULT)
+ * @param[in] kb data
+ */
+SLPAPI int app_agent_send_cmd(int uid, int cmd, bundle *kb)
+{
+ int datalen;
+ bundle_raw *kb_data;
+ int res;
+
+ bundle_encode(kb, &kb_data, &datalen);
+ if ((res = __app_agent_send_raw(uid, cmd, kb_data, datalen)) < 0) {
+ switch (res) {
+ case -EINVAL:
+ res = AUL_R_EINVAL;
+ break;
+ case -ECOMM:
+ res = AUL_R_ECOMM;
+ break;
+ case -EAGAIN:
+ res = AUL_R_ETIMEOUT;
+ break;
+ case -ELOCALLAUNCH_ID:
+ res = AUL_R_LOCAL;
+ break;
+ case -EILLEGALACCESS:
+ res = AUL_R_EILLACC;
+ break;
+ case -ETERMINATING:
+ res = AUL_R_ETERMINATING;
+ break;
+ case -ENOLAUNCHPAD:
+ res = AUL_R_ENOLAUNCHPAD;
+ break;
+ default:
+ res = AUL_R_ERROR;
+ }
+ }
+ free(kb_data);
+
+ return res;
+}
+
+SLPAPI int app_agent_send_cmd_with_noreply(int uid, int cmd, bundle *kb)
+{
+ int datalen;
+ bundle_raw *kb_data;
+ int res;
+
+ bundle_encode(kb, &kb_data, &datalen);
+ if ((res = __app_send_raw_with_noreply(uid, cmd, kb_data, datalen)) < 0) {
+ switch (res) {
+ case -EINVAL:
+ res = AUL_R_EINVAL;
+ break;
+ case -ECOMM:
+ res = AUL_R_ECOMM;
+ break;
+ case -EAGAIN:
+ res = AUL_R_ETIMEOUT;
+ break;
+ case -ELOCALLAUNCH_ID:
+ res = AUL_R_LOCAL;
+ break;
+ case -EILLEGALACCESS:
+ res = AUL_R_EILLACC;
+ break;
+ default:
+ res = AUL_R_ERROR;
+ }
+ }
+ free(kb_data);
+
+ return res;
+}
+
+
+
+
+
+
+
+
+
/**
* @brief encode kb and send it to 'pid'
* @param[in] pid receiver's pid
#define OPTION_VALGRIND_NAME "valgrind"
#define OPTION_VALGRIND_SIZE 8
-
#define PROC_STAT_GID_POS 5
+#define MAX_CMD_BUFSZ 1024
static inline int __read_proc(const char *path, char *buf, int size);
static inline int __find_pid_by_cmdline(const char *dname,
char *__proc_get_cmdline_bypid(int pid)
{
-#define MAX_CMD_BUFSZ 1024
-
char buf[MAX_CMD_BUFSZ];
int ret;
return strdup(buf);
}
+char *__proc_get_exe_bypid(int pid)
+{
+ char buf[MAX_CMD_BUFSZ];
+ char buf2[MAX_CMD_BUFSZ];
+ int ret;
+ ssize_t len;
+
+ snprintf(buf, sizeof(buf), "/proc/%d/exe", pid);
+ len=readlink(buf,buf2,MAX_CMD_BUFSZ);
+ if (len<=0)
+ return NULL;
+
+ return strdup(buf2);
+}
+
static inline int __get_pgid_from_stat(int pid)
{
char buf[MAX_LOCAL_BUFSZ];
dbus_error_init(&error);
- bus = dbus_bus_get(DBUS_BUS_SYSTEM, &error);
+ bus = dbus_bus_get(DBUS_BUS_SESSION, &error);
if (bus == NULL)
_E("Failed to open bus to bus")
dbus_error_init(&error);
- bus = dbus_bus_get(DBUS_BUS_SYSTEM, &error);
+ bus = dbus_bus_get(DBUS_BUS_SESSION, &error);
reply = dbus_message_new_method_return(msg);
dbus_message_unref(msg);
dbus_error_init(&error);
- bus = dbus_bus_get(DBUS_BUS_SYSTEM, &error);
+ bus = dbus_bus_get(DBUS_BUS_SESSION, &error);
if (!bus)
_E("couldn't access session bus");
#include "aul.h"
#define ROOT_UID 0
-#define TMP_FILE "/tmp/.testpkg"
static char **gargv;
static int gargc;
int launch()
{
- FILE *fp;
- int ret = -1;
int pid = -1;
kb = create_internal_bundle(2);
printf("bundle creation fail\n");
return -1;
}
-
pid = aul_launch_app(gargv[1], kb);
-
- /* Write the package name to TMP_FILE*/
- fp = fopen(TMP_FILE, "w");
- if (fp == NULL)
- return -1;
- ret = fprintf(fp, "%d", pid);
- fclose(fp);
- if (ret < 0)
- return -1;
-
return pid;
}
int launch()
{
- FILE *fp;
- int ret = -1;
int pid = -1;
kb = create_internal_bundle(2);
}
pid = aul_open_app(gargv[1]);
-
- /* Write the package name to TMP_FILE*/
- fp = fopen(TMP_FILE, "w");
- if (fp == NULL)
- return -1;
- ret = fprintf(fp, "%d", pid);
- fclose(fp);
- if (ret < 0)
- return -1;
-
return pid;
}