ported NM plugin to upstream NetworkManager changes

splitted secrets (4031)
	using uuid in auth-dialog (4053)
This commit is contained in:
Martin Willi 2008-09-12 13:28:31 +00:00
parent 346bb576a2
commit f061d83358
3 changed files with 55 additions and 22 deletions

View File

@ -65,25 +65,57 @@ static char *lookup_password(char *name, char *service)
/**
* get the connection type
*/
static char* get_connection_type(char *id)
static char* get_connection_type(char *uuid)
{
GConfClient *client;
char *key, *str;
gboolean need_password = FALSE;
GConfClient *client = NULL;
GSList *list;
GSList *iter;
char *key, *str, *path, *found = NULL, *method = NULL;
client = gconf_client_get_default();
key = g_strdup_printf("/system/networking/connections/%s/%s/%s",
id, NM_SETTING_VPN_SETTING_NAME, "method");
str = gconf_client_get_string(client, key, NULL);
g_free(key);
list = gconf_client_all_dirs(client, "/system/networking/connections", NULL);
g_return_val_if_fail(list, NULL);
for (iter = list; iter; iter = iter->next)
{
path = (char *) iter->data;
key = g_strdup_printf("%s/%s/%s", path,
NM_SETTING_CONNECTION_SETTING_NAME,
NM_SETTING_CONNECTION_UUID);
str = gconf_client_get_string(client, key, NULL);
g_free (key);
if (str && !strcmp(str, uuid))
{
found = g_strdup(path);
}
g_free (str);
if (found)
{
break;
}
}
g_slist_foreach(list, (GFunc)g_free, NULL);
g_slist_free(list);
if (found)
{
key = g_strdup_printf ("%s/%s/%s", found,
NM_SETTING_VPN_SETTING_NAME, "method");
method = gconf_client_get_string(client, key, NULL);
g_free(found);
g_free(key);
}
g_object_unref(client);
return str;
return method;
}
int main (int argc, char *argv[])
{
static gboolean retry = FALSE;
static gchar *name = NULL, *id = NULL, *service = NULL, *keyring = NULL, *pass;
gboolean retry = FALSE;
gchar *name = NULL, *uuid = NULL, *service = NULL, *keyring = NULL, *pass;
GOptionContext *context;
GnomeProgram *program = NULL;
int exit_status = 1;
@ -92,7 +124,7 @@ int main (int argc, char *argv[])
GtkWidget *dialog;
GOptionEntry entries[] = {
{ "reprompt", 'r', 0, G_OPTION_ARG_NONE, &retry, "Reprompt for passwords", NULL},
{ "id", 'i', 0, G_OPTION_ARG_STRING, &id, "ID of VPN connection", NULL},
{ "uuid", 'u', 0, G_OPTION_ARG_STRING, &uuid, "UUID of VPN connection", NULL},
{ "name", 'n', 0, G_OPTION_ARG_STRING, &name, "Name of VPN connection", NULL},
{ "service", 's', 0, G_OPTION_ARG_STRING, &service, "VPN service type", NULL},
{ NULL }
@ -111,12 +143,12 @@ int main (int argc, char *argv[])
GNOME_PARAM_GOPTION_CONTEXT, context,
GNOME_PARAM_NONE);
if (id == NULL || name == NULL || service == NULL)
if (uuid == NULL || name == NULL || service == NULL)
{
fprintf (stderr, "Have to supply ID, name, and service\n");
fprintf (stderr, "Have to supply UUID, name, and service\n");
g_object_unref (program);
return 1;
}
}
if (strcmp(service, NM_DBUS_SERVICE_STRONGSWAN) != 0)
{
@ -126,7 +158,7 @@ int main (int argc, char *argv[])
return 1;
}
type = get_connection_type(id);
type = get_connection_type(uuid);
if (!type)
{
fprintf(stderr, "Connection lookup failed\n");

View File

@ -511,6 +511,7 @@ strongswan_plugin_ui_interface_init (NMVpnPluginUiInterface *iface_class)
/* interface implementation */
iface_class->ui_factory = ui_factory;
iface_class->get_capabilities = get_capabilities;
/* TODO: implement delete_connection to purge associated secrets */
}

View File

@ -245,7 +245,7 @@ static gboolean connect_(NMVPNPlugin *plugin, NMConnection *connection,
if (str)
{
user = identification_create_from_string(str);
str = g_hash_table_lookup(settings->data, "password");
str = g_hash_table_lookup(settings->secrets, "password");
creds->set_username_password(creds, user, str);
}
}
@ -263,7 +263,7 @@ static gboolean connect_(NMVPNPlugin *plugin, NMConnection *connection,
BUILD_FROM_FILE, str, BUILD_END);
/* try agent */
str = g_hash_table_lookup(settings->data, "agent");
str = g_hash_table_lookup(settings->secrets, "agent");
if (agent && str && cert)
{
public = cert->get_public_key(cert);
@ -284,7 +284,7 @@ static gboolean connect_(NMVPNPlugin *plugin, NMConnection *connection,
chunk_t secret, chunk;
bool pgp = FALSE;
secret.ptr = g_hash_table_lookup(settings->data, "password");
secret.ptr = g_hash_table_lookup(settings->secrets, "password");
if (secret.ptr)
{
secret.len = strlen(secret.ptr);
@ -398,14 +398,14 @@ static gboolean need_secrets(NMVPNPlugin *plugin, NMConnection *connection,
{
if (streq(method, "eap"))
{
if (g_hash_table_lookup(settings->data, "password"))
if (g_hash_table_lookup(settings->secrets, "password"))
{
return FALSE;
}
}
else if (streq(method, "agent"))
{
if (g_hash_table_lookup(settings->data, "agent"))
if (g_hash_table_lookup(settings->secrets, "agent"))
{
return FALSE;
}
@ -415,7 +415,7 @@ static gboolean need_secrets(NMVPNPlugin *plugin, NMConnection *connection,
path = g_hash_table_lookup(settings->data, "userkey");
if (path)
{
secret.ptr = g_hash_table_lookup(settings->data, "password");
secret.ptr = g_hash_table_lookup(settings->secrets, "password");
if (secret.ptr)
{
secret.len = strlen(secret.ptr);