#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.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
-#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) \
+ do { \
+ if (smack_setlabel((x), "*", SMACK_LABEL_ACCESS)) \
+ _E("failed chsmack -a \"*\" %s", x); \
+ else \
+ _D("chsmack -a \"*\" %s", x); \
+ } while (0)
-static int initdb_count_app(void)
+static int initdb_count_app(uid_t uid)
{
ail_filter_h filter;
ail_error_e ret;
int total = 0;
ret = ail_filter_new(&filter);
- if (ret != AIL_ERROR_OK) {
+ if (ret != AIL_ERROR_OK)
return -1;
- }
ret = ail_filter_add_bool(filter, AIL_PROP_NODISPLAY_BOOL, false);
if (ret != AIL_ERROR_OK) {
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;
return total;
}
-
-
-char* _desktop_to_package(const char* desktop)
+char *_desktop_to_package(const char* desktop)
{
- char *package, *tmp;
+ char *package;
+ char *tmp;
retv_if(!desktop, NULL);
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;
{
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_fota(package) != AIL_ERROR_OK) {
+ if (ail_desktop_fota(package) != AIL_ERROR_OK)
_E("Failed to add a package[%s]", package);
- } else {
+ else
ok_cnt++;
- }
free(package);
}
/* 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;
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();
- if (ret > 0) {
+ 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) {
+ 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.");
- 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);
+ SET_DEFAULT_LABEL(APP_INFO_DB_FILE);
+ SET_DEFAULT_LABEL(APP_INFO_DB_FILE_JOURNAL);
+ }
return AIL_ERROR_OK;
}
-
-
-
-// END