*
*/
-
-
+#define _GNU_SOURCE
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <dirent.h>
#include <unistd.h>
#include <sys/stat.h>
+#include <sys/types.h>
+#include <sys/wait.h>
#include <errno.h>
#include <sys/smack.h>
#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;
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;
}
}
}
-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
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