[libgit2-glib] Add ssh credential schemes
- From: Jesse van den Kieboom <jessevdk src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libgit2-glib] Add ssh credential schemes
- Date: Wed, 25 Jun 2014 09:46:01 +0000 (UTC)
commit 886c1353dd732046892f7abd985997e79805e11b
Author: Jesse van den Kieboom <jessevdk gnome org>
Date: Wed Jun 25 11:45:27 2014 +0200
Add ssh credential schemes
configure.ac | 1 +
libgit2-glib-1.0.pc.in | 2 +-
libgit2-glib/Makefile.am | 5 +
libgit2-glib/ggit-cred-ssh-interactive.c | 346 +++++++++++++++++++++++++++
libgit2-glib/ggit-cred-ssh-interactive.h | 105 ++++++++
libgit2-glib/ggit-cred-ssh-key-from-agent.c | 183 ++++++++++++++
libgit2-glib/ggit-cred-ssh-key-from-agent.h | 67 +++++
libgit2-glib/ggit-types.h | 21 ++
8 files changed, 729 insertions(+), 1 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 1e5e098..519f620 100644
--- a/configure.ac
+++ b/configure.ac
@@ -64,6 +64,7 @@ PKG_CHECK_MODULES(LIBGIT2_GLIB, [
gio-2.0 >= $GLIB_REQUIRED
libgit2 >= $GIT2_REQUIRED
gobject-introspection-1.0 >= $INTROSPECTION_REQUIRED
+ libssh2
])
GOBJECT_INTROSPECTION_REQUIRE($INTROSPECTION_REQUIRED)
diff --git a/libgit2-glib-1.0.pc.in b/libgit2-glib-1.0.pc.in
index 41c193e..2b3696e 100644
--- a/libgit2-glib-1.0.pc.in
+++ b/libgit2-glib-1.0.pc.in
@@ -7,5 +7,5 @@ Name: libgit2-glib
Description: libgit2-glib, a a glib wrapper library around the libgit2 git access library.
Requires: libgit2 >= @GIT2_REQUIRED@, glib-2.0 >= @GLIB_REQUIRED@, gobject-2.0 >= @GLIB_REQUIRED@, gio-2.0
= @GLIB_REQUIRED@, gobject-introspection-1.0 >= @INTROSPECTION_REQUIRED@
Version: @VERSION@
-Cflags: -I${includedir}/libgit2-glib-1.0
+Cflags: -I${includedir}/libgit2-glib-1.0 -DGIT_SSH=1
Libs: -L${libdir} -lgit2-glib-1.0
diff --git a/libgit2-glib/Makefile.am b/libgit2-glib/Makefile.am
index c9c7861..977f77f 100644
--- a/libgit2-glib/Makefile.am
+++ b/libgit2-glib/Makefile.am
@@ -6,6 +6,7 @@ AM_CPPFLAGS = \
$(LIBGIT2_GLIB_CFLAGS) \
$(WARN_CFLAGS) \
$(DISABLE_DEPRECATED_CFLAGS) \
+ -DGIT_SSH=1 \
-DDATADIR=\""$(datadir)"\" \
-DLIBDIR=\""$(libdir)"\"
@@ -30,7 +31,9 @@ INST_H_FILES = \
ggit-config.h \
ggit-config-entry.h \
ggit-cred.h \
+ ggit-cred-ssh-interactive.h \
ggit-cred-plaintext.h \
+ ggit-cred-ssh-key-from-agent.h \
ggit-diff.h \
ggit-diff-delta.h \
ggit-diff-file.h \
@@ -92,6 +95,8 @@ C_FILES = \
ggit-convert.c \
ggit-cred.c \
ggit-cred-plaintext.c \
+ ggit-cred-ssh-interactive.c \
+ ggit-cred-ssh-key-from-agent.c \
ggit-diff.c \
ggit-diff-delta.c \
ggit-diff-file.c \
diff --git a/libgit2-glib/ggit-cred-ssh-interactive.c b/libgit2-glib/ggit-cred-ssh-interactive.c
new file mode 100644
index 0000000..ac5dcea
--- /dev/null
+++ b/libgit2-glib/ggit-cred-ssh-interactive.c
@@ -0,0 +1,346 @@
+/*
+ * ggit-cred-ssh-interactive.c
+ * This file is part of libgit2-glib
+ *
+ * Copyright (C) 2014 - Jesse van den Kieboom
+ *
+ * libgit2-glib is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * libgit2-glib 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with libgit2-glib. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <git2.h>
+#include <gio/gio.h>
+
+#include "ggit-error.h"
+#include "ggit-cred-ssh-interactive.h"
+
+struct _GgitCredSshInteractivePrompt
+{
+ gint ref_count;
+ gchar *name;
+ gchar *text;
+ gchar *instruction;
+ gchar *response;
+ gboolean is_masked;
+};
+
+struct _GgitCredSshInteractivePrivate
+{
+ gchar *username;
+};
+
+enum
+{
+ PROP_0,
+ PROP_USERNAME
+};
+
+G_DEFINE_BOXED_TYPE (GgitCredSshInteractivePrompt,
+ ggit_cred_ssh_interactive_prompt,
+ ggit_cred_ssh_interactive_prompt_ref,
+ ggit_cred_ssh_interactive_prompt_unref);
+
+static void ggit_cred_ssh_interactive_initable_iface_init (GInitableIface *iface);
+
+G_DEFINE_TYPE_EXTENDED (GgitCredSshInteractive,
+ ggit_cred_ssh_interactive,
+ GGIT_TYPE_CRED,
+ 0,
+ G_IMPLEMENT_INTERFACE (G_TYPE_INITABLE,
+ ggit_cred_ssh_interactive_initable_iface_init))
+
+static void
+ggit_cred_ssh_interactive_finalize (GObject *object)
+{
+ GgitCredSshInteractivePrivate *priv = GGIT_CRED_SSH_INTERACTIVE (object)->priv;
+
+ g_free (priv->username);
+
+ G_OBJECT_CLASS (ggit_cred_ssh_interactive_parent_class)->finalize (object);
+}
+
+static void
+ggit_cred_ssh_interactive_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ GgitCredSshInteractivePrivate *priv = GGIT_CRED_SSH_INTERACTIVE (object)->priv;
+
+ switch (prop_id)
+ {
+ case PROP_USERNAME:
+ g_value_set_string (value, priv->username);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
+ggit_cred_ssh_interactive_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ GgitCredSshInteractivePrivate *priv = GGIT_CRED_SSH_INTERACTIVE (object)->priv;
+
+ switch (prop_id)
+ {
+ case PROP_USERNAME:
+ priv->username = g_value_dup_string (value);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
+ggit_cred_ssh_interactive_class_init (GgitCredSshInteractiveClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ object_class->finalize = ggit_cred_ssh_interactive_finalize;
+ object_class->get_property = ggit_cred_ssh_interactive_get_property;
+ object_class->set_property = ggit_cred_ssh_interactive_set_property;
+
+ g_object_class_install_property (object_class,
+ PROP_USERNAME,
+ g_param_spec_string ("username",
+ "user name",
+ "The user name",
+ NULL,
+ G_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT_ONLY |
+ G_PARAM_STATIC_STRINGS));
+
+ g_type_class_add_private (object_class, sizeof (GgitCredSshInteractivePrivate));
+}
+
+static void
+ggit_cred_ssh_interactive_init (GgitCredSshInteractive *cred)
+{
+ cred->priv = G_TYPE_INSTANCE_GET_PRIVATE(cred,
+ GGIT_TYPE_CRED_SSH_INTERACTIVE,
+ GgitCredSshInteractivePrivate);
+}
+
+static void
+callback_wrapper (const char *name,
+ int name_len,
+ const char *instruction,
+ int instruction_len,
+ int num_prompts,
+ const LIBSSH2_USERAUTH_KBDINT_PROMPT *prompts,
+ LIBSSH2_USERAUTH_KBDINT_RESPONSE *responses,
+ void **abstract)
+{
+ GgitCredSshInteractive *interactive;
+ GgitCredSshInteractivePrompt **wprompts;
+ gint i;
+ gchar *wname;
+ gchar *winstruction;
+
+ interactive = *abstract;
+
+ if (GGIT_CRED_SSH_INTERACTIVE_GET_CLASS (interactive)->prompt == NULL)
+ {
+ return;
+ }
+
+ wprompts = g_new (GgitCredSshInteractivePrompt *, num_prompts);
+
+ wname = g_strndup (name, name_len);
+ winstruction = g_strndup (instruction, instruction_len);
+
+ for (i = 0; i < num_prompts; i++)
+ {
+ gchar *text;
+
+ text = g_strndup (prompts[i].text, prompts[i].length);
+
+ wprompts[i] = ggit_cred_ssh_interactive_prompt_new (wname,
+ winstruction,
+ text,
+ prompts[i].echo == 0);
+
+ g_free (text);
+ }
+
+ g_free (wname);
+ g_free (winstruction);
+
+ GGIT_CRED_SSH_INTERACTIVE_GET_CLASS (interactive)->prompt (wprompts, num_prompts);
+
+ for (i = 0; i < num_prompts; i++)
+ {
+ responses[i].text = g_strdup (wprompts[i]->response);
+ responses[i].length = strlen (wprompts[i]->response);
+
+ ggit_cred_ssh_interactive_prompt_unref (wprompts[i]);
+ }
+}
+
+static gboolean
+ggit_cred_ssh_interactive_initable_init (GInitable *initable,
+ GCancellable *cancellable,
+ GError **error)
+{
+ GgitCredSshInteractivePrivate *priv;
+ git_cred *cred;
+ gint ret;
+
+ if (cancellable != NULL)
+ {
+ g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
+ "Cancellable initialization not supported");
+ return FALSE;
+ }
+
+ priv = GGIT_CRED_SSH_INTERACTIVE (initable)->priv;
+
+ ret = git_cred_ssh_interactive_new (&cred, priv->username,
+ callback_wrapper,
+ initable);
+
+ if (ret != GIT_OK)
+ {
+ _ggit_error_set (error, ret);
+ return FALSE;
+ }
+
+ _ggit_native_set (initable,
+ cred,
+ (GDestroyNotify)cred->free);
+
+ return TRUE;
+}
+
+static void
+ggit_cred_ssh_interactive_initable_iface_init (GInitableIface *iface)
+{
+ iface->init = ggit_cred_ssh_interactive_initable_init;
+}
+
+GgitCredSshInteractive *
+ggit_cred_ssh_interactive_new (const gchar *username,
+ GError **error)
+{
+ return g_initable_new (GGIT_TYPE_CRED_SSH_INTERACTIVE,
+ NULL, error,
+ "username", username,
+ NULL);
+}
+
+const gchar *
+ggit_cred_ssh_interactive_get_username (GgitCredSshInteractive *cred)
+{
+ g_return_val_if_fail (GGIT_IS_CRED_SSH_INTERACTIVE (cred), NULL);
+
+ return cred->priv->username;
+}
+
+GgitCredSshInteractivePrompt *
+ggit_cred_ssh_interactive_prompt_new (const gchar *name,
+ const gchar *text,
+ const gchar *instruction,
+ gboolean is_masked)
+{
+ GgitCredSshInteractivePrompt *ret;
+
+ ret = g_slice_new0 (GgitCredSshInteractivePrompt);
+ ret->ref_count = 1;
+
+ ret->name = g_strdup (name);
+ ret->instruction = g_strdup (instruction);
+ ret->text = g_strdup (text);
+
+ ret->is_masked = is_masked;
+
+ return ret;
+}
+
+GgitCredSshInteractivePrompt *
+ggit_cred_ssh_interactive_prompt_ref (GgitCredSshInteractivePrompt *prompt)
+{
+ g_atomic_int_inc (&prompt->ref_count);
+ return prompt;
+}
+
+void
+ggit_cred_ssh_interactive_prompt_unref (GgitCredSshInteractivePrompt *prompt)
+{
+ if (g_atomic_int_dec_and_test (&prompt->ref_count))
+ {
+ g_free (prompt->name);
+ g_free (prompt->instruction);
+ g_free (prompt->text);
+ g_free (prompt->response);
+
+ g_slice_free (GgitCredSshInteractivePrompt, prompt);
+ }
+}
+
+const gchar *
+ggit_cred_ssh_interactive_prompt_get_name (GgitCredSshInteractivePrompt *prompt)
+{
+ g_return_val_if_fail (prompt != NULL, NULL);
+
+ return prompt->name;
+}
+
+const gchar *
+ggit_cred_ssh_interactive_prompt_get_instruction (GgitCredSshInteractivePrompt *prompt)
+{
+ g_return_val_if_fail (prompt != NULL, NULL);
+
+ return prompt->instruction;
+}
+
+const gchar *
+ggit_cred_ssh_interactive_prompt_get_text (GgitCredSshInteractivePrompt *prompt)
+{
+ g_return_val_if_fail (prompt != NULL, NULL);
+
+ return prompt->text;
+}
+
+gboolean
+ggit_cred_ssh_interactive_prompt_is_masked (GgitCredSshInteractivePrompt *prompt)
+{
+ g_return_val_if_fail (prompt != NULL, FALSE);
+
+ return prompt->is_masked;
+}
+
+void
+ggit_cred_ssh_interactive_prompt_set_response (GgitCredSshInteractivePrompt *prompt,
+ const gchar *response)
+{
+ g_return_if_fail (prompt != NULL);
+
+ g_free (prompt->response);
+ prompt->response = g_strdup (response);
+}
+
+const gchar *
+ggit_cred_ssh_interactive_prompt_get_response (GgitCredSshInteractivePrompt *prompt)
+{
+ g_return_val_if_fail (prompt != NULL, NULL);
+
+ return prompt->response;
+}
+
+/* ex:set ts=8 noet: */
diff --git a/libgit2-glib/ggit-cred-ssh-interactive.h b/libgit2-glib/ggit-cred-ssh-interactive.h
new file mode 100644
index 0000000..32f414e
--- /dev/null
+++ b/libgit2-glib/ggit-cred-ssh-interactive.h
@@ -0,0 +1,105 @@
+/*
+ * ggit-cred-ssh-interactive.h
+ * This file is part of libgit2-glib
+ *
+ * Copyright (C) 2014 - Jesse van den Kieboom
+ *
+ * libgit2-glib is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * libgit2-glib 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with libgit2-glib. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#ifndef __GGIT_CRED_SSH_INTERACTIVE_H__
+#define __GGIT_CRED_SSH_INTERACTIVE_H__
+
+#include <glib-object.h>
+#include <libgit2-glib/ggit-cred.h>
+
+G_BEGIN_DECLS
+
+#define GGIT_TYPE_CRED_SSH_INTERACTIVE (ggit_cred_ssh_interactive_get_type ())
+#define GGIT_CRED_SSH_INTERACTIVE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj),
GGIT_TYPE_CRED_SSH_INTERACTIVE, GgitCredSshInteractive))
+#define GGIT_CRED_SSH_INTERACTIVE_CONST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj),
GGIT_TYPE_CRED_SSH_INTERACTIVE, GgitCredSshInteractive const))
+#define GGIT_CRED_SSH_INTERACTIVE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass),
GGIT_TYPE_CRED_SSH_INTERACTIVE, GgitCredSshInteractiveClass))
+#define GGIT_IS_CRED_SSH_INTERACTIVE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj),
GGIT_TYPE_CRED_SSH_INTERACTIVE))
+#define GGIT_IS_CRED_SSH_INTERACTIVE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass),
GGIT_TYPE_CRED_SSH_INTERACTIVE))
+#define GGIT_CRED_SSH_INTERACTIVE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj),
GGIT_TYPE_CRED_SSH_INTERACTIVE, GgitCredSshInteractiveClass))
+
+typedef struct _GgitCredSshInteractiveClass GgitCredSshInteractiveClass;
+typedef struct _GgitCredSshInteractivePrivate GgitCredSshInteractivePrivate;
+
+struct _GgitCredSshInteractive
+{
+ /*< private >*/
+ GgitCred parent;
+
+ GgitCredSshInteractivePrivate *priv;
+};
+
+struct _GgitCredSshInteractiveClass
+{
+ /*< private >*/
+ GgitCredClass parent_class;
+
+ void (*prompt) (GgitCredSshInteractivePrompt **prompts,
+ gsize num_prompts);
+};
+
+GType ggit_cred_ssh_interactive_get_type (void) G_GNUC_CONST;
+
+GgitCredSshInteractive *
+ ggit_cred_ssh_interactive_new (const gchar *username,
+ GError **error);
+
+const gchar *ggit_cred_ssh_interactive_get_username (GgitCredSshInteractive *cred);
+
+GType ggit_cred_ssh_interactive_prompt_get_type (void) G_GNUC_CONST;
+
+GgitCredSshInteractivePrompt *
+ ggit_cred_ssh_interactive_prompt_new
+ (const gchar *name,
+ const gchar *instruction,
+ const gchar *text,
+ gboolean is_masked);
+
+GgitCredSshInteractivePrompt *
+ ggit_cred_ssh_interactive_prompt_ref
+ (GgitCredSshInteractivePrompt *prompt);
+
+void ggit_cred_ssh_interactive_prompt_unref
+ (GgitCredSshInteractivePrompt *prompt);
+
+const gchar *ggit_cred_ssh_interactive_prompt_get_name
+ (GgitCredSshInteractivePrompt *prompt);
+
+const gchar *ggit_cred_ssh_interactive_prompt_get_text
+ (GgitCredSshInteractivePrompt *prompt);
+
+const gchar *ggit_cred_ssh_interactive_prompt_get_instruction
+ (GgitCredSshInteractivePrompt *prompt);
+
+gboolean ggit_cred_ssh_interactive_prompt_is_masked
+ (GgitCredSshInteractivePrompt *prompt);
+
+void ggit_cred_ssh_interactive_prompt_set_response
+ (GgitCredSshInteractivePrompt *prompt,
+ const gchar *response);
+
+const gchar *ggit_cred_ssh_interactive_prompt_get_response
+ (GgitCredSshInteractivePrompt *prompt);
+
+G_END_DECLS
+
+#endif /* __GGIT_CRED_SSH_INTERACTIVE_H__ */
+
+/* ex:set ts=8 noet: */
diff --git a/libgit2-glib/ggit-cred-ssh-key-from-agent.c b/libgit2-glib/ggit-cred-ssh-key-from-agent.c
new file mode 100644
index 0000000..10b4dc5
--- /dev/null
+++ b/libgit2-glib/ggit-cred-ssh-key-from-agent.c
@@ -0,0 +1,183 @@
+/*
+ * ggit-cred-ssh-key-from-agent.c
+ * This file is part of libgit2-glib
+ *
+ * Copyright (C) 2014 - Jesse van den Kieboom
+ *
+ * libgit2-glib is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * libgit2-glib 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with libgit2-glib. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <git2.h>
+#include <gio/gio.h>
+
+#include "ggit-error.h"
+#include "ggit-cred-ssh-key-from-agent.h"
+
+
+struct _GgitCredSshKeyFromAgentPrivate
+{
+ gchar *username;
+};
+
+enum
+{
+ PROP_0,
+ PROP_USERNAME
+};
+
+static void ggit_cred_ssh_key_from_agent_initable_iface_init (GInitableIface *iface);
+
+G_DEFINE_TYPE_EXTENDED (GgitCredSshKeyFromAgent,
+ ggit_cred_ssh_key_from_agent,
+ GGIT_TYPE_CRED,
+ 0,
+ G_IMPLEMENT_INTERFACE (G_TYPE_INITABLE,
+ ggit_cred_ssh_key_from_agent_initable_iface_init))
+
+static void
+ggit_cred_ssh_key_from_agent_finalize (GObject *object)
+{
+ GgitCredSshKeyFromAgentPrivate *priv = GGIT_CRED_SSH_KEY_FROM_AGENT (object)->priv;
+
+ g_free (priv->username);
+
+ G_OBJECT_CLASS (ggit_cred_ssh_key_from_agent_parent_class)->finalize (object);
+}
+
+static void
+ggit_cred_ssh_key_from_agent_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ GgitCredSshKeyFromAgentPrivate *priv = GGIT_CRED_SSH_KEY_FROM_AGENT (object)->priv;
+
+ switch (prop_id)
+ {
+ case PROP_USERNAME:
+ g_value_set_string (value, priv->username);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
+ggit_cred_ssh_key_from_agent_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ GgitCredSshKeyFromAgentPrivate *priv = GGIT_CRED_SSH_KEY_FROM_AGENT (object)->priv;
+
+ switch (prop_id)
+ {
+ case PROP_USERNAME:
+ priv->username = g_value_dup_string (value);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
+ggit_cred_ssh_key_from_agent_class_init (GgitCredSshKeyFromAgentClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ object_class->finalize = ggit_cred_ssh_key_from_agent_finalize;
+ object_class->get_property = ggit_cred_ssh_key_from_agent_get_property;
+ object_class->set_property = ggit_cred_ssh_key_from_agent_set_property;
+
+ g_object_class_install_property (object_class,
+ PROP_USERNAME,
+ g_param_spec_string ("username",
+ "user name",
+ "The user name",
+ NULL,
+ G_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT_ONLY |
+ G_PARAM_STATIC_STRINGS));
+
+ g_type_class_add_private (object_class, sizeof (GgitCredSshKeyFromAgentPrivate));
+}
+
+static void
+ggit_cred_ssh_key_from_agent_init (GgitCredSshKeyFromAgent *cred)
+{
+ cred->priv = G_TYPE_INSTANCE_GET_PRIVATE(cred,
+ GGIT_TYPE_CRED_SSH_KEY_FROM_AGENT,
+ GgitCredSshKeyFromAgentPrivate);
+}
+
+static gboolean
+ggit_cred_ssh_key_from_agent_initable_init (GInitable *initable,
+ GCancellable *cancellable,
+ GError **error)
+{
+ GgitCredSshKeyFromAgentPrivate *priv;
+ git_cred *cred;
+ gint ret;
+
+ if (cancellable != NULL)
+ {
+ g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
+ "Cancellable initialization not supported");
+ return FALSE;
+ }
+
+ priv = GGIT_CRED_SSH_KEY_FROM_AGENT (initable)->priv;
+
+ ret = git_cred_ssh_key_from_agent (&cred, priv->username);
+
+ if (ret != GIT_OK)
+ {
+ _ggit_error_set (error, ret);
+ return FALSE;
+ }
+
+ _ggit_native_set (initable,
+ cred,
+ (GDestroyNotify)cred->free);
+
+ return TRUE;
+}
+
+static void
+ggit_cred_ssh_key_from_agent_initable_iface_init (GInitableIface *iface)
+{
+ iface->init = ggit_cred_ssh_key_from_agent_initable_init;
+}
+
+GgitCredSshKeyFromAgent *
+ggit_cred_ssh_key_from_agent_new (const gchar *username,
+ GError **error)
+{
+ return g_initable_new (GGIT_TYPE_CRED_SSH_KEY_FROM_AGENT,
+ NULL, error,
+ "username", username,
+ NULL);
+}
+
+const gchar *
+ggit_cred_ssh_key_from_agent_get_username (GgitCredSshKeyFromAgent *cred)
+{
+ g_return_val_if_fail (GGIT_IS_CRED_SSH_KEY_FROM_AGENT (cred), NULL);
+
+ return cred->priv->username;
+}
+
+/* ex:set ts=8 noet: */
diff --git a/libgit2-glib/ggit-cred-ssh-key-from-agent.h b/libgit2-glib/ggit-cred-ssh-key-from-agent.h
new file mode 100644
index 0000000..846d357
--- /dev/null
+++ b/libgit2-glib/ggit-cred-ssh-key-from-agent.h
@@ -0,0 +1,67 @@
+/*
+ * ggit-cred-ssh-key-from-agent.h
+ * This file is part of libgit2-glib
+ *
+ * Copyright (C) 2013 - Ignacio Casal Quinteiro
+ *
+ * libgit2-glib is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * libgit2-glib 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with libgit2-glib. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#ifndef __GGIT_CRED_SSH_KEY_FROM_AGENT_H__
+#define __GGIT_CRED_SSH_KEY_FROM_AGENT_H__
+
+#include <glib-object.h>
+#include <libgit2-glib/ggit-cred.h>
+
+G_BEGIN_DECLS
+
+#define GGIT_TYPE_CRED_SSH_KEY_FROM_AGENT (ggit_cred_ssh_key_from_agent_get_type ())
+#define GGIT_CRED_SSH_KEY_FROM_AGENT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj),
GGIT_TYPE_CRED_SSH_KEY_FROM_AGENT, GgitCredSshKeyFromAgent))
+#define GGIT_CRED_SSH_KEY_FROM_AGENT_CONST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj),
GGIT_TYPE_CRED_SSH_KEY_FROM_AGENT, GgitCredSshKeyFromAgent const))
+#define GGIT_CRED_SSH_KEY_FROM_AGENT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass),
GGIT_TYPE_CRED_SSH_KEY_FROM_AGENT, GgitCredSshKeyFromAgentClass))
+#define GGIT_IS_CRED_SSH_KEY_FROM_AGENT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj),
GGIT_TYPE_CRED_SSH_KEY_FROM_AGENT))
+#define GGIT_IS_CRED_SSH_KEY_FROM_AGENT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass),
GGIT_TYPE_CRED_SSH_KEY_FROM_AGENT))
+#define GGIT_CRED_SSH_KEY_FROM_AGENT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj),
GGIT_TYPE_CRED_SSH_KEY_FROM_AGENT, GgitCredSshKeyFromAgentClass))
+
+typedef struct _GgitCredSshKeyFromAgentClass GgitCredSshKeyFromAgentClass;
+typedef struct _GgitCredSshKeyFromAgentPrivate GgitCredSshKeyFromAgentPrivate;
+
+struct _GgitCredSshKeyFromAgent
+{
+ /*< private >*/
+ GgitCred parent;
+
+ GgitCredSshKeyFromAgentPrivate *priv;
+};
+
+struct _GgitCredSshKeyFromAgentClass
+{
+ /*< private >*/
+ GgitCredClass parent_class;
+};
+
+GType ggit_cred_ssh_key_from_agent_get_type (void) G_GNUC_CONST;
+
+GgitCredSshKeyFromAgent *
+ ggit_cred_ssh_key_from_agent_new (const gchar *username,
+ GError **error);
+
+const gchar *ggit_cred_ssh_key_from_agent_get_username (GgitCredSshKeyFromAgent *cred);
+
+G_END_DECLS
+
+#endif /* __GGIT_CRED_SSH_KEY_FROM_AGENT_H__ */
+
+/* ex:set ts=8 noet: */
diff --git a/libgit2-glib/ggit-types.h b/libgit2-glib/ggit-types.h
index 254a161..8f2f39d 100644
--- a/libgit2-glib/ggit-types.h
+++ b/libgit2-glib/ggit-types.h
@@ -96,6 +96,27 @@ typedef struct _GgitConfigEntry GgitConfigEntry;
typedef struct _GgitCred GgitCred;
/**
+ * GgitCredSshInteractive:
+ *
+ * Represents a ssh interactive credential.
+ */
+typedef struct _GgitCredSshInteractive GgitCredSshInteractive;
+
+/**
+ * GgitCredSshInteractivePrompt:
+ *
+ * Represents a ssh interactive prompt.
+ */
+typedef struct _GgitCredSshInteractivePrompt GgitCredSshInteractivePrompt;
+
+/**
+ * GgitCredSshKeyFromAgent:
+ *
+ * Represents a ssh key agent credential.
+ */
+typedef struct _GgitCredSshKeyFromAgent GgitCredSshKeyFromAgent;
+
+/**
* GgitCredPlaintext:
*
* Represents a plain text credential.
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]