Clean Code 34/26734/1 accepted/tizen/common/20140828.155327 submit/tizen_common/20140828.122453 submit/tizen_ivi/20140829.000000
authorBaptiste DURAND <baptiste.durand@open.eurogiciel.org>
Thu, 28 Aug 2014 11:54:25 +0000 (13:54 +0200)
committerBaptiste DURAND <baptiste.durand@open.eurogiciel.org>
Thu, 28 Aug 2014 11:54:25 +0000 (13:54 +0200)
Adapt level trace
And check if process is allowed to set chsmak label
Fix Icon Path management

Change-Id: I1afa7df5000fa4acf6d5e0c19a90a2e5c949d162
Signed-off-by: Baptiste DURAND <baptiste.durand@open.eurogiciel.org>
src/ail_db.c
src/ail_desktop.c

index 46652ea..69eea1c 100755 (executable)
@@ -205,30 +205,33 @@ static char* ail_get_app_DB(uid_t uid)
                        result = strdup(APP_INFO_DB_FILE);
                        journal = strdup(APP_INFO_DB_FILE_JOURNAL);
                        /* chsmack */
-                       if (smack_setlabel(result, SMACK_LABEL, SMACK_LABEL_ACCESS)) {
-                               _E("failed chsmack -a \"%s\" %s", SMACK_LABEL, result);
-               } else {
-                       _D("chsmack -a \"%s\" %s", SMACK_LABEL, result);
-               }
-               if (smack_setlabel(journal, SMACK_LABEL, SMACK_LABEL_ACCESS)) {
-                       _E("failed chsmack -a \"%s\" %s", SMACK_LABEL, journal);
-               } else {
-                       _D("chsmack -a \"%s\" %s", SMACK_LABEL, journal);
-               }
+                       /*Check if we have permission to do it*/
+                       if (geteuid() == 0) {
+                               if (smack_setlabel(result, SMACK_LABEL, SMACK_LABEL_ACCESS)) {
+                                       _E("failed chsmack -a \"%s\" %s", SMACK_LABEL, result);
+                               } else {
+                                       _D("chsmack -a \"%s\" %s", SMACK_LABEL, result);
+                               }
+                               if (smack_setlabel(journal, SMACK_LABEL, SMACK_LABEL_ACCESS)) {
+                                       _E("failed chsmack -a \"%s\" %s", SMACK_LABEL, journal);
+                               } else {
+                                       _D("chsmack -a \"%s\" %s", SMACK_LABEL, journal);
+                               }
+                       }
        }
        dir = strrchr(result, '/');
        if(!dir)
                return result;
-
-       int ret;
-       mkdir(dir + 1, S_IRWXU | S_IRGRP | S_IXGRP | S_IXOTH);
-       ret = chown(dir + 1, uid, grpinfo->gr_gid);
-       if (ret == -1) {
-               char buf[BUFSIZE];
-               strerror_r(errno, buf, sizeof(buf));
-               _E("FAIL : chown %s %d.%d, because %s", dir + 1, uid, grpinfo->gr_gid, buf);
+       if ((uid != GLOBAL_USER)||((uid == GLOBAL_USER)&& (geteuid() == 0 ))) {
+               int ret;
+               mkdir(dir + 1, S_IRWXU | S_IRGRP | S_IXGRP | S_IXOTH);
+               ret = chown(dir + 1, uid, grpinfo->gr_gid);
+               if (ret == -1) {
+                       char buf[BUFSIZE];
+                       strerror_r(errno, buf, sizeof(buf));
+                       _E("FAIL : chown %s %d.%d, because %s", dir + 1, uid, grpinfo->gr_gid, buf);
+               }
        }
-
        return result;
 }
 
@@ -274,14 +277,15 @@ char* al_get_desktop_path(uid_t uid)
                        _D("chsmack -a \"%s\" %s", SMACK_LABEL, result);
                }
        }
-
-       int ret;
-       mkdir(result, S_IRWXU | S_IRGRP | S_IXGRP | S_IXOTH);
-       ret = chown(result, uid, grpinfo->gr_gid);
-       if (ret == -1) {
-               char buf[BUFSIZE];
-               strerror_r(errno, buf, sizeof(buf));
-               _E("FAIL : chown %s %d.%d, because %s", result, uid, grpinfo->gr_gid, buf);
+       if ((uid != GLOBAL_USER)||((uid == GLOBAL_USER)&& (geteuid() == 0 ))) {
+               int ret;
+               mkdir(result, S_IRWXU | S_IRGRP | S_IXGRP | S_IXOTH);
+               ret = chown(result, uid, grpinfo->gr_gid);
+               if (ret == -1) {
+                       char buf[BUFSIZE];
+                       strerror_r(errno, buf, sizeof(buf));
+                       _E("FAIL : chown %s %d.%d, because %s", result, uid, grpinfo->gr_gid, buf);
+               }
        }
        return result;
 }
@@ -376,18 +380,18 @@ ail_error_e db_open(db_open_mode mode, uid_t uid)
                                char query_view_app[AIL_SQL_QUERY_MAX_LEN];
                                char query_view_local[AIL_SQL_QUERY_MAX_LEN];
                                snprintf(query_attach, AIL_SQL_QUERY_MAX_LEN, QUERY_ATTACH, ail_get_app_DB(GLOBAL_USER));
-                               _E("info : execute query_attach : %s", query_attach );
+                               _D("info : execute query_attach : %s", query_attach );
                                if (db_exec_usr_ro(query_attach) < 0) {
                                        return AIL_ERROR_DB_FAILED;
                                }
                                snprintf(query_view_app, AIL_SQL_QUERY_MAX_LEN, QUERY_CREATE_VIEW_APP);
-                               _E("info : execute query_attach : %s", query_view_app );
+                               _D("info : execute query_attach : %s", query_view_app );
                                if (db_exec_usr_ro(query_view_app) < 0) {
                                        return AIL_ERROR_DB_FAILED;
                                }
 
                                snprintf(query_view_local, AIL_SQL_QUERY_MAX_LEN, QUERY_CREATE_VIEW_LOCAL);
-                               _E("info : execute query_attach : %s", query_view_local );
+                               _D("info : execute query_attach : %s", query_view_local );
                                if (db_exec_usr_ro(query_view_local) < 0) {
                                        return AIL_ERROR_DB_FAILED;
                                }
index 3868b79..8b7ff72 100755 (executable)
@@ -252,6 +252,7 @@ _get_icon_with_path(char* icon, uid_t uid)
                char* theme = NULL;
                char* icon_with_path = NULL;
                int len;
+               char *app_path = NULL;
 
                package = _get_package_from_icon(icon);
                retv_if(!package, NULL);
@@ -284,17 +285,17 @@ _get_icon_with_path(char* icon, uid_t uid)
                        sqlite3_snprintf( len, icon_with_path, "%s%q", ail_get_icon_path(uid), icon);
                else
                        sqlite3_snprintf( len, icon_with_path, "%s/%q/small/%q", ail_get_icon_path(GLOBAL_USER), theme, icon);
-               if (!access (icon_with_path, F_OK))
-                       sqlite3_snprintf( len, icon_with_path, "%s/%q/res/icons/%q/small/%q", tzplatform_getenv(TZ_SYS_RO_APP), package, theme, icon);
-               else if (!access (icon_with_path, F_OK))
-                       sqlite3_snprintf( len, icon_with_path, "%s/%q/res/icons/%q/small/%q", tzplatform_getenv(TZ_SYS_RW_APP), package, theme, icon);
-               else
-                       _D("Cannot find icon path");
+                       
+               if (access (icon_with_path, F_OK)) {
+                       app_path = tzplatform_getenv(TZ_SYS_RW_APP);
+                       if (app_path)
+                               sqlite3_snprintf( len, icon_with_path, "%s/%q/res/icons/%q/small/%q",app_path, package, theme, icon);
+                       if (access (icon_with_path, F_OK))
+                               _E("Cannot find icon path");
+               }
                free(theme);
                free(package);
                _D("Icon path : %s", icon_with_path);
-
-
                return icon_with_path;
        } else {
                char* confirmed_icon = NULL;