void nm_active_connection_set_settings_connection (NMActiveConnection *self, NMSettingsConnection *connection) { NMActiveConnectionPrivate *priv; g_return_if_fail (NM_IS_ACTIVE_CONNECTION (self)); priv = NM_ACTIVE_CONNECTION_GET_PRIVATE (self); g_return_if_fail (NM_IS_SETTINGS_CONNECTION (connection)); g_return_if_fail (!priv->settings_connection); g_return_if_fail (!priv->applied_connection); /* Can't change connection after the ActiveConnection is exported over D-Bus. * * Later, we want to change the settings-connection of an activated connection. * When doing that, this changes the assumption that the settings-connection * never changes (once it's set). That has effects for NMVpnConnection and * NMActivationRequest. * For example, we'd have to cancel all pending seret requests. */ g_return_if_fail (!nm_exported_object_is_exported (NM_EXPORTED_OBJECT (self))); _set_settings_connection (self, connection); priv->applied_connection = nm_simple_connection_new_clone (NM_CONNECTION (priv->settings_connection)); nm_connection_clear_secrets (priv->applied_connection); }
static void vpn_export_get_secrets_cb (GObject *object, GAsyncResult *result, gpointer user_data) { NMConnection *tmp; GVariant *secrets; GError *error = NULL; secrets = nm_remote_connection_get_secrets_finish (NM_REMOTE_CONNECTION (object), result, &error); /* We don't really care about errors; if the user couldn't authenticate * then just let them export everything except secrets. Duplicate the * connection so that we don't let secrets sit around in the original * one. */ tmp = nm_simple_connection_new_clone (NM_CONNECTION (object)); g_assert (tmp); if (secrets) nm_connection_update_secrets (tmp, NM_SETTING_VPN_SETTING_NAME, secrets, NULL); vpn_export (tmp); g_object_unref (tmp); if (secrets) g_variant_ref (secrets); g_clear_error (&error); }
static void set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) { NMActiveConnection *self = (NMActiveConnection *) object; NMActiveConnectionPrivate *priv = NM_ACTIVE_CONNECTION_GET_PRIVATE (self); const char *tmp; NMSettingsConnection *con; switch (prop_id) { case PROP_INT_SETTINGS_CONNECTION: /* construct-only */ con = g_value_get_object (value); if (con) { _set_settings_connection (self, con); priv->applied_connection = nm_simple_connection_new_clone ((NMConnection *) priv->settings_connection); nm_connection_clear_secrets (priv->applied_connection); } break; case PROP_INT_DEVICE: /* construct-only */ nm_active_connection_set_device (self, g_value_get_object (value)); break; case PROP_INT_SUBJECT: priv->subject = g_value_dup_object (value); break; case PROP_INT_MASTER: nm_active_connection_set_master (self, g_value_get_object (value)); break; case PROP_SPECIFIC_OBJECT: tmp = g_value_get_string (value); /* NM uses "/" to mean NULL */ if (g_strcmp0 (tmp, "/") != 0) priv->specific_object = g_strdup (tmp); break; case PROP_DEFAULT: priv->is_default = !!g_value_get_boolean (value); break; case PROP_DEFAULT6: priv->is_default6 = !!g_value_get_boolean (value); break; case PROP_VPN: priv->vpn = g_value_get_boolean (value); break; case PROP_MASTER: break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; } }
static void get_secrets_cb (AppletAgent *self, GVariant *secrets, GError *error, gpointer user_data) { Request *r = user_data; /* 'secrets' shouldn't be valid if there was an error */ if (error) { g_warn_if_fail (secrets == NULL); secrets = NULL; } if (!g_cancellable_is_cancelled (r->cancellable)) { /* Save updated secrets as long as user-interaction was allowed; otherwise * we'd be saving secrets we just pulled out of the keyring which is somewhat * redundant. */ if (secrets && (r->flags != NM_SECRET_AGENT_GET_SECRETS_FLAG_NONE)) { NMConnection *dupl; GVariantIter iter; const char *setting_name; /* Copy the existing connection and update its secrets */ dupl = nm_simple_connection_new_clone (r->connection); g_variant_iter_init (&iter, secrets); while (g_variant_iter_next (&iter, "{&s@a{sv}}", (gpointer) &setting_name, NULL)) nm_connection_update_secrets (dupl, setting_name, secrets, NULL); /* And save updated secrets to the keyring */ nm_secret_agent_old_save_secrets (NM_SECRET_AGENT_OLD (self), dupl, get_save_cb, NULL); g_object_unref (dupl); } r->get_callback (NM_SECRET_AGENT_OLD (r->agent), r->connection, secrets, error, r->callback_data); } request_free (r); }
static gboolean nm_connection_editor_set_connection (NMConnectionEditor *editor, NMConnection *orig_connection, GError **error) { NMSettingConnection *s_con; const char *connection_type; const char *slave_type; gboolean success = FALSE; GSList *iter, *copy; g_return_val_if_fail (NM_IS_CONNECTION_EDITOR (editor), FALSE); g_return_val_if_fail (NM_IS_CONNECTION (orig_connection), FALSE); /* clean previous connection */ if (editor->connection) g_object_unref (editor->connection); editor->connection = nm_simple_connection_new_clone (orig_connection); editor->orig_connection = g_object_ref (orig_connection); nm_connection_editor_update_title (editor); /* Handle CA cert ignore stuff */ eap_method_ca_cert_ignore_load (editor->connection); s_con = nm_connection_get_setting_connection (editor->connection); g_assert (s_con); connection_type = nm_setting_connection_get_connection_type (s_con); if (!add_page (editor, ce_page_general_new, editor->connection, error)) goto out; if (!strcmp (connection_type, NM_SETTING_WIRED_SETTING_NAME)) { if (!add_page (editor, ce_page_ethernet_new, editor->connection, error)) goto out; if (!add_page (editor, ce_page_8021x_security_new, editor->connection, error)) goto out; if (!add_page (editor, ce_page_dcb_new, editor->connection, error)) goto out; } else if (!strcmp (connection_type, NM_SETTING_WIRELESS_SETTING_NAME)) { if (!add_page (editor, ce_page_wifi_new, editor->connection, error)) goto out; if (!add_page (editor, ce_page_wifi_security_new, editor->connection, error)) goto out; } else if (!strcmp (connection_type, NM_SETTING_VPN_SETTING_NAME)) { if (!add_page (editor, ce_page_vpn_new, editor->connection, error)) goto out; } else if (!strcmp (connection_type, NM_SETTING_IP_TUNNEL_SETTING_NAME)) { if (!add_page (editor, ce_page_ip_tunnel_new, editor->connection, error)) goto out; } else if (!strcmp (connection_type, NM_SETTING_PPPOE_SETTING_NAME)) { if (!add_page (editor, ce_page_dsl_new, editor->connection, error)) goto out; if (!add_page (editor, ce_page_ethernet_new, editor->connection, error)) goto out; if (!add_page (editor, ce_page_ppp_new, editor->connection, error)) goto out; } else if (!strcmp (connection_type, NM_SETTING_GSM_SETTING_NAME) || !strcmp (connection_type, NM_SETTING_CDMA_SETTING_NAME)) { if (!add_page (editor, ce_page_mobile_new, editor->connection, error)) goto out; if (!add_page (editor, ce_page_ppp_new, editor->connection, error)) goto out; } else if (!strcmp (connection_type, NM_SETTING_BLUETOOTH_SETTING_NAME)) { NMSettingBluetooth *s_bt = nm_connection_get_setting_bluetooth (editor->connection); const char *type = nm_setting_bluetooth_get_connection_type (s_bt); g_assert (type); if (!add_page (editor, ce_page_bluetooth_new, editor->connection, error)) goto out; if (!g_strcmp0 (type, "dun")) { if (!add_page (editor, ce_page_mobile_new, editor->connection, error)) goto out; if (!add_page (editor, ce_page_ppp_new, editor->connection, error)) goto out; } } else if (!strcmp (connection_type, NM_SETTING_INFINIBAND_SETTING_NAME)) { if (!add_page (editor, ce_page_infiniband_new, editor->connection, error)) goto out; } else if (!strcmp (connection_type, NM_SETTING_BOND_SETTING_NAME)) { if (!add_page (editor, ce_page_bond_new, editor->connection, error)) goto out; } else if (!strcmp (connection_type, NM_SETTING_TEAM_SETTING_NAME)) { if (!add_page (editor, ce_page_team_new, editor->connection, error)) goto out; } else if (!strcmp (connection_type, NM_SETTING_BRIDGE_SETTING_NAME)) { if (!add_page (editor, ce_page_bridge_new, editor->connection, error)) goto out; } else if (!strcmp (connection_type, NM_SETTING_VLAN_SETTING_NAME)) { if (!add_page (editor, ce_page_vlan_new, editor->connection, error)) goto out; } else { g_warning ("Unhandled setting type '%s'", connection_type); } slave_type = nm_setting_connection_get_slave_type (s_con); if (!g_strcmp0 (slave_type, NM_SETTING_TEAM_SETTING_NAME)) { if (!add_page (editor, ce_page_team_port_new, editor->connection, error)) goto out; } else if (!g_strcmp0 (slave_type, NM_SETTING_BRIDGE_SETTING_NAME)) { if (!add_page (editor, ce_page_bridge_port_new, editor->connection, error)) goto out; } if ( nm_connection_get_setting_ip4_config (editor->connection) && !add_page (editor, ce_page_ip4_new, editor->connection, error)) goto out; if ( nm_connection_get_setting_ip6_config (editor->connection) && !add_page (editor, ce_page_ip6_new, editor->connection, error)) goto out; /* After all pages are created, then kick off secrets requests that any * the pages may need to make; if they don't need any secrets, then let * them finish initialization. The list might get modified during the loop * which is why copy the list here. */ copy = g_slist_copy (editor->initializing_pages); for (iter = copy; iter; iter = g_slist_next (iter)) { CEPage *page = CE_PAGE (iter->data); const char *setting_name = g_object_get_data (G_OBJECT (page), SECRETS_TAG); if (!setting_name) { /* page doesn't need any secrets */ ce_page_complete_init (page, NULL, NULL, NULL); } else if (!NM_IS_REMOTE_CONNECTION (editor->orig_connection)) { /* We want to get secrets using ->orig_connection, since that's the * remote connection which can actually respond to secrets requests. * ->connection is a plain NMConnection copy of ->orig_connection * which is what gets changed when users modify anything. But when * creating or importing, ->orig_connection will be an NMConnection * since the new connection hasn't been added to NetworkManager yet. * So basically, skip requesting secrets if the connection can't * handle a secrets request. */ ce_page_complete_init (page, setting_name, NULL, NULL); } else { /* Page wants secrets, get them */ get_secrets_for_page (editor, page, setting_name); } g_object_set_data (G_OBJECT (page), SECRETS_TAG, NULL); } g_slist_free (copy); /* set the UI */ recheck_initialization (editor); success = TRUE; out: return success; }