X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=tool%2Fsrc%2Fcreatedb.c;h=04f3f70548e7aa7750bdf8178560405146f420fe;hb=refs%2Ftags%2Fsubmit%2Ftizen_common%2F20151229.144031;hp=e61250593f20e75e95f154599b03bd392796f3ce;hpb=9241f15a201da5ea3e02b95f15325f7aa83f64bf;p=platform%2Fcore%2Fappfw%2Fail.git diff --git a/tool/src/createdb.c b/tool/src/createdb.c index e612505..04f3f70 100644 --- a/tool/src/createdb.c +++ b/tool/src/createdb.c @@ -21,14 +21,15 @@ * */ - - +#define _GNU_SOURCE #include #include #include #include #include #include +#include +#include #include #include @@ -40,48 +41,23 @@ #ifdef _E #undef _E #endif -#define _E(fmt, arg...) fprintf(stderr, "[AIL_INITDB][E][%s,%d] "fmt"\n", __FUNCTION__, __LINE__, ##arg); +#define _E(fmt, arg...) fprintf(stderr, "[AIL_INITDB][E][%s,%d] "fmt"\n", __FUNCTION__, __LINE__, ##arg) #ifdef _D #undef _D #endif -#define _D(fmt, arg...) fprintf(stderr, "[AIL_INITDB][D][%s,%d] "fmt"\n", __FUNCTION__, __LINE__, ##arg); +#define _D(fmt, arg...) fprintf(stderr, "[AIL_INITDB][D][%s,%d] "fmt"\n", __FUNCTION__, __LINE__, ##arg) #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 createb_count_app(void) -{ - ail_filter_h filter; - ail_error_e ret; - int total = 0; - - ret = ail_filter_new(&filter); - if (ret != AIL_ERROR_OK) { - return -1; - } - - ret = ail_filter_add_bool(filter, AIL_PROP_NODISPLAY_BOOL, false); - if (ret != AIL_ERROR_OK) { - ail_filter_destroy(filter); - return -1; - } - ret = ail_filter_count_appinfo(filter, &total); - if (ret != AIL_ERROR_OK) { - ail_filter_destroy(filter); - return -1; - } - - ail_filter_destroy(filter); - - return total; -} - + do { \ + if (smack_setlabel((x), "*", SMACK_LABEL_ACCESS)) \ + _E("failed chsmack -a \"*\" %s", x); \ + else \ + _D("chsmack -a \"*\" %s", x); \ + } while (0) static int createdb_change_perm(const char *db_file) { - char buf[BUFSZE]; char journal_file[BUFSZE]; char *files[3]; int ret, i; @@ -97,15 +73,13 @@ static int createdb_change_perm(const char *db_file) for (i = 0; files[i]; i++) { ret = chown(files[i], GLOBAL_USER, OWNER_ROOT); if (ret == -1) { - strerror_r(errno, buf, sizeof(buf)); - _E("FAIL : chown %s %d.%d, because %s", db_file, OWNER_ROOT, OWNER_ROOT, buf); + _E("FAIL : chown %s %d.%d, because %d", db_file, OWNER_ROOT, OWNER_ROOT, errno); return AIL_ERROR_FAIL; } ret = chmod(files[i], S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); if (ret == -1) { - strerror_r(errno, buf, sizeof(buf)); - _E("FAIL : chmod %s 0664, because %s", db_file, buf); + _E("FAIL : chmod %s 0664, because %d", db_file, errno); return AIL_ERROR_FAIL; } } @@ -114,13 +88,12 @@ static int createdb_change_perm(const char *db_file) } -static int __is_authorized() +static int __is_authorized(void) { /* ail_init db should be called by as root privilege. */ - uid_t uid = getuid(); - uid_t euid = geteuid(); - //euid need to be root to allow smack label changes during initialization + /* euid need to be root to allow smack label changes during initialization */ + /* uid_t euid = geteuid(); */ if ((uid_t) OWNER_ROOT == uid) return 1; else @@ -167,33 +140,33 @@ int main(int argc, char *argv[]) if (!__is_authorized()) { fprintf(stderr, "You are not an authorized user!\n"); _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); } - 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); - } + ret = setenv("AIL_INITDB", "1", 1); _D("AIL_INITDB : %d", ret); - setresuid(GLOBAL_USER, GLOBAL_USER, OWNER_ROOT); + + if (setresuid(GLOBAL_USER, GLOBAL_USER, OWNER_ROOT) != 0) + _E("setresuid() is failed"); if (db_open(DB_OPEN_RW, GLOBAL_USER) != AIL_ERROR_OK) { _E("Fail to create system databases"); return AIL_ERROR_DB_FAILED; } - setuid(OWNER_ROOT); + if (setuid(OWNER_ROOT) != 0) + _E("setuid() is failed."); + ret = createdb_change_perm(APP_INFO_DB_FILE); - if (ret == AIL_ERROR_FAIL) { + if (ret == AIL_ERROR_FAIL) _E("cannot chown."); - } + SET_DEFAULT_LABEL(APP_INFO_DB_FILE); SET_DEFAULT_LABEL(APP_INFO_DB_FILE_JOURNAL); return AIL_ERROR_OK; } - - - -// END