diff options
author | Matthias Schiffer <mschiffer@universe-factory.net> | 2015-06-02 17:27:26 +0200 |
---|---|---|
committer | Matthias Schiffer <mschiffer@universe-factory.net> | 2015-06-02 17:27:26 +0200 |
commit | bb2788366187b080303e1cb6ec680024fb84a88e (patch) | |
tree | 7384c32004654d5dfbc14fb12c564b7cb2ee435a | |
parent | 4bc3bc211d2214374ad249468973c7f3c1a4df0d (diff) | |
download | pam_network_manager-bb2788366187b080303e1cb6ec680024fb84a88e.tar pam_network_manager-bb2788366187b080303e1cb6ec680024fb84a88e.zip |
Delete old connection if it exists
-rw-r--r-- | pam_network_manager_helper.c | 44 |
1 files changed, 38 insertions, 6 deletions
diff --git a/pam_network_manager_helper.c b/pam_network_manager_helper.c index 1027591..c90fa8c 100644 --- a/pam_network_manager_helper.c +++ b/pam_network_manager_helper.c @@ -205,6 +205,30 @@ static void delete_cb(UNUSED NMRemoteConnection *connection, UNUSED GError *erro 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) { DBusGConnection *dbus = NULL; NMRemoteSettings *settings = NULL; @@ -226,7 +250,13 @@ static int authenticate(const char *user, const char *pass) { if (!settings) goto end; + if (handle_old_connection(settings, &arg)) { + arg.ret = PAM_SUCCESS; + goto end; + } + con = nm_connection_new(); + setup_connection(con, user, pass); if (!nm_remote_settings_add_connection_unsaved(settings, con, add_cb, &arg)) @@ -242,16 +272,18 @@ static int authenticate(const char *user, const char *pass) { /* Error */ if (arg.con) { nm_remote_connection_delete(arg.con, delete_cb, &arg); - g_main_loop_run(arg.loop); } end: - g_object_unref(con); - - g_object_unref(settings); - dbus_g_connection_unref(dbus); - g_object_unref(arg.client); + if (con) + g_object_unref(con); + if (settings) + g_object_unref(settings); + if (dbus) + dbus_g_connection_unref(dbus); + if (arg.client) + g_object_unref(arg.client); g_main_loop_unref(arg.loop); return arg.ret; |