Add API_ERROR_DB_ALIAS_UNKNOWN error handle code in data remove functions
authoryuseok.jeon <yuseok.jeon@samsung.com>
Fri, 18 Jul 2014 10:39:14 +0000 (19:39 +0900)
committerBartlomiej Grzelewski <b.grzelewski@samsung.com>
Fri, 12 Sep 2014 12:58:58 +0000 (14:58 +0200)
Change-Id: I0eed434b775b6a2b38c970e293bbfed7fefe24c0
Signed-off-by: yuseok.jeon <yuseok.jeon@samsung.com>
src/manager/service/ckm-logic.cpp [changed mode: 0644->0755]

old mode 100644 (file)
new mode 100755 (executable)
index 8135a5a..948411f
@@ -249,11 +249,31 @@ RawBuffer CKMLogic::removeData(
     int retCode = CKM_API_SUCCESS;
 
     if (0 < m_userDataMap.count(cred.uid)) {
-        Try {
-            m_userDataMap[cred.uid].database.deleteDBRow(alias, cred.smackLabel);
-        } Catch (CKM::Exception) {
-            LogError("Error in deleting row!");
-            retCode = CKM_API_ERROR_DB_ERROR;
+       // check if the data exists or not
+        DBCrypto::DBRowOptional row_optional;
+        if (dataType == DBDataType::CERTIFICATE || dataType == DBDataType::BINARY_DATA) {
+            row_optional = m_userDataMap[cred.uid].database.getDBRow(alias, cred.smackLabel, dataType);
+        } else if ((static_cast<int>(dataType) >= static_cast<int>(DBDataType::DB_KEY_FIRST))
+                && (static_cast<int>(dataType) <= static_cast<int>(DBDataType::DB_KEY_LAST)))
+        {
+            row_optional = m_userDataMap[cred.uid].database.getKeyDBRow(alias, cred.smackLabel);
+        } else {
+            LogError("Unknown type of requested data" << (int)dataType);
+            retCode = CKM_API_ERROR_BAD_REQUEST;
+        }
+        if(!row_optional) {
+            LogError("No row for given alias, label and type");
+            retCode = CKM_API_ERROR_DB_ALIAS_UNKNOWN;
+        }
+
+        // remove if the data exists
+        if(retCode == CKM_API_SUCCESS) {
+            Try {
+                m_userDataMap[cred.uid].database.deleteDBRow(alias, cred.smackLabel);
+            } Catch (CKM::Exception) {
+                LogError("Error in deleting row!");
+                retCode = CKM_API_ERROR_DB_ERROR;
+            }
         }
     } else {
         retCode = CKM_API_ERROR_DB_LOCKED;