Retrieve tizenglobalapp uid with tzplatform_getuid 19/27619/1
authorSabera Djelti (sdi2) <sabera.djelti@open.eurogiciel.org>
Tue, 2 Sep 2014 16:11:01 +0000 (18:11 +0200)
committerBaptiste DURAND <baptiste.durand@open.eurogiciel.org>
Tue, 16 Sep 2014 17:07:37 +0000 (19:07 +0200)
+ Remove checking root group of tizenglobalapp
+fix require root permission for doing chown/chmod

change-Id: I3a97eeaea544f0cf8431c0028224dafeca8306a0
Signed-off-by: Sabera Djelti (sdi2) <sabera.djelti@open.eurogiciel.org>
CMakeLists.txt
ail.pc.in
include/ail.h
src/ail_db.c
src/ail_desktop.c
tool/src/ail_fota.c
tool/src/initdb.c

index 2c3fafe..bb44991 100644 (file)
@@ -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")
index 9588775..0ca14cc 100644 (file)
--- 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@
index 3a04b79..def4027 100755 (executable)
@@ -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)
index 474f453..1a3ac89 100755 (executable)
 #include <pwd.h>
 #include <sys/smack.h>
 #include <sys/stat.h>
+#include <tzplatform_config.h>
 #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 ))) {
index 8b7ff72..82d2067 100755 (executable)
@@ -30,6 +30,7 @@
 #include <time.h>
 #include <sys/types.h>
 #include <sys/wait.h>
+#include <tzplatform_config.h>
 #include <xdgmime.h>
 
 #include <vconf.h>
@@ -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;
index 85aa973..bd20e5f 100644 (file)
@@ -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;
index 2743b34..20bf543 100755 (executable)
@@ -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;