Added some method for gdbus return error 17/71617/2
authorhyunuktak <hyunuk.tak@samsung.com>
Thu, 26 May 2016 07:26:56 +0000 (16:26 +0900)
committertaesubkim <taesub.kim@samsung.com>
Thu, 9 Jun 2016 06:32:18 +0000 (15:32 +0900)
Change-Id: Ib4457ce756fb4df86c7dc87493280f6b410b611b
Signed-off-by: hyunuktak <hyunuk.tak@samsung.com>
daemon/CMakeLists.txt
daemon/include/vpnerror.h [new file with mode: 0755]
daemon/src/vpnerror.c [new file with mode: 0755]
daemon/src/vpnsvc.c
framework/src/capi_vpn_service.c
packaging/capi-vpn-service.spec

index 14e080d..6ffc7ea 100755 (executable)
@@ -15,6 +15,7 @@ SET(pc_requires "capi-base-common")
 SET(SRCS
        src/vpnsvc.c
        src/vpndbus.c
+       src/vpnerror.c
        src/vpn_service_daemon.c
        src/vpn_service_daemon_main.c
 )
diff --git a/daemon/include/vpnerror.h b/daemon/include/vpnerror.h
new file mode 100755 (executable)
index 0000000..e18a788
--- /dev/null
@@ -0,0 +1,41 @@
+/*
+ * VPN Service Module
+ *
+ * Copyright (c) 2015 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.
+ *
+ */
+
+#ifndef __VPNSERVICE_VPNERROR_H__
+#define __VPNSERVICE_VPNERROR_H__
+
+#include <glib.h>
+#include <gio/gio.h>
+#include <glib-object.h>
+
+#include "vpn_service_daemon.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+void vpnsvc_error_inprogress(GDBusMethodInvocation *context);
+void vpnsvc_error_invalid_parameter(GDBusMethodInvocation *context);
+void vpnsvc_error_permission_denied(GDBusMethodInvocation *context);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __VPNSERVICE_VPNERROR_H__ */
diff --git a/daemon/src/vpnerror.c b/daemon/src/vpnerror.c
new file mode 100755 (executable)
index 0000000..2369c26
--- /dev/null
@@ -0,0 +1,53 @@
+/*
+ * VPN Service Module
+ *
+ * Copyright (c) 2015 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 <glib.h>
+#include <dlog/dlog.h>
+
+#include "vpndbus.h"
+#include "vpnerror.h"
+
+#define VPNSVC_ERROR_INTERFACE VPNSERVICE_INTERFACE ".Error"
+
+void vpnsvc_error_inprogress(GDBusMethodInvocation *context)
+{
+       LOGE("dbus method return error");
+       g_dbus_method_invocation_return_error(context,
+               G_DBUS_ERROR,
+               G_DBUS_ERROR_ACCESS_DENIED,
+               VPNSVC_ERROR_INTERFACE ".InProgress");
+}
+
+void vpnsvc_error_invalid_parameter(GDBusMethodInvocation *context)
+{
+       LOGE("dbus method return error");
+       g_dbus_method_invocation_return_error(context,
+               G_DBUS_ERROR,
+               G_DBUS_ERROR_ACCESS_DENIED,
+               VPNSVC_ERROR_INTERFACE ".InvalidParameter");
+}
+
+void vpnsvc_error_permission_denied(GDBusMethodInvocation *context)
+{
+       LOGE("dbus method return error");
+       g_dbus_method_invocation_return_error(context,
+               G_DBUS_ERROR,
+               G_DBUS_ERROR_ACCESS_DENIED,
+               VPNSVC_ERROR_INTERFACE ".PermissionDenied");
+}
index 123db6f..b5d2e9e 100755 (executable)
@@ -25,6 +25,7 @@
 
 #include "vpnsvc.h"
 #include "vpndbus.h"
+#include "vpnerror.h"
 #include "vpn_service_daemon.h"
 
 #include "cynara-client.h"
@@ -53,9 +54,8 @@ gboolean handle_vpn_init(Vpnsvc *object,
        /* check privilege */
        if (vpn_service_gdbus_check_privilege(invocation, PRIVILEGE_VPN_SERVICE) == false
                || vpn_service_gdbus_check_privilege(invocation, PRIVILEGE_INTERNET) == false) {
-               LOGE("permission denied, and finished request.");
-               result = VPNSVC_ERROR_PERMISSION_DENIED;
-               goto done;
+               vpnsvc_error_permission_denied(invocation);
+               return FALSE;
        }
 
        vpnsvc_tun_s handle_s;
@@ -80,8 +80,6 @@ gboolean handle_vpn_init(Vpnsvc *object,
        LOGD("handle_s.fd : %d, handle_s.index : %d, handle_s.name : %s",
                        handle_s.fd, handle_s.index, handle_s.name);
 
-done:
-
        vpnsvc_complete_vpn_init(object, invocation, result, handle_s.index, handle_s.name);
 
        return TRUE;
@@ -98,16 +96,14 @@ gboolean handle_vpn_deinit(Vpnsvc *object,
        /* check privilege */
        if (vpn_service_gdbus_check_privilege(invocation, PRIVILEGE_VPN_SERVICE) == false
                || vpn_service_gdbus_check_privilege(invocation, PRIVILEGE_INTERNET) == false) {
-               LOGE("permission denied, and finished request.");
-               result = VPNSVC_ERROR_PERMISSION_DENIED;
-               goto done;
+               vpnsvc_error_permission_denied(invocation);
+               return FALSE;
        }
 
        LOGD("vpn_deinit, %s\n", arg_dev_name);
 
        result = vpn_daemon_deinit(arg_dev_name);
 
-done:
        vpnsvc_complete_vpn_deinit(object, invocation, result);
 
        return TRUE;
@@ -124,9 +120,8 @@ gboolean handle_vpn_protect(Vpnsvc *object,
        /* check privilege */
        if (vpn_service_gdbus_check_privilege(invocation, PRIVILEGE_VPN_SERVICE) == false
                || vpn_service_gdbus_check_privilege(invocation, PRIVILEGE_INTERNET) == false) {
-               LOGE("permission denied, and finished request.");
-               result = VPNSVC_ERROR_PERMISSION_DENIED;
-               goto done;
+               vpnsvc_error_permission_denied(invocation);
+               return FALSE;
        }
 
        int socket;
@@ -146,7 +141,6 @@ gboolean handle_vpn_protect(Vpnsvc *object,
 
        result = vpn_daemon_protect(socket, arg_dev_name);
 
-done:
        vpnsvc_complete_vpn_protect(object, invocation, result);
 
        return TRUE;
@@ -182,9 +176,8 @@ gboolean handle_vpn_up(Vpnsvc *object,
 
        /* check privilege */
        if (vpn_service_gdbus_check_privilege(invocation, PRIVILEGE_VPN_SERVICE_ADMIN) == false) {
-               LOGE("permission denied, and finished request.");
-               result = VPNSVC_ERROR_PERMISSION_DENIED;
-               goto done;
+               vpnsvc_error_permission_denied(invocation);
+               return FALSE;
        }
 
        LOGD("iface_index : %d", arg_iface_index);
@@ -274,17 +267,14 @@ gboolean handle_vpn_down(Vpnsvc *object,
 
        /* check privilege */
        if (vpn_service_gdbus_check_privilege(invocation, PRIVILEGE_VPN_SERVICE_ADMIN) == false) {
-               LOGE("permission denied, and finished request.");
-               result = VPNSVC_ERROR_PERMISSION_DENIED;
-               goto done;
+               vpnsvc_error_permission_denied(invocation);
+               return FALSE;
        }
 
        LOGD("vpn_down, %d\n", arg_iface_index);
 
        result = vpn_daemon_down(arg_iface_index);
 
-done:
-
        vpnsvc_complete_vpn_down(object, invocation, result);
 
        return TRUE;
@@ -315,9 +305,8 @@ gboolean handle_vpn_block_networks(Vpnsvc *object,
        /* check privilege */
        if (vpn_service_gdbus_check_privilege(invocation, PRIVILEGE_VPN_SERVICE) == false
                || vpn_service_gdbus_check_privilege(invocation, PRIVILEGE_INTERNET) == false) {
-               LOGE("permission denied, and finished request.");
-               result = VPNSVC_ERROR_PERMISSION_DENIED;
-               goto done;
+               vpnsvc_error_permission_denied(invocation);
+               return FALSE;
        }
 
        LOGD("vpn_block_networks");
@@ -363,8 +352,6 @@ gboolean handle_vpn_block_networks(Vpnsvc *object,
        /* call function */
        result = vpn_daemon_block_networks(nets_vpn, prefix_vpn, arg_nr_nets_vpn, nets_orig, prefix_orig, arg_nr_nets_orig);
 
-done:
-
        for (i = 0; i < arg_nr_nets_vpn; ++i) {
                g_free(nets_orig[i]);
                g_free(nets_vpn[i]);
@@ -385,16 +372,14 @@ gboolean handle_vpn_unblock_networks(Vpnsvc *object,
        /* check privilege */
        if (vpn_service_gdbus_check_privilege(invocation, PRIVILEGE_VPN_SERVICE) == false
                || vpn_service_gdbus_check_privilege(invocation, PRIVILEGE_INTERNET) == false) {
-               LOGE("permission denied, and finished request.");
-               result = VPNSVC_ERROR_PERMISSION_DENIED;
-               goto done;
+               vpnsvc_error_permission_denied(invocation);
+               return FALSE;
        }
 
        LOGD("vpn_unblock_networks");
 
        result = vpn_daemon_unblock_networks();
 
-done:
        vpnsvc_complete_vpn_unblock_networks(object, invocation, result);
 
        return TRUE;
index 0e96d7e..dbd5763 100755 (executable)
@@ -156,17 +156,13 @@ GVariant *_vpnsvc_invoke_dbus_method(GDBusConnection *connection,
 
        if (reply == NULL) {
                if (error != NULL) {//LCOV_EXCL_LINE
-                       if (error->code == G_DBUS_ERROR_ACCESS_DENIED) {//LCOV_EXCL_LINE
-                               LOGE("g_dbus_connection_call_sync() failed"//LCOV_EXCL_LINE
-                                       "error [%d: %s]", error->code, error->message);
-                               *dbus_error = VPNSVC_ERROR_PERMISSION_DENIED;//LCOV_EXCL_LINE
-                               g_error_free(error);//LCOV_EXCL_LINE
-                       } else {
-                               LOGE("g_dbus_connection_call_sync() failed"//LCOV_EXCL_LINE
-                                               "error [%d: %s]", error->code, error->message);
-                               *dbus_error = VPNSVC_ERROR_IO_ERROR;//LCOV_EXCL_LINE
-                               g_error_free(error);//LCOV_EXCL_LINE
-                       }
+                       LOGE("g_dbus_connection_call_sync() failed "//LCOV_EXCL_LINE
+                               "error [%d: %s]", error->code, error->message);
+                       if (error->code == G_DBUS_ERROR_ACCESS_DENIED) //LCOV_EXCL_LINE
+                               *dbus_error = VPNSVC_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
+                       else
+                               *dbus_error = VPNSVC_ERROR_IO_ERROR; //LCOV_EXCL_LINE
+                       g_error_free(error);//LCOV_EXCL_LINE
                } else {
                        LOGE("g_dbus_connection_call_sync() failed");//LCOV_EXCL_LINE
                        *dbus_error = VPNSVC_ERROR_IPC_FAILED;//LCOV_EXCL_LINE
@@ -226,12 +222,15 @@ GVariant *_vpnsvc_invoke_dbus_method_with_fd(GDBusConnection *connection,
 
        if (reply == NULL) {
                if (error != NULL) {//LCOV_EXCL_LINE
-                       LOGE("g_dbus_connection_call_sync() failed" //LCOV_EXCL_LINE
+                       LOGE("g_dbus_connection_call_with_unix_fd_list_sync() failed " //LCOV_EXCL_LINE
                                        "error [%d: %s]", error->code, error->message);
-                       *dbus_error = VPNSVC_ERROR_IO_ERROR; //LCOV_EXCL_LINE
+                       if (error->code == G_DBUS_ERROR_ACCESS_DENIED) //LCOV_EXCL_LINE
+                               *dbus_error = VPNSVC_ERROR_PERMISSION_DENIED; //LCOV_EXCL_LINE
+                       else
+                               *dbus_error = VPNSVC_ERROR_IO_ERROR; //LCOV_EXCL_LINE
                        g_error_free(error); //LCOV_EXCL_LINE
                } else {
-                       LOGE("g_dbus_connection_call_sync() failed"); //LCOV_EXCL_LINE
+                       LOGE("g_dbus_connection_call_with_unix_fd_list_sync() failed"); //LCOV_EXCL_LINE
                        *dbus_error = VPNSVC_ERROR_IPC_FAILED; //LCOV_EXCL_LINE
                }
 
@@ -315,6 +314,9 @@ EXPORT_API int vpnsvc_init(const char* iface_name, vpnsvc_h *handle)
                                                        iface_fd,
                                                        &dbus_result);
 
+       if (dbus_result == VPNSVC_ERROR_PERMISSION_DENIED)
+               return VPNSVC_ERROR_PERMISSION_DENIED;
+
        if (op == NULL) {
                close(iface_fd); //LCOV_EXCL_LINE
                _vpnsvc_deinit_vpnsvc_tun_s(tmp_s); //LCOV_EXCL_LINE
@@ -527,6 +529,9 @@ EXPORT_API int vpnsvc_up(vpnsvc_h handle, const char* local_ip, const char* remo
                                                                dns_suffix, tun_s->mtu),
                                                                &dbus_result);
 
+       if (dbus_result == VPNSVC_ERROR_PERMISSION_DENIED)
+               return VPNSVC_ERROR_PERMISSION_DENIED;
+
        if (op == NULL) {
                return VPNSVC_ERROR_IPC_FAILED; //LCOV_EXCL_LINE
        } else {
@@ -576,6 +581,9 @@ EXPORT_API int vpnsvc_down(vpnsvc_h handle)
                                                                g_variant_new("(i)", tun_s->index),
                                                                &dbus_result);
 
+       if (dbus_result == VPNSVC_ERROR_PERMISSION_DENIED)
+               return VPNSVC_ERROR_PERMISSION_DENIED;
+
        if (op == NULL) {
                return VPNSVC_ERROR_IPC_FAILED; //LCOV_EXCL_LINE
        } else {
index 8638d30..7cdcce2 100755 (executable)
@@ -1,6 +1,6 @@
 Name:       vpnsvc-pkg
 Summary:    VPN service library in TIZEN C API
-Version:    1.0.19
+Version:    1.0.20
 Release:    1
 Group:      System/Network
 License:    Apache-2.0