src/pkgmgr-server.c
src/request.c
src/pm-queue.c
- src/db.c
src/restriction_mode.c
)
pkgmgr-info
libtzplatform-config
drm-service-core-tizen
- sqlite3
libgum
pkgmgr
pkgmgr-installer)
ADD_EXECUTABLE(${PKGMGR_SERVER} ${SRCS})
TARGET_LINK_LIBRARIES(${PKGMGR_SERVER} pkgmgr_installer)
-TARGET_LINK_LIBRARIES(${PKGMGR_SERVER} ${SERVER_DEPS_LDFLAGS})
+TARGET_LINK_LIBRARIES(${PKGMGR_SERVER} ${SERVER_DEPS_LDFLAGS} -lgdbm)
CONFIGURE_FILE(org.tizen.pkgmgr.service.in org.tizen.pkgmgr.service @ONLY)
CONFIGURE_FILE(org.tizen.pkgmgr.conf.in org.tizen.pkgmgr.conf @ONLY)
+++ /dev/null
-PRAGMA user_version = 30; /* Tizen 3.0 */
-PRAGMA journal_mode = WAL;
-
-CREATE TABLE blacklist (
- uid INTEGER NOT NULL,
- pkgid TEXT NOT NULL,
- UNIQUE (uid, pkgid)
-);
PKGMGR_REQUEST_TYPE_GENERATE_LICENSE_REQUEST,
PKGMGR_REQUEST_TYPE_REGISTER_LICENSE,
PKGMGR_REQUEST_TYPE_DECRYPT_PACKAGE,
- PKGMGR_REQUEST_TYPE_ADD_BLACKLIST,
- PKGMGR_REQUEST_TYPE_REMOVE_BLACKLIST,
- PKGMGR_REQUEST_TYPE_CHECK_BLACKLIST,
PKGMGR_REQUEST_TYPE_ENABLE_APP_SPLASH_SCREEN,
PKGMGR_REQUEST_TYPE_DISABLE_APP_SPLASH_SCREEN,
PKGMGR_REQUEST_TYPE_SET_RESTRICTION_MODE,
int __return_value_to_caller(const char *req_key, GVariant *result);
int __init_request_handler(void);
void __fini_request_handler(void);
-int __add_blacklist(uid_t uid, const char *pkgid);
-int __remove_blacklist(uid_t uid, const char *pkgid);
-int __check_blacklist(uid_t uid, const char *pkgid, int *result);
-int __set_restriction_mode(uid_t uid, int mode);
-int __unset_restriction_mode(uid_t uid, int mode);
-int __get_restriction_mode(uid_t uid, int *result);
+int __restriction_mode_set(uid_t uid, const char *pkgid, int mode);
+int __restriction_mode_unset(uid_t uid, const char *pkgid, int mode);
+int __restriction_mode_get(uid_t uid, const char *pkgid, int *mode);
#endif/* _PKGMGR_SERVER_H_ */
<busconfig>
<policy user="root">
<allow own="org.tizen.pkgmgr"/>
+ <allow send_destination="org.tizen.pkgmgr" send_interface="org.tizen.pkgmgr" send_member="set_restriction_mode"/>
+ <allow send_destination="org.tizen.pkgmgr" send_interface="org.tizen.pkgmgr" send_member="unset_restriction_mode"/>
+ <allow send_destination="org.tizen.pkgmgr" send_interface="org.tizen.pkgmgr" send_member="get_restriction_mode"/>
</policy>
<policy context="default">
<allow send_destination="org.tizen.pkgmgr"/>
<check send_destination="org.tizen.pkgmgr" send_interface="org.tizen.pkgmgr" send_member="check_blacklist" privilege="http://tizen.org/privilege/packagemanager.admin"/>
<check send_destination="org.tizen.pkgmgr" send_interface="org.tizen.pkgmgr" send_member="enable_app_splash_screen" privilege="http://tizen.org/privilege/packagemanager.admin"/>
<check send_destination="org.tizen.pkgmgr" send_interface="org.tizen.pkgmgr" send_member="disable_app_splash_screen" privilege="http://tizen.org/privilege/packagemanager.admin"/>
- <check send_destination="org.tizen.pkgmgr" send_interface="org.tizen.pkgmgr" send_member="set_restriction_mode" privilege="http://tizen.org/privilege/packagemanager.admin"/>
- <check send_destination="org.tizen.pkgmgr" send_interface="org.tizen.pkgmgr" send_member="unset_restriction_mode" privilege="http://tizen.org/privilege/packagemanager.admin"/>
- <check send_destination="org.tizen.pkgmgr" send_interface="org.tizen.pkgmgr" send_member="get_restriction_mode" privilege="http://tizen.org/privilege/packagemanager.admin"/>
- </policy>
+ </policy>
</busconfig>
BuildRequires: pkgconfig(pkgmgr)
BuildRequires: pkgconfig(pkgmgr-installer)
BuildRequires: pkgconfig(drm-service-core-tizen)
-BuildRequires: pkgconfig(sqlite3)
BuildRequires: pkgconfig(libgum)
+BuildRequires: gdbm-devel
BuildRequires: pkgmgr-info-parser-devel
BuildRequires: pkgmgr-info-parser
BuildRequires: fdupes
%setup -q
cp %{SOURCE1001} .
-%define db_dir %{_localstatedir}/lib/package-manager
%define run_dir /run/user
%define backend_dir %{_sysconfdir}/package-manager/backend
%build
-sqlite3 blacklist.db < ./blacklist.sql
-
-%cmake . -DDB_DIR=%{db_dir} -DBACKEND_DIR=%{backend_dir}
+%cmake . -DRUN_DIR=%{run_dir} -DBACKEND_DIR=%{backend_dir}
%__make %{?_smp_mflags}
cp LICENSE %{buildroot}/usr/share/license/%{name}
mkdir -p %{buildroot}%{_sysconfdir}/package-manager/server
-mkdir -p %{buildroot}%{db_dir}
-install -m 0600 blacklist.db %{buildroot}%{db_dir}
-
%fdupes %{buildroot}
%post
%config %{_sysconfdir}/dbus-1/system.d/org.tizen.pkgmgr.conf
%{_bindir}/pkgmgr-server
%{_sysconfdir}/package-manager/server
-%config(noreplace) %{db_dir}/blacklist.db
%exclude %{_sysconfdir}/package-manager/server/queue_status
/usr/share/license/%{name}
+++ /dev/null
-/*
- * Copyright (c) 2000 - 2016 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include <stdio.h>
-#include <string.h>
-#include <sys/types.h>
-
-#include <sqlite3.h>
-
-#include <package-manager.h>
-
-#include "pkgmgr-server.h"
-
-#ifndef DB_DIR
-#define DB_DIR "/var/lib/package-manager"
-#endif
-
-static const char *_get_db_path(void)
-{
- return DB_DIR"/blacklist.db";
-}
-
-static sqlite3 *_open_db(void)
-{
- int ret;
- const char *path;
- sqlite3 *db;
-
- path = _get_db_path();
- if (path == NULL) {
- ERR("get db path error");
- return NULL;
- }
-
- ret = sqlite3_open_v2(path, &db, SQLITE_OPEN_READWRITE, NULL);
- if (ret != SQLITE_OK) {
- ERR("open db error: %d", ret);
- return NULL;
- }
-
- return db;
-}
-
-static int __add_blacklist_info(sqlite3 *db, uid_t uid, const char *pkgid)
-{
- static const char query[] =
- "INSERT INTO blacklist (uid, pkgid) VALUES(?, ?)";
- int ret;
- sqlite3_stmt *stmt;
-
- ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
- if (ret != SQLITE_OK) {
- ERR("prepare error: %s", sqlite3_errmsg(db));
- return -1;
- }
-
- sqlite3_bind_int(stmt, 1, uid);
- sqlite3_bind_text(stmt, 2, pkgid, -1, SQLITE_STATIC);
-
- ret = sqlite3_step(stmt);
- sqlite3_finalize(stmt);
- if (ret != SQLITE_DONE) {
- ERR("step error: %s", sqlite3_errmsg(db));
- return -1;
- }
-
- return 0;
-}
-
-int __add_blacklist(uid_t uid, const char *pkgid)
-{
- int ret;
- sqlite3 *db;
-
- db = _open_db();
- if (db == NULL)
- return PKGMGR_R_ERROR;
-
- ret = sqlite3_exec(db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
- if (ret != SQLITE_OK) {
- sqlite3_close_v2(db);
- ERR("transaction failed");
- return PKGMGR_R_ERROR;
- }
-
- if (__add_blacklist_info(db, uid, pkgid)) {
- sqlite3_exec(db, "ROLLBACK", NULL, NULL, NULL);
- sqlite3_close_v2(db);
- return PKGMGR_R_ERROR;
- }
-
- ret = sqlite3_exec(db, "COMMIT", NULL, NULL, NULL);
- if (ret != SQLITE_OK) {
- ERR("commit error: %s", sqlite3_errmsg(db));
- sqlite3_close_v2(db);
- return PKGMGR_R_ERROR;
- }
-
- sqlite3_close_v2(db);
-
- return PKGMGR_R_OK;
-}
-
-static int __remove_blacklist_info(sqlite3 *db, uid_t uid, const char *pkgid)
-{
- static const char query[] =
- "DELETE FROM blacklist WHERE uid=? AND pkgid=?";
- int ret;
- sqlite3_stmt *stmt;
-
- ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
- if (ret != SQLITE_OK) {
- ERR("prepare error: %s", sqlite3_errmsg(db));
- return -1;
- }
-
- sqlite3_bind_int(stmt, 1, uid);
- sqlite3_bind_text(stmt, 2, pkgid, -1, SQLITE_STATIC);
-
- ret = sqlite3_step(stmt);
- sqlite3_finalize(stmt);
- if (ret != SQLITE_DONE) {
- ERR("step error: %s", sqlite3_errmsg(db));
- return -1;
- }
-
- return 0;
-}
-
-int __remove_blacklist(uid_t uid, const char *pkgid)
-{
- int ret;
- sqlite3 *db;
-
- db = _open_db();
- if (db == NULL)
- return PKGMGR_R_ERROR;
-
- ret = sqlite3_exec(db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
- if (ret != SQLITE_OK) {
- sqlite3_close_v2(db);
- ERR("transaction failed");
- return PKGMGR_R_ERROR;
- }
-
- if (__remove_blacklist_info(db, uid, pkgid)) {
- sqlite3_exec(db, "ROLLBACK", NULL, NULL, NULL);
- sqlite3_close_v2(db);
- return PKGMGR_R_ERROR;
- }
-
- ret = sqlite3_exec(db, "COMMIT", NULL, NULL, NULL);
- if (ret != SQLITE_OK) {
- ERR("commit error: %s", sqlite3_errmsg(db));
- sqlite3_close_v2(db);
- return PKGMGR_R_ERROR;
- }
-
- sqlite3_close_v2(db);
-
- return PKGMGR_R_OK;
-}
-
-int __check_blacklist(uid_t uid, const char *pkgid, int *result)
-{
- static const char query[] =
- "SELECT * FROM blacklist WHERE uid=? AND pkgid=?";
- int ret;
- sqlite3 *db;
- sqlite3_stmt *stmt;
-
- db = _open_db();
- if (db == NULL) {
- *result = 0;
- return PKGMGR_R_ERROR;
- }
-
- ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
- if (ret != SQLITE_OK) {
- ERR("prepare error: %s", sqlite3_errmsg(db));
- *result = 0;
- sqlite3_close_v2(db);
- return PKGMGR_R_ERROR;
- }
-
- sqlite3_bind_int(stmt, 1, uid);
- sqlite3_bind_text(stmt, 2, pkgid, -1, SQLITE_STATIC);
-
- ret = sqlite3_step(stmt);
- sqlite3_finalize(stmt);
- if (ret != SQLITE_ROW) {
- if (ret != SQLITE_DONE)
- ERR("step error: %s", sqlite3_errmsg(db));
- *result = 0;
- sqlite3_close_v2(db);
- return ret == SQLITE_DONE ? PKGMGR_R_OK : PKGMGR_R_ERROR;
- }
-
- *result = 1;
- sqlite3_close_v2(db);
-
- return PKGMGR_R_OK;
-}
return 0;
}
-static int __process_add_blacklist(pm_dbus_msg *item)
-{
- int ret;
-
- ret = __add_blacklist(item->uid, item->pkgid);
-
- __return_value_to_caller(item->req_id,
- g_variant_new("(i)", ret));
-
- return ret;
-}
-
-static int __process_remove_blacklist(pm_dbus_msg *item)
-{
- int ret;
-
- ret = __remove_blacklist(item->uid, item->pkgid);
-
- __return_value_to_caller(item->req_id,
- g_variant_new("(i)", ret));
-
- return ret;
-}
-
-static int __process_check_blacklist(pm_dbus_msg *item)
-{
- int ret;
- int result = 0;
-
- ret = __check_blacklist(item->uid, item->pkgid, &result);
-
- __return_value_to_caller(item->req_id,
- g_variant_new("(ii)", result, ret));
-
- return ret;
-}
-
static int __process_update_app_splash_screen(pm_dbus_msg *item, int flag)
{
int ret;
int mode;
mode = atoi(item->args);
- ret = __set_restriction_mode(item->uid, mode);
+ ret = __restriction_mode_set(item->uid, item->pkgid, mode);
__return_value_to_caller(item->req_id,
g_variant_new("(i)", ret));
int mode;
mode = atoi(item->args);
- ret = __unset_restriction_mode(item->uid, mode);
+ ret = __restriction_mode_unset(item->uid, item->pkgid, mode);
__return_value_to_caller(item->req_id,
g_variant_new("(i)", ret));
static int __process_get_restriction_mode(pm_dbus_msg *item)
{
int ret;
- int result = -1;
+ int mode = -1;
- ret = __get_restriction_mode(item->uid, &result);
+ ret = __restriction_mode_get(item->uid, item->pkgid, &mode);
__return_value_to_caller(item->req_id,
- g_variant_new("(ii)", result, ret));
+ g_variant_new("(ii)", mode, ret));
return ret;
}
case PKGMGR_REQUEST_TYPE_DECRYPT_PACKAGE:
ret = __process_decrypt_package(item);
break;
- case PKGMGR_REQUEST_TYPE_ADD_BLACKLIST:
- ret = __process_add_blacklist(item);
- break;
- case PKGMGR_REQUEST_TYPE_REMOVE_BLACKLIST:
- ret = __process_remove_blacklist(item);
- break;
- case PKGMGR_REQUEST_TYPE_CHECK_BLACKLIST:
- ret = __process_check_blacklist(item);
- break;
case PKGMGR_REQUEST_TYPE_ENABLE_APP_SPLASH_SCREEN:
ret = __process_update_app_splash_screen(item, 1);
break;
" <arg type='s' name='decrypted_file_path' direction='in'/>"
" <arg type='i' name='ret' direction='out'/>"
" </method>"
- " <method name='add_blacklist'>"
- " <arg type='u' name='uid' direction='in'/>"
- " <arg type='s' name='pkgid' direction='in'/>"
- " <arg type='i' name='ret' direction='out'/>"
- " </method>"
- " <method name='remove_blacklist'>"
- " <arg type='u' name='uid' direction='in'/>"
- " <arg type='s' name='pkgid' direction='in'/>"
- " <arg type='i' name='ret' direction='out'/>"
- " </method>"
- " <method name='check_blacklist'>"
- " <arg type='u' name='uid' direction='in'/>"
- " <arg type='s' name='pkgid' direction='in'/>"
- " <arg type='i' name='result' direction='out'/>"
- " <arg type='i' name='ret' direction='out'/>"
- " </method>"
" <method name='enable_app_splash_screen'>"
" <arg type='u' name='uid' direction='in'/>"
" <arg type='s' name='appid' direction='in'/>"
" </method>"
" <method name='set_restriction_mode'>"
" <arg type='u' name='uid' direction='in'/>"
+ " <arg type='s' name='pkgid' direction='in'/>"
" <arg type='i' name='mode' direction='in'/>"
" <arg type='i' name='ret' direction='out'/>"
" </method>"
" <method name='unset_restriction_mode'>"
" <arg type='u' name='uid' direction='in'/>"
+ " <arg type='s' name='pkgid' direction='in'/>"
" <arg type='i' name='mode' direction='in'/>"
" <arg type='i' name='ret' direction='out'/>"
" </method>"
" <method name='get_restriction_mode'>"
" <arg type='u' name='uid' direction='in'/>"
+ " <arg type='s' name='pkgid' direction='in'/>"
" <arg type='i' name='result' direction='out'/>"
" <arg type='i' name='ret' direction='out'/>"
" </method>"
return 0;
}
-static int __handle_request_add_blacklist(uid_t uid,
- GDBusMethodInvocation *invocation, GVariant *parameters)
-{
- uid_t target_uid = (uid_t)-1;
- char *reqkey;
- char *pkgid = NULL;
-
- g_variant_get(parameters, "(u&s)", &target_uid, &pkgid);
- if (target_uid == (uid_t)-1 || pkgid == NULL) {
- g_dbus_method_invocation_return_value(invocation,
- g_variant_new("(i)", PKGMGR_R_ECOMM));
- return -1;
- }
-
- reqkey = __generate_reqkey("blacklist");
- if (reqkey == NULL) {
- g_dbus_method_invocation_return_value(invocation,
- g_variant_new("(i)", PKGMGR_R_ENOMEM));
- return -1;
- }
-
- if (_pm_queue_push(target_uid, reqkey,
- PKGMGR_REQUEST_TYPE_ADD_BLACKLIST,
- "default", pkgid, "")) {
- g_dbus_method_invocation_return_value(invocation,
- g_variant_new("(i)", PKGMGR_R_ESYSTEM));
- free(reqkey);
- return -1;
- }
-
- if (!g_hash_table_insert(req_table, (gpointer)reqkey,
- (gpointer)invocation))
- ERR("reqkey already exists");
-
- return 0;
-}
-
-static int __handle_request_remove_blacklist(uid_t uid,
- GDBusMethodInvocation *invocation, GVariant *parameters)
-{
- uid_t target_uid = (uid_t)-1;
- char *reqkey;
- char *pkgid = NULL;
-
- g_variant_get(parameters, "(u&s)", &target_uid, &pkgid);
- if (target_uid == (uid_t)-1 || pkgid == NULL) {
- g_dbus_method_invocation_return_value(invocation,
- g_variant_new("(i)", PKGMGR_R_ECOMM));
- return -1;
- }
-
- reqkey = __generate_reqkey("blacklist");
- if (reqkey == NULL) {
- g_dbus_method_invocation_return_value(invocation,
- g_variant_new("(i)", PKGMGR_R_ENOMEM));
- return -1;
- }
-
- if (_pm_queue_push(target_uid, reqkey,
- PKGMGR_REQUEST_TYPE_REMOVE_BLACKLIST,
- "default", pkgid, "")) {
- g_dbus_method_invocation_return_value(invocation,
- g_variant_new("(i)", PKGMGR_R_ESYSTEM));
- free(reqkey);
- return -1;
- }
-
- if (!g_hash_table_insert(req_table, (gpointer)reqkey,
- (gpointer)invocation))
- ERR("reqkey already exists");
-
- return 0;
-}
-
-static int __handle_request_check_blacklist(uid_t uid,
- GDBusMethodInvocation *invocation, GVariant *parameters)
-{
- uid_t target_uid = (uid_t)-1;
- char *reqkey;
- char *pkgid = NULL;
-
- g_variant_get(parameters, "(u&s)", &target_uid, &pkgid);
- if (target_uid == (uid_t)-1 || pkgid == NULL) {
- g_dbus_method_invocation_return_value(invocation,
- g_variant_new("(ii)", PKGMGR_R_ECOMM, -1));
- return -1;
- }
-
- reqkey = __generate_reqkey("blacklist");
- if (reqkey == NULL) {
- g_dbus_method_invocation_return_value(invocation,
- g_variant_new("(ii)", PKGMGR_R_ENOMEM, -1));
- return -1;
- }
-
- if (_pm_queue_push(target_uid, reqkey,
- PKGMGR_REQUEST_TYPE_CHECK_BLACKLIST,
- "default", pkgid, "")) {
- g_dbus_method_invocation_return_value(invocation,
- g_variant_new("(ii)", PKGMGR_R_ESYSTEM, -1));
- free(reqkey);
- return -1;
- }
-
- if (!g_hash_table_insert(req_table, (gpointer)reqkey,
- (gpointer)invocation))
- ERR("reqkey already exists");
-
- return 0;
-}
-
static int __update_app_splash_screen(uid_t uid,
GDBusMethodInvocation *invocation, GVariant *parameters,
int req_type)
GDBusMethodInvocation *invocation, GVariant *parameters)
{
uid_t target_uid = (uid_t)-1;
+ char *pkgid = NULL;
char *reqkey;
int mode = -1;
char buf[4];
- g_variant_get(parameters, "(ui)", &target_uid, &mode);
- if (target_uid == (uid_t)-1 || mode < 0) {
+ g_variant_get(parameters, "(usi)", &target_uid, &pkgid, &mode);
+ if (target_uid == (uid_t)-1 || pkgid == NULL || mode < 0) {
g_dbus_method_invocation_return_value(invocation,
g_variant_new("(i)", PKGMGR_R_ECOMM));
return -1;
snprintf(buf, sizeof(buf), "%d", mode);
if (_pm_queue_push(target_uid, reqkey,
PKGMGR_REQUEST_TYPE_SET_RESTRICTION_MODE,
- "default", "", buf)) {
+ "default", pkgid, buf)) {
g_dbus_method_invocation_return_value(invocation,
g_variant_new("(i)", PKGMGR_R_ESYSTEM));
free(reqkey);
GDBusMethodInvocation *invocation, GVariant *parameters)
{
uid_t target_uid = (uid_t)-1;
+ char *pkgid = NULL;
char *reqkey;
int mode = -1;
char buf[4];
- g_variant_get(parameters, "(ui)", &target_uid, &mode);
- if (target_uid == (uid_t)-1 || mode < 0) {
+ g_variant_get(parameters, "(usi)", &target_uid, &pkgid, &mode);
+ if (target_uid == (uid_t)-1 || pkgid == NULL || mode < 0) {
g_dbus_method_invocation_return_value(invocation,
g_variant_new("(i)", PKGMGR_R_ECOMM));
return -1;
snprintf(buf, sizeof(buf), "%d", mode);
if (_pm_queue_push(target_uid, reqkey,
PKGMGR_REQUEST_TYPE_UNSET_RESTRICTION_MODE,
- "default", "", buf)) {
+ "default", pkgid, buf)) {
g_dbus_method_invocation_return_value(invocation,
g_variant_new("(i)", PKGMGR_R_ESYSTEM));
free(reqkey);
GDBusMethodInvocation *invocation, GVariant *parameters)
{
uid_t target_uid = (uid_t)-1;
+ char *pkgid = NULL;
char *reqkey;
- g_variant_get(parameters, "(u)", &target_uid);
- if (target_uid == (uid_t)-1) {
+ g_variant_get(parameters, "(us)", &target_uid, &pkgid);
+ if (target_uid == (uid_t)-1 || pkgid == NULL) {
g_dbus_method_invocation_return_value(invocation,
g_variant_new("(i)", PKGMGR_R_ECOMM));
return -1;
if (_pm_queue_push(target_uid, reqkey,
PKGMGR_REQUEST_TYPE_GET_RESTRICTION_MODE,
- "default", "", "")) {
+ "default", pkgid, "")) {
g_dbus_method_invocation_return_value(invocation,
g_variant_new("(ii)", -1, PKGMGR_R_ESYSTEM));
free(reqkey);
else if (g_strcmp0(method_name, "decrypt_package") == 0)
ret = __handle_request_decrypt_package(uid, invocation,
parameters);
- else if (g_strcmp0(method_name, "add_blacklist") == 0)
- ret = __handle_request_add_blacklist(uid, invocation,
- parameters);
- else if (g_strcmp0(method_name, "remove_blacklist") == 0)
- ret = __handle_request_remove_blacklist(uid, invocation,
- parameters);
- else if (g_strcmp0(method_name, "check_blacklist") == 0)
- ret = __handle_request_check_blacklist(uid, invocation,
- parameters);
else if (g_strcmp0(method_name, "disable_app_splash_screen") == 0)
ret = __handle_request_disable_app_splash_screen(uid,
invocation, parameters);
-/*
- * Copyright (c) 2016 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
#include <stdio.h>
+#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
-#include <errno.h>
#include <sys/types.h>
-#include <sys/stat.h>
#include <fcntl.h>
-#include <unistd.h>
#include <linux/limits.h>
+#include <gdbm.h>
+
#include "pkgmgr-server.h"
#ifndef RUN_DIR
#define RUN_DIR "/run/user"
#endif
+#define RESTRICTION_DB ".package_manager_restriction_mode"
+#define VAL_SIZE sizeof(int)
+#define ALL_PKG "ALL_PKG"
-#define RESTRICTION_CONF ".package_manager_restriction_mode"
-
-static char *_get_conf_file_path(uid_t uid)
+static char *__get_dbpath(uid_t uid)
{
char buf[PATH_MAX];
- snprintf(buf, sizeof(buf), "%s/%d/%s", RUN_DIR, uid, RESTRICTION_CONF);
+ snprintf(buf, sizeof(buf), "%s/%d/%s", RUN_DIR, uid, RESTRICTION_DB);
return strdup(buf);
}
return cur & ~(mode);
}
-int __set_restriction_mode(uid_t uid, int mode)
+static GDBM_FILE __open(const char *path, bool writable)
{
- char *conf_path;
- int fd;
- int cur = 0;
- ssize_t len;
+ GDBM_FILE db;
+
+ db = gdbm_open((char *)path, 0, writable ? GDBM_WRCREAT : GDBM_READER,
+ S_IRUSR | S_IWUSR, NULL);
+ if (db == NULL)
+ ERR("failed to open gdbm file(%s): %d", path, gdbm_errno);
- conf_path = _get_conf_file_path(uid);
- if (conf_path == NULL) {
- ERR("failed to get conf path");
+ return db;
+}
+
+static void __close(GDBM_FILE dbf)
+{
+ gdbm_close(dbf);
+}
+
+static int __set_value(GDBM_FILE dbf, const char *pkgid, int mode)
+{
+ datum key;
+ datum content;
+ char buf[VAL_SIZE];
+
+ key.dptr = (char *)pkgid;
+ key.dsize = strlen(pkgid) + 1;
+
+ memcpy(buf, &mode, VAL_SIZE);
+ content.dptr = buf;
+ content.dsize = VAL_SIZE;
+
+ if (gdbm_store(dbf, key, content, GDBM_REPLACE)) {
+ ERR("failed to store value");
return -1;
}
- fd = open(conf_path, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR);
- if (fd < 0) {
- ERR("failed to open conf file: %d", errno);
- free(conf_path);
+ return 0;
+}
+
+static int __get_value(GDBM_FILE dbf, const char *pkgid, int *mode)
+{
+ datum key;
+ datum content;
+
+ key.dptr = (char *)pkgid;
+ key.dsize = strlen(pkgid) + 1;
+
+ content = gdbm_fetch(dbf, key);
+ if (content.dptr == NULL) {
+ DBG("no value for key(%s)", pkgid);
return -1;
}
- len = read(fd, &cur, sizeof(int));
- if (len < 0) {
- ERR("failed to read conf file: %d", errno);
- close(fd);
- free(conf_path);
+ if (content.dsize != VAL_SIZE)
+ ERR("content size is different");
+
+ memcpy(mode, content.dptr, VAL_SIZE);
+ free(content.dptr);
+
+ return 0;
+}
+
+int __restriction_mode_set(uid_t uid, const char *pkgid, int mode)
+{
+ GDBM_FILE dbf;
+ char *dbpath;
+ int cur = 0;
+
+ if (pkgid == NULL || !strcmp(pkgid, ""))
+ pkgid = ALL_PKG;
+
+ dbpath = __get_dbpath(uid);
+ if (dbpath == NULL)
+ return -1;
+
+ dbf = __open(dbpath, true);
+ if (dbf == NULL) {
+ free(dbpath);
return -1;
}
+ __get_value(dbf, pkgid, &cur);
mode = __set_mode(cur, mode);
- lseek(fd, 0, SEEK_SET);
- len = write(fd, &mode, sizeof(int));
- if (len < 0) {
- ERR("failed to write conf file: %d", errno);
- close(fd);
- free(conf_path);
+ if (__set_value(dbf, pkgid, mode)) {
+ free(dbpath);
return -1;
}
- close(fd);
- free(conf_path);
+ __close(dbf);
+ free(dbpath);
return 0;
}
-int __unset_restriction_mode(uid_t uid, int mode)
+int __restriction_mode_unset(uid_t uid, const char *pkgid, int mode)
{
- char *conf_path;
- int fd;
+ GDBM_FILE dbf;
+ char *dbpath;
int cur = 0;
- ssize_t len;
- conf_path = _get_conf_file_path(uid);
- if (conf_path == NULL) {
- ERR("failed to get conf path");
- return -1;
- }
+ if (pkgid == NULL || !strcmp(pkgid, ""))
+ pkgid = ALL_PKG;
- if (access(conf_path, F_OK) != 0) {
- ERR("restriction mode is not set");
- free(conf_path);
- return 0;
- }
-
- fd = open(conf_path, O_RDWR, 0);
- if (fd < 0) {
- ERR("failed to open conf file: %s", errno);
- free(conf_path);
+ dbpath = __get_dbpath(uid);
+ if (dbpath == NULL)
return -1;
- }
- len = read(fd, &cur, sizeof(int));
- if (len < 0) {
- ERR("failed to read conf file: %d", errno);
- close(fd);
- free(conf_path);
+ dbf = __open(dbpath, true);
+ if (dbf == NULL) {
+ free(dbpath);
return -1;
}
+ __get_value(dbf, pkgid, &cur);
mode = __unset_mode(cur, mode);
- lseek(fd, 0, SEEK_SET);
- len = write(fd, &mode, sizeof(int));
- if (len < 0) {
- ERR("failed to write conf file: %d", errno);
- close(fd);
- free(conf_path);
+ if (__set_value(dbf, pkgid, mode)) {
+ free(dbpath);
return -1;
}
- close(fd);
- free(conf_path);
+ __close(dbf);
+ free(dbpath);
return 0;
}
-int __get_restriction_mode(uid_t uid, int *result)
+int __restriction_mode_get(uid_t uid, const char *pkgid, int *mode)
{
- char *conf_path;
- int fd;
- int cur;
- ssize_t len;
+ GDBM_FILE dbf;
+ char *dbpath;
- conf_path = _get_conf_file_path(uid);
- if (conf_path == NULL)
- return -1;
-
- if (access(conf_path, F_OK) != 0) {
- free(conf_path);
- *result = 0;
- return 0;
- }
+ if (pkgid == NULL || !strcmp(pkgid, ""))
+ pkgid = ALL_PKG;
- fd = open(conf_path, O_RDONLY, 0);
- if (fd < 0) {
- ERR("failed to open conf file: %s", errno);
- free(conf_path);
+ dbpath = __get_dbpath(uid);
+ if (dbpath == NULL)
return -1;
- }
- len = read(fd, &cur, sizeof(int));
- if (len < 0) {
- ERR("failed to read conf file: %d", errno);
- close(fd);
- free(conf_path);
+ dbf = __open(dbpath, false);
+ if (dbf == NULL) {
+ if (gdbm_errno == GDBM_FILE_OPEN_ERROR) {
+ *mode = 0;
+ return 0;
+ }
+ free(dbpath);
return -1;
}
- *result = cur;
+ if (__get_value(dbf, pkgid, mode)) {
+ free(dbpath);
+ }
- close(fd);
- free(conf_path);
+ __close(dbf);
+ free(dbpath);
return 0;
}