[gmime] Added g_mime_gpg_context_get/set_use_agent()
- From: Jeffrey Stedfast <fejj src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gmime] Added g_mime_gpg_context_get/set_use_agent()
- Date: Wed, 8 Jun 2011 16:28:05 +0000 (UTC)
commit ed985397843a9da3745a8b5de3d1d652acd24724
Author: Jeffrey Stedfast <fejj gnome org>
Date: Wed Jun 8 12:27:27 2011 -0400
Added g_mime_gpg_context_get/set_use_agent()
2011-06-08 Daniel Kahn Gillmor <dkg fifthhorseman net>
Fix for bug #651826
* gmime/gmime-gpg-context.c
(g_mime_gpg_context_[g,s]_set_use_agent): New functions to allow
the invoker to declare that they expect there to be a
functioning
gpg-agent, and want gpg to talk to it for any needed
credentials.
ChangeLog | 9 +++++
docs/reference/gmime-sections.txt | 2 +
gmime/gmime-certificate.h | 1 +
gmime/gmime-gpg-context.c | 70 +++++++++++++++++++++++++++++++++---
gmime/gmime-gpg-context.h | 4 ++
gmime/gmime-signature.h | 1 +
6 files changed, 81 insertions(+), 6 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 563af08..32ab5de 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2011-06-08 Daniel Kahn Gillmor <dkg fifthhorseman net>
+
+ Fix for bug #651826
+
+ * gmime/gmime-gpg-context.c
+ (g_mime_gpg_context_[g,s]_set_use_agent): New functions to allow
+ the invoker to declare that they expect there to be a functioning
+ gpg-agent, and want gpg to talk to it for any needed credentials.
+
2011-06-08 Jeffrey Stedfast <fejj gnome org>
* gmime/gmime-gpg-context.c: If building on Apple, force the use
diff --git a/docs/reference/gmime-sections.txt b/docs/reference/gmime-sections.txt
index 47a7d09..e8b7995 100644
--- a/docs/reference/gmime-sections.txt
+++ b/docs/reference/gmime-sections.txt
@@ -1304,6 +1304,8 @@ g_mime_gpg_context_get_always_trust
g_mime_gpg_context_set_always_trust
g_mime_gpg_context_get_auto_key_retrieve
g_mime_gpg_context_set_auto_key_retrieve
+g_mime_gpg_context_get_use_agent
+g_mime_gpg_context_set_use_agent
<SUBSECTION Private>
g_mime_gpg_context_get_type
diff --git a/gmime/gmime-certificate.h b/gmime/gmime-certificate.h
index 582216e..86bd5f5 100644
--- a/gmime/gmime-certificate.h
+++ b/gmime/gmime-certificate.h
@@ -41,6 +41,7 @@ G_BEGIN_DECLS
#define GMIME_CERTIFICATE_LIST_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GMIME_TYPE_CERTIFICATE_LIST, GMimeCertificateListClass))
#define GMIME_IS_CERTIFICATE_LIST(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GMIME_TYPE_CERTIFICATE_LIST))
#define GMIME_IS_CERTIFICATE_LIST_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GMIME_TYPE_CERTIFICATE_LIST))
+#define GMIME_CERTIFICATE_LIST_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GMIME_TYPE_CERTIFICATE_LIST, GMimeCertificateListClass))
typedef struct _GMimeCertificate GMimeCertificate;
diff --git a/gmime/gmime-gpg-context.c b/gmime/gmime-gpg-context.c
index 7fed007..afe254e 100644
--- a/gmime/gmime-gpg-context.c
+++ b/gmime/gmime-gpg-context.c
@@ -169,6 +169,7 @@ g_mime_gpg_context_init (GMimeGpgContext *ctx, GMimeGpgContextClass *klass)
ctx->auto_key_retrieve = FALSE;
ctx->always_trust = FALSE;
+ ctx->use_agent = FALSE;
ctx->path = NULL;
}
@@ -320,11 +321,12 @@ struct _GpgCtx {
unsigned int seen_eof2:1;
unsigned int flushed:1; /* flushed the diagnostics stream (aka stderr) */
unsigned int always_trust:1;
+ unsigned int use_agent:1;
unsigned int armor:1;
unsigned int need_passwd:1;
unsigned int bad_passwds:2;
- unsigned int padding:21;
+ unsigned int padding:20;
};
static struct _GpgCtx *
@@ -351,6 +353,7 @@ gpg_ctx_new (GMimeGpgContext *ctx)
gpg->cipher = GMIME_CIPHER_ALGO_DEFAULT;
gpg->digest = GMIME_DIGEST_ALGO_DEFAULT;
gpg->always_trust = FALSE;
+ gpg->use_agent = FALSE;
gpg->armor = FALSE;
gpg->stdin_fd = -1;
@@ -421,6 +424,12 @@ gpg_ctx_set_always_trust (struct _GpgCtx *gpg, gboolean trust)
}
static void
+gpg_ctx_set_use_agent (struct _GpgCtx *gpg, gboolean use_agent)
+{
+ gpg->use_agent = use_agent;
+}
+
+static void
gpg_ctx_set_userid (struct _GpgCtx *gpg, const char *userid)
{
g_free (gpg->userid);
@@ -606,6 +615,9 @@ gpg_ctx_get_argv (struct _GpgCtx *gpg, int status_fd, int secret_fd, char ***str
switch (gpg->mode) {
case GPG_CTX_MODE_SIGN:
+ if (gpg->use_agent)
+ g_ptr_array_add (args, "--use-agent");
+
g_ptr_array_add (args, "--sign");
g_ptr_array_add (args, "--detach");
if (gpg->armor)
@@ -637,6 +649,9 @@ gpg_ctx_get_argv (struct _GpgCtx *gpg, int status_fd, int secret_fd, char ***str
g_ptr_array_add (args, "-");
break;
case GPG_CTX_MODE_SIGN_ENCRYPT:
+ if (gpg->use_agent)
+ g_ptr_array_add (args, "--use-agent");
+
g_ptr_array_add (args, "--sign");
if ((digest_str = gpg_digest_str (gpg->digest)))
@@ -667,6 +682,9 @@ gpg_ctx_get_argv (struct _GpgCtx *gpg, int status_fd, int secret_fd, char ***str
g_ptr_array_add (args, "-");
break;
case GPG_CTX_MODE_DECRYPT:
+ if (gpg->use_agent)
+ g_ptr_array_add (args, "--use-agent");
+
g_ptr_array_add (args, "--decrypt");
g_ptr_array_add (args, "--output");
g_ptr_array_add (args, "-");
@@ -1785,6 +1803,7 @@ gpg_sign (GMimeCryptoContext *context, const char *userid, GMimeDigestAlgo diges
gpg = gpg_ctx_new (ctx);
gpg_ctx_set_mode (gpg, GPG_CTX_MODE_SIGN);
+ gpg_ctx_set_use_agent (gpg, ctx->use_agent);
gpg_ctx_set_digest (gpg, digest);
gpg_ctx_set_armor (gpg, TRUE);
gpg_ctx_set_userid (gpg, userid);
@@ -1898,16 +1917,19 @@ gpg_encrypt (GMimeCryptoContext *context, gboolean sign, const char *userid,
guint i;
gpg = gpg_ctx_new (ctx);
- if (sign)
+ if (sign) {
gpg_ctx_set_mode (gpg, GPG_CTX_MODE_SIGN_ENCRYPT);
- else
+ gpg_ctx_set_use_agent (gpg, ctx->use_agent);
+ } else {
gpg_ctx_set_mode (gpg, GPG_CTX_MODE_ENCRYPT);
+ }
+
+ gpg_ctx_set_always_trust (gpg, ctx->always_trust);
gpg_ctx_set_digest (gpg, digest);
gpg_ctx_set_armor (gpg, TRUE);
gpg_ctx_set_userid (gpg, userid);
gpg_ctx_set_istream (gpg, istream);
gpg_ctx_set_ostream (gpg, ostream);
- gpg_ctx_set_always_trust (gpg, ctx->always_trust);
for (i = 0; i < recipients->len; i++)
gpg_ctx_add_recipient (gpg, recipients->pdata[i]);
@@ -1962,6 +1984,7 @@ gpg_decrypt (GMimeCryptoContext *context, GMimeStream *istream,
gpg = gpg_ctx_new (ctx);
gpg_ctx_set_mode (gpg, GPG_CTX_MODE_DECRYPT);
+ gpg_ctx_set_use_agent (gpg, ctx->use_agent);
gpg_ctx_set_istream (gpg, istream);
gpg_ctx_set_ostream (gpg, ostream);
@@ -2173,9 +2196,9 @@ g_mime_gpg_context_set_auto_key_retrieve (GMimeGpgContext *ctx, gboolean auto_ke
* g_mime_gpg_context_get_always_trust:
* @ctx: a #GMimeGpgContext
*
- * Gets the @always_trust flag on the gpg context.
+ * Gets the always_trust flag on the gpg context.
*
- * Returns: the @always_trust flag on the gpg context.
+ * Returns: the always_trust flag on the gpg context.
**/
gboolean
g_mime_gpg_context_get_always_trust (GMimeGpgContext *ctx)
@@ -2201,3 +2224,38 @@ g_mime_gpg_context_set_always_trust (GMimeGpgContext *ctx, gboolean always_trust
ctx->always_trust = always_trust;
}
+
+
+/**
+ * g_mime_gpg_context_get_use_agent:
+ * @ctx: a #GMimeGpgContext
+ *
+ * Gets the use_agent flag on the gpg context.
+ *
+ * Returns: the use_agent flag on the gpg context, which indicates
+ * that GnuPG should attempt to use gpg-agent for credentials.
+ **/
+gboolean
+g_mime_gpg_context_get_use_agent (GMimeGpgContext *ctx)
+{
+ g_return_val_if_fail (GMIME_IS_GPG_CONTEXT (ctx), FALSE);
+
+ return ctx->use_agent;
+}
+
+
+/**
+ * g_mime_gpg_context_set_use_agent:
+ * @ctx: a #GMimeGpgContext
+ * @use_agent: always trust flag
+ *
+ * Sets the @use_agent flag on the gpg context, which indicates that
+ * GnuPG should attempt to use gpg-agent for credentials.
+ **/
+void
+g_mime_gpg_context_set_use_agent (GMimeGpgContext *ctx, gboolean use_agent)
+{
+ g_return_if_fail (GMIME_IS_GPG_CONTEXT (ctx));
+
+ ctx->use_agent = use_agent;
+}
diff --git a/gmime/gmime-gpg-context.h b/gmime/gmime-gpg-context.h
index c82bde8..f80cc37 100644
--- a/gmime/gmime-gpg-context.h
+++ b/gmime/gmime-gpg-context.h
@@ -49,6 +49,7 @@ struct _GMimeGpgContext {
GMimeCryptoContext parent_object;
gboolean auto_key_retrieve;
gboolean always_trust;
+ gboolean use_agent;
char *path;
};
@@ -69,6 +70,9 @@ void g_mime_gpg_context_set_auto_key_retrieve (GMimeGpgContext *ctx, gboolean au
gboolean g_mime_gpg_context_get_always_trust (GMimeGpgContext *ctx);
void g_mime_gpg_context_set_always_trust (GMimeGpgContext *ctx, gboolean always_trust);
+gboolean g_mime_gpg_context_get_use_agent (GMimeGpgContext *ctx);
+void g_mime_gpg_context_set_use_agent (GMimeGpgContext *ctx, gboolean use_agent);
+
G_END_DECLS
#endif /* __GMIME_GPG_CONTEXT_H__ */
diff --git a/gmime/gmime-signature.h b/gmime/gmime-signature.h
index 0369a33..1e5c957 100644
--- a/gmime/gmime-signature.h
+++ b/gmime/gmime-signature.h
@@ -38,6 +38,7 @@ G_BEGIN_DECLS
#define GMIME_SIGNATURE_LIST_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GMIME_TYPE_SIGNATURE_LIST, GMimeSignatureListClass))
#define GMIME_IS_SIGNATURE_LIST(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GMIME_TYPE_SIGNATURE_LIST))
#define GMIME_IS_SIGNATURE_LIST_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GMIME_TYPE_SIGNATURE_LIST))
+#define GMIME_SIGNATURE_LIST_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GMIME_TYPE_SIGNATURE_LIST, GMimeSignatureListClass))
typedef struct _GMimeSignature GMimeSignature;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]