*/
#include "stc-manager-gdbus.h"
+#include "stc-manager.h"
#include "stc-statistics.h"
#include "stc-restriction.h"
-#include "stc-default-connection.h"
-#include "stc-application-lifecycle.h"
+#include "stc-firewall.h"
+#include "stc-connection.h"
+#include "stc-manager-util.h"
+#include "stc-manager-plugin-appstatus.h"
+#include "stc-manager-plugin-procfs.h"
+#include "helper-iptables.h"
+
+#define MANAGER_DBUS_ERROR_NAME "net.stc.manager.Error.Failed"
+
+#define STC_MANAGER_DBUS_REPLY_ERROR(invocation, err_num) \
+ g_dbus_method_invocation_return_dbus_error((invocation), \
+ MANAGER_DBUS_ERROR_NAME, \
+ stc_err_strs[-(err_num)])
+
+static const gchar *stc_err_strs[] = {
+ "ERROR_NONE",
+ "FAIL",
+ "DB_FAILED",
+ "OUT_OF_MEMORY",
+ "INVALID_PARAMETER",
+ "NO_DATA",
+ "ALREADY_DATA",
+ "UNINITIALIZED",
+ "PERMISSION_DENIED",
+ "NOTIMPL"
+};
static gboolean __stc_manager_gdbus_statistics_init(stc_s *stc)
{
g_signal_connect(restriction, "handle-set",
G_CALLBACK(handle_restriction_set), stc);
- g_signal_connect(restriction, "handle-exclude",
- G_CALLBACK(handle_restriction_exclude), stc);
-
g_signal_connect(restriction, "handle-get",
G_CALLBACK(handle_restriction_get), stc);
g_signal_connect(restriction, "handle-get-all",
G_CALLBACK(handle_restriction_get_all), stc);
- g_signal_connect(restriction, "handle-get-state",
- G_CALLBACK(handle_restriction_get_state),
+ g_signal_connect(restriction, "handle-get-type",
+ G_CALLBACK(handle_restriction_get_type),
stc);
- g_signal_connect(restriction, "handle-remove",
- G_CALLBACK(handle_restriction_remove), stc);
+ g_signal_connect(restriction, "handle-unset",
+ G_CALLBACK(handle_restriction_unset), stc);
/* Export the object (@manager takes its own reference to @object) */
g_dbus_object_manager_server_export(stc->obj_mgr,
return ret;
}
+static gboolean __stc_manager_gdbus_firewall_init(stc_s *stc)
+{
+ __STC_LOG_FUNC_ENTER__;
+ gboolean ret = TRUE;
+ gchar *s = NULL;
+
+ StcObjectSkeleton *object = NULL;
+ StcFirewall *firewall = NULL;
+ s = g_strdup_printf(STC_DBUS_SERVICE_FIREWALL_PATH);
+
+ /* Add interface to default object path */
+ object = stc_object_skeleton_new(s);
+ g_free(s);
+
+ firewall = stc_firewall_skeleton_new();
+ stc_object_skeleton_set_firewall(object, firewall);
+ g_object_unref(firewall);
+
+ /* Register for method callbacks as signal callbacks */
+
+ g_signal_connect(firewall, "handle-lock",
+ G_CALLBACK(handle_firewall_lock),
+ stc);
+
+ g_signal_connect(firewall, "handle-unlock",
+ G_CALLBACK(handle_firewall_unlock),
+ stc);
+
+ g_signal_connect(firewall, "handle-get-lock",
+ G_CALLBACK(handle_firewall_get_lock),
+ stc);
+
+ g_signal_connect(firewall, "handle-add-chain",
+ G_CALLBACK(handle_firewall_add_chain),
+ stc);
+
+ g_signal_connect(firewall, "handle-remove-chain",
+ G_CALLBACK(handle_firewall_remove_chain),
+ stc);
+
+ g_signal_connect(firewall, "handle-flush-chain",
+ G_CALLBACK(handle_firewall_flush_chain),
+ stc);
+
+ g_signal_connect(firewall, "handle-get-all-chain",
+ G_CALLBACK(handle_firewall_get_all_chain),
+ stc);
+
+ g_signal_connect(firewall, "handle-set-chain",
+ G_CALLBACK(handle_firewall_set_chain),
+ stc);
+
+ g_signal_connect(firewall, "handle-unset-chain",
+ G_CALLBACK(handle_firewall_unset_chain),
+ stc);
+
+ g_signal_connect(firewall, "handle-add-rule",
+ G_CALLBACK(handle_firewall_add_rule),
+ stc);
+
+ g_signal_connect(firewall, "handle-remove-rule",
+ G_CALLBACK(handle_firewall_remove_rule),
+ stc);
+
+ g_signal_connect(firewall, "handle-update-rule",
+ G_CALLBACK(handle_firewall_update_rule),
+ stc);
+
+ g_signal_connect(firewall, "handle-get-all-rule",
+ G_CALLBACK(handle_firewall_get_all_rule),
+ stc);
+
+ /* Export the object (@manager takes its own reference to @object) */
+ g_dbus_object_manager_server_export(stc->obj_mgr,
+ G_DBUS_OBJECT_SKELETON(object));
+ g_object_unref(object);
+
+ stc->firewall_obj = (gpointer)firewall;
+
+ __STC_LOG_FUNC_EXIT__;
+ return ret;
+}
+
+static gboolean __stc_manager_gdbus_manager_init(stc_s *stc)
+{
+ __STC_LOG_FUNC_ENTER__;
+ gboolean ret = TRUE;
+ gchar *s = NULL;
+
+ StcObjectSkeleton *object = NULL;
+ StcManager *manager = NULL;
+ s = g_strdup_printf(STC_DBUS_SERVICE_MANAGER_PATH);
+
+ object = stc_object_skeleton_new(s);
+ g_free(s);
+
+ manager = stc_manager_skeleton_new();
+ stc_object_skeleton_set_manager(object, manager);
+ g_object_unref(manager);
+
+ g_signal_connect(manager, "handle-stop",
+ G_CALLBACK(handle_manager_stop), stc);
+
+ g_signal_connect(manager, "handle-commit-iptables",
+ G_CALLBACK(handle_manager_commit_iptables), stc);
+
+ g_signal_connect(manager, "handle-commit-ip6tables",
+ G_CALLBACK(handle_manager_commit_ip6tables), stc);
+
+ g_dbus_object_manager_server_export(stc->obj_mgr,
+ G_DBUS_OBJECT_SKELETON(object));
+ g_object_unref(object);
+
+ stc->manager_obj = (gpointer)manager;
+
+ __STC_LOG_FUNC_EXIT__;
+ return ret;
+}
+
+
static void __stc_manager_gdbus_on_bus_acquired(GDBusConnection *connection,
const gchar *name,
gpointer user_data)
stc->connection = connection;
if (__stc_manager_gdbus_statistics_init(stc) == FALSE) {
- STC_LOGE("Can not signal connect to statistics");
+ STC_LOGE("Can not signal connect to statistics"); //LCOV_EXCL_LINE
/* Deinitialize and quit manager */
}
if (__stc_manager_gdbus_restriction_init(stc) == FALSE) {
- STC_LOGE("Cannot signal connect to restriction");
+ STC_LOGE("Cannot signal connect to restriction"); //LCOV_EXCL_LINE
+ /* Deinitialize and quit manager */
+ }
+
+ if (__stc_manager_gdbus_firewall_init(stc) == FALSE) {
+ STC_LOGE("Cannot signal connect to firewall"); //LCOV_EXCL_LINE
+ /* Deinitialize and quit manager */
+ }
+
+ if (__stc_manager_gdbus_manager_init(stc) == FALSE) {
+ STC_LOGE("Cannot signal connect to manager"); //LCOV_EXCL_LINE
/* Deinitialize and quit manager */
}
g_dbus_object_manager_server_set_connection(stc->obj_mgr,
stc->connection);
- stc_application_lifecycle_monitor_init(stc);
- stc_default_connection_monitor_init(stc);
+ iptables_init();
+ stc_connection_monitor_init(stc);
+
+ stc_plugin_appstatus_register_state_changed_cb(stc,
+ stc_plugin_procfs_app_status_changed, NULL);
__STC_LOG_FUNC_EXIT__;
}
STC_LOGD("name : %s", name);
}
+//LCOV_EXCL_START
static void __stc_manager_gdbus_on_name_lost(GDBusConnection *connection,
const gchar *name,
gpointer user_data)
{
STC_LOGD("name : %s", name);
}
+//LCOV_EXCL_STOP
void stc_manager_gdbus_init(gpointer stc_data)
{
{
__STC_LOG_FUNC_ENTER__;
stc_s *stc = (stc_s *)stc_data;
- stc_application_lifecycle_monitor_deinit(stc);
- stc_default_connection_monitor_deinit(stc);
+
+ stc_plugin_appstatus_deregister_state_changed_cb(stc);
+ stc_connection_monitor_deinit(stc);
+
g_bus_unown_name(stc->gdbus_owner_id);
+
stc->statistics_obj = NULL;
stc->restriction_obj = NULL;
+ stc->firewall_obj = NULL;
+ stc->manager_obj = NULL;
__STC_LOG_FUNC_EXIT__;
}
GVariant *reply = NULL;
if (connection == NULL) {
- STC_LOGE("Failed to get GDBusconnection");
- return reply;
+ STC_LOGE("Failed to get GDBusconnection"); //LCOV_EXCL_LINE
+ return reply; //LCOV_EXCL_LINE
}
reply = g_dbus_connection_call_sync(connection,
if (reply == NULL) {
if (error != NULL) {
- STC_LOGE("g_dbus_connection_call_sync() failed"
- "error [%d: %s]", error->code, error->message);
- g_error_free(error);
+ STC_LOGE("g_dbus_connection_call_sync() failed" //LCOV_EXCL_LINE
+ " error [%d: %s]", error->code, error->message);
+ g_error_free(error); //LCOV_EXCL_LINE
} else {
- STC_LOGE("g_dbus_connection_call_sync() failed");
+ STC_LOGE("g_dbus_connection_call_sync() failed"); //LCOV_EXCL_LINE
}
return NULL;
GDestroyNotify user_data_free_func)
{
if (connection == NULL) {
- STC_LOGE("Failed to get GDBusconnection");
- return 0;
+ STC_LOGE("Failed to get GDBusconnection"); //LCOV_EXCL_LINE
+ return 0; //LCOV_EXCL_LINE
}
return g_dbus_connection_signal_subscribe(connection,
guint subscription_id)
{
if (connection == NULL) {
- STC_LOGE("Failed to get GDBusconnection");
- return;
+ STC_LOGE("Failed to get GDBusconnection"); //LCOV_EXCL_LINE
+ return; //LCOV_EXCL_LINE
}
g_dbus_connection_signal_unsubscribe(connection, subscription_id);
GVariant *value = NULL;
if (!cb) {
- __STC_LOG_FUNC_EXIT__;
- return;
+ __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
+ return; //LCOV_EXCL_LINE
}
while (g_variant_iter_loop(iter, "{sv}", &key, &value)) {
- DEBUG_GDBUS_KEY_VALUE(key, value);
- if (key && cb)
+ /* DEBUG_GDBUS_KEY_VALUE(key, value); */
+ if (key)
cb(key, value, user_data);
}
GError *error = NULL;
if (connection == NULL) {
- STC_LOGE("GDBusconnection is NULL");
+ STC_LOGE("GDBusconnection is NULL"); //LCOV_EXCL_LINE
return 0;
}
parameters,
&error);
if (rv != TRUE) {
- STC_LOGE("Failed to emit signal [%s] interface [%s] Error [%s]",
+ STC_LOGE("Failed to emit signal [%s] interface [%s] Error [%s]", //LCOV_EXCL_LINE
signal_name, interface_name, error->message);
- g_error_free(error);
+ g_error_free(error); //LCOV_EXCL_LINE
} else {
STC_LOGD("[%s] signal sent on [%s] interface", signal_name,
interface_name);
return rv;
}
+
+gboolean handle_manager_stop(StcManager *object,
+ GDBusMethodInvocation *invocation)
+{
+ __STC_LOG_FUNC_ENTER__;
+ GVariant *return_parameters = NULL;
+
+ STC_LOGI("stc manager stop");
+
+ return_parameters = g_variant_new("(i)", STC_ERROR_NONE);
+
+ DEBUG_GDBUS_VARIANT("Return parameters: ", return_parameters);
+ STC_DBUS_REPLY(invocation, return_parameters);
+
+ stc_stop_manager();
+
+ __STC_LOG_FUNC_EXIT__;
+ return TRUE;
+}
+
+gboolean handle_manager_commit_iptables(StcManager *object,
+ GDBusMethodInvocation *invocation,
+ const gchar *option,
+ void *user_data)
+{
+ __STC_LOG_FUNC_ENTER__;
+ GVariant *return_parameters = NULL;
+ int ret = STC_ERROR_NONE;
+ int err_num = 0;
+ char *err_str = NULL;
+ char cmd[STC_CMD_SIZE] = { 0, };
+
+ if (option == NULL) {
+ STC_MANAGER_DBUS_REPLY_ERROR(invocation,
+ STC_ERROR_INVALID_PARAMETER);
+ __STC_LOG_FUNC_EXIT__;
+ return TRUE;
+ }
+
+ STC_LOGD("[%s]", option);
+ g_snprintf(cmd, STC_CMD_SIZE, "%s %s", STC_IPTABLES, option);
+
+ ret = stc_commit_iptables(cmd, &err_num, &err_str);
+
+ return_parameters = g_variant_new("(iis)", ret, err_num, err_str);
+
+ DEBUG_GDBUS_VARIANT("Return parameters: ", return_parameters);
+ STC_DBUS_REPLY(invocation, return_parameters);
+
+ __STC_LOG_FUNC_EXIT__;
+ return TRUE;
+}
+
+gboolean handle_manager_commit_ip6tables(StcManager *object,
+ GDBusMethodInvocation *invocation,
+ const gchar *option,
+ void *user_data)
+{
+ __STC_LOG_FUNC_ENTER__;
+ GVariant *return_parameters = NULL;
+ int ret = STC_ERROR_NONE;
+ int err_num = 0;
+ char *err_str = NULL;
+ char cmd[STC_CMD_SIZE] = { 0, };
+
+ if (option == NULL) {
+ STC_MANAGER_DBUS_REPLY_ERROR(invocation,
+ STC_ERROR_INVALID_PARAMETER);
+ __STC_LOG_FUNC_EXIT__;
+ return TRUE;
+ }
+
+ STC_LOGD("[%s]", option);
+ g_snprintf(cmd, STC_CMD_SIZE, "%s %s", STC_IP6TABLES, option);
+
+ ret = stc_commit_iptables(cmd, &err_num, &err_str);
+
+ return_parameters = g_variant_new("(iis)", ret, err_num, err_str);
+
+ DEBUG_GDBUS_VARIANT("Return parameters: ", return_parameters);
+ STC_DBUS_REPLY(invocation, return_parameters);
+
+ __STC_LOG_FUNC_EXIT__;
+ return TRUE;
+}