#include "stc-manager.h"
#include "stc-statistics.h"
#include "stc-restriction.h"
+#include "stc-firewall.h"
#include "stc-default-connection.h"
-#include "stc-manager-plugin.h"
-#include "stc-app-lifecycle.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)
{
__STC_LOG_FUNC_ENTER__;
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-unset",
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__;
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);
/* 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 */
iptables_init();
stc_default_connection_monitor_init(stc);
- stc_register_state_changed_cb(stc, stc_manager_app_status_changed, NULL);
+
+ stc_plugin_appstatus_register_state_changed_cb(stc,
+ stc_plugin_procfs_app_status_changed, NULL);
__STC_LOG_FUNC_EXIT__;
}
__STC_LOG_FUNC_ENTER__;
stc_s *stc = (stc_s *)stc_data;
- stc_deregister_state_changed_cb(stc);
+ stc_plugin_appstatus_deregister_state_changed_cb(stc);
stc_default_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__;
}
if (reply == NULL) {
if (error != NULL) {
STC_LOGE("g_dbus_connection_call_sync() failed" //LCOV_EXCL_LINE
- "error [%d: %s]", error->code, error->message);
+ " error [%d: %s]", error->code, error->message);
g_error_free(error); //LCOV_EXCL_LINE
} else {
STC_LOGE("g_dbus_connection_call_sync() failed"); //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);
}
__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;
+}