SET(SRCS
src/vpnsvc.c
src/vpndbus.c
+ src/vpnerror.c
src/vpn_service_daemon.c
src/vpn_service_daemon_main.c
)
--- /dev/null
+/*
+ * 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__ */
--- /dev/null
+/*
+ * 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");
+}
#include "vpnsvc.h"
#include "vpndbus.h"
+#include "vpnerror.h"
#include "vpn_service_daemon.h"
#include "cynara-client.h"
/* 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;
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;
/* 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;
/* 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;
result = vpn_daemon_protect(socket, arg_dev_name);
-done:
vpnsvc_complete_vpn_protect(object, invocation, result);
return TRUE;
/* 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);
/* 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;
/* 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");
/* 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]);
/* 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;
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
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
}
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
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 {
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 {
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