return -1;
}
-static int _recover_db(sqlite3 *db, const char *path, uid_t uid)
+static void __change_smack(const char *path)
+{
+ char journal_path[PATH_MAX];
+
+ snprintf(journal_path, sizeof(journal_path), "%s-journal", path);
+ SET_SMACK_LABEL(path);
+ SET_SMACK_LABEL(journal_path);
+}
+
+static int __change_own(uid_t uid, const char *path)
{
- int ret;
- char *errmsg = NULL;
struct passwd pwd;
struct passwd *result;
- char buf[MAX_BUF_SIZE];
+ int ret;
uid_t new_uid;
+ char buf[MAX_BUF_SIZE];
char journal_path[PATH_MAX];
- _I("DB recovery process start");
- if (db)
- sqlite3_close(db);
- unlink(path);
-
ret = getpwuid_r(uid, &pwd, buf, sizeof(buf), &result);
if (result == NULL) {
if (ret == 0)
- _E("no such user: %d", uid);
+ printf("no such user: %d", uid);
else
- _E("getpwuid_r failed: %d", errno);
+ printf("getpwuid_r failed: %d", errno);
+ return WIDGET_ERROR_FAULT;
+ }
+
+ if (pwd.pw_uid == tzplatform_getuid(TZ_SYS_GLOBALAPP_USER))
+ new_uid = 0;
+ else
+ new_uid = pwd.pw_uid;
+
+ ret = chown(path, new_uid, pwd.pw_gid);
+ if (ret == -1) {
+ printf("chown fail %s", path);
+ return WIDGET_ERROR_FAULT;
+ }
+
+ snprintf(journal_path, sizeof(journal_path), "%s-journal", path);
+ ret = chown(journal_path, new_uid, pwd.pw_gid);
+ if (ret == -1) {
+ printf("chown fail %s", path);
return WIDGET_ERROR_FAULT;
}
+ return WIDGET_ERROR_NONE;
+}
+
+static int _recover_db(sqlite3 *db, const char *path, uid_t uid, bool is_init)
+{
+ int ret;
+ char *errmsg = NULL;
+
+ _I("DB recovery process start");
+ if (db)
+ sqlite3_close(db);
+ unlink(path);
+
ret = sqlite3_open_v2(path, &db,
- SQLITE_OPEN_CREATE |SQLITE_OPEN_READWRITE,
+ SQLITE_OPEN_CREATE | SQLITE_OPEN_READWRITE,
NULL);
if (ret != SQLITE_OK) {
_E("Failed to open db[%d]", ret);
return WIDGET_ERROR_FAULT;
}
- snprintf(journal_path, sizeof(journal_path), "%s-journal", path);
- SET_SMACK_LABEL(path);
- SET_SMACK_LABEL(journal_path);
- if (pwd.pw_uid == tzplatform_getuid(TZ_SYS_GLOBALAPP_USER))
- new_uid = 0;
- else
- new_uid = pwd.pw_uid;
-
- ret = chown(path, new_uid, pwd.pw_gid);
- if (ret == -1) {
- _E("chown fail %s", path);
- return WIDGET_ERROR_FAULT;
- }
-
- ret = chown(journal_path, new_uid, pwd.pw_gid);
- if (ret == -1) {
- _E("chown fail %s", path);
- return WIDGET_ERROR_FAULT;
+ __change_smack(path);
+ if (!is_init) {
+ ret = __change_own(uid, path);
+ if (ret != WIDGET_ERROR_NONE)
+ return ret;
}
_I("DB recovery process done");
if (path == NULL)
return WIDGET_ERROR_FAULT;
+ _I("_check_db_integrity %d %d", uid, is_init);
+
/* check table exist */
ret = sqlite3_open_v2(path, &db, SQLITE_OPEN_READONLY, NULL);
if (ret != SQLITE_OK) {
/* LCOV_EXCL_START */
- ret = _recover_db(db, path, uid);
+ ret = _recover_db(db, path, uid, is_init);
return ret;
/* LCOV_EXCL_STOP */
}
/* check integrity */
ret = _integrity_check(db);
if (ret != WIDGET_ERROR_NONE) {
- ret = _recover_db(db, path, uid);
+ ret = _recover_db(db, path, uid, is_init);
return ret;
}
/* check table exist */
ret = _check_table_exist(db);
if (ret != WIDGET_ERROR_NONE) {
- ret = _recover_db(db, path, uid);
+ ret = _recover_db(db, path, uid, is_init);
return ret;
}
{
int ret;
- ret = _check_db_integrity(tzplatform_getuid(TZ_SYS_GLOBALAPP_USER),
- is_init);
+ ret = _check_db_integrity(ROOT_USER, is_init);
_I("check global app db result : %d", ret);
ret = _check_db_integrity(tzplatform_getuid(TZ_SYS_DEFAULT_USER),