Add multi User features 03/22003/2 submit/tizen_common/20140528.173953
authorBaptiste DURAND <baptiste.durand@open.eurogiciel.org>
Fri, 11 Apr 2014 08:46:34 +0000 (10:46 +0200)
committerBaptiste DURAND <baptiste.durand@open.eurogiciel.org>
Wed, 28 May 2014 15:01:42 +0000 (17:01 +0200)
Change-Id: I94a850f64e029ff09959a9d210ed76a878949b0e
Signed-off-by: Baptiste DURAND <baptiste.durand@open.eurogiciel.org>
Signed-off-by: Corentin Lecouvey <corentin.lecouvey@open.eurogiciel.org>
include/ail.h
initdb/src/initdb.c
src/ail_db.c
src/ail_desktop.c
tool/src/ail_fota.c
tool/src/initdb.c

index 1a81250..fab4ff9 100755 (executable)
 #define __AIL_H__
 
 #include <stdbool.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <pwd.h>
+#include <tzplatform_config.h>
+#define OWNER_ROOT 0
+#define GROUP_MENU 6010
+#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)
+#define APP_INFO_DB_FILE tzplatform_mkpath(TZ_SYS_DB,".app_info.db")
+#define APP_INFO_DB_FILE_JOURNAL tzplatform_mkpath(TZ_SYS_DB,".app_info.db-journal")
+#define APP_INFO_DB_LABEL "ail::db"
 
 #ifdef __cplusplus
 extern "C" {
index 4d58945..673ca7d 100755 (executable)
 #include "ail.h"
 #include "ail_private.h"
 
-#define OWNER_ROOT 0
-#define GROUP_MENU 6010
-#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)
-#define APP_INFO_DB_FILE tzplatform_mkpath(TZ_SYS_DB,".app_info.db")
-#define APP_INFO_DB_FILE_JOURNAL tzplatform_mkpath(TZ_SYS_DB,".app_info.db-journal")
-#define APP_INFO_DB_LABEL "ail::db"
 
 #ifdef _E
 #undef _E
@@ -244,15 +236,15 @@ int main(int argc, char *argv[])
 
        if (!__is_authorized()) {
                fprintf(stderr, "You are not an authorized user!\n");
-               _D("You are not an authorized user!\n");
-               return AIL_ERROR_FAIL;
-       }
+               _D("You are not root user!\n");
 
+    }
+    else {
        const char *argv_rm[] = { "/bin/rm", APP_INFO_DB_FILE, NULL };
        xsystem(argv_rm);
        const char *argv_rmjn[] = { "/bin/rm", APP_INFO_DB_FILE_JOURNAL, NULL };
        xsystem(argv_rmjn);
-
+    }
        ret = setenv("AIL_INITDB", "1", 1);
        _D("AIL_INITDB : %d", ret);
 
@@ -271,15 +263,18 @@ int main(int argc, char *argv[])
                _E("cannot load usr desktop directory.");
        }
 
+
+#ifdef WRT_SMACK_ENABLED
+if (__is_authorized()) {
        ret = initdb_change_perm(APP_INFO_DB_FILE);
        if (ret == AIL_ERROR_FAIL) {
                _E("cannot chown.");
        }
-#ifdef WRT_SMACK_ENABLED
        const char *argv_smack[] = { "/usr/bin/chsmack", "-a", APP_INFO_DB_LABEL, APP_INFO_DB_FILE, NULL };
        xsystem(argv_smack);
        const char *argv_smackjn[] = { "/usr/bin/chsmack", "-a", APP_INFO_DB_LABEL, APP_INFO_DB_FILE_JOURNAL, NULL };
        xsystem(argv_smackjn);
+}
 #endif
        return AIL_ERROR_OK;
 }
index 8f24689..4b2dafa 100755 (executable)
@@ -48,6 +48,13 @@ static __thread struct {
        .dbrw = NULL
 };
 
+static char* getUserAppDB(void) 
+{
+  if(getuid())
+    return tzplatform_mkpath(TZ_USER_HOME, ".applications/dbspace/.app_info.db"); 
+   else 
+    return APP_INFO_DB_FILE;
+}
 
 static ail_error_e db_do_prepare(sqlite3 *db, const char *query, sqlite3_stmt **stmt)
 {
@@ -73,14 +80,14 @@ ail_error_e db_open(db_open_mode mode)
        if(mode & DB_OPEN_RO) {
                if (!db_info.dbro) {
                        //ret = db_util_open_with_options(APP_INFO_DB, &db_info.dbro, SQLITE_OPEN_READONLY, NULL);
-                       ret = db_util_open(APP_INFO_DB, &db_info.dbro, 0);
+                       ret = db_util_open(getUserAppDB(), &db_info.dbro, 0);
                        retv_with_dbmsg_if(ret != SQLITE_OK, AIL_ERROR_DB_FAILED);
                }
        }
 
        if(mode & DB_OPEN_RW) {
                if (!db_info.dbrw) {
-                       ret = db_util_open(APP_INFO_DB, &db_info.dbrw, 0);
+                       ret = db_util_open(getUserAppDB(), &db_info.dbrw, 0);
                        retv_with_dbmsg_if(ret != SQLITE_OK, AIL_ERROR_DB_FAILED);
                }
        }
index 6fd4fa1..d79e288 100755 (executable)
@@ -39,8 +39,6 @@
 #include "ail_sql.h"
 #include "ail.h"
 
-#define OPT_DESKTOP_DIRECTORY "/opt/share/applications"
-#define USR_DESKTOP_DIRECTORY "/usr/share/applications"
 #define BUFSZE 4096
 
 #define whitespace(c) (((c) == ' ') || ((c) == '\t'))
@@ -790,25 +788,30 @@ static int _count_all(void)
        return count;
 }
 
-
-
 char *_pkgname_to_desktop(const char *package)
 {
        char *desktop;
+  char *desktop_path;
        int size;
 
        retv_if(!package, NULL);
 
-       size = strlen(OPT_DESKTOP_DIRECTORY) + strlen(package) + 10;
+       if(getuid() > 0)
+  {
+    desktop_path = tzplatform_mkpath(TZ_USER_HOME, ".applications/desktop");
+  }
+  else
+  {
+    desktop_path = tzplatform_getenv(TZ_SYS_RW_DESKTOP_APP);
+  }
+
+       size = strlen(desktop_path) + strlen(package) + 10;
        desktop = malloc(size);
        retv_if(!desktop, NULL);
 
-       snprintf(desktop, size, OPT_DESKTOP_DIRECTORY"/%s.desktop", package);
-
-       if (access(desktop, R_OK) == 0)
-               return desktop;
+  snprintf(desktop, size, "%s/%s.desktop", desktop_path, package);
 
-       snprintf(desktop, size, USR_DESKTOP_DIRECTORY"/%s.desktop", package);
+  _D("uid: %d / desktop: [%s]\n",  getuid(), desktop);
 
        return desktop;
 }
@@ -943,13 +946,13 @@ int __is_ail_initdb(void)
                return 0;
 }
 
-
-
 /* Manipulating desktop_info functions */
 static ail_error_e _init_desktop_info(desktop_info_s *info, const char *package)
 {
        static int is_initdb = -1;
 
+  _D("package - [%s].", package);
+
        if(is_initdb == -1)
                is_initdb = __is_ail_initdb();
 
@@ -985,6 +988,8 @@ static ail_error_e _init_desktop_info(desktop_info_s *info, const char *package)
        info->desktop = _pkgname_to_desktop(package);
        retv_if(!info->desktop, AIL_ERROR_FAIL);
 
+  _D("desktop - [%s].", info->desktop);
+
        return AIL_ERROR_OK;
 }
 
@@ -1575,7 +1580,6 @@ static ail_error_e _clean_pkgid_data(const char* pkgid)
        return AIL_ERROR_OK;
 }
 
-
 static ail_error_e _send_db_done_noti(noti_type type, const char *package)
 {
        char *type_string, *noti_string;
@@ -1597,11 +1601,11 @@ static ail_error_e _send_db_done_noti(noti_type type, const char *package)
                        return AIL_ERROR_FAIL;
        }
 
-       size = strlen(package) + 8;
-       noti_string = calloc(1, size);
+       size = snprintf(NULL, 0, "%s:%s:%u", type_string, package, getuid());
+       noti_string = (char*) calloc(size + 1, sizeof(char));
        retv_if(!noti_string, AIL_ERROR_OUT_OF_MEMORY);
 
-       snprintf(noti_string, size, "%s:%s", type_string, package);
+       snprintf(noti_string, size + 1, "%s:%s:%u", type_string, package, getuid());
        vconf_set_str(VCONFKEY_AIL_INFO_STATE, noti_string);
        vconf_set_str(VCONFKEY_MENUSCREEN_DESKTOP, noti_string); // duplicate, will be removed
        _D("Noti : %s", noti_string);
@@ -1672,10 +1676,6 @@ EXPORT_API ail_error_e ail_desktop_add(const char *appid)
        int count;
 
        retv_if(!appid, AIL_ERROR_INVALID_PARAMETER);
-       if (!__is_authorized()) {
-               _E("You are not an authorized user on adding!\n");
-               return -1;
-       }
 
        count = _count_all();
        if (count <= 0) {
@@ -1684,7 +1684,6 @@ EXPORT_API ail_error_e ail_desktop_add(const char *appid)
                        _D("Cannot create a table. Maybe there is already a table.");
                }
        }
-
        ret = _init_desktop_info(&info, appid);
        retv_if(ret != AIL_ERROR_OK, AIL_ERROR_FAIL);
 
@@ -1710,10 +1709,6 @@ EXPORT_API ail_error_e ail_desktop_update(const char *appid)
        ail_error_e ret;
 
        retv_if(!appid, AIL_ERROR_INVALID_PARAMETER);
-       if (!__is_authorized()) {
-               _E("You are not an authorized user on updating!\n");
-               return -1;
-       }
 
        ret = _init_desktop_info(&info, appid);
        retv_if(ret != AIL_ERROR_OK, AIL_ERROR_FAIL);
@@ -1739,10 +1734,6 @@ EXPORT_API ail_error_e ail_desktop_remove(const char *appid)
        ail_error_e ret;
 
        retv_if(!appid, AIL_ERROR_INVALID_PARAMETER);
-       if (!__is_authorized()) {
-               _E("You are not an authorized user on removing!\n");
-               return -1;
-       }
 
        ret = _remove_package(appid);
        retv_if(ret != AIL_ERROR_OK, AIL_ERROR_FAIL);
@@ -1758,10 +1749,6 @@ EXPORT_API ail_error_e ail_desktop_clean(const char *pkgid)
        ail_error_e ret;
 
        retv_if(!pkgid, AIL_ERROR_INVALID_PARAMETER);
-       if (!__is_authorized()) {
-               _E("You are not an authorized user on removing!\n");
-               return -1;
-       }
 
        _D("ail_desktop_clean=%s",pkgid);
 
@@ -1779,10 +1766,6 @@ EXPORT_API ail_error_e ail_desktop_fota(const char *appid)
        int count;
 
        retv_if(!appid, AIL_ERROR_INVALID_PARAMETER);
-       if (!__is_authorized()) {
-               _E("You are not an authorized user on adding!\n");
-               return -1;
-       }
 
        count = _count_all();
        if (count <= 0) {
index d9a129f..64cc9d8 100644 (file)
 #include "ail.h"
 #include "ail_private.h"
 
-#define OWNER_ROOT 0
-#define GROUP_MENU 6010
-#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)
-#define APP_INFO_DB_FILE tzplatform_mkpath(TZ_SYS_DB,".app_info.db")
-#define APP_INFO_DB_FILE_JOURNAL tzplatform_mkpath(TZ_SYS_DB,".app_info.db-journal")
-#define APP_INFO_DB_LABEL "ail::db"
-
 #ifdef _E
 #undef _E
 #endif
@@ -244,15 +235,14 @@ int main(int argc, char *argv[])
 
        if (!__is_authorized()) {
                fprintf(stderr, "You are not an authorized user!\n");
-               _D("You are not an authorized user!\n");
-               return AIL_ERROR_FAIL;
-       }
-
+               _D("You are not root user!\n");
+    }
+    else {
        const char *argv_rm[] = { "/bin/rm", APP_INFO_DB_FILE, NULL };
        xsystem(argv_rm);
        const char *argv_rmjn[] = { "/bin/rm", APP_INFO_DB_FILE_JOURNAL, NULL };
        xsystem(argv_rmjn);
-
+    }
        ret = setenv("AIL_INITDB", "1", 1);
        _D("AIL_INITDB : %d", ret);
 
@@ -271,17 +261,16 @@ int main(int argc, char *argv[])
                _E("cannot load usr desktop directory.");
        }
 
-       ret = initdb_change_perm(APP_INFO_DB_FILE);
-       if (ret == AIL_ERROR_FAIL) {
-               _E("cannot chown.");
+       if (__is_authorized()) {
+               ret = initdb_change_perm(APP_INFO_DB_FILE);
+               if (ret == AIL_ERROR_FAIL) {
+                       _E("cannot chown.");
+               }
+               const char *argv_smack[] = { "/usr/bin/chsmack", "-a", APP_INFO_DB_LABEL, APP_INFO_DB_FILE, NULL };
+               xsystem(argv_smack);
+               const char *argv_smackjn[] = { "/usr/bin/chsmack", "-a", APP_INFO_DB_LABEL, APP_INFO_DB_FILE_JOURNAL, NULL };
+               xsystem(argv_smackjn);
        }
-
-#ifdef WRT_SMACK_ENABLED
-       const char *argv_smack[] = { "/usr/bin/chsmack", "-a", APP_INFO_DB_LABEL, APP_INFO_DB_FILE, NULL };
-       xsystem(argv_smack);
-       const char *argv_smackjn[] = { "/usr/bin/chsmack", "-a", APP_INFO_DB_LABEL, APP_INFO_DB_FILE_JOURNAL, NULL };
-       xsystem(argv_smackjn);
-#endif
        return AIL_ERROR_OK;
 }
 
index eefb9b8..d8b7373 100755 (executable)
 #include "ail.h"
 #include "ail_private.h"
 
-#define OWNER_ROOT 0
-#define GROUP_MENU 6010
-#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)
-#define APP_INFO_DB_FILE tzplatform_mkpath(TZ_SYS_DB,".app_info.db")
-#define APP_INFO_DB_FILE_JOURNAL tzplatform_mkpath(TZ_SYS_DB,".app_info.db-journal")
-#define APP_INFO_DB_LABEL "ail::db"
 
 #ifdef _E
 #undef _E
@@ -244,14 +236,14 @@ int main(int argc, char *argv[])
 
        if (!__is_authorized()) {
                fprintf(stderr, "You are not an authorized user!\n");
-               _D("You are not an authorized user!\n");
-               return AIL_ERROR_FAIL;
-       }
-
+               _D("You are not root user!\n");
+    }
+    else {
        const char *argv_rm[] = { "/bin/rm", APP_INFO_DB_FILE, NULL };
        xsystem(argv_rm);
        const char *argv_rmjn[] = { "/bin/rm", APP_INFO_DB_FILE_JOURNAL, NULL };
        xsystem(argv_rmjn);
+    }
 
        ret = setenv("AIL_INITDB", "1", 1);
        _D("AIL_INITDB : %d", ret);
@@ -271,17 +263,16 @@ int main(int argc, char *argv[])
                _E("cannot load usr desktop directory.");
        }
 
-       ret = initdb_change_perm(APP_INFO_DB_FILE);
-       if (ret == AIL_ERROR_FAIL) {
-               _E("cannot chown.");
+       if (__is_authorized()) {
+               ret = initdb_change_perm(APP_INFO_DB_FILE);
+               if (ret == AIL_ERROR_FAIL) {
+                       _E("cannot chown.");
+               }
+               const char *argv_smack[] = { "/usr/bin/chsmack", "-a", APP_INFO_DB_LABEL, APP_INFO_DB_FILE, NULL };
+               xsystem(argv_smack);
+               const char *argv_smackjn[] = { "/usr/bin/chsmack", "-a", APP_INFO_DB_LABEL, APP_INFO_DB_FILE_JOURNAL, NULL };
+               xsystem(argv_smackjn);
        }
-
-#ifdef WRT_SMACK_ENABLED
-       const char *argv_smack[] = { "/usr/bin/chsmack", "-a", APP_INFO_DB_LABEL, APP_INFO_DB_FILE, NULL };
-       xsystem(argv_smack);
-       const char *argv_smackjn[] = { "/usr/bin/chsmack", "-a", APP_INFO_DB_LABEL, APP_INFO_DB_FILE_JOURNAL, NULL };
-       xsystem(argv_smackjn);
-#endif
        return AIL_ERROR_OK;
 }