2 * security-manager, database access
4 * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd All Rights Reserved
6 * Contact: Rafal Krypa <r.krypa@samsung.com>
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
23 * @file privilege_db.h
24 * @author Krzysztof Sasiak <k.sasiak@samsung.com>
25 * @author Rafal Krypa <r.krypa@samsung.com>
27 * @brief This file contains declaration of the API to privilges database.
36 #include <dpl/db/sql_connection.h>
38 #ifndef PRIVILEGE_DB_H_
39 #define PRIVILEGE_DB_H_
41 namespace SecurityManager {
43 typedef std::vector<std::string> TPermissionsList;
45 enum class QueryType {
50 ERemoveAppPermissions,
56 * PrivilegeDb database class
60 SecurityManager::DB::SqlConnection *mSqlConnection;
61 const std::map<QueryType, const char * const > Queries = {
62 { QueryType::EGetPkgPermissions, "SELECT permission_name FROM app_permission_view WHERE pkg_name=?"},
63 { QueryType::EAddApplication, "INSERT INTO app_pkg_view (app_name, pkg_name) VALUES (?, ?)" },
64 { QueryType::ERemoveApplication, "DELETE FROM app_pkg_view WHERE app_name=? AND pkg_name=?" },
65 { QueryType::EAddAppPermissions, "INSERT INTO app_permission_view (app_name, pkg_name, permission_name) VALUES (?, ?, ?)" },
66 { QueryType::ERemoveAppPermissions, "DELETE FROM app_permission_view WHERE app_name=? AND pkg_name=? AND permission_name=?" },
67 { QueryType::EPkgIdExists, "SELECT * FROM pkg WHERE name=?" }
71 * Check if pkgId is already registered in database
73 * @param pkgId - package identifier
74 * @exception DB::SqlConnection::Exception::InternalError on internal error
75 * @return true if pkgId exists in the database
78 bool PkgIdExists(const std::string &pkgId);
81 * Check if there's a tuple of (appId, packageId) inside the database
83 * @param appId - application identifier
84 * @param pkgId - package identifier
85 * @param[out] currentPermissions - list of current permissions assigned to tuple (appId, pkgId)
86 * @exception DB::SqlConnection::Exception::InternalError on internal error
88 void GetPkgPermissions(const std::string &pkgId,
89 TPermissionsList ¤tPermission);
95 DECLARE_EXCEPTION_TYPE(SecurityManager::Exception, Base)
96 DECLARE_EXCEPTION_TYPE(Base, IOError)
97 DECLARE_EXCEPTION_TYPE(Base, InternalError)
102 * @exception DB::SqlConnection::Exception::IOError on problems with database access
105 PrivilegeDb(const std::string &path);
110 * @exception DB::SqlConnection::Exception::InternalError on internal error
113 void BeginTransaction(void);
117 * @exception DB::SqlConnection::Exception::InternalError on internal error
120 void CommitTransaction(void);
123 * Rollback transaction
124 * @exception DB::SqlConnection::Exception::InternalError on internal error
127 void RollbackTransaction(void);
130 * Add an application into the database
132 * @param appId - application identifier
133 * @param pkgId - package identifier
134 * @param[out] pkgIdIsNew - return info if pkgId is new to the database
135 * @exception DB::SqlConnection::Exception::InternalError on internal error
137 void AddApplication(const std::string &appId, const std::string &pkgId,
141 * Remove an application from the database
143 * @param appId - application identifier
144 * @param pkgId - package identifier
145 * @param[out] pkgIdIsNoMore - return info if pkgId is in the database
146 * @exception DB::SqlConnection::Exception::InternalError on internal error
148 void RemoveApplication(const std::string &appId, const std::string &pkgId,
149 bool &pkgIdIsNoMore);
152 * Update permissions belonging to tuple (appId, pkgId)
154 * @param appId - application identifier
155 * @param pkgId - package identifier
156 * @param permissions - list of permissions to assign
157 * @param[out] addedPermissions - return list of added permissions
158 * @param[out] removedPermissions - return list of removed permissions
159 * @exception DB::SqlConnection::Exception::InternalError on internal error
161 void UpdatePermissions(const std::string &appId,
162 const std::string &pkgId, const TPermissionsList &permissions,
163 TPermissionsList &addedPermissions,
164 TPermissionsList &removedPermissions);
168 } //namespace SecurityManager
170 #endif // PRIVILEGE_DB_H_