#include <db-util.h>
#include <pkgmgr-info.h>
#include <tzplatform_config.h>
-
#include "account-private.h"
/* ACCOUNT_TABLE */
"key TEXT "\
");"
+/* DELETED_ACCOUNT_TABLE */
+#define DELETED_ACCOUNT_SCHEMA "create table deleted_account \n"\
+"(\n"\
+"_id INTEGER, "\
+"user_name TEXT, "\
+"email_address TEXT, "\
+"display_name TEXT, "\
+"icon_path TEXT, "\
+"source TEXT, "\
+"package_name TEXT, "\
+"access_token TEXT, "\
+"domain_name TEXT, "\
+"auth_type INTEGER, "\
+"secret INTEGER, "\
+"sync_support INTEGER, "\
+"txt_custom0 TEXT, "\
+"txt_custom1 TEXT, "\
+"txt_custom2 TEXT, "\
+"txt_custom3 TEXT, "\
+"txt_custom4 TEXT, "\
+"int_custom0 INTEGER, "\
+"int_custom1 INTEGER, "\
+"int_custom2 INTEGER, "\
+"int_custom3 INTEGER, "\
+"int_custom4 INTEGER "\
+");"
+
+/* DELETED_CAPABILITY_TABLE */
+#define DELETED_CAPABILITY_SCHEMA "create table deleted_capability \n"\
+"(\n"\
+"_id INTEGER, "\
+"key TEXT, "\
+"value INTEGER, "\
+"package_name TEXT, "\
+"user_name TEXT, "\
+"account_id INTEGER "\
+");"
+
+/* DELETED_ACCOUNT_CUSTOM_TABLE */
+#define DELETED_ACCOUNT_CUSTOM_SCHEMA "create table deleted_account_custom \n"\
+"(\n"\
+"AccountId INTEGER, "\
+"AppId TEXT, "\
+"Key TEXT, "\
+"Value TEXT "\
+");"
+
+/* DELETED_TRIGGER_QUERY */
+/* ACCOUNT_TABLE */
+#define TRIGGER_QUERY_DEL_ACC_TAB "create trigger aft_acc_del \n"\
+"after delete on account \n"\
+"begin \n"\
+"insert into deleted_account \n"\
+"values "\
+"(\n"\
+"old._id, "\
+"old.user_name, "\
+"old.email_address, "\
+"old.display_name, "\
+"old.icon_path, "\
+"old.source, "\
+"old.package_name, "\
+"old.access_token, "\
+"old.domain_name, "\
+"old.auth_type, "\
+"old.secret, "\
+"old.sync_support, "\
+"old.txt_custom0, "\
+"old.txt_custom1, "\
+"old.txt_custom2, "\
+"old.txt_custom3, "\
+"old.txt_custom4, "\
+"old.int_custom0, "\
+"old.int_custom1, "\
+"old.int_custom2, "\
+"old.int_custom3, "\
+"old.int_custom4 "\
+");"\
+"end;"
+
+/* CAPABILITY_TABLE */
+#define TRIGGER_QUERY_DEL_CAP_TAB "create trigger aft_capa_del \n"\
+"after delete on capability \n"\
+"begin \n"\
+"insert into deleted_capability \n"\
+"values "\
+"(\n"\
+"old._id, "\
+"old.key, "\
+"old.value, "\
+"old.package_name, "\
+"old.user_name, "\
+"old.account_id "\
+");"\
+"end;"
+
+/* ACCOUNT_CUSTOM_TABLE */
+#define TRIGGER_QUERY_DEL_ACUST_TAB "create trigger aft_cust_del \n"\
+"after delete on account_custom \n"\
+"begin \n"\
+"insert into deleted_account_custom \n"\
+"values "\
+"(\n"\
+"old.AccountId, "\
+"old.AppId, "\
+"old.Key, "\
+"old.Value "\
+");"\
+"end;"
+
#define OWNER_ROOT 0
#define GLOBAL_USER tzplatform_getuid(TZ_SYS_GLOBALAPP_USER)
do { \
snprintf(dest, size-1, "%s%d%s", tzplatform_mkpath(TZ_SYS_DB, "/"), uid, "/.account.db-journal"); \
} while (0)
-#define ACCOUNT_TABLE "account"
-#define CAPABILITY_TABLE "capability"
-#define ACCOUNT_CUSTOM_TABLE "account_custom"
-#define ACCOUNT_TYPE_TABLE "account_type"
-#define LABEL_TABLE "label"
-#define PROVIDER_FEATURE_TABLE "provider_feature"
-#define ACCOUNT_SQLITE_SEQ "sqlite_sequence"
-#define ACCOUNT_SQL_LEN_MAX 1024
-#define ACCOUNT_TABLE_TOTAL_COUNT 6
+
+#define ACCOUNT_TABLE "account"
+#define CAPABILITY_TABLE "capability"
+#define ACCOUNT_CUSTOM_TABLE "account_custom"
+#define ACCOUNT_TYPE_TABLE "account_type"
+#define LABEL_TABLE "label"
+#define PROVIDER_FEATURE_TABLE "provider_feature"
+#define DELETED_ACCOUNT_TABLE "deleted_account"
+#define DELETED_CAPABILITY_TABLE "deleted_capability"
+#define DELETED_ACCOUNT_CUSTOM_TABLE "deleted_account_custom"
+#define ACCOUNT_SQLITE_SEQ "sqlite_sequence"
+#define ACCOUNT_SQL_LEN_MAX 1024
+#define ACCOUNT_TABLE_TOTAL_COUNT 9
typedef sqlite3_stmt * account_stmt;
int _remove_sensitive_info_from_non_owning_account_list(GList *account_list, int caller_pid, uid_t uid);
int _remove_sensitive_info_from_non_owning_account_slist(GSList *account_list, int caller_pid, uid_t uid);
-
const char *_account_db_err_msg(sqlite3 *account_db_handle);
int _account_db_err_code(sqlite3 *account_db_handle);
int _account_execute_query(sqlite3 *account_db_handle, const char *query);
void _account_convert_column_to_capability(account_stmt hstmt, account_capability_s *capability_record);
void _account_convert_column_to_custom(account_stmt hstmt, account_custom_s *custom_record);
-
int _account_get_record_count(sqlite3 *account_db_handle, const char *query);
int _account_create_all_tables(sqlite3 *account_db_handle);
int _account_check_is_all_table_exists(sqlite3 *account_db_handle);
int _account_db_handle_close(sqlite3 *account_db_handle);
-
int _account_type_query_app_id_exist_from_all_db(sqlite3 *account_user_db, sqlite3 *account_global_db, const char *app_id);
void _account_get_appid_from_db(pkgmgrinfo_appinfo_h *ahandle, pkgmgrinfo_pkginfo_h *phandle, char **package_id, const char *appid, uid_t uid, GSList **appid_list);
int _account_get_represented_appid_from_db(sqlite3 *account_user_db, sqlite3 *account_global_db, const char *appid, uid_t uid, char **verified_appid);
const char *package_name, const char *app_id, const char* table);
int _account_delete_account_by_package_name(sqlite3 *account_db_handle, const char *package_name, gboolean permission, int pid, uid_t uid);
-
int _account_type_convert_account_to_sql(account_type_s *account_type, account_stmt hstmt, char *sql_value);
void _account_type_convert_column_to_provider_feature(account_stmt hstmt, provider_feature_s *feature_record);
void _account_type_convert_column_to_label(account_stmt hstmt, label_s *label_record);
rc = _account_execute_query(account_db_handle, ACCOUNT_SCHEMA);
if (rc == SQLITE_BUSY)
return _ACCOUNT_ERROR_DATABASE_BUSY;
- ACCOUNT_RETURN_VAL((SQLITE_OK == rc), {}, _ACCOUNT_ERROR_DB_FAILED, ("_account_execute_query(account_db_handle, %s) failed(%d, %s).\n", ACCOUNT_SCHEMA, rc, _account_db_err_msg(account_db_handle)));
+ ACCOUNT_RETURN_VAL((SQLITE_OK == rc), {}, _ACCOUNT_ERROR_DB_FAILED, ("_account_execute_query(account_db_handle, %s) failed(%d, %s).\n",
+ ACCOUNT_SCHEMA, rc, _account_db_err_msg(account_db_handle)));
}
rc = _account_execute_query(account_db_handle, CAPABILITY_SCHEMA);
if (rc == SQLITE_BUSY)
return _ACCOUNT_ERROR_DATABASE_BUSY;
- ACCOUNT_RETURN_VAL((SQLITE_OK == rc), {}, _ACCOUNT_ERROR_DB_FAILED, ("_account_execute_query(account_db_handle, %s) failed(%d, %s).\n", CAPABILITY_SCHEMA, rc, _account_db_err_msg(account_db_handle)));
+ ACCOUNT_RETURN_VAL((SQLITE_OK == rc), {}, _ACCOUNT_ERROR_DB_FAILED, ("_account_execute_query(account_db_handle, %s) failed(%d, %s).\n",
+ CAPABILITY_SCHEMA, rc, _account_db_err_msg(account_db_handle)));
}
/* Create account custom table */
rc = _account_execute_query(account_db_handle, ACCOUNT_CUSTOM_SCHEMA);
if (rc == SQLITE_BUSY)
return _ACCOUNT_ERROR_DATABASE_BUSY;
- ACCOUNT_RETURN_VAL((SQLITE_OK == rc), {}, _ACCOUNT_ERROR_DB_FAILED, ("_account_execute_query(account_db_handle, %s) failed(%d, %s).\n", query, rc, _account_db_err_msg(account_db_handle)));
+ ACCOUNT_RETURN_VAL((SQLITE_OK == rc), {}, _ACCOUNT_ERROR_DB_FAILED, ("_account_execute_query(account_db_handle, %s) failed(%d, %s).\n",
+ query, rc, _account_db_err_msg(account_db_handle)));
}
/* Create account type table */
rc = _account_execute_query(account_db_handle, ACCOUNT_TYPE_SCHEMA);
if (rc == SQLITE_BUSY)
return _ACCOUNT_ERROR_DATABASE_BUSY;
- ACCOUNT_RETURN_VAL((SQLITE_OK == rc), {}, _ACCOUNT_ERROR_DB_FAILED, ("_account_execute_query(account_db_handle, %s) failed(%d, %s).\n", ACCOUNT_TYPE_SCHEMA, rc, _account_db_err_msg(account_db_handle)));
+ ACCOUNT_RETURN_VAL((SQLITE_OK == rc), {}, _ACCOUNT_ERROR_DB_FAILED, ("_account_execute_query(account_db_handle, %s) failed(%d, %s).\n",
+ ACCOUNT_TYPE_SCHEMA, rc, _account_db_err_msg(account_db_handle)));
}
/* Create label table */
rc = _account_execute_query(account_db_handle, LABEL_SCHEMA);
if (rc == SQLITE_BUSY)
return _ACCOUNT_ERROR_DATABASE_BUSY;
- ACCOUNT_RETURN_VAL((SQLITE_OK == rc), {}, _ACCOUNT_ERROR_DB_FAILED, ("_account_execute_query(account_db_handle, %s) failed(%d, %s).\n", LABEL_SCHEMA, rc, _account_db_err_msg(account_db_handle)));
+ ACCOUNT_RETURN_VAL((SQLITE_OK == rc), {}, _ACCOUNT_ERROR_DB_FAILED, ("_account_execute_query(account_db_handle, %s) failed(%d, %s).\n",
+ LABEL_SCHEMA, rc, _account_db_err_msg(account_db_handle)));
}
/* Create account feature table */
rc = _account_execute_query(account_db_handle, PROVIDER_FEATURE_SCHEMA);
if (rc == SQLITE_BUSY)
return _ACCOUNT_ERROR_DATABASE_BUSY;
- ACCOUNT_RETURN_VAL((SQLITE_OK == rc), {}, _ACCOUNT_ERROR_DB_FAILED, ("_account_execute_query(account_db_handle, %s) failed(%d, %s).\n", PROVIDER_FEATURE_SCHEMA, rc, _account_db_err_msg(account_db_handle)));
+ ACCOUNT_RETURN_VAL((SQLITE_OK == rc), {}, _ACCOUNT_ERROR_DB_FAILED, ("_account_execute_query(account_db_handle, %s) failed(%d, %s).\n",
+ PROVIDER_FEATURE_SCHEMA, rc, _account_db_err_msg(account_db_handle)));
+ }
+
+ /* Create deleted account table */
+ ACCOUNT_MEMSET(query, 0, sizeof(query));
+ ACCOUNT_SNPRINTF(query, sizeof(query), "select count(*) from sqlite_master where name in ('%s')", DELETED_ACCOUNT_TABLE);
+ rc = _account_get_record_count(account_db_handle, query);
+ if (rc <= 0) {
+ rc = _account_execute_query(account_db_handle, DELETED_ACCOUNT_SCHEMA);
+ if (rc == SQLITE_BUSY)
+ return _ACCOUNT_ERROR_DATABASE_BUSY;
+ ACCOUNT_RETURN_VAL((SQLITE_OK == rc), {}, _ACCOUNT_ERROR_DB_FAILED, ("_account_execute_query(account_db_handle, %s) failed(%d, %s).\n",
+ DELELTED_ACCOUNT_SCHEMA, rc, _account_db_err_msg(account_db_handle)));
+ rc = _account_execute_query(account_db_handle, TRIGGER_QUERY_DEL_ACC_TAB);
+ if (rc == SQLITE_BUSY)
+ return _ACCOUNT_ERROR_DATABASE_BUSY;
+ }
+
+ /* Create deleted capability table */
+ ACCOUNT_MEMSET(query, 0, sizeof(query));
+ ACCOUNT_SNPRINTF(query, sizeof(query), "select count(*) from sqlite_master where name in ('%s')", DELETED_CAPABILITY_TABLE);
+ rc = _account_get_record_count(account_db_handle, query);
+ if (rc <= 0) {
+ rc = _account_execute_query(account_db_handle, DELETED_CAPABILITY_SCHEMA);
+ if (rc == SQLITE_BUSY)
+ return _ACCOUNT_ERROR_DATABASE_BUSY;
+ ACCOUNT_RETURN_VAL((SQLITE_OK == rc), {}, _ACCOUNT_ERROR_DB_FAILED, ("_account_execute_query(account_db_handle, %s) failed(%d, %s).\n",
+ DELETED_CAPABILITY_SCHEMA, rc, _account_db_err_msg(account_db_handle)));
+ rc = _account_execute_query(account_db_handle, TRIGGER_QUERY_DEL_CAP_TAB);
+ if (rc == SQLITE_BUSY)
+ return _ACCOUNT_ERROR_DATABASE_BUSY;
+ }
+
+ /* Create deleted account custom table */
+ ACCOUNT_MEMSET(query, 0, sizeof(query));
+ ACCOUNT_SNPRINTF(query, sizeof(query), "select count(*) from sqlite_master where name in ('%s')", DELETED_ACCOUNT_CUSTOM_TABLE);
+ rc = _account_get_record_count(account_db_handle, query);
+ if (rc <= 0) {
+ rc = _account_execute_query(account_db_handle, DELETED_ACCOUNT_CUSTOM_SCHEMA);
+ if (rc == SQLITE_BUSY)
+ return _ACCOUNT_ERROR_DATABASE_BUSY;
+ ACCOUNT_RETURN_VAL((SQLITE_OK == rc), {}, _ACCOUNT_ERROR_DB_FAILED, ("_account_execute_query(account_db_handle, %s) failed(%d, %s).\n",
+ query, rc, _account_db_err_msg(account_db_handle)));
+ rc = _account_execute_query(account_db_handle, TRIGGER_QUERY_DEL_ACUST_TAB);
+ if (rc == SQLITE_BUSY)
+ return _ACCOUNT_ERROR_DATABASE_BUSY;
}
_INFO("create all table - END");
char query[ACCOUNT_SQL_LEN_MAX] = {0,};
ACCOUNT_MEMSET(query, 0, sizeof(query));
- ACCOUNT_SNPRINTF(query, sizeof(query), "select count(*) from sqlite_master where name in ('%s', '%s', '%s', '%s', '%s', '%s')",
- ACCOUNT_TABLE, CAPABILITY_TABLE, ACCOUNT_CUSTOM_TABLE, ACCOUNT_TYPE_TABLE, LABEL_TABLE, PROVIDER_FEATURE_TABLE);
+ ACCOUNT_SNPRINTF(query, sizeof(query), "select count(*) from sqlite_master where name in ('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s')",
+ ACCOUNT_TABLE, CAPABILITY_TABLE, ACCOUNT_CUSTOM_TABLE, ACCOUNT_TYPE_TABLE, LABEL_TABLE, PROVIDER_FEATURE_TABLE,
+ DELETED_ACCOUNT_TABLE, DELETED_CAPABILITY_TABLE, DELETED_ACCOUNT_CUSTOM_TABLE);
rc = _account_get_record_count(account_db_handle, query);
if (rc != ACCOUNT_TABLE_TOTAL_COUNT)