From 6c8dca2ee68a7874a6d7818c9796a91684d9aacf Mon Sep 17 00:00:00 2001 From: "Sabera Djelti (sdi2)" Date: Tue, 2 Sep 2014 18:11:01 +0200 Subject: [PATCH] Retrieve tizenglobalapp uid with tzplatform_getuid + Remove checking root group of tizenglobalapp +fix require root permission for doing chown/chmod change-Id: I3a97eeaea544f0cf8431c0028224dafeca8306a0 Signed-off-by: Sabera Djelti (sdi2) --- CMakeLists.txt | 3 +++ ail.pc.in | 2 +- include/ail.h | 2 +- src/ail_db.c | 56 ++++++++++++++++------------------------------------- src/ail_desktop.c | 5 +++-- tool/src/ail_fota.c | 2 +- tool/src/initdb.c | 2 +- 7 files changed, 27 insertions(+), 45 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2c3fafe..bb44991 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -33,6 +33,9 @@ INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include) INCLUDE(FindPkgConfig) +pkg_check_modules(LDPC REQUIRED libtzplatform-config) + + pkg_check_modules(LPKGS REQUIRED glib-2.0 sqlite3 dlog db-util xdgmime vconf libtzplatform-config libsmack) STRING(REPLACE ";" " " EXTRA_CFLAGS "${LPKGS_CFLAGS}") SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fvisibility=hidden") diff --git a/ail.pc.in b/ail.pc.in index 9588775..0ca14cc 100644 --- a/ail.pc.in +++ b/ail.pc.in @@ -7,5 +7,5 @@ Name: ail Description: Application Information Library Version: @VERSION@ Requires: sqlite3 vconf dlog db-util -Libs: -L@LIBDIR@ -lail +Libs: -L@LIBDIR@ -lail -l@LDPC_LIBRARIES@ Cflags: -I@INCLUDEDIR@ diff --git a/include/ail.h b/include/ail.h index 3a04b79..def4027 100755 --- a/include/ail.h +++ b/include/ail.h @@ -33,7 +33,7 @@ #define OWNER_ROOT 0 #define GROUP_MENU 6010 -#define GLOBAL_USER 0 //tzplatform +#define GLOBAL_USER tzplatform_getuid(TZ_SYS_GLOBALAPP_USER) #define BUFSZE 1024 #define OPT_DESKTOP_DIRECTORY tzplatform_getenv(TZ_SYS_RW_DESKTOP_APP) #define USR_DESKTOP_DIRECTORY tzplatform_getenv(TZ_SYS_RO_DESKTOP_APP) diff --git a/src/ail_db.c b/src/ail_db.c index 474f453..1a3ac89 100755 --- a/src/ail_db.c +++ b/src/ail_db.c @@ -31,10 +31,11 @@ #include #include #include +#include #include "ail_private.h" #include "ail_db.h" -#define GLOBAL_USER 0 //#define tzplatform_getenv(TZ_GLOBAL) //TODO +#define GLOBAL_USER tzplatform_getuid(TZ_SYS_GLOBALAPP_USER) #define BUFSIZE 4096 #define QUERY_ATTACH "attach database '%s' as Global" #define QUERY_CREATE_VIEW_APP "CREATE temp VIEW app_info as select distinct * from (select * from main.app_info m union select * from Global.app_info g)" @@ -137,23 +138,16 @@ char* ail_get_icon_path(uid_t uid) asprintf(&result, "%s/.applications/icons/", userinfo->pw_dir); } else { result = tzplatform_mkpath(TZ_SYS_RW_ICONS, "/"); - grpinfo = getgrnam("root"); - if (grpinfo == NULL) { - _E("getgrnam(root) returns NULL !"); - return NULL; - } - if (grpinfo->gr_gid != userinfo->pw_gid) { - _E("UID [%d] does not belong to 'root' group!", uid); - return NULL; - } } 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 (getuid() == OWNER_ROOT) { + 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; } @@ -185,15 +179,6 @@ static char* ail_get_app_DB(uid_t uid) asprintf(&result, "%s/.applications/dbspace/.app_info.db", userinfo->pw_dir); asprintf(&journal, "%s/.applications/dbspace/.app_info.db-journal", userinfo->pw_dir); } else { - grpinfo = getgrnam("root"); - if (grpinfo == NULL) { - _E("getgrnam(root) returns NULL !"); - return NULL; - } - if (grpinfo->gr_gid != userinfo->pw_gid) { - _E("UID [%d] does not belong to 'root' group!", uid); - return NULL; - } result = strdup(APP_INFO_DB_FILE); journal = strdup(APP_INFO_DB_FILE_JOURNAL); } @@ -208,12 +193,14 @@ static char* ail_get_app_DB(uid_t uid) if ((uid != GLOBAL_USER)||((uid == GLOBAL_USER)&& (geteuid() == 0 ))) { int ret; mkdir(temp, 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 (getuid() == OWNER_ROOT) { + 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); + } + } } free(temp); return result; @@ -244,15 +231,6 @@ char* al_get_desktop_path(uid_t uid) } asprintf(&result, "%s/.applications/desktop/", userinfo->pw_dir); } else { - grpinfo = getgrnam("root"); - if (grpinfo == NULL) { - _E("getgrnam(root) returns NULL !"); - return NULL; - } - if (grpinfo->gr_gid != userinfo->pw_gid) { - _E("UID [%d] does not belong to 'root' group!", uid); - return NULL; - } result = tzplatform_mkpath(TZ_SYS_RW_DESKTOP_APP, "/"); } if ((uid != GLOBAL_USER)||((uid == GLOBAL_USER)&& (geteuid() == 0 ))) { diff --git a/src/ail_desktop.c b/src/ail_desktop.c index 8b7ff72..82d2067 100755 --- a/src/ail_desktop.c +++ b/src/ail_desktop.c @@ -30,6 +30,7 @@ #include #include #include +#include #include #include @@ -43,7 +44,7 @@ #include "ail.h" #define BUFSIZE 4096 -#define GLOBAL_USER 0 +#define GLOBAL_USER tzplatform_getuid(TZ_SYS_GLOBALAPP_USER) #define whitespace(c) (((c) == ' ') || ((c) == '\t')) #define argsdelimiter " \t" @@ -1635,7 +1636,7 @@ static void _fini_desktop_info(desktop_info_s *info) static int __is_authorized() { uid_t uid = getuid(); - if ((uid_t) 0 == uid ) + if ((uid_t) GLOBAL_USER == uid ) return 1; else return 0; diff --git a/tool/src/ail_fota.c b/tool/src/ail_fota.c index 85aa973..bd20e5f 100644 --- a/tool/src/ail_fota.c +++ b/tool/src/ail_fota.c @@ -193,7 +193,7 @@ static int __is_authorized() /* ail_init db should be called by as root privilege. */ uid_t uid = getuid(); - if ((uid_t) 0 == uid) + if ((uid_t) GLOBAL_USER == uid) return 1; else return 0; diff --git a/tool/src/initdb.c b/tool/src/initdb.c index 2743b34..20bf543 100755 --- a/tool/src/initdb.c +++ b/tool/src/initdb.c @@ -190,7 +190,7 @@ static int __is_authorized() /* ail_init db should be called by as root privilege. */ uid_t uid = getuid(); - if ((uid_t) 0 == uid) + if ((uid_t) GLOBAL_USER == uid) return 1; else return 0; -- 2.7.4