aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--camel/ChangeLog6
-rw-r--r--camel/camel-pgp-context.c49
2 files changed, 55 insertions, 0 deletions
diff --git a/camel/ChangeLog b/camel/ChangeLog
index 63de9500f6..8c6b76e3ab 100644
--- a/camel/ChangeLog
+++ b/camel/ChangeLog
@@ -1,5 +1,11 @@
2001-04-02 Jeffrey Stedfast <fejj@ximian.com>
+ * camel-pgp-context.c (camel_pgp_sign): mutex lock & unlock the context.
+ (camel_pgp_clearsign): Same.
+ (camel_pgp_verify): Same.
+ (camel_pgp_encrypt): Same.
+ (camel_pgp_decrypt): And finally here...
+
* camel-pgp-context.h: Update the function prototypes to match
those found in camel-pgp-context.c.
diff --git a/camel/camel-pgp-context.c b/camel/camel-pgp-context.c
index 3193f5d8b2..05e5a190d5 100644
--- a/camel/camel-pgp-context.c
+++ b/camel/camel-pgp-context.c
@@ -49,12 +49,25 @@
#include <iconv.h>
+#ifdef ENABLE_THREADS
+#include <pthread.h>
+#define PGP_LOCK(ctx) g_mutex_lock (((CamelPgpContext *) ctx)->priv->lock)
+#define PGP_UNLOCK(ctx) g_mutex_unlock (((CamelPgpContext *) ctx)->priv->lock);
+#else
+#define PGP_LOCK(ctx)
+#define PGP_UNLOCK(ctx)
+#endif
+
#define d(x)
struct _CamelPgpContextPrivate {
CamelSession *session;
CamelPgpType type;
char *path;
+
+#ifdef ENABLE_THREADS
+ GMutex *lock;
+#endif
};
static CamelObjectClass *parent_class;
@@ -498,6 +511,8 @@ camel_pgp_sign (CamelPgpContext *context, const char *userid, CamelPgpHashType h
char passwd_fd[32];
int retval, i;
+ PGP_LOCK(context);
+
/* get the plaintext in a form we can use */
plaintext = g_byte_array_new ();
stream = camel_stream_mem_new ();
@@ -631,6 +646,8 @@ camel_pgp_sign (CamelPgpContext *context, const char *userid, CamelPgpHashType h
g_free (ciphertext);
pgp_forget_passphrase (context->priv->session, context->priv->type, userid);
+ PGP_UNLOCK(context);
+
return -1;
}
@@ -639,6 +656,8 @@ camel_pgp_sign (CamelPgpContext *context, const char *userid, CamelPgpHashType h
camel_stream_write (ostream, ciphertext, strlen (ciphertext));
g_free (ciphertext);
+ PGP_UNLOCK(context);
+
return 0;
exception:
@@ -650,6 +669,8 @@ camel_pgp_sign (CamelPgpContext *context, const char *userid, CamelPgpHashType h
g_free (passphrase);
}
+ PGP_UNLOCK(context);
+
return -1;
}
@@ -682,6 +703,8 @@ camel_pgp_clearsign (CamelPgpContext *context, const char *userid, CamelPgpHashT
char passwd_fd[32];
int retval, i;
+ PGP_LOCK(context);
+
/* get the plaintext in a form we can use */
plaintext = g_byte_array_new ();
stream = camel_stream_mem_new ();
@@ -820,6 +843,8 @@ camel_pgp_clearsign (CamelPgpContext *context, const char *userid, CamelPgpHashT
camel_stream_write (ostream, ciphertext, strlen (ciphertext));
g_free (ciphertext);
+ PGP_UNLOCK(context);
+
return 0;
exception:
@@ -831,6 +856,8 @@ camel_pgp_clearsign (CamelPgpContext *context, const char *userid, CamelPgpHashT
g_free (passphrase);
}
+ PGP_UNLOCK(context);
+
return -1;
}
@@ -887,6 +914,8 @@ camel_pgp_verify (CamelPgpContext *context, CamelStream *istream,
char *sigfile = NULL;
int retval, i, clearlen;
+ PGP_LOCK(context);
+
/* get the plaintext in a form we can use */
plaintext = g_byte_array_new ();
stream = camel_stream_mem_new ();
@@ -1023,12 +1052,16 @@ camel_pgp_verify (CamelPgpContext *context, CamelStream *istream,
g_free (diagnostics);
g_free (cleartext);
+ PGP_UNLOCK(context);
+
return valid;
exception:
g_byte_array_free (plaintext, TRUE);
+ PGP_UNLOCK(context);
+
return NULL;
}
@@ -1063,6 +1096,8 @@ camel_pgp_encrypt (CamelPgpContext *context, gboolean sign, const char *userid,
char passwd_fd[32];
char *passphrase = NULL;
+ PGP_LOCK(context);
+
/* get the plaintext in a form we can use */
plaintext = g_byte_array_new ();
stream = camel_stream_mem_new ();
@@ -1239,6 +1274,8 @@ camel_pgp_encrypt (CamelPgpContext *context, gboolean sign, const char *userid,
if (sign)
pgp_forget_passphrase (context->priv->session, context->priv->type, userid);
+ PGP_UNLOCK(context);
+
return -1;
}
@@ -1247,6 +1284,8 @@ camel_pgp_encrypt (CamelPgpContext *context, gboolean sign, const char *userid,
camel_stream_write (ostream, ciphertext, strlen (ciphertext));
g_free (ciphertext);
+ PGP_UNLOCK(context);
+
return 0;
exception:
@@ -1258,6 +1297,8 @@ camel_pgp_encrypt (CamelPgpContext *context, gboolean sign, const char *userid,
pgp_forget_passphrase (context->priv->session, context->priv->type, userid);
}
+ PGP_UNLOCK(context);
+
return -1;
}
@@ -1289,6 +1330,8 @@ camel_pgp_decrypt (CamelPgpContext *context, CamelStream *istream,
char passwd_fd[32];
int retval, i;
+ PGP_LOCK(context);
+
/* get the ciphertext in a form we can use */
ciphertext = g_byte_array_new ();
stream = camel_stream_mem_new ();
@@ -1376,6 +1419,8 @@ camel_pgp_decrypt (CamelPgpContext *context, CamelStream *istream,
pgp_forget_passphrase (context->priv->session, context->priv->type, NULL);
+ PGP_UNLOCK(context);
+
return -1;
}
@@ -1384,6 +1429,8 @@ camel_pgp_decrypt (CamelPgpContext *context, CamelStream *istream,
camel_stream_write (ostream, plaintext, plainlen);
g_free (plaintext);
+ PGP_UNLOCK(context);
+
return 0;
exception:
@@ -1395,6 +1442,8 @@ camel_pgp_decrypt (CamelPgpContext *context, CamelStream *istream,
g_free (passphrase);
}
+ PGP_UNLOCK(context);
+
return -1;
}