X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=tool%2Fsrc%2Fail_fota.c;h=20d17c58cf10e83e1a130e16372ab70aa1783eec;hb=d8c31d21dfab9bc56baa4627f74fa87b47e4b077;hp=334388faddc0a9b89c81f9449f5a8eff2eaf6e24;hpb=067d80d54e49361d813f50c8d4fbf11704ed03a2;p=platform%2Fcore%2Fappfw%2Fail.git diff --git a/tool/src/ail_fota.c b/tool/src/ail_fota.c index 334388f..20d17c5 100644 --- a/tool/src/ail_fota.c +++ b/tool/src/ail_fota.c @@ -28,19 +28,11 @@ #include #include #include +#include #include "ail.h" #include "ail_private.h" -#define OWNER_ROOT 0 -#define GROUP_MENU 6010 -#define BUFSZE 1024 -#define OPT_DESKTOP_DIRECTORY "/opt/share/applications" -#define USR_DESKTOP_DIRECTORY "/usr/share/applications" -#define APP_INFO_DB_FILE "/opt/dbspace/.app_info.db" -#define APP_INFO_DB_FILE_JOURNAL "/opt/dbspace/.app_info.db-journal" -#define APP_INFO_DB_LABEL "ail::db" - #ifdef _E #undef _E #endif @@ -51,7 +43,11 @@ #endif #define _D(fmt, arg...) fprintf(stderr, "[AIL_INITDB][D][%s,%d] "fmt"\n", __FUNCTION__, __LINE__, ##arg); -static int initdb_count_app(void) +#define SET_DEFAULT_LABEL(x) \ + if(smack_setlabel((x), "*", SMACK_LABEL_ACCESS)) _E("failed chsmack -a \"*\" %s", x) \ + else _D("chsmack -a \"*\" %s", x) + +static int initdb_count_app(uid_t uid) { ail_filter_h filter; ail_error_e ret; @@ -67,8 +63,11 @@ static int initdb_count_app(void) ail_filter_destroy(filter); return -1; } - - ret = ail_filter_count_appinfo(filter, &total); +//__isadmin + if (uid != GLOBAL_USER) + ret = ail_filter_count_usr_appinfo(filter, &total, uid); + else + ret = ail_filter_count_appinfo(filter, &total); if (ret != AIL_ERROR_OK) { ail_filter_destroy(filter); return -1; @@ -199,7 +198,9 @@ static int __is_authorized() /* ail_init db should be called by as root privilege. */ uid_t uid = getuid(); - if ((uid_t) 0 == uid) + uid_t euid = geteuid(); + //euid need to be root to allow smack label changes during initialization + if (((uid_t) GLOBAL_USER == uid) && (euid == OWNER_ROOT) ) return 1; else return 0; @@ -244,43 +245,35 @@ 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 { + if(remove(APP_INFO_DB_FILE)) + _E(" %s is not removed",APP_INFO_DB_FILE); + if(remove(APP_INFO_DB_FILE_JOURNAL)) + _E(" %s is not removed",APP_INFO_DB_FILE_JOURNAL); } - - 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); - ret = initdb_count_app(); + ret = initdb_count_app(getuid()); if (ret > 0) { _D("Some Apps in the App Info DB."); } - ret = initdb_load_directory(OPT_DESKTOP_DIRECTORY); - if (ret == AIL_ERROR_FAIL) { - _E("cannot load opt desktop directory."); - } - ret = initdb_load_directory(USR_DESKTOP_DIRECTORY); if (ret == AIL_ERROR_FAIL) { _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."); + } + SET_DEFAULT_LABEL(APP_INFO_DB_FILE); + SET_DEFAULT_LABEL(APP_INFO_DB_FILE_JOURNAL); } - - 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); - return AIL_ERROR_OK; }