Support receiving result callbacks for system daemon 60/110760/2
authorJunghoon Park <jh9216.park@samsung.com>
Mon, 16 Jan 2017 01:24:01 +0000 (10:24 +0900)
committerHwankyu Jhun <h.jhun@samsung.com>
Wed, 18 Jan 2017 02:27:44 +0000 (11:27 +0900)
- Add aul_launch_app_with_result_for_uid() which will be used
at __run_svc_with_pkgname()

Change-Id: Ia6475dcf9310fb7d89e0ca753600771635bf05d0
Signed-off-by: Junghoon Park <jh9216.park@samsung.com>
include/aul.h
include/launch.h
src/aul_sock.c
src/launch_with_result.c
src/service.c

index 116534a..35ae8ad 100644 (file)
@@ -257,6 +257,8 @@ typedef enum aul_widget_instance_event {
 #define AUL_K_IS_SUBAPP                "__AUL_IS_SUBAPP__"
 /** AUL internal private key */
 #define AUL_K_INSTANCE_ID      "__AUL_INSTANCE_ID__"
+/** AUL internal private key */
+#define AUL_K_ORG_CALLER_UID   "__AUL_ORG_CALLER_UID__"
 
 /**
  * @brief      This is callback function for aul_launch_init
index d137267..d8d3f7a 100644 (file)
@@ -40,6 +40,9 @@ int aul_send_result(bundle *kb, int is_cancel);
 int aul_launch_app_with_result(const char *pkgname, bundle *kb,
                               void (*cbfunc) (bundle *, int, void *),
                               void *data);
+int aul_launch_app_with_result_for_uid(const char *pkgname, bundle *kb,
+                              void (*cbfunc) (bundle *, int, void *),
+                              void *data, uid_t uid);
 int app_subapp_terminate_request(void);
 int __call_aul_handler(aul_type type, bundle *kb);
 gboolean __aul_glib_handler(gpointer data);
index 223018b..0451804 100644 (file)
@@ -39,8 +39,8 @@
 #define MAX_PAYLOAD_SIZE       (1024 * 1024 * 1)
 #define PATH_AMD_SOCK "/run/aul/daemons/.amd-sock"
 
-#ifdef TIZEN_FEATURE_DEFAULT_USER
 #define REGULAR_UID_MIN 5000
+#ifdef TIZEN_FEATURE_DEFAULT_USER
 static uid_t default_uid;
 static int default_uid_initialized;
 #endif
@@ -129,6 +129,17 @@ API int aul_sock_set_sock_option(int fd, int cli)
        return 0;
 }
 
+static void __create_socket_path(char *path_buf, int size, int pid, uid_t uid)
+{
+       if (uid < REGULAR_UID_MIN) {
+               snprintf(path_buf, size,
+                       "/run/aul/daemons/%d/.app-sock-%d", uid, pid);
+       } else {
+               snprintf(path_buf, size,
+                       "/run/aul/apps/%d/%d/.app-sock", uid, pid);
+       }
+}
+
 API int aul_sock_create_server(int pid, uid_t uid)
 {
        struct sockaddr_un saddr;
@@ -153,8 +164,15 @@ API int aul_sock_create_server(int pid, uid_t uid)
 
        memset(&saddr, 0, sizeof(saddr));
        saddr.sun_family = AF_UNIX;
-       snprintf(saddr.sun_path, sizeof(saddr.sun_path),
+
+       if (uid < REGULAR_UID_MIN) {
+               snprintf(saddr.sun_path, sizeof(saddr.sun_path),
+                       "/run/aul/daemons/%d", uid);
+
+       } else {
+               snprintf(saddr.sun_path, sizeof(saddr.sun_path),
                        "/run/aul/apps/%d/%d", uid, pid);
+       }
 
        ret = mkdir(saddr.sun_path, 0700);
        if (ret != 0) {
@@ -172,8 +190,7 @@ API int aul_sock_create_server(int pid, uid_t uid)
                }
        }
 
-       snprintf(saddr.sun_path, sizeof(saddr.sun_path),
-                       "/run/aul/apps/%d/%d/.app-sock", uid, pid);
+       __create_socket_path(saddr.sun_path, sizeof(saddr.sun_path), pid, uid);
        unlink(saddr.sun_path);
 
        /* labeling to socket for SMACK */
@@ -217,9 +234,7 @@ API int aul_sock_create_server(int pid, uid_t uid)
                int pgid;
                pgid = getpgid(pid);
                if (pgid > 1) {
-                       snprintf(p_saddr.sun_path, sizeof(p_saddr.sun_path),
-                                       "/run/aul/apps/%d/%d/.app-sock",
-                                       uid, pgid);
+                       __create_socket_path(saddr.sun_path, sizeof(saddr.sun_path), pgid, uid);
                        if (link(saddr.sun_path, p_saddr.sun_path) < 0) {
                                if (errno == EEXIST)
                                        _D("pg path - already exists");
@@ -269,8 +284,7 @@ static int __create_client_sock(int pid, uid_t uid)
                snprintf(saddr.sun_path, sizeof(saddr.sun_path),
                                "%s", PATH_AMD_SOCK);
        } else {
-               snprintf(saddr.sun_path, sizeof(saddr.sun_path),
-                               "/run/aul/apps/%d/%d/.app-sock", uid, pid);
+               __create_socket_path(saddr.sun_path, sizeof(saddr.sun_path), pid, uid);
        }
 
 retry_con:
@@ -908,7 +922,7 @@ int aul_sock_recv_pkt_with_cb(int fd,
 
                ret = __recv_raw_with_fd(fd, pkt[i]->len, pkt[i]->data,
                                &recv_size);
-               if (ret < 0 ) {
+               if (ret < 0) {
                        _E("recv error - %d", ret);
                        free(pkt[i]);
                        pkt[i] = NULL;
index 3a5a547..86dc723 100644 (file)
@@ -309,6 +309,13 @@ API int aul_launch_app_with_result(const char *pkgname, bundle *kb,
                               void (*cbfunc) (bundle *, int, void *),
                               void *data)
 {
+       return aul_launch_app_with_result_for_uid(pkgname, kb, cbfunc, data, getuid());
+}
+
+API int aul_launch_app_with_result_for_uid(const char *pkgname, bundle *kb,
+                              void (*cbfunc) (bundle *, int, void *),
+                              void *data, uid_t uid)
+{
        int ret;
        char num_str[MAX_LOCAL_BUFSZ] = { 0, };
        int num;
@@ -326,7 +333,7 @@ API int aul_launch_app_with_result(const char *pkgname, bundle *kb,
        bundle_del(kb, AUL_K_SEQ_NUM);
        bundle_add(kb, AUL_K_SEQ_NUM, num_str);
 
-       ret = app_request_to_launchpad(APP_START_RES, pkgname, kb);
+       ret = app_request_to_launchpad_for_uid(APP_START_RES, pkgname, kb, uid);
 
        if (ret > 0)
                __add_resultcb(ret, cbfunc, data, num);
@@ -340,9 +347,33 @@ void __iterate(const char *key, const char *val, void *data)
        _D("%d %s %s", i++, key, val);
 }
 
+static int __set_caller_info(bundle *kb)
+{
+       const char *caller_pid;
+       const char *caller_uid;
+
+       caller_pid = bundle_get_val(kb, AUL_K_CALLER_PID);
+       if (caller_pid == NULL) {
+               _E("Failed to get caller pid");
+               return AUL_R_EINVAL;
+       }
+
+       caller_uid = bundle_get_val(kb, AUL_K_CALLER_UID);
+       if (caller_uid == NULL) {
+               _E("Failed to get caller uid");
+               return AUL_R_EINVAL;
+       }
+
+       bundle_del(kb, AUL_K_ORG_CALLER_PID);
+       bundle_add(kb, AUL_K_ORG_CALLER_PID, caller_pid);
+       bundle_del(kb, AUL_K_ORG_CALLER_UID);
+       bundle_add(kb, AUL_K_ORG_CALLER_UID, caller_uid);
+
+       return AUL_R_OK;
+}
+
 API int aul_forward_app(const char* pkgname, bundle *kb)
 {
-       char *caller;
        int ret;
        bundle *dupb;
        bundle *outb;
@@ -351,14 +382,8 @@ API int aul_forward_app(const char* pkgname, bundle *kb)
        if (pkgname == NULL || kb == NULL)
                return AUL_R_EINVAL;
 
-       caller = (char *)bundle_get_val(kb, AUL_K_CALLER_PID);
-       if (caller == NULL) {
-               _E("original msg doest not have caller pid");
+       if (__set_caller_info(kb) < 0)
                return AUL_R_EINVAL;
-       }
-
-       bundle_del(kb, AUL_K_ORG_CALLER_PID);
-       bundle_add(kb, AUL_K_ORG_CALLER_PID, caller);
 
        dupb = bundle_dup(kb);
        if (dupb == NULL) {
@@ -402,6 +427,7 @@ API int aul_create_result_bundle(bundle *inb, bundle **outb)
 {
        const char *pid_str;
        const char *num_str;
+       const char *uid_str;
 
        *outb = NULL;
 
@@ -423,6 +449,17 @@ API int aul_create_result_bundle(bundle *inb, bundle **outb)
                _D("original msg is not msg with result");
        }
 
+       uid_str = bundle_get_val(inb, AUL_K_ORG_CALLER_UID);
+       if (uid_str == NULL)
+               uid_str = bundle_get_val(inb, AUL_K_CALLER_UID);
+
+       if (uid_str == NULL) {
+               _E("Failed to find caller uid");
+               bundle_free(*outb);
+               *outb = NULL;
+               return AUL_R_EINVAL;
+       }
+       bundle_add(*outb, AUL_K_ORG_CALLER_UID, uid_str);
 
        pid_str = bundle_get_val(inb, AUL_K_ORG_CALLER_PID);
        if (pid_str) {
index e951362..f233a1c 100755 (executable)
@@ -220,8 +220,8 @@ static int __run_svc_with_pkgname(char *pkgname, bundle *b, int request_code,
                SECURE_LOGD("pkg_name : %s - with result", pkgname);
 
                cb_info = __create_rescb(request_code, cbfunc, data);
-               ret = aul_launch_app_with_result(pkgname, b, __aul_cb,
-                               cb_info);
+               ret = aul_launch_app_with_result_for_uid(pkgname, b, __aul_cb,
+                               cb_info, uid);
        } else {
                SECURE_LOGD("pkg_name : %s - no result", pkgname);