void nm_call_store_remove (NMCallStore *store, GObject *object, gpointer call_id) { GHashTable *call_ids_hash; g_return_if_fail (store != NULL); g_return_if_fail (object != NULL); g_return_if_fail (call_id != NULL); call_ids_hash = g_hash_table_lookup (store, object); if (!call_ids_hash) { nm_warning ("Trying to remove a non-existant call id."); return; } if (!g_hash_table_remove (call_ids_hash, call_id)) nm_warning ("Trying to remove a non-existant call id."); if (g_hash_table_size (call_ids_hash) == 0) { g_hash_table_remove (store, object); g_object_weak_unref (object, object_destroyed_cb, store); } }
static void get_one_connection (DBusGConnection *bus, const char *path, NMConnectionScope scope, GHashTable *table) { DBusGProxy *proxy; NMConnection *connection = NULL; const char *service; GError *error = NULL; GHashTable *settings = NULL; g_return_if_fail (bus != NULL); g_return_if_fail (path != NULL); g_return_if_fail (table != NULL); service = (scope == NM_CONNECTION_SCOPE_SYSTEM) ? NM_DBUS_SERVICE_SYSTEM_SETTINGS : NM_DBUS_SERVICE_USER_SETTINGS; proxy = dbus_g_proxy_new_for_name (bus, service, path, NM_DBUS_IFACE_SETTINGS_CONNECTION); if (!proxy) return; if (!dbus_g_proxy_call (proxy, "GetSettings", &error, G_TYPE_INVALID, DBUS_TYPE_G_MAP_OF_MAP_OF_VARIANT, &settings, G_TYPE_INVALID)) { nm_warning ("error: cannot retrieve connection: %s", error ? error->message : "(unknown)"); goto out; } connection = nm_connection_new_from_hash (settings, &error); g_hash_table_destroy (settings); if (!connection) { nm_warning ("error: invalid connection: '%s' / '%s' invalid: %d", error ? g_type_name (nm_connection_lookup_setting_type_by_quark (error->domain)) : "(unknown)", error ? error->message : "(unknown)", error ? error->code : -1); goto out; } nm_connection_set_scope (connection, scope); nm_connection_set_path (connection, path); g_hash_table_insert (table, g_strdup (path), g_object_ref (connection)); out: g_clear_error (&error); if (connection) g_object_unref (connection); g_object_unref (proxy); }
static void ip4_dns_writer (GKeyFile *file, NMSetting *setting, const char *key, const GValue *value) { GArray *array; char **list; int i, num = 0; g_return_if_fail (G_VALUE_HOLDS (value, DBUS_TYPE_G_UINT_ARRAY)); array = (GArray *) g_value_get_boxed (value); if (!array || !array->len) return; list = g_new0 (char *, array->len + 1); for (i = 0; i < array->len; i++) { char buf[INET_ADDRSTRLEN + 1]; struct in_addr addr; addr.s_addr = g_array_index (array, guint32, i); if (!inet_ntop (AF_INET, &addr, buf, sizeof (buf))) { nm_warning ("%s: error converting IP4 address 0x%X", __func__, ntohl (addr.s_addr)); } else list[num++] = g_strdup (buf); } g_key_file_set_string_list (file, nm_setting_get_name (setting), key, (const char **) list, num); g_strfreev (list); }
void nm_ap_export_to_dbus (NMAccessPoint *ap) { NMAccessPointPrivate *priv; NMDBusManager *mgr; DBusGConnection *g_connection; static guint32 counter = 0; g_return_if_fail (NM_IS_AP (ap)); priv = NM_AP_GET_PRIVATE (ap); if (priv->dbus_path) { nm_warning ("Tried to export AP %s twice.", priv->dbus_path); return; } mgr = nm_dbus_manager_get (); g_assert (mgr); g_connection = nm_dbus_manager_get_connection (mgr); g_assert (g_connection); priv->dbus_path = g_strdup_printf (NM_DBUS_PATH_ACCESS_POINT "/%d", counter++); dbus_g_connection_register_g_object (g_connection, priv->dbus_path, G_OBJECT (ap)); g_object_unref (mgr); }
static void mac_address_writer (GKeyFile *file, NMSetting *setting, const char *key, const GValue *value) { GByteArray *array; const char *setting_name = nm_setting_get_name (setting); char *mac; struct ether_addr tmp; g_return_if_fail (G_VALUE_HOLDS (value, DBUS_TYPE_G_UCHAR_ARRAY)); array = (GByteArray *) g_value_get_boxed (value); if (!array) return; if (array->len != ETH_ALEN) { nm_warning ("%s: invalid %s / %s MAC address length %d", __func__, setting_name, key, array->len); return; } memcpy (tmp.ether_addr_octet, array->data, ETH_ALEN); mac = ether_ntoa (&tmp); g_key_file_set_string (file, setting_name, key, mac); }
static void helper_failed (DBusGConnection *connection, const char *reason) { DBusGProxy *proxy; GError *err = NULL; proxy = dbus_g_proxy_new_for_name (connection, NM_DBUS_SERVICE_OPENSSH, NM_VPN_DBUS_PLUGIN_PATH, NM_VPN_DBUS_PLUGIN_INTERFACE); dbus_g_proxy_call (proxy, "SetFailure", &err, G_TYPE_STRING, reason, G_TYPE_INVALID, G_TYPE_INVALID); if (err) { nm_warning ("Could not send failure information: %s", err->message); g_error_free (err); } g_object_unref (proxy); exit (1); }
static void real_connection_secrets_updated (NMDevice *dev, NMConnection *connection, GSList *updated_settings, RequestSecretsCaller caller) { NMActRequest *req; gboolean found = FALSE; GSList *iter; if (caller == SECRETS_CALLER_PPP) { NMPPPManager *ppp_manager; NMSettingGsm *s_gsm = NULL; ppp_manager = nm_modem_get_ppp_manager (NM_MODEM (dev)); g_return_if_fail (ppp_manager != NULL); s_gsm = (NMSettingGsm *) nm_connection_get_setting (connection, NM_TYPE_SETTING_GSM); if (!s_gsm) { /* Shouldn't ever happen */ nm_ppp_manager_update_secrets (ppp_manager, nm_device_get_iface (dev), NULL, NULL, "missing GSM setting; no secrets could be found."); } else { const char *username = nm_setting_gsm_get_username (s_gsm); const char *password = nm_setting_gsm_get_password (s_gsm); nm_ppp_manager_update_secrets (ppp_manager, nm_device_get_iface (dev), username ? username : "", password ? password : "", NULL); } return; } g_return_if_fail (caller == SECRETS_CALLER_GSM); g_return_if_fail (nm_device_get_state (dev) == NM_DEVICE_STATE_NEED_AUTH); for (iter = updated_settings; iter; iter = g_slist_next (iter)) { const char *setting_name = (const char *) iter->data; if (!strcmp (setting_name, NM_SETTING_GSM_SETTING_NAME)) found = TRUE; else nm_warning ("Ignoring updated secrets for setting '%s'.", setting_name); } if (!found) return; req = nm_device_get_act_request (dev); g_assert (req); g_return_if_fail (nm_act_request_get_connection (req) == connection); nm_device_activate_schedule_stage1_device_prepare (dev); }
static void write_ip4_values (GKeyFile *file, const char *setting_name, const char *key, GPtrArray *array, guint32 tuple_len, guint32 addr1_pos, guint32 addr2_pos) { char **list = NULL; int i, j; list = g_new (char *, tuple_len); for (i = 0, j = 0; i < array->len; i++, j++) { GArray *tuple = g_ptr_array_index (array, i); gboolean success = TRUE; char *key_name; int k; memset (list, 0, tuple_len * sizeof (char *)); for (k = 0; k < tuple_len; k++) { if (k == addr1_pos || k == addr2_pos) { char buf[INET_ADDRSTRLEN + 1]; struct in_addr addr; /* IP addresses */ addr.s_addr = g_array_index (tuple, guint32, k); if (!inet_ntop (AF_INET, &addr, buf, sizeof (buf))) { nm_warning ("%s: error converting IP4 address 0x%X", __func__, ntohl (addr.s_addr)); success = FALSE; break; } else { list[k] = g_strdup (buf); } } else { /* prefix, metric */ list[k] = g_strdup_printf ("%d", g_array_index (tuple, guint32, k)); } } if (success) { key_name = g_strdup_printf ("%s%d", key, j + 1); g_key_file_set_string_list (file, setting_name, key_name, (const char **) list, tuple_len); g_free (key_name); } for (k = 0; k < tuple_len; k++) g_free (list[k]); } g_free (list); }
static void child_watch_cb (GPid pid, gint status, gpointer user_data) { NMVPNPlugin *plugin = NM_VPN_PLUGIN (user_data); NMOpensshPluginPrivate *priv = NM_OPENSSH_PLUGIN_GET_PRIVATE (plugin); NMVPNPluginFailure failure = NM_VPN_PLUGIN_FAILURE_CONNECT_FAILED; guint error = 0; gboolean good_exit = FALSE; if (WIFEXITED (status)) { error = WEXITSTATUS (status); if (error != 0) nm_warning ("sshtun exited with error code %d", error); } else if (WIFSTOPPED (status)) nm_warning ("sshtun stopped unexpectedly with signal %d", WSTOPSIG (status)); else if (WIFSIGNALED (status)) nm_warning ("sshtun died with signal %d", WTERMSIG (status)); else nm_warning ("sshtun died from an unknown cause"); sshtun_stop (priv->handle); sshtun_del (priv->handle); priv->handle = NULL; switch (error) { case 0: good_exit = TRUE; break; default: failure = NM_VPN_PLUGIN_FAILURE_CONNECT_FAILED; break; } if (!good_exit) nm_vpn_plugin_failure (plugin, failure); nm_vpn_plugin_set_state (plugin, NM_VPN_SERVICE_STATE_STOPPED); }
GtkWidget * nma_wired_dialog_new (const char *glade_file, NMClient *nm_client, NMSettingsConnectionInterface *connection, NMDevice *device) { GladeXML *xml; GtkWidget *dialog; gboolean success; xml = glade_xml_new (glade_file, "wireless_dialog", NULL); if (!xml) { applet_warning_dialog_show (_("The NetworkManager Applet could not find some required resources (the glade file was not found).")); return NULL; } dialog = glade_xml_get_widget (xml, "wireless_dialog"); if (!dialog) { nm_warning ("Couldn't find glade wireless_dialog widget."); g_object_unref (xml); return NULL; } success = dialog_init (dialog, xml, nm_client, glade_file, NM_CONNECTION (connection)); if (!success) { nm_warning ("Couldn't create wired security dialog."); gtk_widget_destroy (dialog); return NULL; } g_object_set_data_full (G_OBJECT (dialog), "connection", g_object_ref (connection), (GDestroyNotify) g_object_unref); return dialog; }
void nm_ap_set_mode (NMAccessPoint *ap, const NM80211Mode mode) { NMAccessPointPrivate *priv; g_return_if_fail (NM_IS_AP (ap)); if (mode == NM_802_11_MODE_ADHOC || mode == NM_802_11_MODE_INFRA) { priv = NM_AP_GET_PRIVATE (ap); if (priv->mode != mode) { priv->mode = mode; g_object_notify (G_OBJECT (ap), NM_AP_MODE); } } else nm_warning ("Invalid AP mode '%d'", mode); }
static gchar * ip4_address_as_string (guint32 ip) { struct in_addr tmp_addr; char buf[INET_ADDRSTRLEN+1]; memset (&buf, '\0', sizeof (buf)); tmp_addr.s_addr = ip; if (inet_ntop (AF_INET, &tmp_addr, buf, INET_ADDRSTRLEN)) { return g_strdup (buf); } else { nm_warning ("%s: error converting IP4 address 0x%X", __func__, ntohl (tmp_addr.s_addr)); return NULL; } }
int nm_call_store_foreach (NMCallStore *store, GObject *object, NMCallStoreFunc callback, gpointer user_data) { StoreForeachInfo info; g_return_val_if_fail (store != NULL, -1); g_return_val_if_fail (callback != NULL, -1); info.object = object; info.count = 0; info.callback = callback; info.user_data = user_data; if (object) { GHashTable *call_ids_hash; GSList *ids; call_ids_hash = g_hash_table_lookup (store, object); if (!call_ids_hash) { nm_warning ("Object not in store"); return -1; } /* Create a copy of the hash keys (call_ids) so that the callback is free to modify the store */ ids = get_call_ids (call_ids_hash); g_slist_foreach (ids, call_callback, &info); g_slist_free (ids); } else { GHashTable *copy; /* Create a copy of the main store so that callbacks can modify it */ copy = g_hash_table_new (NULL, NULL); g_hash_table_foreach (store, duplicate_hash, copy); g_hash_table_foreach (copy, call_all_callbacks, &info); g_hash_table_destroy (copy); } return info.count; }
static gchar * ip6_address_as_string (const struct in6_addr *ip) { char buf[INET6_ADDRSTRLEN]; memset (&buf, '\0', sizeof (buf)); if (inet_ntop (AF_INET6, ip, buf, INET6_ADDRSTRLEN)) { return g_strdup (buf); } else { int j; GString *ip6_str = g_string_new (NULL); g_string_append_printf (ip6_str, "%02X", ip->s6_addr[0]); for (j = 1; j < 16; j++) g_string_append_printf (ip6_str, " %02X", ip->s6_addr[j]); nm_warning ("%s: error converting IP6 address %s", __func__, ip6_str->str); g_string_free (ip6_str, TRUE); return NULL; } }
static void ip6_dns_writer (GKeyFile *file, NMSetting *setting, const char *key, const GValue *value) { GPtrArray *array; GByteArray *byte_array; char **list; int i, num = 0; g_return_if_fail (G_VALUE_HOLDS (value, DBUS_TYPE_G_ARRAY_OF_ARRAY_OF_UCHAR)); array = (GPtrArray *) g_value_get_boxed (value); if (!array || !array->len) return; list = g_new0 (char *, array->len + 1); for (i = 0; i < array->len; i++) { char buf[INET6_ADDRSTRLEN]; byte_array = g_ptr_array_index (array, i); if (!inet_ntop (AF_INET6, (struct in6_addr *) byte_array->data, buf, sizeof (buf))) { int j; GString *ip6_str = g_string_new (NULL); g_string_append_printf (ip6_str, "%02X", byte_array->data[0]); for (j = 1; j < 16; j++) g_string_append_printf (ip6_str, " %02X", byte_array->data[j]); nm_warning ("%s: error converting IP6 address %s", __func__, ip6_str->str); g_string_free (ip6_str, TRUE); } else list[num++] = g_strdup (buf); } g_key_file_set_string_list (file, nm_setting_get_name (setting), key, (const char **) list, num); g_strfreev (list); }
GtkWidget * nma_wireless_dialog_new (NMClient *client, NMConnection *connection, NMDevice *device, NMAccessPoint *ap) { NMAWirelessDialog *self; NMAWirelessDialogPrivate *priv; guint32 dev_caps; g_return_val_if_fail (NM_IS_CLIENT (client), NULL); g_return_val_if_fail (NM_IS_CONNECTION (connection), NULL); g_return_val_if_fail (NM_IS_DEVICE (device), NULL); g_return_val_if_fail (NM_IS_ACCESS_POINT (ap), NULL); /* Ensure device validity */ dev_caps = nm_device_get_capabilities (device); g_return_val_if_fail (dev_caps & NM_DEVICE_CAP_NM_SUPPORTED, NULL); g_return_val_if_fail (NM_IS_DEVICE_WIFI (device), NULL); self = NMA_WIRELESS_DIALOG (g_object_new (NMA_TYPE_WIRELESS_DIALOG, NULL)); if (!self) return NULL; priv = NMA_WIRELESS_DIALOG_GET_PRIVATE (self); priv->client = g_object_ref (client); priv->ap = g_object_ref (ap); if (!internal_init (self, connection, device, TRUE, FALSE)) { nm_warning ("Couldn't create wireless security dialog."); g_object_unref (self); return NULL; } return GTK_WIDGET (self); }
static void ip6_addr_writer (GKeyFile *file, NMSetting *setting, const char *key, const GValue *value) { GPtrArray *array; const char *setting_name = nm_setting_get_name (setting); int i, j; g_return_if_fail (G_VALUE_HOLDS (value, DBUS_TYPE_G_ARRAY_OF_IP6_ADDRESS)); array = (GPtrArray *) g_value_get_boxed (value); if (!array || !array->len) return; for (i = 0, j = 1; i < array->len; i++) { GValueArray *values = g_ptr_array_index (array, i); char *key_name, *ip6_addr; if (values->n_values != 3) { nm_warning ("%s: error writing IP6 address %d (address array length " "%d is not 3)", __func__, i, values->n_values); continue; } ip6_addr = ip6_array_to_addr_prefix (values); if (ip6_addr) { /* Write it out */ key_name = g_strdup_printf ("%s%d", key, j++); g_key_file_set_string (file, setting_name, key_name, ip6_addr); g_free (key_name); g_free (ip6_addr); } } }
static void stage1_prepare_done (DBusGProxy *proxy, DBusGProxyCall *call_id, gpointer user_data) { NMDevice *device = NM_DEVICE (user_data); GError *error = NULL; dbus_g_proxy_end_call (proxy, call_id, &error, G_TYPE_INVALID); if (!error) nm_device_activate_schedule_stage2_device_config (device); else { const char *required_secret = NULL; gboolean retry_secret = FALSE; if (dbus_g_error_has_name (error, MM_MODEM_ERROR_SIM_PIN)) required_secret = NM_SETTING_GSM_PIN; else if (dbus_g_error_has_name (error, MM_MODEM_ERROR_SIM_WRONG)) { clear_pin (device); required_secret = NM_SETTING_GSM_PIN; retry_secret = TRUE; } else nm_warning ("GSM modem connection failed: %s", error->message); if (required_secret) { nm_device_state_changed (device, NM_DEVICE_STATE_NEED_AUTH, NM_DEVICE_STATE_REASON_NONE); nm_act_request_get_secrets (nm_device_get_act_request (device), NM_SETTING_GSM_SETTING_NAME, retry_secret, SECRETS_CALLER_GSM, required_secret, NULL); } else nm_device_state_changed (device, NM_DEVICE_STATE_FAILED, translate_mm_error (error)); g_error_free (error); } }
GtkWidget * nma_wireless_dialog_hidden_new (NMClient *client) { NMAWirelessDialog *self; NMAWirelessDialogPrivate *priv; g_return_val_if_fail (NM_IS_CLIENT (client), NULL); self = NMA_WIRELESS_DIALOG (g_object_new (NMA_TYPE_WIRELESS_DIALOG, NULL)); if (!self) return NULL; priv = NMA_WIRELESS_DIALOG_GET_PRIVATE (self); priv->client = g_object_ref (client); if (!internal_init (self, NULL, NULL, FALSE, FALSE)) { nm_warning ("Couldn't create wireless security dialog."); g_object_unref (self); return NULL; } return GTK_WIDGET (self); }
static gboolean ip6_array_to_addr (GValueArray *values, guint32 idx, char *buf, size_t buflen, gboolean *out_is_unspec) { GByteArray *byte_array; GValue *addr_val; struct in6_addr *addr; g_return_val_if_fail (buflen >= INET6_ADDRSTRLEN, FALSE); addr_val = g_value_array_get_nth (values, idx); byte_array = g_value_get_boxed (addr_val); addr = (struct in6_addr *) byte_array->data; if (out_is_unspec && IN6_IS_ADDR_UNSPECIFIED (addr)) *out_is_unspec = TRUE; errno = 0; if (!inet_ntop (AF_INET6, addr, buf, buflen)) { GString *ip6_str = g_string_sized_new (INET6_ADDRSTRLEN + 10); /* error converting the address */ g_string_append_printf (ip6_str, "%02X", byte_array->data[0]); for (idx = 1; idx < 16; idx++) g_string_append_printf (ip6_str, " %02X", byte_array->data[idx]); nm_warning ("%s: error %d converting IP6 address %s", __func__, errno, ip6_str->str); g_string_free (ip6_str, TRUE); return FALSE; } return TRUE; }
static void send_ip4_config (DBusGConnection *connection, GHashTable *config) { DBusGProxy *proxy; GError *err = NULL; proxy = dbus_g_proxy_new_for_name (connection, NM_DBUS_SERVICE_OPENSSH, NM_VPN_DBUS_PLUGIN_PATH, NM_VPN_DBUS_PLUGIN_INTERFACE); dbus_g_proxy_call (proxy, "SetIp4Config", &err, dbus_g_type_get_map ("GHashTable", G_TYPE_STRING, G_TYPE_VALUE), config, G_TYPE_INVALID, G_TYPE_INVALID); if (err) { nm_warning ("Could not send failure information: %s", err->message); g_error_free (err); } g_object_unref (proxy); }
static gboolean nm_openssh_send_ip4_config (sshtun_handle_t handle) { DBusGConnection *connection; GError *err = NULL; GHashTable *config; GValue *val; struct in_addr temp_addr; const char *tmp; connection = dbus_g_bus_get (DBUS_BUS_SYSTEM, &err); if (!connection) return FALSE; config = g_hash_table_new (g_str_hash, g_str_equal); /* Gateway */ val = addr_to_gvalue (sshtun_get_param (handle, SSHTUN_PARAM_GW_ADDR)); if (val) g_hash_table_insert (config, NM_VPN_PLUGIN_IP4_CONFIG_GATEWAY, val); else { helper_failed (connection, "VPN Gateway"); dbus_g_connection_unref (connection); return FALSE; } /* Tunnel device */ val = str_to_gvalue (sshtun_get_param (handle, SSHTUN_PARAM_TUN_DEV), FALSE); if (val) g_hash_table_insert (config, NM_VPN_PLUGIN_IP4_CONFIG_TUNDEV, val); else { helper_failed (connection, "Tunnel Device"); dbus_g_connection_unref (connection); return FALSE; } /* IP address */ val = addr_to_gvalue (sshtun_get_param (handle, SSHTUN_PARAM_ADDR)); if (val) g_hash_table_insert (config, NM_VPN_PLUGIN_IP4_CONFIG_ADDRESS, val); else { helper_failed (connection, "IP4 Address"); dbus_g_connection_unref (connection); return FALSE; } /* PTP address */ val = addr_to_gvalue (sshtun_get_param (handle, SSHTUN_PARAM_PEER_ADDR)); if (val) g_hash_table_insert (config, NM_VPN_PLUGIN_IP4_CONFIG_PTP, val); /* Netmask */ tmp = sshtun_get_param (handle, SSHTUN_PARAM_NETMASK); if (tmp && inet_pton (AF_INET, tmp, &temp_addr) > 0) { val = uint_to_gvalue (nm_utils_ip4_netmask_to_prefix (temp_addr.s_addr)); g_hash_table_insert (config, NM_VPN_PLUGIN_IP4_CONFIG_PREFIX, val); } /* MTU */ tmp = sshtun_get_param (handle, SSHTUN_PARAM_MTU); if (tmp && strlen (tmp)) { long int mtu; errno = 0; mtu = strtol (tmp, NULL, 10); if (errno || mtu < 0 || mtu > 20000) { nm_warning ("Ignoring invalid tunnel MTU '%s'", tmp); } else { val = uint_to_gvalue ((guint32) mtu); g_hash_table_insert (config, NM_VPN_PLUGIN_IP4_CONFIG_MTU, val); } } send_ip4_config (connection, config); dbus_g_connection_unref (connection); return TRUE; }
static gboolean internal_init (NMAWirelessDialog *self, NMConnection *specific_connection, NMDevice *specific_device, gboolean auth_only, gboolean create) { NMAWirelessDialogPrivate *priv = NMA_WIRELESS_DIALOG_GET_PRIVATE (self); GtkWidget *widget; char *label, *icon_name = "network-wireless"; gboolean security_combo_focus = FALSE; gtk_window_set_position (GTK_WINDOW (self), GTK_WIN_POS_CENTER_ALWAYS); gtk_container_set_border_width (GTK_CONTAINER (self), 6); gtk_window_set_default_size (GTK_WINDOW (self), 488, -1); gtk_window_set_resizable (GTK_WINDOW (self), FALSE); gtk_dialog_set_has_separator (GTK_DIALOG (self), FALSE); if (auth_only) icon_name = "dialog-password"; else icon_name = "network-wireless"; gtk_window_set_icon_name (GTK_WINDOW (self), icon_name); widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "image1")); gtk_image_set_from_icon_name (GTK_IMAGE (widget), icon_name, GTK_ICON_SIZE_DIALOG); gtk_box_set_spacing (GTK_BOX (gtk_bin_get_child (GTK_BIN (self))), 2); widget = gtk_dialog_add_button (GTK_DIALOG (self), GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL); gtk_box_set_child_packing (GTK_BOX (GTK_DIALOG (self)->action_area), widget, FALSE, TRUE, 0, GTK_PACK_END); /* Connect/Create button */ if (create) { GtkWidget *image; widget = gtk_button_new_with_mnemonic (_("C_reate")); image = gtk_image_new_from_stock (GTK_STOCK_CONNECT, GTK_ICON_SIZE_BUTTON); gtk_button_set_image (GTK_BUTTON (widget), image); gtk_widget_show (widget); gtk_dialog_add_action_widget (GTK_DIALOG (self), widget, GTK_RESPONSE_OK); } else widget = gtk_dialog_add_button (GTK_DIALOG (self), GTK_STOCK_CONNECT, GTK_RESPONSE_OK); gtk_box_set_child_packing (GTK_BOX (GTK_DIALOG (self)->action_area), widget, FALSE, TRUE, 0, GTK_PACK_END); g_object_set (G_OBJECT (widget), "can-default", TRUE, NULL); gtk_widget_grab_default (widget); widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "hbox1")); if (!widget) { nm_warning ("Couldn't find UI wireless_dialog widget."); return FALSE; } gtk_widget_reparent (widget, gtk_bin_get_child (GTK_BIN (self))); /* If given a valid connection, hide the SSID bits and connection combo */ if (specific_connection) { widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "network_name_label")); gtk_widget_hide (widget); widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "network_name_entry")); gtk_widget_hide (widget); security_combo_focus = TRUE; } else { widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "network_name_entry")); g_signal_connect (G_OBJECT (widget), "changed", (GCallback) ssid_entry_changed, self); gtk_widget_grab_focus (widget); } gtk_dialog_set_response_sensitive (GTK_DIALOG (self), GTK_RESPONSE_OK, FALSE); if (!device_combo_init (self, specific_device)) { g_warning ("No wireless devices available."); return FALSE; } if (!connection_combo_init (self, specific_connection)) { g_warning ("Couldn't set up connection combo box."); return FALSE; } if (!security_combo_init (self)) { g_warning ("Couldn't set up wireless security combo box."); return FALSE; } if (security_combo_focus) gtk_widget_grab_focus (priv->sec_combo); security_combo_changed (priv->sec_combo, self); g_signal_connect (G_OBJECT (priv->sec_combo), "changed", G_CALLBACK (security_combo_changed), self); if (priv->connection) { char *tmp; char *esc_ssid = NULL; NMSettingWireless *s_wireless; const GByteArray *ssid; s_wireless = NM_SETTING_WIRELESS (nm_connection_get_setting (priv->connection, NM_TYPE_SETTING_WIRELESS)); ssid = s_wireless ? nm_setting_wireless_get_ssid (s_wireless) : NULL; if (ssid) esc_ssid = nm_utils_ssid_to_utf8 ((const char *) ssid->data, ssid->len); tmp = g_strdup_printf (_("Passwords or encryption keys are required to access the wireless network '%s'."), esc_ssid ? esc_ssid : "<unknown>"); gtk_window_set_title (GTK_WINDOW (self), _("Wireless Network Authentication Required")); label = g_strdup_printf ("<span size=\"larger\" weight=\"bold\">%s</span>\n\n%s", _("Authentication required by wireless network"), tmp); g_free (esc_ssid); g_free (tmp); } else if (priv->adhoc_create) { gtk_window_set_title (GTK_WINDOW (self), _("Create New Wireless Network")); label = g_strdup_printf ("<span size=\"larger\" weight=\"bold\">%s</span>\n\n%s", _("New wireless network"), _("Enter a name for the wireless network you wish to create.")); } else { gtk_window_set_title (GTK_WINDOW (self), _("Connect to Hidden Wireless Network")); label = g_strdup_printf ("<span size=\"larger\" weight=\"bold\">%s</span>\n\n%s", _("Hidden wireless network"), _("Enter the name and security details of the hidden wireless network you wish to connect to.")); } widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "caption_label")); gtk_label_set_markup (GTK_LABEL (widget), label); g_free (label); /* Re-validate from an idle handler so that widgets like file choosers * have had time to find their files. */ g_idle_add (revalidate, self); return TRUE; }
static NMCmdLine * create_dm_cmd_line (const char *iface, NMIP4Config *ip4_config, const char *pidfile, GError **error) { const char *dm_binary; NMCmdLine *cmd; GString *s; NMIP4Address *tmp; struct in_addr addr; char buf[INET_ADDRSTRLEN + 1]; char localaddr[INET_ADDRSTRLEN + 1]; dm_binary = nm_find_dnsmasq (); if (!dm_binary) { g_set_error (error, NM_DNSMASQ_MANAGER_ERROR, NM_DNSMASQ_MANAGER_ERROR_NOT_FOUND, "Could not find dnsmasq binary."); return NULL; } /* Find the IP4 address to use */ tmp = nm_ip4_config_get_address (ip4_config, 0); /* Create dnsmasq command line */ cmd = nm_cmd_line_new (); nm_cmd_line_add_string (cmd, dm_binary); nm_cmd_line_add_string (cmd, "--no-hosts"); nm_cmd_line_add_string (cmd, "--keep-in-foreground"); nm_cmd_line_add_string (cmd, "--bind-interfaces"); nm_cmd_line_add_string (cmd, "--no-poll"); nm_cmd_line_add_string (cmd, "--except-interface=lo"); s = g_string_new ("--listen-address="); addr.s_addr = nm_ip4_address_get_address (tmp); if (!inet_ntop (AF_INET, &addr, &localaddr[0], INET_ADDRSTRLEN)) { nm_warning ("%s: error converting IP4 address 0x%X", __func__, ntohl (addr.s_addr)); goto error; } g_string_append (s, localaddr); nm_cmd_line_add_string (cmd, s->str); g_string_free (s, TRUE); s = g_string_new ("--dhcp-range="); /* Add start of address range */ addr.s_addr = nm_ip4_address_get_address (tmp) + htonl (9); if (!inet_ntop (AF_INET, &addr, &buf[0], INET_ADDRSTRLEN)) { nm_warning ("%s: error converting IP4 address 0x%X", __func__, ntohl (addr.s_addr)); goto error; } g_string_append (s, buf); g_string_append_c (s, ','); /* Add end of address range */ addr.s_addr = nm_ip4_address_get_address (tmp) + htonl (99); if (!inet_ntop (AF_INET, &addr, &buf[0], INET_ADDRSTRLEN)) { nm_warning ("%s: error converting IP4 address 0x%X", __func__, ntohl (addr.s_addr)); goto error; } g_string_append (s, buf); g_string_append (s, ",60m"); nm_cmd_line_add_string (cmd, s->str); g_string_free (s, TRUE); s = g_string_new ("--dhcp-option=option:router,"); g_string_append (s, localaddr); nm_cmd_line_add_string (cmd, s->str); g_string_free (s, TRUE); nm_cmd_line_add_string (cmd, "--dhcp-lease-max=50"); s = g_string_new ("--pid-file="); g_string_append (s, pidfile); nm_cmd_line_add_string (cmd, s->str); g_string_free (s, TRUE); return cmd; error: nm_cmd_line_destroy (cmd); return NULL; }