Integration with security-manager 94/29994/11
authorZbigniew Jasinski <z.jasinski@samsung.com>
Thu, 6 Nov 2014 16:57:36 +0000 (17:57 +0100)
committerZbigniew Jasinski <z.jasinski@samsung.com>
Mon, 9 Mar 2015 13:12:49 +0000 (14:12 +0100)
* Removed dependency on libprivilege-control: perm_app_set_privilege()
  switched to security_manager_prepare_app()
* amd_session_agent gets CAP_MAC_ADMIN, CAP_MAC_OVERRIDE and CAP_SETGID for
  Smack label management
* Fix semantics - launching apps by appId

Change-Id: I408a07f2cc249b76a8c6c9928c632863358ed3ae
Signed-off-by: Zbigniew Jasinski <z.jasinski@samsung.com>
13 files changed:
CMakeLists.txt
am_daemon/amd_launch.c
am_daemon/amd_request.c
am_daemon/amd_status.c
am_session_agent/agent.c
app_launcher.c
feature/preexec.h
include/access_control.h
include/menu_db_util.h
packaging/aul.spec
src/launch.c
src/pkginfo.c
test/aul_test.c

index 54032e4..ef25a8a 100644 (file)
@@ -19,10 +19,10 @@ MESSAGE("Build type: ${CMAKE_BUILD_TYPE}")
 
 # Set required packages
 INCLUDE(FindPkgConfig)
-SET(AUL-1_PKG_CHECK_MODULES dlog libprivilege-control app-checker rua glib-2.0 vconf pkgmgr-info privacy-manager-client)
+SET(AUL-1_PKG_CHECK_MODULES dlog app-checker rua glib-2.0 vconf pkgmgr-info privacy-manager-client)
 pkg_check_modules(pkgs REQUIRED  ${AUL-1_PKG_CHECK_MODULES} )
 
-pkg_check_modules(libpkgs REQUIRED dlog bundle dbus-glib-1 ail xdgmime app-checker libtzplatform-config pkgmgr-info libsystemd-daemon)
+pkg_check_modules(libpkgs REQUIRED dlog bundle dbus-glib-1 ail xdgmime app-checker libtzplatform-config pkgmgr-info libsystemd-daemon security-manager)
 PKG_CHECK_MODULES(PKGS REQUIRED glib-2.0 gio-2.0 dlog bundle rua)
 
 FIND_LIBRARY(LIB_DL dl)
index 685699a..e695d1e 100644 (file)
@@ -669,8 +669,8 @@ int _start_app(char* appid, bundle* kb, int cmd, int caller_pid, uid_t caller_ui
                        _D("appid : %s", appid);
                        bundle_add(kb, AUL_K_PRIVACY_APPID, appid);
                        appid = PRIVACY_POPUP;
-                       bundle_del(kb, AUL_K_PKG_NAME);
-                       bundle_add(kb, AUL_K_PKG_NAME, appid);
+                       bundle_del(kb, AUL_K_APPID);
+                       bundle_add(kb, AUL_K_APPID, appid);
                        ai = appinfo_find(caller_uid, appid);
                }
        }
index a2c4697..3a9411e 100644 (file)
@@ -267,7 +267,7 @@ static gboolean __request_handler(gpointer data)
                case APP_START:
                case APP_START_RES:
                        kb = bundle_decode(pkt->data, pkt->len);
-                       appid = (char *)bundle_get_val(kb, AUL_K_PKG_NAME);
+                       appid = (char *)bundle_get_val(kb, AUL_K_APPID);
                        if (cr.uid == 0) {
                                _E("Root user request to start app assumming this is done by system deamon... Please fix it...switch to DEFAULT_USER");
                                ret = _start_app(appid, kb, pkt->cmd, cr.pid, DEFAULT_USER, clifd);
@@ -304,7 +304,7 @@ static gboolean __request_handler(gpointer data)
                case APP_KILL_BY_PID:
                case APP_TERM_REQ_BY_PID:
                        kb = bundle_decode(pkt->data, pkt->len);
-                       appid = (char *)bundle_get_val(kb, AUL_K_PKG_NAME);
+                       appid = (char *)bundle_get_val(kb, AUL_K_APPID);
                        ret = __app_process_by_pid(pkt->cmd, appid, &cr);
                        __real_send(clifd, ret);
                        break;
index e94b9ed..921accc 100644 (file)
@@ -264,7 +264,7 @@ static int __get_pkginfo(const char *dname, const char *cmdline, void *priv,uid_
        else {
                strncat(r_info, dname, 8);
                strncat(r_info, ":", 1);
-               strncat(r_info, _get_pkgname(menu_info), MAX_PACKAGE_STR_SIZE);
+               strncat(r_info, _get_appid(menu_info), MAX_PACKAGE_STR_SIZE);
                strncat(r_info, ":", 1);
                strncat(r_info, _get_app_path(menu_info), MAX_PACKAGE_APP_PATH_SIZE);
                strncat(r_info, ";", 1);
@@ -309,7 +309,7 @@ int _status_send_running_appinfo_v2(int fd)
        return 0;
 }
 
-static int __get_pkgname_bypid(int pid, char *pkgname, int len)
+static int __get_appid_bypid(int pid, char *appid, int len)
 {
        char *cmdline;
        app_info_from_db *menu_info;
@@ -326,7 +326,7 @@ static int __get_pkgname_bypid(int pid, char *pkgname, int len)
                free(cmdline);
                return -1;
        } else {
-               snprintf(pkgname, len, "%s", _get_pkgname(menu_info));
+               snprintf(appid, len, "%s", _get_appid(menu_info));
        }
 
        free(cmdline);
@@ -352,7 +352,7 @@ int _status_get_appid_bypid(int fd, int pid)
 
        pkt->cmd = APP_GET_APPID_BYPID_ERROR;
 
-       if (__get_pkgname_bypid(pid, (char *)pkt->data, MAX_PACKAGE_STR_SIZE) == 0) {
+       if (__get_appid_bypid(pid, (char *)pkt->data, MAX_PACKAGE_STR_SIZE) == 0) {
                SECURE_LOGD("appid for %d is %s", pid, pkt->data);
                pkt->cmd = APP_GET_APPID_BYPID_OK;
                goto out;
@@ -364,7 +364,7 @@ int _status_get_appid_bypid(int fd, int pid)
                goto out;
 
        _D("second change pgid = %d, pid = %d", pgid, pid);
-       if (__get_pkgname_bypid(pgid, (char *)pkt->data, MAX_PACKAGE_STR_SIZE) == 0)
+       if (__get_appid_bypid(pgid, (char *)pkt->data, MAX_PACKAGE_STR_SIZE) == 0)
                pkt->cmd = APP_GET_APPID_BYPID_OK;
 
  out:
index 817dedf..ab8851c 100644 (file)
@@ -68,7 +68,7 @@ static bool loop_flag = TRUE;
 
 _static_ void __set_oom();
 _static_ void __set_env(app_info_from_db * menu_info, bundle * kb);
-_static_ int __prepare_exec(const char *pkg_name,
+_static_ int __prepare_exec(const char *appId,
                            const char *app_path, app_info_from_db * menu_info,
                            bundle * kb);
 _static_ int __fake_launch_app(int cmd, int pid, bundle * kb);
@@ -114,8 +114,6 @@ _static_ void __set_env(app_info_from_db * menu_info, bundle * kb)
 {
        const char *str;
 
-       setenv("PKG_NAME", _get_pkgname(menu_info), 1);
-
        str = bundle_get_val(kb, AUL_K_STARTTIME);
        if (str != NULL)
                setenv("APP_START_TIME", str, 1);
@@ -124,7 +122,7 @@ _static_ void __set_env(app_info_from_db * menu_info, bundle * kb)
                setenv("HWACC", menu_info->hwacc, 1);
 }
 
-_static_ int __prepare_exec(const char *pkg_name,
+_static_ int __prepare_exec(const char *appId,
                            const char *app_path, app_info_from_db * menu_info,
                            bundle * kb)
 {
@@ -137,15 +135,15 @@ _static_ int __prepare_exec(const char *pkg_name,
        /* TODO : should be add to check permission in the kernel*/
        setsid();
 
-       __preexec_run(menu_info->pkg_type, pkg_name, app_path);
+       __preexec_run(menu_info->pkg_type, appId, app_path);
 
        /* SET OOM*/
        __set_oom();
 
        /* SET PRIVILEGES*/
        if(bundle_get_val(kb, AUL_K_PRIVACY_APPID) == NULL) {
-                _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("appId: %s / pkg_type : %s / app_path : %s ", appId, menu_info->pkg_type, app_path);
+               if ((ret = __set_access(appId, menu_info->pkg_type, app_path)) != 0) {
                         _D("fail to set privileges - check your package's credential : %d\n", ret);
              return -1;
                }
@@ -339,7 +337,7 @@ static inline 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)
 {
-       bundle_del(kb, AUL_K_PKG_NAME);
+       bundle_del(kb, AUL_K_APPID);
        bundle_del(kb, AUL_K_EXEC);
        bundle_del(kb, AUL_K_PACKAGETYPE);
        bundle_del(kb, AUL_K_HWACC);
@@ -556,8 +554,8 @@ _static_ void __send_result_to_caller(int clifd, int ret)
        return;
 }
 
-static app_info_from_db *_get_app_info_from_bundle_by_pkgname(
-                                                       const char *pkgname, bundle *kb)
+static app_info_from_db *_get_app_info_from_bundle_by_appid(
+                                                       const char *appid, bundle *kb)
 {
        app_info_from_db *menu_info;
 
@@ -566,7 +564,7 @@ static app_info_from_db *_get_app_info_from_bundle_by_pkgname(
                return NULL;
        }
 
-       menu_info->pkg_name = strdup(pkgname);
+       menu_info->appid = strdup(appid);
        menu_info->app_path = strdup(bundle_get_val(kb, AUL_K_EXEC));
        if (menu_info->app_path != NULL)
                menu_info->original_app_path = strdup(menu_info->app_path);
@@ -599,7 +597,7 @@ _static_ void __agent_main_loop(int main_fd)
        app_pkt_t *pkt = NULL;
        app_info_from_db *menu_info = NULL;
 
-       const char *pkg_name = NULL;
+       const char *appId = NULL;
        const char *app_path = NULL;
        int pid = -1;
        int uid = -1;
@@ -626,8 +624,8 @@ _static_ void __agent_main_loop(int main_fd)
        INIT_PERF(kb);
        PERF("packet processing start");
 
-       pkg_name = bundle_get_val(kb, AUL_K_PKG_NAME);
-       SECURE_LOGD("pkg name : %s\n", pkg_name);
+       appId = bundle_get_val(kb, AUL_K_APPID);
+       SECURE_LOGD("appId : %s\n", appId);
 
        /* get caller uid and check if not coming from someone else than AMD */
        uid = __get_caller_uid(kb);
@@ -641,7 +639,7 @@ _static_ void __agent_main_loop(int main_fd)
                goto end;
        }
 
-       menu_info = _get_app_info_from_bundle_by_pkgname(pkg_name, kb);
+       menu_info = _get_app_info_from_bundle_by_appid(appId, kb);
        if (menu_info == NULL) {
                _D("package not found");
                goto end;
@@ -658,9 +656,9 @@ _static_ void __agent_main_loop(int main_fd)
        }
 
        __modify_bundle(kb, cr.pid, menu_info, pkt->cmd);
-       pkg_name = _get_pkgname(menu_info);
+       appId = _get_appid(menu_info);
 
-       _D("start %s: type=%s caller_uid=%d path=%s",pkg_name,menu_info->pkg_type,uid,app_path);
+       _D("start %s: type=%s caller_uid=%d path=%s",appId,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"))
@@ -681,10 +679,10 @@ _static_ void __agent_main_loop(int main_fd)
                        PERF("prepare exec - first done");
                        _D("lock up test log(no error) : prepare exec - first done");
 
-                       if (__prepare_exec(pkg_name, app_path,
+                       if (__prepare_exec(appId, app_path,
                                           menu_info, kb) < 0) {
                                SECURE_LOGE("preparing work fail to launch - "
-                                  "can not launch %s\n", pkg_name);
+                                  "can not launch %s\n", appId);
                                exit(-1);
                        }
 
@@ -708,7 +706,7 @@ _static_ void __agent_main_loop(int main_fd)
                        __send_app_launch_signal_dbus(pid);
                        __signal_unblock_sigchld();
 
-                       __add_history(pkg_name, app_path, pkt->data);
+                       __add_history(appId, app_path, pkt->data);
                }
        }
 
index 233b0d4..d007887 100644 (file)
@@ -164,7 +164,7 @@ int iterfunc_kill(const aul_app_info *info, void *data)
         return 0;
     if(strcmp(info->appid,data) == 0) {
         aul_kill_pid(info->pid);
-    printf("\t Kill pkg_name: %s (%d)\n", info->appid,info->pid);
+        printf("\t Kill appId: %s (%d)\n", info->appid,info->pid);
     }
     return 0;
 }
@@ -240,7 +240,7 @@ int main(int argc, char **argv)
                 if (dispRunList) {
                     break;
                 }
-                printf("\t pkg_name (PID)\n");
+                printf("\t appId (PID)\n");
                 if (aul_app_get_running_app_info(iterfunc_status, NULL)) {
                     printf("Fail to display the list of Running applications");
                     return -1;
index 1b567c4..d3baa92 100644 (file)
@@ -141,7 +141,7 @@ static inline void __preexec_init(int argc, char **argv)
        preexec_initialized = 1;
 }
 
-static inline void __preexec_run(const char *pkg_type, const char *pkg_name,
+static inline void __preexec_run(const char *pkg_type, const char *appid,
                                 const char *app_path)
 {
        GSList *iter = NULL;
@@ -155,7 +155,7 @@ static inline void __preexec_run(const char *pkg_type, const char *pkg_name,
                if (type_t) {
                        if (!strcmp(pkg_type, type_t->pkg_type)) {
                                if (type_t->dl_do_pre_exe != NULL) {
-                                       type_t->dl_do_pre_exe((char *)pkg_name,
+                                       type_t->dl_do_pre_exe((char *)appid,
                                                              (char *)app_path);
                                        _D("called dl_do_pre_exe() type: %s",
                                           pkg_type);
@@ -179,7 +179,7 @@ static inline void __preexec_init(int argc, char **argv)
 {
 }
 
-static inline void __preexec_run(const char *pkg_type, const char *pkg_name,
+static inline void __preexec_run(const char *pkg_type, const char *appid,
                                 const char *app_path)
 {
 }
index 04a4999..f9dd841 100644 (file)
  */
 
 
-#ifdef DAC_ACTIVATE
-
-#include <privilege-control.h>
 #include <tzplatform_config.h>
-#define INHOUSE_UID     tzplatform_getuid(TZ_USER_NAME);
-static inline int __set_access(const char* pkg_name, const char* pkg_type, const char* app_path)
-{
-       return perm_app_set_privilege(pkg_name, pkg_type, app_path);
-}
-
-#else
-
-static inline int __set_access(const char* pkg_name, const char* pkg_type, const char* app_path)
+#include <security-manager.h>
+static inline int __set_access(const char* appId, const char* pkg_type, const char* app_path)
 {
-       return 0;
+       return security_manager_prepare_app(appId) == SECURITY_MANAGER_SUCCESS ? 0 : -1;
 }
-
-#endif
-
-
index a61ad71..a45d450 100644 (file)
@@ -48,7 +48,7 @@
 #define AUL_RETRIEVE_SERVICE                   "x_slp_service like '?'"
 
 typedef struct {
-       char *pkg_name;         /* appid */
+       char *appid;            /* appid */
        char *app_path;         /* exec */
        char *original_app_path;        /* exec */
        char *pkg_type;         /* x_slp_packagetype */
@@ -56,9 +56,9 @@ typedef struct {
        char *pkg_id;
 } app_info_from_db;
 
-static inline char *_get_pkgname(app_info_from_db *menu_info)
+static inline char *_get_appid(app_info_from_db *menu_info)
 {
-       return menu_info ? menu_info->pkg_name : NULL;
+       return menu_info ? menu_info->appid : NULL;
 }
 
 static inline char *_get_app_path(app_info_from_db *menu_info)
@@ -101,8 +101,8 @@ static inline char *_get_original_app_path(app_info_from_db *menu_info)
 static inline void _free_app_info_from_db(app_info_from_db *menu_info)
 {
        if (menu_info != NULL) {
-               if (menu_info->pkg_name != NULL)
-                       free(menu_info->pkg_name);
+               if (menu_info->appid != NULL)
+                       free(menu_info->appid);
                if (menu_info->app_path != NULL)
                        free(menu_info->app_path);
                if (menu_info->original_app_path != NULL)
@@ -135,6 +135,7 @@ static inline app_info_from_db *_get_app_info_from_db_by_pkgname(
                return NULL;
        }
 
+
        if (getuid() != GLOBAL_USER)
                ret = pkgmgrinfo_appinfo_get_usr_appinfo(appid, getuid(), &handle);
        else
@@ -145,7 +146,7 @@ static inline app_info_from_db *_get_app_info_from_db_by_pkgname(
                return NULL;
        }
 
-       menu_info->pkg_name = strdup(appid);
+       menu_info->appid = strdup(appid);
 
        ret = pkgmgrinfo_appinfo_get_exec(handle, &exec);
        if (ret != PMINFO_R_OK)
@@ -189,7 +190,7 @@ static inline int __appinfo_func(const pkgmgrinfo_appinfo_h appinfo,
 
        ret = pkgmgrinfo_appinfo_get_appid(appinfo, &appid);
        if (ret == PMINFO_R_OK && appid) {
-               menu_info->pkg_name = strdup(appid);
+               menu_info->appid = strdup(appid);
                ret = PMINFO_R_ERROR;
        }
 
@@ -241,7 +242,7 @@ static inline app_info_from_db *_get_app_info_from_db_by_apppath_user(
                ret = pkgmgrinfo_appinfo_filter_foreach_appinfo(filter,
                                __appinfo_func, (void *)menu_info);
 
-       if ((ret != PMINFO_R_OK) || (menu_info->pkg_name  == NULL)) {
+       if ((ret != PMINFO_R_OK) || (menu_info->appid == NULL)) {
                pkgmgrinfo_appinfo_filter_destroy(filter);
                _free_app_info_from_db(menu_info);
                return NULL;
index 7ae9d72..1a1081f 100644 (file)
@@ -24,7 +24,7 @@ BuildRequires:  pkgconfig(bundle)
 BuildRequires:  pkgconfig(dlog)
 BuildRequires:  pkgconfig(ail)
 BuildRequires:  xdgmime-devel, pkgconfig(xdgmime)
-BuildRequires:  pkgconfig(libprivilege-control)
+BuildRequires:  pkgconfig(security-manager)
 BuildRequires:  pkgconfig(app-checker)
 BuildRequires:  pkgconfig(app-checker-server)
 BuildRequires:  pkgconfig(rua)
@@ -129,7 +129,7 @@ systemctl daemon-reload
 %attr(0755,root,root) %{_bindir}/aul_mime.sh
 %{_bindir}/aul_test
 %{_bindir}/app_launcher
-%{_bindir}/amd_session_agent
+%caps(cap_mac_admin,cap_mac_override,cap_setgid=ei) %{_bindir}/amd_session_agent
 %{_datadir}/aul/miregex/*
 %{_datadir}/aul/service/*
 %{_datadir}/aul/preload_list.txt
index f8be552..6ea4070 100644 (file)
@@ -271,7 +271,7 @@ SLPAPI int app_send_cmd_with_noreply(int pid, int cmd, bundle *kb)
 static void __clear_internal_key(bundle *kb)
 {
        bundle_del(kb, AUL_K_CALLER_PID);
-       bundle_del(kb, AUL_K_PKG_NAME);
+       bundle_del(kb, AUL_K_APPID);
        bundle_del(kb, AUL_K_WAIT_RESULT);
        bundle_del(kb, AUL_K_SEND_RESULT);
        bundle_del(kb, AUL_K_ARGV0);
@@ -326,19 +326,19 @@ static int __app_resume_local()
  * @brief      start caller with kb
  * @return     callee's pid
  */
-int app_request_to_launchpad(int cmd, const char *pkgname, bundle *kb)
+int app_request_to_launchpad(int cmd, const char *appid, bundle *kb)
 {
        int must_free = 0;
        int ret = 0;
 
-       SECURE_LOGD("launch request : %s", pkgname);
+       SECURE_LOGD("launch request : %s", appid);
        if (kb == NULL) {
                kb = bundle_create();
                must_free = 1;
        } else
                __clear_internal_key(kb);
 
-       bundle_add(kb, AUL_K_PKG_NAME, pkgname);
+       bundle_add(kb, AUL_K_APPID, appid);
        __set_stime(kb);
        ret = app_send_cmd(AUL_UTIL_PID, cmd, kb);
 
index 975c01e..52769b5 100644 (file)
@@ -36,7 +36,7 @@ typedef struct _internal_param_t {
        void *user_param;
 } internal_param_t;
 
-static int __get_pkgname_bypid(int pid, char *pkgname, int len);
+static int __get_appid_bypid(int pid, char *appid, int len);
 
 SLPAPI int aul_app_is_running(const char *appid)
 {
@@ -89,7 +89,7 @@ SLPAPI int aul_app_get_running_app_info(aul_app_info_iter_fn enum_fn,
        return AUL_R_OK;
 }
 
-static int __get_pkgname_bypid(int pid, char *pkgname, int len)
+static int __get_appid_bypid(int pid, char *appid, int len)
 {
        char *cmdline;
        app_info_from_db *menu_info;
@@ -103,7 +103,7 @@ static int __get_pkgname_bypid(int pid, char *pkgname, int len)
                free(cmdline);
                return -1;
        } else
-               snprintf(pkgname, len, "%s", _get_pkgname(menu_info));
+               snprintf(appid, len, "%s", _get_appid(menu_info));
 
        free(cmdline);
        _free_app_info_from_db(menu_info);
@@ -122,7 +122,7 @@ SLPAPI int aul_app_get_appid_bypid(int pid, char *appid, int len)
        int pgid;
 
        if(pid == getpid() || getuid()==0 || geteuid()==0) {
-               if (__get_pkgname_bypid(pid, appid, len) == 0) {
+               if (__get_appid_bypid(pid, appid, len) == 0) {
                        SECURE_LOGD("appid for %d is %s", pid, appid);
                        return AUL_R_OK;
                }
@@ -133,7 +133,7 @@ SLPAPI int aul_app_get_appid_bypid(int pid, char *appid, int len)
                        return AUL_R_ERROR;
 
                _D("second change pgid = %d, pid = %d", pgid, pid);
-               if (__get_pkgname_bypid(pgid, appid, len) == 0)
+               if (__get_appid_bypid(pgid, appid, len) == 0)
                        return AUL_R_OK;
 
                return AUL_R_ERROR;
index 8ce2b90..fa28579 100644 (file)
@@ -244,7 +244,7 @@ int is_run_test()
 int iterfunc(const aul_app_info *info, void *data)
 {
        printf("\t==========================\n");
-       printf("\t pkg_name: %s\n", info->appid);
+       printf("\t appid: %s\n", info->appid);
        printf("\t app_path: %s\n", info->app_path);
        printf("\t running pid: %d\n", info->pid);
        printf("\t==========================\n");
@@ -374,7 +374,7 @@ static void print_menu_db_info(const app_info_from_db *info)
        }
 
        printf("\t==========================\n");
-       printf("\t pkg_name: %s\n", info->pkg_name);
+       printf("\t appid: %s\n", info->appid);
        printf("\t app_path: %s\n", info->app_path);
        printf("\t is_minst: %d\n", 0);
        printf("\t==========================\n");