NMFirewallPendingCall
nm_firewall_manager_remove_from_zone (NMFirewallManager *self,
                                      const char *iface,
                                      const char *zone)
{
	NMFirewallManagerPrivate *priv = NM_FIREWALL_MANAGER_GET_PRIVATE (self);
	CBInfo *info;

	if (priv->running == FALSE) {
		nm_log_dbg (LOGD_FIREWALL, "(%s) firewall zone remove skipped (not running)", iface);
		return PENDING_CALL_DUMMY;
	}

	info = _cb_info_create (self, iface, NULL, NULL);

	nm_log_dbg (LOGD_FIREWALL, "(%s) firewall zone remove -> %s%s%s [%u]", iface,
	                           zone?"\"":"", zone ? zone : "*", zone?"\"":"", info->id);
	info->dbus_call = dbus_g_proxy_begin_call_with_timeout (priv->proxy,
	                                                        "removeInterface",
	                                                        remove_cb,
	                                                        info,
	                                                        (GDestroyNotify) _cb_info_free,
	                                                        10000,      /* timeout */
	                                                        G_TYPE_STRING, zone ? zone : "",
	                                                        G_TYPE_STRING, iface,
	                                                        G_TYPE_INVALID);
	return PENDING_CALL_FROM_INFO (info);
}
Ejemplo n.º 2
0
gpointer
nm_firewall_manager_add_or_change_zone (NMFirewallManager *self,
                                        const char *iface,
                                        const char *zone,
                                        gboolean add, /* TRUE == add, FALSE == change */
                                        FwAddToZoneFunc callback,
                                        gpointer user_data)
{
	NMFirewallManagerPrivate *priv = NM_FIREWALL_MANAGER_GET_PRIVATE (self);
	CBInfo *info;

	if (priv->running == FALSE) {
		nm_log_dbg (LOGD_FIREWALL, "(%s) firewall zone add/change skipped (not running)", iface);
		callback (NULL, user_data);
		return NULL;
	}

	info = _cb_info_create (iface, callback, user_data);

	nm_log_dbg (LOGD_FIREWALL, "(%s) firewall zone %s -> %s%s%s [%u]", iface, add ? "add" : "change",
	                           zone?"\"":"", zone ? zone : "default", zone?"\"":"", info->id);
	return dbus_g_proxy_begin_call_with_timeout (priv->proxy,
	                                             add ? "addInterface" : "changeZone",
	                                             add_or_change_cb,
	                                             info,
	                                             (GDestroyNotify) cb_info_free,
	                                             10000,      /* timeout */
	                                             G_TYPE_STRING, zone ? zone : "",
	                                             G_TYPE_STRING, iface,
	                                             G_TYPE_INVALID);
}
NMFirewallPendingCall
nm_firewall_manager_add_or_change_zone (NMFirewallManager *self,
                                        const char *iface,
                                        const char *zone,
                                        gboolean add, /* TRUE == add, FALSE == change */
                                        FwAddToZoneFunc callback,
                                        gpointer user_data)
{
	NMFirewallManagerPrivate *priv = NM_FIREWALL_MANAGER_GET_PRIVATE (self);
	CBInfo *info;

	if (priv->running == FALSE) {
		if (callback) {
			info = _cb_info_create (self, iface, callback, user_data);
			info->idle_id = g_idle_add (add_or_change_idle_cb, info);
			nm_log_dbg (LOGD_FIREWALL, "(%s) firewall zone %s -> %s%s%s [%u] (not running, simulate success)", iface, add ? "add" : "change",
			            zone?"\"":"", zone ? zone : "default", zone?"\"":"", info->id);
			return PENDING_CALL_FROM_INFO (info);
		} else {
			nm_log_dbg (LOGD_FIREWALL, "(%s) firewall zone add/change skipped (not running)", iface);
			return PENDING_CALL_DUMMY;
		}
	}

	info = _cb_info_create (self, iface, callback, user_data);

	nm_log_dbg (LOGD_FIREWALL, "(%s) firewall zone %s -> %s%s%s [%u]", iface, add ? "add" : "change",
	                           zone?"\"":"", zone ? zone : "default", zone?"\"":"", info->id);
	info->dbus_call = dbus_g_proxy_begin_call_with_timeout (priv->proxy,
	                                                        add ? "addInterface" : "changeZone",
	                                                        add_or_change_cb,
	                                                        info,
	                                                        (GDestroyNotify) _cb_info_free,
	                                                        10000,      /* timeout */
	                                                        G_TYPE_STRING, zone ? zone : "",
	                                                        G_TYPE_STRING, iface,
	                                                        G_TYPE_INVALID);
	return PENDING_CALL_FROM_INFO (info);
}
Ejemplo n.º 4
0
static NMFirewallManagerCallId
_start_request (NMFirewallManager *self,
                CBInfoOpsType ops_type,
                const char *iface,
                const char *zone,
                NMFirewallManagerAddRemoveCallback callback,
                gpointer user_data)
{
	NMFirewallManagerPrivate *priv;
	CBInfo *info;
	const char *dbus_method;

	g_return_val_if_fail (NM_IS_FIREWALL_MANAGER (self), NULL);
	g_return_val_if_fail (iface && *iface, NULL);

	priv = NM_FIREWALL_MANAGER_GET_PRIVATE (self);

	info = _cb_info_create (self, ops_type, iface, callback, user_data);

	_LOGD (info, "firewall zone %s %s:%s%s%s%s",
	       _ops_type_to_string (info->ops_type),
	       iface,
	       NM_PRINT_FMT_QUOTED (zone, "\"", zone, "\"", "default"),
	       _cb_info_is_idle (info) ? " (not running, simulate success)" : "");

	if (!_cb_info_is_idle (info)) {

		switch (ops_type) {
		case CB_INFO_OPS_ADD:
			dbus_method = "addInterface";
			break;
		case CB_INFO_OPS_CHANGE:
			dbus_method = "changeZone";
			break;
		case CB_INFO_OPS_REMOVE:
			dbus_method = "removeInterface";
			break;
		default:
			g_assert_not_reached ();
		}

		g_dbus_proxy_call (priv->proxy,
		                   dbus_method,
		                   g_variant_new ("(ss)", zone ? zone : "", iface),
		                   G_DBUS_CALL_FLAGS_NONE, 10000,
		                   info->dbus.cancellable,
		                   _handle_dbus,
		                   info);

		if (!info->callback) {
			/* if the user did not provide a callback, the call_id is useless.
			 * Especially, the user cannot use the call-id to cancel the request,
			 * because he cannot know whether the request is still pending.
			 *
			 * Hence, returning %NULL doesn't mean that the request could not be started
			 * (the request will always be started). */
			return NULL;
		}
	} else if (!info->callback) {
		/* if the user did not provide a callback and firewalld is not running,
		 * there is no point in scheduling an idle-request to fake success. Just
		 * return right away. */
		_LOGD (info, "complete: drop request simulating success");
		_cb_info_complete_normal (info, NULL);
		return NULL;
	} else
		info->idle.id = g_idle_add (_handle_idle, info);

	return info;
}