[gnome-keyring/wip/dueno/ssh-agent: 1/4] ssh-agent: assorted minor fixes



commit a63f2bff337e4e45b9719eb3ec018241894e9f71
Author: Daiki Ueno <dueno src gnome org>
Date:   Mon Dec 11 15:22:57 2017 +0100

    ssh-agent: assorted minor fixes

 configure.ac                             |    6 +++---
 daemon/gkd-pkcs11.c                      |    1 -
 daemon/ssh-agent/gkd-ssh-agent-client.c  |    2 +-
 daemon/ssh-agent/gkd-ssh-agent-ops.c     |    5 ++++-
 daemon/ssh-agent/gkd-ssh-agent-preload.c |   18 +++++++-----------
 daemon/ssh-agent/gkd-ssh-interaction.c   |   26 ++++++++++++++++++++++++++
 daemon/ssh-agent/gkd-ssh-openssh.c       |   23 ++++++++++++++++++++++-
 7 files changed, 63 insertions(+), 18 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index d2b4b7b..8d6d544 100644
--- a/configure.ac
+++ b/configure.ac
@@ -349,12 +349,12 @@ AC_ARG_ENABLE([ssh-agent],
 
 if test "$enable_ssh_agent" != "no"; then
        AC_PATH_PROG([SSH_AGENT], [ssh-agent], [no])
-       AC_PATH_PROG([SSH_ADD], [ssh-agent], [no])
+       AC_PATH_PROG([SSH_ADD], [ssh-add], [no])
        if test "$SSH_AGENT" = "no" -o "$SSH_ADD" = "no"; then
                AC_MSG_ERROR([the ssh-agent and ssh-add commands were not found])
        fi
-       AC_DEFINE_UNQUOTED(SSH_AGENT, "$SSH_AGENT", [The path to ssh-agent]) 
-       AC_DEFINE_UNQUOTED(SSH_ADD, "$SSH_ADD", [The path to ssh-add]) 
+       AC_DEFINE_UNQUOTED(SSH_AGENT, "$SSH_AGENT", [The path to ssh-agent])
+       AC_DEFINE_UNQUOTED(SSH_ADD, "$SSH_ADD", [The path to ssh-add])
        AC_DEFINE(WITH_SSH, 1, [Whether to build SSH agent or not])
        ssh_status="yes"
 else
diff --git a/daemon/gkd-pkcs11.c b/daemon/gkd-pkcs11.c
index 8821d01..1e9db20 100644
--- a/daemon/gkd-pkcs11.c
+++ b/daemon/gkd-pkcs11.c
@@ -66,7 +66,6 @@ gkd_pkcs11_initialize (void)
        CK_FUNCTION_LIST_PTR gnome2_store;
        CK_FUNCTION_LIST_PTR xdg_store;
        CK_C_INITIALIZE_ARGS init_args;
-       gboolean ret;
        CK_RV rv;
 
        /* Secrets */
diff --git a/daemon/ssh-agent/gkd-ssh-agent-client.c b/daemon/ssh-agent/gkd-ssh-agent-client.c
index 98f2773..2cf44c4 100644
--- a/daemon/ssh-agent/gkd-ssh-agent-client.c
+++ b/daemon/ssh-agent/gkd-ssh-agent-client.c
@@ -167,7 +167,7 @@ gkd_ssh_agent_client_connect (void)
                source = g_timeout_add_seconds (5, agent_ready_timeout, &timedout);
                while (started && !ssh_agent_ready && !timedout) {
 g_message ("waiting for agent: %u", (guint)timedout);
-                       g_main_context_iteration (NULL, TRUE);
+                       g_main_context_iteration (NULL, FALSE);
                }
                g_source_remove (source);
 g_message ("waited for agent");
diff --git a/daemon/ssh-agent/gkd-ssh-agent-ops.c b/daemon/ssh-agent/gkd-ssh-agent-ops.c
index f528a41..0669d0e 100644
--- a/daemon/ssh-agent/gkd-ssh-agent-ops.c
+++ b/daemon/ssh-agent/gkd-ssh-agent-ops.c
@@ -155,6 +155,9 @@ op_request_identities (GkdSshAgentCall *call)
        egg_buffer_set_uint32 (call->resp, 5, added + g_hash_table_size (answer));
        g_hash_table_unref (answer);
 
+       /* Set the correct total size of the payload */
+       egg_buffer_set_uint32 (call->resp, 0, call->resp->len - 4);
+
        return TRUE;
 }
 
@@ -208,7 +211,7 @@ op_sign_request (GkdSshAgentCall *call)
        GBytes *key;
 
        /* If parsing the request fails, just pass through */
-       if (egg_buffer_get_byte_array (call->resp, offset, &offset, &blob, &length)) {
+       if (egg_buffer_get_byte_array (call->req, offset, &offset, &blob, &length)) {
                key = g_bytes_new (blob, length);
                preload_key_if_necessary (call->ssh_agent, key);
                g_bytes_unref (key);
diff --git a/daemon/ssh-agent/gkd-ssh-agent-preload.c b/daemon/ssh-agent/gkd-ssh-agent-preload.c
index 5595e43..395d5fb 100644
--- a/daemon/ssh-agent/gkd-ssh-agent-preload.c
+++ b/daemon/ssh-agent/gkd-ssh-agent-preload.c
@@ -123,8 +123,10 @@ file_load_inlock (EggFileTracker *tracker,
                public_key = gkd_ssh_openssh_parse_public_key (public_bytes, &comment);
                if (public_key) {
                        preload = g_new0 (Preload, 1);
-                       preload->filename = g_strdup (path);
+                       preload->filename = private_path;
+                       private_path = NULL;
                        preload->public_key = public_key;
+                       preload->private_file = private_bytes;
                        preload->comment = comment;
                        g_hash_table_replace (preloads_by_filename, preload->filename, preload);
                        g_hash_table_replace (preloads_by_key, preload->public_key, preload);
@@ -229,10 +231,8 @@ gkd_ssh_agent_preload_clear (GBytes *key)
        preload_lock_and_update ();
 
        preload = g_hash_table_lookup (preloads_by_key, key);
-       if (preload) {
-               g_bytes_unref (preload->private_file);
-               preload->private_file = NULL;
-       }
+       if (preload)
+               g_clear_pointer (&preload->private_file, (GDestroyNotify) g_bytes_unref);
 
        preload_unlock ();
 }
@@ -246,12 +246,8 @@ gkd_ssh_agent_preload_clear_all (void)
        preload_lock_and_update ();
 
        g_hash_table_iter_init (&iter, preloads_by_key);
-       while (g_hash_table_iter_next (&iter, NULL, (gpointer *)&preload)) {
-               if (preload->private_file) {
-                       g_bytes_unref (preload->private_file);
-                       preload->private_file = NULL;
-               }
-       }
+       while (g_hash_table_iter_next (&iter, NULL, (gpointer *)&preload))
+               g_clear_pointer (&preload->private_file, (GDestroyNotify) g_bytes_unref);
 
        preload_unlock ();
 }
diff --git a/daemon/ssh-agent/gkd-ssh-interaction.c b/daemon/ssh-agent/gkd-ssh-interaction.c
index f9d7470..aa3c99a 100644
--- a/daemon/ssh-agent/gkd-ssh-interaction.c
+++ b/daemon/ssh-agent/gkd-ssh-interaction.c
@@ -65,6 +65,30 @@ gkd_ssh_interaction_finalize (GObject *obj)
 }
 
 static void
+on_prompt_password (GObject *source_object,
+                   GAsyncResult *result,
+                   gpointer user_data)
+{
+       GTask *task = G_TASK (user_data);
+       GTlsPassword *password = g_task_get_task_data (task);
+       GcrPrompt *self = GCR_PROMPT (source_object);
+       GError *error = NULL;
+       const gchar *value;
+
+       value = gcr_prompt_password_finish (self, result, &error);
+       if (!value) {
+               g_task_return_error (task, error);
+               g_object_unref (task);
+               return;
+       }
+       g_tls_password_set_value (password, (const guchar *)value, strlen (value));
+       g_object_unref (self);
+
+       g_task_return_boolean (task, TRUE);
+       g_object_unref (task);
+}
+
+static void
 on_prompt_open (GObject *source_object,
                 GAsyncResult *result,
                 gpointer user_data)
@@ -101,6 +125,8 @@ on_prompt_open (GObject *source_object,
        if (g_tls_password_get_flags (password) & G_TLS_PASSWORD_RETRY)
                gcr_prompt_set_warning (prompt, _("The unlock password was incorrect"));
 
+       gcr_prompt_password_async (prompt, g_task_get_cancellable (task), on_prompt_password, g_object_ref 
(task));
+
        g_object_unref (task);
 }
 
diff --git a/daemon/ssh-agent/gkd-ssh-openssh.c b/daemon/ssh-agent/gkd-ssh-openssh.c
index 5453f8c..29e4eca 100644
--- a/daemon/ssh-agent/gkd-ssh-openssh.c
+++ b/daemon/ssh-agent/gkd-ssh-openssh.c
@@ -1,3 +1,24 @@
+/*
+ * Copyright (C) 2014 Stef Walter
+ *
+ * Gnome keyring is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * Gnome keyring is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ * Author: Stef Walter <stef thewalter net>
+ */
+
+#include "config.h"
 
 #include "gkd-ssh-openssh.h"
 
@@ -68,7 +89,7 @@ gkd_ssh_openssh_parse_public_key (GBytes *input,
        /* Decode the base64 key */
        save = state = 0;
        decoded = g_malloc (n_data * 3 / 4);
-       n_decoded = g_base64_decode_step ((gchar*)data, n_data, decoded, &state, &save);
+       n_decoded = g_base64_decode_step ((gchar*)data, at - data, decoded, &state, &save);
 
        if (!n_decoded) {
                g_free (decoded);


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