Fix for duplicates in all alias list query
authorKrzysztof Jackiewicz <k.jackiewicz@samsung.com>
Tue, 2 Dec 2014 16:28:24 +0000 (17:28 +0100)
committerMaciej J. Karpiuk <m.karpiuk2@samsung.com>
Tue, 17 Feb 2015 10:18:55 +0000 (11:18 +0100)
[Issue#] N/A
[Feature/Bug] N/A
[Problem] DBperfGetAliasList fails
[Cause] DB_CMD_NAME_SELECT_BY_TYPE_AND_PERMISSION query is incorrect. When
listing objects accessible by given label it will produce one result for every
owned object times the number of accessors allowed.

Example:
Label L1 is owner of object (L1 N1)
Labels L2 and L3 have read permission to (L1 N1)
Listing all aliases accessible by L1 will produce:
L1 N1 (access by L2)
L1 N1 (access by L3)

[Solution] Add GROUP BY clause clause to get rid of duplicated objects

[Verification] ckm-tests-internall succeeds

Change-Id: I63f0d576750038e0abc1d7d41921e05d87cadfe4

src/manager/service/db-crypto.cpp

index a67bae0..2ec31e0 100644 (file)
@@ -125,12 +125,18 @@ namespace {
             " idx=" DB_CMD_NAME_LOOKUP_IDX ";";
 
 
+    /*
+     * GROUP BY is necessary because of the following case:
+     * -There are several permissions to L1, N1 (label, name) from other accessors. When listing
+     *  objects accessible by L1 the query will produce one result (L1, N1) for each allowed
+     *  accessor but GROUP BY will reduce them to one so L1 will have (L1, N1) on its list only once
+     */
     const char *DB_CMD_NAME_SELECT_BY_TYPE_AND_PERMISSION =
             "SELECT N.label, N.name FROM NAME_TABLE AS N "
             " JOIN OBJECT_TABLE AS O ON O.idx=N.idx "
             " LEFT JOIN PERMISSION_TABLE AS P ON P.idx=N.idx "
             " WHERE O.dataType>=?001 AND O.dataType<=?002 AND "
-            " (N.label=?003 OR (P.label=?003 AND P.accessFlags IS NOT NULL));";
+            " ((N.label=?003) OR (P.label=?003 AND P.accessFlags IS NOT NULL)) GROUP BY N.idx;";
 }
 
 namespace CKM {