return false;
}
-static bool __change_owner(const char *files[2], uid_t uid)
-{
- int ret;
- int i;
- int fd;
- struct passwd pwd;
- struct passwd *result;
- char buf[BUFSIZE];
- struct stat sb;
- mode_t mode;
-
- if (uid == OWNER_ROOT) {
- ret = getpwnam_r(APPFW_USER, &pwd, buf, sizeof(buf), &result);
- if (result == NULL) {
- if (ret == 0)
- LOGE("no such user: %d", uid);
- else
- LOGE("getpwnam_r failed: %d", errno);
- return false;
- }
- uid = pwd.pw_uid;
- }
-
- ret = getpwuid_r(uid, &pwd, buf, sizeof(buf), &result);
- if (result == NULL) {
- if (ret == 0)
- LOGE("no such user: %d", uid);
- else
- LOGE("getpwuid_r failed: %d", errno);
- return false;
- }
-
- for (i = 0; i < 2; i++) {
- fd = open(files[i], O_RDONLY);
- if (fd == -1) {
- LOGE("open %s failed: %d", files[i], errno);
- return false;
- }
- ret = fstat(fd, &sb);
- if (ret == -1) {
- LOGE("stat %s failed: %d", files[i], errno);
- close(fd);
- return false;
- }
- if (S_ISLNK(sb.st_mode)) {
- LOGE("%s is symlink!", files[i]);
- close(fd);
- return false;
- }
- ret = fchown(fd, uid, pwd.pw_gid);
- if (ret == -1) {
- LOGE("fchown %s failed: %d", files[i], errno);
- close(fd);
- return false;
- }
-
- mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH;
- if (strstr(files[0], PKGMGR_CERT_DB_FILE) != NULL)
- mode |= S_IWOTH;
- ret = fchmod(fd, mode);
- if (ret == -1) {
- LOGE("fchmod %s failed: %d", files[i], errno);
- close(fd);
- return false;;
- }
- close(fd);
- }
-
- return true;
-}
-
-static void __change_permission(uid_t uid)
-{
- const char *files[2];
- char *parser_dbpath = NULL;
- char journal_file[PATH_MAX];
- GList *tmp_list;
- user_info *tmp_info;
-
- if (uid < REGULAR_USER) {
- files[0] = PKGMGR_PARSER_DB_FILE;
- snprintf(journal_file, sizeof(journal_file),
- "%s-journal", PKGMGR_PARSER_DB_FILE);
- files[1] = journal_file;
-
- if (!__change_owner(files, uid)) {
- LOGE("Failed to change ownership");
- return;
- }
-
- files[0] = PKGMGR_CERT_DB_FILE;
- snprintf(journal_file, sizeof(journal_file),
- "%s-journal", PKGMGR_CERT_DB_FILE);
- files[1] = journal_file;
- if (!__change_owner(files, uid)) {
- LOGE("Failed to change ownership");
- return;
- }
- } else {
- for (tmp_list = user_info_list; tmp_list != NULL;
- tmp_list = g_list_next(tmp_list)) {
- tmp_info = (user_info *)tmp_list->data;
- if (!tmp_info)
- continue;
-
- if (tmp_info->uid == uid) {
- parser_dbpath = tmp_info->db_path;
- break;
- }
- }
- files[0] = parser_dbpath;
- snprintf(journal_file, sizeof(journal_file),
- "%s-journal", parser_dbpath);
- files[1] = journal_file;
-
- if (!__change_owner(files, uid)) {
- LOGE("Failed to change ownership");
- return;
- }
- }
-}
-
static void _xsystem(const char *argv[])
{
int status = 0;
__create_need_to_recovery_file(uid);
__create_db(uid);
- __change_permission(uid);
snprintf(uid_string, sizeof(uid_string), "%d", (int)uid);
_xsystem((uid > REGULAR_USER) ? initdb_rw : initdb_ro);
__remove_need_to_recovery_file(uid);
for (tmp_list = user_info_list;
tmp_list != NULL; tmp_list = g_list_next(tmp_list)) {
tmp_info = (user_info *)tmp_list->data;
- if (!tmp_info || tmp_info->uid < REGULAR_USER)
+ if (!tmp_info)
continue;
__initdb(tmp_info->uid);
}
{
GList *tmp_list = NULL;
user_info *tmp_info;
- bool need_recovery = false;
+ bool need_recovery;
for (tmp_list = user_info_list;
tmp_list != NULL; tmp_list = g_list_next(tmp_list)) {
+ need_recovery = false;
tmp_info = (user_info *)tmp_list->data;
if (!tmp_info)
continue;
if (!strcmp(".", ent->d_name) || !strcmp("..", ent->d_name) ||
!S_ISDIR(stats.st_mode))
continue;
+ uid = (uid_t)atoi(ent->d_name);
+ if (uid < REGULAR_USER)
+ continue;
+
info = calloc(1, sizeof(user_info));
if (!info) {
closedir(dir);
return;
}
- uid = (uid_t)atoi(ent->d_name);
- if (!uid) {
- free(info);
- continue;
- }
info->uid = uid;
info->db_path = __get_dbpath(uid);
user_info_list = g_list_append(user_info_list, info);