Tizen 2.4.0 rev3 SDK Public Release tizen_2.4
authorjk7744.park <jk7744.park@samsung.com>
Wed, 24 Feb 2016 09:59:32 +0000 (18:59 +0900)
committerjk7744.park <jk7744.park@samsung.com>
Wed, 24 Feb 2016 09:59:32 +0000 (18:59 +0900)
src/pkgmgr-server.c

index 3487272..0a5f2b0 100755 (executable)
@@ -300,37 +300,6 @@ static int __check_privilege_by_cookie(const char *e_cookie, int req_type)
        return ret;
 }
 
-static int __check_admin_privilege_by_cookie(const char *e_cookie)
-{
-       guchar *cookie = NULL;
-       gsize size;
-       int ret = PMINFO_R_ERROR;
-
-       if (e_cookie == NULL)   {
-               _LOGE("e_cookie is NULL!!!");
-               return PMINFO_R_ERROR;
-       }
-
-       cookie = g_base64_decode(e_cookie, &size);
-       if (cookie == NULL)     {
-               _LOGE("Unable to decode cookie!!!");
-               return PMINFO_R_ERROR;
-       }
-
-       ret = security_server_check_privilege_by_cookie((const char *)cookie, "privilege::tizen::packagemanager.admin rw", "rw");
-       if (ret == SECURITY_SERVER_API_SUCCESS)
-               ret = PMINFO_R_OK;
-
-
-       if (cookie){
-               g_free(cookie);
-               cookie = NULL;
-       }
-
-       return ret;
-}
-
-
 static int __get_position_from_pkg_type(char *pkgtype)
 {
        int i = 0;
@@ -449,13 +418,13 @@ static void __register_signal_handler(void)
 }
 
 #ifdef _APPFW_FEATURE_DRM_ENABLE
-int decrypt_pkg_cb(const char *drm_file_path, const char *decrypted_file_path, const char *cookie, int *ret)
+int decrypt_pkg_cb(const char *drm_file_path, const char *decrypted_file_path, int *ret)
 {
        __register_signal_handler();
 
        _LOGE(">> in callback >> package_manager_drm_decrypt_license is called.");
 
-       if (drm_file_path == NULL || decrypted_file_path == NULL || cookie == NULL) {
+       if (drm_file_path == NULL || decrypted_file_path == NULL) {
                _LOGE("Invalid parameter.");
                *ret = PKGMGR_R_EINVAL;
                __set_drm_busy(0);
@@ -463,14 +432,6 @@ int decrypt_pkg_cb(const char *drm_file_path, const char *decrypted_file_path, c
        }
        int retval = 0;
        const char *smack_label = "*";
-       int cookie_result = 0;
-
-       cookie_result = __check_admin_privilege_by_cookie(cookie);
-       if (cookie_result < 0){
-               _LOGE("__check_admin_privilege_by_cookie result fail[%d]", cookie_result);
-               *ret = PKGMGR_R_EPRIV;
-               return -1;
-       }
 
        retval = drm_tizen_decrypt_package(drm_file_path, strlen(drm_file_path), decrypted_file_path, strlen(decrypted_file_path));
        if (retval != 1) {
@@ -495,28 +456,19 @@ int decrypt_pkg_cb(const char *drm_file_path, const char *decrypted_file_path, c
        return 0;
 }
 
-int reg_license_cb(const char *resp_data, const char *cookie, int *ret)
+int reg_license_cb(const char *resp_data, int *ret)
 {
        __register_signal_handler();
 
        _LOGE(">> in callback >> package_manager_drm_register_license is called.");
 
-       if (resp_data == NULL || cookie == NULL) {
+       if (resp_data == NULL) {
                _LOGE("Invalid parameter.");
                *ret = PKGMGR_R_EINVAL;
                __set_drm_busy(0);
                return -1;
        }
        int retval = 0;
-       int cookie_result = 0;
-
-       cookie_result = __check_admin_privilege_by_cookie(cookie);
-       if (cookie_result < 0){
-               _LOGE("__check_admin_privilege_by_cookie result fail[%d]", cookie_result);
-               *ret = PKGMGR_R_EPRIV;
-               return -1;
-       }
-
        retval = drm_tizen_register_license(resp_data, strlen(resp_data));
        if (retval != 1) {
                _LOGE("drm_tizen_register_license is failed.");
@@ -531,13 +483,13 @@ int reg_license_cb(const char *resp_data, const char *cookie, int *ret)
        return 0;
 }
 
-int gen_license_req_cb(const char *resp_data, const char *cookie, char **req_data, char **license_url, int *ret)
+int gen_license_req_cb(const char *resp_data, char **req_data, char **license_url, int *ret)
 {
        __register_signal_handler();
 
        _LOGE(">> in callback >> package_manager_drm_generate_license_request is called.");
 
-       if (resp_data == NULL || req_data == NULL || license_url == NULL || cookie == NULL) {
+       if (resp_data == NULL || req_data == NULL || license_url == NULL) {
                _LOGE("Invalid parameter.");
                *ret = PKGMGR_R_EINVAL;
                __set_drm_busy(0);
@@ -548,15 +500,6 @@ int gen_license_req_cb(const char *resp_data, const char *cookie, char **req_dat
        unsigned int temp_req_len = sizeof(temp_req_data);
        char temp_license_url[1024] = {0,};
        unsigned int temp_license_url_len = sizeof(temp_license_url);
-       int cookie_result = 0;
-
-       cookie_result = __check_admin_privilege_by_cookie(cookie);
-       if (cookie_result < 0){
-               _LOGE("__check_admin_privilege_by_cookie result fail[%d]", cookie_result);
-               *ret = PKGMGR_R_EPRIV;
-               return -1;
-       }
-
        retval = drm_tizen_generate_license_request(resp_data, strlen(resp_data), temp_req_data, &temp_req_len, temp_license_url, &temp_license_url_len);
        if (retval != 1) {
                _LOGE("drm_tizen_generate_license_request is failed.");
@@ -648,6 +591,7 @@ void req_cb(void *cb_data, const char *req_id, const int req_type,
 
        switch (item->req_type) {
        case COMM_REQ_TO_INSTALL:
+       case COMM_REQ_TO_UNINSTALL:
                /* check caller privilege */
                cookie_result = __check_privilege_by_cookie(cookie, item->req_type);
                if (cookie_result < 0){
@@ -675,28 +619,6 @@ void req_cb(void *cb_data, const char *req_id, const int req_type,
                        g_idle_add(queue_job, NULL);
                *ret = PKGMGR_R_OK;
                break;
-       case COMM_REQ_TO_UNINSTALL:
-               /* check caller privilege */
-               cookie_result = __check_privilege_by_cookie(cookie, item->req_type);
-               if (cookie_result < 0){
-                       _LOGE("__check_privilege_by_cookie result fail[%d]", cookie_result);
-                       *ret = PKGMGR_R_EPRIV;
-                       goto err;
-               }
-
-               /* quiet mode */
-               err = _pm_queue_push(item);
-               p = __get_position_from_pkg_type(item->pkg_type);
-               if (p < 0) {
-                       _LOGE("invalid or unsupported package");
-                       *ret = PKGMGR_R_ERROR;
-                       break;
-               }
-               __set_backend_mode(p);
-               if (err == 0)
-                       g_idle_add(queue_job, NULL);
-               *ret = PKGMGR_R_OK;
-               break;
        case COMM_REQ_ACTIVATE_PKG:
                err = _pm_queue_push(item);
                p = __get_position_from_pkg_type(item->pkg_type);
@@ -755,6 +677,12 @@ void req_cb(void *cb_data, const char *req_id, const int req_type,
                *ret = PKGMGR_R_OK;
                break;
        case COMM_REQ_TO_CLEARER:
+               /* get pkgtype from msg-args */
+               if (_zone_set_type_and_backend(item, zone)) {
+                       *ret = PKGMGR_R_ERROR;
+                       goto err;
+               }
+
                /* In case of clearer, there is no popup */
                err = _pm_queue_push(item);
                p = __get_position_from_pkg_type(item->pkg_type);
@@ -776,6 +704,12 @@ void req_cb(void *cb_data, const char *req_id, const int req_type,
                        goto err;
                }
 
+               /* get pkgtype from msg-args */
+               if (_zone_set_type_and_backend(item, zone)) {
+                       *ret = PKGMGR_R_ERROR;
+                       goto err;
+               }
+
                /* In case of mover, there is no popup */
                err = _pm_queue_push(item);
                p = __get_position_from_pkg_type(item->pkg_type);
@@ -945,6 +879,7 @@ void req_tep_cb(void *cb_data, const char *req_id, const int req_type,
 
        switch (item->req_type) {
        case COMM_REQ_TO_INSTALL:
+       case COMM_REQ_TO_UNINSTALL:
                /* check caller privilege */
                cookie_result = __check_privilege_by_cookie(cookie, item->req_type);
                if (cookie_result < 0){
@@ -973,32 +908,6 @@ void req_tep_cb(void *cb_data, const char *req_id, const int req_type,
                        g_idle_add(queue_job, NULL);
                *ret = PKGMGR_R_OK;
                break;
-       case COMM_REQ_TO_UNINSTALL:
-               /* check caller privilege */
-               cookie_result = __check_privilege_by_cookie(cookie, item->req_type);
-               if (cookie_result < 0){
-                       _LOGE("__check_privilege_by_cookie result fail[%d]\n", cookie_result);
-                       *ret = PKGMGR_R_EPRIV;
-                       goto err;
-               }
-
-               _LOGE("pkg type[%s]", item->pkg_type);
-
-               /* quiet mode */
-               err = _pm_queue_push(item);
-               p = __get_position_from_pkg_type(item->pkg_type);
-               if (p < 0) {
-                       _LOGE("invalid or unsupported package");
-                       *ret = PKGMGR_R_ERROR;
-                       break;
-               }
-               __set_backend_mode(p);
-               if (err == 0)
-                       g_idle_add(queue_job, NULL);
-               *ret = PKGMGR_R_OK;
-               break;
-
-
        case COMM_REQ_ACTIVATE_PKG:
                err = _pm_queue_push(item);
                p = __get_position_from_pkg_type(item->pkg_type);
@@ -1854,7 +1763,6 @@ pop:
 
        int ret = 0;
        char *backend_cmd = NULL;
-       char **args_vector = NULL;
 
        /* queue is empty and backend process is not running */
        if ( (item == NULL) || (item->req_type == -1) ) {
@@ -1896,6 +1804,7 @@ pop:
 
                switch (item->req_type) {
                case COMM_REQ_TO_INSTALL:
+               case COMM_REQ_TO_UNINSTALL:
                        _LOGD("before run _get_backend_path(%s)", item->backend_installer);
                        backend_cmd = _get_backend_cmd(item->backend_installer);
                        if (NULL == backend_cmd) {
@@ -1910,21 +1819,13 @@ pop:
                        _LOGD("Try to exec [%s][%s]", item->pkg_type, backend_cmd);
                        fprintf(stdout, "Try to exec [%s][%s]\n", item->pkg_type, backend_cmd);
 
-                       args_vector = __generate_argv(item->args);
+                       char **args_vector = __generate_argv(item->args);
                        args_vector[0] = backend_cmd;
 
                        /* Execute backend !!! */
                        __exec_with_arg_vector(backend_cmd, args_vector, item->zone);
                        free(backend_cmd);
                        break;
-               case COMM_REQ_TO_UNINSTALL:
-                       args_vector = __generate_argv(item->args);
-
-                       _LOGD("Try to exec [%s][%s]", item->pkg_type, args_vector[0]);
-                       fprintf(stdout, "Try to exec [%s][%s]\n", item->pkg_type, args_vector[0]);
-
-                       /* Execute backend !!! */
-                       __exec_with_arg_vector(args_vector[0], args_vector, item->zone);
                case COMM_REQ_ACTIVATE_PKG:
                        _LOGE("ACTIVATE_PKG start [pkgid = %s]",item->pkgid);
 
@@ -2040,13 +1941,25 @@ pop:
                        break;
                case COMM_REQ_TO_MOVER:
                case COMM_REQ_TO_CLEARER:
-                       args_vector = __generate_argv(item->args);
+                       _LOGD("before run _get_backend_path()");
+                       backend_cmd = _get_backend_cmd(item->backend_installer);
+                       if (!backend_cmd) {
+                               backend_cmd = _get_backend_cmd(item->pkg_type);
+                               if (!backend_cmd) {
+                                       _LOGE("failed to get backend cmd");
+                                       break;
+                               }
+                       }
 
-                       _LOGD("Try to exec [%s][%s]", item->pkg_type, args_vector[0]);
-                       fprintf(stdout, "Try to exec [%s][%s]\n", item->pkg_type, args_vector[0]);
+                       _LOGD("Try to exec [%s][%s]", item->pkg_type, backend_cmd);
+                       fprintf(stdout, "Try to exec [%s][%s]\n", item->pkg_type, backend_cmd);
+
+                       char **args_vectors = __generate_argv(item->args);
+                       args_vectors[0] = backend_cmd;
 
                        /* Execute backend !!! */
-                       __exec_with_arg_vector(args_vector[0], args_vector, item->zone);
+                       __exec_with_arg_vector(backend_cmd, args_vectors, item->zone);
+                       free(backend_cmd);
                        break;
                case COMM_REQ_GET_SIZE:
                        __exec_with_arg_vector("usr/bin/pkg_getsize", __generate_argv(item->args), item->zone);