--- /dev/null
+/*
+ * Copyright (c) 2019 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.
+ */
+
+#define _GNU_SOURCE
+#include <system_info.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <aul.h>
+#include <cert-svc/ccert.h>
+#include <cert-svc/cinstance.h>
+#include <cynara-session.h>
+#include <cynara-client.h>
+#include <cynara-creds-gdbus.h>
+#include <tzplatform_config.h>
+
+#include "alarm-manager-util.h"
+
+static int __bg_category_func(const char *name, void *user_data)
+{
+ bg_category_cb_info_t *info = (bg_category_cb_info_t *)user_data;
+ ALARM_MGR_LOG_PRINT("appid[%s], bg name = %s", info->appid, name);
+ if (name && strncmp("enable", name, strlen(name)) &&
+ strncmp("disable", name, strlen(name))) {
+ info->has_bg = true;
+ return -1;
+ }
+
+ return 0;
+}
+
+profile_t _get_profile()
+{
+ static profile_t saved = PROFILE_UNKNOWN;
+ char *profileName;
+ int r;
+
+ if (__builtin_expect(saved != PROFILE_UNKNOWN, 1))
+ return saved;
+
+ r = system_info_get_platform_string("http://tizen.org/feature/profile",
+ &profileName);
+ if (r != SYSTEM_INFO_ERROR_NONE) {
+ ALARM_MGR_LOG_PRINT("Failed to get profile info. error(%d)", r);
+ return saved;
+ }
+
+ switch (*profileName) {
+ case 'm':
+ case 'M':
+ saved = PROFILE_MOBILE;
+ break;
+ case 'w':
+ case 'W':
+ saved = PROFILE_WEARABLE;
+ break;
+ case 't':
+ case 'T':
+ saved = PROFILE_TV;
+ break;
+ case 'i':
+ case 'I':
+ saved = PROFILE_IVI;
+ break;
+ default: // common or unknown ==> ALL ARE COMMON.
+ saved = PROFILE_COMMON;
+ }
+ free(profileName);
+
+ return saved;
+}
+
+int _pkg_is_global(const char *callee_pkgid, uid_t uid)
+{
+ int retval;
+ int return_code = ERR_ALARM_SYSTEM_FAIL;
+ pkgmgrinfo_pkginfo_h handle;
+
+ retval = pkgmgrinfo_pkginfo_get_usr_pkginfo(callee_pkgid, uid, &handle);
+ if (retval != PMINFO_R_OK) {
+ ALARM_MGR_EXCEPTION_PRINT("Failed to get pkginfo\n");
+ return_code = ERR_ALARM_INVALID_ID;
+ } else {
+ bool is_global = 0;
+ retval = pkgmgrinfo_pkginfo_is_global(handle, &is_global);
+ if (retval == PMINFO_R_OK && is_global)
+ return_code = ALARMMGR_RESULT_SUCCESS;
+ else if (retval == PMINFO_R_OK && !is_global)
+ return_code = ERR_ALARM_NOT_PERMITTED_APP;
+
+ pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
+ }
+
+ return return_code;
+}
+
+int _cynara_check(GDBusMethodInvocation *invocation, const char *privilege,
+ pid_t pid)
+{
+ int ret = 0;
+ char *user = NULL;
+ char *client = NULL;
+ char *client_session = NULL;
+ cynara *p_cynara = NULL;
+ const char *sender_unique_name;
+ GDBusConnection *connection;
+
+ connection = g_dbus_method_invocation_get_connection(invocation);
+ sender_unique_name = g_dbus_method_invocation_get_sender(invocation);
+
+ ret = cynara_initialize(&p_cynara, NULL);
+ if (ret != CYNARA_API_SUCCESS) {
+ ALARM_MGR_EXCEPTION_PRINT("cynara_initialize() failed : %d", ret);
+ ret = ERR_ALARM_SYSTEM_FAIL;
+ goto cynara_out;
+ }
+
+ ret = cynara_creds_gdbus_get_user(connection, sender_unique_name,
+ USER_METHOD_DEFAULT, &user);
+ if (ret != CYNARA_API_SUCCESS) {
+ ALARM_MGR_EXCEPTION_PRINT("cynara_creds_gdbus_get_user() failed : %d", ret);
+ ret = ERR_ALARM_SYSTEM_FAIL;
+ goto cynara_out;
+ }
+
+ ret = cynara_creds_gdbus_get_client(connection, sender_unique_name,
+ CLIENT_METHOD_DEFAULT, &client);
+ if (ret != CYNARA_API_SUCCESS) {
+ ALARM_MGR_EXCEPTION_PRINT("cynara_creds_gdbus_get_client() failed : %d", ret);
+ ret = ERR_ALARM_SYSTEM_FAIL;
+ goto cynara_out;
+ }
+
+ ALARM_MGR_LOG_PRINT("user :%s , client :%s ,unique_name : %s, pid() : %d",
+ user, client, sender_unique_name, pid);
+
+ client_session = cynara_session_from_pid(pid);
+ if (!client_session) {
+ ALARM_MGR_EXCEPTION_PRINT("cynara_session_from_pid() failed : %d", ret);
+ ret = ERR_ALARM_SYSTEM_FAIL;
+ goto cynara_out;
+ }
+
+ ret = cynara_check(p_cynara, client, client_session, user,
+ privilege);
+ if (ret == CYNARA_API_ACCESS_ALLOWED) {
+ ALARM_MGR_LOG_PRINT("CYNARA_ACCESS_ALLOWED");
+ ret = ALARMMGR_RESULT_SUCCESS;
+ }
+ else {
+ ALARM_MGR_LOG_PRINT("CYNARA_NOT_ALLOWED [%d]", ret);
+ ret = ERR_ALARM_NOT_PERMITTED_APP;
+ }
+
+cynara_out:
+ if (client_session)
+ g_free(client_session);
+ if (client)
+ g_free(client);
+ if (user)
+ g_free(user);
+ if (p_cynara)
+ cynara_finish(p_cynara);
+
+ return ret;
+}
+
+char *_get_pkgid_by_appid(const char *app_id, uid_t uid)
+{
+ pkgmgrinfo_pkginfo_h handle;
+ char *pkgid = NULL;
+ char *temp;
+
+ if (pkgmgrinfo_appinfo_get_usr_appinfo(app_id, uid, &handle) == PMINFO_R_OK) {
+ if (pkgmgrinfo_appinfo_get_pkgid(handle, &temp) == PMINFO_R_OK) {
+ if (temp)
+ pkgid = strdup(temp);
+ }
+ pkgmgrinfo_appinfo_destroy_appinfo(handle);
+ }
+
+ return pkgid;
+}
+
+int _is_ui_app(const char *appid, uid_t uid)
+{
+ int ret = 0;
+ int found = 0;
+ char *component = NULL;
+ pkgmgrinfo_appinfo_h appinfo_h = NULL;
+
+ if (appid == NULL)
+ return 0;
+
+ ret = pkgmgrinfo_appinfo_get_usr_appinfo(appid, uid, &appinfo_h);
+ if (ret < 0)
+ return 0;
+
+ ret = pkgmgrinfo_appinfo_get_component_type(appinfo_h, &component);
+ if (ret == 0 && component != NULL && strncmp(component, "uiapp", 5) == 0)
+ found = 1;
+
+ if (appinfo_h)
+ pkgmgrinfo_appinfo_destroy_appinfo(appinfo_h);
+
+ return found;
+}
+
+bool _is_app(const char *appid, uid_t uid)
+{
+ pkgmgrinfo_appinfo_h appinfo_h = NULL;
+ int ret;
+
+ ret = pkgmgrinfo_appinfo_get_usr_appinfo(appid, uid, &appinfo_h);
+ if (ret != PMINFO_R_OK)
+ return false;
+
+ if (appinfo_h)
+ pkgmgrinfo_appinfo_destroy_appinfo(appinfo_h);
+
+ return true;
+}
+
+int _compare_api_version(int *result, int pid, uid_t uid)
+{
+ int ret = 0;
+ pkgmgrinfo_pkginfo_h pkginfo = NULL;
+ char pkgid[512] = {0, };
+ char *pkg_version;
+
+ if (aul_app_get_pkgid_bypid_for_uid(pid, pkgid, sizeof(pkgid), uid) != AUL_R_OK) {
+ ALARM_MGR_EXCEPTION_PRINT("aul_app_get_pkgid_bypid() is failed. PID %d may not be app.", getpid());
+ } else {
+ ret = pkgmgrinfo_pkginfo_get_usr_pkginfo(pkgid, uid, &pkginfo);
+ if (ret != PMINFO_R_OK) {
+ ALARM_MGR_EXCEPTION_PRINT("Failed to get pkginfo\n");
+ } else {
+ ret = pkgmgrinfo_pkginfo_get_api_version(pkginfo, &pkg_version);
+ if (ret != PMINFO_R_OK)
+ ALARM_MGR_EXCEPTION_PRINT("Failed to check api version [%d]\n", ret);
+ *result = strverscmp(pkg_version, "2.4");
+ pkgmgrinfo_pkginfo_destroy_pkginfo(pkginfo);
+ }
+ }
+ return ret;
+}
+
+bool _permit_by_config(pkgmgrinfo_appinfo_h handle, uid_t uid)
+{
+ if (access(tzplatform_mkpath(TZ_SYS_RO_SHARE,
+ "alarm-manager/alarm-config-service-restricted"), F_OK) == 0) {
+ ALARM_MGR_LOG_PRINT("This profile restrict alarms for service applications\n");
+ return false;
+ }
+
+ if (access(tzplatform_mkpath(TZ_SYS_RO_SHARE,
+ "alarm-manager/alarm-config-platform-service-permitted"), F_OK) == 0) {
+ ALARM_MGR_LOG_PRINT("This profile permit alarm for service applications which has platform cert\n");
+ char *pkgid;
+ int r;
+ const char *cert_value;
+ pkgmgrinfo_certinfo_h certinfo;
+ CertSvcInstance instance;
+ CertSvcCertificate certificate;
+ CertSvcVisibility visibility = CERTSVC_VISIBILITY_PUBLIC;
+
+ r = pkgmgrinfo_appinfo_get_pkgid(handle, &pkgid);
+ if (r != PMINFO_R_OK) {
+ ALARM_MGR_EXCEPTION_PRINT("Failed to get certinfo pkgid");
+ return false;
+ }
+
+ r = pkgmgrinfo_pkginfo_create_certinfo(&certinfo);
+ if (r != PMINFO_R_OK) {
+ ALARM_MGR_EXCEPTION_PRINT("Failed to create certinfo");
+ return false;
+ }
+
+ r = pkgmgrinfo_pkginfo_load_certinfo(pkgid, certinfo, uid);
+ if (r != PMINFO_R_OK) {
+ ALARM_MGR_EXCEPTION_PRINT("Failed to load certinfo");
+ pkgmgrinfo_pkginfo_destroy_certinfo(certinfo);
+ return false;
+ }
+
+ r = pkgmgrinfo_pkginfo_get_cert_value(certinfo,
+ PMINFO_DISTRIBUTOR_ROOT_CERT, &cert_value);
+ if (r != PMINFO_R_OK || cert_value == NULL) {
+ ALARM_MGR_EXCEPTION_PRINT("Failed to get cert value");
+ pkgmgrinfo_pkginfo_destroy_certinfo(certinfo);
+ return false;
+ }
+
+ r = certsvc_instance_new(&instance);
+ if (r != CERTSVC_SUCCESS) {
+ ALARM_MGR_EXCEPTION_PRINT("certsvc_instance_new() is failed.");
+ pkgmgrinfo_pkginfo_destroy_certinfo(certinfo);
+ return false;
+ }
+
+ r = certsvc_certificate_new_from_memory(instance,
+ (const unsigned char *)cert_value,
+ strlen(cert_value),
+ CERTSVC_FORM_DER_BASE64,
+ &certificate);
+ if (r != CERTSVC_SUCCESS) {
+ ALARM_MGR_EXCEPTION_PRINT("certsvc_certificate_new_from_memory() is failed.");
+ pkgmgrinfo_pkginfo_destroy_certinfo(certinfo);
+ certsvc_instance_free(instance);
+ return false;
+ }
+
+ r = certsvc_certificate_get_visibility(certificate, &visibility);
+ if (r != CERTSVC_SUCCESS)
+ ALARM_MGR_EXCEPTION_PRINT("certsvc_certificate_get_visibility() is failed.");
+
+ pkgmgrinfo_pkginfo_destroy_certinfo(certinfo);
+ certsvc_instance_free(instance);
+ certsvc_certificate_free(certificate);
+
+ ALARM_MGR_EXCEPTION_PRINT("visibility is %d", visibility);
+ if (visibility & CERTSVC_VISIBILITY_PLATFORM) {
+ return true;
+ }
+ }
+
+ if (access(tzplatform_mkpath(TZ_SYS_RO_SHARE,
+ "alarm-manager/alarm-config-all-service-permitted"), F_OK) == 0) {
+ ALARM_MGR_LOG_PRINT("This profile permit alarms for all service applications\n");
+ return true;
+ }
+
+ return false;
+}
+
+bool _is_permitted(const char *app_id, int alarm_type, uid_t uid)
+{
+ pkgmgrinfo_appinfo_h handle = NULL;
+ int ret;
+ bool _return = false;
+
+ if (app_id == NULL) {
+ ALARM_MGR_EXCEPTION_PRINT("app_id is NULL. Only expicit launch is permitted\n");
+ return false;
+ }
+
+ ret = pkgmgrinfo_appinfo_get_usr_appinfo(app_id, uid, &handle);
+ if (ret != PMINFO_R_OK) {
+ ALARM_MGR_EXCEPTION_PRINT("Failed to get appinfo [%s]\n", app_id);
+ } else {
+ char *app_type = NULL;
+ ret = pkgmgrinfo_appinfo_get_component_type(handle, &app_type);
+ if (app_type && strcmp("uiapp", app_type) == 0) {
+ if (alarm_type & ALARM_TYPE_EXACT_SERVICE_APP) {
+ ALARM_MGR_EXCEPTION_PRINT("[%s] is ui application.\
+ But alarm_type is ALARM_TYPE_EXACT_SERVICE_APP.\
+ soit is not allowed", app_id);
+ _return = false;
+ goto out;
+ }
+ ALARM_MGR_LOG_PRINT("[%s] is ui application. It is allowed", app_id);
+ _return = true;
+ goto out;
+ } else if (app_type && strcmp("svcapp", app_type) == 0) {
+ ALARM_MGR_LOG_PRINT("[%s] is service application.", app_id);
+
+ if (_permit_by_config(handle, uid)) {
+ ALARM_MGR_LOG_PRINT("service applications are allowed");
+ _return = true;
+ goto out;
+ }
+
+ bg_category_cb_info_t info = {
+ .appid = app_id,
+ .has_bg = false
+ };
+
+ if (alarm_type & ALARM_TYPE_INEXACT || alarm_type & ALARM_TYPE_EXACT_SERVICE_APP) {
+ ret = pkgmgrinfo_appinfo_foreach_background_category(handle, __bg_category_func, &info);
+ if (ret == PMINFO_R_OK && info.has_bg) {
+ ALARM_MGR_LOG_PRINT("[%s] has background categories. It is allowed", app_id);
+ _return = true;
+ goto out;
+ } else {
+ ALARM_MGR_EXCEPTION_PRINT("Failed to foreach background category. [%s] is not allowed", app_id);
+ }
+ }
+ }
+ }
+
+out:
+ if (handle)
+ pkgmgrinfo_appinfo_destroy_appinfo(handle);
+
+ return _return;
+}
#include <stdlib.h>
#include <time.h>
#include <signal.h>
-#include <string.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <sys/types.h>
#include <vconf.h>
#include <vconf-keys.h>
#include <dlfcn.h>
-#include <pkgmgr-info.h>
#include <package-manager.h>
#include <device/display.h>
#include <systemd/sd-login.h>
#include <notification.h>
#include <notification_ipc.h>
#include <notification_internal.h>
-#include <system_info.h>
-#include <cert-svc/ccert.h>
-#include <cert-svc/cinstance.h>
-#include <cynara-session.h>
-#include <cynara-client.h>
-#include <cynara-creds-gdbus.h>
#include <glib.h>
#if !GLIB_CHECK_VERSION(2, 31, 0)
#include "alarm.h"
#include "alarm-internal.h"
#include "alarm-manager-db.h"
+#include "alarm-manager-util.h"
#include "alarm-mgr-stub.h"
#define BILLION 1000000000 /* for calculating nano seconds */
static time_t periodic_alarm_standard_time = 0;
-static int __is_ui_app(const char *appid, uid_t uid);
static long __get_proper_interval(long interval, int alarm_type);
static void __alarm_add_to_list(__alarm_info_t *__alarm_info);
static void __alarm_generate_alarm_id(__alarm_info_t *__alarm_info, alarm_id_t *alarm_id);
void on_bus_name_owner_changed(GDBusConnection *connection, const gchar *sender_name, const gchar *object_path,
const gchar *interface_name, const gchar *signal_name, GVariant *parameters, gpointer user_data);
bool __get_caller_unique_name(int pid, char *unique_name, int size, bool *is_app, uid_t uid);
-static bool __permit_by_config(pkgmgrinfo_appinfo_h handle, uid_t uid);
static notification_h __get_notification(guchar *data, int datalen);
#ifdef _APPFW_FEATURE_ALARM_MANAGER_MODULE_LOG
char *unique_name;
} appid_cache_t;
-typedef enum {
- PROFILE_UNKNOWN = 0,
- PROFILE_MOBILE,
- PROFILE_WEARABLE,
- PROFILE_TV,
- PROFILE_IVI,
- PROFILE_COMMON,
-} profile_t;
-
-static profile_t _get_profile()
-{
- static profile_t saved = PROFILE_UNKNOWN;
- char *profileName;
- int r;
-
- if (__builtin_expect(saved != PROFILE_UNKNOWN, 1))
- return saved;
-
- r = system_info_get_platform_string("http://tizen.org/feature/profile",
- &profileName);
- if (r != SYSTEM_INFO_ERROR_NONE) {
- ALARM_MGR_LOG_PRINT("Failed to get profile info. error(%d)", r);
- return saved;
- }
-
- switch (*profileName) {
- case 'm':
- case 'M':
- saved = PROFILE_MOBILE;
- break;
- case 'w':
- case 'W':
- saved = PROFILE_WEARABLE;
- break;
- case 't':
- case 'T':
- saved = PROFILE_TV;
- break;
- case 'i':
- case 'I':
- saved = PROFILE_IVI;
- break;
- default: // common or unknown ==> ALL ARE COMMON.
- saved = PROFILE_COMMON;
- }
- free(profileName);
-
- return saved;
-}
-
static bool __get_cached_unique_name(int pid, char *unique_name, int size, bool *is_app, uid_t uid)
{
appid_cache_t *data = NULL;
return false;
}
- if (__is_ui_app(callee_appid, uid))
+ if (_is_ui_app(callee_appid, uid))
ret = true;
bundle_free(b);
char app_name[512] = { 0 };
bundle *b;
const char *callee_appid = NULL;
- char *caller_pkgid = NULL;
- char *callee_pkgid = NULL;
- pkgmgrinfo_pkginfo_h caller_handle;
- pkgmgrinfo_pkginfo_h callee_handle;
bundle_raw *b_data = NULL;
int datalen = 0;
bool caller_is_app = false;
/* caller */
if (caller_is_app) {
- if (pkgmgrinfo_appinfo_get_usr_appinfo(app_name, uid, &caller_handle) == PMINFO_R_OK) {
- if (pkgmgrinfo_appinfo_get_pkgid(caller_handle, &caller_pkgid) == PMINFO_R_OK) {
- if (caller_pkgid)
- __alarm_info->caller_pkgid = strdup(caller_pkgid);
- }
- pkgmgrinfo_appinfo_destroy_appinfo(caller_handle);
- }
+ __alarm_info->caller_pkgid = _get_pkgid_by_appid(app_name, uid);
}
/* callee */
b = bundle_decode((bundle_raw *)bundle_data, strlen(bundle_data));
callee_appid = appsvc_get_appid(b);
- if (pkgmgrinfo_appinfo_get_usr_appinfo(callee_appid, uid, &callee_handle) == PMINFO_R_OK) {
- if (pkgmgrinfo_appinfo_get_pkgid(callee_handle, &callee_pkgid) == PMINFO_R_OK) {
- if (callee_pkgid)
- __alarm_info->callee_pkgid = strdup(callee_pkgid);
- }
- pkgmgrinfo_appinfo_destroy_appinfo(callee_handle);
- }
+ __alarm_info->caller_pkgid = _get_pkgid_by_appid(callee_appid, uid);
if (b && caller_is_app) {
__set_caller_info(b, pid, uid, app_name,
time_t current_time;
time_t due_time;
char unique_name[MAX_APP_ID] = { 0 };
- char *caller_pkgid = NULL;
- pkgmgrinfo_pkginfo_h caller_handle;
bool caller_is_app = false;
__alarm_info_t *__alarm_info = NULL;
/* Get caller_appid to get caller's package id. There is no callee. */
if (caller_is_app) {
- if (pkgmgrinfo_appinfo_get_usr_appinfo(unique_name, uid, &caller_handle) == PMINFO_R_OK) {
- if (pkgmgrinfo_appinfo_get_pkgid(caller_handle, &caller_pkgid) == PMINFO_R_OK) {
- if (caller_pkgid)
- __alarm_info->caller_pkgid = strdup(caller_pkgid);
- }
- pkgmgrinfo_appinfo_destroy_appinfo(caller_handle);
- }
+ __alarm_info->caller_pkgid = _get_pkgid_by_appid(unique_name, uid);
}
SECURE_LOGD("caller_pkgid = %s, callee_pkgid = null", __alarm_info->caller_pkgid);
struct tm ts_ret;
char due_time_r[100] = { 0 };
char app_name[512] = { 0 };
- char *caller_pkgid = NULL;
- pkgmgrinfo_pkginfo_h caller_handle;
bool caller_is_app = false;
char *new_noti_data = NULL;
__alarm_info->app_unique_name = strdup(app_name);
if (caller_is_app) {
- if (pkgmgrinfo_appinfo_get_usr_appinfo(app_name, uid, &caller_handle) == PMINFO_R_OK) {
- if (pkgmgrinfo_appinfo_get_pkgid(caller_handle, &caller_pkgid) == PMINFO_R_OK) {
- if (caller_pkgid)
- __alarm_info->caller_pkgid = strdup(caller_pkgid);
- }
- pkgmgrinfo_appinfo_destroy_appinfo(caller_handle);
- }
+ __alarm_info->caller_pkgid = _get_pkgid_by_appid(app_name, uid);
}
SECURE_LOGD("caller_pkgid = %s, callee_pkgid = null",
return pid;
}
-static int __is_ui_app(const char *appid, uid_t uid)
-{
- if (appid == NULL)
- return 0;
-
- int ret = 0;
- pkgmgrinfo_appinfo_h appinfo_h = NULL;
-
- ret = pkgmgrinfo_appinfo_get_usr_appinfo(appid, uid, &appinfo_h);
-
- if (ret < 0)
- return 0;
-
- char *component = NULL;
- int found = 0;
-
- ret = pkgmgrinfo_appinfo_get_component_type(appinfo_h, &component);
- if (ret == 0 && component != NULL && strncmp(component, "uiapp", 5) == 0)
- found = 1;
-
- if (appinfo_h)
- pkgmgrinfo_appinfo_destroy_appinfo(appinfo_h);
-
- return found;
-}
-
-static int __compare_api_version(int *result, int pid, uid_t uid)
-{
- int ret = 0;
- pkgmgrinfo_pkginfo_h pkginfo = NULL;
- char pkgid[512] = {0, };
- char *pkg_version;
-
- if (aul_app_get_pkgid_bypid_for_uid(pid, pkgid, sizeof(pkgid), uid) != AUL_R_OK) {
- ALARM_MGR_EXCEPTION_PRINT("aul_app_get_pkgid_bypid() is failed. PID %d may not be app.", getpid());
- } else {
- ret = pkgmgrinfo_pkginfo_get_usr_pkginfo(pkgid, uid, &pkginfo);
- if (ret != PMINFO_R_OK) {
- ALARM_MGR_EXCEPTION_PRINT("Failed to get pkginfo\n");
- } else {
- ret = pkgmgrinfo_pkginfo_get_api_version(pkginfo, &pkg_version);
- if (ret != PMINFO_R_OK)
- ALARM_MGR_EXCEPTION_PRINT("Failed to check api version [%d]\n", ret);
- *result = strverscmp(pkg_version, "2.4");
- pkgmgrinfo_pkginfo_destroy_pkginfo(pkginfo);
- }
- }
- return ret;
-}
-
-static int __bg_category_func(const char *name, void *user_data)
-{
- bg_category_cb_info_t *info = (bg_category_cb_info_t *)user_data;
- ALARM_MGR_LOG_PRINT("appid[%s], bg name = %s", info->appid, name);
- if (name && strncmp("enable", name, strlen(name)) &&
- strncmp("disable", name, strlen(name))) {
- info->has_bg = true;
- return -1;
- }
-
- return 0;
-}
-
-static bool __is_permitted(const char *app_id, int alarm_type, uid_t uid)
-{
- pkgmgrinfo_appinfo_h handle = NULL;
- int ret;
- bool _return = false;
-
- if (app_id == NULL) {
- ALARM_MGR_EXCEPTION_PRINT("app_id is NULL. Only expicit launch is permitted\n");
- return false;
- }
-
- ret = pkgmgrinfo_appinfo_get_usr_appinfo(app_id, uid, &handle);
- if (ret != PMINFO_R_OK) {
- ALARM_MGR_EXCEPTION_PRINT("Failed to get appinfo [%s]\n", app_id);
- } else {
- char *app_type = NULL;
- ret = pkgmgrinfo_appinfo_get_component_type(handle, &app_type);
- if (app_type && strcmp("uiapp", app_type) == 0) {
- if (alarm_type & ALARM_TYPE_EXACT_SERVICE_APP) {
- ALARM_MGR_EXCEPTION_PRINT("[%s] is ui application. it is not allowed", app_id);
- _return = false;
- goto out;
- }
- ALARM_MGR_LOG_PRINT("[%s] is ui application. It is allowed", app_id);
- _return = true;
- goto out;
- } else if (app_type && strcmp("svcapp", app_type) == 0) {
- ALARM_MGR_LOG_PRINT("[%s] is service application.", app_id);
-
- if (__permit_by_config(handle, uid)) {
- ALARM_MGR_LOG_PRINT("service applications are allowed");
- _return = true;
- goto out;
- }
-
- bg_category_cb_info_t info = {
- .appid = app_id,
- .has_bg = false
- };
-
- if (alarm_type & ALARM_TYPE_INEXACT || alarm_type & ALARM_TYPE_EXACT_SERVICE_APP) {
- ret = pkgmgrinfo_appinfo_foreach_background_category(handle, __bg_category_func, &info);
- if (ret == PMINFO_R_OK && info.has_bg) {
- ALARM_MGR_LOG_PRINT("[%s] has background categories. It is allowed", app_id);
- _return = true;
- goto out;
- } else {
- ALARM_MGR_EXCEPTION_PRINT("Failed to foreach background category. [%s] is not allowed", app_id);
- }
- }
- }
- }
-
-out:
- if (handle)
- pkgmgrinfo_appinfo_destroy_appinfo(handle);
-
- return _return;
-}
-
static int __find_login_user(uid_t *uid)
{
uid_t *uids;
static void __alarm_expired()
{
int ret;
+ bool is_app = false;
const char *destination_app_service_name = NULL;
alarm_id_t alarm_id = -1;
int app_pid = 0;
ALARM_MGR_LOG_PRINT("Value of alarm_expire_mode [%d]", expire_mode);
- if (__compare_api_version(&result, app_pid, __alarm_info->uid) < 0) {
+ if (_compare_api_version(&result, app_pid, __alarm_info->uid) < 0) {
ALARM_MGR_EXCEPTION_PRINT("Unable to check api version\n");
result = -1;
}
ALARM_MGR_EXCEPTION_PRINT("Unable to launch app [%s] \n", appid);
} else {
ALARM_MGR_LOG_PRINT("Successfuly ran app svc\n");
- if (__is_ui_app(appid, __alarm_info->uid) &&
+ if (_is_ui_app(appid, __alarm_info->uid) &&
expire_mode == ALARM_EXPIRE_MODE_NORMAL)
device_display_change_state(DISPLAY_STATE_NORMAL);
}
ALARM_MGR_EXCEPTION_PRINT("Failed to post notification\n");
} else {
char appid[MAX_SERVICE_NAME_LEN] = { 0, };
- pkgmgrinfo_appinfo_h appinfo_handle = NULL;
struct running_info_t app_info;
if (__alarm_info->dst_service_name == NULL) {
strncpy(appid, __alarm_info->dst_service_name + 6, sizeof(appid) - 1);
}
- ret = PMINFO_R_ERROR;
if (__alarm_info->uid >= REGULAR_UID_MIN) {
- ret = pkgmgrinfo_appinfo_get_usr_appinfo(appid,
- __alarm_info->uid, &appinfo_handle);
+ is_app = _is_app(appid, __alarm_info->uid);
}
- ALARM_MGR_LOG_PRINT("appid : %s (%p)", appid, appinfo_handle);
- if (appinfo_handle)
- pkgmgrinfo_appinfo_destroy_appinfo(appinfo_handle);
+ ALARM_MGR_LOG_PRINT("appid : %s app?(%d)", appid, is_app);
/* Case #2. The process was killed && App type
* This app is launched and owner of DBus connection is changed. and then, expiration noti is sent by DBus. */
-
app_info.is_running = false;
- if (ret == PMINFO_R_OK) {
+ if (is_app) {
app_info.pid = __alarm_info->pid;
app_info.appid = appid;
aul_app_get_all_running_app_info_for_uid(__app_info_iter,
&app_info, __alarm_info->uid);
}
- if (ret == PMINFO_R_OK && !app_info.is_running) {
+ if (is_app && !app_info.is_running) {
__expired_alarm_t *expire_info;
char alarm_id_str[32] = { 0, };
return true;
}
-static bool __permit_by_config(pkgmgrinfo_appinfo_h handle, uid_t uid)
-{
- if (access(tzplatform_mkpath(TZ_SYS_RO_SHARE,
- "alarm-manager/alarm-config-service-restricted"), F_OK) == 0) {
- ALARM_MGR_LOG_PRINT("This profile restrict alarms for service applications\n");
- return false;
- }
-
- if (access(tzplatform_mkpath(TZ_SYS_RO_SHARE,
- "alarm-manager/alarm-config-platform-service-permitted"), F_OK) == 0) {
- ALARM_MGR_LOG_PRINT("This profile permit alarm for service applications which has platform cert\n");
- char *pkgid;
- int r;
- const char *cert_value;
- pkgmgrinfo_certinfo_h certinfo;
- CertSvcInstance instance;
- CertSvcCertificate certificate;
- CertSvcVisibility visibility = CERTSVC_VISIBILITY_PUBLIC;
-
- r = pkgmgrinfo_appinfo_get_pkgid(handle, &pkgid);
- if (r != PMINFO_R_OK) {
- ALARM_MGR_EXCEPTION_PRINT("Failed to get certinfo pkgid");
- return false;
- }
-
- r = pkgmgrinfo_pkginfo_create_certinfo(&certinfo);
- if (r != PMINFO_R_OK) {
- ALARM_MGR_EXCEPTION_PRINT("Failed to create certinfo");
- return false;
- }
-
- r = pkgmgrinfo_pkginfo_load_certinfo(pkgid, certinfo, uid);
- if (r != PMINFO_R_OK) {
- ALARM_MGR_EXCEPTION_PRINT("Failed to load certinfo");
- pkgmgrinfo_pkginfo_destroy_certinfo(certinfo);
- return false;
- }
-
- r = pkgmgrinfo_pkginfo_get_cert_value(certinfo,
- PMINFO_DISTRIBUTOR_ROOT_CERT, &cert_value);
- if (r != PMINFO_R_OK || cert_value == NULL) {
- ALARM_MGR_EXCEPTION_PRINT("Failed to get cert value");
- pkgmgrinfo_pkginfo_destroy_certinfo(certinfo);
- return false;
- }
-
- r = certsvc_instance_new(&instance);
- if (r != CERTSVC_SUCCESS) {
- ALARM_MGR_EXCEPTION_PRINT("certsvc_instance_new() is failed.");
- pkgmgrinfo_pkginfo_destroy_certinfo(certinfo);
- return false;
- }
-
- r = certsvc_certificate_new_from_memory(instance,
- (const unsigned char *)cert_value,
- strlen(cert_value),
- CERTSVC_FORM_DER_BASE64,
- &certificate);
- if (r != CERTSVC_SUCCESS) {
- ALARM_MGR_EXCEPTION_PRINT("certsvc_certificate_new_from_memory() is failed.");
- pkgmgrinfo_pkginfo_destroy_certinfo(certinfo);
- certsvc_instance_free(instance);
- return false;
- }
-
- r = certsvc_certificate_get_visibility(certificate, &visibility);
- if (r != CERTSVC_SUCCESS)
- ALARM_MGR_EXCEPTION_PRINT("certsvc_certificate_get_visibility() is failed.");
-
- pkgmgrinfo_pkginfo_destroy_certinfo(certinfo);
- certsvc_instance_free(instance);
- certsvc_certificate_free(certificate);
-
- ALARM_MGR_EXCEPTION_PRINT("visibility is %d", visibility);
- if (visibility & CERTSVC_VISIBILITY_PLATFORM) {
- return true;
- }
- }
-
- if (access(tzplatform_mkpath(TZ_SYS_RO_SHARE,
- "alarm-manager/alarm-config-all-service-permitted"), F_OK) == 0) {
- ALARM_MGR_LOG_PRINT("This profile permit alarms for all service applications\n");
- return true;
- }
-
- return false;
-}
-
#ifdef _APPFW_FEATURE_ALARM_MANAGER_MODULE_LOG
static void __initialize_module_log(void)
{
return;
}
-static int __cynara_check(GDBusMethodInvocation *invocation, pid_t pid)
-{
- int ret = 0;
- char *user = NULL;
- char *client = NULL;
- char *client_session = NULL;
- cynara *p_cynara = NULL;
- const char *sender_unique_name;
- GDBusConnection *connection;
- const char *notitification_priv = "http://tizen.org/privilege/notification";
-
- connection = g_dbus_method_invocation_get_connection(invocation);
- sender_unique_name = g_dbus_method_invocation_get_sender(invocation);
-
- ret = cynara_initialize(&p_cynara, NULL);
- if (ret != CYNARA_API_SUCCESS) {
- ALARM_MGR_EXCEPTION_PRINT("cynara_initialize() failed");
- goto cynara_out;
- }
-
- ret = cynara_creds_gdbus_get_user(connection, sender_unique_name,
- USER_METHOD_DEFAULT, &user);
- if (ret != CYNARA_API_SUCCESS) {
- ALARM_MGR_EXCEPTION_PRINT("cynara_creds_gdbus_get_user() failed");
- goto cynara_out;
- }
-
- ret = cynara_creds_gdbus_get_client(connection, sender_unique_name,
- CLIENT_METHOD_DEFAULT, &client);
- if (ret != CYNARA_API_SUCCESS) {
- ALARM_MGR_EXCEPTION_PRINT("cynara_creds_gdbus_get_client() failed");
- goto cynara_out;
- }
-
- ALARM_MGR_LOG_PRINT("user :%s , client :%s ,unique_name : %s, pid() : %d",
- user, client, sender_unique_name, pid);
-
- client_session = cynara_session_from_pid(pid);
- if (!client_session) {
- ALARM_MGR_EXCEPTION_PRINT("cynara_session_from_pid() failed");
- ret = CYNARA_API_INVALID_PARAM;
- goto cynara_out;
- }
-
- ret = cynara_check(p_cynara, client, client_session, user,
- notitification_priv);
- if (ret == CYNARA_API_ACCESS_ALLOWED)
- ALARM_MGR_LOG_PRINT("CYNARA_ACCESS_ALLOWED");
- else
- ALARM_MGR_LOG_PRINT("CYNARA_NOT_ALLOWED [%d]", ret);
-
-cynara_out:
- if (client_session)
- g_free(client_session);
- if (client)
- g_free(client);
- if (user)
- g_free(user);
- if (p_cynara)
- cynara_finish(p_cynara);
-
- return ret;
-}
-
static int __check_modifiable(uid_t uid, pid_t pid, int alarm_id)
{
bool caller_is_app = false;
GSList *gs_iter = NULL;
__alarm_info_t *entry = NULL;
char *caller_pkgid = NULL;
- pkgmgrinfo_pkginfo_h caller_handle;
if (__get_cached_unique_name(pid, app_name, sizeof(app_name),
&caller_is_app, uid) == false)
app_name);
return ALARMMGR_RESULT_SUCCESS;
} else {
- if (pkgmgrinfo_appinfo_get_usr_appinfo(app_name, uid, &caller_handle) != PMINFO_R_OK) {
+ caller_pkgid = _get_pkgid_by_appid(app_name, uid);
+ if (!caller_pkgid) {
ALARM_MGR_EXCEPTION_PRINT("Failed to get appinfo %s", app_name);
return ERR_ALARM_SYSTEM_FAIL;
- } else {
- if (pkgmgrinfo_appinfo_get_pkgid(caller_handle, &caller_pkgid) != PMINFO_R_OK) {
- ALARM_MGR_EXCEPTION_PRINT("Failed to get pkgid %s", app_name);
- pkgmgrinfo_appinfo_destroy_appinfo(caller_handle);
- return ERR_ALARM_SYSTEM_FAIL;
- }
}
}
if (entry->uid == uid && entry->alarm_id == alarm_id &&
strcmp(caller_pkgid, entry->caller_pkgid) == 0) {
ALARM_MGR_LOG_PRINT("Found alarm of app (uid:%d, pid:%d, caller_pkgid:%s) ", uid, pid, caller_pkgid);
- pkgmgrinfo_appinfo_destroy_appinfo(caller_handle);
+
+ if (caller_pkgid)
+ free(caller_pkgid);
return ALARMMGR_RESULT_SUCCESS;
}
}
ALARM_MGR_EXCEPTION_PRINT("[%s] is not permitted to modify alarm_id[%d]", app_name, alarm_id);
- pkgmgrinfo_appinfo_destroy_appinfo(caller_handle);
+ if (caller_pkgid)
+ free(caller_pkgid);
return ERR_ALARM_NOT_PERMITTED_APP;
}
} else {
callee_appid = appsvc_get_appid(b);
- if (__compare_api_version(&result, pid, uid) < 0) {
+ if (_compare_api_version(&result, pid, uid) < 0) {
ALARM_MGR_EXCEPTION_PRINT("Unable to check api version\n");
return_code = ERR_ALARM_SYSTEM_FAIL;
g_dbus_method_invocation_return_value(invoc, g_variant_new("(ii)", alarm_id, return_code));
if (alarm_type & ALARM_TYPE_INEXACT)
alarm_type ^= ALARM_TYPE_INEXACT;
} else { /* Since 2.4 */
- if (!__is_permitted(callee_appid, alarm_type, uid)) {
+ if (!_is_permitted(callee_appid, alarm_type, uid)) {
ALARM_MGR_EXCEPTION_PRINT("[%s] is not permitted \n", callee_appid);
return_code = ERR_ALARM_NOT_PERMITTED_APP;
g_dbus_method_invocation_return_value(invoc, g_variant_new("(ii)", alarm_id, return_code));
uid_t uid;
pid_t pid;
const char *name = g_dbus_method_invocation_get_sender(invoc);
+ const char *notification_priv = "http://tizen.org/privilege/notification";
uid = __get_caller_uid(name);
pid = __get_caller_pid(name);
return true;
}
- ret = __cynara_check(invoc, pid);
- if (ret != CYNARA_API_ACCESS_ALLOWED) {
- if (ret == CYNARA_API_ACCESS_DENIED)
- return_code = ERR_ALARM_NOT_PERMITTED_APP;
- else
- return_code = ERR_ALARM_SYSTEM_FAIL;
+ ret = _cynara_check(invoc, notification_priv, pid);
+ if (ret != ALARMMGR_RESULT_SUCCESS) {
+ return_code = ret;
g_dbus_method_invocation_return_value(invoc, g_variant_new("(ii)", alarm_id, return_code));
return true;
ALARM_MGR_LOG_PRINT("The alarm pkgid : %s.", callee_pkgid);
- pkgmgrinfo_pkginfo_h handle;
- retval = pkgmgrinfo_pkginfo_get_usr_pkginfo(callee_pkgid, uid, &handle);
- if (retval != PMINFO_R_OK) {
- ALARM_MGR_EXCEPTION_PRINT("Failed to get pkginfo\n");
- return_code = ERR_ALARM_INVALID_ID;
+ retval = _pkg_is_global(callee_pkgid, uid);
+ if (retval == ALARMMGR_RESULT_SUCCESS) {
+ entry->global = global;
+ if (!_alarm_set_global_to_db(entry, global))
+ return_code = ERR_ALARM_SYSTEM_FAIL;
} else {
- bool is_global = 0;
- retval = pkgmgrinfo_pkginfo_is_global(handle, &is_global);
- if (retval == PMINFO_R_OK && is_global) {
- entry->global = global;
- if (!_alarm_set_global_to_db(entry, global))
- return_code = ERR_ALARM_SYSTEM_FAIL;
- } else if (retval == PMINFO_R_OK && !is_global) {
- return_code = ERR_ALARM_NOT_PERMITTED_APP;
- }
- pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
+ ALARM_MGR_EXCEPTION_PRINT("Get pkginfo error [%d]", retval);
+ return_code = retval;
}
+
g_dbus_method_invocation_return_value(invoc, g_variant_new("(i)", return_code));
}