Delete old connection if it exists
This commit is contained in:
parent
4bc3bc211d
commit
bb27883661
1 changed files with 38 additions and 6 deletions
|
@ -205,6 +205,30 @@ static void delete_cb(UNUSED NMRemoteConnection *connection, UNUSED GError *erro
|
||||||
g_main_loop_quit(arg->loop);
|
g_main_loop_quit(arg->loop);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void read_cb(UNUSED NMRemoteSettings *settings, gpointer user_data) {
|
||||||
|
cb_arg *arg = user_data;
|
||||||
|
g_main_loop_quit(arg->loop);
|
||||||
|
}
|
||||||
|
|
||||||
|
static gboolean handle_old_connection(NMRemoteSettings *settings, cb_arg *arg) {
|
||||||
|
NMRemoteConnection *con = NULL;
|
||||||
|
|
||||||
|
g_signal_connect(settings, NM_REMOTE_SETTINGS_CONNECTIONS_READ,
|
||||||
|
G_CALLBACK(read_cb), arg);
|
||||||
|
|
||||||
|
g_main_loop_run(arg->loop);
|
||||||
|
|
||||||
|
con = nm_remote_settings_get_connection_by_uuid(settings, CONNECTION_UUID);
|
||||||
|
if (!con)
|
||||||
|
goto end;
|
||||||
|
|
||||||
|
nm_remote_connection_delete(con, delete_cb, arg);
|
||||||
|
g_main_loop_run(arg->loop);
|
||||||
|
|
||||||
|
end:
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
static int authenticate(const char *user, const char *pass) {
|
static int authenticate(const char *user, const char *pass) {
|
||||||
DBusGConnection *dbus = NULL;
|
DBusGConnection *dbus = NULL;
|
||||||
NMRemoteSettings *settings = NULL;
|
NMRemoteSettings *settings = NULL;
|
||||||
|
@ -226,7 +250,13 @@ static int authenticate(const char *user, const char *pass) {
|
||||||
if (!settings)
|
if (!settings)
|
||||||
goto end;
|
goto end;
|
||||||
|
|
||||||
|
if (handle_old_connection(settings, &arg)) {
|
||||||
|
arg.ret = PAM_SUCCESS;
|
||||||
|
goto end;
|
||||||
|
}
|
||||||
|
|
||||||
con = nm_connection_new();
|
con = nm_connection_new();
|
||||||
|
|
||||||
setup_connection(con, user, pass);
|
setup_connection(con, user, pass);
|
||||||
|
|
||||||
if (!nm_remote_settings_add_connection_unsaved(settings, con, add_cb, &arg))
|
if (!nm_remote_settings_add_connection_unsaved(settings, con, add_cb, &arg))
|
||||||
|
@ -242,15 +272,17 @@ static int authenticate(const char *user, const char *pass) {
|
||||||
/* Error */
|
/* Error */
|
||||||
if (arg.con) {
|
if (arg.con) {
|
||||||
nm_remote_connection_delete(arg.con, delete_cb, &arg);
|
nm_remote_connection_delete(arg.con, delete_cb, &arg);
|
||||||
|
|
||||||
g_main_loop_run(arg.loop);
|
g_main_loop_run(arg.loop);
|
||||||
}
|
}
|
||||||
|
|
||||||
end:
|
end:
|
||||||
|
if (con)
|
||||||
g_object_unref(con);
|
g_object_unref(con);
|
||||||
|
if (settings)
|
||||||
g_object_unref(settings);
|
g_object_unref(settings);
|
||||||
|
if (dbus)
|
||||||
dbus_g_connection_unref(dbus);
|
dbus_g_connection_unref(dbus);
|
||||||
|
if (arg.client)
|
||||||
g_object_unref(arg.client);
|
g_object_unref(arg.client);
|
||||||
g_main_loop_unref(arg.loop);
|
g_main_loop_unref(arg.loop);
|
||||||
|
|
||||||
|
|
Reference in a new issue