[network-manager-vpnc/dcbw/need-secrets: 3/3] auth-dialog: parse hints and display server messages



commit 504cc2def78223d13d4f35a7ae26a32011255a57
Author: Dan Williams <dcbw redhat com>
Date:   Fri Jun 28 12:36:54 2013 -0500

    auth-dialog: parse hints and display server messages

 auth-dialog/main.c      |   33 ++++++++++++++++++++++++++++++---
 nm-vpnc-service.name.in |    1 +
 2 files changed, 31 insertions(+), 3 deletions(-)
---
diff --git a/auth-dialog/main.c b/auth-dialog/main.c
index 178facf..edf5c64 100644
--- a/auth-dialog/main.c
+++ b/auth-dialog/main.c
@@ -115,12 +115,15 @@ keyfile_print_stdout (GKeyFile *keyfile)
        g_free (data);
 }
 
+#define VPN_MSG_TAG "x-vpn-message:"
+
 static gboolean
 get_secrets (const char *vpn_uuid,
              const char *vpn_name,
              gboolean retry,
              gboolean allow_interaction,
              gboolean external_ui_mode,
+             const char **hints,
              const char *in_upw,
              char **out_upw,
              NMSettingSecretFlags upw_flags,
@@ -130,9 +133,10 @@ get_secrets (const char *vpn_uuid,
 {
        NMAVpnPasswordDialog *dialog;
        char *upw = NULL, *gpw = NULL;
-       char *prompt;
+       char *prompt = NULL;
        gboolean success = FALSE;
        gboolean need_upw = TRUE, need_gpw = TRUE;
+       const char **iter;
 
        g_return_val_if_fail (vpn_uuid != NULL, FALSE);
        g_return_val_if_fail (vpn_name != NULL, FALSE);
@@ -192,7 +196,26 @@ get_secrets (const char *vpn_uuid,
                        return TRUE;
        }
 
-       prompt = g_strdup_printf (_("You need to authenticate to access the Virtual Private Network '%s'."), 
vpn_name);
+       /* Process hints; if hints are given only ask for what they want */
+       if (hints && g_strv_length ((char **) hints)) {
+               need_upw = FALSE;
+               need_gpw = FALSE;
+               for (iter = hints; iter && *iter; iter++) {
+                       if (!prompt && strncmp (*iter, VPN_MSG_TAG, strlen (VPN_MSG_TAG)) == 0)
+                               prompt = g_strdup (*iter + strlen (VPN_MSG_TAG));
+                       else if (strcmp (*iter, NM_VPNC_KEY_XAUTH_PASSWORD) == 0)
+                               need_upw = TRUE;
+                       else if (strcmp (*iter, NM_VPNC_KEY_SECRET) == 0)
+                               need_gpw = TRUE;
+               }
+
+               /* Don't ask if both passwords are unused */
+               if (!need_upw && !need_gpw)
+                       return TRUE;
+       }
+
+       if (!prompt)
+               prompt = g_strdup_printf (_("You need to authenticate to access the Virtual Private Network 
'%s'."), vpn_name);
 
        if (external_ui_mode) {
                GKeyFile *keyfile;
@@ -329,6 +352,7 @@ main (int argc, char *argv[])
        char *vpn_name = NULL, *vpn_uuid = NULL, *vpn_service = NULL;
        GHashTable *data = NULL, *secrets = NULL;
        char *password = NULL, *group_password = NULL;
+       char **hints = NULL;
        NMSettingSecretFlags upw_flags = NM_SETTING_SECRET_FLAG_NONE;
        NMSettingSecretFlags gpw_flags = NM_SETTING_SECRET_FLAG_NONE;
        GError *error = NULL;
@@ -340,6 +364,7 @@ main (int argc, char *argv[])
                        { "service", 's', 0, G_OPTION_ARG_STRING, &vpn_service, "VPN service type", NULL},
                        { "allow-interaction", 'i', 0, G_OPTION_ARG_NONE, &allow_interaction, "Allow user 
interaction", NULL},
                        { "external-ui-mode", 0, 0, G_OPTION_ARG_NONE, &external_ui_mode, "External UI mode", 
NULL},
+                       { "hint", 't', 0, G_OPTION_ARG_STRING_ARRAY, &hints, "Hints from the VPN plugin", 
NULL},
                        { NULL }
                };
 
@@ -379,7 +404,7 @@ main (int argc, char *argv[])
        gpw_flags = get_pw_flags (data, NM_VPNC_KEY_SECRET, NM_VPNC_KEY_SECRET_TYPE);
 
        if (!get_secrets (vpn_uuid, vpn_name,
-                         retry, allow_interaction, external_ui_mode,
+                         retry, allow_interaction, external_ui_mode, (const char **) hints,
                          g_hash_table_lookup (secrets, NM_VPNC_KEY_XAUTH_PASSWORD),
                          &password,
                          upw_flags,
@@ -410,5 +435,7 @@ main (int argc, char *argv[])
                g_hash_table_unref (data);
        if (secrets)
                g_hash_table_unref (secrets);
+       if (hints)
+               g_strfreev (hints);
        return 0;
 }
diff --git a/nm-vpnc-service.name.in b/nm-vpnc-service.name.in
index ad40005..ec15b94 100644
--- a/nm-vpnc-service.name.in
+++ b/nm-vpnc-service.name.in
@@ -7,3 +7,4 @@ program= LIBEXECDIR@/nm-vpnc-service
 auth-dialog= LIBEXECDIR@/nm-vpnc-auth-dialog
 properties= PLUGINDIR@/libnm-vpnc-properties
 supports-external-ui-mode=true
+supports-hints=true


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]