summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAbhishek Vijay <abhishek.v@samsung.com>2019-02-20 16:28:30 +0530
committerAbhishek Vijay <abhishek.v@samsung.com>2019-05-09 19:57:50 +0530
commitcbcc629ba4634917c6307cc65f7024f0225cdb3d (patch)
treeb5743675fd8e502027f83be5579c64fd37103c0e
parent1b0ebec7f5a34af2ab61cc97ba625ef923b3e99b (diff)
downloadaccount-manager-cbcc629ba4634917c6307cc65f7024f0225cdb3d.tar.gz
account-manager-cbcc629ba4634917c6307cc65f7024f0225cdb3d.tar.bz2
account-manager-cbcc629ba4634917c6307cc65f7024f0225cdb3d.zip
preserving deleted account information
Change-Id: Ifda8c53850f5be6b2eb6534acebb126b989a8a61 Signed-off-by: Abhishek Vijay <abhishek.v@samsung.com>
-rw-r--r--server/include/account-server-db.h3
-rw-r--r--server/src/account-server-db.c185
-rw-r--r--server/src/account-server.c24
3 files changed, 191 insertions, 21 deletions
diff --git a/server/include/account-server-db.h b/server/include/account-server-db.h
index f70d2c3..04f1cd0 100644
--- a/server/include/account-server-db.h
+++ b/server/include/account-server-db.h
@@ -32,9 +32,10 @@ GSList* _account_type_query_all(void);
int _account_delete(int pid, uid_t uid, int account_id);
int _account_delete_from_db_by_user_name(int pid, uid_t uid, const char *user_name, const char *package_name);
//int _account_delete_from_db_by_package_name(int pid, uid_t uid, const char *package_name, gboolean permission);
+int account_server_empty_deleted_account_info_tables(const char* del_account_table, const char* del_capability_table, const char* del_account_custom_table);
int _account_update_to_db_by_id(int pid, uid_t uid, account_s *account, int account_id);
int _account_get_total_count_from_db(gboolean include_hidden, int *count);
-int _account_query_account_by_account_id(int pid, uid_t uid, int account_db_id, account_s *account_record);
+int _account_query_account_by_account_id(int pid, uid_t uid, int account_db_id, account_s *account_record, bool *IsDeletedAccount);
int _account_update_to_db_by_user_name(int pid, uid_t uid, account_s* account, const char *user_name, const char *package_name);
int _account_type_query_label_by_locale(const char* app_id, const char* locale, char **label);
GSList* _account_type_query_by_provider_feature(const char* key, int *error_code);
diff --git a/server/src/account-server-db.c b/server/src/account-server-db.c
index 75bd125..bf2d727 100644
--- a/server/src/account-server-db.c
+++ b/server/src/account-server-db.c
@@ -41,8 +41,6 @@
#include "account_type.h"
#include "account-server-db.h"
-//typedef sqlite3_stmt* account_stmt;
-
#define EMAIL_SERVICE_CMDLINE "/usr/bin/email-service"
#define EMAIL_APPID "email-setting-efl"
@@ -1859,37 +1857,194 @@ CATCH:
return error_code;
}
-int _account_query_account_by_account_id(int pid, uid_t uid, int account_db_id, account_s *account_record)
+int account_server_empty_deleted_account_info_tables(const char* del_account_table, const char* del_capability_table,
+ const char* del_account_custom_table)
+{
+ _INFO("account_server_empty_deleted_account_info_tables start");
+
+ account_stmt hstmt = NULL;
+ int error_code = _ACCOUNT_ERROR_NONE;
+ int rc = 0;
+ char query[ACCOUNT_SQL_LEN_MAX] = {0, };
+
+ ACCOUNT_RETURN_VAL((g_hAccountDB != NULL), {}, _ACCOUNT_ERROR_DB_NOT_OPENED, ("The database isn't connected."));
+
+ rc = _account_begin_transaction(g_hAccountDB);
+ _INFO("after _account_begin_trasaction");
+
+ if (_account_db_err_code(g_hAccountDB) == SQLITE_PERM) {
+ ACCOUNT_ERROR("Access failed(%s)", _account_db_err_msg(g_hAccountDB));
+ return _ACCOUNT_ERROR_PERMISSION_DENIED;
+ }
+
+ if (rc == _ACCOUNT_ERROR_DATABASE_BUSY) {
+ ACCOUNT_ERROR("database busy(%s)", _account_db_err_msg(g_hAccountDB));
+ return _ACCOUNT_ERROR_DATABASE_BUSY;
+ } else if (rc != _ACCOUNT_ERROR_NONE) {
+ ACCOUNT_ERROR("account_delete:_account_begin_transaction fail %d\n", rc);
+ return rc;
+ }
+
+ /*clear deleted account table*/
+ ACCOUNT_MEMSET(query, 0, sizeof(query));
+ ACCOUNT_SNPRINTF(query, sizeof(query), "DELETE FROM %s", del_account_table);
+
+ _INFO("clearing deleted-account-table - query[%s]", query);
+
+ hstmt = _account_prepare_query(g_hAccountDB, query);
+ if ((_account_db_err_code(g_hAccountDB) == SQLITE_PERM)) {
+ _account_end_transaction(g_hAccountDB, false);
+ ACCOUNT_ERROR("Access failed(%s)", _account_db_err_msg(g_hAccountDB));
+ return _ACCOUNT_ERROR_PERMISSION_DENIED;
+ }
+
+ if (hstmt == NULL) {
+ _ERR("_account_svc_query_prepare(%s) failed(%s).\n", query, _account_db_err_msg(g_hAccountDB));
+ error_code = _ACCOUNT_ERROR_DB_FAILED;
+ goto END;
+ }
+
+ rc = _account_query_step(hstmt);
+ if (rc != SQLITE_DONE) {
+ _ERR("The record isn't found");
+ error_code = _ACCOUNT_ERROR_RECORD_NOT_FOUND;
+ goto END;
+ }
+
+ rc = _account_query_finalize(hstmt);
+ if (rc != _ACCOUNT_ERROR_NONE) {
+ _ERR("finalize error");
+ error_code = rc;
+ goto END;
+ }
+
+ /*clear deleted capability table*/
+ ACCOUNT_MEMSET(query, 0, sizeof(query));
+ ACCOUNT_SNPRINTF(query, sizeof(query), "DELETE FROM %s", del_capability_table);
+
+ _INFO("clearing deleted-capability-table - query[%s]", query);
+
+ hstmt = _account_prepare_query(g_hAccountDB, query);
+ if (hstmt == NULL) {
+ _ERR("_account_svc_query_prepare(%s) failed(%s).\n", query, _account_db_err_msg(g_hAccountDB));
+ error_code = _ACCOUNT_ERROR_DB_FAILED;
+ goto END;
+ }
+
+ rc = _account_query_step(hstmt);
+ if (rc != SQLITE_DONE) {
+ _ERR("The record isn't found");
+ error_code = _ACCOUNT_ERROR_RECORD_NOT_FOUND;
+ goto END;
+ }
+
+ rc = _account_query_finalize(hstmt);
+ if (rc != _ACCOUNT_ERROR_NONE) {
+ _ERR("finalize error");
+ error_code = rc;
+ goto END;
+ }
+
+ /*clear deleted account_custom table*/
+ ACCOUNT_MEMSET(query, 0, sizeof(query));
+ ACCOUNT_SNPRINTF(query, sizeof(query), "DELETE FROM %s", del_account_custom_table);
+
+ _INFO("clearing deleted-account-custom-table - query[%s]", query);
+
+ hstmt = _account_prepare_query(g_hAccountDB, query);
+ if (hstmt == NULL) {
+ _ERR("_account_svc_query_prepare(%s) failed(%s).\n", query, _account_db_err_msg(g_hAccountDB));
+ error_code = _ACCOUNT_ERROR_DB_FAILED;
+ goto END;
+ }
+
+ rc = _account_query_step(hstmt);
+ if (rc != SQLITE_DONE) {
+ _ERR("The record isn't found");
+ error_code = _ACCOUNT_ERROR_RECORD_NOT_FOUND;
+ goto END;
+ }
+
+ rc = _account_query_finalize(hstmt);
+ if (rc != _ACCOUNT_ERROR_NONE) {
+ _ERR("finalize error");
+ error_code = rc;
+ goto END;
+ }
+
+ rc = _account_end_transaction(g_hAccountDB, true);
+ if (rc != _ACCOUNT_ERROR_NONE)
+ _ERR("clear deleted account tables - fail [%d]", rc);
+
+ hstmt = NULL;
+ _INFO("account_server_empty_deleted_account_info_tables end");
+END:
+ return error_code;
+}
+
+int _account_query_account_by_account_id(int pid, uid_t uid, int account_db_id, account_s *account_record, bool *IsDeletedAccount)
{
_INFO("_account_query_account_by_account_id() start, account_db_id=[%d]", account_db_id);
- int error_code = _ACCOUNT_ERROR_NONE;
- account_stmt hstmt = NULL;
- char query[ACCOUNT_SQL_LEN_MAX] = {0, };
- int rc = 0;
+ int error_code = _ACCOUNT_ERROR_NONE;
+ account_stmt hstmt = NULL;
+ char query[ACCOUNT_SQL_LEN_MAX] = {0, };
+ int rc = 0;
ACCOUNT_RETURN_VAL((account_db_id > 0), {}, _ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT INDEX IS LESS THAN 0"));
ACCOUNT_RETURN_VAL(account_record != NULL, {}, _ACCOUNT_ERROR_INVALID_PARAMETER, ("ACCOUNT IS NULL"));
ACCOUNT_RETURN_VAL((g_hAccountDB != NULL), {}, _ACCOUNT_ERROR_DB_NOT_OPENED, ("The database isn't connected."));
- ACCOUNT_MEMSET(query, 0x00, ACCOUNT_SQL_LEN_MAX);
-
ACCOUNT_DEBUG("starting db operations");
+ /* prepare query for account-table */
+ ACCOUNT_MEMSET(query, 0x00, ACCOUNT_SQL_LEN_MAX);
ACCOUNT_SNPRINTF(query, sizeof(query), "SELECT * FROM %s WHERE _id = %d", ACCOUNT_TABLE, account_db_id);
- hstmt = _account_prepare_query(g_hAccountDB, query);
- rc = _account_db_err_code(g_hAccountDB);
+
_INFO("after _account_prepare_query, rc=[%d]", rc);
+ hstmt = _account_prepare_query(g_hAccountDB, query);
+
+ rc = _account_db_err_code(g_hAccountDB);
if (rc == SQLITE_PERM) {
ACCOUNT_ERROR("Access failed(%s)", _account_db_err_msg(g_hAccountDB));
return _ACCOUNT_ERROR_PERMISSION_DENIED;
}
ACCOUNT_DEBUG("before _account_query_step");
+
rc = _account_query_step(hstmt);
+
ACCOUNT_DEBUG("after _account_query_step returned [%d]", rc);
- ACCOUNT_CATCH_ERROR(rc == SQLITE_ROW, {}, _ACCOUNT_ERROR_RECORD_NOT_FOUND, ("The record isn't found.\n"));
+
+ /*querying information from deleted_account_table*/
+ if (rc != SQLITE_ROW) {
+ ACCOUNT_DEBUG("checking account info in deleted_account_table");
+ /* query from deleted-account-info table */
+ ACCOUNT_MEMSET(query, 0x00, ACCOUNT_SQL_LEN_MAX);
+ ACCOUNT_SNPRINTF(query, sizeof(query), "SELECT * FROM %s WHERE _id = %d", DELETED_ACCOUNT_TABLE, account_db_id);
+
+ /*free previous hstmt*/
+ if (hstmt != NULL) {
+ rc = _account_query_finalize(hstmt);
+ ACCOUNT_RETURN_VAL((rc == _ACCOUNT_ERROR_NONE), {}, rc, ("finalize error"));
+ hstmt = NULL;
+ }
+
+ hstmt = _account_prepare_query(g_hAccountDB, query);
+
+ rc = _account_db_err_code(g_hAccountDB);
+ if (rc == SQLITE_PERM) {
+ ACCOUNT_ERROR("Access failed(%s)", _account_db_err_msg(g_hAccountDB));
+ return _ACCOUNT_ERROR_PERMISSION_DENIED;
+ }
+
+ rc = _account_query_step(hstmt);
+ ACCOUNT_CATCH_ERROR(rc == SQLITE_ROW, {}, _ACCOUNT_ERROR_RECORD_NOT_FOUND, ("The record isn't found.\n"));
+
+ ACCOUNT_DEBUG("getting account info from deleted_account_table");
+ *IsDeletedAccount = true;
+ }
while (rc == SQLITE_ROW) {
ACCOUNT_DEBUG("before _account_convert_column_to_account");
@@ -2325,7 +2480,7 @@ int account_server_delete_account_by_package_name(const char* package_name, bool
int _account_delete(int pid, uid_t uid, int account_id)
{
- int error_code = _ACCOUNT_ERROR_NONE;
+ int error_code = _ACCOUNT_ERROR_NONE;
account_stmt hstmt = NULL;
char query[ACCOUNT_SQL_LEN_MAX] = {0, };
int rc = 0;
@@ -2398,6 +2553,7 @@ int _account_delete(int pid, uid_t uid, int account_id)
return ret_transaction;
}
+ /* capability table */
ACCOUNT_MEMSET(query, 0x00, sizeof(query));
ACCOUNT_SNPRINTF(query, sizeof(query), "DELETE FROM %s WHERE account_id = %d", CAPABILITY_TABLE, account_id);
@@ -2420,8 +2576,8 @@ int _account_delete(int pid, uid_t uid, int account_id)
ACCOUNT_RETURN_VAL((rc == _ACCOUNT_ERROR_NONE), {}, rc, ("finalize error"));
hstmt = NULL;
+ /* account table */
ACCOUNT_MEMSET(query, 0, sizeof(query));
-
ACCOUNT_SNPRINTF(query, sizeof(query), "DELETE FROM %s WHERE _id = %d", ACCOUNT_TABLE, account_id);
hstmt = _account_prepare_query(g_hAccountDB, query);
@@ -2437,7 +2593,6 @@ int _account_delete(int pid, uid_t uid, int account_id)
/* delete custom data */
ACCOUNT_MEMSET(query, 0, sizeof(query));
-
ACCOUNT_SNPRINTF(query, sizeof(query), "DELETE FROM %s WHERE AccountId = %d", ACCOUNT_CUSTOM_TABLE, account_id);
hstmt = _account_prepare_query(g_hAccountDB, query);
diff --git a/server/src/account-server.c b/server/src/account-server.c
index 306ff61..732e840 100644
--- a/server/src/account-server.c
+++ b/server/src/account-server.c
@@ -37,10 +37,16 @@
#include "account-server-db.h"
#include "lifecycle.h"
+
#define _PRIVILEGE_ACCOUNT_READ "http://tizen.org/privilege/account.read"
#define _PRIVILEGE_ACCOUNT_WRITE "http://tizen.org/privilege/account.write"
#define ACCOUNT_MGR_DBUS_PATH "/org/tizen/account/manager"
+
+#define DEL_ACCOUNT_TBL "deleted_account"
+#define DEL_CAPABILITY_TBL "deleted_capability"
+#define DEL_ACCOUNT_CUSTOM_TBL "deleted_account_custom"
+
static guint owner_id = 0;
static AccountManager* account_mgr_server_obj = NULL;
static GMainLoop *mainloop = NULL;
@@ -1179,13 +1185,14 @@ RETURN:
gboolean
account_manager_handle_account_query_account_by_account_id(AccountManager *object, GDBusMethodInvocation *invocation,
- gint account_db_id, gint uid)
+ gint account_db_id, gint uid)
{
_INFO("account_manager_handle_account_query_account_by_account_id start");
lifecycle_method_call_active();
GVariant* account_variant = NULL;
account_s* account_data = NULL;
+ bool IsDeletedAccount = false;
guint pid = _get_client_pid(invocation);
@@ -1217,7 +1224,7 @@ account_manager_handle_account_query_account_by_account_id(AccountManager *objec
}
_INFO("before _account_query_account_by_account_id");
- return_code = _account_query_account_by_account_id(pid, (uid_t)uid, account_db_id, account_data);
+ return_code = _account_query_account_by_account_id(pid, (uid_t)uid, account_db_id, account_data, &IsDeletedAccount);
_INFO("after _account_query_account_by_return_code=[%d]", return_code);
_INFO("user_name = %s, user_data_txt[0] = %s, user_data_int[1] = %d", account_data->user_name, account_data->user_data_txt[0], account_data->user_data_int[1]);
@@ -1239,6 +1246,13 @@ RETURN:
account_manager_complete_account_query_account_by_account_id(object, invocation, account_variant);
}
+ /*clear deleted account tables*/
+ if (IsDeletedAccount) {
+ _INFO("deleted account info requested");
+ return_code = account_server_empty_deleted_account_info_tables(DEL_ACCOUNT_TBL, DEL_CAPABILITY_TBL, DEL_ACCOUNT_CUSTOM_TBL);
+ ACCOUNT_RETURN_VAL((return_code == _ACCOUNT_ERROR_NONE), {}, return_code, ("failed to clear deleted account tables"));
+ }
+
return_code = _account_db_close();
if (return_code != _ACCOUNT_ERROR_NONE) {
ACCOUNT_DEBUG("_account_db_close() fail[%d]", return_code);
@@ -1261,9 +1275,9 @@ RETURN:
gboolean
account_manager_handle_account_query_account_by_user_name(AccountManager *obj,
- GDBusMethodInvocation *invocation,
- const gchar *user_name,
- gint uid)
+ GDBusMethodInvocation *invocation,
+ const gchar *user_name,
+ gint uid)
{
_INFO("account_manager_handle_account_query_account_by_user_name start");
lifecycle_method_call_active();