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));
77 dbus_info->interface_object = object;
78 dbus_info->invocation = invocation;
80 tcore_user_request_set_user_info(ur, dbus_info);
81 tcore_user_request_set_free_hook(ur, _free_hook);
86 gboolean check_access_control (GDBusMethodInvocation *invoc, const char *label, const char *perm)
88 GDBusConnection *conn;
97 conn = g_dbus_method_invocation_get_connection (invoc);
99 warn ("access control denied (no connection info)");
103 sender = g_dbus_method_invocation_get_sender (invoc);
105 param = g_variant_new ("(s)", sender);
107 warn ("access control denied (sender info fail)");
111 result_pid = g_dbus_connection_call_sync (conn, "org.freedesktop.DBus",
112 "/org/freedesktop/DBus",
113 "org.freedesktop.DBus",
114 "GetConnectionUnixProcessID",
116 G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
118 warn ("access control denied (dbus error: %d(%s))",
119 error->code, error->message);
120 g_error_free (error);
125 warn ("access control denied (fail to get pid)");
129 g_variant_get (result_pid, "(u)", &pid);
130 g_variant_unref (result_pid);
132 dbg ("sender: %s pid = %u", sender, pid);
134 ret = security_server_check_privilege_by_pid (pid, label, perm);
135 if (ret != SECURITY_SERVER_API_SUCCESS) {
136 warn ("pid(%u) access (%s - %s) denied(%d)", pid, label, perm, ret);
142 if (result == FALSE) {
143 g_dbus_method_invocation_return_error (invoc,
145 G_DBUS_ERROR_ACCESS_DENIED,
151 enum dbus_tapi_sim_slot_id get_sim_slot_id_by_cp_name(char *cp_name)
153 if(g_str_has_suffix(cp_name , "0")){
154 return SIM_SLOT_PRIMARY;
155 } else if (g_str_has_suffix(cp_name , "1")){
156 return SIM_SLOT_SECONDARY;
157 } else if(g_str_has_suffix(cp_name , "2")){
158 return SIM_SLOT_TERTIARY;
160 return SIM_SLOT_PRIMARY;
163 gboolean dbus_plugin_util_load_xml(char *docname, char *groupname, void **i_doc, void **i_root_node)
165 xmlDocPtr *doc = (xmlDocPtr *)i_doc;
166 xmlNodePtr *root_node = (xmlNodePtr *)i_root_node;
168 dbg("docname:%s, groupname:%s", docname, groupname);
170 *doc = xmlParseFile(docname);
172 *root_node = xmlDocGetRootElement(*doc);
174 dbg("*root_node->name:%s", (*root_node)->name);
175 if (0 == xmlStrcmp((*root_node)->name, (const xmlChar *) groupname)) {
176 *root_node = (*root_node)->xmlChildrenNode;
184 err("Cannot parse doc(%s)", docname);
188 void dbus_plugin_util_unload_xml(void **i_doc, void **i_root_node)
190 xmlDocPtr *doc = (xmlDocPtr *)i_doc;
191 xmlNodePtr *root_node = (xmlNodePtr *)i_root_node;
193 dbg("unloading XML");