API for transaction rollback in libprivilege
authorPawel Broda <p.broda@partner.samsung.com>
Wed, 4 Dec 2013 13:27:26 +0000 (14:27 +0100)
committerKrzysztof Jackiewicz <k.jackiewicz@samsung.com>
Wed, 5 Feb 2014 10:19:56 +0000 (11:19 +0100)
[Issue#]       SSDWSSP-609
[Feature]      Provides possibility to rollback transaction.
[Cause]        N/A
[Solution]     N/A
[Verification] Build and run on the target.

Change-Id: Ic347e8c26733014564ccbc7d024d350bc87391cb

include/privilege-control.h
include/rules-db.h
src/privilege-control.c
src/rules-db.c

index cafa084..7469764 100644 (file)
@@ -61,13 +61,13 @@ extern "C" {
 /// Query fails during stepping a SQL statement
 #define PC_ERR_DB_QUERY_STEP            -10
 
-// Unable to establish a connection with the database
+/// Unable to establish a connection with the database
 #define PC_ERR_DB_CONNECTION            -11
 
-// There is no application with such app_id
+/// There is no application with such app_id
 #define PC_ERR_DB_NO_SUCH_APP           -12
 
-// There already exists a permission with this name and type
+/// There already exists a permission with this name and type
 #define PC_ERR_DB_PERM_FORBIDDEN        -13
 
 
@@ -517,6 +517,14 @@ int perm_begin(void);
 int perm_end(void);
 
 /**
+* Run to rollback any privilege modification.
+*
+* @return PC_OPERATION_SUCCESS on success,
+*         PC_ERR_* on error
+*/
+int perm_rollback(void);
+
+/**
  * Adds additional rules to the database. The rules can use wild-cards and labels.
  * It must be called within database transaction started with perm_begin() and
  * finished with perm_end().
index 9334ac3..b6b2200 100644 (file)
@@ -62,6 +62,17 @@ int rdb_modification_finish(void);
 
 
 /**
+ * Rollbacks last transaction and finishes session
+ * with the database.
+ *
+ * @ingroup RDB API functions
+ * @return  PC_OPERATION_SUCCESS on success,
+ *          error code otherwise
+ */
+int rdb_modification_rollback(void);
+
+
+/**
  * Add application label to the database.
  * If label present: do nothing.
  *
index ccb2b28..7840b9c 100644 (file)
@@ -112,6 +112,20 @@ API int perm_end(void)
        return rdb_modification_finish();
 }
 
+API int perm_rollback(void)
+{
+       SECURE_C_LOGD("Entering function: %s.", __func__);
+
+       int ret = rdb_modification_rollback();
+
+       if (ret != PC_OPERATION_SUCCESS) {
+               C_LOGE("RDB %s failed with: %d", __func__, ret);
+               return ret;
+       }
+
+       return PC_OPERATION_SUCCESS;
+}
+
 API int control_privilege(void)//deprecated
 {
        SECURE_C_LOGD("Entering function: %s.", __func__);
index 64e99f8..691cb76 100644 (file)
@@ -213,6 +213,19 @@ int rdb_modification_finish(void)
        }
 }
 
+int rdb_modification_rollback(void)
+{
+       if(p_db__) {
+               if(i_session_ret_code__ == PC_OPERATION_SUCCESS) {
+                       // Trigger rollback
+                       i_session_ret_code__ = PC_ERR_INVALID_OPERATION;
+               }
+               return rdb_modification_finish();
+       } else {
+               C_LOGE("RDB: Error nothing to rollback");
+               return PC_ERR_INVALID_OPERATION;
+       }
+}
 
 int rdb_add_application(const char *const s_label_name)
 {