*
*/
-
-
+#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>
#include "ail_private.h"
#include "ail_db.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 initdb_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;
-}
-
-
-
-char* _desktop_to_package(const char* desktop)
+ do { \
+ if (smack_setlabel((x), "*", SMACK_LABEL_ACCESS)) \
+ _E("failed chsmack -a \"*\" %s", x); \
+ else \
+ _D("chsmack -a \"*\" %s", x); \
+ } while (0)
+
+char *_desktop_to_package(const char* desktop)
{
char *package, *tmp;
retv_if(!package, NULL);
tmp = strrchr(package, '.');
- if(tmp == NULL) {
+ if (tmp == NULL) {
_E("[%s] is not a desktop file", package);
free(package);
return NULL;
return package;
}
-
-
int initdb_load_directory(const char *directory)
{
DIR *dir;
struct dirent entry, *result;
- int len, ret;
+ int ret;
char buf[BUFSZE];
int total_cnt = 0;
int ok_cnt = 0;
- // desktop file
+ /* desktop file */
dir = opendir(directory);
if (!dir) {
if (strerror_r(errno, buf, sizeof(buf)) == 0)
return AIL_ERROR_FAIL;
}
- len = strlen(directory) + 1;
_D("Loading desktop files from %s", directory);
for (ret = readdir_r(dir, &entry, &result);
continue;
}
- if (ail_desktop_add(package) != AIL_ERROR_OK) {
+ if (ail_desktop_add(package) != AIL_ERROR_OK)
_E("Failed to add a package[%s]", package);
- } else {
+ else
ok_cnt++;
- }
+
free(package);
}
return AIL_ERROR_OK;
}
-
-
static int initdb_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;
}
}
return AIL_ERROR_OK;
}
-
static int __is_authorized()
{
/* 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
fprintf(stderr, "You are not an authorized user!\n");
_D("You are not root user!\n");
return -1;
- }
- 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;
}
ret = initdb_load_directory(USR_DESKTOP_DIRECTORY);
- if (ret == AIL_ERROR_FAIL) {
+ if (ret == AIL_ERROR_FAIL)
_E("cannot load usr desktop directory.");
- }
- setuid(OWNER_ROOT);
+ if (setuid(OWNER_ROOT) != 0)
+ _E("setuid() is failed.");
+
ret = initdb_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