From: Zofia Abramowska Date: Tue, 26 Jan 2016 11:13:17 +0000 (+0100) Subject: Add private sharing to sqlite database X-Git-Tag: accepted/tizen/mobile/20160217.011427~15 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F68%2F57968%2F9;p=platform%2Fcore%2Fsecurity%2Fsecurity-manager.git Add private sharing to sqlite database This patch introduces changes to database schema required to store information about private path sharing. Change-Id: I5c31decb1af2e062e5fb23108ffc9236c82763b6 --- diff --git a/db/db.sql b/db/db.sql index 2d354ea..931cb0f 100644 --- a/db/db.sql +++ b/db/db.sql @@ -44,6 +44,24 @@ FOREIGN KEY (app_id) REFERENCES app (app_id) FOREIGN KEY (privilege_id) REFERENCES privilege (privilege_id) ); +CREATE TABLE IF NOT EXISTS shared_path ( +path_id INTEGER PRIMARY KEY, +path VARCHAR NOT NULL, +path_label VARCHAR NOT NULL, +UNIQUE (path) +); + +CREATE TABLE IF NOT EXISTS app_private_sharing ( +owner_app_id INTEGER NOT NULL, +target_app_id INTEGER NOT NULL, +path_id INTEGER NOT NULL, +counter INTEGER NOT NULL, +PRIMARY KEY (owner_app_id, target_app_id, path_id) +FOREIGN KEY (owner_app_id) REFERENCES app (app_id) +FOREIGN KEY (target_app_id) REFERENCES app (app_id) +FOREIGN KEY (path_id) REFERENCES shared_path (path_id) +); + CREATE TABLE IF NOT EXISTS privilege_group ( privilege_id INTEGER NOT NULL, group_name VARCHAR NOT NULL, @@ -152,6 +170,56 @@ BEGIN DELETE FROM pkg WHERE pkg_id NOT IN (SELECT DISTINCT pkg_id from app); END; +DROP VIEW IF EXISTS app_private_sharing_view; +CREATE VIEW app_private_sharing_view AS +SELECT + app1.name AS owner_app_name, + app2.name AS target_app_name, + path, + path_label, + counter +FROM app_private_sharing +LEFT JOIN app AS app1 ON app1.app_id = owner_app_id +LEFT JOIN app AS app2 ON app2.app_id = target_app_id +LEFT JOIN shared_path USING (path_id); + +DROP TRIGGER IF EXISTS app_private_sharing_view_insert_trigger; +CREATE TRIGGER app_private_sharing_view_insert_trigger +INSTEAD OF INSERT ON app_private_sharing_view +BEGIN + INSERT OR IGNORE INTO shared_path(path, path_label) VALUES (NEW.path, NEW.path_label); + INSERT OR REPLACE INTO app_private_sharing VALUES ( + (SELECT app_id FROM app WHERE NEW.owner_app_name = name), + (SELECT app_id FROM app WHERE NEW.target_app_name = name), + (SELECT path_id FROM shared_path WHERE NEW.path = path), + COALESCE((SELECT counter FROM app_private_sharing + WHERE target_app_id = (SELECT app_id FROM app + WHERE NEW.target_app_name = name) + AND path_id = (SELECT path_id FROM shared_path WHERE NEW.path = path)), + 0) + 1); +END; + +DROP TRIGGER IF EXISTS app_private_sharing_view_remove_delete_trigger; +CREATE TRIGGER app_private_sharing_view_remove_delete_trigger +INSTEAD OF DELETE ON app_private_sharing_view +WHEN OLD.counter = 1 +BEGIN + DELETE FROM app_private_sharing + WHERE path_id = (SELECT path_id FROM shared_path WHERE path = OLD.path) + AND target_app_id = (SELECT app_id FROM app WHERE name = OLD.target_app_name); + DELETE FROM shared_path WHERE path_id NOT IN (SELECT path_id FROM app_private_sharing) AND path = OLD.path; +END; + +DROP TRIGGER IF EXISTS app_private_sharing_view_decrement_delete_trigger; +CREATE TRIGGER app_private_sharing_view_decrement_delete_trigger +INSTEAD OF DELETE ON app_private_sharing_view +WHEN OLD.counter > 1 +BEGIN + UPDATE app_private_sharing SET counter = OLD.counter - 1 + WHERE target_app_id = (SELECT app_id FROM app WHERE name = OLD.target_app_name) + AND path_id = (SELECT path_id FROM shared_path WHERE path = OLD.path); +END; + DROP VIEW IF EXISTS privilege_group_view; CREATE VIEW privilege_group_view AS SELECT