4 * Copyright (c) 2012 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Ja-young Gu <jygu@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.
25 #include <security-server.h>
29 #include <communicator.h>
31 #include <user_request.h>
33 #include <libxml/xmlmemory.h>
34 #include <libxml/parser.h>
35 #include <libxml/tree.h>
37 #include "generated-code.h"
41 static void _free_hook(UserRequest *ur)
43 struct dbus_request_info *user_info;
45 user_info = (struct dbus_request_info *)tcore_user_request_ref_user_info(ur);
50 char *dbus_plugin_get_cp_name_by_object_path(const char *object_path)
55 if (!g_str_has_prefix(object_path, MY_DBUS_PATH)) {
59 return (char *)object_path + strlen(MY_DBUS_PATH) + 1;
62 UserRequest *dbus_plugin_macro_user_request_new(struct custom_data *ctx, void *object, GDBusMethodInvocation *invocation)
64 UserRequest *ur = NULL;
66 struct dbus_request_info *dbus_info;
68 cp_name = GET_CP_NAME(invocation);
69 dbg("cp_name = [%s]", cp_name);
71 ur = tcore_user_request_new(ctx->comm, cp_name);
73 dbus_info = calloc(1, sizeof(struct dbus_request_info));
74 dbus_info->interface_object = object;
75 dbus_info->invocation = invocation;
77 tcore_user_request_set_user_info(ur, dbus_info);
78 tcore_user_request_set_free_hook(ur, _free_hook);
83 gboolean check_access_control (GDBusMethodInvocation *invoc, const char *label, const char *perm)
85 GDBusConnection *conn;
94 conn = g_dbus_method_invocation_get_connection (invoc);
96 warn ("access control denied (no connection info)");
100 sender = g_dbus_method_invocation_get_sender (invoc);
102 param = g_variant_new ("(s)", sender);
104 warn ("access control denied (sender info fail)");
108 result_pid = g_dbus_connection_call_sync (conn, "org.freedesktop.DBus",
109 "/org/freedesktop/DBus",
110 "org.freedesktop.DBus",
111 "GetConnectionUnixProcessID",
113 G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
115 warn ("access control denied (dbus error: %d(%s))",
116 error->code, error->message);
117 g_error_free (error);
122 warn ("access control denied (fail to get pid)");
126 g_variant_get (result_pid, "(u)", &pid);
127 g_variant_unref (result_pid);
129 dbg ("sender: %s pid = %u", sender, pid);
131 ret = security_server_check_privilege_by_pid (pid, label, perm);
132 if (ret != SECURITY_SERVER_API_SUCCESS) {
133 warn ("pid(%u) access (%s - %s) denied(%d)", pid, label, perm, ret);
139 if (result == FALSE) {
140 g_dbus_method_invocation_return_error (invoc,
142 G_DBUS_ERROR_ACCESS_DENIED,
148 enum dbus_tapi_sim_slot_id get_sim_slot_id_by_cp_name(char *cp_name)
150 if(g_str_has_suffix(cp_name , "0")){
151 return SIM_SLOT_PRIMARY;
152 } else if (g_str_has_suffix(cp_name , "1")){
153 return SIM_SLOT_SECONDARY;
154 } else if(g_str_has_suffix(cp_name , "2")){
155 return SIM_SLOT_TERTIARY;
157 return SIM_SLOT_PRIMARY;
160 gboolean dbus_plugin_util_load_xml(char *docname, char *groupname, void **i_doc, void **i_root_node)
162 xmlDocPtr *doc = (xmlDocPtr *)i_doc;
163 xmlNodePtr *root_node = (xmlNodePtr *)i_root_node;
165 dbg("docname:%s, groupname:%s", docname, groupname);
167 *doc = xmlParseFile(docname);
169 *root_node = xmlDocGetRootElement(*doc);
171 dbg("*root_node->name:%s", (*root_node)->name);
172 if (0 == xmlStrcmp((*root_node)->name, (const xmlChar *) groupname)) {
173 *root_node = (*root_node)->xmlChildrenNode;
181 err("Cannot parse doc(%s)", docname);
185 void dbus_plugin_util_unload_xml(void **i_doc, void **i_root_node)
187 xmlDocPtr *doc = (xmlDocPtr *)i_doc;
188 xmlNodePtr *root_node = (xmlNodePtr *)i_root_node;
190 dbg("unloading XML");