Added privilege check method. Removed smack label in dbus conf 12/82212/1
authorkmook <kmook.choi@samsung.com>
Tue, 2 Aug 2016 03:52:07 +0000 (12:52 +0900)
committerkmook <kmook.choi@samsung.com>
Tue, 2 Aug 2016 03:52:07 +0000 (12:52 +0900)
Change-Id: Ibd11534fe8dab3213af67f0b00a59b038f5f2876
Signed-off-by: kmook <kmook.choi@samsung.com>
common/Types.h
daemon/DbusServer.cpp
lib/conv_lib_service.cpp
lib/dbus_client.cpp
lib/dbus_client.h
packaging/d2d-conv-manager.conf

index b03e84f..4eadafe 100644 (file)
@@ -38,6 +38,7 @@
 #define METHOD_REQUEST "Request"
 #define METHOD_RESPOND "Respond"
 #define SIGNAL_LAUNCHED        "Launched"
+#define METHOD_CHK_PRIV_NETWORK_GET    "ChkPrivNetworkGet"
 
 #define ARG_REQTYPE            "type"
 #define ARG_COOKIE             "cookie"
index f541473..2229051 100755 (executable)
@@ -45,6 +45,9 @@ static const gchar introspectionXml[] =
        "                       <arg type='s' name='" ARG_RESULT_ADD "' direction='out'/>"
        "                       <arg type='s' name='" ARG_OUTPUT "' direction='out'/>"
        "               </method>"
+       "               <method name='" METHOD_CHK_PRIV_NETWORK_GET "'>"
+       "                       <arg type='i' name='" ARG_RESULT_ERR "' direction='out'/>"
+       "               </method>"
        "       </interface>"
        "</node>";
 
@@ -95,18 +98,19 @@ static void __handle_request(GDBusConnection* conn, const char *sender, GVariant
        } catch (std::bad_alloc& ba) {
                _E("Memory Allocation Failed..");
                g_dbus_method_invocation_return_value(invocation, g_variant_new("(iss)", CONV_ERROR_INVALID_OPERATION, EMPTY_JSON_OBJECT, EMPTY_JSON_OBJECT));
-//             delete creds;
+               delete creds;
                return;
        } catch (int e) {
                _E("Caught %d", e);
                g_dbus_method_invocation_return_value(invocation, g_variant_new("(iss)", CONV_ERROR_INVALID_OPERATION, EMPTY_JSON_OBJECT, EMPTY_JSON_OBJECT));
-//             delete creds;
+               delete creds;
                return;
        }
 
        if (!recvRequest) {
                _E("Memory allocation failed");
                g_dbus_method_invocation_return_value(invocation, g_variant_new("(iss)", CONV_ERROR_INVALID_OPERATION, EMPTY_JSON_OBJECT, EMPTY_JSON_OBJECT));
+               delete creds;
                return;
        }
 
@@ -122,6 +126,8 @@ static void __handle_method_call(GDBusConnection *conn, const gchar *sender,
 
        if (STR_EQ(method_name, METHOD_REQUEST))
                __handle_request(conn, sender, param, invocation);
+       else if (STR_EQ(method_name, METHOD_CHK_PRIV_NETWORK_GET))
+               g_dbus_method_invocation_return_value(invocation, g_variant_new("(i)", CONV_ERROR_NONE));
        else
                _W("Invalid method: %s", method_name);
 
index a466281..0512b48 100755 (executable)
@@ -485,6 +485,10 @@ static int conv_service_unset_connected_cb(conv_service_h handle)
 EXTAPI int conv_service_get_connection_state(conv_service_h handle, conv_service_connection_state_e* state)
 {
        IF_FAIL_RETURN_TAG(conv::util::is_feature_supported(), CONV_ERROR_NOT_SUPPORTED, _E, "Not supported");
+
+       int error = conv::dbus_client::call(METHOD_CHK_PRIV_NETWORK_GET);
+       IF_FAIL_RETURN_TAG(error == CONV_ERROR_NONE, error, _E, "Privilege checking failed (%#x)", error);
+
        ASSERT_NOT_NULL(handle);
        ASSERT_NOT_NULL(state);
 
index 4d20557..8d9b567 100755 (executable)
@@ -240,3 +240,24 @@ int conv::dbus_client::register_callback(const char* subject, subject_response_c
 
        return true;
 }
+
+int conv::dbus_client::call(const char* subject)
+{
+       int ret = CONV_ERROR_NONE;
+       GError *err = NULL;
+
+       GVariant *response = g_dbus_connection_call_sync(dbus_connection, DBUS_DEST, DBUS_PATH, DBUS_IFACE,
+                       subject, NULL, NULL, G_DBUS_CALL_FLAGS_NONE, DBUS_TIMEOUT, NULL, &err);
+
+       if (response) {
+               g_variant_unref(response);
+               return CONV_ERROR_NONE;
+       }
+
+       ret = CONV_ERROR_INVALID_OPERATION;
+       if (err->code == G_DBUS_ERROR_ACCESS_DENIED)
+               ret = CONV_ERROR_PERMISSION_DENIED;
+
+       HANDLE_GERROR(err);
+       return ret;
+}
index 4c67516..f23e6d6 100644 (file)
@@ -30,6 +30,7 @@ namespace conv {
                int request(int type, int* req_id, const char* subject, const char* input, std::string* req_result, std::string* data_read);
                int request_with_no_reply(int type, int* req_id, const char* subject, const char* input);
                int register_callback(const char* subject, subject_response_cb callback);
+               int call(const char* subject);
        }
 
 }      /* namespace ctx */
index 409b8a6..2ee1769 100644 (file)
@@ -1,22 +1,17 @@
 <!DOCTYPE busconfig PUBLIC "-//freedesktop//DTD D-BUS Bus Configuration 1.0//EN" "http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">
 <busconfig>
-       <policy smack="System">
+       <policy user="root">
                <allow own="org.tizen.d2dconv"/>
-               <allow send_destination="org.tizen.d2dconv"/>
-               <allow send_interface="org.tizen.d2dconv"/>
-               <allow receive_sender="org.tizen.d2dconv"/>
+               <allow send_destination="org.tizen.d2dconv" send_interface="org.tizen.d2dconv" send_member="Request"/>
+               <allow send_interface="org.tizen.d2dconv" send_member="Respond"/>
        </policy>
-       <policy at_console="true">
-               <allow send_destination="org.tizen.d2dconv"/>
-               <allow receive_sender="org.tizen.d2dconv"/>
-       </policy>
-       <policy smack="User">
-               <allow send_destination="org.tizen.d2dconv"/>
-               <allow receive_sender="org.tizen.d2dconv"/>
+       <policy user="owner">
+               <allow own="org.tizen.d2dconv"/>
+               <allow send_destination="org.tizen.d2dconv" send_interface="org.tizen.d2dconv" send_member="Request"/>
+               <allow send_interface="org.tizen.d2dconv" send_member="Respond"/>
        </policy>
        <policy context="default">
-               <allow send_destination="org.tizen.d2dconv"/>
-               <allow receive_sender="org.tizen.d2dconv"/>
+               <check send_destination="org.tizen.d2dconv" send_interface="org.tizen.d2dconv"
+                       send_member="ChkPrivNetworkGet" privilege="http://tizen.org/privilege/network.get"/>
        </policy>
 </busconfig>
-