46
50
return nm_connection_to_hash (nm_exported_connection_get_connection (exported));
50
get_id (NMExportedConnection *exported)
52
return NM_KEYFILE_CONNECTION_GET_PRIVATE (exported)->filename;
54
string_to_gvalue (const char *str)
58
val = g_slice_new0 (GValue);
59
g_value_init (val, G_TYPE_STRING);
60
g_value_set_string (val, str);
66
copy_one_secret (gpointer key, gpointer value, gpointer user_data)
68
g_hash_table_insert ((GHashTable *) user_data,
69
g_strdup ((char *) key),
70
string_to_gvalue (value));
74
add_secrets (NMSetting *setting,
80
GHashTable *secrets = user_data;
85
if (G_VALUE_HOLDS_STRING (value)) {
86
g_hash_table_insert (secrets, g_strdup (key), string_to_gvalue (g_value_get_string (value)));
87
} else if (G_VALUE_HOLDS (value, DBUS_TYPE_G_MAP_OF_STRING)) {
88
/* Flatten the string hash by pulling its keys/values out */
89
g_hash_table_foreach (g_value_get_boxed (value), copy_one_secret, secrets);
91
g_message ("%s: unhandled secret %s type %s", __func__, key, G_VALUE_TYPE_NAME (value));
95
destroy_gvalue (gpointer data)
97
GValue *value = (GValue *) data;
99
g_value_unset (value);
100
g_slice_free (GValue, value);
104
extract_secrets (NMKeyfileConnection *exported,
105
const char *setting_name,
108
NMKeyfileConnectionPrivate *priv = NM_KEYFILE_CONNECTION_GET_PRIVATE (exported);
113
tmp = connection_from_file (priv->filename, TRUE);
115
g_set_error (error, NM_SETTINGS_ERROR, 1,
116
"%s.%d - Could not read secrets from file %s.",
117
__FILE__, __LINE__, priv->filename);
121
setting = nm_connection_get_setting_by_name (tmp, setting_name);
123
g_object_unref (tmp);
124
g_set_error (error, NM_SETTINGS_ERROR, 1,
125
"%s.%d - Could not read secrets from file %s.",
126
__FILE__, __LINE__, priv->filename);
130
/* Add the secrets from this setting to the secrets hash */
131
secrets = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, destroy_gvalue);
132
nm_setting_enumerate_values (setting, add_secrets, secrets);
134
g_object_unref (tmp);
140
get_secrets (NMExportedConnection *exported,
141
const gchar *setting_name,
143
gboolean request_new,
144
DBusGMethodInvocation *context)
146
NMConnection *connection;
147
GError *error = NULL;
148
GHashTable *settings = NULL;
149
GHashTable *secrets = NULL;
152
connection = nm_exported_connection_get_connection (exported);
153
setting = nm_connection_get_setting_by_name (connection, setting_name);
155
g_set_error (&error, NM_SETTINGS_ERROR, 1,
156
"%s.%d - Connection didn't have requested setting '%s'.",
157
__FILE__, __LINE__, setting_name);
161
/* Returned secrets are a{sa{sv}}; this is the outer a{s...} hash that
162
* will contain all the individual settings hashes.
164
settings = g_hash_table_new_full (g_str_hash, g_str_equal,
165
g_free, (GDestroyNotify) g_hash_table_destroy);
167
/* Read in a temporary connection and just extract the secrets */
168
secrets = extract_secrets (NM_KEYFILE_CONNECTION (exported), setting_name, &error);
172
g_hash_table_insert (settings, g_strdup (setting_name), secrets);
174
dbus_g_method_return (context, settings);
175
g_hash_table_destroy (settings);
179
nm_warning ("%s", error->message);
180
dbus_g_method_return_error (context, error);
181
g_error_free (error);
56
185
update (NMExportedConnection *exported,
57
GHashTable *new_settings,
186
GHashTable *new_settings,
189
NMKeyfileConnectionPrivate *priv = NM_KEYFILE_CONNECTION_GET_PRIVATE (exported);
62
192
success = NM_EXPORTED_CONNECTION_CLASS (nm_keyfile_connection_parent_class)->update (exported, new_settings, error);
64
success = write_connection (nm_exported_connection_get_connection (exported), error);
194
NMConnection *connection;
195
char *filename = NULL;
197
connection = nm_exported_connection_get_connection (exported);
198
success = write_connection (connection, &filename, error);
199
if (success && filename && strcmp (priv->filename, filename)) {
200
/* Update the filename if it changed */
201
g_free (priv->filename);
202
priv->filename = filename;
111
wrapped = connection_from_file (priv->filename);
253
wrapped = connection_from_file (priv->filename, FALSE);
257
/* if for some reason the connection didn't have a UUID, add one */
258
s_con = (NMSettingConnection *) nm_connection_get_setting (wrapped, NM_TYPE_SETTING_CONNECTION);
259
if (s_con && !s_con->uuid) {
260
GError *error = NULL;
262
s_con->uuid = nm_utils_uuid_generate ();
263
if (!write_connection (wrapped, NULL, &error)) {
264
g_warning ("Couldn't update connection %s with a UUID: (%d) %s",
265
s_con->id, error ? error->code : 0,
266
error ? error->message : "unknown");
267
g_error_free (error);
115
271
g_object_set (object, NM_EXPORTED_CONNECTION_CONNECTION, wrapped, NULL);
116
272
g_object_unref (wrapped);