예제 #1
0
/**
 * _nm_dbus_signal_connect_data:
 * @proxy: a #GDBusProxy
 * @signal_name: the D-Bus signal to connect to
 * @signature: (allow-none): the signal's type signature (must be a tuple)
 * @c_handler: the signal handler function
 * @data: (allow-none): data to pass to @c_handler
 * @destroy_data: (allow-none): closure destroy notify for @data
 * @connect_flags: connection flags
 *
 * Connects to the D-Bus signal @signal_name on @proxy. @c_handler must be a
 * void function whose first argument is a #GDBusProxy, followed by arguments
 * for each element of @signature, ending with a #gpointer argument for @data.
 *
 * The argument types in @c_handler correspond to the types output by
 * g_dbus_gvariant_to_gvalue(), except for 'ay' and 'aay'. In particular:
 * - both 16-bit and 32-bit integers are passed as #gint/#guint
 * - 'as' values are passed as #GStrv (char **)
 * - all other array, tuple, and dict types are passed as #GVariant
 *
 * If @signature is %NULL, then the signal's parameters will be ignored, and
 * @c_handler should take only the #GDBusProxy and #gpointer arguments.
 *
 * Returns: the signal handler ID, which can be used with
 *   g_signal_handler_remove(). Beware that because of the way the signal is
 *   connected, you will not be able to remove it with
 *   g_signal_handlers_disconnect_by_func(), although
 *   g_signal_handlers_disconnect_by_data() will work correctly.
 */
gulong
_nm_dbus_signal_connect_data (GDBusProxy *proxy,
                              const char *signal_name,
                              const GVariantType *signature,
                              GCallback c_handler,
                              gpointer data,
                              GClosureNotify destroy_data,
                              GConnectFlags connect_flags)
{
	NMDBusSignalData *sd;
	GClosure *closure;
	gboolean swapped = !!(connect_flags & G_CONNECT_SWAPPED);
	gboolean after = !!(connect_flags & G_CONNECT_AFTER);

	g_return_val_if_fail (G_IS_DBUS_PROXY (proxy), 0);
	g_return_val_if_fail (signal_name != NULL, 0);
	g_return_val_if_fail (signature == NULL || g_variant_type_is_tuple (signature), 0);
	g_return_val_if_fail (c_handler != NULL, 0);

	sd = g_slice_new (NMDBusSignalData);
	sd->signal_name = g_strdup (signal_name);
	sd->signature = signature;

	closure = (swapped ? g_cclosure_new_swap : g_cclosure_new) (c_handler, data, destroy_data);
	g_closure_set_marshal (closure, g_cclosure_marshal_generic);
	g_closure_set_meta_marshal (closure, sd, dbus_signal_meta_marshal);
	g_closure_add_finalize_notifier (closure, sd, dbus_signal_data_free);

	return g_signal_connect_closure (proxy, "g-signal", closure, after);
}
static void
nm_exit_notify (void *data, int arg)
{
	g_return_if_fail (G_IS_DBUS_PROXY (gl.proxy));

	_LOGI ("exit: cleaning up");
	g_clear_object (&gl.proxy);
}
예제 #3
0
/**
 * mm_modem_simple_get_path:
 * @self: A #MMModemSimple.
 *
 * Gets the DBus path of the #MMObject which implements this interface.
 *
 * Returns: (transfer none): The DBus path of the #MMObject object.
 */
const gchar *
mm_modem_simple_get_path (MMModemSimple *self)
{
    g_return_val_if_fail (G_IS_DBUS_PROXY (self), NULL);

    RETURN_NON_EMPTY_CONSTANT_STRING (
        g_dbus_proxy_get_object_path (G_DBUS_PROXY (self)));
}
static int
get_credentials (char *username, char *password)
{
	const char *my_username = NULL;
	const char *my_password = NULL;
	size_t len;
	GVariant *ret;
	GError *err = NULL;

	if (!password) {
		/* pppd is checking pap support; return 1 for supported */
		g_return_val_if_fail (username, -1);
		return 1;
	}

	g_return_val_if_fail (username, -1);
	g_return_val_if_fail (G_IS_DBUS_PROXY (proxy), -1);

	g_message ("nm-sstp-ppp-plugin: (%s): passwd-hook, requesting credentials...", __func__);

	ret = g_dbus_proxy_call_sync (proxy,
	                              "NeedSecrets",
	                              NULL,
	                              G_DBUS_CALL_FLAGS_NONE, -1,
	                              NULL, &err);
	if (!ret) {
		g_warning ("nm-sstp-ppp-plugin: (%s): could not get secrets: (%d) %s",
		           __func__,
		           err ? err->code : -1,
		           err->message ? err->message : "(unknown)");
		g_error_free (err);
		return -1;
	}

	g_message ("nm-sstp-ppp-plugin: (%s): got credentials from NetworkManager-sstp", __func__);
	g_variant_get (ret, "(&s&s)", &my_username, &my_password);

	if (my_username) {
		len = strlen (my_username) + 1;
		len = len < MAXNAMELEN ? len : MAXNAMELEN;

		strncpy (username, my_username, len);
		username[len - 1] = '\0';
	}

	if (my_password) {
		len = strlen (my_password) + 1;
		len = len < MAXSECRETLEN ? len : MAXSECRETLEN;

		strncpy (password, my_password, len);
		password[len - 1] = '\0';
	}

	g_variant_unref (ret);

	return 1;
}
static void
nm_exit_notify (void *data, int arg)
{
	g_return_if_fail (G_IS_DBUS_PROXY (proxy));

	g_message ("nm-sstp-ppp-plugin: (%s): cleaning up", __func__);

	g_object_unref (proxy);
	proxy = NULL;
}
예제 #6
0
/**
 * mm_modem_simple_dup_path:
 * @self: A #MMModemSimple.
 *
 * Gets a copy of the DBus path of the #MMObject object which implements this interface.
 *
 * Returns: (transfer full): The DBus path of the #MMObject. The returned value should be freed with g_free().
 */
gchar *
mm_modem_simple_dup_path (MMModemSimple *self)
{
    gchar *value;

    g_return_val_if_fail (G_IS_DBUS_PROXY (self), NULL);

    g_object_get (G_OBJECT (self),
                  "g-object-path", &value,
                  NULL);
    RETURN_NON_EMPTY_STRING (value);
}
void
_g_dbus_object_proxy_add_interface (GDBusObjectProxy *proxy,
                                    GDBusProxy       *interface_proxy)
{
  const gchar *interface_name;

  g_return_if_fail (G_IS_DBUS_OBJECT_PROXY (proxy));
  g_return_if_fail (G_IS_DBUS_PROXY (interface_proxy));

  interface_name = g_dbus_proxy_get_interface_name (interface_proxy);
  _g_dbus_object_proxy_remove_interface (proxy, interface_name);
  g_hash_table_insert (proxy->priv->map_name_to_iface,
                       g_strdup (interface_name),
                       g_object_ref (interface_proxy));
  g_signal_emit_by_name (proxy, "interface-added", interface_proxy);
}
static int
get_credentials (char *username, char *password)
{
	const char *my_username = NULL;
	const char *my_password = NULL;
	GVariant *ret;
	GError *error = NULL;

	if (!password) {
		/* pppd is checking pap support; return 1 for supported */
		g_return_val_if_fail (username, -1);
		return 1;
	}

	g_return_val_if_fail (username, -1);
	g_return_val_if_fail (G_IS_DBUS_PROXY (gl.proxy), -1);

	_LOGI ("passwd-hook: requesting credentials...");

	ret = g_dbus_proxy_call_sync (gl.proxy,
	                              "NeedSecrets",
	                              NULL,
	                              G_DBUS_CALL_FLAGS_NONE, -1,
	                              NULL, &error);
	if (!ret) {
		_LOGW ("passwd-hook: could not get secrets: %s",
		       error->message);
		g_error_free (error);
		return -1;
	}

	_LOGI ("passwd-hook: got credentials from NetworkManager-l2tp");

	g_variant_get (ret, "(&s&s)", &my_username, &my_password);

	if (my_username)
		g_strlcpy (username, my_username, MAXNAMELEN);

	if (my_password) {
		g_strlcpy (password, my_password, MAXSECRETLEN);
	}

	g_variant_unref (ret);

	return 1;
}
static void
nm_phasechange (void *data, int arg)
{
	NMPPPStatus ppp_status = NM_PPP_STATUS_UNKNOWN;
	char *ppp_phase;

	g_return_if_fail (G_IS_DBUS_PROXY (proxy));
	switch (arg) {
	case PHASE_DEAD:
		ppp_status = NM_PPP_STATUS_DEAD;
		ppp_phase = "dead";
		break;
	case PHASE_INITIALIZE:
		ppp_status = NM_PPP_STATUS_INITIALIZE;
		ppp_phase = "initialize";
		break;
	case PHASE_SERIALCONN:
		ppp_status = NM_PPP_STATUS_SERIALCONN;
		ppp_phase = "serial connection";
		break;
	case PHASE_DORMANT:
		ppp_status = NM_PPP_STATUS_DORMANT;
		ppp_phase = "dormant";
		break;
	case PHASE_ESTABLISH:
		ppp_status = NM_PPP_STATUS_ESTABLISH;
		ppp_phase = "establish";
		break;
	case PHASE_AUTHENTICATE:
		ppp_status = NM_PPP_STATUS_AUTHENTICATE;
		ppp_phase = "authenticate";
		break;
	case PHASE_CALLBACK:
		ppp_status = NM_PPP_STATUS_CALLBACK;
		ppp_phase = "callback";
		break;
	case PHASE_NETWORK:
		ppp_status = NM_PPP_STATUS_NETWORK;
		ppp_phase = "network";
		break;
	case PHASE_RUNNING:
		ppp_status = NM_PPP_STATUS_RUNNING;
		ppp_phase = "running";
		break;
	case PHASE_TERMINATE:
		ppp_status = NM_PPP_STATUS_TERMINATE;
		ppp_phase = "terminate";
		break;
	case PHASE_DISCONNECT:
		ppp_status = NM_PPP_STATUS_DISCONNECT;
		ppp_phase = "disconnect";
		break;
	case PHASE_HOLDOFF:
		ppp_status = NM_PPP_STATUS_HOLDOFF;
		ppp_phase = "holdoff";
		break;
	case PHASE_MASTER:
		ppp_status = NM_PPP_STATUS_MASTER;
		ppp_phase = "master";
		break;

	default:
		ppp_phase = "unknown";
		break;
	}

	g_message ("nm-sstp-ppp-plugin: (%s): status %d / phase '%s'",
	           __func__,
	           ppp_status,
	           ppp_phase);

	if (ppp_status != NM_PPP_STATUS_UNKNOWN) {
		g_dbus_proxy_call (proxy,
		                   "SetState",
		                   g_variant_new ("(u)", ppp_status),
		                   G_DBUS_CALL_FLAGS_NONE, -1,
	                           NULL,
	                           NULL, NULL);
	}
}
static void
nm_ip_up (void *data, int arg)
{
	guint32 pppd_made_up_address = htonl (0x0a404040 + ifunit);
	ipcp_options opts = ipcp_gotoptions[0];
	ipcp_options peer_opts = ipcp_hisoptions[0];
	GVariantBuilder builder;
	struct sockaddr_in addr;

	g_return_if_fail (G_IS_DBUS_PROXY (proxy));

	g_message ("nm-sstp-ppp-plugin: (%s): ip-up event", __func__);

	if (!opts.ouraddr) {
		g_warning ("nm-sstp-ppp-plugin: (%s): didn't receive an internal IP from pppd!", __func__);
		return;
	}

	g_variant_builder_init (&builder, G_VARIANT_TYPE_VARDICT);

	g_variant_builder_add (&builder, "{sv}",
	                       NM_VPN_PLUGIN_IP4_CONFIG_TUNDEV,
	                       g_variant_new_string (ifname));

	g_variant_builder_add (&builder, "{sv}",
	                       NM_VPN_PLUGIN_IP4_CONFIG_ADDRESS,
	                       g_variant_new_uint32 (opts.ouraddr));

	/* Request the address of the server sstpc connected to */
	if (0 == nm_sstp_getaddr(&addr))
	{
		/* This will eliminate the need to have nm-sstp-service
		 * insert a new entry for "gateway" as we have already set it.
		 */
		g_variant_builder_add (&builder, "{sv}",
		                       NM_VPN_PLUGIN_IP4_CONFIG_EXT_GATEWAY,
		                       g_variant_new_uint32 (addr.sin_addr.s_addr));
	}

	/* Prefer the peer options remote address first, _unless_ pppd made the
	 * address up, at which point prefer the local options remote address,
	 * and if that's not right, use the made-up address as a last resort.
	 */
	if (peer_opts.hisaddr && (peer_opts.hisaddr != pppd_made_up_address)) {
		g_variant_builder_add (&builder, "{sv}",
		                       NM_VPN_PLUGIN_IP4_CONFIG_PTP,
		                       g_variant_new_uint32 (peer_opts.hisaddr));
	} else if (opts.hisaddr) {
		g_variant_builder_add (&builder, "{sv}",
		                       NM_VPN_PLUGIN_IP4_CONFIG_PTP,
		                       g_variant_new_uint32 (opts.hisaddr));
	} else if (peer_opts.hisaddr == pppd_made_up_address) {
		/* As a last resort, use the made-up address */
		g_variant_builder_add (&builder, "{sv}",
		                       NM_VPN_PLUGIN_IP4_CONFIG_PTP,
		                       g_variant_new_uint32 (peer_opts.ouraddr));
	}

	g_variant_builder_add (&builder, "{sv}",
	                       NM_VPN_PLUGIN_IP4_CONFIG_PREFIX,
	                       g_variant_new_uint32 (32));

	if (opts.dnsaddr[0] || opts.dnsaddr[1]) {
		guint32 dns[2];
		int len = 0;

		if (opts.dnsaddr[0])
			dns[len++] = opts.dnsaddr[0];
		if (opts.dnsaddr[1])
			dns[len++] = opts.dnsaddr[1];

		g_variant_builder_add (&builder, "{sv}",
		                       NM_VPN_PLUGIN_IP4_CONFIG_DNS,
		                       g_variant_new_fixed_array (G_VARIANT_TYPE_UINT32,
		                                                  dns, len, sizeof (guint32)));
	}

	/* Default MTU to 1400, which is also what Windows XP/Vista use */
	g_variant_builder_add (&builder, "{sv}",
	                       NM_VPN_PLUGIN_IP4_CONFIG_MTU,
	                        g_variant_new_uint32 (1400));

	g_message ("nm-sstp-ppp-plugin: (%s): sending Ip4Config to NetworkManager-sstp...", __func__);

	g_dbus_proxy_call (proxy,
	                   "SetIp4Config",
	                   g_variant_new ("(a{sv})", &builder),
	                   G_DBUS_CALL_FLAGS_NONE, -1,
	                   NULL,
	                   NULL, NULL);
}
static void
nm_ip_up (void *data, int arg)
{
	guint32 pppd_made_up_address = htonl (0x0a404040 + ifunit);
	ipcp_options opts = ipcp_gotoptions[0];
	ipcp_options peer_opts = ipcp_hisoptions[0];
	GVariantBuilder builder;

	g_return_if_fail (G_IS_DBUS_PROXY (gl.proxy));

	_LOGI ("ip-up: event");

	if (!opts.ouraddr) {
		_LOGW ("ip-up: didn't receive an internal IP from pppd!");
		nm_phasechange (NULL, PHASE_DEAD);
		return;
	}

	g_variant_builder_init (&builder, G_VARIANT_TYPE_VARDICT);

	g_variant_builder_add (&builder, "{sv}",
	                       NM_VPN_PLUGIN_IP4_CONFIG_TUNDEV,
	                       g_variant_new_string (ifname));

	g_variant_builder_add (&builder, "{sv}",
	                       NM_VPN_PLUGIN_IP4_CONFIG_ADDRESS,
	                       g_variant_new_uint32 (opts.ouraddr));

	/* Prefer the peer options remote address first, _unless_ pppd made the
	 * address up, at which point prefer the local options remote address,
	 * and if that's not right, use the made-up address as a last resort.
	 */
	if (peer_opts.hisaddr && (peer_opts.hisaddr != pppd_made_up_address)) {
		g_variant_builder_add (&builder, "{sv}",
		                       NM_VPN_PLUGIN_IP4_CONFIG_PTP,
		                       g_variant_new_uint32 (peer_opts.hisaddr));
	} else if (opts.hisaddr) {
		g_variant_builder_add (&builder, "{sv}",
		                       NM_VPN_PLUGIN_IP4_CONFIG_PTP,
		                       g_variant_new_uint32 (opts.hisaddr));
	} else if (peer_opts.hisaddr == pppd_made_up_address) {
		/* As a last resort, use the made-up address */
		g_variant_builder_add (&builder, "{sv}",
		                       NM_VPN_PLUGIN_IP4_CONFIG_PTP,
		                       g_variant_new_uint32 (peer_opts.ouraddr));
	}

	g_variant_builder_add (&builder, "{sv}",
	                       NM_VPN_PLUGIN_IP4_CONFIG_PREFIX,
	                       g_variant_new_uint32 (32));

	if (opts.dnsaddr[0] || opts.dnsaddr[1]) {
		guint32 dns[2];
		int len = 0;

		if (opts.dnsaddr[0])
			dns[len++] = opts.dnsaddr[0];
		if (opts.dnsaddr[1])
			dns[len++] = opts.dnsaddr[1];

		g_variant_builder_add (&builder, "{sv}",
		                       NM_VPN_PLUGIN_IP4_CONFIG_DNS,
		                       g_variant_new_fixed_array (G_VARIANT_TYPE_UINT32,
		                                                  dns, len, sizeof (guint32)));
	}

	_LOGI ("ip-up: sending Ip4Config to NetworkManager-l2tp...");

	g_dbus_proxy_call (gl.proxy,
	                   "SetIp4Config",
	                   g_variant_new ("(a{sv})", &builder),
	                   G_DBUS_CALL_FLAGS_NONE, -1,
	                   NULL,
	                   NULL, NULL);
}
예제 #12
0
static GtkWidget *
get_config_widgets (const char *bdaddr, const char **uuids)
{
	WidgetInfo *info;
	NmaBtDevice *device;
	GtkWidget *vbox, *hbox;
	gboolean pan = FALSE, dun = FALSE, busy;
	GtkTreeIter iter;
	BluetoothClient *btclient;
	GtkTreeModel *btmodel;
	guint id;

	/* Don't allow configuration if NM isn't running; it just confuses people
	 * if they see the checkboxes but the configuration doesn't seem to have
	 * any visible effect since they aren't running NM/nm-applet.
	 */
	if (!nm_is_running ())
		return NULL;

	get_capabilities (bdaddr, uuids, &pan, &dun);
	if (!pan && !dun)
		return NULL;

	/* BluetoothClient setup */
	btclient = bluetooth_client_new ();
	btmodel = bluetooth_client_get_model (btclient);
	g_assert (btmodel);

	device = get_device (bdaddr);
	if (!device) {
		const char *op = NULL;
		gpointer proxy;
		char *alias;

		if (!get_device_iter (btmodel, bdaddr, &iter)) {
			g_warning ("%s: failed to retrieve device %s from gnome-bluetooth!", __func__, bdaddr);
			g_object_unref (btmodel);
			g_object_unref (btclient);
			return NULL;
		}

		gtk_tree_model_get (btmodel, &iter,
		                    BLUETOOTH_COLUMN_ALIAS, &alias,
		                    BLUETOOTH_COLUMN_PROXY, &proxy,
		                    -1);
		g_assert (proxy);

		/* At some point gnome-bluetooth switched to gdbus, so we don't know
		* if the proxy will be a DBusGProxy (dbus-glib) or a GDBusProxy (gdbus).
		*/
		if (G_IS_DBUS_PROXY (proxy))
			op = g_dbus_proxy_get_object_path (G_DBUS_PROXY (proxy));
		else if (DBUS_IS_G_PROXY (proxy))
			op = dbus_g_proxy_get_path (DBUS_G_PROXY (proxy));
		else
			g_assert_not_reached ();

		device = nma_bt_device_new (bdaddr, alias, op, pan, dun);
		g_free (alias);
		g_object_unref (proxy);

		if (!device) {
			g_warning ("%s: failed to create Bluetooth proxy object!", bdaddr);
			g_object_unref (btmodel);
			g_object_unref (btclient);
			return NULL;
		}

		add_device (device);
	}

	info = g_malloc0 (sizeof (WidgetInfo));
	info->device = g_object_ref (device);
	info->btclient = btclient;

	g_signal_connect (G_OBJECT (btclient), "notify::default-adapter",
	                  G_CALLBACK (default_adapter_changed), info);
	g_signal_connect (G_OBJECT (btclient), "notify::default-adapter-powered",
	                  G_CALLBACK (default_adapter_powered_changed), info);

	id = g_signal_connect (device, "notify::" NMA_BT_DEVICE_PAN_ENABLED,
	                       G_CALLBACK (device_pan_enabled_cb), info);
	info->sigids = g_slist_prepend (info->sigids, GUINT_TO_POINTER (id));

	id = g_signal_connect (device, "notify::" NMA_BT_DEVICE_DUN_ENABLED,
	                       G_CALLBACK (device_dun_enabled_cb), info);
	info->sigids = g_slist_prepend (info->sigids, GUINT_TO_POINTER (id));

	id = g_signal_connect (device, "notify::" NMA_BT_DEVICE_BUSY,
	                       G_CALLBACK (device_busy_cb), info);
	info->sigids = g_slist_prepend (info->sigids, GUINT_TO_POINTER (id));

	id = g_signal_connect (device, "notify::" NMA_BT_DEVICE_STATUS,
	                       G_CALLBACK (device_status_cb), info);
	info->sigids = g_slist_prepend (info->sigids, GUINT_TO_POINTER (id));

	/* UI setup */
	vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
	g_object_set_data_full (G_OBJECT (vbox), "info", info, widget_info_destroy);

	busy = nma_bt_device_get_busy (device);

	if (pan) {
		info->pan_button = gtk_check_button_new_with_label (_("Use your mobile phone as a network device (PAN/NAP)"));
		gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (info->pan_button),
		                              nma_bt_device_get_pan_enabled (device));
		info->pan_toggled_id = g_signal_connect (G_OBJECT (info->pan_button), "toggled", G_CALLBACK (pan_button_toggled), info);
		gtk_box_pack_start (GTK_BOX (vbox), info->pan_button, FALSE, TRUE, 6);
		gtk_widget_set_sensitive (info->pan_button, !busy);
	}

	if (dun) {
		info->dun_button = gtk_check_button_new_with_label (_("Access the Internet using your mobile phone (DUN)"));
		gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (info->dun_button),
		                              nma_bt_device_get_dun_enabled (device));
		info->dun_toggled_id = g_signal_connect (G_OBJECT (info->dun_button), "toggled", G_CALLBACK (dun_button_toggled), info);
		gtk_box_pack_start (GTK_BOX (vbox), info->dun_button, FALSE, TRUE, 6);
		set_dun_button_sensitive (info, !busy);
	}

	hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
	gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, TRUE, 6);

	/* Spinner's hbox */
	info->hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
	gtk_box_pack_start (GTK_BOX (hbox), info->hbox, FALSE, FALSE, 0);

	device_busy_cb (device, NULL, info);

	/* Status label */
	info->status = gtk_label_new (nma_bt_device_get_status (device));
	gtk_label_set_max_width_chars (GTK_LABEL (info->status), 80);
	gtk_label_set_line_wrap (GTK_LABEL (info->status), TRUE);
	gtk_box_pack_start (GTK_BOX (hbox), info->status, FALSE, TRUE, 6);

	default_adapter_powered_changed (G_OBJECT (info->btclient), NULL, info);

	return vbox;
}